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
|
/*
Miranda IM History Sweeper Light plugin
Copyright (C) 2002-2003 Sergey V. Gershovich
Copyright (C) 2006-2009 Boris Krasnovskiy
Copyright (C) 2010, 2011 tico-tico
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 "historysweeperlight.h"
// Time Stamps strings
const char* time_stamp_strings[] =
{
"Delete older than 1 day",
"Delete older than 3 days",
"Delete older than 7 days",
"Delete older than 2 weeks (14 days)",
"Delete older than 1 month (30 days)",
"Delete older than 3 months (90 days)",
"Delete older than 6 months (180 days)",
"Delete older than 1 year (365 days)"
};
const char* keep_strings[] =
{
"Keep 1 last event",
"Keep 2 last events",
"Keep 5 last events",
"Keep 10 last events",
"Keep 20 last events",
"Keep 50 last events"
};
struct
{
char* szDescr;
char* szName;
int defIconID;
}
static const iconList[] =
{
{ "Default Action", "actG", IDI_ACTG },
{ "Action 1", "act1", IDI_ACT1 },
{ "Action 2", "act2", IDI_ACT2 },
{ "Delete All", "actDel", IDI_ACTDEL }
};
static HANDLE hIconLibItem[SIZEOF(iconList)];
void InitIcons(void)
{
int i; char szSettingName[100]; SKINICONDESC sid = {0}; TCHAR szFile[MAX_PATH];
GetModuleFileName(hInst, szFile, SIZEOF(szFile));
sid.cbSize = sizeof(SKINICONDESC);
sid.ptszDefaultFile = szFile;
sid.cx = sid.cy = 16;
sid.pszName = szSettingName;
sid.pszSection = ModuleName;
sid.flags = SIDF_PATH_TCHAR;
for (i = 0; i < SIZEOF(iconList); i++)
{
mir_snprintf(szSettingName, SIZEOF(szSettingName), "%s_%s", ModuleName, iconList[i].szName);
sid.pszDescription = (char*)iconList[i].szDescr;
sid.iDefaultIndex = -iconList[i].defIconID;
hIconLibItem[i] = (HANDLE)CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
}
}
HICON LoadIconEx(const char* name)
{
char szSettingName[100];
mir_snprintf(szSettingName, sizeof(szSettingName), "%s_%s", ModuleName, name);
return (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)szSettingName);
}
HANDLE GetIconHandle(const char* name)
{
int i;
for (i=0; i < SIZEOF(iconList); i++)
if (lstrcmpA(iconList[i].szName, name) == 0)
return hIconLibItem[i];
return NULL;
}
void ReleaseIconEx(const char* name)
{
char szSettingName[100];
mir_snprintf(szSettingName, sizeof(szSettingName), "%s_%s", ModuleName, name);
CallService(MS_SKIN2_RELEASEICON, 0, (LPARAM)szSettingName);
}
HANDLE hAllContacts, hSystemHistory;
void ResetListOptions(HWND hwndList)
{
int i;
SendMessage(hwndList, CLM_SETBKBITMAP, 0, 0);
SendMessage(hwndList, CLM_SETBKCOLOR, GetSysColor(COLOR_WINDOW), 0);
SendMessage(hwndList, CLM_SETGREYOUTFLAGS, 0, 0);
SendMessage(hwndList, CLM_SETLEFTMARGIN, 4, 0);
SendMessage(hwndList, CLM_SETINDENT, 10, 0);
for (i=0; i<=FONTID_MAX; i++)
SendMessage(hwndList, CLM_SETTEXTCOLOR, i, GetSysColor(COLOR_WINDOWTEXT));
}
static void ShowAllContactIcons(HWND hwndList)
{
HANDLE hContact, hItem;
SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hAllContacts,
MAKELPARAM(0, DBGetContactSettingByte(NULL, ModuleName, "SweepHistory", 0)));
SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hSystemHistory,
MAKELPARAM(0, DBGetContactSettingByte(NULL, ModuleName, "SweepSHistory", 0)));
for (hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0); hContact;
hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0))
{
hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem,
MAKELPARAM(0, DBGetContactSettingByte(hContact, ModuleName, "SweepHistory", 0)));
}
}//ShowAllContactIcons
void LoadSettings(HWND hwndDlg)
{
int i; CLCINFOITEM cii = {0}; HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST);
cii.cbSize = sizeof(cii);
cii.flags = CLCIIF_GROUPFONT;
cii.pszText = TranslateT("*** Defaut Action ***");
hAllContacts = (HANDLE)SendMessage(hwndList, CLM_ADDINFOITEM, 0, (LPARAM)&cii);
cii.pszText = TranslateT("*** System History ***");
hSystemHistory = (HANDLE)SendMessage(hwndList, CLM_ADDINFOITEM, 0, (LPARAM)&cii);
ShowAllContactIcons(hwndList);
SendDlgItemMessage(hwndDlg, IDC_SSOLDER, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hwndDlg, IDC_SSKEEP, CB_RESETCONTENT, 0, 0);
for (i = 0; i < SIZEOF(time_stamp_strings); i++)
{
TCHAR* ptszTimeStr = (TCHAR*)CallService(MS_LANGPACK_PCHARTOTCHAR, 0, (LPARAM)time_stamp_strings[i]);
SendDlgItemMessage(hwndDlg, IDC_SSOLDER, CB_ADDSTRING, 0, (LPARAM)ptszTimeStr);
mir_free(ptszTimeStr);
}
for (i = 0; i < SIZEOF(keep_strings); i++)
{
TCHAR* ptszTimeStr = (TCHAR*)CallService(MS_LANGPACK_PCHARTOTCHAR, 0, (LPARAM)keep_strings[i]);
SendDlgItemMessage(hwndDlg, IDC_SSKEEP, CB_ADDSTRING, 0, (LPARAM)ptszTimeStr);
mir_free(ptszTimeStr);
}
SendDlgItemMessage(hwndDlg, IDC_SSOLDER, CB_SETCURSEL, DBGetContactSettingByte(NULL, ModuleName, "StartupShutdownOlder", 0), 0);
SendDlgItemMessage(hwndDlg, IDC_SSKEEP, CB_SETCURSEL, DBGetContactSettingByte(NULL, ModuleName, "StartupShutdownKeep", 0), 0);
CheckDlgButton(hwndDlg, IDC_UNSAFEMODE, DBGetContactSettingByte(NULL, ModuleName, "UnsafeMode", 0));
CheckDlgButton(hwndDlg, IDC_SWEEPONCLOSE, DBGetContactSettingByte(NULL, ModuleName, "SweepOnClose", 0));
CheckDlgButton(hwndDlg, IDC_HISTMW, DBGetContactSettingByte(NULL, ModuleName, "ChangeInMW", 0));
}//LoadSettings
void SaveSettings(HWND hwndDlg)
{
int st, i; StatusIconData sid = {0}; HANDLE hContact, hItem; HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST);
DBWriteContactSettingByte(NULL, ModuleName, "StartupShutdownOlder", (BYTE)SendDlgItemMessage(hwndDlg, IDC_SSOLDER, CB_GETCURSEL, 0, 0));
DBWriteContactSettingByte(NULL, ModuleName, "StartupShutdownKeep", (BYTE)SendDlgItemMessage(hwndDlg, IDC_SSKEEP, CB_GETCURSEL, 0, 0));
DBWriteContactSettingByte(NULL, ModuleName, "UnsafeMode", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_UNSAFEMODE));
DBWriteContactSettingByte(NULL, ModuleName, "SweepOnClose", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SWEEPONCLOSE));
DBWriteContactSettingByte(NULL, ModuleName, "ChangeInMW", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_HISTMW));
sid.cbSize = sizeof(sid);
sid.szModule = ModuleName;
DBWriteContactSettingByte(NULL, ModuleName, "SweepHistory",
(BYTE)SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hAllContacts, 0));
DBWriteContactSettingByte(NULL, ModuleName, "SweepSHistory",
(BYTE)SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hSystemHistory, 0));
for (hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0); hContact;
hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0))
{
hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
st = SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, 0);
if ( st != 0 ) DBWriteContactSettingByte(hContact, ModuleName, "SweepHistory", (BYTE)st);
else DBDeleteContactSetting(hContact, ModuleName, "SweepHistory");
// set per-contact icons in status bar
for(i = 0; i < 4; i++)
{
sid.dwId = i;
sid.flags = (st == i) ? 0 : MBF_HIDDEN;
CallService(MS_MSG_MODIFYICON, (WPARAM)hContact, (LPARAM)&sid);
}
}
// set tooltips
st = DBGetContactSettingByte(NULL, ModuleName, "SweepHistory", 0);
sid.dwId = 0;
if (st == 0) sid.szTooltip = Translate("Keep all events");
else if (st == 1) sid.szTooltip = Translate(time_stamp_strings[DBGetContactSettingByte(NULL, ModuleName, "StartupShutdownOlder", 0)]);
else if (st == 2) sid.szTooltip = Translate(keep_strings[DBGetContactSettingByte(NULL, ModuleName, "StartupShutdownKeep", 0)]);
else if (st == 3) sid.szTooltip = Translate("Delete all events");
CallService(MS_MSG_MODIFYICON, 0, (LPARAM)&sid);
sid.dwId = 1;
sid.szTooltip = Translate(time_stamp_strings[DBGetContactSettingByte(NULL, ModuleName, "StartupShutdownOlder", 0)]);
CallService(MS_MSG_MODIFYICON, 0, (LPARAM)&sid);
sid.dwId = 2;
sid.szTooltip = Translate(keep_strings[DBGetContactSettingByte(NULL, ModuleName, "StartupShutdownKeep", 0)]);
CallService(MS_MSG_MODIFYICON, 0, (LPARAM)&sid);
}//SaveSettings
INT_PTR CALLBACK DlgProcHSOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG:
{
HIMAGELIST hIml = ImageList_Create( GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
ILC_MASK | (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16 ), 2, 2 );
HICON hIcon = LoadSkinnedIcon(SKINICON_OTHER_SMALLDOT);
ImageList_AddIcon(hIml, hIcon);
CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0);
hIcon = LoadIconEx("act1");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_ACT1, STM_SETICON, (WPARAM)hIcon, 0);
hIcon = LoadIconEx("act2");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_ACT2, STM_SETICON, (WPARAM)hIcon, 0);
hIcon = LoadIconEx("actDel");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_SETEXTRAIMAGELIST, 0, (LPARAM)hIml);
SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_SETEXTRACOLUMNS, 1, 0);
TranslateDialogDefault(hwndDlg);
ResetListOptions(GetDlgItem(hwndDlg, IDC_LIST));
LoadSettings(hwndDlg);
}
return TRUE;
case WM_DESTROY:
{
HIMAGELIST hIml = (HIMAGELIST)SendDlgItemMessage(hwndDlg, IDC_LIST, CLM_GETEXTRAIMAGELIST, 0, 0);
ImageList_Destroy(hIml);
ReleaseIconEx("act1");
ReleaseIconEx("act2");
ReleaseIconEx("actDel");
}
break;
case WM_COMMAND:
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); // Send message to activate "Apply" button
return TRUE;
case WM_NOTIFY:
{
NMCLISTCONTROL* nmc = (NMCLISTCONTROL*)lParam;
if ( nmc->hdr.idFrom == 0 && nmc->hdr.code == (unsigned)PSN_APPLY )
{
SaveSettings(hwndDlg);
}
else if (nmc->hdr.idFrom == IDC_LIST)
{
switch (nmc->hdr.code)
{
case CLN_NEWCONTACT:
case CLN_LISTREBUILT:
ShowAllContactIcons(nmc->hdr.hwndFrom);
break;
case CLN_OPTIONSCHANGED:
ResetListOptions(nmc->hdr.hwndFrom);
break;
case NM_CLICK:
{
HANDLE hItem; DWORD hitFlags; int iImage;
if ( nmc->iColumn == -1 )
break;
// Find clicked item
hItem = (HANDLE)SendMessage(nmc->hdr.hwndFrom, CLM_HITTEST, (WPARAM)&hitFlags, MAKELPARAM(nmc->pt.x,nmc->pt.y));
// Nothing was clicked
if (hItem == NULL || !(IsHContactContact(hItem) || IsHContactInfo(hItem)))
break;
// It was not our extended icon
if (!(hitFlags & CLCHT_ONITEMEXTRA))
break;
iImage = SendMessage(nmc->hdr.hwndFrom, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(nmc->iColumn, 0));
SendMessage(nmc->hdr.hwndFrom, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(nmc->iColumn, (iImage + 1) % 4));
// Activate Apply button
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
break;
}
}
}
break;
}
return FALSE;
}
int HSOptInitialise(WPARAM wParam,LPARAM lParam)
{
OPTIONSDIALOGPAGE odp = {0};
odp.cbSize = sizeof(odp);
odp.position = 0;
odp.hInstance = hInst;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_HISTORYSWEEPER);
odp.ptszTitle = _T(ModuleName);
odp.ptszGroup = _T("History");
odp.pfnDlgProc = DlgProcHSOpts;
odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
Options_AddPage(wParam, &odp);
return 0;
}
|