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
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
|
#include "stdafx.h"
#include "CConfig.h"
#include "CAppletManager.h"
#include "m_system.h"
// specifies how long contact status notifications are ignored after signon
#define PROTOCOL_NOTIFY_DELAY 1500
//########################################################################
// functions
//########################################################################
//************************************************************************
// returns the AppletManager's instance
//************************************************************************
CAppletManager *CAppletManager::GetInstance()
{
return (CAppletManager*)CLCDOutputManager::GetInstance();
}
//************************************************************************
// Constructor
//************************************************************************
CAppletManager::CAppletManager()
{
m_uiTimer = NULL;
m_pLastScreen = NULL;
}
//************************************************************************
// Destructor
//************************************************************************
CAppletManager::~CAppletManager()
{
}
//************************************************************************
// Initializes the AppletManager
//************************************************************************
bool CAppletManager::Initialize(tstring strAppletName)
{
if(!CLCDOutputManager::Initialize(strAppletName))
return false;
GetLCDConnection()->Connect(CConfig::GetIntSetting(DEVICE));
// set the volumewheel hook
SetVolumeWheelHook();
// initialize the screens
m_NotificationScreen.Initialize();
m_EventScreen.Initialize();
m_ContactlistScreen.Initialize();
m_ChatScreen.Initialize();
m_CreditsScreen.Initialize();
m_ScreensaverScreen.Initialize();
// add the screens to the list
AddScreen(&m_NotificationScreen);
AddScreen(&m_EventScreen);
AddScreen(&m_ContactlistScreen);
AddScreen(&m_ChatScreen);
AddScreen(&m_CreditsScreen);
AddScreen(&m_ScreensaverScreen);
// activate the event screen
ActivateScreen(&m_EventScreen);
// hook the neccessary events
m_hMIHookMessageWindowEvent = HookEvent(ME_MSG_WINDOWEVENT,CAppletManager::HookMessageWindowEvent);
m_hMIHookEventAdded = HookEvent(ME_DB_EVENT_ADDED, CAppletManager::HookEventAdded);
m_hMIHookStatusChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, CAppletManager::HookStatusChanged);
m_hMIHookProtoAck = HookEvent(ME_PROTO_ACK, CAppletManager::HookProtoAck);
m_hMIHookContactDeleted = HookEvent(ME_DB_CONTACT_DELETED, CAppletManager::HookContactDeleted);
m_hMIHookContactAdded = HookEvent(ME_DB_CONTACT_ADDED, CAppletManager::HookContactAdded);
m_hMIHookSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED,CAppletManager::HookSettingChanged);
m_hMIHookContactIsTyping = HookEvent(ME_PROTO_CONTACTISTYPING,CAppletManager::HookContactIsTyping);
// enumerate protocols
int iCount;
int iProtoCount = 0;
PROTOACCOUNT **ppAccounts;
CProtocolData *pProtoData = NULL;
CIRCConnection *pIRCConnection = NULL;
CallService(MS_PROTO_ENUMACCOUNTS,(WPARAM)&iCount,(LPARAM)&ppAccounts);
for(int i=0;i<iCount;i++)
{
/**if(ppProtocolDescriptor[i]->type != PROTOTYPE_PROTOCOL)
continue;**/
if (ppAccounts[i]->bIsEnabled == 0)
continue;
iProtoCount++;
pProtoData = new CProtocolData();
pProtoData->iStatus = ID_STATUS_OFFLINE;
pProtoData->strProtocol = toTstring(ppAccounts[i]->szModuleName);
pProtoData->lTimeStamp = 0;
// try to create an irc connection for that protocol (will fail if it is no irc protocol)
pIRCConnection = CreateIRCConnection(pProtoData->strProtocol);
m_vProtocolData.push_back(pProtoData);
}
// load status bitmaps
m_ahStatusBitmaps[0] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_OFFLINE),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
m_ahStatusBitmaps[1] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_ONLINE),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
m_ahStatusBitmaps[2] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_AWAY),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
m_ahStatusBitmaps[3] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_NA),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
m_ahStatusBitmaps[4] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_OCCUPIED),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
m_ahStatusBitmaps[5] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_DND),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
m_ahStatusBitmaps[6] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_INVISIBLE),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
m_ahStatusBitmaps[7] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_STATUS_FFC),
IMAGE_BITMAP,5, 5, LR_MONOCHROME);
// Load event bitmaps
m_ahEventBitmaps[0] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_MSG),
IMAGE_BITMAP,6, 6, LR_MONOCHROME);
m_ahEventBitmaps[1] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_CON),
IMAGE_BITMAP,6, 6, LR_MONOCHROME);
m_ahEventBitmaps[2] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_USER),
IMAGE_BITMAP,6, 6, LR_MONOCHROME);
m_ahEventBitmaps[3] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_INFO),
IMAGE_BITMAP,6, 6, LR_MONOCHROME);
m_ahLargeEventBitmaps[0] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_MSG_LARGE),
IMAGE_BITMAP,8, 8, LR_MONOCHROME);
m_ahLargeEventBitmaps[1] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_CON_LARGE),
IMAGE_BITMAP,8, 8, LR_MONOCHROME);
m_ahLargeEventBitmaps[2] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_USER_LARGE),
IMAGE_BITMAP,8, 8, LR_MONOCHROME);
m_ahLargeEventBitmaps[3] = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_EVENT_INFO_LARGE),
IMAGE_BITMAP,8, 8, LR_MONOCHROME);
// start the update timer
m_uiTimer = SetTimer(0,0,1000/10,CAppletManager::UpdateTimer);
return true;
}
//************************************************************************
// Deinitializes the AppletManager
//************************************************************************
bool CAppletManager::Shutdown()
{
if(!IsInitialized())
return false;
// stop the update timer
KillTimer(0,m_uiTimer);
// delete status bitmaps
for(int i=0;i<8;i++)
DeleteObject(m_ahStatusBitmaps[i]);
// delete event bitmaps
for(int i=0;i<8;i++)
{
DeleteObject(m_ahLargeEventBitmaps[i]);
DeleteObject(m_ahEventBitmaps[i]);
}
// unhook the events
UnhookEvent(m_hMIHookMessageWindowEvent);
UnhookEvent(m_hMIHookEventAdded);
UnhookEvent(m_hMIHookStatusChanged);
UnhookEvent(m_hMIHookProtoAck);
UnhookEvent(m_hMIHookContactDeleted);
UnhookEvent(m_hMIHookContactAdded);
UnhookEvent(m_hMIHookSettingChanged);
// unhook all irc protocols, and delete the classes
vector<CIRCConnection*>::iterator iter = m_vIRCConnections.begin();
while(iter != m_vIRCConnections.end())
{
UnhookEvent((*iter)->hEventHook);
delete *iter;
iter++;
}
m_vIRCConnections.clear();
// Deinitialize the screens
m_NotificationScreen.Shutdown();
m_EventScreen.Shutdown();
m_ContactlistScreen.Shutdown();
m_ChatScreen.Shutdown();
m_CreditsScreen.Shutdown();
m_ScreensaverScreen.Shutdown();
// deinitialize the configuration manager
CConfig::Shutdown();
// delete the protocol information
CProtocolData *pProtoData;
for(int i=0;i<m_vProtocolData.size();i++)
{
pProtoData = m_vProtocolData[i];
delete pProtoData;
}
m_vProtocolData.clear();
// deinitialize the outputmanager
if(!CLCDOutputManager::Shutdown())
return false;
return true;
}
//************************************************************************
// Translates the specified string, and inserts the parameters
//************************************************************************
tstring CAppletManager::TranslateString(TCHAR *szString,...)
{
TCHAR out[1024];
TCHAR *szTranslatedString = TranslateTS(szString);
va_list body;
va_start(body, szString);
_vstprintf(out, szTranslatedString, body);
va_end(body);
return out;
}
//************************************************************************
// checks if the patched IRC protocol is in place
//************************************************************************
bool CAppletManager::IsIRCHookEnabled()
{
if(m_vIRCConnections.size() == NULL)
return false;
return true;
}
//************************************************************************
// returns the informations structure for the specified protocol
//************************************************************************
CProtocolData* CAppletManager::GetProtocolData(tstring strProtocol)
{
for(int i=0;i<m_vProtocolData.size();i++)
{
if(m_vProtocolData[i]->strProtocol == strProtocol)
return m_vProtocolData[i];
}
return NULL;
}
//************************************************************************
// Updates the AppletManager
//************************************************************************
bool CAppletManager::Update()
{
if(!CLCDOutputManager::Update())
return false;
// Update Messagejobs
UpdateMessageJobs();
// Screensaver detection
BOOL bActive = false;
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &bActive, 0);
if(bActive != m_bScreensaver)
{
if(CConfig::GetBoolSetting(SCREENSAVER_LOCK)) {
if(!m_bScreensaver) {
ActivateScreensaverScreen();
} else {
ActivateEventScreen();
}
}
if(CConfig::GetBoolSetting(CONTROL_BACKLIGHTS)) {
if(GetLCDConnection() &&
GetLCDConnection()->GetConnectionType() == TYPE_LOGITECH)
{
CLCDConnectionLogitech *pLCDConnection = (CLCDConnectionLogitech*)GetLCDConnection();
// Screensaver starts
if(!m_bScreensaver)
{
m_G15LightStatus = pLCDConnection->GetLightStatus();
pLCDConnection->SetLCDBacklight(LCD_OFF);
pLCDConnection->SetKBDBacklight(KBD_OFF);
pLCDConnection->SetMKeyLight(0,0,0,0);
}
// Screensaver ends
else
{
SG15LightStatus currentStatus = pLCDConnection->GetLightStatus();
if(currentStatus.eLCDBrightness == LCD_OFF)
pLCDConnection->SetLCDBacklight(m_G15LightStatus.eLCDBrightness);
if(currentStatus.eKBDBrightness == KBD_OFF)
pLCDConnection->SetKBDBacklight(m_G15LightStatus.eKBDBrightness);
if(!currentStatus.bMRKey && !currentStatus.bMKey[0] && !currentStatus.bMKey[1]
&& !currentStatus.bMKey[2])
pLCDConnection->SetMKeyLight(m_G15LightStatus.bMKey[0],m_G15LightStatus.bMKey[1],m_G15LightStatus.bMKey[2],m_G15LightStatus.bMRKey);
}
}
}
m_bScreensaver = bActive;
}
return true;
}
//************************************************************************
// Called when the active screen has expired
//************************************************************************
void CAppletManager::OnScreenExpired(CLCDScreen *pScreen)
{
// If the notification screen has expired, activate the last active screen
if(pScreen == (CLCDScreen*)&m_NotificationScreen)
{
ActivateScreen(m_pLastScreen);
if(CConfig::GetBoolSetting(TRANSITIONS))
m_pGfx->StartTransition();
}
}
//************************************************************************
// the update timer's callback function
//************************************************************************
VOID CALLBACK CAppletManager::UpdateTimer(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
CAppletManager::GetInstance()->Update();
}
//************************************************************************
// applies the volumewheel setting
//************************************************************************
void CAppletManager::SetVolumeWheelHook()
{
// Set the volumewheel hook
if(GetLCDConnection() && GetLCDConnection()->GetConnectionType() == TYPE_LOGITECH)
{
CLCDConnectionLogitech *pLCDConnection = (CLCDConnectionLogitech*)GetLCDConnection();
if(pLCDConnection->GetConnectionState() == CONNECTED)
pLCDConnection->SetVolumeWheelHook(CConfig::GetBoolSetting(HOOK_VOLUMEWHEEL));
}
}
//************************************************************************
// Called when the connection state has changed
//************************************************************************
void CAppletManager::OnConnectionChanged(int iConnectionState)
{
if(iConnectionState == CONNECTED)
{
SetVolumeWheelHook();
}
CConfig::OnConnectionChanged();
}
//************************************************************************
// called when the plugin's configuration has changed
//************************************************************************
void CAppletManager::OnConfigChanged()
{
GetLCDConnection()->Connect(CConfig::GetIntSetting(DEVICE));
m_pGfx->StartTransition(TRANSITION_MORPH);
// Set the volumewheel hook
SetVolumeWheelHook();
// send the event to all screens
m_NotificationScreen.OnConfigChanged();
m_ChatScreen.OnConfigChanged();
m_EventScreen.OnConfigChanged();
m_ContactlistScreen.OnConfigChanged();
m_CreditsScreen.OnConfigChanged();
}
//************************************************************************
// activate a screen
//************************************************************************
void CAppletManager::ActivateScreen(CScreen *pScreen) {
if(GetActiveScreen() && GetActiveScreen() != &m_NotificationScreen) {
m_pLastScreen = (CScreen*)GetActiveScreen();
}
CLCDOutputManager::ActivateScreen(pScreen);
}
//************************************************************************
// activates the previous screen
//************************************************************************
void CAppletManager::ActivatePreviousScreen() {
if(m_pLastScreen) {
ActivateScreen(m_pLastScreen);
}
}
//************************************************************************
// activates the credits screen
//************************************************************************
void CAppletManager::ActivateScreensaverScreen()
{
m_ScreensaverScreen.Reset();
ActivateScreen(&m_ScreensaverScreen);
}
//************************************************************************
// activates the credits screen
//************************************************************************
void CAppletManager::ActivateCreditsScreen()
{
m_CreditsScreen.Reset();
ActivateScreen(&m_CreditsScreen);
}
//************************************************************************
// activates the event screen
//************************************************************************
void CAppletManager::ActivateEventScreen()
{
m_ChatScreen.SetContact(NULL);
ActivateScreen(&m_EventScreen);
if(CConfig::GetBoolSetting(TRANSITIONS))
m_pGfx->StartTransition();
}
//************************************************************************
// activates the contactlist screen
//************************************************************************
void CAppletManager::ActivateCListScreen()
{
m_ChatScreen.SetContact(NULL);
m_ContactlistScreen.ResetPosition();
ActivateScreen(&m_ContactlistScreen);
if(CConfig::GetBoolSetting(TRANSITIONS))
m_pGfx->StartTransition();
}
//************************************************************************
// activates the chat screen
//************************************************************************
bool CAppletManager::ActivateChatScreen(HANDLE hContact)
{
if(!m_ChatScreen.SetContact(hContact))
return false;
m_ContactlistScreen.OnSessionOpened(hContact);
ActivateScreen(&m_ChatScreen);
if(CConfig::GetBoolSetting(TRANSITIONS))
m_pGfx->StartTransition();
return true;
}
//************************************************************************
// returns the contacts displayname
//************************************************************************
tstring CAppletManager::GetContactDisplayname(HANDLE hContact,bool bShortened)
{
if(!bShortened || !CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF))
return (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR);
tstring strNick = GetContactDisplayname(hContact,false);
if(strNick.length() > CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET))
return strNick.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + _T("...");
return strNick;
}
//************************************************************************
// returns the contacts group
//************************************************************************
tstring CAppletManager::GetContactGroup(HANDLE hContact)
{
DBVARIANT dbv;
int res = db_get_ts(hContact, "CList", "Group", &dbv);
tstring strGroup = _T("");
if(!res)
strGroup = dbv.ptszVal;
db_free(&dbv);
return strGroup;
}
//************************************************************************
// returns the bitmap for the specified event
//************************************************************************
HBITMAP CAppletManager::GetEventBitmap(EventType eType, bool bLarge)
{
switch(eType)
{
case EVENT_MSG_RECEIVED:
case EVENT_MSG_SENT:
case EVENT_IRC_RECEIVED:
case EVENT_IRC_SENT:
if(bLarge)
return m_ahLargeEventBitmaps[0];
else
return m_ahEventBitmaps[0];
case EVENT_PROTO_STATUS:
case EVENT_PROTO_CONNECTED:
case EVENT_PROTO_DISCONNECTED:
if(bLarge)
return m_ahLargeEventBitmaps[1];
else
return m_ahEventBitmaps[1];
case EVENT_STATUS:
case EVENT_SIGNED_ON:
case EVENT_SIGNED_OFF:
if(bLarge)
return m_ahLargeEventBitmaps[2];
else
return m_ahEventBitmaps[2];
default:
if(bLarge)
return m_ahLargeEventBitmaps[3];
else
return m_ahEventBitmaps[3];
}
}
//************************************************************************
// returns the bitmap for the specified status
//************************************************************************
HBITMAP CAppletManager::GetStatusBitmap(int iStatus)
{
switch(iStatus)
{
case ID_STATUS_OFFLINE:
return m_ahStatusBitmaps[0];
case ID_STATUS_ONLINE:
return m_ahStatusBitmaps[1];
case ID_STATUS_NA:
return m_ahStatusBitmaps[3];
case ID_STATUS_OCCUPIED:
return m_ahStatusBitmaps[4];
case ID_STATUS_DND:
return m_ahStatusBitmaps[5];
case ID_STATUS_INVISIBLE:
return m_ahStatusBitmaps[6];
case ID_STATUS_FREECHAT:
return m_ahStatusBitmaps[7];
case ID_STATUS_AWAY:
default:
return m_ahStatusBitmaps[2];
}
}
//************************************************************************
// returns a formatted timestamp string
//************************************************************************
tstring CAppletManager::GetFormattedTimestamp(tm *tm_time)
{
time_t now;
tm tm_now;
time(&now);
localtime_s(&tm_now,&now);
TCHAR buffer[128];
setlocale( LC_ALL, "" );
if(tm_time->tm_mday != tm_now.tm_mday || tm_time->tm_mon != tm_now.tm_mon)
{
if(CConfig::GetBoolSetting(TIMESTAMP_SECONDS))
_tcsftime(buffer,128,_T("[%x %H:%M:%S]"),tm_time);
else
_tcsftime(buffer,128,_T("[%x %H:%M]"),tm_time);
}
else
{
if(CConfig::GetBoolSetting(TIMESTAMP_SECONDS))
_tcsftime(buffer,128,_T("[%H:%M:%S]"),tm_time);
else
_tcsftime(buffer,128,_T("[%H:%M]"),tm_time);
}
return toTstring(buffer);
}
//************************************************************************
// called to process the specified event
//************************************************************************
void CAppletManager::HandleEvent(CEvent *pEvent)
{
TRACE(_T("<< Event: %i\n"),(int)pEvent->eType);
// check if the event's timestamp needs to be set
if(!pEvent->bTime)
{
time_t now;
time(&now);
localtime_s(&pEvent->Time,&now);
}
// check wether the event needs notification
// check for protocol filters
if(pEvent->hContact != NULL && pEvent->eType != EVENT_CONTACT_ADDED)
{
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)pEvent->hContact, 0);
if(szProto == NULL || !CConfig::GetProtocolNotificationFilter(toTstring(szProto)))
pEvent->bNotification = false;
}
pEvent->bLog = pEvent->bNotification;
if(CAppletManager::IsSubContact(pEvent->hContact))
{
pEvent->bLog = false;
pEvent->bNotification = false;
}
// if the applet is in foreground, skip notifications for the chatsession contact
if(pEvent->hContact && GetLCDConnection()->IsForeground() && pEvent->hContact == m_ChatScreen.GetContact() &&
(!m_ChatScreen.IsInputActive() || !CConfig::GetBoolSetting(NOTIFY_NO_SKIP_REPLY)))
{
if(pEvent->eType == EVENT_STATUS && CConfig::GetBoolSetting(NOTIFY_SKIP_STATUS))
pEvent->bNotification = false;
if( pEvent->eType == EVENT_SIGNED_ON && CConfig::GetBoolSetting(NOTIFY_SKIP_SIGNON))
pEvent->bNotification = false;
if(pEvent->eType == EVENT_SIGNED_OFF && CConfig::GetBoolSetting(NOTIFY_SKIP_SIGNOFF))
pEvent->bNotification = false;
if((pEvent->eType == EVENT_IRC_RECEIVED || pEvent->eType == EVENT_MSG_RECEIVED) && CConfig::GetBoolSetting(NOTIFY_SKIP_MESSAGES))
pEvent->bNotification = false;
}
// send the event to all screens
m_NotificationScreen.OnEventReceived(pEvent);
m_ChatScreen.OnEventReceived(pEvent);
m_EventScreen.OnEventReceived(pEvent);
m_ContactlistScreen.OnEventReceived(pEvent);
// activate notification screen if neccessary (and screensaverscreen is not active)
if(pEvent->bNotification)
{
if(GetActiveScreen() != (CLCDScreen*)&m_NotificationScreen && GetActiveScreen() != (CLCDScreen*)&m_ScreensaverScreen)
{
m_NotificationScreen.SetAlert(true);
m_NotificationScreen.SetExpiration(CConfig::GetIntSetting(NOTIFY_DURATION)*1000);
ActivateScreen(&m_NotificationScreen);
if(GetLCDConnection()->IsForeground() && CConfig::GetBoolSetting(TRANSITIONS))
m_pGfx->StartTransition();
}
}
}
bool CAppletManager::IsUtfSendAvailable(HANDLE hContact) {
char* szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
if ( szProto == NULL )
return FALSE;
return ( CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDUTF ) ? TRUE : FALSE;
}
//************************************************************************
// returns the contacts message service name
//************************************************************************
char *CAppletManager::GetMessageServiceName(HANDLE hContact,bool bIsUnicode)
{
if(g_bUnicode) {
char szServiceName[100];
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0);
if(szProto == NULL)
return NULL;
if (!bIsUnicode)
return PSS_MESSAGE;
_snprintf(szServiceName, sizeof(szServiceName), "%s%sW", szProto, PSS_MESSAGE);
if (ServiceExists(szServiceName))
return PSS_MESSAGE "W";
} else {
return PSS_MESSAGE;
}
}
//************************************************************************
// updates all pending message jobs
//************************************************************************
void CAppletManager::UpdateMessageJobs()
{
list<SMessageJob*>::iterator iter = m_MessageJobs.begin();
while(iter != m_MessageJobs.end())
{
// TODO: Fertigstellen
if((*iter)->dwTimestamp + 15*1000 < GetTickCount())
{
CEvent Event;
Event.eType = EVENT_MESSAGE_ACK;
Event.hValue = (*iter)->hEvent;
Event.hContact = (*iter)->hContact;
Event.iValue = ACKRESULT_FAILED;
Event.strValue = TranslateString(_T("Timeout: No response from contact/server"));
HandleEvent(&Event);
SMessageJob *pJob = *iter;
m_MessageJobs.erase(iter);
free(pJob->pcBuffer);
delete(pJob);
break;
}
iter++;
}
}
//************************************************************************
// adds a message job to the list
//************************************************************************
void CAppletManager::AddMessageJob(SMessageJob *pJob)
{
m_MessageJobs.push_back(pJob);
}
//************************************************************************
// finishes a message job
//************************************************************************
void CAppletManager::FinishMessageJob(SMessageJob *pJob)
{
list<SMessageJob*>::iterator iter = m_MessageJobs.begin();
while(iter != m_MessageJobs.end())
{
if((*iter) == pJob)
{
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)pJob->hContact, 0);
tstring strProto = toTstring(szProto);
CIRCConnection *pIRCCon = GetIRCConnection(strProto);
// Only add the message to the history if the contact isn't an irc chatroom
if(!(pIRCCon && db_get_b(pJob->hContact, szProto, "ChatRoom", 0) != 0))
{
// Add the message to the database
DBEVENTINFO dbei = { 0 };
dbei.cbSize = sizeof(dbei);
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.flags = DBEF_SENT;
dbei.szModule = szProto;
dbei.timestamp = time(NULL);
// Check if protocoll is valid
if(dbei.szModule == NULL)
return;
if(pJob->dwFlags & PREF_UTF) {
dbei.flags |= DBEF_UTF;
}
dbei.cbBlob = pJob->iBufferSize;
dbei.pBlob = (PBYTE) pJob->pcBuffer;
db_event_add(pJob->hContact, &dbei);
}
SMessageJob *pJob = *iter;
m_MessageJobs.erase(iter);
free(pJob->pcBuffer);
delete(pJob);
return;
}
}
}
//************************************************************************
// cancels a message job
//************************************************************************
void CAppletManager::CancelMessageJob(SMessageJob *pJob)
{
list<SMessageJob*>::iterator iter = m_MessageJobs.begin();
while(iter != m_MessageJobs.end())
{
if((*iter) == pJob)
{
SMessageJob *pJob = *iter;
m_MessageJobs.erase(iter);
free(pJob->pcBuffer);
delete(pJob);
return;
}
}
}
//************************************************************************
// returns wether or not a contact is a subcontact
//************************************************************************
bool CAppletManager::IsSubContact(HANDLE hContact)
{
if(!db_get_b(0, "MetaContacts", "Enabled", 1))
return false;
bool bIsSubcontact = db_get_b(hContact,"MetaContacts","IsSubcontact",0);
return bIsSubcontact;
// HANDLE hMetaContact = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, NULL);
// return hMetaContact != NULL;
}
//************************************************************************
// sends typing notifications to the specified contact
//************************************************************************
void CAppletManager::SendTypingNotification(HANDLE hContact,bool bEnable)
{
DWORD protoStatus;
DWORD protoCaps;
DWORD typeCaps;
if (!hContact)
return;
// Don't send to protocols who don't support typing
// Don't send to users who are unchecked in the typing notification options
// Don't send to protocols that are offline
// Don't send to users who are not visible and
// Don't send to users who are not on the visible list when you are in invisible mode.
if (!db_get_b(hContact, "SRMsg", "SupportTyping", db_get_b(NULL, "SRMsg", "DefaultTyping", 1)))
return;
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
if (!szProto)
return;
protoStatus = CallProtoService(szProto, PS_GETSTATUS, 0, 0);
protoCaps = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0);
typeCaps = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0);
if (!(typeCaps & PF4_SUPPORTTYPING))
return;
if (protoStatus < ID_STATUS_ONLINE)
return;
if (protoCaps & PF1_VISLIST && db_get_w(hContact, szProto, "ApparentMode", 0) == ID_STATUS_OFFLINE)
return;
if (protoCaps & PF1_INVISLIST && protoStatus == ID_STATUS_INVISIBLE && db_get_w(hContact, szProto, "ApparentMode", 0) != ID_STATUS_ONLINE)
return;
if (db_get_b(hContact, "CList", "NotOnList", 0)
&& !db_get_b(NULL, "SRMsg", "UnknownTyping", 1))
return;
// End user check
CallService(MS_PROTO_SELFISTYPING, (WPARAM) hContact, bEnable?PROTOTYPE_SELFTYPING_ON:PROTOTYPE_SELFTYPING_OFF);
}
//************************************************************************
// sends a message to the specified contact
//************************************************************************
HANDLE CAppletManager::SendMessageToContact(HANDLE hContact,tstring strMessage)
{
string strAscii = toNarrowString(strMessage);
int bufSize = lstrlenA(strAscii.c_str())+1;
SMessageJob *pJob = new SMessageJob();
pJob->dwTimestamp = GetTickCount();
pJob->hContact = hContact;
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
tstring strProto = toTstring(szProto);
CIRCConnection *pIRCCon = CAppletManager::GetInstance()->GetIRCConnection(strProto);
if(pIRCCon && db_get_b(hContact, szProto, "ChatRoom", 0) != 0)
{
GCDEST gcd = {0};
GCEVENT gce = {0};
DBVARIANT dbv;
if (!db_get((HANDLE)hContact, szProto, "Nick", &dbv) && dbv.type == DBVT_ASCIIZ )
gcd.pszID = dbv.pszVal;
else
return NULL;
string strID = string(gcd.pszID) + " - " + toNarrowString(pIRCCon->strNetwork).c_str();
gcd.pszID = (char*)strID.c_str();
gcd.pszModule = szProto;
gcd.iType = GC_EVENT_SENDMESSAGE;
gce.cbSize = sizeof(GCEVENT);
gce.pDest = &gcd;
gce.pszStatus = "";
// gce.bAddToLog = true;
gce.pszUserInfo = NULL;
gce.pszText = (char *)strAscii.c_str();
gce.dwItemData = NULL;
gce.time = time(NULL);
gce.bIsMe = true;
CallService(MS_GC_EVENT, NULL, (LPARAM) &gce);
pJob->hEvent = NULL;
}
else
{
DWORD pref = 0;
bool bIsUnicode = false;
if(CAppletManager::IsUtfSendAvailable(pJob->hContact)) {
pref = PREF_UTF;
char* szMsgUtf = NULL;
#if defined( _UNICODE )
szMsgUtf = mir_utf8encodeW( strMessage.c_str());
#else
int codepage = CallService( MS_LANGPACK_GETCODEPAGE, 0, 0 );
szMsgUtf = mir_utf8encodecp(strMessage.c_str(), codepage);
#endif
pJob->iBufferSize = strlen(szMsgUtf)+1;
pJob->pcBuffer = (char *)malloc(pJob->iBufferSize);
pJob->dwFlags = PREF_UTF;
memcpy(pJob->pcBuffer,szMsgUtf,pJob->iBufferSize);
mir_free(szMsgUtf);
} else {
#ifdef _UNICODE
bIsUnicode = !IsUnicodeAscii(strMessage.c_str(),lstrlen(strMessage.c_str()));
#endif
if(bIsUnicode) {
pref = PREF_UNICODE;
pJob->iBufferSize = bufSize * (sizeof(TCHAR) + 1);
} else {
pJob->iBufferSize = bufSize;
}
pJob->pcBuffer = (char *)malloc(pJob->iBufferSize);
memcpy(pJob->pcBuffer,strAscii.c_str(),bufSize);
if(bIsUnicode) {
memcpy(&pJob->pcBuffer[bufSize],strMessage.c_str(),bufSize*sizeof(TCHAR));
}
}
char *szService = CAppletManager::GetMessageServiceName(pJob->hContact,bIsUnicode);
if(szService == NULL)
{
free(pJob->pcBuffer);
pJob->pcBuffer == NULL;
return NULL;
}
pJob->hEvent = (HANDLE) CallContactService(pJob->hContact, szService , pref, (LPARAM)pJob->pcBuffer );
CAppletManager::GetInstance()->AddMessageJob(pJob);
}
return pJob->hEvent;
}
//************************************************************************
// check if a contacts message window is opened
//************************************************************************
bool CAppletManager::IsMessageWindowOpen(HANDLE hContact)
{
MessageWindowInputData mwid;
mwid.cbSize = sizeof(MessageWindowInputData);
mwid.hContact = hContact;
mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
MessageWindowData mwd;
mwd.cbSize = sizeof(MessageWindowData);
CallService(MS_MSG_GETWINDOWDATA,(WPARAM)&mwid,(LPARAM)&mwd);
if(mwd.uState & MSG_WINDOW_STATE_EXISTS)
return true;
return false;
}
//************************************************************************
// marks the given message as read
//************************************************************************
void CAppletManager::MarkMessageAsRead(HANDLE hContact,HANDLE hEvent)
{
db_event_markRead(hContact, hEvent);
CallService(MS_CLIST_REMOVEEVENT, (WPARAM)hContact, (LPARAM)hEvent);
}
//************************************************************************
// translates the given database event
//************************************************************************
bool CAppletManager::TranslateDBEvent(CEvent *pEvent,WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
HANDLE hdbevent = (HANDLE)lParam;
// Create struct for dbevent
DBEVENTINFO dbevent;
ZeroMemory(&dbevent, sizeof(dbevent));
//dbevent.flags |= PREF_UNICODE;
dbevent.cbSize = sizeof(dbevent);
dbevent.cbBlob = db_event_getBlobSize(hdbevent);
if(dbevent.cbBlob == -1) // hdbevent is invalid
{
return false;
}
dbevent.pBlob = (PBYTE)malloc(dbevent.cbBlob);
if(db_event_get(hdbevent, &dbevent) != 0)
{
free(dbevent.pBlob);
return false;
}
pEvent->dwFlags = dbevent.flags;
pEvent->hContact = hContact;
pEvent->hValue = hdbevent;
time_t timestamp = (time_t)dbevent.timestamp;
localtime_s(&pEvent->Time,×tamp);
pEvent->bTime = true;
/*
if(dbevent.eventType == EVENTTYPE_MESSAGE && dbevent.flags & DBEF_READ) {
free(dbevent.pBlob);
return false;
}
*/
// Skip events from the user except for messages
if(dbevent.eventType != EVENTTYPE_MESSAGE && (dbevent.flags & DBEF_SENT))
{
free(dbevent.pBlob);
return false;
}
int msglen = 0;
tstring strName = CAppletManager::GetContactDisplayname(hContact,true);
switch(dbevent.eventType)
{
case EVENTTYPE_MESSAGE:
msglen = strlen((char *) dbevent.pBlob) + 1;
#ifdef _UNICODE
if (dbevent.flags & DBEF_UTF) {
pEvent->strValue = Utf8_Decode((char*)dbevent.pBlob);
} else if ((int) dbevent.cbBlob == msglen*3){
pEvent->strValue = (TCHAR *) & dbevent.pBlob[msglen];
} else {
pEvent->strValue = toTstring((char*)dbevent.pBlob);
}
#else
pEvent->strValue = toTstring((char*)dbevent.pBlob);
#endif
pEvent->eType = (dbevent.flags & DBEF_SENT) ? EVENT_MSG_SENT:EVENT_MSG_RECEIVED;
if(pEvent->eType == EVENT_MSG_RECEIVED)
{
pEvent->dwFlags = MSG_UNREAD;
if(CConfig::GetBoolSetting(NOTIFY_MESSAGES))
pEvent->bNotification = true;
}
pEvent->strDescription = strName + _T(": ") +pEvent->strValue;
pEvent->strSummary = TranslateString(_T("New message from %s"),strName.c_str());
break;
case EVENTTYPE_URL:
if(CConfig::GetBoolSetting(NOTIFY_URL))
pEvent->bNotification = true;
pEvent->eType = EVENT_URL;
pEvent->strDescription = TranslateString(_T("Incoming URL from %s"),strName.c_str());
break;
case EVENTTYPE_CONTACTS:
if(CConfig::GetBoolSetting(NOTIFY_CONTACTS))
pEvent->bNotification = true;
pEvent->strDescription = TranslateString(_T("Incoming contacts from %s"),strName.c_str());
pEvent->eType = EVENT_CONTACTS;
break;
case EVENTTYPE_ADDED:
if(CConfig::GetBoolSetting(NOTIFY_CONTACTS))
pEvent->bNotification = true;
pEvent->strDescription = TranslateString(_T("You were added by %s"),strName.c_str());
pEvent->eType = EVENT_ADDED;
break;
case EVENTTYPE_AUTHREQUEST:
if(CConfig::GetBoolSetting(NOTIFY_CONTACTS))
pEvent->bNotification = true;
pEvent->strDescription = TranslateString(_T("Incoming Authrequest!"));
pEvent->eType = EVENT_AUTHREQUEST;
break;
case EVENTTYPE_FILE:
if(CConfig::GetBoolSetting(NOTIFY_FILE))
pEvent->bNotification = true;
pEvent->strDescription = TranslateString(_T("Incoming file from %s"),strName.c_str());
pEvent->eType = EVENT_FILE;
break;
default:
return false;
break;
}
if(CConfig::GetBoolSetting(NOTIFY_SHOWPROTO))
{
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)pEvent->hContact, 0);
pEvent->strDescription = _T("(")+toTstring(szProto)+_T(") ") + pEvent->strDescription;
}
// Clean up
free(dbevent.pBlob);
return true;
}
//************************************************************************
// removes IRC formatting tags from the string
//************************************************************************
tstring CAppletManager::StripIRCFormatting(tstring strText)
{
tstring::size_type End=0,Start=0;
tstring strEntity = _T("");
tstring strReplace = _T("");
tstring::size_type len = strText.length();
int i = 0;
while(i < strText.length())
{
Start = strText.find(_T("%"),i);
if(Start != string::npos && Start < strText.length() - 1)
{
strEntity = strText[Start+1];
if(strEntity == _T("%"))
{
strText.replace(Start,2,_T("%"));
i = Start +1;
}
/*
else if(strEntity == _T("b") || strEntity == _T("B") ||
strEntity == _T("i") || strEntity == _T("I") ||
strEntity ==_T("u") || strEntity == _T("U") ||
strEntity == _T("C") ||strEntity == _T("F"))
{
strText.erase(Start,2);
i = Start;
}
*/
else if(strEntity == _T("c") || strEntity == _T("f"))
{
strText.erase(Start,4);
i = Start;
}
else
{
strText.erase(Start,2);
i = Start;
}
}
else
break;
}
return strText;
}
//************************************************************************
// returns the IRC connection class for the specified protocol
//************************************************************************
CIRCConnection *CAppletManager::GetIRCConnection(tstring strProtocol)
{
vector<CIRCConnection*>::iterator iter = m_vIRCConnections.begin();
while(iter != m_vIRCConnections.end())
{
if((*iter)->strProtocol == strProtocol)
return *iter;
iter++;
}
return NULL;
}
//************************************************************************
// creates the IRC connection class for the specified protocol
//************************************************************************
CIRCConnection *CAppletManager::CreateIRCConnection(tstring strProtocol)
{
char buffer[128];
sprintf(buffer,"%s/HookableEvents",toNarrowString(strProtocol).c_str());
// try to hook the events
HANDLE hEventHook = HookEvent(buffer,CAppletManager::HookChatInbound);
// if the hook could not be established, the protocol is not an IRC instance
if(!hEventHook)
return NULL;
TRACE(_T("Patched IRC-Connection found: %s\n"),strProtocol.c_str());
CIRCConnection *pIRCCon = new CIRCConnection();
pIRCCon->strProtocol = strProtocol;
pIRCCon->hEventHook = hEventHook;
pIRCCon->strNetwork = _T("");
m_vIRCConnections.push_back(pIRCCon);
return pIRCCon;
}
//************************************************************************
// returns the history class for the specified IRC channel
//************************************************************************
CIRCHistory *CAppletManager::GetIRCHistory(HANDLE hContact)
{
list<CIRCHistory*>::iterator iter = m_LIRCHistorys.begin();
while(iter != m_LIRCHistorys.end())
{
if((*iter)->hContact == hContact)
return *iter;
iter++;
}
return NULL;
}
CIRCHistory *CAppletManager::GetIRCHistoryByName(tstring strProtocol,tstring strChannel)
{
list<CIRCHistory*>::iterator iter = m_LIRCHistorys.begin();
while(iter != m_LIRCHistorys.end())
{
if((*iter)->strChannel == strChannel && (*iter)->strProtocol == strProtocol)
return *iter;
iter++;
}
return NULL;
}
//************************************************************************
// deletes the history class for the specified IRC channel
//************************************************************************
void CAppletManager::DeleteIRCHistory(HANDLE hContact)
{
list<CIRCHistory*>::iterator iter = m_LIRCHistorys.begin();
while(iter != m_LIRCHistorys.end())
{
if((*iter)->hContact == hContact)
{
CIRCHistory *pHistory = *iter;
pHistory->LMessages.clear();
pHistory->LUsers.clear();
m_LIRCHistorys.erase(iter);
delete pHistory;
return;
}
iter++;
}
}
//************************************************************************
// creates a history class for the specified IRC channel
//************************************************************************
CIRCHistory *CAppletManager::CreateIRCHistory(HANDLE hContact,tstring strChannel)
{
char *szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
if(!szProto)
return NULL;
CIRCHistory *pHistory = GetIRCHistoryByName(toTstring(szProto),strChannel);
if(pHistory)
{
pHistory->hContact = hContact;
return pHistory;
}
pHistory = new CIRCHistory();
pHistory->hContact = hContact;
pHistory->strChannel = strChannel;
pHistory->strProtocol = toTstring(szProto);
m_LIRCHistorys.push_back(pHistory);
return pHistory;
}
CIRCHistory *CAppletManager::CreateIRCHistoryByName(tstring strProtocol,tstring strChannel)
{
CIRCHistory *pHistory = GetIRCHistoryByName(strProtocol,strChannel);
if(pHistory)
return pHistory;
pHistory = new CIRCHistory();
pHistory->hContact = NULL;
pHistory->strChannel = strChannel;
pHistory->strProtocol = strProtocol;
m_LIRCHistorys.push_back(pHistory);
return pHistory;
}
//########################################################################
// hook functions
//########################################################################
//************************************************************************
// inbound chat event hook function
//************************************************************************
int CAppletManager::HookChatInbound(WPARAM wParam,LPARAM lParam)
{
GCEVENT *gce = (GCEVENT*)lParam;
GCDEST *gcd = (GCDEST*)gce->pDest;
if(gce == NULL || gcd == NULL)
TRACE(_T("<< [%s] skipping invalid IRC event\n"));
TRACE(_T("<< [%s:%s] IRC event %04X\n"),toTstring(gcd->pszModule).c_str(),toTstring(gcd->pszID).c_str(),gcd->iType);
// get the matching irc connection entry
CIRCConnection *pIRCCon = CAppletManager::GetInstance()->GetIRCConnection(toTstring(gcd->pszModule));
if(!pIRCCon)
{
TRACE(_T("<< [%s] IRC connection not found, skipping event\n"),toTstring(gcd->pszModule).c_str());
return 0;
}
// fetch the network name
if(gcd->iType == GC_EVENT_CHANGESESSIONAME)
{
if(!_tcsicmp(gcd->ptszID,_T("Network log")))
{
pIRCCon->strNetwork = toTstring(gce->ptszText);
TRACE(_T("\t Found network identifier: %s\n"),pIRCCon->strNetwork.c_str());
return 0;
}
}
CEvent Event;
if(gce->bIsMe)
Event.eType = EVENT_IRC_SENT;
else
Event.eType = EVENT_IRC_RECEIVED;
Event.iValue = gcd->iType;
Event.hValue = (HANDLE)lParam;
CIRCHistory *pHistory = NULL;
if(gcd->ptszID)
{
tstring strChannel = toTstring(gcd->ptszID);
tstring::size_type pos = strChannel.find('-');
if(pos != tstring::npos)
strChannel = strChannel.substr(0,pos-1);
else
{
if(_tcsicmp(gcd->ptszID,_T("Network log")))
TRACE(_T("\t WARNING: ignoring unknown event!\n"));
return 0;
}
pHistory = CAppletManager::GetInstance()->GetIRCHistoryByName(pIRCCon->strProtocol,strChannel);
if(!pHistory)
{
if(gcd->iType == GC_EVENT_JOIN)
{
pHistory = CAppletManager::GetInstance()->CreateIRCHistoryByName(pIRCCon->strProtocol,strChannel);
if(pHistory)
pHistory->LUsers.push_back(toTstring(gce->ptszNick));
}
return 0;
}
Event.hContact = pHistory->hContact;
}
else if(gcd->iType != GC_EVENT_INFORMATION)
{
TRACE(_T("\t WARNING: ignoring unknown event!\n"));
return 0;
}
else
Event.hContact = NULL;
// Ignore events from hidden chatrooms, except for join events
if(gcd->ptszID != NULL && db_get_b(Event.hContact,"CList","Hidden",0))
{
if(gcd->iType == GC_EVENT_JOIN && pHistory)
pHistory->LUsers.push_back(toTstring(gce->ptszNick));
TRACE(_T("\t Chatroom is hidden, skipping event!\n"));
return 0;
}
tstring strText = StripIRCFormatting(toTstring(gce->ptszText));
tstring strNick = toTstring(gce->ptszNick);
tstring strStatus = toTstring(gce->ptszStatus);
if(CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strNick.length() > CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET))
strNick = strNick.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + _T("...");
TRACE(_T("\t Handling event...\t"));
switch(gcd->iType)
{
case GC_EVENT_INFORMATION:
if(CConfig::GetBoolSetting(NOTIFY_IRC_CHANNEL))
Event.bNotification = true;
if(strText.find(_T("CTCP")) == 0)
Event.strValue = _T("--> ") + strText;
else
Event.strValue = strText;
break;
case GC_EVENT_ACTION:
if(CConfig::GetBoolSetting(NOTIFY_IRC_EMOTES))
Event.bNotification = true;
Event.strValue = strNick + _T(" ") + strText;
break;
case GC_EVENT_MESSAGE:
if(CConfig::GetBoolSetting(NOTIFY_IRC_MESSAGES))
Event.bNotification = true;
Event.strValue = strNick + _T(": ") + strText;
break;
case GC_EVENT_JOIN:
// Add the user to the list
pHistory->LUsers.push_back(toTstring(gce->ptszNick));
if(CConfig::GetBoolSetting(NOTIFY_IRC_USERS))
Event.bNotification = true;
// Skip join event for user
if(gce->bIsMe)
return 0;
Event.strValue = TranslateString(_T("%s has joined the channel"),strNick.c_str());
break;
case GC_EVENT_PART:
{
if(CConfig::GetBoolSetting(NOTIFY_IRC_USERS))
Event.bNotification = true;
tstring strFullNick = toTstring(gce->ptszNick);
Event.strValue = TranslateString(strText.empty()?_T("%s has left"):_T("%s has left: %s"),strNick.c_str(),strText.c_str());
if(pHistory)
{
// Remove the user from the list
list<tstring>::iterator iter = pHistory->LUsers.begin();
while(iter != pHistory->LUsers.end())
{
if((*iter) == strFullNick)
{
pHistory->LUsers.erase(iter);
break;
}
iter++;
}
}
break;
}
case GC_EVENT_QUIT:
if(CConfig::GetBoolSetting(NOTIFY_IRC_USERS))
Event.bNotification = true;
Event.strValue = TranslateString(strText.empty()?_T("%s has disconnected"):_T("%s has disconnected: %s"),strNick.c_str(),strText.c_str());
break;
case GC_EVENT_KICK:
if(CConfig::GetBoolSetting(NOTIFY_IRC_USERS))
Event.bNotification = true;
Event.strValue = TranslateString(_T("%s has kicked %s: %s"),strStatus.c_str(),strNick.c_str(),strText.c_str());
break;
case GC_EVENT_NICK:
{
if(CConfig::GetBoolSetting(NOTIFY_IRC_USERS))
Event.bNotification = true;
tstring strFullNick = toTstring(gce->ptszNick);
if(CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strText.length() > CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET))
strText = strText.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + _T("...");
Event.strValue = TranslateString(_T("%s is now known as %s"),strNick.c_str(),strText.c_str());
if(pHistory)
{
// change the nick in the userlist
list<tstring>::iterator iter = pHistory->LUsers.begin();
while(iter != pHistory->LUsers.end())
{
if((*iter) == strFullNick)
(*iter) = strText;
iter++;
}
}
break;
}
case GC_EVENT_NOTICE:
if(CConfig::GetBoolSetting(NOTIFY_IRC_NOTICES))
Event.bNotification = true;
Event.strValue = TranslateString(_T("Notice from %s: %s"),strNick.c_str(),strText.c_str());
break;
case GC_EVENT_TOPIC:
if(CConfig::GetBoolSetting(NOTIFY_IRC_CHANNEL))
Event.bNotification = true;
Event.strValue = TranslateString(_T("Topic is now '%s' (set by %s)"),strText.c_str(),strNick.c_str());
break;
case GC_EVENT_ADDSTATUS:
{
if(CConfig::GetBoolSetting(NOTIFY_IRC_STATUS))
Event.bNotification = true;
tstring strNick2 = toTstring(gce->ptszStatus);
if(CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strNick2.length() > CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET))
strNick2 = strNick2.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + _T("...");
Event.strValue = TranslateString(_T("%s enables '%s' for %s"),strText.c_str(),strNick2.c_str(),strNick.c_str());
break;
}
case GC_EVENT_REMOVESTATUS:
{
if(CConfig::GetBoolSetting(NOTIFY_IRC_STATUS))
Event.bNotification = true;
tstring strNick2 = toTstring(gce->ptszStatus);
if(CConfig::GetBoolSetting(NOTIFY_NICKCUTOFF) && strNick2.length() > CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET))
strNick2 = strNick2.erase(CConfig::GetIntSetting(NOTIFY_NICKCUTOFF_OFFSET)) + _T("...");
Event.strValue = TranslateString(_T("%s disables '%s' for %s"),strText.c_str(),strNick2.c_str(),strNick.c_str());
break;
}
default:
TRACE(_T("OK!\n"));
return 0;
}
if(gce->bIsMe || gcd->ptszID == NULL)
Event.bNotification = false;
// set the event's timestamp
Event.bTime = true;
time_t now;
time(&now);
localtime_s(&Event.Time,&now);
SIRCMessage IRCMsg;
IRCMsg.bIsMe = gce->bIsMe;
IRCMsg.strMessage = Event.strValue;
IRCMsg.Time = Event.Time;
if(pHistory)
{
pHistory->LMessages.push_back(IRCMsg);
// Limit the size to the session logsize
if(pHistory->LMessages.size() > CConfig::GetIntSetting(SESSION_LOGSIZE))
pHistory->LMessages.pop_front();
}
else if(gce->ptszNick && gcd->iType == GC_EVENT_QUIT)
{
tstring strNick = toTstring(gce->ptszNick);
if(!CAppletManager::GetInstance()->m_LIRCHistorys.empty())
{
list<CIRCHistory*>::iterator iter = CAppletManager::GetInstance()->m_LIRCHistorys.begin();
list<tstring>::iterator nickiter;
while(iter != CAppletManager::GetInstance()->m_LIRCHistorys.end())
{
nickiter = (*iter)->LUsers.begin();
while(nickiter != (*iter)->LUsers.end())
{
if((*nickiter) == strNick)
{
(*iter)->LMessages.push_back(IRCMsg);
// Limit the size to the session logsize
if((*iter)->LMessages.size() > CConfig::GetIntSetting(SESSION_LOGSIZE))
(*iter)->LMessages.pop_front();
(*iter)->LUsers.erase(nickiter);
Event.hContact = (*iter)->hContact;
tstring strName = CAppletManager::GetContactDisplayname((*iter)->hContact,true);
Event.strDescription = strName + _T(" - ")+Event.strValue;
Event.strSummary = _T("(") + toTstring(gcd->pszModule) + _T(") ")+strName;
CAppletManager::GetInstance()->HandleEvent(&Event);
break;
}
nickiter++;
}
iter++;
}
}
TRACE(_T("OK!\n"));
return 0;
}
else if(gcd->ptszID != NULL)
{
TRACE(_T("OK!\n"));
return 0;
}
if(pHistory)
{
tstring strChannel = pHistory->strChannel;
if(CConfig::GetBoolSetting(NOTIFY_CHANNELCUTOFF) && strNick.length() > CConfig::GetIntSetting(NOTIFY_CHANNELCUTOFF_OFFSET)) {
strChannel = strChannel.erase(CConfig::GetIntSetting(NOTIFY_CHANNELCUTOFF_OFFSET)) + _T("...");
}
Event.strDescription = strChannel + _T(" - ")+Event.strValue;
Event.strSummary = _T("(") + toTstring(gcd->pszModule) + _T(") ")+pHistory->strChannel;
}
else
Event.strDescription = Event.strValue;
TRACE(_T("OK!\n"));
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
//************************************************************************
// message window event hook function
//************************************************************************
int CAppletManager::HookMessageWindowEvent(WPARAM wParam, LPARAM lParam)
{
MessageWindowEventData *mwed = (MessageWindowEventData*)lParam;
CEvent Event;
Event.eType = EVENT_MESSAGEWINDOW;
Event.hContact = mwed->hContact;
Event.iValue = mwed->uType;
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
//************************************************************************
// contact typing notification hook function
//************************************************************************
int CAppletManager::HookContactIsTyping(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
int iState = (int)lParam;
CEvent Event;
Event.eType = EVENT_TYPING_NOTIFICATION;
Event.hContact = hContact;
Event.iValue = iState;
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
//************************************************************************
// new event hook function
//************************************************************************
int CAppletManager::HookEventAdded(WPARAM wParam, LPARAM lParam)
{
CEvent Event;
if(CAppletManager::TranslateDBEvent(&Event,wParam,lParam))
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
//************************************************************************
// contact status change hook function
//************************************************************************
int CAppletManager::HookStatusChanged(WPARAM wParam, LPARAM lParam)
{
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
if ((wParam == 0) || (strcmp(cws->szSetting,"Status") != NULL))
return 0;
// Prepare message and append to queue
CEvent Event;
Event.hContact = (HANDLE)wParam;
int iStatus = cws->value.wVal;
Event.iValue = iStatus;
int iOldStatus = CAppletManager::GetInstance()->m_ContactlistScreen.GetContactStatus(Event.hContact);
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)Event.hContact, 0);
tstring strProto = toTstring(szProto);
CProtocolData *pProtocolData = CAppletManager::GetInstance()->GetProtocolData(toTstring(szProto));
if(pProtocolData == NULL)
return false;
// Fetch the contacts name
tstring strName = CAppletManager::GetContactDisplayname(Event.hContact,true);
// Get status String
Event.strValue = toTstring((char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, iStatus, 0));
// check if this is an irc protocol
CIRCConnection *pIRCCon = CAppletManager::GetInstance()->GetIRCConnection(strProto);
// Contact signed on
if(iOldStatus == ID_STATUS_OFFLINE && iStatus != ID_STATUS_OFFLINE)
{
if(CConfig::GetBoolSetting(NOTIFY_SIGNOFF))
Event.bNotification = true;
Event.eType = EVENT_SIGNED_ON;
if(pIRCCon && db_get_b(Event.hContact, szProto, "ChatRoom", 0) != 0)
{
Event.strDescription = TranslateString(_T("Joined %s"),strName.c_str());
DBVARIANT dbv;
if (db_get_ts(Event.hContact, szProto, "Nick", &dbv))
return 0;
CAppletManager::GetInstance()->CreateIRCHistory(Event.hContact,dbv.ptszVal);
db_free(&dbv);
}
else
Event.strDescription = TranslateString(_T("%s signed on (%s)"),strName.c_str(),Event.strValue.c_str());
}
// Contact signed off
else if(iStatus == ID_STATUS_OFFLINE && iOldStatus != ID_STATUS_OFFLINE)
{
if(CConfig::GetBoolSetting(NOTIFY_SIGNON))
Event.bNotification = true;
Event.eType = EVENT_SIGNED_OFF;
if(pIRCCon && db_get_b(Event.hContact, szProto, "ChatRoom", 0) != 0)
{
Event.strDescription = TranslateString(_T("Left %s"),strName.c_str());
// delete IRC-Channel history
CAppletManager::GetInstance()->DeleteIRCHistory(Event.hContact);
}
else
Event.strDescription = TranslateString(_T("%s signed off"),strName.c_str());
}
// Contact changed status
else if(iStatus != iOldStatus)
{
if(CConfig::GetBoolSetting(NOTIFY_STATUS))
Event.bNotification = true;
Event.eType = EVENT_STATUS;
Event.strDescription = TranslateString(_T("%s is now %s"),strName.c_str(),Event.strValue.c_str());
}
// ignore remaining events
else
return 0;
if(CConfig::GetBoolSetting(NOTIFY_SHOWPROTO))
Event.strDescription = _T("(")+strProto+_T(") ") + Event.strDescription;
Event.strSummary = TranslateString(_T("Contactlist event"));
// Block notifications after connecting/disconnecting
if(pProtocolData->iStatus == ID_STATUS_OFFLINE ||
pProtocolData->lTimeStamp + PROTOCOL_NOTIFY_DELAY > GetTickCount())
Event.bNotification = false;
//CAppletManager::GetInstance()->ActivateNotificationScreen(&Event);
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
//************************************************************************
// protocoll ack hook function
//************************************************************************
int CAppletManager::HookProtoAck(WPARAM wParam, LPARAM lParam)
{
ACKDATA *pAck = (ACKDATA *) lParam;
if(lParam == 0)
return 0;
// Prepare message and append to queue
CEvent Event;
// Message job handling
if(pAck->type == ACKTYPE_MESSAGE)
{
list<SMessageJob*>::iterator iter = CAppletManager::GetInstance()->m_MessageJobs.begin();
while(iter != CAppletManager::GetInstance()->m_MessageJobs.end())
{
if((*iter)->hEvent == pAck->hProcess && (*iter)->hContact == pAck->hContact)
{
Event.eType = EVENT_MESSAGE_ACK;
Event.hValue = pAck->hProcess;
Event.hContact = pAck->hContact;
Event.iValue = pAck->result;
if(pAck->lParam != 0)
Event.strValue = toTstring((char*)pAck->lParam);
else
Event.strValue = _T("");
if(Event.iValue == ACKRESULT_SUCCESS)
CAppletManager::GetInstance()->FinishMessageJob((*iter));
else
CAppletManager::GetInstance()->CancelMessageJob((*iter));
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
iter++;
}
}
// protocol status changes
else if(pAck->type == ACKTYPE_STATUS && pAck->result == ACKRESULT_SUCCESS)
{
int iOldStatus = (int)pAck->hProcess;
int iNewStatus = pAck->lParam;
tstring strProto = toTstring(pAck->szModule);
// ignore metacontacts status changes
if(toLower(strProto) == _T("metacontacts"))
return 0;
CProtocolData *pProtoData = CAppletManager::GetInstance()->GetProtocolData(strProto);
if(pProtoData == NULL)
return 0;
if(iNewStatus == ID_STATUS_CONNECTING)
return 0;
if(iNewStatus == ID_STATUS_OFFLINE)
{
if(CConfig::GetBoolSetting(NOTIFY_PROTO_SIGNOFF))
Event.bNotification = true;
Event.eType = EVENT_PROTO_DISCONNECTED;
}
else if(iNewStatus != ID_STATUS_OFFLINE && iOldStatus == ID_STATUS_CONNECTING)
{
if(CConfig::GetBoolSetting(NOTIFY_PROTO_SIGNON))
Event.bNotification = true;
Event.eType = EVENT_PROTO_CONNECTED;
}
else
{
if(CConfig::GetBoolSetting(NOTIFY_PROTO_STATUS))
Event.bNotification = true;
Event.eType = EVENT_PROTO_STATUS;
}
// Skip connecting status
if(iNewStatus == ID_STATUS_CONNECTING)
return 0;
pProtoData->iStatus = iNewStatus;
Event.iValue = iNewStatus;
Event.strValue = strProto;
// set the event description / summary
tstring strStatus = toTstring((char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, iNewStatus, 0));
Event.strDescription = _T("(") + Event.strValue + _T(") ")+ TranslateString(_T("You are now %s"),strStatus.c_str());
Event.strSummary = TranslateString(_T("Protocol status change"));
if(Event.eType != EVENT_PROTO_STATUS)
pProtoData->lTimeStamp = GetTickCount();
CAppletManager::GetInstance()->HandleEvent(&Event);
//CAppletManager::GetInstance()->ActivateNotificationScreen(&Event);
}
return 0;
}
//************************************************************************
// contact added hook function
//************************************************************************
int CAppletManager::HookContactAdded(WPARAM wParam, LPARAM lParam)
{
CEvent Event;
Event.eType = EVENT_CONTACT_ADDED;
Event.hContact = (HANDLE)wParam;
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
//************************************************************************
// contact deleted hook function
//************************************************************************
int CAppletManager::HookContactDeleted(WPARAM wParam, LPARAM lParam)
{
CEvent Event;
Event.eType = EVENT_CONTACT_DELETED;
Event.hContact = (HANDLE)wParam;
Event.bNotification = CConfig::GetBoolSetting(NOTIFY_CONTACTS);
Event.bLog = Event.bNotification;
tstring strName = CAppletManager::GetContactDisplayname(Event.hContact,true);
Event.strDescription = TranslateString(_T("%s was deleted from contactlist!"),strName.c_str());
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
//************************************************************************
// setting changed hook function
//************************************************************************
int CAppletManager::HookSettingChanged(WPARAM wParam,LPARAM lParam)
{
DBCONTACTWRITESETTING *dbcws = (DBCONTACTWRITESETTING*)lParam;
CEvent Event;
Event.hContact = (HANDLE)wParam;
if(!lstrcmpA(dbcws->szModule,"MetaContacts"))
{
//if(!lstrcmpA(dbcws->szSetting,"Enabled")) {
// CAppletManager::GetInstance()->OnConfigChanged();
// return 0;
//} else
if(!lstrcmpA(dbcws->szSetting,"IsSubcontact")) {
Event.eType = EVENT_CONTACT_GROUP;
DBVARIANT dbv;
int res = db_get_ts((HANDLE)wParam, "CList", "Group", &dbv);
if(!res)
Event.strValue = dbv.ptszVal;
db_free(&dbv);
} else {
return 0;
}
}
else if(!lstrcmpA(dbcws->szSetting,"Nick") || !lstrcmpA(dbcws->szSetting,"MyHandle"))
{
DBVARIANT dbv={0};
// if the protocol nick has changed, check if a custom handle is set
if(!lstrcmpA(dbcws->szSetting,"Nick"))
{
if (!db_get_ts(Event.hContact, "CList", "MyHandle", &dbv))
{
// handle found, ignore this event
if(dbv.pszVal && strlen(dbv.pszVal)>0)
return 0;
}
db_free(&dbv);
}
Event.eType = EVENT_CONTACT_NICK;
if(dbcws->value.type != DBVT_DELETED && dbcws->value.pszVal && strlen(dbcws->value.pszVal)>0)
{
#ifdef _UNICODE
if(dbcws->value.type == DBVT_UTF8)
Event.strValue = Utf8_Decode(dbcws->value.pszVal);
else
#endif
Event.strValue = toTstring(dbcws->value.pszVal);
}
else
{
char *szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)Event.hContact, 0);
if (db_get_ts(Event.hContact, szProto, "Nick", &dbv))
return 0;
Event.strValue = dbv.ptszVal;
db_free(&dbv);
}
}
else if(!lstrcmpA(dbcws->szModule,"CList"))
{
if(!lstrcmpA(dbcws->szSetting,"Hidden"))
{
Event.eType = EVENT_CONTACT_HIDDEN;
Event.iValue = db_get_b((HANDLE)wParam,"CList","Hidden",0);
}
else if(!lstrcmpA(dbcws->szSetting,"Group"))
{
Event.eType = EVENT_CONTACT_GROUP;
DBVARIANT dbv;
int res = db_get_ts((HANDLE)wParam, "CList", "Group", &dbv);
if(!res)
Event.strValue = dbv.ptszVal;
db_free(&dbv);
}
else
return 0;
}
else
return 0;
CAppletManager::GetInstance()->HandleEvent(&Event);
return 0;
}
|