This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_history.cpp
2629 lines (2410 loc) · 90 KB
/
ui_history.cpp
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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Konnekt UI
Obs³uga historii.
*/
#include "stdafx.h"
#pragma hdrstop
#include <io.h>
#include <fstream>
#include <Richedit.h>
#include "include\func.h"
#include "include\simxml.h"
#include "include\dbtable.h"
#include "include\dtablebin.h"
#include "include\time64.h"
#include "ui_main.h"
#include "resource_ui.h"
#include "include\win_listview.h"
#include "ui_actions.h"
#include "ui_cntlist.h"
#include "ui_history.h"
#include "ui_msgcontrol.h"
CdtColDesc h_desc;
string historyDir;
#define HDT_DIR 0
#define HDT_DTB 1
#define HDT_QUEUE 2
#define HDT_SEARCH 3
#define HDT_ITEM 0x80
enum enReturn {
retFalse = 0 , retTrue = 1 , retCancel = 2
};
struct cHistHeader {
string id;
int width;
string name;
string fmt;
int index;
cHistHeader() {width=0;name="";index=-1;}
};
class cHist {
public:
int type;
string path; // sciezka do pliku
string dir;
string info;
string name;
int cnt; // spokrewniony kontakt
int listState; // stan elementu na liœcie...
unsigned int size; // rozmiar w b
unsigned subItems; // ilosc podelementow
unsigned __int64 sort; // wartosc wg. ktorej sortuje
int ico;
virtual void open() = 0; // wypisuje element
virtual void prepare() = 0; // otwiera element i wywo³uje open
virtual void select() {prepare();} // zaznacza element i wywo³uje prepare
virtual enReturn erase(){return retFalse;}; // usuwa element
virtual bool canErase(){return false;};
virtual enReturn save(ofstream & file , int type){return retFalse;}; // zapisuje element
virtual bool saveBefore() {return false;} // zanim wybierzemy plik... true przerwie zapisywanie...
const static char saveXML = 2;
const static char saveTXT = 1;
virtual bool canSave(){return false;};
virtual bool canSearch() {return true;}
virtual bool search() {return false;} // przeszukuje w g³¹b
virtual void compact(){};
virtual void listRepaint(); // odœwie¿a element na liœcie
virtual void listSetState(int newState);
virtual int listGetState();
virtual void listPushBack(); // wstawia na listê
virtual const CStdString getColumnString(const cHistHeader * col);
virtual int count() {return subItems;}
virtual class cHistDir * getParent() {return 0;}
cHist () {sort = 0; ico=0; cnt=-1;subItems=0;listState=0;size=0;}
};
class cHistHeaders {
public:
void load (const char * src); // wczytuje kolumny
int pos (string hdr);
vector <cHistHeader> hdrs;
};
typedef vector <cHistHeader>::iterator hdrs_it_t;
class cHistItem : public cHist {
public:
unsigned int pos; // pozycja (w bajtach) w pliku lub ID w Queue
unsigned int id;
string title;
string first_uid;
cTime64 date;
class cHistDir * parent;
cHistItem() {type = HDT_ITEM;}
virtual void open() {}
virtual void prepare();
virtual void remove() {}// Usuwa zaznaczone elementy
void select(); // zaznacza element i wywo³uje prepare
const CStdString getColumnString(const cHistHeader * col);
cHistDir * getParent() {return parent;}
};
class cHistItemDTB : public cHistItem {
public:
unsigned int limit;
bool wholeThread;
void open();
bool canErase() {return true;}
bool canSave() {return true;}
enReturn erase();
enReturn save(ofstream &file , int type);
cHistItemDTB() {limit = 0x7FFFFFFF; wholeThread = false;}
};
class cHistItemQueue : public cHistItem {
public:
void open();
bool canErase() {return true;}
enReturn erase();
};
class cHistDir : public cHist {
public:
HTREEITEM treeItem;
string when_empty;
string list;
vector <cHistItem*> items;
typedef vector <cHistItem*>::iterator items_it;
cHistHeaders * headers , * dirheaders;
bool headers_created;
bool searchDisabled;
cHistDir * parent;
int sortColumn; // kolumna wg. ktorej sortuje (od 1) . 0 - wg. sort
cHistDir(cHistDir * par) {sortColumn = 0; type = HDT_DIR;headers = dirheaders = 0;parent = par;headers_created=false; searchDisabled = false;}
~cHistDir();
void prepare(); // laduje naglowki
void open(); // otwiera katalog
virtual enReturn save(ofstream &file , int type);
int count() {return items.size();}
virtual void fill();
int itemsClear();
bool search();
bool canErase() {return false;}
bool canSave() {return true;}
bool canSearch() {return !searchDisabled;}
virtual void msgInsert(cMessage * m , const char * display , bool scroll); // dodaje wiadomoϾ do okna ...
void select(); // zaznacza element i wywo³uje prepare
cHistDir * getParent() {return parent;}
};
typedef cHistDir::items_it items_it_t;
class cHistDirDTB : public cHistDir {
public:
cHistDirDTB(cHistDir * par):cHistDir(par) {type = HDT_DTB;parent = par;}
void open();
enReturn erase();
bool canErase() {return 1;}
void compact();
bool search();
};
class cHistDirQueue : public cHistDir {
public:
int net , type , flag , noflag;
cHistDirQueue(cHistDir * par):cHistDir(par) {type = HDT_QUEUE;parent = par;}
void open();
int count();
int checkMsg(int pos);
enReturn erase();
bool search();
bool canSave() {return false;}
};
struct cHistSearchOptions {
CStdString query;
bool useCase;
bool words;
bool findAll;
bool onlyCurrent;
bool regexp;
signed int threadPrev; // ile wczeœniejszych -1 - ca³oœæ
signed int threadNext; // ile póŸniejszych. -1 - ca³oœæ
__time64_t timeFrom, timeTo;
void GetFromDialog(HWND wnd);
void SetInDialog(HWND wnd);
void SetHistoryWindow(HWND wnd);
cHistDir * currentOpen;
CStdString GetName();
CStdString GetInfo();
void Load(cXML & xml);
bool const operator == (const cHistSearchOptions & b) {
return query == b.query && useCase == b.useCase
&& words == b.words /*&& findAll == b.findAll*/
&& onlyCurrent == b.onlyCurrent && regexp == b.regexp
&& (!currentOpen || !b.currentOpen || currentOpen == b.currentOpen)
&& timeFrom == b.timeFrom && timeTo == b.timeTo
/*&& threadPrev == b.threadPrev && threadNext == b.threadNext*/
;
}
cHistSearchOptions() {currentOpen = 0; }
};
class cHistDirSearch : public cHistDir {
public:
cHistSearchOptions opt;
cPreg preg; // wzorzec do u¿ycia podczas wyœwietlania
cHistDirSearch(cHistDir * par , cHistSearchOptions & opt):cHistDir(par),opt(opt),preg(0) {type = HDT_SEARCH;parent = par;}
void open();
enReturn erase(); // tylko zapytania
bool saveBefore();
/* TODO: zapisywanie zapytañ */
bool canSearch() {return false;}
bool canErase() {return true;}
void addFoundItem(cHistItem * item); /* Dodaje do wyników szukania... */
void msgInsert(cMessage * m , const char * display , bool scroll);
};
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
struct hist_s{
HIMAGELIST iml;
class cHist * selected;
class cHistDir * dir_opened;
class cHistItem * item_opened;
class cHistHeaders * headers; // aktualne naglowki
int selectedList;
bool DTopened;
CdTable DT;
CdtFileBin DTfb;
bool DTtemp;
struct search_s {
class cHistDirSearch * foundDir; // katalog znalezionych
bool inProgress; // czy wyszukiwanie idzie...
enum eState{
stReady , stPreparing , stSearch , stCancel
} state;
bool canGetNext; // czy wyszukiwanie idzie...
cPreg preg; // preg ze wzorcem do znalezienia
cHistSearchOptions opt;
void Show();
void Reset();
void ResetMRU();
void Start();
void Next(); // do nastêpnego wyniku
void Stop();
bool IsActive() {return inProgress && foundDir;}
static LRESULT WndProc(HWND wnd , int message , WPARAM wParam , LPARAM lParam);
HWND wnd;
HWND prgrsWnd;
search_s () {
state = stReady;
}
} search;
void changeDT(const char * file , bool useTemp = true);
HWND statusWnd , prgrsWnd , tbWnd , listWnd , hwnd;
cMsgControl * msgControl;
bool running;
vector <class cHistDir*> dirs;
typedef vector <cHistDir*>::iterator dirs_it;
vector <class cHist*> itemsOnList; // elementy aktualnie na liœcie
typedef vector <class cHist*>::iterator itemsOnList_it; // elementy aktualnie na liœcie
void GetDispInfo(NMLVDISPINFO * disp);
void SetDispInfo(NMLVDISPINFO * disp);
void ODStateChanged(NMLVODSTATECHANGE * state);
void SetStatus(const char * status);
void start(int cnt=0);
void end();
void checkErase();
void checkSave();
void compact();
void eraseSelected();
void saveSelected();
void printSelected();
void listPrepare(cHistHeaders * headers);
void dialogFill(HWND hwnd);
void removeFromDirs(cHistDir * dir);
// int sortColumn;
void sort() {listSort();}
void listSort();
void init();
void refresh(bool all = false);
void shred();
enReturn erase(cHist * item);
enReturn save(ofstream & file , cHist * item , int type);
void listSynchronize();
void listClear();
void resetOpenedItem();
hist_s();
};
hist_s hist;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
int hist_add (cMessage * m , const char * dir , sUICnt * cnt , const char * name = 0 , int session = 0 ) {
if (!cnt && (!dir || !dir[0])) return 0;
if (!GETINT(CFG_LOGHISTORY)) return 0;
string path = profileDir + "history\\";
// IMLOG("HIST %s ... %s" , profileDir.c_str() , path.c_str());
path += dir;
mkdirs((char*)path.c_str());
path += "\\";
string fn;
if (name) fn = name;
if (cnt) {
if (*GETCNTC(cnt->ID , CNT_UID)) fn="u"+GETCNTS(cnt->ID , CNT_UID);
else if (*GETCNTC(cnt->ID , CNT_CELLPHONE)) fn="p"+GETCNTS(cnt->ID , CNT_CELLPHONE);
else if (*GETCNTC(cnt->ID , CNT_EMAIL)) fn="e"+GETCNTS(cnt->ID , CNT_EMAIL);
else if (*GETCNTC(cnt->ID , CNT_DISPLAY)) fn="d"+GETCNTS(cnt->ID , CNT_DISPLAY);
else fn="_inne";
}
fn = urlEncode(fn , '#');
if (cnt) { // dodajemy jeszcze sieæ...
fn+=".";
fn+=inttoch(cnt->net);
}
fn+=".dtb";
// fn = Preg.replace("/[^a-z0-9¹æê³ñ󜿟¥ÆÊ£ÑÓŒ¯ _.-]+/ig" , "_" , fn.c_str());
CdTable Msg;
Msg.cxor_key = HIST_XOR_KEY;
Msg.cols = h_desc;
CdtFileBin fb;
fb.assign(&Msg);
Msg.addrow();
Msg.setint(0 , MSG_ID , m->id);
Msg.setint(0 , MSG_NET , m->net);
Msg.setint(0 , MSG_TYPE , m->type);
Msg.setch(0 , MSG_FROMUID , m->fromUid);
Msg.setch(0 , MSG_TOUID , m->toUid);
Msg.setch(0 , MSG_BODY , m->body);
Msg.setch(0 , MSG_EXT , m->ext);
Msg.setint(0 , MSG_FLAG , m->flag);
Msg.set64(0 , MSG_TIME , m->time);
Msg.setint(0 , MSGH_SESSION , session);
if (!*m->fromUid)
Msg.setch(0 , MSGH_DISPLAY , GETCNTC(0,CNT_DISPLAY));
else
{
int p = ICMessage(IMC_CNT_FIND , m->net , (int)m->fromUid);
Msg.setch(0 , MSGH_DISPLAY , (p>0)?GETCNTC(p,CNT_DISPLAY) : "");
}
fb.append((path + fn).c_str());
return 1;
}
int cHistHeaders::pos (string hdr) {
for (hdrs_it_t hdrs_it=hdrs.begin() ; hdrs_it != hdrs.end(); hdrs_it++)
if (hdrs_it->id == hdr) return hdrs_it->index;
return -1;
}
// **************************************************
void cHist::listRepaint(){
hist_s::itemsOnList_it it = std::find(hist.itemsOnList.begin() , hist.itemsOnList.end() , this);
if (it == hist.itemsOnList.end()) return;
int i = it - hist.itemsOnList.begin();
ListView_RedrawItems(hist.listWnd , i , i);
}
void cHist::listSetState(int newState) {
listState = newState;
}
int cHist::listGetState() {
return listState;
}
void cHist::listPushBack() {
this->listState = 0;
hist.itemsOnList.push_back(this);
}
const CStdString cHist::getColumnString(const cHistHeader * col) {
static char buff [10];
if (col->id == "info")
return this->info.empty() ? this->name : this->info;
else if (col->id == "name" || col->id == "contact")
return this->name;
else if (col->id == "count")
return itoa(this->count() , buff , 10);
else if (col->id == "parent")
return this->getParent() ? this->getParent()->name : "-";
else if (col->id == "size") {
_snprintf(buff , 10 , "%.0fKB" , (float)this->size / 1024);
return buff;
}
else return "???";
}
// --------------------------- DIR
int cHistDir::itemsClear() {
if (!items.size()) return 0;
for (items_it_t items_it = items.begin(); items_it!=items.end(); items_it++)
delete *items_it;
items.clear();
if (hist.dir_opened == this) {
hist.listClear();
}
return 1;
}
cHistDir::~cHistDir() {
if (headers && headers_created) {delete headers;headers=0;}
if (dirheaders) {delete dirheaders;}
itemsClear();
}
void cHistHeaders::load (const char * src){
cPreg Preg;
while (src) {
Preg.match("/< *([^ >/]+)[^>]*>/i" , src);
if (!Preg.matched) {break;}
src += Preg[0].size();
if (Preg[1]!="") {
cHistHeader hh;
hh.id = Preg[1];
string attr = Preg[0];
Preg.match("/width *= *\"(\\d+)\"/i" , attr.c_str());
hh.width = max(16 , Preg.matched?chtoint(Preg[1].c_str()):0);
Preg.match("/name *= *\"(.+?)\"/i" , attr.c_str());
hh.name = !Preg.matched?hh.id:Preg[1];
Preg.match("/format *= *\"(.+?)\"/i" , attr.c_str());
hh.fmt = !Preg.matched?string(""):Preg[1];
hdrs.push_back(hh);
}
src = strchr(src , '<');
}
}
enReturn cHistDir::save(ofstream &file , int type) {
if (type==saveXML) {
file << " <" << (this->cnt > 0 ? "contact" : "dir") << " name=\"" << EncodeEntities(this->name) << "\" info=\"" << EncodeEntities(this->info) << "\">" << endl;
} else if (type==saveTXT) {
file << "**********************************************************************" << endl;
file << "* " << this->name.c_str() << endl;
}
enReturn ret = retTrue;
for (hist_s::dirs_it it=hist.dirs.begin(); it != hist.dirs.end(); it++) {
if ((*it)->parent == this) {
if ((ret = (*it)->save(file , abs(type))) == retCancel)
break;
}
}
if (ret != retCancel) {
ret = retTrue;
for (unsigned int i=0; i<this->items.size(); i++) {
if (this->items[i]->save(file , abs(type)) == retCancel) break;
}
}
if (type==saveXML) {
file << " </"<< (this->cnt > 0 ? "contact" : "dir") << ">" << endl;
}
return ret;
}
void cHistDir::select() {
if (hist.dir_opened == this) return;
TreeView_SelectItem(GetDlgItem(hwndHistory , IDC_TREE) , treeItem);
cHist::select();
}
void cHistDir::prepare() {
if (hist.dir_opened == this) return;
hist.dir_opened = this;
hist.listPrepare(headers);
open();
}
void cHistDir::open() {
if (!headers) return;
// Wyswietla wszystkie podkatalogi
HWND titem = GetDlgItem(hwndHistory , IDC_TREE);
if (list=="ALL") {
HTREEITEM it = TreeView_GetChild(titem , treeItem);
SendMessage(hist.prgrsWnd , PBM_SETRANGE , 0 , MAKELPARAM(0 , subItems));
SendMessage(hist.prgrsWnd , PBM_SETPOS , 0 , 0);
while (it) {
TVITEMEX ti;
ti.mask = TVIF_PARAM;
ti.hItem = it;
TreeView_GetItem(titem , &ti);
((cHist*)ti.lParam)->open();
it = TreeView_GetNextSibling(titem , it);
SendMessage(hist.prgrsWnd , PBM_STEPIT , 0 , 0);
}
SendMessage(hist.prgrsWnd , PBM_SETPOS , 0 , 0);
// PLIKI
} else if (list=="FILES") {
/* HTREEITEM it = TreeView_GetChild(titem , treeItem);
while (it) {
TVITEMEX ti;
ti.mask = TVIF_PARAM | TVIF_IMAGE;
ti.hItem = it;
TreeView_GetItem(titem , &ti);
LVITEM lvi;
lvi.mask = LVIF_IMAGE | LVIF_PARAM;
lvi.iItem=0;
lvi.iSubItem=0;
lvi.lParam=ti.lParam;
lvi.iImage=ti.iImage;
int pos = ListView_InsertItem(item, &lvi);
lvi.mask = LVIF_TEXT;
cHistDir * param = (cHistDir*)ti.lParam;
lvi.pszText=(char*)(param->info.empty()?param->name.c_str():param->info.c_str());
lvi.iItem=pos;
lvi.iSubItem=hist.headers->pos("info");
if (lvi.iSubItem>=0) ListView_SetItem(item, &lvi);
lvi.pszText=(char*)inttoch(((cHistDir*)ti.lParam)->count());
lvi.iItem=pos;
lvi.iSubItem=hist.headers->pos("count");
if (lvi.iSubItem>=0) ListView_SetItem(item, &lvi);
it = TreeView_GetNextSibling(titem , it);
}*/
for (hist_s::dirs_it it = hist.dirs.begin(); it != hist.dirs.end(); it++) {
if ((*it)->parent == this)
(*it)->listPushBack();
}
}
hist.sort();
}
void cHistDir::fill() {
//Wypelnia liste ...
if (!hist.headers) return;
/*
HWND item = GetDlgItem(hwndHistory , IDC_LIST);
LVITEM lvi;
for (items_it_t items_it = items.begin(); items_it!=items.end(); items_it++) {
cHistItem * hi = *items_it;
lvi.iImage=Ico[hi->ico].index[0];
lvi.mask = LVIF_IMAGE | LVIF_PARAM;
lvi.iItem=0;
lvi.iSubItem=0;
lvi.lParam=(LPARAM)(*items_it);
int pos = ListView_InsertItem(item, &lvi);
//IMERROR();
lvi.mask = LVIF_TEXT;
lvi.iItem=pos;
lvi.pszText=(char*)hi->name.c_str();
lvi.iSubItem=hist.headers->pos("contact");
if (lvi.iSubItem>=0) ListView_SetItem(item, &lvi);
lvi.pszText=(char*)hi->first_uid.c_str();
lvi.iSubItem=hist.headers->pos("first_uid");
if (lvi.iSubItem>=0) ListView_SetItem(item, &lvi);
lvi.pszText=(char*)hi->title.c_str();
lvi.iSubItem=hist.headers->pos("title");
if (lvi.iSubItem>=0) ListView_SetItem(item, &lvi);
lvi.pszText=(char*)hi->parent->name.c_str();
lvi.iSubItem=hist.headers->pos("parent");
if (lvi.iSubItem>=0) ListView_SetItem(item, &lvi);
int hpos = hist.headers->pos("date");
if (hpos>=0) {
string s=(char*)hi->date.strftime(
(hist.headers->hdrs[hpos].fmt==""?"%H:%M %d %b'%y %A"
:(char*)hist.headers->hdrs[hpos].fmt.c_str())).c_str();
lvi.pszText = (char*)s.c_str();
lvi.iSubItem=hpos;
ListView_SetItem(item, &lvi);
}
lvi.pszText=(char*)inttoch(hi->subItems+1);
lvi.iSubItem=hist.headers->pos("count");
if (lvi.iSubItem>=0) ListView_SetItem(item, &lvi);
}
*/
// kopiujemy po prostu listê elementów, to tablicy aktualnie wyœwietlanych
// hist.itemsOnList.clear();
for (items_it it = items.begin(); it != items.end(); it++)
(*it)->listPushBack();
hist.listSynchronize();
hist.sort();
}
bool cHistDir::search() {
if (!canSearch()) return false;
for (items_it_t it = items.begin(); it != items.end(); it++) {
if (!hist.search.IsActive()) return false;
(*it)->search();
}
return false;
}
void cHistDir::msgInsert(cMessage * m , const char * display , bool scroll) {
hist.msgControl->msgInsert(m , display , scroll);
}
enReturn cHistDirDTB::erase() {
IMLOG("* ERASE %s" , path.c_str());
return unlink(path.c_str()) ? retFalse : retTrue;
}
void cHistDirDTB::compact() {
CdTable Msg;
Msg.cxor_key = HIST_XOR_KEY;
Msg.cols = h_desc;
CdtFileBin fb;
fb.assign(&Msg);
IMLOG("- > Wczytujê %s" , path.c_str());
fb.load(path.c_str());
IMLOG("- > Zapisujê...");
fb.save(path.c_str());
}
void cHistDirDTB::open() {
// if (hist_dir_opened == this) return;
// MessageBox(0 , "DTB" , "" , 0);
if (!items.size()) {
// Wczytuje dane do tablicy items'ow
CdTable Msg;
Msg.cxor_key = HIST_XOR_KEY;
Msg.cols = h_desc;
CdtFileBin fb;
fb.assign(&Msg);
if (fb.open(path.c_str() , DT_READ)) return;
if (fb.freaddesc()) return;
Msg.cols = fb.fcols;
fb.freadsize();
fb.fset(fb.pos_row , SEEK_SET);
Msg.addrow();
cHistItemDTB * lastHi = 0;
int readColumns [] = {MSGH_SESSION , 0};
SendMessage(hist.prgrsWnd , PBM_SETRANGE32 , 0 , this->size);
SendMessage(hist.prgrsWnd , PBM_SETPOS , 0 , 0);
hist.SetStatus("Wczytujê plik...");
while (1) {
// LARGE_INTEGER tick , tick1 , tick2;
// QueryPerformanceCounter(&tick);
if (fb.freadpartialrow(0 , readColumns)) {
if (!fb.ffindnextrow())
continue; // mijamy...
else
break; // definitywnie koniec
}
// QueryPerformanceCounter(&tick1);
// tick1.QuadPart = tick1.QuadPart - tick.QuadPart;
if (Msg.getint(0 , MSGH_SESSION) && lastHi) {
lastHi->subItems++;
} else {
// Wczytaliœmy CZÊŒCIOWO! Trzeba wróciæ i wczytaæ porz¹dnie
fb.fset(Msg.rows[0]->pos , SEEK_SET);
SendMessage(hist.prgrsWnd , PBM_SETPOS , Msg.rows[0]->pos , 0);
// QueryPerformanceCounter(&tick);
if (fb.freadrow(0) != 0)
break; // to ju¿ jakiœ tragiczny b³¹d, raz czyta, raz nie
// QueryPerformanceCounter(&tick2);
// tick2.QuadPart = tick2.QuadPart - tick.QuadPart;
// IMLOG("TICK: %2.2f , %08I64d , %08I64d" , (float)(tick1.LowPart+1)/(float)(tick2.LowPart+1) , tick1.QuadPart , tick2.QuadPart);
cHistItemDTB * hi = new cHistItemDTB;
hi->parent = this;
hi->wholeThread = true; // optymistycznie, ale raczej prawda...
hi->pos = Msg.rows[0]->pos;
hi->id = DT_MASKID(Msg.rows[0]->id);
hi->subItems = 1;
hi->dir = dir;
hi->path = path;
hi->name = name;
hi->first_uid = Msg.getint(0,MSG_FLAG)&MF_SEND?Msg.getch(0 , MSG_TOUID):Msg.getch(0 , MSG_FROMUID);
hi->title = GetExtParam(Msg.getch(0 , MSG_EXT) , MEX_TITLE);
if (hi->title.empty()) {
string body = Msg.getch(0 , MSG_BODY);
if (Msg.getint(0 , MSG_FLAG) & MF_HTML) {
cPreg preg(false);
body = preg.replace("/<.+?>/" , "" , body.c_str());
body = DecodeEntities(body.c_str());
}
hi->title = body.substr(0 , 50);
}
hi->ico = UIIcon(IT_MESSAGE , Msg.getint(0,MSG_NET) , Msg.getint(0,MSG_TYPE) , 0);
if (!Ico.find(hi->ico)) hi->ico = UIIcon(IT_MESSAGE , 0 , Msg.getint(0,MSG_TYPE) , 0);
unsigned int i;
for (i=0; i<hi->title.size(); i++) {
if ((unsigned char)hi->title[i] < 31) {hi->title.erase(i);break;}
}
if (i>=49) hi->title+="...";
cTime64 t64(Msg.get64(0 , MSG_TIME));
hi->sort = __int64(t64) & 0xFFFFFFFFFFFF;
hi->date = t64;
items.push_back(hi);
lastHi = hi;
}
}
fb.close();
}
SendMessage(hist.prgrsWnd , PBM_SETPOS , 0 , 0);
hist.SetStatus(0);
fill();
}
bool cHistDirDTB::search() {
if (!canSearch() || !hist.search.IsActive()) return false;
CdTable Msg;
Msg.cxor_key = HIST_XOR_KEY;
Msg.cols = h_desc;
CdtFileBin fb;
fb.assign(&Msg);
if (fb.open(path.c_str() , DT_READ)) return false;
if (fb.freaddesc()) return false;
Msg.cols = fb.fcols;
fb.freadsize();
fb.fset(fb.pos_row , SEEK_SET);
Msg.addrow();
int readColumns [] = {MSGH_SESSION , 0};
int progress = SendMessage(hist.search.prgrsWnd , PBM_GETPOS , 0 , 0);
bool alreadyRead = false;
while (hist.search.IsActive()) {
// Ka¿da taka pêtla, to jeden ca³y w¹tek (znaleziony, lub nie)
if (!alreadyRead) {
if (fb.freadrow(0) != 0)
break; // nie ma wiêcej w¹tków
} else
alreadyRead = false;
size_t startPos = Msg.rows[0]->pos; // zapamiêtujemy pozycjê pierwszego w w¹tku...
vector <size_t> positions; // pozycje kolejnych wiadomoœci
cHistItemDTB * found;
unsigned int inThread = 0;
bool nextMatch = false; // czy skakaæ do nastêpnego szukania
bool threadBeginner = Msg.getint(0 , MSGH_SESSION) == 0; // czy zaczêliœmy prawid³owo w¹tek...
do {
inThread ++;
if (hist.search.opt.threadPrev > 0) // œledzimy poprzedzaj¹ce
positions.push_back(Msg.rows[0]->pos);
if (hist.search.opt.query.empty() == false)
hist.search.preg.setSubject(Msg.getch(0 , MSG_BODY));
__time64_t msgTime = 0;
if (hist.search.opt.timeFrom || hist.search.opt.timeTo) {
msgTime = cTime64(Msg.get64(0 , MSG_TIME));
}
if ((!hist.search.opt.timeFrom || hist.search.opt.timeFrom <= msgTime)
&& (!hist.search.opt.timeTo || hist.search.opt.timeTo >= msgTime)
&& (hist.search.opt.query.empty() || hist.search.preg.match() > 0)
) {
// skoro siê znalaz³ tworzymy item'a
found = new cHistItemDTB();
found->parent = hist.search.foundDir;
found->cnt = this->cnt;
found->date = Msg.get64(0 , MSG_TIME);
found->id = DT_MASKID(Msg.rows[0]->id);
found->dir = this->dir;
found->path = this->path;
found->name = this->name;
found->first_uid = Msg.getint(0,MSG_FLAG)&MF_SEND?Msg.getch(0 , MSG_TOUID):Msg.getch(0 , MSG_FROMUID);
found->ico = UIIcon(IT_MESSAGE , Msg.getint(0,MSG_NET) , Msg.getint(0,MSG_TYPE) , 0);
if (!Ico.find(found->ico)) found->ico = UIIcon(IT_MESSAGE , 0 , Msg.getint(0,MSG_TYPE) , 0);
if (hist.search.opt.query.empty()) {
found->title = CStdString(Msg.getch(0 , MSG_BODY)).substr(0 , 50);
} else {
found->title = hist.search.preg.getSubjectRef().substr(hist.search.preg.getVector(0) , 50);
}
unsigned int i;
for (i=0; i<found->title.size(); i++) {
if ((unsigned char)found->title[i] < 31) {found->title[i] = ' ';}
}
if (i>=49) found->title+="...";
cTime64 t64(Msg.get64(0 , MSG_TIME));
found->sort = __int64(t64) & 0xFFFFFFFFFFFF;
found->date = t64;
// Gdy zaliczamy WSZYSTKIE wczeœniejsze
if (hist.search.opt.threadPrev < 0) {
found->subItems = inThread;
found->pos = startPos;
} else if (hist.search.opt.threadPrev == 0) {
// Zaliczamy OD znalezionego
found->subItems = 1;
found->pos = Msg.rows[0]->pos;
} else {
// i inne sytuacje...
found->subItems = min(hist.search.opt.threadPrev + 1 , (signed)positions.size());
found->pos = positions[(positions.size() - 1) - (found->subItems - 1)];
}
// Je¿eli zaliczonych, jest mniej ni¿ w w¹tku - to wiadomo - nie jest od pocz¹tku
if (found->subItems < inThread - 1)
threadBeginner = false;
// Ustalamy limit
found->limit = hist.search.opt.threadNext < 0 ? -1 : found->subItems + hist.search.opt.threadNext;
// na szybko przelatujemy iloœæ zaliczanych póŸniejszych...
while (found->subItems < found->limit
&& fb.freadpartialrow(0 , readColumns) == 0)
{
if (Msg.getint(0 , MSGH_SESSION) == 0) {
// to ju¿ nastêpny w¹tek... zostawiamy go nowej pêtli, wiêc trzeba cofn¹æ do czytania
fb.fset(Msg.rows[0]->pos , SEEK_SET);
// Je¿eli pierwszy zaliczony, to pierwszy w w¹tku, znaczy ¿e dojechaliœmy do koñca w¹tku i mamy ca³y
if (threadBeginner)
found->wholeThread = true;
break;
}
found->subItems ++;
}
// dodajemy do listy znalezionych... mo¿emy sobie poczekaæ...
hist.search.foundDir->addFoundItem(found);
nextMatch = true;
} // match
SendMessage(hist.search.prgrsWnd , PBM_SETPOS , progress + Msg.rows[0]->pos , 0);
Ctrl->WMProcess();
if (nextMatch || fb.freadrow(0) != 0)
break;
if (Msg.getint(0 , MSGH_SESSION) == 0) {
alreadyRead = true;
break;
}
} while (hist.search.IsActive()); // czytamy kolejne wiadomoœci
}
fb.close();
return true;
}
void cHistDirQueue::open() {
// if (items.size()) {fill();return;}
itemsClear();
int c = Ctrl->DTgetCount(DTMSG);
for (int i=0; i < c; i++) {
int id = Ctrl->DTgetID(DTMSG , i);
if (checkMsg(id)) {
cHistItemQueue * hi = new cHistItemQueue;
hi->parent = this;
hi->pos = id;
hi->subItems = 0;
hi->dir = dir;
hi->path = path;
char * uid = (*Ctrl->DTgetStr(DTMSG , id , MSG_FROMUID))?Ctrl->DTgetStr(DTMSG , id , MSG_FROMUID):Ctrl->DTgetStr(DTMSG , id , MSG_TOUID);
cnt = ICMessage(IMC_CNT_FIND , Ctrl->DTgetInt(DTMSG , id , MSG_NET)
, (int)uid);
hi->name = cnt!=DT_NOROW?GETCNTC(cnt , CNT_DISPLAY):SAFECHAR(uid);
cnt = Ctrl->DTgetID(DTCNT , cnt);
hi->title = string(Ctrl->DTgetStr(DTMSG , id , MSG_BODY)).substr(0 , 50);
hi->ico = UIIcon(IT_LOGO , Ctrl->DTgetInt(DTMSG , id , MSG_NET) , 0, 0);
unsigned int j;
for (j=0; j<hi->title.size(); j++) {
if ((unsigned char)hi->title[j] < 31) {hi->title.erase(j);}
}
if (j>=49) hi->title+="...";
cTime64 t64;
hi->sort = Ctrl->DTgetInt64(DTMSG , id , MSG_TIME);
t64 = (__int64)hi->sort;
hi->date = t64;
items.push_back(hi);
}
}
fill();
}
int cHistDirQueue::checkMsg(int pos) {
int mflg = Ctrl->DTgetInt(DTMSG , pos , MSG_FLAG);
int mnet = Ctrl->DTgetInt(DTMSG , pos , MSG_NET);
int mtype = Ctrl->DTgetInt(DTMSG , pos , MSG_TYPE);
if (
(!net || (net == Ctrl->DTgetInt(DTMSG , pos , MSG_NET)))
&&
(!type || (type == Ctrl->DTgetInt(DTMSG , pos , MSG_TYPE)))
&&
(!flag || flag==-1 || (mflg & flag))
&&
(!(mflg & noflag))
)
return 1;
return 0;
}
enReturn cHistDirQueue::erase() {
for (unsigned int i=0; i<this->items.size(); i++) {
if (this->items[i]->erase() == retCancel) return retCancel;
}
return retFalse;
}
int cHistDirQueue::count() {
int c = Ctrl->DTgetCount(DTMSG);
int cnt = 0;
for (int i=0; i < c; i++) {
if (checkMsg(i)) cnt++;
}
return cnt;
}
bool cHistDirQueue::search() {
if (!canSearch()) return false;
int c = Ctrl->DTgetCount(DTMSG);
for (int i=0; i < c; i++) {
if (!hist.search.IsActive())
return true;
int id = Ctrl->DTgetID(DTMSG , i);
if (checkMsg(id)) {
if (hist.search.opt.query.empty() == false)
hist.search.preg.setSubject(Ctrl->DTgetStr(DTMSG , id , MSG_BODY));
if ((!hist.search.opt.timeFrom || hist.search.opt.timeFrom <= Ctrl->DTgetInt64(DTMSG , id , MSG_TIME))
&& (!hist.search.opt.timeTo || hist.search.opt.timeTo >= Ctrl->DTgetInt64(DTMSG , id , MSG_TIME))
&& (hist.search.opt.query.empty() || hist.search.preg.match() > 0)
) {
cHistItemQueue * found = new cHistItemQueue;
found->parent = this;
found->pos = id;
found->subItems = 0;
found->dir = dir;
found->path = path;
char * uid = (*Ctrl->DTgetStr(DTMSG , id , MSG_FROMUID))?Ctrl->DTgetStr(DTMSG , id , MSG_FROMUID):Ctrl->DTgetStr(DTMSG , id , MSG_TOUID);
cnt = ICMessage(IMC_CNT_FIND , Ctrl->DTgetInt(DTMSG , id , MSG_NET)
, (int)uid);
found->name = cnt!=DT_NOROW?GETCNTC(cnt , CNT_DISPLAY):SAFECHAR(uid);
cnt = Ctrl->DTgetID(DTCNT , cnt);
if (hist.search.opt.query.empty()) {
found->title = CStdString(Ctrl->DTgetStr(DTMSG , id , MSG_BODY)).substr(0 , 50);
} else {
found->title = hist.search.preg.getSubjectRef().substr(hist.search.preg.getVector(0) , 50);
}
found->ico = UIIcon(IT_LOGO , Ctrl->DTgetInt(DTMSG , id , MSG_NET) , 0, 0);
unsigned int j;
for (j=0; j<found->title.size(); j++) {
if ((unsigned char)found->title[j] < 31) {found->title[j] = ' ';}
}
if (j>=49) found->title+="...";
cTime64 t64(Ctrl->DTgetInt64(DTMSG , id , MSG_TIME));
found->sort = __int64(t64) & 0xFFFFFFFFFFFF;
found->date = t64;
hist.search.foundDir->addFoundItem(found);
} // match
}
}
}
void cHistDirSearch::open() {
fill();
if (hist.search.state != hist_s::search_s::stReady) return;
hist.search.Reset();
this->opt.SetInDialog(0);
if (this->items.empty())
hist.search.Show();
}
void cHistDirSearch::msgInsert(cMessage * msg , const char * display , bool scroll){
if (!GETINT(CFG_UIHISTORY_MARKFOUND) || hist.search.opt.query.empty()) {
cHistDir::msgInsert(msg , display , scroll);
return;
}
cMessage m = *msg;
CStdString body;
if (!(m.flag & MF_HTML)) {
m.flag |= MF_HTML;
body = EncodeEntities(m.body);
body.Replace("\n" , "<br/>");
this->preg.setSubject(body);
} else
this->preg.setSubject(m.body);
body = this->preg.replace("<span class=\"mark\">$&</span>");