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
|
/*
NewXstatusNotify YM - Plugin for Miranda IM
Copyright (c) 2007-2011 yaho
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; either version 2 of the License, or
(at your option) any later version.
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "stdafx.h"
XSTATUSCHANGE *NewXSC(MCONTACT hContact, char *szProto, int xstatusType, int action, wchar_t *stzTitle, wchar_t *stzText)
{
XSTATUSCHANGE *xsc = (XSTATUSCHANGE *)mir_alloc(sizeof(XSTATUSCHANGE));
xsc->hContact = hContact;
xsc->szProto = szProto;
xsc->type = xstatusType;
xsc->action = action;
xsc->stzTitle = stzTitle;
xsc->stzText = stzText;
return xsc;
}
void FreeXSC(XSTATUSCHANGE *xsc)
{
if (xsc) {
mir_free(xsc->stzTitle);
mir_free(xsc->stzText);
mir_free(xsc);
}
}
void RemoveLoggedEventsXStatus(MCONTACT hContact)
{
for (int i = eventListXStatus.getCount() - 1; i >= 0; i--) {
DBEVENT *dbevent = eventListXStatus[i];
if (dbevent->hContact == hContact) {
db_event_delete(dbevent->hContact, dbevent->hDBEvent);
eventListXStatus.remove(i);
mir_free(dbevent);
}
}
}
void RemoveLoggedEventsStatus(MCONTACT hContact)
{
for (int i = eventListStatus.getCount() - 1; i >= 0; i--) {
DBEVENT *dbevent = eventListStatus[i];
if (dbevent->hContact == hContact) {
db_event_delete(dbevent->hContact, dbevent->hDBEvent);
eventListStatus.remove(i);
mir_free(dbevent);
}
}
}
void RemoveLoggedEventsSMsg(MCONTACT hContact)
{
for (int i = eventListSMsg.getCount() - 1; i >= 0; i--) {
DBEVENT *dbevent = eventListSMsg[i];
if (dbevent->hContact == hContact) {
db_event_delete(dbevent->hContact, dbevent->hDBEvent);
eventListSMsg.remove(i);
mir_free(dbevent);
}
}
}
wchar_t* GetStatusTypeAsString(int type, wchar_t *buff)
{
switch (type) {
case TYPE_JABBER_MOOD:
mir_wstrcpy(buff, TranslateT("Mood")); return buff;
case TYPE_JABBER_ACTIVITY:
mir_wstrcpy(buff, TranslateT("Activity")); return buff;
case TYPE_ICQ_XSTATUS:
mir_wstrcpy(buff, TranslateT("xStatus")); return buff;
default:
mir_wstrcpy(buff, TranslateT("<unknown>")); return buff;
}
}
CMString ReplaceVars(XSTATUSCHANGE *xsc, const wchar_t *tmplt)
{
if (xsc == NULL || tmplt == NULL || tmplt[0] == '\0')
return CMString();
size_t len = mir_wstrlen(tmplt);
CMString res;
for (size_t i = 0; i < len; i++) {
if (tmplt[i] == '%') {
i++;
switch (tmplt[i]) {
case 'n':
wchar_t stzType[32];
res.Append(GetStatusTypeAsString(xsc->type, stzType));
break;
case 't':
if (xsc->stzTitle == NULL || xsc->stzTitle[0] == '\0')
res.Append(TranslateT("<no title>"));
else
res.Append(xsc->stzTitle);
break;
case 'm':
if (xsc->stzText == NULL || xsc->stzText[0] == '\0')
res.Append(TranslateT("<no status message>"));
else
AddCR(res, xsc->stzText);
break;
case 'c':
if (xsc->hContact == NULL)
res.Append(TranslateT("Contact"));
else
res.Append(pcli->pfnGetContactDisplayName(xsc->hContact, 0));
break;
default:
i--;
res.AppendChar(tmplt[i]);
break;
}
}
else if (tmplt[i] == '\\') {
i++;
switch (tmplt[i]) {
case 'n':
res.AppendChar('\r'); res.AppendChar('\n');
break;
case 't':
res.AppendChar('\t');
break;
default:
i--;
res.AppendChar(tmplt[i]);
break;
}
}
else res.AppendChar(tmplt[i]);
}
if (res.GetLength() > 2044) {
res.Truncate(2044);
res.Append(L"...");
}
return res;
}
void ShowXStatusPopup(XSTATUSCHANGE *xsc)
{
if (xsc == NULL)
return;
HICON hIcon = NULL;
switch (xsc->type) {
case TYPE_JABBER_MOOD:
case TYPE_JABBER_ACTIVITY:
DBVARIANT dbv;
char szSetting[64];
mir_snprintf(szSetting, "%s/%s/icon", xsc->szProto, (xsc->type == TYPE_JABBER_MOOD) ? "mood" : "activity");
if (!db_get_s(xsc->hContact, "AdvStatus", szSetting, &dbv)) {
hIcon = IcoLib_GetIcon(dbv.pszVal);
db_free(&dbv);
}
break;
case TYPE_ICQ_XSTATUS:
int statusId = db_get_b(xsc->hContact, xsc->szProto, "XStatusId", 0);
hIcon = (HICON)CallProtoService(xsc->szProto, PS_GETCUSTOMSTATUSICON, statusId, LR_SHARED);
}
if (hIcon == NULL)
hIcon = Skin_LoadProtoIcon(xsc->szProto, db_get_w(xsc->hContact, xsc->szProto, "Status", ID_STATUS_ONLINE));
// cut message if needed
wchar_t *copyText = NULL;
if (opt.PXMsgTruncate && (opt.PXMsgLen > 0) && xsc->stzText && (mir_wstrlen(xsc->stzText) > opt.PXMsgLen)) {
wchar_t buff[MAX_TEXT_LEN + 3];
copyText = mir_wstrdup(xsc->stzText);
wcsncpy(buff, xsc->stzText, opt.PXMsgLen);
buff[opt.PXMsgLen] = 0;
mir_wstrcat(buff, L"...");
replaceStrW(xsc->stzText, buff);
}
wchar_t *Template = L"";
switch (xsc->action) {
case NOTIFY_NEW_XSTATUS:
Template = templates.PopupXstatusChanged; break;
case NOTIFY_NEW_MESSAGE:
Template = templates.PopupXMsgChanged; break;
case NOTIFY_REMOVE_XSTATUS:
Template = templates.PopupXstatusRemoved; break;
case NOTIFY_REMOVE_MESSAGE:
Template = templates.PopupXMsgRemoved; break;
}
ShowChangePopup(xsc->hContact, hIcon, ID_STATUS_EXTRASTATUS, ReplaceVars(xsc, Template));
if (copyText) {
mir_free(xsc->stzText);
xsc->stzText = copyText;
}
}
void BlinkXStatusIcon(XSTATUSCHANGE *xsc)
{
if (xsc == NULL)
return;
HICON hIcon = NULL;
wchar_t str[256] = { 0 };
wchar_t stzType[32];
mir_snwprintf(str, TranslateT("%s changed %s"), pcli->pfnGetContactDisplayName(xsc->hContact, 0), GetStatusTypeAsString(xsc->type, stzType));
if (opt.BlinkIcon_Status) {
DBVARIANT dbv;
char szSetting[64];
switch (xsc->type) {
case TYPE_JABBER_MOOD:
case TYPE_JABBER_ACTIVITY:
mir_snprintf(szSetting, "%s/%s/icon", xsc->szProto, (xsc->type == TYPE_JABBER_MOOD) ? "mood" : "activity");
if (!db_get_s(xsc->hContact, "AdvStatus", szSetting, &dbv)) {
hIcon = IcoLib_GetIcon(dbv.pszVal);
db_free(&dbv);
}
break;
case TYPE_ICQ_XSTATUS:
int statusId = db_get_b(xsc->hContact, xsc->szProto, "XStatusId", 0);
hIcon = (HICON)CallProtoService(xsc->szProto, PS_GETCUSTOMSTATUSICON, statusId, LR_SHARED);
}
}
if (hIcon == NULL)
hIcon = Skin_LoadIcon(SKINICON_OTHER_USERONLINE);
BlinkIcon(xsc->hContact, hIcon, str);
mir_free(str);
}
void PlayXStatusSound(MCONTACT hContact, int action)
{
switch (action) {
case NOTIFY_NEW_XSTATUS:
PlayChangeSound(hContact, XSTATUS_SOUND_CHANGED); return;
case NOTIFY_REMOVE_XSTATUS:
PlayChangeSound(hContact, XSTATUS_SOUND_REMOVED); return;
case NOTIFY_NEW_MESSAGE:
PlayChangeSound(hContact, XSTATUS_SOUND_MSGCHANGED); return;
case NOTIFY_REMOVE_MESSAGE:
PlayChangeSound(hContact, XSTATUS_SOUND_MSGREMOVED); return;
}
}
void LogChangeToDB(XSTATUSCHANGE *xsc)
{
if (xsc == NULL || (opt.XLogToDB_WinOpen && !CheckMsgWnd(xsc->hContact)))
return;
wchar_t *Template = L"";
switch (xsc->action) {
case NOTIFY_NEW_XSTATUS:
Template = templates.LogXstatusChanged; break;
case NOTIFY_REMOVE_XSTATUS:
Template = templates.LogXstatusRemoved; break;
case NOTIFY_NEW_MESSAGE:
Template = templates.LogXMsgChanged; break;
case NOTIFY_REMOVE_MESSAGE:
Template = templates.LogXMsgRemoved; break;
case NOTIFY_OPENING_ML:
Template = templates.LogXstatusOpening; break;
}
wchar_t stzLastLog[2 * MAX_TEXT_LEN];
CMString stzLogText(ReplaceVars(xsc, Template));
DBGetStringDefault(xsc->hContact, MODULE, DB_LASTLOG, stzLastLog, _countof(stzLastLog), L"");
if (opt.XLogToDB) {
db_set_ws(xsc->hContact, MODULE, DB_LASTLOG, stzLogText);
T2Utf blob(stzLogText);
DBEVENTINFO dbei = { 0 };
dbei.cbSize = sizeof(dbei);
dbei.cbBlob = (DWORD)mir_strlen(blob) + 1;
dbei.pBlob = (PBYTE)(char*)blob;
dbei.eventType = EVENTTYPE_STATUSCHANGE;
dbei.flags = DBEF_READ | DBEF_UTF;
dbei.timestamp = (DWORD)time(NULL);
dbei.szModule = MODULE;
MEVENT hDBEvent = db_event_add(xsc->hContact, &dbei);
if (opt.XLogToDB_WinOpen && opt.XLogToDB_Remove) {
DBEVENT *dbevent = (DBEVENT *)mir_alloc(sizeof(DBEVENT));
dbevent->hContact = xsc->hContact;
dbevent->hDBEvent = hDBEvent;
eventListXStatus.insert(dbevent);
}
}
}
void LogChangeToFile(XSTATUSCHANGE *xsc)
{
if (xsc == NULL)
return;
wchar_t stzDate[32], stzTime[32], stzText[MAX_TEXT_LEN];
GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, L"HH':'mm", stzTime, _countof(stzTime));
GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, L"dd/MM/yyyy", stzDate, _countof(stzDate));
wchar_t *Template = L"";
switch (xsc->action) {
case NOTIFY_NEW_XSTATUS:
Template = templates.LogXstatusChanged; break;
case NOTIFY_REMOVE_XSTATUS:
Template = templates.LogXstatusRemoved; break;
case NOTIFY_NEW_MESSAGE:
Template = templates.LogXMsgChanged; break;
case NOTIFY_REMOVE_MESSAGE:
Template = templates.LogXMsgRemoved; break;
}
mir_snwprintf(stzText, L"%s, %s. %s %s\r\n", stzDate, stzTime,
pcli->pfnGetContactDisplayName(xsc->hContact, 0), ReplaceVars(xsc, Template).GetString());
LogToFile(stzText);
}
void ExtraStatusChanged(XSTATUSCHANGE *xsc)
{
if (xsc == NULL)
return;
BOOL bEnablePopup = true, bEnableSound = true, bEnableLog = opt.XLogToDB;
char buff[12] = { 0 };
mir_snprintf(buff, "%d", ID_STATUS_EXTRASTATUS);
if ((db_get_b(0, MODULE, buff, 1) == 0)
|| (db_get_w(xsc->hContact, xsc->szProto, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
|| (!opt.HiddenContactsToo && (db_get_b(xsc->hContact, "CList", "Hidden", 0) == 1))
|| (CallProtoService(xsc->szProto, PS_GETSTATUS, 0, 0) == ID_STATUS_OFFLINE))
{
FreeXSC(xsc);
return;
}
// check per-contact ignored events
if (db_get_b(xsc->hContact, MODULE, "EnableXStatusNotify", 1) == 0)
bEnableSound = bEnablePopup = false;
// check if our status isn't on autodisable list
if (opt.AutoDisable) {
char statusIDs[12], statusIDp[12];
WORD myStatus = (WORD)CallProtoService(xsc->szProto, PS_GETSTATUS, 0, 0);
mir_snprintf(statusIDs, "s%d", myStatus);
mir_snprintf(statusIDp, "p%d", myStatus);
bEnableSound = db_get_b(0, MODULE, statusIDs, 1) ? FALSE : bEnableSound;
bEnablePopup = db_get_b(0, MODULE, statusIDp, 1) ? FALSE : bEnablePopup;
}
if (!(templates.PopupXFlags & xsc->action))
bEnablePopup = false;
if (db_get_b(0, MODULE, xsc->szProto, 1) == 0 && !opt.PXOnConnect)
bEnablePopup = false;
int xstatusID = db_get_b(xsc->hContact, xsc->szProto, "XStatusId", 0);
if (opt.PXDisableForMusic && xsc->type == TYPE_ICQ_XSTATUS && xstatusID == XSTATUS_MUSIC)
bEnableSound = bEnablePopup = false;
if (bEnablePopup && db_get_b(xsc->hContact, MODULE, "EnablePopups", 1) && !opt.TempDisabled)
ShowXStatusPopup(xsc);
if (bEnableSound && db_get_b(0, "Skin", "UseSound", 1) && db_get_b(xsc->hContact, MODULE, "EnableSounds", 1) && !opt.TempDisabled)
PlayXStatusSound(xsc->hContact, xsc->action);
if (opt.BlinkIcon && opt.BlinkIcon_ForMsgs && !opt.TempDisabled)
BlinkXStatusIcon(xsc);
if (opt.XLogDisableForMusic && xsc->type == TYPE_ICQ_XSTATUS && xstatusID == XSTATUS_MUSIC)
bEnableLog = false;
if (!(templates.LogXFlags & xsc->action))
bEnableLog = false;
if (bEnableLog && db_get_b(xsc->hContact, MODULE, "EnableXLogging", 1))
LogChangeToDB(xsc);
if (opt.XLogToFile && db_get_b(xsc->hContact, MODULE, "EnableXLogging", 1))
LogChangeToFile(xsc);
FreeXSC(xsc);
}
wchar_t* GetDefaultXstatusName(int statusID, char *szProto, wchar_t *buff, int bufflen)
{
wchar_t nameBuff[64];
buff[0] = 0;
CUSTOM_STATUS xstatus = { 0 };
xstatus.cbSize = sizeof(CUSTOM_STATUS);
xstatus.flags = CSSF_MASK_NAME | CSSF_DEFAULT_NAME | CSSF_TCHAR;
xstatus.ptszName = nameBuff;
xstatus.wParam = (WPARAM*)&statusID;
if (!CallProtoService(szProto, PS_GETCUSTOMSTATUSEX, 0, (LPARAM)&xstatus))
wcsncpy_s(buff, bufflen, TranslateTS(nameBuff), _TRUNCATE);
return buff;
}
wchar_t* GetIcqXStatus(MCONTACT hContact, char *szProto, char *szValue, wchar_t *buff, int bufflen)
{
DBVARIANT dbv;
buff[0] = 0;
int statusID = db_get_b(hContact, szProto, "XStatusId", -1);
if (statusID != -1) {
if (!db_get_ts(hContact, szProto, szValue, &dbv)) {
if ((mir_strcmp(szValue, "XStatusName") == 0) && dbv.ptszVal[0] == 0)
GetDefaultXstatusName(statusID, szProto, buff, bufflen);
else
wcsncpy(buff, dbv.ptszVal, bufflen);
buff[bufflen - 1] = 0;
db_free(&dbv);
}
}
return buff;
}
wchar_t* GetJabberAdvStatusText(MCONTACT hContact, char *szProto, char *szSlot, char *szValue, wchar_t *buff, int bufflen)
{
DBVARIANT dbv;
char szSetting[128];
buff[0] = 0;
mir_snprintf(szSetting, "%s/%s/%s", szProto, szSlot, szValue);
if (!db_get_ts(hContact, "AdvStatus", szSetting, &dbv)) {
wcsncpy(buff, dbv.ptszVal, bufflen);
buff[bufflen - 1] = 0;
db_free(&dbv);
}
return buff;
}
void LogXstatusChange(MCONTACT hContact, char *szProto, int xstatusType, wchar_t *stzTitle, wchar_t *stzText)
{
XSTATUSCHANGE *xsc = NewXSC(hContact, szProto, xstatusType, NOTIFY_OPENING_ML, stzTitle[0] ? mir_wstrdup(stzTitle) : NULL, stzText[0] ? mir_wstrdup(stzText) : NULL);
LogChangeToDB(xsc);
FreeXSC(xsc);
}
void AddXStatusEventThread(void *arg)
{
MCONTACT hContact = (MCONTACT)(DWORD_PTR)arg;
char *szProto = GetContactProto(hContact);
if (szProto == NULL)
return;
wchar_t stzTitle[MAX_TITLE_LEN], stzText[MAX_TEXT_LEN];
if (ProtoServiceExists(szProto, JS_PARSE_XMPP_URI)) {
GetJabberAdvStatusText(hContact, szProto, "mood", "title", stzTitle, _countof(stzTitle));
if (stzTitle[0]) {
GetJabberAdvStatusText(hContact, szProto, "mood", "text", stzText, _countof(stzText));
LogXstatusChange(hContact, szProto, TYPE_JABBER_MOOD, stzTitle, stzText);
}
GetJabberAdvStatusText(hContact, szProto, "activity", "title", stzTitle, _countof(stzTitle));
if (stzTitle[0]) {
GetJabberAdvStatusText(hContact, szProto, "activity", "text", stzText, _countof(stzText));
LogXstatusChange(hContact, szProto, TYPE_JABBER_ACTIVITY, stzTitle, stzText);
}
}
else {
GetIcqXStatus(hContact, szProto, "XStatusName", stzTitle, _countof(stzTitle));
if (stzTitle[0]) {
GetIcqXStatus(hContact, szProto, "XStatusMsg", stzText, _countof(stzText));
LogXstatusChange(hContact, szProto, TYPE_ICQ_XSTATUS, stzTitle, stzText);
}
}
}
void AddSMsgEventThread(void *arg)
{
MCONTACT hContact = (MCONTACT)(DWORD_PTR)arg;
STATUSMSGINFO smi;
smi.hContact = hContact;
smi.proto = GetContactProto(hContact);
if (smi.proto == NULL)
return;
smi.newstatusmsg = db_get_tsa(smi.hContact, "CList", "StatusMsg");
LogSMsgToDB(&smi, templates.LogSMsgOpening);
mir_free(smi.newstatusmsg);
}
int OnWindowEvent(WPARAM, LPARAM lParam)
{
MessageWindowEventData *mwed = (MessageWindowEventData *)lParam;
if (mwed->uType == MSG_WINDOW_EVT_CLOSE) {
if (opt.XLogToDB && opt.XLogToDB_WinOpen && opt.XLogToDB_Remove)
RemoveLoggedEventsXStatus(mwed->hContact);
if (opt.LogToDB && opt.LogToDB_WinOpen && opt.LogToDB_Remove)
RemoveLoggedEventsStatus(mwed->hContact);
if (opt.SMsgLogToDB && opt.SMsgLogToDB_WinOpen && opt.SMsgLogToDB_Remove)
RemoveLoggedEventsSMsg(mwed->hContact);
}
else if (mwed->uType == MSG_WINDOW_EVT_OPEN) {
if (opt.XLogToDB && (templates.LogXFlags & NOTIFY_OPENING_ML) && db_get_b(mwed->hContact, MODULE, "EnableXLogging", 1))
mir_forkthread(AddXStatusEventThread, (void *)mwed->hContact);
if (opt.SMsgLogToDB && (templates.LogSMsgFlags & NOTIFY_OPENING_ML) && db_get_b(mwed->hContact, MODULE, "EnableSMsgLogging", 1))
mir_forkthread(AddSMsgEventThread, (void *)mwed->hContact);
}
return 0;
}
|