summaryrefslogtreecommitdiff
path: root/plugins/Actman/i_options.inc
blob: 26dd8e1f0809ae30a7b5ff54f1f88b8c17f2ae52 (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
{Save/load options}

const
  opt_group   = 'Group';
  opt_actions = 'Action';
  opt_numacts = 'numactions';
  opt_numhk   = 'numgroups';
  opt_firstAction = 'firstaction';

  opt_cproto   = 'cproto';
  opt_cuid     = 'cuid';
  opt_ischat   = 'ischat';

  opt_descr    = 'descr';
  opt_id       = 'id';
  opt_flags    = 'flags';
  opt_flags2   = 'flags2';
  opt_time     = 'time';
  opt_show     = 'show';
  opt_action   = 'action';
  opt_value    = 'value';
  opt_file     = 'file';

  opt_next     = 'next';
  opt_type     = 'type';
  opt_contact  = 'contact';
  opt_text     = 'text';
  opt_prg      = 'program';
  opt_args     = 'arguments';
  opt_service  = 'service';
  opt_wparam   = 'wparam';
  opt_wlparam  = 'wparamlen';
  opt_llparam  = 'lparamlen';
  opt_lparam   = 'lparam';
  opt_chain    = 'chain';
  opt_cond     = 'condition';
  opt_count    = 'count';
  opt_module   = 'module';
  opt_setting  = 'setting';
  opt_oper     = 'operation';
  opt_mathval  = 'mathval';
  opt_operval  = 'operval';
  opt_varval   = 'varval';
  opt_msgtitle = 'msgtitle';
  opt_msgtext  = 'msgtext';
  opt_boxopts  = 'boxopts';


//----- Save settings -----

procedure SaveNumValue(setting:pAnsiChar;value:uint_ptr;isvar:boolean);
begin
  if isvar then
    DBWriteUnicode(0,DBBranch,setting,pWideChar(value))
  else
    DBWriteDWord  (0,DBBranch,setting,value);
end;

function SaveActions(section:pAnsiChar;first:integer):integer;
var
  p,p1:PAnsiChar;
  act:pHKAction;
  i:integer;
begin
  result:=0;
  // in: section = "Group#/"
  p1:=StrCopyE(StrEnd(section),opt_actions); // "Group#/Action"
  DBDeleteGroup(0,DBBranch,section);
  i:=1;
  while first<>0 do
  begin
    act:=@ActionList[first];
    p:=StrEnd(IntToStr(p1,i)); //!!!
    p^:='/'; inc(p); // "Group#/Action#/"

    StrCopy(p,opt_flags ); DBWriteDWord(0,DBBranch,section,act^.flags);
    StrCopy(p,opt_flags2); DBWriteDWord(0,DBBranch,section,act^.flags2);
    StrCopy(p,opt_type  ); DBWriteByte (0,DBBranch,section,act^.actionType);
    if act^.descr<>nil then
    begin
      StrCopy(p,opt_descr); DBWriteUnicode(0,DBBranch,section,act^.descr);
    end;

    case act^.actionType of
      ACT_CONTACT: begin
        p^:=#0;
        SaveContact(act^.contact,DBBranch,section);
      end;

      ACT_SERVICE: begin
        StrCopy(p,opt_service); DBWriteString(0,DBBranch,section,act^.service);

        if (act^.flags and (ACF_WCURRENT or ACF_WRESULT or ACF_WPARAM))=0 then
        begin
          StrCopy(p,opt_wparam);
          if (act^.flags and ACF_WPARNUM)<>0 then
            SaveNumValue(section,act^.wparam,(act^.flags2 and ACF2_SRV_WPAR)<>0)
//            DBWriteDWord(0,DBBranch,section,act^.wparam)
          else if act^.wparam<>0 then
          begin
            if (act^.flags and ACF_WSTRUCT)<>0 then
              DBWriteUTF8(0,DBBranch,section,pAnsiChar(act^.wparam))
            else if (act^.flags and ACF_WUNICODE)<>0 then
              DBWriteUnicode(0,DBBranch,section,pWideChar(act^.wparam))
            else
              DBWriteString(0,DBBranch,section,PAnsiChar(act^.wparam));
          end;
        end;

        if (act^.flags and (ACF_LCURRENT or ACF_LRESULT or ACF_LPARAM))=0 then
        begin
          StrCopy(p,opt_lparam);
          if (act^.flags and ACF_LPARNUM)<>0 then
            SaveNumValue(section,act^.lparam,(act^.flags2 and ACF2_SRV_LPAR)<>0)
//            DBWriteDWord(0,DBBranch,section,act^.lparam)
          else if act^.lparam<>0 then
          begin
            if (act^.flags and ACF_LSTRUCT)<>0 then
              DBWriteUTF8(0,DBBranch,section,pAnsiChar(act^.lparam))
            else if (act^.flags and ACF_LUNICODE)<>0 then
              DBWriteUnicode(0,DBBranch,section,pWideChar(act^.lparam))
            else
              DBWriteString(0,DBBranch,section,PAnsiChar(act^.lparam));
          end;
        end;

      end;

      ACT_PROGRAM: begin
        StrCopy(p,opt_prg ); DBWriteUnicode(0,DBBranch,section,act^.prgname);
        StrCopy(p,opt_args); DBWriteUnicode(0,DBBranch,section,act^.args);
        StrCopy(p,opt_time); DBWriteDWord  (0,DBBranch,section,act^.time);
        StrCopy(p,opt_show); DBWriteDWord  (0,DBBranch,section,act^.show);
      end;

      ACT_TEXT: begin
        if (act^.flags and ACF_CLIPBRD)=0 then
        begin
          StrCopy(p,opt_text); DBWriteUnicode(0,DBBranch,section,act^.text);
          if (act^.flags and ACF_FILE)<>0 then
          begin
            StrCopy(p,opt_file); DBWriteUnicode(0,DBBranch,section,act^.tfile);
          end;
        end;
      end;

      ACT_ADVANCE: begin
        StrCopy(p,opt_cond   ); DBWriteByte   (0,DBBranch,section,act^.condition);
        StrCopy(p,opt_value  ); DBWriteDWord  (0,DBBranch,section,act^.value);
        StrCopy(p,opt_action ); DBWriteByte   (0,DBBranch,section,act^.action);
        StrCopy(p,opt_operval); DBWriteUnicode(0,DBBranch,section,act^.operval);
        StrCopy(p,opt_oper   ); DBWriteByte   (0,DBBranch,section,act^.oper);
        StrCopy(p,opt_mathval); DBWriteDWord  (0,DBBranch,section,act^.mathval);
        StrCopy(p,opt_varval ); DBWriteUnicode(0,DBBranch,section,act^.varval);
      end;

      ACT_CHAIN: begin
        StrCopy(p,opt_text); DBWriteDWord(0,DBBranch,section,act^.id);
      end;

      ACT_RW: begin
        if (act^.flags and ACF_NOCNTCT)=0 then
        begin
          p^:=#0;
          SaveContact(act^.dbcontact,DBBranch,section);
        end;
        StrCopy(p,opt_module ); DBWriteString(0,DBBranch,section,act^.dbmodule);
        StrCopy(p,opt_setting); DBWriteString(0,DBBranch,section,act^.dbsetting);
        StrCopy(p,opt_value  );
        if (act^.flags and ACF_DBUTEXT)=0 then
        begin
          SaveNumValue(section,act^.dbvalue,(act^.flags2 and ACF2_RW_TVAR)<>0);
//          DBWriteDWord(0,DBBranch,section,act^.dbvalue)
        end
        else
          DBWriteUnicode(0,DBBranch,section,pWideChar(act^.dbvalue));
      end;

      ACT_MESSAGE: begin
        StrCopy(p,opt_msgtitle); DBWriteUnicode(0,DBBranch,section,act^.msgtitle);
        StrCopy(p,opt_msgtext ); DBWriteUnicode(0,DBBranch,section,act^.msgtext);
        StrCopy(p,opt_boxopts ); DBWriteByte   (0,DBBranch,section,act^.boxopts); //!!
      end;

    end;
    inc(result);
    inc(i);
    first:=ActionList^[first].next;
  end;
end;

procedure SaveGroups;
var
  HK:pHKRecord;
  NumHK:integer;
  i,num:integer;
  section:array [0..127] of AnsiChar;
  p,p1:PAnsiChar;
  Actions:integer;
begin
// even if crap in settings, skip on read
//  DBDeleteGroup(0,DBBranch,opt_group);
  HK:=@GroupList^;
  i:=MaxGroups;
  NumHK:=0;
  Actions:=1;
  DBWriteUnicode(0,DBBranch,'CLformat',fCLformat);
  DBWriteByte   (0,DBBranch,'CLfilter',ord(fCLfilter));

  p1:=StrCopyE(section,opt_group);
  while i>0 do
  begin
    with HK^ do
    begin
      if (flags and (ACF_ASSIGNED or ACF_VOLATILE))=ACF_ASSIGNED then
      begin
        p:=StrEnd(IntToStr(p1,NumHK));
        p^:='/'; inc(p);

        StrCopy(p,opt_id   ); DBWriteDWord(0,DBBranch,section,id);
        StrCopy(p,opt_flags); DBWriteDWord(0,DBBranch,section,flags);
        StrCopy(p,opt_descr);
        if descr<>nil then
          DBWriteUnicode (0,DBBranch,section,descr)
        else
          DBDeleteSetting(0,DBBranch,section);

        p^:=#0;
    //??
        num:=SaveActions(section,firstAction);
        StrCopy(p,opt_numacts); DBWriteWord(0,DBBranch,section,num);

        inc(Actions,num);
        inc(NumHK);
      end;
    end;
    inc(HK);
    dec(i);
  end;
  DBWriteWord(0,DBBranch,opt_numhk  ,NumHK);
  DBWriteWord(0,DBBranch,opt_numacts,Actions-1);
end;

//----- Load settings -----

function LoadNumValue(setting:pAnsiChar;isvar:boolean):uint_ptr;
begin
  if isvar then
    result:=uint_ptr(DBReadUnicode(0,DBBranch,setting,nil))
  else
    result:=DBReadDWord(0,DBBranch,setting);
end;

function LoadActions(section:pAnsiChar;count:integer):integer;
var
  p,p1:PAnsiChar;
  act:tHKAction;
  i,num,oldnum:integer;
begin
  result:=0;
  p1:=StrCopyE(StrEnd(section),opt_actions); // "Group#/Action"

  oldnum:=0;
  for i:=1 to count do
  begin
    p:=StrEnd(IntToStr(p1,i));
    p^:='/'; inc(p); // "Group#/Action#/"
    FillChar(act,SizeOf(act),0);

    StrCopy(p,opt_flags ); act.flags :=DBReadDWord  (0,DBBranch,section,0);
    if (act.flags and ACF_ASSIGNED)<>0 then
    begin
      StrCopy(p,opt_flags2); act.flags2    :=DBReadDWord  (0,DBBranch,section,0);
      StrCopy(p,opt_descr ); act.descr     :=DBReadUnicode(0,DBBranch,section,nil);
      StrCopy(p,opt_type  ); act.actionType:=DBReadByte   (0,DBBranch,section,ACT_CONTACT);

      case act.actionType of
        ACT_CONTACT: begin
          p^:=#0;
          act.contact:=LoadContact(DBBranch,section);
        end;

        ACT_SERVICE: begin
          StrCopy(p,opt_service);
          act.service:=DBReadString(0,DBBranch,section,nil);

          if (act.flags and (ACF_WCURRENT or ACF_WRESULT or ACF_WPARAM))=0 then
          begin
            StrCopy(p,opt_wparam);
            if (act.flags and ACF_WPARNUM)<>0 then
              act.wparam:=LoadNumValue(section,(act.flags2 and ACF2_SRV_WPAR)<>0)
            else if (act.flags and ACF_WSTRUCT)<>0 then
              act.wparam:=wparam(DBReadUTF8(0,DBBranch,section,nil))
            else if (act.flags and ACF_WUNICODE)<>0 then
              act.wparam:=wparam(DBReadUnicode(0,DBBranch,section,nil))
            else
              act.wparam:=wparam(DBReadString (0,DBBranch,section,nil));
          end;

          if (act.flags and (ACF_LCURRENT or ACF_LRESULT or ACF_LPARAM))=0 then
          begin
            StrCopy(p,opt_lparam);
            if (act.flags and ACF_LPARNUM)<>0 then
               act.lparam:=LoadNumValue(section,(act.flags2 and ACF2_SRV_LPAR)<>0)
  //              act.lparam:=DBReadDWord(0,DBBranch,section,0)
            else if (act.flags and ACF_LSTRUCT)<>0 then
              act.lparam:=lparam(DBReadUTF8(0,DBBranch,section,nil))
            else if (act.flags and ACF_LUNICODE)<>0 then
              act.lparam:=lparam(DBReadUnicode(0,DBBranch,section,nil))
            else
              act.lparam:=lparam(DBReadString(0,DBBranch,section,nil));
          end;

        end;

        ACT_PROGRAM: begin
          StrCopy(p,opt_prg ); act.prgname:=DBReadUnicode(0,DBBranch,section,nil);
          StrCopy(p,opt_args); act.args   :=DBReadUnicode(0,DBBranch,section,nil);
          StrCopy(p,opt_time); act.time   :=DBReadDWord  (0,DBBranch,section,0);
          StrCopy(p,opt_show); act.show   :=DBReadDWord  (0,DBBranch,section,SW_SHOW);
        end;

        ACT_TEXT: begin
          if (act.flags and ACF_CLIPBRD)=0 then
          begin
            StrCopy(p,opt_text); act.text:=DBReadUnicode(0,DBBranch,section,nil);
            if (act.flags and ACF_FILE)<>0 then
            begin
              StrCopy(p,opt_file); act.tfile:=DBReadUnicode(0,DBBranch,section,nil);
            end;
          end;
        end;

        ACT_ADVANCE: begin
          StrCopy(p,opt_cond   ); act.condition:=DBReadByte   (0,DBBranch,section);
          StrCopy(p,opt_value  ); act.value    :=DBReadDWord  (0,DBBranch,section);
          StrCopy(p,opt_action ); act.action   :=DBReadByte   (0,DBBranch,section);
          StrCopy(p,opt_oper   ); act.oper     :=DBReadByte   (0,DBBranch,section);
          StrCopy(p,opt_mathval); act.mathval  :=DBReadDWord  (0,DBBranch,section);
          StrCopy(p,opt_operval); act.operval  :=DBReadUnicode(0,DBBranch,section);
          StrCopy(p,opt_varval ); act.varval   :=DBReadUnicode(0,DBBranch,section);
        end;

        ACT_CHAIN: begin
          StrCopy(p,opt_text); act.id:=DBReadDWord(0,DBBranch,section);
        end;

        ACT_RW: begin
          if (act.flags and ACF_NOCNTCT)=0 then
          begin
            p^:=#0;
            act.dbcontact:=LoadContact(DBBranch,section);
          end;
          StrCopy(p,opt_module ); act.dbmodule :=DBReadString(0,DBBranch,section);
          StrCopy(p,opt_setting); act.dbsetting:=DBReadString(0,DBBranch,section);
          StrCopy(p,opt_value  );

          if (act.flags and ACF_DBUTEXT)=0 then
            act.dbvalue:=LoadNumValue(section,(act.flags2 and ACF2_RW_TVAR)<>0)
          else
            act.dbvalue:=uint_ptr(DBReadUnicode(0,DBBranch,section));
        end;

        ACT_MESSAGE: begin
          StrCopy(p,opt_msgtitle); act.msgtitle:=DBReadUnicode(0,DBBranch,section);
          StrCopy(p,opt_msgtext ); act.msgtext :=DBReadUnicode(0,DBBranch,section);
          StrCopy(p,opt_boxopts ); act.boxopts :=DBReadByte   (0,DBBranch,section);
        end;

      end;
      num:=NewAction(ActionList,MaxActions);
      move(act,ActionList^[num],SizeOf(tHKAction));
      if i=1 then
        result:=num
      else
        ActionList^[oldnum].next:=num;
      oldnum:=num;
    end;
  end;
end;

procedure LoadGroups;
var
  HK:pHKRecord;
  i,num:cardinal;
  p,p1:PAnsiChar;
  section:array [0..127] of AnsiChar;
  NumGroups,NumActions:cardinal;
begin
{ remove doubling - no need? (called just once)
  if MaxGroups>0 then
  begin
    while MaxGroups>0 do
    begin
      FreeGroup(MaxGroups);
      dec(MaxGroups);
    end;
    FreeMem(GroupList);
  end;
}  
  NumGroups:=DBReadWord(0,DBBranch,opt_numhk,HKListPage);
  if NumGroups<HKListPage then
    MaxGroups:=HKListPage
  else
    MaxGroups:=NumGroups;
  GetMem  (GroupList ,MaxGroups*SizeOf(tHKRecord));
  FillChar(GroupList^,MaxGroups*SizeOf(tHKRecord),0);

{ remove doubling - no need? (called just once)
  if MaxActions<>0 then
  begin
    act:=@ActionList[1];
    while MaxActions>0 do
    begin
      FreeAction(act);
      inc(act);
      dec(MaxActions);
    end;
    FreeMem(ActionList);
  end;
}
  NumActions:=DBReadWord(0,DBBranch,opt_numacts,ActListPage);
  if NumActions<ActListPage then
    MaxActions:=ActListPage
  else
    MaxActions:=NumActions+1;
  GetMem  (ActionList ,MaxActions*SizeOf(tHKAction));
  FillChar(ActionList^,MaxActions*SizeOf(tHKAction),0);

  HK:=@GroupList^; //??
  i:=0;
  p1:=StrCopyE(section,opt_group);
  while i<NumGroups do
  begin
    p:=StrEnd(IntToStr(p1,i));
    p^:='/'; inc(p);

    StrCopy(p,opt_flags);
    with HK^ do
    begin
      flags:=DBReadDWord(0,DBBranch,section,0{integer(ACF_ASSIGNED or ACF_DISABLED)});
      if (flags and ACF_ASSIGNED)<>0 then // not needed in normal cases
      begin
        StrCopy(p,opt_id   ); id   :=DBReadDWord  (0,DBBranch,section);
        StrCopy(p,opt_descr); descr:=DBReadUnicode(0,DBBranch,section,nil);
        if descr=nil then
          StrDupW(descr,TranslateW('No description'));

        StrCopy(p,opt_numacts); num:=DBReadWord(0,DBBranch,section);
        p^:=#0;
        firstAction:=LoadActions(section,num);
      end;
    end;
    inc(HK);
    inc(i);
  end;
  fCLfilter:=DBReadByte   (0,DBBranch,'CLfilter',0)<>0;
  fCLformat:=DBReadUnicode(0,DBBranch,'CLformat');
end;