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
|
/*
AdvancedAutoAway Plugin for Miranda-IM (www.miranda-im.org)
KeepStatus Plugin for Miranda-IM (www.miranda-im.org)
StartupStatus Plugin for Miranda-IM (www.miranda-im.org)
Copyright 2003-2006 P. Boon
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 "commonstatus.h"
#include "resource.h"
#define TIMER_ID 1
// variables
static HWND win;
static int timeOut;
struct TConfirmSetting : public PROTOCOLSETTINGEX
{
TConfirmSetting( const PROTOCOLSETTINGEX& x )
{
memcpy( this, &x, sizeof(PROTOCOLSETTINGEX));
if ( szMsg )
szMsg = _tcsdup( szMsg );
}
~TConfirmSetting()
{
if ( szMsg )
free( szMsg );
}
};
static int CompareSettings( const TConfirmSetting* p1, const TConfirmSetting* p2 )
{ return lstrcmpA( p1->szName, p2->szName );
}
static OBJLIST<TConfirmSetting> *confirmSettings;
static INT_PTR CALLBACK StatusMessageDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
static PROTOCOLSETTINGEX* protoSetting = NULL;
switch(msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
protoSetting = (PROTOCOLSETTINGEX *)lParam;
if (protoSetting->szMsg == NULL) {
TCHAR* smsg = GetDefaultStatusMessage(protoSetting, GetActualStatus(protoSetting));
if (smsg != NULL) {
SetDlgItemText(hwndDlg, IDC_STSMSG, smsg);
mir_free(smsg);
}
}
else SetDlgItemText(hwndDlg, IDC_STSMSG, protoSetting->szMsg);
{
TCHAR desc[ 512 ];
mir_sntprintf(desc, SIZEOF(desc),
TranslateT("Set %s message for %s."),
CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, GetActualStatus(protoSetting), GSMDF_TCHAR ),
protoSetting->tszAccName );
SetDlgItemText(hwndDlg, IDC_DESCRIPTION, desc);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_OK:
{
int len = SendMessage(GetDlgItem(hwndDlg, IDC_STSMSG), WM_GETTEXTLENGTH, 0, 0);
if (len > 0) {
protoSetting->szMsg = ( TCHAR* )realloc(protoSetting->szMsg, sizeof(TCHAR)*(len+1));
if (protoSetting->szMsg != NULL)
GetDlgItemText(hwndDlg, IDC_STSMSG, protoSetting->szMsg, len+1);
}
SendMessage(GetParent(hwndDlg), UM_STSMSGDLGCLOSED, (WPARAM)TRUE, 0);
EndDialog(hwndDlg, IDC_OK);
}
break;
case IDC_CANCEL:
SendMessage(GetParent(hwndDlg), UM_STSMSGDLGCLOSED, 0, 0);
EndDialog(hwndDlg, IDC_CANCEL);
break;
}
break;
}
return FALSE;
}
static int SetStatusList(HWND hwndDlg)
{
if (confirmSettings->getCount() == 0)
return -1;
HWND hList = GetDlgItem(hwndDlg, IDC_STARTUPLIST);
TCHAR buf[100];
// create items
LVITEM lvItem = { 0 };
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.cchTextMax = 256;
for ( int i=0; i < confirmSettings->getCount(); i++ ) {
lvItem.pszText = (*confirmSettings)[i].tszAccName;
if (ListView_GetItemCount(hList) < confirmSettings->getCount())
ListView_InsertItem(hList,&lvItem);
int actualStatus;
switch( (*confirmSettings)[i].status ) {
case ID_STATUS_LAST: actualStatus = (*confirmSettings)[i].lastStatus; break;
case ID_STATUS_CURRENT: actualStatus = CallProtoService((*confirmSettings)[i].szName,PS_GETSTATUS, 0, 0); break;
default: actualStatus = (*confirmSettings)[i].status;
}
TCHAR* status = ( TCHAR* )CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, actualStatus, GSMDF_TCHAR );
switch( (*confirmSettings)[i].status ) {
case ID_STATUS_LAST:
mir_sntprintf(buf, SIZEOF(buf), _T("%s (%s)"), TranslateT("<last>"), status);
ListView_SetItemText(hList, lvItem.iItem, 1, buf);
break;
case ID_STATUS_CURRENT:
mir_sntprintf( buf, SIZEOF(buf), _T("%s (%s)"), TranslateT("<current>"), status);
ListView_SetItemText(hList, lvItem.iItem, 1, buf);
break;
default:
ListView_SetItemText(hList, lvItem.iItem, 1, status);
}
// status message
if ( !((!((CallProtoService((*confirmSettings)[i].szName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&PF1_MODEMSGSEND)&~PF1_INDIVMODEMSG)) || (!(CallProtoService((*confirmSettings)[i].szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))))) {
TCHAR *msg = GetDefaultStatusMessage( &(*confirmSettings)[i], actualStatus );
if ( msg != NULL ) {
TCHAR* fMsg = variables_parsedup( msg, (*confirmSettings)[i].tszAccName, NULL );
ListView_SetItemText(hList, lvItem.iItem, 2, fMsg);
mir_free(fMsg);
mir_free(msg);
}
else ListView_SetItemText(hList, lvItem.iItem, 2, TranslateT("<n/a>"));
}
else ListView_SetItemText(hList, lvItem.iItem, 2, TranslateT("<n/a>"));
ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE);
ListView_SetColumnWidth(hList, 2, LVSCW_AUTOSIZE);
lvItem.lParam = (LPARAM)&(*confirmSettings)[i];
ListView_SetItem(hList,&lvItem);
lvItem.iItem++;
}
// grey out status box
EnableWindow(GetDlgItem(hwndDlg,IDC_STATUS), (ListView_GetNextItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST),-1,LVNI_SELECTED)>=0));
return 0;
}
static INT_PTR CALLBACK ConfirmDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
HWND hList=GetDlgItem(hwndDlg,IDC_STARTUPLIST);
SendMessage(hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
// create columns
LVCOLUMN lvCol = { 0 };
lvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
lvCol.pszText = TranslateT("Protocol");
ListView_InsertColumn(hList, 0, &lvCol );
lvCol.cx = 100;
lvCol.pszText = TranslateT("Status");
ListView_InsertColumn(hList, 1, &lvCol );
lvCol.pszText = TranslateT("Message");
ListView_InsertColumn(hList, 2, &lvCol );
}
// create items
confirmSettings = new OBJLIST<TConfirmSetting>(10, CompareSettings);
SetStatusList(hwndDlg);
EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), FALSE);
// fill profile combo box
if (!ServiceExists(MS_SS_GETPROFILE))
EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILE), FALSE);
else {
int defaultProfile;
int profileCount = (int)CallService(MS_SS_GETPROFILECOUNT, (WPARAM)&defaultProfile, 0);
for ( int i=0; i < profileCount; i++ ) {
char profileName[128];
CallService( MS_SS_GETPROFILENAME, i, (LPARAM)profileName );
int item = SendDlgItemMessageA( hwndDlg, IDC_PROFILE, CB_ADDSTRING, 0, (LPARAM)profileName );
SendDlgItemMessage( hwndDlg, IDC_PROFILE, CB_SETITEMDATA, item, ( LPARAM )i );
}
if ( profileCount == 0 )
EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILE), FALSE);
}
// start timer
if (timeOut > 0) {
TCHAR text[32];
_sntprintf(text, SIZEOF(text), TranslateT("Closing in %d"), timeOut);
SetDlgItemText(hwndDlg, IDC_CLOSE, text);
SetTimer(hwndDlg, TIMER_ID, 1000, NULL);
}
break;
case WM_TIMER:
{
TCHAR text[32];
_sntprintf(text, SIZEOF(text), TranslateT("Closing in %d"), timeOut-1);
SetDlgItemText(hwndDlg, IDC_CLOSE, text);
if (timeOut <= 0) {
KillTimer(hwndDlg, TIMER_ID);
SendMessage(hwndDlg, UM_CLOSECONFIRMDLG, 0, 0);
}
else timeOut--;
}
break;
case WM_COMMAND:
// stop timer
KillTimer(hwndDlg, TIMER_ID);
SetDlgItemText(hwndDlg, IDC_CLOSE, TranslateT("Close"));
if ( (HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) == BN_CLICKED) || (HIWORD(wParam) == NM_CLICK)) { // something clicked
switch (LOWORD(wParam)) {
case IDC_PROFILE:
{
int i, profile = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0);
for ( i=0; i < confirmSettings->getCount(); i++ ) {
if ((*confirmSettings)[i].szMsg != NULL) {
free((*confirmSettings)[i].szMsg);
(*confirmSettings)[i].szMsg = NULL;
} }
CallService(MS_SS_GETPROFILE, (WPARAM)profile, (LPARAM)&confirmSettings);
for ( i=0; i < confirmSettings->getCount(); i++ )
if ((*confirmSettings)[i].szMsg != NULL) // we free this later, copy to our memory space
(*confirmSettings)[i].szMsg = _tcsdup((*confirmSettings)[i].szMsg);
SetStatusList(hwndDlg);
}
break;
case IDC_STATUS:
{
LVITEM lvItem = { 0 };
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.iSubItem = 0;
lvItem.iItem = ListView_GetNextItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST),-1,LVNI_SELECTED);
if (lvItem.iItem == -1)
break;
ListView_GetItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST), &lvItem);
PROTOCOLSETTINGEX* proto = (PROTOCOLSETTINGEX*)lvItem.lParam;
int actualStatus = proto->status = (int)SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_GETCURSEL, 0, 0), 0);
// LAST STATUS
if (proto->status == ID_STATUS_LAST) {
TCHAR last[80];
mir_sntprintf(last, SIZEOF(last), _T("%s (%s)"),
TranslateT("<last>"),
CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, proto->lastStatus, GSMDF_TCHAR ));
ListView_SetItemText(GetDlgItem(hwndDlg,IDC_STARTUPLIST), lvItem.iItem, 1, last);
actualStatus = proto->lastStatus;
}
// CURRENT STATUS
else if (proto->status == ID_STATUS_CURRENT) {
int currentStatus = CallProtoService(proto->szName,PS_GETSTATUS, 0, 0);
TCHAR current[80];
mir_sntprintf(current, SIZEOF(current), _T("%s (%s)"),
TranslateT("<current>"),
CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, currentStatus, GSMDF_TCHAR ));
ListView_SetItemText(GetDlgItem(hwndDlg,IDC_STARTUPLIST), lvItem.iItem, 1, current);
actualStatus = currentStatus;
}
else ListView_SetItemText(GetDlgItem(hwndDlg,IDC_STARTUPLIST), lvItem.iItem, 1,
( TCHAR* )CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, proto->status, GSMDF_TCHAR ));
if ((!((CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&PF1_MODEMSGSEND)&~PF1_INDIVMODEMSG)) || (!(CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))))
EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), FALSE);
else if ( (proto->status == ID_STATUS_LAST) || (proto->status == ID_STATUS_CURRENT))
EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), TRUE);
else
EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), (CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))?TRUE:FALSE);
SetStatusList(hwndDlg);
}
break;
case IDC_SETSTSMSG:
{
LVITEM lvItem = { 0 };
lvItem.mask=LVIF_TEXT|LVIF_PARAM;
lvItem.iSubItem=0;
lvItem.iItem = ListView_GetNextItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST),-1,LVNI_SELECTED);
if (lvItem.iItem == -1)
break;
ListView_GetItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST), &lvItem);
DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SETSTSMSGDIALOG), hwndDlg, StatusMessageDlgProc, lvItem.lParam);
}
break;
case IDC_CLOSE:
SendMessage(hwndDlg, UM_CLOSECONFIRMDLG, 0, 0);
break;
case IDC_CANCEL:
DestroyWindow(hwndDlg);
break;
}
}
break;
case WM_NOTIFY:
switch(((NMHDR*)lParam)->idFrom) {
case IDC_STARTUPLIST:
switch(((NMHDR*)lParam)->code) {
// fill combobox
case NM_CLICK:
{
LVITEM lvItem;
PROTOCOLSETTINGEX* proto;
TCHAR buf[100];
int item, flags, i, currentStatus, actualStatus;
KillTimer(hwndDlg, TIMER_ID);
SetDlgItemText(hwndDlg, IDC_CLOSE, TranslateT("Close"));
memset(&lvItem,0,sizeof(lvItem));
lvItem.mask=LVIF_TEXT|LVIF_PARAM;
lvItem.iSubItem=0;
lvItem.iItem = ListView_GetNextItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST),-1,LVNI_SELECTED);
if ( ListView_GetItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST), &lvItem) == FALSE) {
SetStatusList(hwndDlg);
break;
}
proto = (PROTOCOLSETTINGEX*)lvItem.lParam;
flags = CallProtoService(proto->szName, PS_GETCAPS,PFLAGNUM_2,0)&~CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0);
// clear box and add new status, loop status and check if compatible with proto
SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_RESETCONTENT, 0, 0);
actualStatus = proto->status;
// last
mir_sntprintf(buf, SIZEOF(buf), _T("%s (%s)"),
TranslateT("<last>"),
CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)proto->lastStatus, GSMDF_TCHAR));
item = SendDlgItemMessage( hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)buf );
SendDlgItemMessage( hwndDlg, IDC_STATUS, CB_SETITEMDATA, item, (LPARAM)ID_STATUS_LAST );
if (proto->status == ID_STATUS_LAST) {
SendDlgItemMessage(hwndDlg,IDC_STATUS,CB_SETCURSEL,(WPARAM)item,0);
actualStatus = proto->lastStatus;
}
// current
currentStatus = CallProtoService(proto->szName,PS_GETSTATUS, 0, 0);
mir_sntprintf( buf, SIZEOF(buf), _T("%s (%s)"),
TranslateT("<current>"),
CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)currentStatus, GSMDF_TCHAR));
item = SendDlgItemMessage(hwndDlg,IDC_STATUS,CB_ADDSTRING,0,(LPARAM)buf);
SendDlgItemMessage(hwndDlg,IDC_STATUS,CB_SETITEMDATA,item,(LPARAM)ID_STATUS_CURRENT);
if (proto->status == ID_STATUS_CURRENT) {
SendDlgItemMessage(hwndDlg,IDC_STATUS,CB_SETCURSEL,(WPARAM)item,0);
actualStatus = currentStatus;
}
for (i=0; i < SIZEOF(statusModeList); i++) {
if ( ((flags&statusModePf2List[i]) || (statusModePf2List[i] == PF2_OFFLINE)) && (!((!(flags)&Proto_Status2Flag(statusModePf2List[i]))) || ((CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0)&Proto_Status2Flag(statusModePf2List[i]))))) {
TCHAR* statusMode = ( TCHAR* )CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, statusModeList[i], GSMDF_TCHAR);
item = SendDlgItemMessage(hwndDlg,IDC_STATUS,CB_ADDSTRING,0,(LPARAM)statusMode);
SendDlgItemMessage(hwndDlg,IDC_STATUS,CB_SETITEMDATA,item,(LPARAM)statusModeList[i]);
if (statusModeList[i] == proto->status)
SendDlgItemMessage(hwndDlg,IDC_STATUS,CB_SETCURSEL,(WPARAM)item,0);
}
}
// enable status box
EnableWindow(GetDlgItem(hwndDlg,IDC_STATUS), (ListView_GetNextItem(GetDlgItem(hwndDlg,IDC_STARTUPLIST),-1,LVNI_SELECTED)>=0));
if ( (!((CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&PF1_MODEMSGSEND)&~PF1_INDIVMODEMSG)) || (!(CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))))
EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), FALSE);
else if ( proto->status == ID_STATUS_LAST || proto->status == ID_STATUS_CURRENT )
EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), TRUE);
else
EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), (CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))?TRUE:FALSE);
}
break;
}
break;
}
break;
case UM_STSMSGDLGCLOSED:
SetStatusList(hwndDlg);
break;
case UM_CLOSECONFIRMDLG:
CallService(MS_CS_SETSTATUSEX, (WPARAM)&confirmSettings, 0);
DestroyWindow(hwndDlg);
break;
case WM_DESTROY:
delete confirmSettings; confirmSettings = 0;
break;
}
return 0;
}
INT_PTR ShowConfirmDialogEx(WPARAM wParam, LPARAM lParam)
{
if ( wParam == 0 )
return -1;
delete confirmSettings; confirmSettings = 0;
OBJLIST<PROTOCOLSETTINGEX>& param = *( OBJLIST<PROTOCOLSETTINGEX>* )wParam;
for (int i=0; i < param.getCount(); i++)
confirmSettings->insert( new TConfirmSetting( param[i] ));
timeOut = lParam;
if (timeOut < 0)
timeOut = DEF_CLOSE_TIME;
if (GetWindow(win, 0) == NULL) {
win = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CONFIRMDIALOG), NULL, ConfirmDlgProc, NULL);
EnableWindow(win,TRUE);
}
return (INT_PTR)win;
}
|