summaryrefslogtreecommitdiff
path: root/plugins/QuickSearch/sr_global.pas
blob: 5110ef8de83d93a507445e191abf2b86d9c08335 (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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
unit sr_global;

interface
uses windows,messages,commctrl,m_api,dbsettings,mirutils;

const
  // for QS window only
  IDM_STAYONTOP = WM_USER+1;
  WM_MYADDCONTACT    = WM_USER+2;
  WM_MYDELETECONTACT = WM_USER+3;

  WM_MYSHOWHIDEITEM = WM_USER + 4;
  WM_MYMOVEITEM     = WM_USER + 5;
const
  wcUp      = 1;
  wcDown    = 2;
  wcHide    = 3;
  wcShow    = 4;
  wcDelete  = 5;
  wcInsert  = 6;
  wcChange  = 7;
  wcRefresh = 8;

const
  opened:boolean = false;
const
  QS_QS     :PAnsiChar = 'QS_QS';
  QS_NEW    :PAnsiChar = 'QS_New';
  QS_ITEM   :PAnsiChar = 'QS_Item';
  QS_UP     :PAnsiChar = 'QS_Up';
  QS_DOWN   :PAnsiChar = 'QS_Down';
  QS_DELETE :PAnsiChar = 'QS_Delete';
  QS_DEFAULT:PAnsiChar = 'QS_Default';
  QS_RELOAD :PAnsiChar = 'QS_Reload';
  QS_MALE   :PAnsiChar = 'QS_Male';
  QS_FEMALE :PAnsiChar = 'QS_Female';
const
  qs_module     :PAnsiChar = 'QuickSearch';
  qs_name       :PAnsiChar = 'Quick Search';
  QS_SHOWSERVICE:PAnsiChar = 'QuickSearch_PLUGIN/Show';

const
  StatusSort = 1000;

const
  ptNumber  = 0;
  ptInteger = 1;
  ptString  = 2;
  ptUnicode = 3;
  ptCurrent = 4;

const //types
  ST_BYTE        = 0;
  ST_WORD        = 1;
  ST_INT         = 2;
  ST_STRING      = 3;
  ST_IP          = 4;
  ST_LASTSEEN    = 5;
  ST_CONTACTINFO = 6;
  ST_LASTEVENT   = 7;
  ST_TIMESTAMP   = 8;
  ST_SERVICE     = 9;
  ST_SCRIPT      = 10;
  ST_METACONTACT = 11;

  ST_MAXTYPE     = 11;

const
  COL_ON      = $0001; // Show column
  COL_INIT    = $0002; // No need to update
  COL_XSTATUS = $0100;
  COL_GENDER  = $0200;
  COL_CLIENT  = $0400;

{$include resource.inc}

type
  tserviceparam = record
    case _type:word of
      0: (n:dword);
      1: (i:integer);
      2: (a:PAnsiChar);
      3: (w:PWideChar);
  end;
type
  tcolumnitem=record
    title          :PWideChar;
    module_name    :PAnsiChar;
    width          :dword;
    setting_type   :dword;     // ST_* constants
    setting_cnftype:dword;     // pt* constants
    wparam         :tserviceparam;
    lparam         :tserviceparam;
    flags          :dword;     // COL_* constants
  end;
  tcolumnarray = array of tcolumnitem;
  tqsopt=record
    grrect          :TRECT;
    columns         :tcolumnarray;//array of tcolumnitem;
    numcolumns      :integer;
    columnsort      :integer;
    ascendsort      :boolean;
    sortbystatus    :boolean;
    drawgrid        :boolean;
    showinmenu      :boolean;
    showonlyinlist  :boolean;
    showintoptoolbar:boolean;
    usetoolstyle    :boolean;
    closeafteraction:boolean;
    stayontop       :boolean;
    showoffline     :boolean;
    showclienticons :boolean;
    exportheaders   :boolean;
    singlecsv       :boolean;
    skipminimized   :boolean;
    savepattern     :boolean;
    colorize        :boolean;
  end;

procedure reghotkeys;
procedure unreghotkeys;

procedure saveopt_wnd;
procedure saveopt_db;
procedure loadopt_db(full:boolean);
procedure clear_columns;
function new_column(after:integer=-1):integer;
procedure delete_column(pos:integer);
procedure loaddefaultcolumns;

procedure AddRemoveMenuItemToMainMenu;
procedure addtotoolbar;
procedure removetoolbar;

var
  qsopt:tqsopt;

const
  MainMenuItem:integer=0;
  hTTBButton  :thandle=0;

implementation

uses common;

const
  HKN_GLOBAL:PAnsiChar = 'QS_Global';
const
  so_mbottom         :PAnsiChar = 'mbottom';
  so_mright          :PAnsiChar = 'mright';
  so_mtop            :PAnsiChar = 'mtop';
  so_mleft           :PAnsiChar = 'mleft';
  so_columnsort      :PAnsiChar = 'columnsort';
  so_sortbystatus    :PAnsiChar = 'sortbystatus';
  so_ascendsort      :PAnsiChar = 'ascendsort';
  so_showonlyinlist  :PAnsiChar = 'showonlyinlist';
  so_dontusetoolstyle:PAnsiChar = 'dontusetoolstyle';
  so_showinmenu      :PAnsiChar = 'showinmenu';
  so_showintoptoolbar:PAnsiChar = 'showintoptoolbar';
  so_closeafteraction:PAnsiChar = 'closeafteraction';
  so_exportheaders   :PAnsiChar = 'exportheaders';
  so_singlecsv       :PAnsiChar = 'singlecsv';
  so_savepattern     :PAnsiChar = 'savepattern';
  so_numcolumns      :PAnsiChar = 'numcolumns';
  so_item            :PAnsiChar = 'item';
  so_drawgrid        :PAnsiChar = 'drawgrid';
  so_stayontop       :PAnsiChar = 'stayontop';
  so_showclienticons :PAnsiChar = 'showclienticons';
  so_skipminimized   :PAnsiChar = 'skipminimized';
  so_showoffline     :PAnsiChar = 'showoffline';
  so_colorize        :PAnsiChar = 'colorize';

  so__title          :PAnsiChar = '_title';
  so__setting_type   :PAnsiChar = '_setting_type';
  so__setting_cnftype:PAnsiChar = '_setting_cnftype';
  so__module_name    :PAnsiChar = '_module_name';
  so__wparam_type    :PAnsiChar = '_wparam_type';
  so__lparam_type    :PAnsiChar = '_lparam_type';
  so__wparam         :PAnsiChar = '_wparam';
  so__lparam         :PAnsiChar = '_lparam';
  so__width          :PAnsiChar = '_width';
  so__flags          :PAnsiChar = '_flags';

procedure reghotkeys;
var
  hkrec:HOTKEYDESC;
begin
  FillChar(hkrec,SizeOf(hkrec),0);
  with hkrec do
  begin
    cbSize          :=HOTKEYDESC_SIZE_V1;
    pszName         :=HKN_GLOBAL;
    pszDescription.a:='QuickSearch window hotkey';
    pszSection.a    :=qs_name;
    pszService      :=QS_SHOWSERVICE;
    DefHotKey       :=(HOTKEYF_ALT shl 8) or VK_F3;
  end;
  CallService(MS_HOTKEY_REGISTER,0,lparam(@hkrec));
end;

procedure unreghotkeys;
begin
  CallService(MS_HOTKEY_UNREGISTER,0,lparam(HKN_GLOBAL));
end;

procedure removetoolbar;
begin
  if hTTBButton<>0 then
  begin
    if ServiceExists(MS_TTB_REMOVEBUTTON)>0 then
    begin
      CallService(MS_TTB_REMOVEBUTTON,WPARAM(hTTBButton),0);
      hTTBButton:=0;
    end;
  end;
end;

procedure addtotoolbar;
var
  ttbopt:TTBButton;
begin
  removetoolbar;

  if qsopt.showintoptoolbar then
  begin
    if ServiceExists(MS_TTB_ADDBUTTON)>0 then
    begin
      ZeroMemory(@ttbopt,sizeof(ttbopt));
      ttbopt.cbSize    :=sizeof(ttbopt);
      ttbopt.pszService:=QS_SHOWSERVICE;
      ttbopt.hIconUp   :=CallService(MS_SKIN2_GETICON,0,lparam(QS_QS));
      ttbopt.hIconDn   :=ttbopt.hIconUp;
      ttbopt.dwFlags   :=TTBBF_VISIBLE;
      ttbopt.name      :=qs_module;
      hTTBButton:=TopToolbar_AddButton(@ttbopt);
      if hTTBButton=THANDLE(-1) then
        hTTBButton:=0;
    end;
  end;
end;

procedure AddRemoveMenuItemToMainMenu;
var
  cmi:TCLISTMENUITEM;
begin
  if qsopt.showinmenu then
  begin
    if MainMenuItem<>0 then exit;
    ZeroMemory(@cmi,sizeof(cmi));
    cmi.cbSize      :=sizeof(cmi) ;
    cmi.szName.a    :=qs_name;
    cmi.position    :=500050000;
//    cmi.pszPopupName:=nil;
//    cmi.flags       :=0;
    cmi.pszService  :=QS_SHOWSERVICE;
    cmi.hIcon       :=CallService(MS_SKIN2_GETICON,0,lparam(QS_QS));
    MainMenuItem    :=Menu_AddMainMenuItem(@cmi);
  end
  else
  begin
    if (MainMenuItem<>0) and
       (ServiceExists(MS_CLIST_REMOVEMAINMENUITEM)<>0) then
    begin
      CallService(MS_CLIST_REMOVEMAINMENUITEM,MainMenuItem,0);
      MainMenuItem:=0;
    end;
  end;
end;

// -------- column functions ---------

procedure clear_column(num:integer);
begin
  with qsopt.columns[num] do
  begin
    mFreeMem(title);
    if setting_type<>ST_CONTACTINFO then
    begin
      mFreeMem(module_name);
      if setting_type<>ST_SERVICE then
        mFreeMem(wparam.a)
      else
      begin
        if (wparam._type=ptString) or (wparam._type=ptUnicode) then mFreeMem(wparam.a);
        if (lparam._type=ptString) or (lparam._type=ptUnicode) then mFreeMem(lparam.a);
      end;
    end;
  end;
end;

procedure clear_columns;
var
  i:integer;
begin
  for i:=0 to qsopt.numcolumns-1 do
    clear_column(i);
  FillChar(qsopt.columns[0],Length(qsopt.columns),0);
  qsopt.numcolumns:=0;
end;

procedure delete_column(pos:integer);
begin
  if (pos>=0) and (qsopt.numcolumns>0) then
  begin
    dec(qsopt.numcolumns);
    clear_column(pos);
    move(qsopt.columns[pos+1],qsopt.columns[pos],(qsopt.numcolumns-pos)*sizeof(tcolumnitem));
    SetLength(qsopt.columns,qsopt.numcolumns);
  end;
end;

function new_column(after:integer=-1):integer;
begin
  SetLength(qsopt.columns,qsopt.numcolumns+1);
  FillChar(qsopt.columns[qsopt.numcolumns],SizeOf(tcolumnitem),0);
  with qsopt.columns[qsopt.numcolumns] do
  begin
    StrDupW(title,'New column');
    width:=64;
    flags:=COL_ON;
  end;
  result:=qsopt.numcolumns;
  inc(qsopt.numcolumns);
end;

procedure MakeTitle(var title; name:pAnsiChar);
begin
  FastAnsiToWide(name,pWideChar(title));
end;

procedure loaddefaultcolumns;
begin
  clear_columns;
  qsopt.numcolumns:=15;
  SetLength(qsopt.columns    ,qsopt.numcolumns);
  FillChar(qsopt.columns[0],qsopt.numcolumns*SizeOf(tcolumnitem),0);

  // protocol
  with qsopt.columns[0] do
  begin
    MakeTitle(title,'Protocol');
    StrDup (module_name,MS_PROTO_GETCONTACTBASEPROTO);
    width          :=82;
    setting_type   :=ST_SERVICE;
    setting_cnftype:=ptString;
    wparam._type   :=ptCurrent;
    lparam._type   :=ptNumber;
    lparam.n       :=0;
    flags          :=COL_ON;
  end;

  with qsopt.columns[1] do
  begin
    MakeTitle(title,'Real Protocol');
    StrDup(module_name,'Protocol');
    StrDup(wparam.a   ,'p');
    width          :=82;
    setting_type   :=ST_STRING;
    flags          :=0;
  end;

  //gender
  with qsopt.columns[2] do
  begin
    MakeTitle(title,'Gender');
    width          :=20;
    setting_type   :=ST_CONTACTINFO;
    setting_cnftype:=CNF_GENDER;
    flags          :=COL_ON;
  end;

  //uin
  with qsopt.columns[3] do
  begin
    MakeTitle(title,'UserID');
    width          :=80;
    setting_type   :=ST_CONTACTINFO;
    setting_cnftype:=CNF_UNIQUEID;
    flags          :=COL_ON;
  end;

  //username(displayname)
  with qsopt.columns[4] do
  begin
    MakeTitle(title,'Nickname');
    StrDup(module_name,MS_CLIST_GETCONTACTDISPLAYNAME);
    width          :=76;
    setting_type   :=ST_SERVICE;
    setting_cnftype:=ptUnicode;
    wparam._type   :=ptCurrent;
    lparam._type   :=ptNumber;
    lparam.n       :=2; // 0 for ANSI
    flags          :=COL_ON;
  end;

  //firstname
  with qsopt.columns[5] do
  begin
    MakeTitle(title,'First name');
    width          :=68;
    setting_type   :=ST_CONTACTINFO;
    setting_cnftype:=CNF_FIRSTNAME;
    flags          :=COL_ON;
  end;

  //lastname
  with qsopt.columns[6] do
  begin
    MakeTitle(title,'Last name');
    width          :=66;
    setting_type   :=ST_CONTACTINFO;
    setting_cnftype:=CNF_LASTNAME;
    flags          :=COL_ON;
  end;

  //group
  with qsopt.columns[7] do
  begin
    MakeTitle(title,'Group');
    width          :=80;
    StrDup(module_name,'CList');
    StrDup(wparam.a   ,'Group');
    setting_type   :=ST_STRING;
    flags          :=COL_ON;
  end;

  //email
  with qsopt.columns[8] do
  begin
    MakeTitle(title,'E-mail');
    width          :=116;
    setting_type   :=ST_CONTACTINFO;
    setting_cnftype:=CNF_EMAIL;
    flags          :=COL_ON;
  end;

 //miranda version
  with qsopt.columns[9] do
  begin
    MakeTitle(title,'Client ID');
    StrDup(wparam.a,'MirVer');
    width       :=60;
    setting_type:=ST_STRING;
    flags       :=COL_ON;
  end;

 //IP version
  with qsopt.columns[10] do
  begin
    MakeTitle(title,'Ext IP');
    StrDup(module_name,'ICQ');
    StrDup(wparam.a   ,'IP');
    width       :=100;
    setting_type:=ST_IP;
    flags       :=0;
  end;

 //LastSeen
  with qsopt.columns[11] do
  begin
    MakeTitle(title,'LastSeen');
    StrDup(module_name,'SeenModule');
    width       :=116;
    setting_type:=ST_LASTSEEN;
    flags       :=0;
  end;

 //last event
  with qsopt.columns[12] do
  begin
    MakeTitle(title,'Last Event');
    width       :=100;
    setting_type:=ST_LASTEVENT;
    flags       :=0;
  end;

 //online since
  with qsopt.columns[13] do
  begin
    MakeTitle(title,'Online since');
    StrDup(module_name,'ICQ');
    StrDup(wparam.a   ,'LogonTS');
    width       :=100;
    setting_type:=ST_TIMESTAMP;
    flags       :=0;
  end;

 //metacontacts
  with qsopt.columns[14] do
  begin
    MakeTitle(title,'Metacontact');
    width       :=50;
    setting_type:=ST_METACONTACT;
    flags       :=0;
  end;
end;

// -------- save/load settings ---------

procedure WriteInt(setting:PAnsiChar;value:int);
begin
  DBWriteDword(0,qs_module,setting,value)
end;
procedure WriteWord(setting:PAnsiChar;value:word);
begin
  DBWriteWord(0,qs_module,setting,value)
end;
procedure WriteStr(setting:PAnsiChar;value:PAnsiChar);
begin
  DBWriteString(0,qs_module,setting,value)
end;
procedure WriteUnicode(setting:PAnsiChar;value:PWideChar);
begin
  DBWriteUnicode(0,qs_module,setting,value)
end;
procedure WriteBool(setting:PAnsiChar;value:bool);
begin
  DBWriteByte(0,qs_module,setting,ord(value))
end;

procedure saveopt_wnd;
var
  i:integer;
  buf:array [0..127] of AnsiChar;
  p,pp:PAnsiChar;
begin
  WriteInt (so_mbottom    ,qsopt.grrect.bottom);
  WriteInt (so_mright     ,qsopt.grrect.right);
  WriteInt (so_mtop       ,qsopt.grrect.top);
  WriteInt (so_mleft      ,qsopt.grrect.left);

  WriteBool(so_showoffline,qsopt.showoffline);
  WriteBool(so_colorize   ,qsopt.colorize);

  WriteInt (so_columnsort ,qsopt.columnsort);

  pp:=StrCopyE(buf,so_item);
  for i:=0 to qsopt.numcolumns-1 do
  begin
    p:=StrEnd(IntToStr(pp,i));
    with qsopt.columns[i] do
    begin
      StrCopy(p,so__flags); WriteInt (buf,flags);
      StrCopy(p,so__width); WriteWord(buf,width);
    end;
  end;
end;

{
  "fast" writing"
  order array - if column order only changed
  column flags - if checkboxes changed only
}
procedure saveopt_db;
var
  i:integer;
  buf:array [0..127] of AnsiChar;
  p,pp:PAnsiChar;
begin
  WriteWord(so_numcolumns      ,qsopt.numcolumns);

  WriteBool(so_sortbystatus    ,qsopt.sortbystatus);
  WriteBool(so_showinmenu      ,qsopt.showinmenu);
//  WriteInt (so_columnsort      ,qsopt.columnsort);
  WriteBool(so_ascendsort      ,qsopt.ascendsort);
  WriteBool(so_showonlyinlist  ,qsopt.showonlyinlist);

  WriteBool(so_showintoptoolbar,qsopt.showintoptoolbar);
  WriteBool(so_dontusetoolstyle,not qsopt.usetoolstyle);
  WriteBool(so_closeafteraction,qsopt.closeafteraction);
  WriteBool(so_drawgrid        ,qsopt.drawgrid);
  WriteBool(so_stayontop       ,qsopt.stayontop);
  WriteBool(so_showclienticons ,qsopt.showclienticons);
  WriteBool(so_exportheaders   ,qsopt.exportheaders);
  WriteBool(so_singlecsv       ,qsopt.singlecsv);
  WriteBool(so_skipminimized   ,qsopt.skipminimized);
  WriteBool(so_savepattern     ,qsopt.savepattern);

  pp:=StrCopyE(buf,so_item);
  for i:=0 to qsopt.numcolumns-1 do
  begin
    p:=StrEnd(IntToStr(pp,i));
    with qsopt.columns[i] do
    begin
      StrCopy(p,so__title);
      WriteUnicode(buf,title);
      case setting_type of
        ST_SCRIPT: begin
          StrCopy(p,so__wparam);
          WriteUnicode(buf,wparam.w);
        end;
        ST_CONTACTINFO: begin
          StrCopy(p,so__setting_cnftype); WriteWord(buf,setting_cnftype);
        end;
        ST_SERVICE: begin
          StrCopy(p,so__module_name    ); WriteStr (buf,module_name);
          StrCopy(p,so__setting_cnftype); WriteWord(buf,setting_cnftype);
          StrCopy(p,so__wparam_type    ); WriteWord(buf,wparam._type);
          StrCopy(p,so__lparam_type    ); WriteWord(buf,lparam._type);
          StrCopy(p,so__wparam);
          case wparam._type of
            ptNumber,
            ptInteger: WriteInt    (buf,wparam.n);
            ptString : WriteStr    (buf,wparam.a);
            ptUnicode: WriteUnicode(buf,wparam.w);
          end;
          StrCopy(p,so__lparam);
          case lparam._type of
            ptNumber,
            ptInteger: WriteInt    (buf,lparam.n);
            ptString : WriteStr    (buf,lparam.a);
            ptUnicode: WriteUnicode(buf,lparam.w);
          end;
        end;
      else
        StrCopy(p,so__module_name); WriteStr(buf,module_name);
        StrCopy(p,so__wparam     ); WriteStr(buf,wparam.a);
      end;
      StrCopy(p,so__setting_type); WriteWord(buf,setting_type);
      StrCopy(p,so__flags       ); WriteInt (buf,flags);
      StrCopy(p,so__width       ); WriteWord(buf,width);
    end;
  end;
end;

function GetInt(setting:PAnsiChar;default:integer):integer;
begin
  result:=DBReadDWord(0,qs_module,setting,default);
end;
function GetWord(setting:PAnsiChar;default:word):word;
begin
  result:=DBReadWord(0,qs_module,setting,default);
end;
function GetBool(setting:PAnsiChar;default:bool):bool;
begin
  result:=bool(DBReadByte(0,qs_module,setting,integer(default)));
end;
function GetStr(setting:PAnsiChar):PAnsiChar;
begin
  result:=DBReadString(0,qs_module,setting,nil);
end;
function GetUnicode(setting:PAnsiChar):PWideChar;
begin
  result:=DBReadUnicode(0,qs_module,setting,nil);
end;

{
  if "fast"writing enabled
  fill columns accordingly comumn order array
}
procedure loadopt_db(full:boolean);
var
  i:integer;
  buf:array [0..127] of AnsiChar;
  p,pp:PAnsiChar;
begin
  if full then
  begin
    zeromemory(@qsopt,sizeof(qsopt));

    qsopt.grrect.bottom:=GetInt(so_mbottom,240);
    qsopt.grrect.right :=GetInt(so_mright,550);
    qsopt.grrect.top   :=GetInt(so_mtop,0);
    qsopt.grrect.left  :=GetInt(so_mleft,0);

    qsopt.columnsort      :=GetInt (so_columnsort,StatusSort);
    qsopt.sortbystatus    :=GetBool(so_sortbystatus,true);
    qsopt.ascendsort      :=GetBool(so_ascendsort  ,true);

    qsopt.showonlyinlist  :=GetBool(so_showonlyinlist  ,false);
    qsopt.usetoolstyle    :=not GetBool(so_dontusetoolstyle,false);
    qsopt.showinmenu      :=GetBool(so_showinmenu      ,true);
    qsopt.showintoptoolbar:=GetBool(so_showintoptoolbar,true);
    qsopt.closeafteraction:=GetBool(so_closeafteraction,false);
    qsopt.drawgrid        :=GetBool(so_drawgrid        ,true);
    qsopt.stayontop       :=GetBool(so_stayontop       ,false);
    qsopt.singlecsv       :=GetBool(so_singlecsv       ,false);
    qsopt.exportheaders   :=GetBool(so_exportheaders   ,false);
    qsopt.showoffline     :=GetBool(so_showoffline     ,true);
    qsopt.skipminimized   :=GetBool(so_skipminimized   ,true);
    qsopt.savepattern     :=GetBool(so_savepattern     ,true);
    qsopt.colorize        :=GetBool(so_colorize        ,true);

    if ServiceExists(MS_FP_GETCLIENTICONW)<>0 then
      qsopt.showclienticons:=GetBool(so_showclienticons,true)
    else
      qsopt.showclienticons:=false;
  end
  else
    clear_columns;

  qsopt.numcolumns:=GetWord(so_numcolumns,0);
  if qsopt.numcolumns=0 then
  begin
    loaddefaultcolumns;
    saveopt_db;
  end
  else
  begin
    pp:=StrCopyE(buf,so_item);
    SetLength(qsopt.columns,qsopt.numcolumns);
    FillChar(qsopt.columns[0],SizeOf(tcolumnitem)*qsopt.numcolumns,0);
    for i:=0 to qsopt.numcolumns-1 do
    begin
      p:=StrEnd(IntToStr(pp,i));
      with qsopt.columns[i] do
      begin
        StrCopy(p,so__title);
        title:=GetUnicode(buf);
        StrCopy(p,so__setting_type); setting_type:=GetWord(buf,0);
        case setting_type of
          ST_SCRIPT: begin
            StrCopy(p,so__wparam);
            wparam.w:=GetUnicode(buf);
          end;
          ST_CONTACTINFO: begin
            StrCopy(p,so__setting_cnftype); setting_cnftype:=GetWord(buf,0);
          end;
          ST_SERVICE: begin
            StrCopy(p,so__setting_cnftype); setting_cnftype:=GetWord(buf,0);
            StrCopy(p,so__module_name); module_name :=GetStr(buf);
            StrCopy(p,so__wparam_type); wparam._type:=GetWord(buf,0);
            StrCopy(p,so__lparam_type); lparam._type:=GetWord(buf,0);
            StrCopy(p,so__wparam);
            case wparam._type of
              ptNumber,
              ptInteger: wparam.n:=GetInt(buf,0);
              ptString : wparam.a:=GetStr(buf);
              ptUnicode: wparam.w:=GetUnicode(buf);
            end;
            StrCopy(p,so__lparam);
            case lparam._type of
              ptNumber,
              ptInteger: lparam.n:=GetInt(buf,0);
              ptString : lparam.a:=GetStr(buf);
              ptUnicode: lparam.w:=GetUnicode(buf);
            end;
          end;
        else
          StrCopy(p,so__module_name); module_name:=GetStr(buf);
          StrCopy(p,so__wparam     ); wparam.a   :=GetStr(buf);
        end;
        StrCopy(p,so__width); width:=GetWord(buf,20);
        StrCopy(p,so__flags); flags:=GetInt (buf,COL_ON);
      end;
    end;
  end;
end;

end.