summaryrefslogtreecommitdiff
path: root/plugins/Watrack/status/i_opt_tmpl.inc
blob: 285e61a9e83dad54f82d44c208063eb15817facf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
{Save/load options}

const
  opt_numstr:PAnsiChar = 'template/numstr';
const
  ppref = 'proto/';
  spref = 'strings/';

procedure SaveTemplates;
var
  i,lProtoStatus:cardinal;
  lTmplType:tTemplateType;
  p:PAnsiChar;
  buf:PAnsiChar;
  NumProto:cardinal;
  tmpl:pStrTemplate;
  tmp:SmallInt;
  setting:array [0..63] of AnsiChar;
  pset:PAnsiChar;
begin
  DBWriteWord(0,PluginShort,opt_numstr,NumString);
  StrCopy(setting,spref);
  pset:=StrEnd(setting);
  for i:=1 to NumString do
  begin
    IntToStr(pset,i);
    DBWriteUnicode(0,PluginShort,setting,strings^[i].text);
  end;

  NumProto:=GetNumProto;
  mGetMem(buf,16384);
  for i:=0 to NumProto do
  begin
    pset:=StrCopyE(setting,ppref);
    pset:=StrCopyE(pset,GetProtoName(i));

    StrCopy(pset,'/XStatus');
    DBWriteWord(0,PluginShort,setting,GetProtoSetting(i,true));
    inc(pset);
    if i<>0 then
    begin
      StrCopy(pset,'enabled');
      DBWriteWord(0,PluginShort,setting,GetProtoSetting(i));
    end;

    p:=buf;
    tmpl:=@StrTemplates^[i];
    pset[3]:=#0;
    for lProtoStatus:=0 to NumStatus-1 do
      for lTmplType:=tmpl_first to tmpl_last do
      begin
        tmp:=tmpl^[lProtoStatus,lTmplType];
        if tmp=0 then
        begin
          if p<>buf then
          begin
            p^:=',';
            inc(p);
          end;
          p^:='0'; inc(p); // for compatibility
          p^:=AnsiChar(lProtoStatus  +ORD('0')); inc(p);
          p^:=AnsiChar(ORD(lTmplType)+ORD('0')); inc(p);
        end
        else if (tmp<>0) and (tmp<>smallint(dubtmpl)) then
        begin
          pset[0]:='0'; // for compatibility
          pset[1]:=AnsiChar(lProtoStatus  +ORD('0'));
          pset[2]:=AnsiChar(ORD(lTmplType)+ORD('0'));
          DBWriteWord(0,PluginShort,setting,word(tmp));
        end;
      end;
    if p<>buf then
    begin
      p^:=#0;
      StrCopy(pset,'empty');
      DBWriteString(0,PluginShort,setting,buf);
    end;
  end;
  mFreeMem(buf);
end;

procedure InitDefault;
var
  tmpl:pStrTemplate;
begin
  NumString:=8;
  mGetMem (strings ,SizeOf(tMyString)*NumString);
  FillChar(strings^,SizeOf(tMyString)*NumString,0);

  if isVarsInstalled then
  begin
    StrDupW(strings^[1].text,TranslateW(defAltTemplate));
    StrDupW(strings^[4].text,TranslateW(defAltChannelText));
  end
  else
  begin
    StrDupW(strings^[1].text,TranslateW(defTemplate));
    StrDupW(strings^[4].text,TranslateW(defChannelText));
  end;
  StrDupW(strings^[2].text,TranslateW(defStatusTitle));
  StrDupW(strings^[3].text,TranslateW(defStatusText));

  tmpl:=@StrTemplates^[DefaultTemplate];
  if tmpl^[0,tmpl_first]=smallint(dubtmpl) then
  begin
    // music played
    tmpl^[0,tmpl_pm    ]:=1;
    tmpl^[0,tmpl_chat  ]:=4;
    tmpl^[0,tmpl_xtitle]:=2;
    tmpl^[0,tmpl_stext ]:=3;
    tmpl^[0,tmpl_xtext ]:=3;
  end;
end;

function EnumSettingsProc(const szSetting:PAnsiChar;lParam:LPARAM):int; cdecl;
var
  p:^PAnsiChar;
  i:cardinal;
  pp:AnsiChar;
begin
  if StrCmp(ppref,szSetting,Length(ppref))=0 then
  begin
    i:=StrLen(szSetting)+1;
    pp:=szSetting[i-2];
    if (pp>='0') and (pp<='9') then
    begin
      p:=pointer(lParam);
      move(szSetting^,p^^,i);
      inc(p^,i);
    end;
  end;
  result:=0;
end;

function EnumTemplates:PAnsiChar;
var
  p:PAnsiChar;
begin
  mGetMem(result,16384);
  result^:=#0;
  p:=result;
  db_enum_settings(0, @EnumSettingsProc, PluginShort, @p);
end;

procedure LoadTemplates;
var
  buf:PAnsiChar;
  lProtoStatus,i,j:cardinal;
  lTmplType:tTemplateType;
  p:PAnsiChar;
  pc:PAnsiChar;
  NumProto:cardinal;
  tmpl:pStrTemplate;
  setting:array [0..63] of AnsiChar;
  pset:PAnsiChar;
begin
  NumString:=DBReadWord(0,PluginShort,opt_numstr,0);
  if NumString>0 then
  begin
    mGetMem (strings ,SizeOf(tMyString)*NumString);
    FillChar(strings^,SizeOf(tMyString)*NumString,0);
    StrCopy(setting,spref);
    pset:=StrEnd(setting);
    for i:=1 to NumString do
    begin
      IntToStr(pset,i);
      strings^[i].text:=DBReadUnicode(0,PluginShort,setting,nil);
    end;

    NumProto:=GetNumProto;
    buf:=EnumTemplates;
    for i:=0 to NumProto do
    begin
      pset:=StrCopyE(setting,ppref);
      pset:=StrCopyE(pset,GetProtoName(i));

      StrCopy(pset,'/XStatus');
      j:=DBReadWord(0,PluginShort,setting,$080B);
{!!
      if j=0 then          
        j:=DefaultXStatus;
}
      SetProtoSetting(i,j,true);

      inc(pset);
      if i<>0 then
      begin
        StrCopy(pset,'enabled');
        SetProtoSetting(i,DBReadWord(0,PluginShort,setting,psf_all));
      end;

      tmpl:=@StrTemplates^[i];
      StrCopy(pset,'empty');
      pc:=DBReadString(0,PluginShort,setting,nil);
      if pc<>nil then
      begin
        p:=pc;
        if (p^>='0') and (p^<='9') then
          while p^<>#0 do
          begin
            lProtoStatus :=              ORD(p[1])-ORD('0');
            lTmplType    :=tTemplateType(ORD(p[2])-ORD('0'));
            tmpl^[lProtoStatus,lTmplType]:=0;
            inc(p,3);
            if p^=',' then
              inc(p);
          end;
        mFreeMem(pc);
      end;

      pc:=buf;
      pset^:=#0;
      j:=StrLen(setting);
      pset[3]:=#0;
      while pc^<>#0 do
      begin
        if StrCmp(pc,setting,j)=0 then // only proper proto
        begin
          pc:=StrEnd(pc);
          lProtoStatus :=              ORD((pc-2)^)-ORD('0');
          lTmplType    :=tTemplateType(ORD((pc-1)^)-ORD('0'));

          pset[0]:='0';
          pset[1]:=AnsiChar(lProtoStatus  +ORD('0'));
          pset[2]:=AnsiChar(ORD(lTmplType)+ORD('0'));

          tmpl^[lProtoStatus,lTmplType]:=
              DBReadWord(0,PluginShort,setting,dubtmpl);
        end
        else
          pc:=StrEnd(pc);
        inc(pc);
      end;
    end;
    mFreeMem(buf);
  end
  else
    InitDefault;
end;