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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
|
/*
Basic History plugin
Copyright (C) 2011-2012 Krzysztof Kral
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
#include "Options.h"
#include "resource.h"
extern bool g_SmileyAddAvail;
extern bool bPopupsEnabled;
Options *Options::instance;
struct EventNamesType
{
int id;
wchar_t* name;
}
EventNames[] =
{
EVENTTYPE_MESSAGE, LPGENW("Message"),
EVENTTYPE_FILE, LPGENW("File transfer"),
EVENTTYPE_URL, LPGENW("Link"),
EVENTTYPE_AUTHREQUEST, LPGENW("Authorization request"),
EVENTTYPE_ADDED, LPGENW("You were added"),
EVENTTYPE_CONTACTS, LPGENW("Contacts received"),
ICQEVENTTYPE_SMS, LPGENW("SMS message")
};
struct TCpTable
{
UINT cpId;
wchar_t *cpName;
}
cpTable[] = {
{ CP_UTF8, L"UTF-8" },
{ 1250, L"windows-1250" },
{ 1251, L"windows-1251" },
{ 1252, L"windows-1252" },
{ 1253, L"windows-1253" },
{ 1254, L"windows-1254" },
{ 1255, L"windows-1255" },
{ 1256, L"windows-1256" },
{ 1257, L"windows-1257" },
{ 1258, L"windows-1258" },
{ 28591, L"iso-8859-1" },
{ 28592, L"iso-8859-2" },
{ 28593, L"iso-8859-3" },
{ 28594, L"iso-8859-4" },
{ 28595, L"iso-8859-5" },
{ 28596, L"iso-8859-6" },
{ 28597, L"iso-8859-7" },
{ 28598, L"iso-8859-8" },
{ 28599, L"iso-8859-9" },
{ 28603, L"iso-8859-13" },
{ 28605, L"iso-8859-15" },
};
Options::Options()
{
showContacts = false;
showContactGroups = true;
noFindBorder = false;
groupNewOnTop = true;
groupShowEvents = true;
groupShowTime = true;
groupShowName = false;
groupShowMessage = true;
groupMessageLen = 43;
groupTime = 5;
groupMessagesNumber = 100;
messagesNewOnTop = false;
messagesShowDate = false;
messagesShowSec = false;
messagesShowName = true;
messagesShowEvents = false;
messagesUseSmileys = true;
searchForInList = true;
searchForInMess = true;
searchMatchCase = false;
searchMatchWhole = false;
searchOnlyIn = false;
searchOnlyOut = false;
searchOnlyGroup = false;
searchAllContacts = false;
schedulerAlerts = true;
schedulerHistoryAlerts = true;
defFilter = 0;
codepageTxt = CP_UTF8;
codepageHtml1 = CP_UTF8;
codepageHtml2 = CP_UTF8;
encodingTxt = L"UTF-8";
encodingHtml1 = L"UTF-8";
encodingHtml2 = L"UTF-8";
exportHtml1ShowDate = true;
exportHtml2ShowDate = false;
exportHtml2UseSmileys = true;
}
Options::~Options()
{
}
int Options::InitOptions(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 100000000;
odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
odp.szTitle.w = LPGENW("History");
odp.szTab.w = LPGENW("Group list");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GROUPLIST);
odp.pfnDlgProc = Options::DlgProcOptsGroupList;
g_plugin.addOptions(wParam, &odp);
odp.szTab.w = LPGENW("Messages");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MESSAGES);
odp.pfnDlgProc = Options::DlgProcOptsMessages;
g_plugin.addOptions(wParam, &odp);
odp.szTab.w = LPGENW("Searching");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_SEARCHING);
odp.pfnDlgProc = Options::DlgProcOptsSearching;
g_plugin.addOptions(wParam, &odp);
odp.szTab.w = LPGENW("Export");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_EXPORT);
odp.pfnDlgProc = Options::DlgProcOptsExport;
g_plugin.addOptions(wParam, &odp);
odp.szTab.w = LPGENW("Scheduler");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_SCHEDULER);
odp.pfnDlgProc = Options::DlgProcOptsScheduler;
g_plugin.addOptions(wParam, &odp);
odp.szTab.w = LPGENW("Advanced");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAIN);
odp.pfnDlgProc = Options::DlgProcOptsMain;
g_plugin.addOptions(wParam, &odp);
return 0;
}
struct FontOptionsList
{
wchar_t* szDescr;
COLORREF defColour;
wchar_t* szDefFace;
BYTE defStyle;
char defSize;
wchar_t* szBackgroundName;
DWORD flags;
};
struct ColorOptionsList
{
wchar_t* tszName;
COLORREF def;
};
struct HotkeyOptionsList
{
const char *pszName;
wchar_t *pwszDescription;
wchar_t *pwszSection;
const char *pszService;
WORD DefHotKey;
LPARAM lParam;
};
static FontOptionsList g_FontOptionsList[] = {
{LPGENW(">> Outgoing timestamp"), RGB(0, 0, 0), L"MS Shell Dlg 2", DBFONTF_BOLD, -11, LPGENW("Outgoing background"), FIDF_ALLOWEFFECTS},
{LPGENW("<< Incoming timestamp"), RGB(0, 0, 0), L"MS Shell Dlg 2", DBFONTF_BOLD, -11, LPGENW("Incoming background"), FIDF_ALLOWEFFECTS},
{LPGENW(">> Outgoing name"), RGB(100,100,100), L"MS Shell Dlg 2", DBFONTF_BOLD, -11, LPGENW("Outgoing background"), FIDF_ALLOWEFFECTS},
{LPGENW("<< Incoming name"), RGB(90,160,90), L"MS Shell Dlg 2", DBFONTF_BOLD, -11, LPGENW("Incoming background"), FIDF_ALLOWEFFECTS},
{LPGENW(">> Outgoing messages"), RGB(0, 0, 0), L"MS Shell Dlg 2", 0, -11, LPGENW("Outgoing background"), FIDF_ALLOWEFFECTS},
{LPGENW("<< Incoming messages"), RGB(0, 0, 0), L"MS Shell Dlg 2", 0, -11, LPGENW("Incoming background"), FIDF_ALLOWEFFECTS},
{LPGENW("Group list"), RGB(0, 0, 0), L"MS Shell Dlg 2", 0, -11, LPGENW("Group list background"), FIDF_DISABLESTYLES},
{LPGENW("Find window"), RGB(0, 0, 0), L"MS Shell Dlg 2", 0, -11, LPGENW("Find window background"), FIDF_DISABLESTYLES},
};
static ColorOptionsList g_ColorOptionsList[] = {
LPGENW("Outgoing background"), RGB(245,245,255),
LPGENW("Incoming background"), RGB(245,255,245),
LPGENW("Group list background"), GetSysColor(COLOR_3DFACE),
LPGENW("Window background"), GetSysColor(COLOR_3DFACE),
LPGENW("Contact list background"), GetSysColor(COLOR_3DFACE),
LPGENW("Find window background"), GetSysColor(COLOR_WINDOW),
};
static HotkeyOptionsList g_HotkeyOptionsList[] = {
{ "basichistory_hot_showall", LPGENW("Open global history"), LPGENW("History"), MS_HISTORY_SHOWCONTACTHISTORY, HOTKEYCODE(HOTKEYF_CONTROL | HOTKEYF_SHIFT, 'H') | HKF_MIRANDA_LOCAL, 0 },
{ "basichistory_hot_find", LPGENW("Find"), LPGENW("History"), nullptr, HOTKEYCODE(HOTKEYF_CONTROL, 'F'), HISTORY_HK_FIND },
{ "basichistory_hot_findnext", LPGENW("Find next"), LPGENW("History"), nullptr, VK_F3, HISTORY_HK_FINDNEXT },
{ "basichistory_hot_findprev", LPGENW("Find previous"), LPGENW("History"), nullptr, VK_F2, HISTORY_HK_FINDPREV },
{ "basichistory_hot_matchcase", LPGENW("Switch match case"), LPGENW("History"), nullptr, 0, HISTORY_HK_MATCHCASE },
{ "basichistory_hot_matchwhole", LPGENW("Switch match whole word"), LPGENW("History"), nullptr, 0, HISTORY_HK_MATCHWHOLE },
{ "basichistory_hot_showcontacts", LPGENW("Show/hide contacts"), LPGENW("History"), nullptr, 0, HISTORY_HK_SHOWCONTACTS },
{ "basichistory_hot_onlyin", LPGENW("Switch only incoming messages"), LPGENW("History"), nullptr, 0, HISTORY_HK_ONLYIN },
{ "basichistory_hot_onlyout", LPGENW("Switch only outgoing messages"), LPGENW("History"), nullptr, 0, HISTORY_HK_ONLYOUT },
{ "basichistory_hot_onlygroup", LPGENW("Switch only selected group"), LPGENW("History"), nullptr, 0, HISTORY_HK_ONLYGROUP },
{ "basichistory_hot_allcontacts", LPGENW("Switch all contacts"), LPGENW("History"), nullptr, 0, HISTORY_HK_ALLCONTACTS },
{ "basichistory_hot_delete", LPGENW("Delete"), LPGENW("History"), nullptr, VK_DELETE, HISTORY_HK_DELETE },
{ "basichistory_hot_exrhtml", LPGENW("Export to rich HTML"), LPGENW("History"), nullptr, 0, HISTORY_HK_EXRHTML },
{ "basichistory_hot_exphtml", LPGENW("Export to plain HTML"), LPGENW("History"), nullptr, 0, HISTORY_HK_EXPHTML },
{ "basichistory_hot_extxt", LPGENW("Export to text file"), LPGENW("History"), nullptr, 0, HISTORY_HK_EXTXT },
{ "basichistory_hot_exbin", LPGENW("Export to binary"), LPGENW("History"), nullptr, 0, HISTORY_HK_EXBIN },
{ "basichistory_hot_impbin", LPGENW("Import from binary"), LPGENW("History"), nullptr, 0, HISTORY_HK_IMPBIN },
{ "basichistory_hot_exdat", LPGENW("Export to dat (mContacts)"), LPGENW("History"), nullptr, 0, HISTORY_HK_EXDAT },
{ "basichistory_hot_impdat", LPGENW("Import from dat (mContacts)"), LPGENW("History"), nullptr, 0, HISTORY_HK_IMPDAT },
};
const int g_fontsSize = _countof(g_FontOptionsList);
const int g_colorsSize = _countof(g_ColorOptionsList);
const int g_hotkeysSize = _countof(g_HotkeyOptionsList);
void Options::Load(void)
{
FontIDW fid = { 0 };
ColourIDW cid = { 0 };
HOTKEYDESC hid = {};
fid.cbSize = sizeof(FontIDW);
cid.cbSize = sizeof(ColourIDW);
strncpy_s(fid.dbSettingsGroup, "BasicHistory_Fonts", _TRUNCATE);
wcsncpy_s(fid.backgroundGroup, L"History", _TRUNCATE);
wcsncpy_s(fid.group, LPGENW("History"), _TRUNCATE);
for (int i = 0; i < g_fontsSize; ++i) {
fid.order = i;
wcsncpy_s(fid.deffontsettings.szFace, g_FontOptionsList[i].szDefFace, _TRUNCATE);
fid.deffontsettings.size = g_FontOptionsList[i].defSize;
fid.deffontsettings.colour = g_FontOptionsList[i].defColour;
fid.deffontsettings.style = g_FontOptionsList[i].defStyle;
fid.deffontsettings.charset = DEFAULT_CHARSET;
mir_snprintf(fid.prefix, _countof(fid.prefix), "Font%d", i);
wcsncpy_s(fid.name, g_FontOptionsList[i].szDescr, _TRUNCATE);
wcsncpy_s(fid.backgroundName, g_FontOptionsList[i].szBackgroundName, _TRUNCATE);
fid.flags = FIDF_DEFAULTVALID | FIDF_CLASSGENERAL | g_FontOptionsList[i].flags;
g_plugin.addFont(&fid);
}
strncpy_s(cid.dbSettingsGroup, "BasicHistory_Fonts", _TRUNCATE);
wcsncpy_s(cid.group, LPGENW("History"), _TRUNCATE);
for (int i = 0; i < g_colorsSize; ++i) {
wcsncpy_s(cid.name, g_ColorOptionsList[i].tszName, _TRUNCATE);
mir_snprintf(cid.setting, _countof(cid.setting), "Color%d", i);
cid.order = i;
cid.defcolour = g_ColorOptionsList[i].def;
g_plugin.addColor(&cid);
}
hid.dwFlags = HKD_UNICODE;
for (int i = 0; i < g_hotkeysSize; ++i) {
hid.pszName = g_HotkeyOptionsList[i].pszName;
hid.szDescription.w = g_HotkeyOptionsList[i].pwszDescription;
hid.szSection.w = g_HotkeyOptionsList[i].pwszSection;
hid.pszService = g_HotkeyOptionsList[i].pszService;
hid.DefHotKey = g_HotkeyOptionsList[i].DefHotKey;
hid.lParam = g_HotkeyOptionsList[i].lParam;
g_plugin.addHotkey(&hid);
}
showContacts = db_get_b(0, MODULENAME, "showContacts", 0) ? true : false;
showContactGroups = db_get_b(0, MODULENAME, "showContactGroups", 1) ? true : false;
noFindBorder = db_get_b(0, MODULENAME, "noFindBorder", 0) ? true : false;
groupNewOnTop = db_get_b(0, MODULENAME, "groupNewOnTop", 1) ? true : false;
groupShowEvents = db_get_b(0, MODULENAME, "groupShowEvents", 1) ? true : false;
groupShowTime = db_get_b(0, MODULENAME, "groupShowTime", 1) ? true : false;
groupShowName = db_get_b(0, MODULENAME, "groupShowName", 0) ? true : false;
groupShowMessage = db_get_b(0, MODULENAME, "groupShowMessage", 1) ? true : false;
groupMessageLen = db_get_dw(0, MODULENAME, "groupMessageLen", 43);
if (groupMessageLen < 5) groupMessageLen = 5;
groupTime = db_get_dw(0, MODULENAME, "groupTime", 5);
if (groupTime < 1) groupTime = 1;
groupMessagesNumber = db_get_dw(0, MODULENAME, "groupMessagesNumber", 100);
if (groupMessagesNumber < 1) groupMessagesNumber = 1;
messagesNewOnTop = db_get_b(0, MODULENAME, "messagesNewOnTop", 0) ? true : false;
messagesShowDate = db_get_b(0, MODULENAME, "messagesShowDate", 0) ? true : false;
messagesShowSec = db_get_b(0, MODULENAME, "messagesShowSec", 0) ? true : false;
messagesShowName = db_get_b(0, MODULENAME, "messagesShowName", 1) ? true : false;
messagesShowEvents = db_get_b(0, MODULENAME, "messagesShowEvents", 0) ? true : false;
messagesUseSmileys = db_get_b(0, MODULENAME, "messagesUseSmileys", 1) ? true : false;
searchForInList = db_get_b(0, MODULENAME, "searchForInList", 1) ? true : false;
searchForInMess = db_get_b(0, MODULENAME, "searchForInMess", 1) ? true : false;
searchMatchCase = db_get_b(0, MODULENAME, "searchMatchCase", 0) ? true : false;
searchMatchWhole = db_get_b(0, MODULENAME, "searchMatchWhole", 0) ? true : false;
searchOnlyIn = db_get_b(0, MODULENAME, "searchOnlyIn", 0) ? true : false;
searchOnlyOut = db_get_b(0, MODULENAME, "searchOnlyOut", 0) ? true : false;
searchOnlyGroup = db_get_b(0, MODULENAME, "searchOnlyGroup", 0) ? true : false;
searchAllContacts = db_get_b(0, MODULENAME, "searchAllContacts", 0) ? true : false;
schedulerAlerts = db_get_b(0, MODULENAME, "schedulerAlerts", 1) ? true : false;
schedulerHistoryAlerts = db_get_b(0, MODULENAME, "schedulerHistoryAlerts", 1) ? true : false;
defFilter = db_get_b(0, MODULENAME, "defFilter", defFilter);
int filtersCount = db_get_dw(0, MODULENAME, "customFiltersCount", 0);
for (int i = 0; i < filtersCount; ++i) {
char buf[256];
FilterOptions fo;
mir_snprintf(buf, "filterName_%d", i);
DBVARIANT nameV;
if (!db_get_ws(0, MODULENAME, buf, &nameV)) {
fo.name = nameV.pwszVal;
db_free(&nameV);
}
else break;
mir_snprintf(buf, "filterInOut_%d", i);
int inOut = db_get_b(0, MODULENAME, buf, 0);
if (inOut == 1)
fo.onlyIncomming = true;
else if (inOut == 2)
fo.onlyOutgoing = true;
mir_snprintf(buf, "filterEvents_%d", i);
DBVARIANT eventsV;
if (!db_get_s(0, MODULENAME, buf, &eventsV)) {
int k = 0;
char* id = eventsV.pszVal;
while (eventsV.pszVal[k]) {
if (eventsV.pszVal[k] == ';') {
eventsV.pszVal[k] = 0;
fo.events.push_back(strtol(id, nullptr, 16));
id = eventsV.pszVal + k + 1;
}
++k;
}
db_free(&eventsV);
}
else break;
customFilters.insert(customFilters.end(), fo);
}
if (defFilter > 1) {
defFilter = 0;
DBVARIANT defFilterStrV;
if (!db_get_ws(0, MODULENAME, "defFilterStr", &defFilterStrV)) {
std::wstring filterName = defFilterStrV.pwszVal;
for (int i = 0; i < (int)customFilters.size(); ++i) {
if (filterName == customFilters[i].name) {
defFilter = i + 2;
break;
}
}
db_free(&defFilterStrV);
}
}
codepageTxt = db_get_dw(0, MODULENAME, "codepageTxt", CP_UTF8);
codepageHtml1 = db_get_dw(0, MODULENAME, "codepageHtml1", CP_UTF8);
codepageHtml2 = db_get_dw(0, MODULENAME, "codepageHtml2", CP_UTF8);
DBVARIANT encodingV;
if (!db_get_ws(0, MODULENAME, "encodingTxt", &encodingV)) {
encodingTxt = encodingV.pwszVal;
db_free(&encodingV);
}
else encodingTxt = L"UTF-8";
if (!db_get_ws(0, MODULENAME, "encodingHtml1", &encodingV)) {
encodingHtml1 = encodingV.pwszVal;
db_free(&encodingV);
}
else encodingHtml1 = L"UTF-8";
if (!db_get_ws(0, MODULENAME, "encodingHtml2", &encodingV)) {
encodingHtml2 = encodingV.pwszVal;
db_free(&encodingV);
}
else encodingHtml2 = L"UTF-8";
exportHtml1ShowDate = db_get_b(0, MODULENAME, "exportHtml1ShowDate", 1) ? true : false;
exportHtml2ShowDate = db_get_b(0, MODULENAME, "exportHtml2ShowDate", 0) ? true : false;
exportHtml2UseSmileys = db_get_b(0, MODULENAME, "exportHtml2UseSmileys", 1) ? true : false;
if (!db_get_ws(0, MODULENAME, "extCssHtml2", &encodingV)) {
extCssHtml2 = encodingV.pwszVal;
db_free(&encodingV);
}
else extCssHtml2 = L"";
if (!db_get_ws(0, MODULENAME, "ftpLogPath", &encodingV)) {
ftpLogPath = encodingV.pwszVal;
db_free(&encodingV);
}
if (!db_get_ws(0, MODULENAME, "ftpExePath", &encodingV)) {
ftpExePath = encodingV.pwszVal;
db_free(&encodingV);
}
else ftpExePath = ftpExePathDef;
LoadTasks();
}
COLORREF Options::GetFont(Fonts fontId, PLOGFONT font)
{
return Font_GetW(LPGENW("History"), g_FontOptionsList[fontId].szDescr, font);
}
COLORREF Options::GetColor(Colors colorId)
{
return Colour_GetW(LPGENW("History"), g_ColorOptionsList[colorId].tszName);
}
void Options::Save()
{
db_set_b(0, MODULENAME, "showContacts", showContacts ? 1 : 0);
db_set_b(0, MODULENAME, "showContactGroups", showContactGroups ? 1 : 0);
db_set_b(0, MODULENAME, "noFindBorder", noFindBorder ? 1 : 0);
db_set_b(0, MODULENAME, "groupNewOnTop", groupNewOnTop ? 1 : 0);
db_set_b(0, MODULENAME, "groupShowEvents", groupShowEvents ? 1 : 0);
db_set_b(0, MODULENAME, "groupShowTime", groupShowTime ? 1 : 0);
db_set_b(0, MODULENAME, "groupShowName", groupShowName ? 1 : 0);
db_set_b(0, MODULENAME, "groupShowMessage", groupShowMessage ? 1 : 0);
if (groupMessageLen < 5)
groupMessageLen = 5;
db_set_dw(0, MODULENAME, "groupMessageLen", groupMessageLen);
if (groupTime < 1)
groupTime = 1;
db_set_dw(0, MODULENAME, "groupTime", groupTime);
if (groupMessagesNumber < 1)
groupMessagesNumber = 1;
db_set_dw(0, MODULENAME, "groupMessagesNumber", groupMessagesNumber);
db_set_b(0, MODULENAME, "messagesNewOnTop", messagesNewOnTop ? 1 : 0);
db_set_b(0, MODULENAME, "messagesShowDate", messagesShowDate ? 1 : 0);
db_set_b(0, MODULENAME, "messagesShowSec", messagesShowSec ? 1 : 0);
db_set_b(0, MODULENAME, "messagesShowName", messagesShowName ? 1 : 0);
db_set_b(0, MODULENAME, "messagesShowEvents", messagesShowEvents ? 1 : 0);
db_set_b(0, MODULENAME, "messagesUseSmileys", messagesUseSmileys ? 1 : 0);
db_set_b(0, MODULENAME, "searchForInList", searchForInList ? 1 : 0);
db_set_b(0, MODULENAME, "searchForInMess", searchForInMess ? 1 : 0);
db_set_b(0, MODULENAME, "searchMatchCase", searchMatchCase ? 1 : 0);
db_set_b(0, MODULENAME, "searchMatchWhole", searchMatchWhole ? 1 : 0);
db_set_b(0, MODULENAME, "searchOnlyIn", searchOnlyIn ? 1 : 0);
db_set_b(0, MODULENAME, "searchOnlyOut", searchOnlyOut ? 1 : 0);
db_set_b(0, MODULENAME, "searchOnlyGroup", searchOnlyGroup ? 1 : 0);
db_set_b(0, MODULENAME, "searchAllContacts", searchAllContacts ? 1 : 0);
db_set_b(0, MODULENAME, "schedulerAlerts", schedulerAlerts ? 1 : 0);
db_set_b(0, MODULENAME, "schedulerHistoryAlerts", schedulerHistoryAlerts ? 1 : 0);
if (defFilter < 0 || defFilter - 2 >= (int)customFilters.size())
defFilter = 0;
db_set_b(0, MODULENAME, "defFilter", defFilter < 2 ? defFilter : 2);
if (defFilter >= 2)
db_set_ws(0, MODULENAME, "defFilterStr", customFilters[defFilter - 2].name.c_str());
db_set_dw(0, MODULENAME, "customFiltersCount", (DWORD)customFilters.size());
for (int i = 0; i < (int)customFilters.size(); ++i) {
char buf[256];
mir_snprintf(buf, "filterName_%d", i);
db_set_ws(0, MODULENAME, buf, customFilters[i].name.c_str());
mir_snprintf(buf, "filterInOut_%d", i);
db_set_b(0, MODULENAME, buf, customFilters[i].onlyIncomming ? 1 : (customFilters[i].onlyOutgoing ? 2 : 0));
std::string events;
for (std::vector<int>::iterator it = customFilters[i].events.begin(); it != customFilters[i].events.end(); ++it) {
_itoa_s(*it, buf, 16);
events += buf;
events += ";";
}
mir_snprintf(buf, "filterEvents_%d", i);
db_set_s(0, MODULENAME, buf, events.c_str());
}
db_set_dw(0, MODULENAME, "codepageTxt", codepageTxt);
db_set_dw(0, MODULENAME, "codepageHtml1", codepageHtml1);
db_set_dw(0, MODULENAME, "codepageHtml2", codepageHtml2);
db_set_ws(0, MODULENAME, "encodingTxt", encodingTxt.c_str());
db_set_ws(0, MODULENAME, "encodingHtml1", encodingHtml1.c_str());
db_set_ws(0, MODULENAME, "encodingHtml2", encodingHtml2.c_str());
db_set_b(0, MODULENAME, "exportHtml1ShowDate", exportHtml1ShowDate ? 1 : 0);
db_set_b(0, MODULENAME, "exportHtml2ShowDate", exportHtml2ShowDate ? 1 : 0);
db_set_b(0, MODULENAME, "exportHtml2UseSmileys", exportHtml2UseSmileys ? 1 : 0);
db_set_ws(0, MODULENAME, "extCssHtml2", extCssHtml2.c_str());
db_set_ws(0, MODULENAME, "ftpLogPath", ftpLogPath.c_str());
if (ftpExePath != ftpExePathDef)
db_set_ws(0, MODULENAME, "ftpExePath", ftpExePath.c_str());
else
db_unset(0, MODULENAME, "ftpExePath");
}
void Options::SaveTasks(std::list<TaskOptions>* tasks)
{
mir_cslock lck(criticalSection);
int oldTaskNr = (int)taskOptions.size();
taskOptions.clear();
int i = 0;
char buf[256];
for (std::list<TaskOptions>::iterator it = tasks->begin(); it != tasks->end(); ++it) {
mir_snprintf(buf, "Task_compress_%d", i);
db_set_b(0, MODULENAME, buf, it->compress);
mir_snprintf(buf, "Task_useFtp_%d", i);
db_set_b(0, MODULENAME, buf, it->useFtp);
mir_snprintf(buf, "Task_isSystem_%d", i);
db_set_b(0, MODULENAME, buf, it->isSystem);
mir_snprintf(buf, "Task_active_%d", i);
db_set_b(0, MODULENAME, buf, it->active);
mir_snprintf(buf, "Task_exportImported_%d", i);
db_set_b(0, MODULENAME, buf, it->exportImported);
mir_snprintf(buf, "Task_type_%d", i);
db_set_b(0, MODULENAME, buf, it->type);
mir_snprintf(buf, "Task_eventUnit_%d", i);
db_set_b(0, MODULENAME, buf, it->eventUnit);
mir_snprintf(buf, "Task_trigerType_%d", i);
db_set_b(0, MODULENAME, buf, it->trigerType);
mir_snprintf(buf, "Task_exportType_%d", i);
db_set_b(0, MODULENAME, buf, it->exportType);
mir_snprintf(buf, "Task_importType_%d", i);
db_set_b(0, MODULENAME, buf, it->importType);
mir_snprintf(buf, "Task_eventDeltaTime_%d", i);
db_set_dw(0, MODULENAME, buf, it->eventDeltaTime);
mir_snprintf(buf, "Task_filterId_%d", i);
db_set_dw(0, MODULENAME, buf, it->filterId);
mir_snprintf(buf, "Task_dayTime_%d", i);
db_set_dw(0, MODULENAME, buf, it->dayTime);
mir_snprintf(buf, "Task_dayOfWeek_%d", i);
db_set_dw(0, MODULENAME, buf, it->dayOfWeek);
mir_snprintf(buf, "Task_dayOfMonth_%d", i);
db_set_dw(0, MODULENAME, buf, it->dayOfMonth);
mir_snprintf(buf, "Task_deltaTime_%d", i);
db_set_dw(0, MODULENAME, buf, it->deltaTime);
mir_snprintf(buf, "Task_lastExport_low_%d", i);
db_set_dw(0, MODULENAME, buf, (int)it->lastExport);
mir_snprintf(buf, "Task_lastExport_hi_%d", i);
db_set_dw(0, MODULENAME, buf, ((unsigned long long int)it->lastExport) >> 32);
mir_snprintf(buf, "Task_ftpName_%d", i);
db_set_ws(0, MODULENAME, buf, it->ftpName.c_str());
mir_snprintf(buf, "Task_filterName_%d", i);
db_set_ws(0, MODULENAME, buf, it->filterName.c_str());
mir_snprintf(buf, "Task_filePath_%d", i);
db_set_ws(0, MODULENAME, buf, it->filePath.c_str());
mir_snprintf(buf, "Task_taskName_%d", i);
db_set_ws(0, MODULENAME, buf, it->taskName.c_str());
mir_snprintf(buf, "Task_zipPassword_%d", i);
db_set_s(0, MODULENAME, buf, it->zipPassword.c_str());
mir_snprintf(buf, "IsInTask_%d", i);
for (auto &hContact : Contacts())
db_unset(hContact, MODULENAME, buf);
for (size_t j = 0; j < it->contacts.size(); ++j)
db_set_b(it->contacts[j], MODULENAME, buf, 1);
it->orderNr = i++;
taskOptions.push_back(*it);
}
db_set_dw(0, MODULENAME, "Task_count", i);
for (i = (int)tasks->size(); i < oldTaskNr; ++i) {
mir_snprintf(buf, "Task_compress_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_useFtp_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_isSystem_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_active_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_type_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_eventUnit_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_trigerType_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_exportType_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_eventDeltaTime_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_filterId_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_dayTime_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_dayOfWeek_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_dayOfMonth_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_deltaTime_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_lastExport_low_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_lastExport_hi_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_ftpName_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_filterName_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_filePath_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "Task_taskName_%d", i);
db_unset(NULL, MODULENAME, buf);
mir_snprintf(buf, "IsInTask_%d", i);
for (auto &hContact : Contacts())
db_unset(hContact, MODULENAME, buf);
}
}
void Options::SaveTaskTime(TaskOptions& to)
{
int i = to.orderNr;
char buf[256];
mir_snprintf(buf, "Task_lastExport_low_%d", i);
db_set_dw(0, MODULENAME, buf, (int)to.lastExport);
mir_snprintf(buf, "Task_lastExport_hi_%d", i);
db_set_dw(0, MODULENAME, buf, ((unsigned long long int)to.lastExport) >> 32);
}
void Options::LoadTasks()
{
int taskCount = db_get_dw(0, MODULENAME, "Task_count", 0);
char buf[256];
for (int i = 0; i < taskCount; ++i) {
TaskOptions to;
mir_snprintf(buf, "Task_compress_%d", i);
to.compress = db_get_b(0, MODULENAME, buf, to.compress) != 0;
mir_snprintf(buf, "Task_useFtp_%d", i);
to.useFtp = db_get_b(0, MODULENAME, buf, to.useFtp) != 0;
mir_snprintf(buf, "Task_isSystem_%d", i);
to.isSystem = db_get_b(0, MODULENAME, buf, to.isSystem) != 0;
mir_snprintf(buf, "Task_active_%d", i);
to.active = db_get_b(0, MODULENAME, buf, to.active) != 0;
mir_snprintf(buf, "Task_exportImported_%d", i);
to.exportImported = db_get_b(0, MODULENAME, buf, to.exportImported) != 0;
mir_snprintf(buf, "Task_type_%d", i);
to.type = (TaskOptions::TaskType)db_get_b(0, MODULENAME, buf, to.type);
mir_snprintf(buf, "Task_eventUnit_%d", i);
to.eventUnit = (TaskOptions::EventUnit)db_get_b(0, MODULENAME, buf, to.eventUnit);
mir_snprintf(buf, "Task_trigerType_%d", i);
to.trigerType = (TaskOptions::TrigerType)db_get_b(0, MODULENAME, buf, to.trigerType);
mir_snprintf(buf, "Task_exportType_%d", i);
to.exportType = (IExport::ExportType)db_get_b(0, MODULENAME, buf, to.exportType);
mir_snprintf(buf, "Task_importType_%d", i);
to.importType = (IImport::ImportType)db_get_b(0, MODULENAME, buf, to.importType);
mir_snprintf(buf, "Task_eventDeltaTime_%d", i);
to.eventDeltaTime = db_get_dw(0, MODULENAME, buf, to.eventDeltaTime);
mir_snprintf(buf, "Task_filterId_%d", i);
to.filterId = db_get_dw(0, MODULENAME, buf, to.filterId);
mir_snprintf(buf, "Task_dayTime_%d", i);
to.dayTime = db_get_dw(0, MODULENAME, buf, to.dayTime);
mir_snprintf(buf, "Task_dayOfWeek_%d", i);
to.dayOfWeek = db_get_dw(0, MODULENAME, buf, to.dayOfWeek);
mir_snprintf(buf, "Task_dayOfMonth_%d", i);
to.dayOfMonth = db_get_dw(0, MODULENAME, buf, to.dayOfMonth);
mir_snprintf(buf, "Task_deltaTime_%d", i);
to.deltaTime = db_get_dw(0, MODULENAME, buf, to.deltaTime);
unsigned long long int le = to.lastExport;
mir_snprintf(buf, "Task_lastExport_low_%d", i);
to.lastExport = db_get_dw(0, MODULENAME, buf, (int)le) & 0xffffffff;
mir_snprintf(buf, "Task_lastExport_hi_%d", i);
to.lastExport |= ((unsigned long long int)db_get_dw(0, MODULENAME, buf, le >> 32)) << 32;
mir_snprintf(buf, "Task_ftpName_%d", i);
DBVARIANT var;
if (!db_get_ws(0, MODULENAME, buf, &var)) {
to.ftpName = var.ptszVal;
db_free(&var);
}
mir_snprintf(buf, "Task_filterName_%d", i);
if (!db_get_ws(0, MODULENAME, buf, &var)) {
to.filterName = var.ptszVal;
db_free(&var);
}
mir_snprintf(buf, "Task_filePath_%d", i);
if (!db_get_ws(0, MODULENAME, buf, &var)) {
to.filePath = var.ptszVal;
db_free(&var);
}
mir_snprintf(buf, "Task_taskName_%d", i);
if (!db_get_ws(0, MODULENAME, buf, &var)) {
to.taskName = var.ptszVal;
db_free(&var);
}
mir_snprintf(buf, "Task_zipPassword_%d", i);
if (!db_get_s(0, MODULENAME, buf, &var)) {
to.zipPassword = var.pszVal;
db_free(&var);
}
mir_snprintf(buf, "IsInTask_%d", i);
for (auto &hContact : Contacts())
if (db_get_b(hContact, MODULENAME, buf, 0) == 1)
to.contacts.push_back(hContact);
to.orderNr = i;
taskOptions.push_back(to);
}
}
void OptionsMainChanged();
void OptionsGroupChanged();
void OptionsMessageChanged();
void OptionsSearchingChanged();
void OptionsSchedulerChanged();
void InitTaskMenuItems();
void SetEventCB(HWND hwndCB, int eventId)
{
int cpCount = _countof(EventNames);
int selCpIdx = -1;
for (int i = 0; i < cpCount; ++i)
if (EventNames[i].id == eventId)
selCpIdx = i;
if (selCpIdx == -1) {
wchar_t buf[24];
mir_snwprintf(buf, L"%d", eventId);
ComboBox_SetText(hwndCB, buf);
}
else ComboBox_SetCurSel(hwndCB, selCpIdx);
}
int GetEventCB(HWND hwndCB, bool errorReport, int &eventId)
{
int selCpIdx = ComboBox_GetCurSel(hwndCB);
if (selCpIdx < 0) {
wchar_t text[24];
ComboBox_GetText(hwndCB, text, 24);
wchar_t * stopOn = nullptr;
long cp = wcstol(text, &stopOn, 10);
if (errorReport && (stopOn == text || *stopOn != '\0' || cp < 0)) {
MessageBox(GetParent(hwndCB), TranslateT("Invalid event number"), TranslateT("Error"), MB_OK | MB_ICONERROR);
SetFocus(hwndCB);
return -1;
}
eventId = cp;
}
else if (selCpIdx > 1)
eventId = EventNames[selCpIdx - 2].id;
else
return selCpIdx + 1;
return 0;
}
void ClearLB(HWND hwndLB)
{
while (ListBox_GetCount(hwndLB) > 0)
ListBox_DeleteString(hwndLB, 0);
}
void ReloadEventLB(HWND hwndLB, const FilterOptions &sel)
{
while (ListBox_GetCount(hwndLB) > 0)
ListBox_DeleteString(hwndLB, 0);
if (sel.onlyIncomming && !sel.onlyOutgoing)
ListBox_AddString(hwndLB, TranslateT("Incoming events"));
else if (sel.onlyOutgoing && !sel.onlyIncomming)
ListBox_AddString(hwndLB, TranslateT("Outgoing events"));
for (std::vector<int>::const_iterator it = sel.events.begin(); it != sel.events.end(); ++it) {
int cpCount = _countof(EventNames);
int selCpIdx = -1;
for (int i = 0; i < cpCount; ++i)
if (EventNames[i].id == *it)
selCpIdx = i;
if (selCpIdx == -1) {
wchar_t buf[24];
mir_snwprintf(buf, L"%d", *it);
ListBox_AddString(hwndLB, buf);
}
else ListBox_AddString(hwndLB, TranslateW(EventNames[selCpIdx].name));
}
}
bool CheckFile(HWND hwndEdit)
{
wchar_t buf[MAX_PATH];
Edit_GetText(hwndEdit, buf, MAX_PATH);
DWORD atr = GetFileAttributes(buf);
if (atr == INVALID_FILE_ATTRIBUTES || atr & FILE_ATTRIBUTE_DIRECTORY) {
MessageBox(GetParent(hwndEdit), TranslateT("File does not exist. Enter correct file path."), TranslateT("Invalid file"), MB_OK | MB_ICONERROR);
SetFocus(hwndEdit);
return false;
}
return true;
}
bool OpenFileDlg(HWND hwndDlg, HWND hwndEdit, const wchar_t* defName, const wchar_t* ext, const wchar_t* title, bool open)
{
wchar_t filter[1024];
std::locale loc;
wchar_t extUpper[32];
wcscpy_s(extUpper, ext);
extUpper[0] = std::toupper(ext[0], loc);
mir_snwprintf(filter, TranslateT("%s files (*.%s)"), extUpper, ext);
size_t len = mir_wstrlen(filter) + 1;
mir_snwprintf(filter + len, _countof(filter) - len, L"*.%s", ext);
len += mir_wstrlen(filter + len) + 1;
wcscpy_s(filter + len, 1024 - len, TranslateT("All files (*.*)"));
len += mir_wstrlen(filter + len) + 1;
wcscpy_s(filter + len, 1024 - len, L"*.*");
len += mir_wstrlen(filter + len) + 1;
filter[len] = 0;
wchar_t stzFilePath[1024];
Edit_GetText(hwndEdit, stzFilePath, 1023);
if (stzFilePath[0] == 0) {
wcscpy_s(stzFilePath, defName);
len = mir_wstrlen(stzFilePath) + 1;
stzFilePath[len] = 0;
}
else {
len = mir_wstrlen(stzFilePath) + 1;
stzFilePath[len] = 0;
}
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwndDlg;
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = stzFilePath;
ofn.lpstrTitle = title;
ofn.nMaxFile = _countof(stzFilePath);
ofn.lpstrDefExt = ext;
if (open) {
ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if (GetOpenFileName(&ofn)) {
Edit_SetText(hwndEdit, stzFilePath);
return true;
}
}
else {
ofn.Flags = OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
if (GetSaveFileName(&ofn)) {
Edit_SetText(hwndEdit, stzFilePath);
return true;
}
}
return false;
}
INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)FALSE);
CheckDlgButton(hwndDlg, IDC_SHOWCONTACTS, instance->showContacts ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWCONTACTGROUPS, instance->showContactGroups ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_FINDNOBORDER, instance->noFindBorder ? BST_CHECKED : BST_UNCHECKED);
HWND events = GetDlgItem(hwndDlg, IDC_EVENT);
HWND defFilter = GetDlgItem(hwndDlg, IDC_DEFFILTER);
HWND listFilter = GetDlgItem(hwndDlg, IDC_LIST_FILTERS);
HWND ftp = GetDlgItem(hwndDlg, IDC_WINSCP);
HWND ftpLog = GetDlgItem(hwndDlg, IDC_WINSCPLOG);
ComboBox_AddString(events, TranslateT("Incoming events"));
ComboBox_AddString(events, TranslateT("Outgoing events"));
for (auto &it : EventNames)
ComboBox_AddString(events, TranslateW(it.name));
ComboBox_AddString(defFilter, TranslateT("Default history events"));
ComboBox_AddString(defFilter, TranslateT("All events"));
Edit_LimitText(GetDlgItem(hwndDlg, IDC_FILTER_NAME), 20);
ComboBox_LimitText(events, 20);
instance->customFiltersTemp.clear();
instance->customFiltersTemp.insert(instance->customFiltersTemp.begin(), instance->customFilters.begin(), instance->customFilters.end());
for (std::vector<FilterOptions>::iterator it = instance->customFiltersTemp.begin(); it != instance->customFiltersTemp.end(); ++it) {
ComboBox_AddString(defFilter, it->name.c_str());
ListBox_AddString(listFilter, it->name.c_str());
}
ComboBox_SetCurSel(defFilter, instance->defFilter);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_FILTER), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_EVENT), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_EVENT), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_EVENT), FALSE);
Edit_LimitText(ftp, MAX_PATH);
Edit_LimitText(ftpLog, MAX_PATH);
Edit_SetText(ftp, instance->ftpExePath.c_str());
Edit_SetText(ftpLog, instance->ftpLogPath.c_str());
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)TRUE);
}
return TRUE;
case WM_COMMAND:
{
BOOL init = (BOOL)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (HIWORD(wParam) == BN_CLICKED) {
HWND listFilter = GetDlgItem(hwndDlg, IDC_LIST_FILTERS);
HWND listEvents = GetDlgItem(hwndDlg, IDC_LIST_EVENTS);
HWND nameFilter = GetDlgItem(hwndDlg, IDC_FILTER_NAME);
HWND defFilter = GetDlgItem(hwndDlg, IDC_DEFFILTER);
HWND eventCB = GetDlgItem(hwndDlg, IDC_EVENT);
switch (LOWORD(wParam)) {
case IDC_ADD_FILTER:
{
wchar_t name[24];
Edit_GetText(nameFilter, name, 24);
if (name[0] == 0) {
MessageBox(hwndDlg, TranslateT("Enter filter name"), TranslateT("Error"), MB_ICONERROR);
return TRUE;
}
FilterOptions fo(name);
for (std::vector<FilterOptions>::iterator it = instance->customFiltersTemp.begin(); it != instance->customFiltersTemp.end(); ++it) {
if (it->name == fo.name) {
MessageBox(hwndDlg, TranslateT("Filter name exists"), TranslateT("Error"), MB_ICONERROR);
return TRUE;
}
}
instance->customFiltersTemp.insert(instance->customFiltersTemp.end(), fo);
int i = ListBox_AddString(listFilter, name);
ListBox_SetCurSel(listFilter, i);
ComboBox_AddString(defFilter, name);
name[0] = 0;
Edit_SetText(nameFilter, name);
ReloadEventLB(listEvents, instance->customFiltersTemp[i]);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_FILTER), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_EVENT), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_EVENT), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_EVENT), FALSE);
}
break;
case IDC_DELETE_FILTER:
{
int sel = ListBox_GetCurSel(listFilter);
if (sel < 0)
return TRUE;
for (size_t i = sel; i < instance->customFiltersTemp.size() - 1; ++i)
instance->customFiltersTemp[i] = instance->customFiltersTemp[i + 1];
instance->customFiltersTemp.resize(instance->customFiltersTemp.size() - 1);
ListBox_DeleteString(listFilter, sel);
ComboBox_DeleteString(defFilter, sel + 2);
if (ComboBox_GetCurSel(defFilter) < 0)
ComboBox_SetCurSel(defFilter, 0);
ClearLB(listEvents);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_FILTER), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_EVENT), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_EVENT), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_EVENT), FALSE);
}
break;
case IDC_ADD_EVENT:
{
int sel = ListBox_GetCurSel(listFilter);
if (sel < 0)
return TRUE;
int eventId;
int selCB = GetEventCB(eventCB, true, eventId);
if (selCB < 0)
return TRUE;
if (selCB == 1) {
if (instance->customFiltersTemp[sel].onlyIncomming) {
MessageBox(hwndDlg, TranslateT("Event already exists"), TranslateT("Error"), MB_ICONERROR);
return TRUE;
}
if (instance->customFiltersTemp[sel].onlyOutgoing)
instance->customFiltersTemp[sel].onlyOutgoing = false;
else
instance->customFiltersTemp[sel].onlyIncomming = true;
}
else if (selCB == 2) {
if (instance->customFiltersTemp[sel].onlyOutgoing) {
MessageBox(hwndDlg, TranslateT("Event already exists"), TranslateT("Error"), MB_ICONERROR);
return TRUE;
}
if (instance->customFiltersTemp[sel].onlyIncomming)
instance->customFiltersTemp[sel].onlyIncomming = false;
else
instance->customFiltersTemp[sel].onlyOutgoing = true;
}
else {
if (std::find(instance->customFiltersTemp[sel].events.begin(), instance->customFiltersTemp[sel].events.end(), eventId) != instance->customFiltersTemp[sel].events.end()) {
MessageBox(hwndDlg, TranslateT("Event already exists"), TranslateT("Error"), MB_ICONERROR);
return TRUE;
}
instance->customFiltersTemp[sel].events.push_back(eventId);
}
ReloadEventLB(listEvents, instance->customFiltersTemp[sel]);
ComboBox_SetCurSel(eventCB, -1);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_EVENT), FALSE);
}
break;
case IDC_DELETE_EVENT:
{
int sel = ListBox_GetCurSel(listFilter);
if (sel < 0)
return TRUE;
int eventSel = ListBox_GetCurSel(listEvents);
if (eventSel < 0)
return TRUE;
int stId = 0;
if (instance->customFiltersTemp[sel].onlyIncomming || instance->customFiltersTemp[sel].onlyOutgoing)
++stId;
if (eventSel >= stId) {
--eventSel;
for (int i = eventSel; i < (int)instance->customFiltersTemp[sel].events.size() - 1; ++i)
instance->customFiltersTemp[sel].events[i] = instance->customFiltersTemp[sel].events[i + 1];
instance->customFiltersTemp[sel].events.resize(instance->customFiltersTemp[sel].events.size() - 1);
}
else {
instance->customFiltersTemp[sel].onlyIncomming = false;
instance->customFiltersTemp[sel].onlyOutgoing = false;
}
ReloadEventLB(listEvents, instance->customFiltersTemp[sel]);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_EVENT), FALSE);
}
break;
case IDC_WINSCP_BROWSE:
if (!OpenFileDlg(hwndDlg, GetDlgItem(hwndDlg, IDC_WINSCP), L"WinSCP.exe", L"exe", TranslateT("Browse WinSCP file"), true))
return TRUE;
break;
case IDC_WINSCPLOG_BROWSE:
if (!OpenFileDlg(hwndDlg, GetDlgItem(hwndDlg, IDC_WINSCPLOG), L"ftplog.txt", L"txt", TranslateT("Save WinSCP log file"), false))
return TRUE;
break;
}
}
else if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_LIST_FILTERS) {
HWND listFilter = GetDlgItem(hwndDlg, IDC_LIST_FILTERS);
HWND listEvents = GetDlgItem(hwndDlg, IDC_LIST_EVENTS);
int sel = ListBox_GetCurSel(listFilter);
if (sel < 0)
ClearLB(listEvents);
else
ReloadEventLB(listEvents, instance->customFiltersTemp[sel]);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_FILTER), sel >= 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_EVENT), sel >= 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_EVENT), sel >= 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_EVENT), FALSE);
}
else if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_LIST_EVENTS) {
HWND listEvents = GetDlgItem(hwndDlg, IDC_LIST_EVENTS);
int sel = ListBox_GetCurSel(listEvents);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_EVENT), sel >= 0);
}
if (init && (HIWORD(wParam) == BN_CLICKED || (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_DEFFILTER) || (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) != IDC_FILTER_NAME)))
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
}
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
HWND ftp = GetDlgItem(hwndDlg, IDC_WINSCP);
wchar_t buf[MAX_PATH];
Edit_GetText(ftp, buf, MAX_PATH);
if (buf[0] != 0 && !CheckFile(ftp)) {
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
return TRUE;
}
instance->ftpExePath = buf;
Edit_GetText(GetDlgItem(hwndDlg, IDC_WINSCPLOG), buf, MAX_PATH);
instance->ftpLogPath = buf;
instance->showContacts = IsDlgButtonChecked(hwndDlg, IDC_SHOWCONTACTS) ? true : false;
instance->showContactGroups = IsDlgButtonChecked(hwndDlg, IDC_SHOWCONTACTGROUPS) ? true : false;
instance->noFindBorder = IsDlgButtonChecked(hwndDlg, IDC_FINDNOBORDER) ? true : false;
instance->defFilter = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_DEFFILTER));
instance->customFilters.clear();
instance->customFilters.insert(instance->customFilters.begin(), instance->customFiltersTemp.begin(), instance->customFiltersTemp.end());
Options::instance->Save();
OptionsMainChanged();
}
return TRUE;
}
return FALSE;
}
class OptsData
{
public:
OptsData()
{
init = false;
}
bool init;
};
INT_PTR CALLBACK Options::DlgProcOptsGroupList(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
OptsData* optsData = new OptsData();
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)optsData);
CheckDlgButton(hwndDlg, IDC_NEWONTOP, instance->groupNewOnTop ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWEVENTS, instance->groupShowEvents ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWTIME, instance->groupShowTime ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWNAME, instance->groupShowName ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWMESSAGE, instance->groupShowMessage ? BST_CHECKED : BST_UNCHECKED);
Edit_LimitText(GetDlgItem(hwndDlg, IDC_MESSAGELEN), 4);
SetDlgItemInt(hwndDlg, IDC_MESSAGELEN, instance->groupMessageLen, FALSE);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_SHOWMESSAGE, BN_CLICKED), NULL);
Edit_LimitText(GetDlgItem(hwndDlg, IDC_GROUPTIME), 2);
Edit_LimitText(GetDlgItem(hwndDlg, IDC_LIMITMESSAGES), 3);
SetDlgItemInt(hwndDlg, IDC_GROUPTIME, instance->groupTime, FALSE);
SetDlgItemInt(hwndDlg, IDC_LIMITMESSAGES, instance->groupMessagesNumber, FALSE);
optsData->init = true;
}
return TRUE;
case WM_COMMAND:
{
OptsData* optsData = (OptsData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_SHOWMESSAGE) {
if (IsDlgButtonChecked(hwndDlg, IDC_SHOWMESSAGE)) {
EnableWindow(GetDlgItem(hwndDlg, IDC_MESSAGELEN), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_MESSAGELEN_DESC), TRUE);
}
else {
EnableWindow(GetDlgItem(hwndDlg, IDC_MESSAGELEN), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_MESSAGELEN_DESC), FALSE);
}
}
if (optsData->init && (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == EN_CHANGE))
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
}
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
instance->groupNewOnTop = IsDlgButtonChecked(hwndDlg, IDC_NEWONTOP) ? true : false;
instance->groupShowEvents = IsDlgButtonChecked(hwndDlg, IDC_SHOWEVENTS) ? true : false;
instance->groupShowTime = IsDlgButtonChecked(hwndDlg, IDC_SHOWTIME) ? true : false;
instance->groupShowName = IsDlgButtonChecked(hwndDlg, IDC_SHOWNAME) ? true : false;
instance->groupShowMessage = IsDlgButtonChecked(hwndDlg, IDC_SHOWMESSAGE) ? true : false;
BOOL success;
instance->groupMessageLen = GetDlgItemInt(hwndDlg, IDC_MESSAGELEN, &success, FALSE);
instance->groupTime = GetDlgItemInt(hwndDlg, IDC_GROUPTIME, &success, FALSE);
instance->groupMessagesNumber = GetDlgItemInt(hwndDlg, IDC_LIMITMESSAGES, &success, FALSE);
Options::instance->Save();
OptionsGroupChanged();
}
return TRUE;
}
return FALSE;
}
INT_PTR CALLBACK Options::DlgProcOptsMessages(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
CheckDlgButton(hwndDlg, IDC_NEWONTOP, instance->messagesNewOnTop ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWDATE, instance->messagesShowDate ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWSECOND, instance->messagesShowSec ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWNAME, instance->messagesShowName ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWEVENTS, instance->messagesShowEvents ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SHOWSMILEYS, instance->messagesUseSmileys ? BST_CHECKED : BST_UNCHECKED);
if (!g_SmileyAddAvail)
EnableWindow(GetDlgItem(hwndDlg, IDC_SHOWSMILEYS), FALSE);
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
instance->messagesNewOnTop = IsDlgButtonChecked(hwndDlg, IDC_NEWONTOP) ? true : false;
instance->messagesShowDate = IsDlgButtonChecked(hwndDlg, IDC_SHOWDATE) ? true : false;
instance->messagesShowSec = IsDlgButtonChecked(hwndDlg, IDC_SHOWSECOND) ? true : false;
instance->messagesShowName = IsDlgButtonChecked(hwndDlg, IDC_SHOWNAME) ? true : false;
instance->messagesShowEvents = IsDlgButtonChecked(hwndDlg, IDC_SHOWEVENTS) ? true : false;
instance->messagesUseSmileys = IsDlgButtonChecked(hwndDlg, IDC_SHOWSMILEYS) ? true : false;
Options::instance->Save();
OptionsMessageChanged();
}
return TRUE;
}
return FALSE;
}
INT_PTR CALLBACK Options::DlgProcOptsSearching(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
CheckDlgButton(hwndDlg, IDC_FORLIST, instance->searchForInList ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_FORMES, instance->searchForInMess ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_MATCHCASE, instance->searchMatchCase ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_MATCHWHOLE, instance->searchMatchWhole ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_ONLYIN, instance->searchOnlyIn ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_ONLYOUT, instance->searchOnlyOut ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_ONLYGROUP, instance->searchOnlyGroup ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_ALLCONTACTS, instance->searchAllContacts ? BST_CHECKED : BST_UNCHECKED);
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_ONLYIN) {
if (IsDlgButtonChecked(hwndDlg, IDC_ONLYIN) && IsDlgButtonChecked(hwndDlg, IDC_ONLYOUT))
CheckDlgButton(hwndDlg, IDC_ONLYOUT, BST_UNCHECKED);
}
else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_ONLYOUT) {
if (IsDlgButtonChecked(hwndDlg, IDC_ONLYOUT) && IsDlgButtonChecked(hwndDlg, IDC_ONLYIN))
CheckDlgButton(hwndDlg, IDC_ONLYIN, BST_UNCHECKED);
}
if (HIWORD(wParam) == BN_CLICKED)
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
instance->searchForInList = IsDlgButtonChecked(hwndDlg, IDC_FORLIST) ? true : false;
instance->searchForInMess = IsDlgButtonChecked(hwndDlg, IDC_FORMES) ? true : false;
instance->searchMatchCase = IsDlgButtonChecked(hwndDlg, IDC_MATCHCASE) ? true : false;
instance->searchMatchWhole = IsDlgButtonChecked(hwndDlg, IDC_MATCHWHOLE) ? true : false;
instance->searchOnlyIn = IsDlgButtonChecked(hwndDlg, IDC_ONLYIN) ? true : false;
instance->searchOnlyOut = IsDlgButtonChecked(hwndDlg, IDC_ONLYOUT) ? true : false;
instance->searchOnlyGroup = IsDlgButtonChecked(hwndDlg, IDC_ONLYGROUP) ? true : false;
instance->searchAllContacts = IsDlgButtonChecked(hwndDlg, IDC_ALLCONTACTS) ? true : false;
Options::instance->Save();
OptionsSearchingChanged();
}
return TRUE;
}
return FALSE;
}
void InitCodepageCB(HWND hwndCB, unsigned int codepage, const std::wstring& name)
{
int cpCount = sizeof(cpTable) / sizeof(cpTable[0]);
int selCpIdx = -1;
ComboBox_LimitText(hwndCB, 256);
for (int i = 0; i < cpCount; ++i) {
ComboBox_AddString(hwndCB, TranslateW(cpTable[i].cpName));
if (cpTable[i].cpId == codepage && name == cpTable[i].cpName)
selCpIdx = i;
}
if (selCpIdx == -1) {
wchar_t buf[300];
mir_snwprintf(buf, L"%d;%s", codepage, name.c_str());
ComboBox_SetText(hwndCB, buf);
}
else ComboBox_SetCurSel(hwndCB, selCpIdx);
ComboBox_LimitText(hwndCB, 127);
}
unsigned int GetCodepageCB(HWND hwndCB, bool errorReport, unsigned int, const std::wstring& defName, std::wstring& name)
{
int selCpIdx = ComboBox_GetCurSel(hwndCB);
if (selCpIdx < 0) {
wchar_t text[128];
ComboBox_GetText(hwndCB, text, 128);
std::wstring str = text;
name = L"";
size_t pos = str.find_first_of(';');
if (pos < str.length()) {
text[pos] = 0;
name = str.substr(pos + 1);
}
wchar_t * stopOn = nullptr;
long cp = wcstol(text, &stopOn, 10);
if ((pos >= str.length() || name.empty() || stopOn == text || *stopOn != '\0' || cp < 0 || cp > 0xffff)) {
if (errorReport) {
MessageBox(GetParent(hwndCB), TranslateT("You've entered invalid codepage. Select codepage from combo box or enter correct number."), TranslateT("Invalid codepage"), MB_OK | MB_ICONERROR);
SetFocus(hwndCB);
}
name = defName;
return -1;
}
return cp;
}
else {
name = cpTable[selCpIdx].cpName;
return cpTable[selCpIdx].cpId;
}
}
INT_PTR CALLBACK Options::DlgProcOptsExport(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)FALSE);
InitCodepageCB(GetDlgItem(hwndDlg, IDC_TXTENC), instance->codepageTxt, instance->encodingTxt);
InitCodepageCB(GetDlgItem(hwndDlg, IDC_HTML1ENC), instance->codepageHtml1, instance->encodingHtml1);
InitCodepageCB(GetDlgItem(hwndDlg, IDC_HTML2ENC), instance->codepageHtml2, instance->encodingHtml2);
CheckDlgButton(hwndDlg, IDC_HTML1DATE, instance->exportHtml1ShowDate ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_HTML2DATE, instance->exportHtml2ShowDate ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_HTML2SHOWSMILEYS, instance->exportHtml2UseSmileys ? BST_CHECKED : BST_UNCHECKED);
Edit_LimitText(GetDlgItem(hwndDlg, IDC_HTML2EXTCSSFILE), MAX_PATH);
if (instance->extCssHtml2.empty()) {
EnableWindow(GetDlgItem(hwndDlg, IDC_HTML2EXTCSSFILE), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CSS_BROWSE), FALSE);
}
else {
CheckDlgButton(hwndDlg, IDC_HTML2EXTCSS, BST_CHECKED);
Edit_SetText(GetDlgItem(hwndDlg, IDC_HTML2EXTCSSFILE), instance->extCssHtml2.c_str());
}
if (!g_SmileyAddAvail)
EnableWindow(GetDlgItem(hwndDlg, IDC_HTML2SHOWSMILEYS), FALSE);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)TRUE);
return TRUE;
case WM_COMMAND:
{
BOOL init = (BOOL)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_HTML2EXTCSS) {
BOOL en = (BOOL)IsDlgButtonChecked(hwndDlg, IDC_HTML2EXTCSS);
EnableWindow(GetDlgItem(hwndDlg, IDC_HTML2EXTCSSFILE), en);
EnableWindow(GetDlgItem(hwndDlg, IDC_CSS_BROWSE), en);
}
else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_CSS_BROWSE) {
if (!OpenFileDlg(hwndDlg, GetDlgItem(hwndDlg, IDC_HTML2EXTCSSFILE), L"", L"css", TranslateT("Browse CSS file"), true))
return TRUE;
}
if (init && (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE || HIWORD(wParam) == EN_CHANGE))
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
return TRUE;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
std::wstring newName1, newName2, newName3;
unsigned int cp1 = GetCodepageCB(GetDlgItem(hwndDlg, IDC_TXTENC), true, instance->codepageTxt, instance->encodingTxt, newName1);
if (cp1 == -1) {
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
return TRUE;
}
unsigned int cp2 = GetCodepageCB(GetDlgItem(hwndDlg, IDC_HTML1ENC), true, instance->codepageHtml1, instance->encodingHtml1, newName2);
if (cp2 == -1) {
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
return TRUE;
}
unsigned int cp3 = GetCodepageCB(GetDlgItem(hwndDlg, IDC_HTML2ENC), true, instance->codepageHtml2, instance->encodingHtml2, newName3);
if (cp3 == -1) {
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
return TRUE;
}
if (IsDlgButtonChecked(hwndDlg, IDC_HTML2EXTCSS)) {
if (!CheckFile(GetDlgItem(hwndDlg, IDC_HTML2EXTCSSFILE))) {
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
return TRUE;
}
wchar_t buf[MAX_PATH];
Edit_GetText(GetDlgItem(hwndDlg, IDC_HTML2EXTCSSFILE), buf, MAX_PATH);
instance->extCssHtml2 = buf;
}
else instance->extCssHtml2 = L"";
instance->codepageTxt = cp1;
instance->encodingTxt = newName1;
instance->codepageHtml1 = cp2;
instance->encodingHtml1 = newName2;
instance->codepageHtml2 = cp3;
instance->encodingHtml2 = newName3;
instance->exportHtml1ShowDate = IsDlgButtonChecked(hwndDlg, IDC_HTML1DATE) ? true : false;
instance->exportHtml2ShowDate = IsDlgButtonChecked(hwndDlg, IDC_HTML2DATE) ? true : false;
instance->exportHtml2UseSmileys = IsDlgButtonChecked(hwndDlg, IDC_HTML2SHOWSMILEYS) ? true : false;
Options::instance->Save();
}
return TRUE;
}
return FALSE;
}
struct DlgTaskOpt
{
std::list<TaskOptions>* tasks;
TaskOptions* to;
};
INT_PTR CALLBACK Options::DlgProcOptsScheduler(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
std::list<TaskOptions>* tasks = (std::list<TaskOptions>*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
tasks = new std::list<TaskOptions>(Options::instance->taskOptions.begin(), Options::instance->taskOptions.end());
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)tasks);
HWND listTasks = GetDlgItem(hwndDlg, IDC_LIST_TASKS);
for (std::list<TaskOptions>::iterator it = tasks->begin(); it != tasks->end(); ++it)
ListBox_AddString(listTasks, it->taskName.c_str());
if (!bPopupsEnabled)
EnableWindow(GetDlgItem(hwndDlg, IDC_SCHEDULER_ALERTS), FALSE);
CheckDlgButton(hwndDlg, IDC_SCHEDULER_ALERTS, instance->schedulerAlerts ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SCHEDULER_HISTORY_ALERTS, instance->schedulerHistoryAlerts ? BST_CHECKED : BST_UNCHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_TASK), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_TASK), FALSE);
}
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
HWND listTasks = GetDlgItem(hwndDlg, IDC_LIST_TASKS);
int sel = ListBox_GetCurSel(listTasks);
TaskOptions toAdd;
TaskOptions* to = &toAdd;
switch (LOWORD(wParam)) {
case IDC_EDIT_TASK:
if (sel >= 0) {
std::list<TaskOptions>::iterator it = tasks->begin();
while (sel-- > 0 && it != tasks->end())
++it;
if (it == tasks->end())
break;
to = &(*it);
}
else break;
case IDC_ADD_TASK:
{
DlgTaskOpt top;
top.tasks = tasks;
top.to = to;
if (DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DLG_TASK), hwndDlg, DlgProcOptsTask, (LPARAM)&top) == IDOK) {
if (LOWORD(wParam) == IDC_ADD_TASK) {
tasks->push_back(*to);
ListBox_AddString(listTasks, to->taskName.c_str());
ListBox_SetCurSel(listTasks, tasks->size() - 1);
}
else {
sel = ListBox_GetCurSel(listTasks);
ListBox_DeleteString(listTasks, sel);
ListBox_InsertString(listTasks, sel, to->taskName.c_str());
ListBox_SetCurSel(listTasks, sel);
}
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_TASK), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_TASK), TRUE);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
}
break;
case IDC_DELETE_TASK:
if (sel >= 0) {
ListBox_DeleteString(listTasks, sel);
std::list<TaskOptions>::iterator it = tasks->begin();
while (sel-- > 0 && it != tasks->end())
++it;
if (it != tasks->end())
tasks->erase(it);
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_TASK), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_TASK), FALSE);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
break;
default:
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
}
else if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_LIST_TASKS) {
HWND listTasks = GetDlgItem(hwndDlg, IDC_LIST_TASKS);
int sel = ListBox_GetCurSel(listTasks);
if (sel < 0) {
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_TASK), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_TASK), FALSE);
}
else {
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_TASK), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_TASK), TRUE);
}
}
return TRUE;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
instance->schedulerAlerts = IsDlgButtonChecked(hwndDlg, IDC_SCHEDULER_ALERTS) ? true : false;
instance->schedulerHistoryAlerts = IsDlgButtonChecked(hwndDlg, IDC_SCHEDULER_HISTORY_ALERTS) ? true : false;
Options::instance->SaveTasks(tasks);
OptionsSchedulerChanged();
InitTaskMenuItems();
}
return TRUE;
case WM_DESTROY:
delete tasks;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
break;
}
return FALSE;
}
void RebuildList(HWND hwnd, MCONTACT hSystem, TaskOptions* to)
{
HANDLE hItem;
if (to->isSystem && hSystem)
SendMessage(hwnd, CLM_SETCHECKMARK, (WPARAM)hSystem, 1);
for (size_t i = 0; i < to->contacts.size(); ++i) {
hItem = (HANDLE)SendMessage(hwnd, CLM_FINDCONTACT, (WPARAM)to->contacts[i], 0);
if (hItem)
SendMessage(hwnd, CLM_SETCHECKMARK, (WPARAM)hItem, 1);
}
}
void SaveList(HWND hwnd, MCONTACT hSystem, TaskOptions* to)
{
to->contacts.clear();
if (hSystem)
to->isSystem = SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM)hSystem, 0) != 0;
for (auto &hContact : Contacts()) {
HANDLE hItem = (HANDLE)SendMessage(hwnd, CLM_FINDCONTACT, hContact, 0);
if (hItem && SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
to->contacts.push_back(hContact);
}
}
bool IsValidTask(TaskOptions& to, std::list<TaskOptions>* top = nullptr, std::wstring* err = nullptr, std::wstring* errDescr = nullptr);
#ifndef LOCALE_SSHORTTIME
#define LOCALE_SSHORTTIME 0x00000079
#endif
INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static MCONTACT hSystem;
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
DlgTaskOpt* top = (DlgTaskOpt*)lParam;
TaskOptions* to = top->to;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
HWND comboType = GetDlgItem(hwndDlg, IDC_TASK_TYPE);
HWND filter = GetDlgItem(hwndDlg, IDC_TASK_FILTER);
HWND eventUnit = GetDlgItem(hwndDlg, IDC_EVENT_UNIT);
HWND trigerType = GetDlgItem(hwndDlg, IDC_TRIGER_TYPE);
HWND exportType = GetDlgItem(hwndDlg, IDC_EXPORT_TYPE);
HWND importType = GetDlgItem(hwndDlg, IDC_IMPORT_TYPE);
HWND compress = GetDlgItem(hwndDlg, IDC_COMPRESS);
HWND exportPath = GetDlgItem(hwndDlg, IDC_EXPORT_PATH);
HWND ftpFile = GetDlgItem(hwndDlg, IDC_FTP);
HWND ftpFileButton = GetDlgItem(hwndDlg, IDC_UPLOAD);
HWND contactList = GetDlgItem(hwndDlg, IDC_LIST_CONTACTSEX);
HWND weekList = GetDlgItem(hwndDlg, IDC_TRIGER_WEEK);
HWND day = GetDlgItem(hwndDlg, IDC_TRIGER_DAY);
HWND deltaTime = GetDlgItem(hwndDlg, IDC_TRIGER_DELTA_TIME);
HWND time = GetDlgItem(hwndDlg, IDC_TRIGER_TIME);
HWND name = GetDlgItem(hwndDlg, IDC_TASK_NAME);
HWND active = GetDlgItem(hwndDlg, IDC_TASK_ACTIVE);
HWND password = GetDlgItem(hwndDlg, IDC_PASSWORD);
HWND expImp = GetDlgItem(hwndDlg, IDC_EXPIMP);
Edit_LimitText(name, 16);
Edit_SetText(name, to->taskName.c_str());
Button_SetCheck(active, to->active);
Button_SetCheck(expImp, to->exportImported);
ComboBox_AddString(comboType, TranslateT("Export"));
ComboBox_AddString(comboType, TranslateT("Delete"));
ComboBox_AddString(comboType, TranslateT("Export and delete"));
ComboBox_AddString(comboType, TranslateT("Import"));
ComboBox_AddString(comboType, TranslateT("Import and merge"));
ComboBox_SetCurSel(comboType, to->type);
Edit_LimitText(GetDlgItem(hwndDlg, IDC_EVENT_TIME), 6);
SetDlgItemInt(hwndDlg, IDC_EVENT_TIME, to->eventDeltaTime, TRUE);
ComboBox_AddString(eventUnit, TranslateT("Minute"));
ComboBox_AddString(eventUnit, TranslateT("Hour"));
ComboBox_AddString(eventUnit, TranslateT("Day"));
ComboBox_SetCurSel(eventUnit, to->eventUnit);
ComboBox_AddString(filter, TranslateT("Default history events"));
ComboBox_AddString(filter, TranslateT("All events"));
int selFilter = to->filterId;
if (selFilter > 1)
selFilter = 0;
int i = 1;
for (std::vector<FilterOptions>::iterator it = instance->customFilters.begin(); it != instance->customFilters.end(); ++it) {
++i;
ComboBox_AddString(filter, it->name.c_str());
if (to->filterId > 1 && it->name == to->filterName)
selFilter = i;
}
ComboBox_SetCurSel(filter, selFilter);
ComboBox_AddString(trigerType, TranslateT("At start"));
ComboBox_AddString(trigerType, TranslateT("At finish"));
ComboBox_AddString(trigerType, TranslateT("Daily"));
ComboBox_AddString(trigerType, TranslateT("Weekly"));
ComboBox_AddString(trigerType, TranslateT("Monthly"));
ComboBox_AddString(trigerType, TranslateT("Delta time (minutes)"));
ComboBox_AddString(trigerType, TranslateT("Delta time (hours)"));
ComboBox_SetCurSel(trigerType, to->trigerType);
ComboBox_AddString(exportType, TranslateT("Rich HTML"));
ComboBox_AddString(exportType, TranslateT("Plain HTML"));
ComboBox_AddString(exportType, TranslateT("Txt"));
ComboBox_AddString(exportType, TranslateT("Binary"));
ComboBox_AddString(exportType, TranslateT("Dat (mContacts)"));
ComboBox_SetCurSel(exportType, to->exportType);
ComboBox_AddString(importType, TranslateT("Binary"));
ComboBox_AddString(importType, TranslateT("Dat (mContacts)"));
ComboBox_SetCurSel(importType, to->importType);
Button_SetCheck(compress, to->compress);
Edit_LimitText(password, 99);
SetWindowTextA(password, to->zipPassword.c_str());
Edit_LimitText(exportPath, MAX_PATH);
Edit_SetText(exportPath, to->filePath.c_str());
if (!FTPAvail()) {
EnableWindow(ftpFile, FALSE);
EnableWindow(ftpFileButton, FALSE);
to->useFtp = false;
}
Button_SetCheck(ftpFileButton, to->useFtp);
Edit_SetText(ftpFile, to->ftpName.c_str());
ComboBox_AddString(weekList, TranslateT("Monday"));
ComboBox_AddString(weekList, TranslateT("Tuesday"));
ComboBox_AddString(weekList, TranslateT("Wednesday"));
ComboBox_AddString(weekList, TranslateT("Thursday"));
ComboBox_AddString(weekList, TranslateT("Friday"));
ComboBox_AddString(weekList, TranslateT("Saturday"));
ComboBox_AddString(weekList, TranslateT("Sunday"));
ComboBox_SetCurSel(weekList, to->dayOfWeek);
Edit_LimitText(day, 2);
SetDlgItemInt(hwndDlg, IDC_TRIGER_DAY, to->dayOfMonth, FALSE);
Edit_LimitText(deltaTime, 4);
SetDlgItemInt(hwndDlg, IDC_TRIGER_DELTA_TIME, to->deltaTime, FALSE);
wchar_t timeFormat[10];
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTTIME, timeFormat, 10) == 0) {
wchar_t sep = ':';
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STIME, timeFormat, 10) > 0)
sep = timeFormat[0];
mir_snwprintf(timeFormat, L"HH%cmm", sep);
}
SYSTEMTIME st;
GetSystemTime(&st);
st.wHour = to->dayTime / 60;
st.wMinute = to->dayTime % 60;
st.wSecond = 0;
st.wMilliseconds = 0;
DateTime_SetFormat(time, timeFormat);
DateTime_SetSystemtime(time, GDT_VALID, &st);
CLCINFOITEM cii = { 0 };
cii.cbSize = sizeof(cii);
cii.flags = CLCIIF_GROUPFONT | CLCIIF_CHECKBOX | CLCIIF_BELOWCONTACTS;
cii.pszText = TranslateT("System");
hSystem = (MCONTACT)SendMessage(contactList, CLM_ADDINFOITEM, 0, (LPARAM)& cii);
SendMessage(contactList, CLM_AUTOREBUILD, 0, 0);
RebuildList(contactList, hSystem, to);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_TASK_TYPE, CBN_SELCHANGE), NULL);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_TRIGER_TYPE, CBN_SELCHANGE), NULL);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_COMPRESS, BN_CLICKED), NULL);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_UPLOAD, BN_CLICKED), NULL);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_COMPRESS, BN_CLICKED), NULL);
}
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
if (LOWORD(wParam) == IDOK) {
DlgTaskOpt* top = (DlgTaskOpt*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
TaskOptions* to = top->to;
TaskOptions toCp(*to);
toCp.taskName.resize(17);
int nameLen = Edit_GetText(GetDlgItem(hwndDlg, IDC_TASK_NAME), (wchar_t*)toCp.taskName.c_str(), 17);
toCp.taskName.resize(nameLen);
toCp.active = Button_GetCheck(GetDlgItem(hwndDlg, IDC_TASK_ACTIVE)) != 0;
toCp.exportImported = Button_GetCheck(GetDlgItem(hwndDlg, IDC_EXPIMP)) != 0;
toCp.type = (enum TaskOptions::TaskType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_TASK_TYPE));
toCp.filterId = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_TASK_FILTER));
if (toCp.filterId > 1)
toCp.filterName = instance->customFilters[toCp.filterId - 2].name;
BOOL isOK = FALSE;
toCp.eventDeltaTime = GetDlgItemInt(hwndDlg, IDC_EVENT_TIME, &isOK, TRUE);
if (!isOK) {
wchar_t tszBuf[256];
mir_snwprintf(tszBuf, TranslateT("Invalid '%s' value."), TranslateT("Events older than"));
MessageBox(hwndDlg, tszBuf, TranslateT("Error"), MB_ICONERROR);
break;
}
toCp.eventUnit = (enum TaskOptions::EventUnit)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_EVENT_UNIT));
toCp.trigerType = (enum TaskOptions::TrigerType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_TRIGER_TYPE));
toCp.exportType = (enum IExport::ExportType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE));
toCp.importType = (enum IImport::ImportType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_IMPORT_TYPE));
toCp.compress = Button_GetCheck(GetDlgItem(hwndDlg, IDC_COMPRESS)) != 0;
char bufC[100];
GetDlgItemTextA(hwndDlg, IDC_PASSWORD, bufC, _countof(bufC));
toCp.zipPassword = bufC;
HWND exportPath = GetDlgItem(hwndDlg, IDC_EXPORT_PATH);
int exLen = Edit_GetTextLength(exportPath);
toCp.filePath.resize(exLen + 1);
Edit_GetText(exportPath, (wchar_t*)toCp.filePath.c_str(), exLen + 1);
toCp.filePath.resize(exLen);
toCp.useFtp = Button_GetCheck(GetDlgItem(hwndDlg, IDC_UPLOAD)) != 0;
HWND ftpFile = GetDlgItem(hwndDlg, IDC_FTP);
exLen = Edit_GetTextLength(ftpFile);
toCp.ftpName.resize(exLen + 1);
Edit_GetText(ftpFile, (wchar_t*)toCp.ftpName.c_str(), exLen + 1);
toCp.ftpName.resize(exLen);
SYSTEMTIME st;
DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_TRIGER_TIME), &st);
toCp.dayTime = st.wHour * 60 + st.wMinute;
toCp.dayOfWeek = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_TRIGER_WEEK));
toCp.dayOfMonth = GetDlgItemInt(hwndDlg, IDC_TRIGER_DAY, &isOK, FALSE);
if (!isOK) {
if (toCp.trigerType == TaskOptions::Monthly) {
wchar_t tszBuf[256];
mir_snwprintf(tszBuf, TranslateT("Invalid '%s' value."), TranslateT("Day"));
MessageBox(hwndDlg, tszBuf, TranslateT("Error"), MB_ICONERROR);
break;
}
else toCp.dayOfMonth = to->dayOfMonth;
}
toCp.deltaTime = GetDlgItemInt(hwndDlg, IDC_TRIGER_DELTA_TIME, &isOK, FALSE);
if (!isOK) {
if (toCp.trigerType == TaskOptions::DeltaMin || toCp.trigerType == TaskOptions::DeltaHour) {
wchar_t tszBuf[256];
mir_snwprintf(tszBuf, TranslateT("Invalid '%s' value."), TranslateT("Delta time"));
MessageBox(hwndDlg, tszBuf, TranslateT("Error"), MB_ICONERROR);
break;
}
else toCp.deltaTime = to->deltaTime;
}
SaveList(GetDlgItem(hwndDlg, IDC_LIST_CONTACTSEX), hSystem, &toCp);
std::wstring err;
std::wstring errDescr;
std::wstring lastName = to->taskName;
to->taskName = L"";
if (!IsValidTask(toCp, top->tasks, &err, &errDescr)) {
to->taskName = lastName;
wchar_t tszBuf[256];
if (err.empty())
wcscpy_s(tszBuf, TranslateT("Some value is invalid"));
else if (errDescr.empty())
mir_snwprintf(tszBuf, TranslateT("Invalid '%s' value."), err.c_str());
else
mir_snwprintf(tszBuf, TranslateT("Invalid '%s' value.\n%s"), err.c_str(), errDescr.c_str());
MessageBox(hwndDlg, tszBuf, TranslateT("Error"), MB_ICONERROR);
break;
}
toCp.lastExport = time(0);
*to = toCp;
EndDialog(hwndDlg, IDOK);
}
else if (LOWORD(wParam) == IDCANCEL) {
EndDialog(hwndDlg, IDCANCEL);
}
else if (LOWORD(wParam) == IDC_UPLOAD) {
if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_UPLOAD)) == 0)
EnableWindow(GetDlgItem(hwndDlg, IDC_FTP), FALSE);
else
EnableWindow(GetDlgItem(hwndDlg, IDC_FTP), TRUE);
}
else if (LOWORD(wParam) == IDC_COMPRESS) {
if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_COMPRESS)) == 0) {
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD_LABEL), FALSE);
}
else {
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD_LABEL), TRUE);
}
}
}
else if (HIWORD(wParam) == CBN_SELCHANGE) {
if (LOWORD(wParam) == IDC_TASK_TYPE) {
TaskOptions::TaskType sel = (enum TaskOptions::TaskType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_TASK_TYPE));
int show = sel == TaskOptions::Delete ? SW_HIDE : SW_SHOW;
int showFilter = (sel == TaskOptions::Import || sel == TaskOptions::ImportAndMarge) ? SW_HIDE : SW_SHOW;
int showImport = (sel == TaskOptions::Import || sel == TaskOptions::ImportAndMarge) ? SW_SHOW : SW_HIDE;
ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE_LABEL), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_COMPRESS), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_PASSWORD_LABEL), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PATH), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PATH_LABEL), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_FTP), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_UPLOAD), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_FTP_LABEL), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_EXPIMP), show);
ShowWindow(GetDlgItem(hwndDlg, IDC_TASK_FILTER), showFilter);
ShowWindow(GetDlgItem(hwndDlg, IDC_TASK_FILTER_LABEL), showFilter);
ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_TIME), showFilter);
ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_UNIT), showFilter);
ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_LABEL), showFilter);
if (show != showFilter) {
ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE), SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg, IDC_EXPIMP), SW_HIDE);
}
ShowWindow(GetDlgItem(hwndDlg, IDC_IMPORT_TYPE), showImport);
std::wstring str;
wchar_t* compressText = TranslateT("Compress output files");
wchar_t* uploadText = TranslateT("Upload to FTP (WinSCP requred)");
wchar_t* typeText = TranslateT("Export to");
if (showFilter == SW_HIDE) {
str = TranslateT("** Use <ext> to insert extension, <contact> to insert contact name");
compressText = TranslateT("Input files are compressed");
uploadText = TranslateT("Download from FTP (WinSCP requred)");
typeText = TranslateT("Import from");
}
else if (show == SW_HIDE)
str = TranslateT("* Use negative values to filter younger events");
else {
str = TranslateT("* Use negative values to filter younger events");
str += L"\n";
str += TranslateT("** Use <date> to insert date, <ext> to insert extension, <contact> to insert contact name");
}
Static_SetText(GetDlgItem(hwndDlg, IDC_TASK_STAR), str.c_str());
Button_SetText(GetDlgItem(hwndDlg, IDC_COMPRESS), compressText);
Button_SetText(GetDlgItem(hwndDlg, IDC_UPLOAD), uploadText);
Static_SetText(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE_LABEL), typeText);
}
else if (LOWORD(wParam) == IDC_TRIGER_TYPE) {
TaskOptions::TrigerType sel = (enum TaskOptions::TrigerType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_TRIGER_TYPE));
int showT = (sel == TaskOptions::Daily || sel == TaskOptions::Weekly || sel == TaskOptions::Monthly) ? SW_SHOW : SW_HIDE;
int showW = sel == TaskOptions::Weekly ? SW_SHOW : SW_HIDE;
int showM = sel == TaskOptions::Monthly ? SW_SHOW : SW_HIDE;
int showDT = (sel == TaskOptions::DeltaMin || sel == TaskOptions::DeltaHour) ? SW_SHOW : SW_HIDE;
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_TIME), showT);
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_TIME_LABEL), showT);
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_WEEK), showW);
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_WEEK_LABEL), showW);
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DAY), showM);
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DAY_LABEL), showM);
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DELTA_TIME), showDT);
ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DELTA_TIME_LABEL), showDT);
}
}
return TRUE;
}
return FALSE;
}
bool Options::FTPAvail()
{
DWORD atr = GetFileAttributes(instance->ftpExePath.c_str());
return !(atr == INVALID_FILE_ATTRIBUTES || atr & FILE_ATTRIBUTE_DIRECTORY);
}
|