summaryrefslogtreecommitdiff
path: root/plugins/NewXstatusNotify/src/indsnd.cpp
blob: 3c196a4d4e32052d231ce805cf2462249ee7302a (plain)
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
/*
	NewXstatusNotify YM - Plugin for Miranda IM
	Copyright (c) 2001-2004 Luca Santarelli
	Copyright (c) 2005-2007 Vasilich
	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"

void PreviewSound(HWND hList)
{
	wchar_t buff[MAX_PATH], stzSoundPath[MAX_PATH];

	LVITEM lvi = { 0 };
	lvi.mask = LVIF_PARAM;
	lvi.iItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
	ListView_GetItem(hList, &lvi);

	int hlpStatus = lvi.lParam;

	ListView_GetItemText(hList, lvi.iItem, 1, buff, _countof(buff));
	if (!mir_wstrcmp(buff, TranslateW(DEFAULT_SOUND))) {
		if (hlpStatus < ID_STATUS_MIN)
			Skin_PlaySound(StatusListEx[hlpStatus].lpzSkinSoundName);
		else
			Skin_PlaySound(StatusList[Index(hlpStatus)].lpzSkinSoundName);
	}
	else {
		PathToAbsoluteW(buff, stzSoundPath);
		Skin_PlaySoundFile(stzSoundPath);
	}
}

BOOL RemoveSoundFromList(HWND hList)
{
	int iSel = ListView_GetSelectionMark(hList);
	if (iSel != -1) {
		iSel = -1;
		while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1)
			ListView_SetItemText(hList, iSel, 1, TranslateW(DEFAULT_SOUND));
		return TRUE;
	}

	return FALSE;
}

wchar_t *SelectSound(HWND hwndDlg, wchar_t *buff, size_t bufflen)
{
	OPENFILENAME ofn = { 0 };

	HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
	ListView_GetItemText(hList, ListView_GetNextItem(hList, -1, LVNI_SELECTED), 1, buff, (DWORD)bufflen);
	if (!mir_wstrcmp(buff, TranslateW(DEFAULT_SOUND)))
		buff = nullptr;

	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = GetParent(hwndDlg);
	ofn.hInstance = g_plugin.getInst();
	wchar_t filter[MAX_PATH];
	if (GetModuleHandle(L"bass_interface.dll"))
		mir_snwprintf(filter, L"%s (*.wav, *.mp3, *.ogg)%c*.wav;*.mp3;*.ogg%c%s (*.*)%c*%c", TranslateT("Sound files"), 0, 0, TranslateT("All files"), 0, 0);
	else
		mir_snwprintf(filter, L"%s (*.wav)%c*.wav%c%s (*.*)%c*%c", TranslateT("Wave files"), 0, 0, TranslateT("All files"), 0, 0);
	ofn.lpstrFilter = filter;
	ofn.lpstrFile = buff;
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
	ofn.nMaxFile = MAX_PATH;
	ofn.nMaxFileTitle = MAX_PATH;
	ofn.lpstrDefExt = L"";
	if (GetOpenFileName(&ofn))
		return buff;

	return nullptr;
}

HIMAGELIST GetStatusIconsImgList(char *szProto)
{
	HIMAGELIST hList = nullptr;
	if (szProto) {
		hList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, STATUS_COUNT - 1, 0);
		if (hList != nullptr) {
			for (int i = ID_STATUS_MIN; i <= ID_STATUS_MAX; i++)
				ImageList_AddIcon(hList, Skin_LoadProtoIcon(szProto, i));
			ImageList_AddSkinIcon(hList, SKINICON_OTHER_USERONLINE);
		}
	}

	return hList;
}

INT_PTR CALLBACK DlgProcSoundUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static MCONTACT hContact = NULL;
	HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			hContact = lParam;
			char *szProto = Proto_GetBaseAccountName(hContact);

			ListView_SetImageList(hList, GetStatusIconsImgList(szProto), LVSIL_SMALL);
			ListView_SetExtendedListViewStyleEx(hList, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);

			RECT rc = { 0 };
			GetClientRect(hList, &rc);

			LV_COLUMN lvc = { 0 };
			lvc.mask = LVCF_WIDTH | LVCF_TEXT;
			lvc.cx = STATUS_COLUMN;
			lvc.pszText = TranslateT("Status");
			ListView_InsertColumn(hList, 0, &lvc);

			lvc.cx = rc.right - STATUS_COLUMN - GetSystemMetrics(SM_CXVSCROLL);
			lvc.pszText = TranslateT("Sound file");
			ListView_InsertColumn(hList, 1, &lvc);

			if (szProto) {
				DBVARIANT dbv;
				wchar_t buff[MAX_PATH];

				for (int i = ID_STATUS_MAX; i >= ID_STATUS_MIN; i--) {
					int flags = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_2, 0);
					if (flags == 0)
						flags = PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND | PF2_HEAVYDND | PF2_FREECHAT;

					if ((flags & Proto_Status2Flag(i)) || i == ID_STATUS_OFFLINE) {
						LV_ITEM lvi = { 0 };
						lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
						lvi.iItem = 0;
						lvi.iSubItem = 0;
						lvi.iImage = Index(i);
						lvi.lParam = (LPARAM)i;
						lvi.pszText = TranslateW(StatusList[Index(i)].lpzSkinSoundDesc);
						lvi.iItem = ListView_InsertItem(hList, &lvi);

						if (!g_plugin.getWString(hContact, StatusList[Index(i)].lpzSkinSoundName, &dbv)) {
							mir_wstrcpy(buff, dbv.pwszVal);
							db_free(&dbv);
						}
						else mir_wstrcpy(buff, TranslateW(DEFAULT_SOUND));

						ListView_SetItemText(hList, lvi.iItem, 1, buff);
					}
				}

				for (int i = 0; i <= ID_STATUSEX_MAX; i++) {
					LV_ITEM lvi = { 0 };
					lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
					lvi.iItem = 0;
					lvi.iSubItem = 0;
					lvi.iImage = Index(ID_STATUS_MAX) + 1; // additional icon
					lvi.lParam = (LPARAM)i;
					lvi.pszText = TranslateW(StatusListEx[i].lpzSkinSoundDesc);
					lvi.iItem = ListView_InsertItem(hList, &lvi);

					if (!g_plugin.getWString(hContact, StatusList[i].lpzSkinSoundName, &dbv)) {
						wcsncpy(buff, dbv.pwszVal, _countof(buff)-1);
						db_free(&dbv);
					}
					else wcsncpy(buff, TranslateW(DEFAULT_SOUND), _countof(buff)-1);

					ListView_SetItemText(hList, lvi.iItem, 1, buff);
				}
			}

			CheckDlgButton(hwndDlg, IDC_CHECK_NOTIFYSOUNDS, g_plugin.getByte(hContact, "EnableSounds", 1) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_CHECK_NOTIFYPOPUPS, g_plugin.getByte(hContact, "EnablePopups", 1) ? BST_CHECKED : BST_UNCHECKED);

			ShowWindow(GetDlgItem(hwndDlg, IDC_INDSNDLIST), opt.UseIndSnd ? SW_SHOW : SW_HIDE);
			ShowWindow(GetDlgItem(hwndDlg, IDC_TEXT_ENABLE_IS), opt.UseIndSnd ? SW_HIDE : SW_SHOW);
			ShowWindow(GetDlgItem(hwndDlg, IDC_CHANGE), opt.UseIndSnd ? SW_SHOW : SW_HIDE);
			ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), opt.UseIndSnd ? SW_SHOW : SW_HIDE);
			ShowWindow(GetDlgItem(hwndDlg, IDC_DELETE), opt.UseIndSnd ? SW_SHOW : SW_HIDE);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_PREVIEW:
			if (ListView_GetSelectionMark(hList) != -1)
				PreviewSound(hList);
			break;
		case IDC_CHANGE:
			{
				int iSel = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_INDSNDLIST), -1, LVNI_SELECTED);
				if (iSel != -1) {
					wchar_t stzFilePath[MAX_PATH];
					if (SelectSound(hwndDlg, stzFilePath, MAX_PATH - 1) != nullptr) {
						iSel = -1;
						while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1)
							ListView_SetItemText(hList, iSel, 1, stzFilePath);

						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					}
				}
			}
			break;
		case IDC_DELETE:
			if (ListView_GetSelectionMark(hList) != -1)
				if (RemoveSoundFromList(GetDlgItem(hwndDlg, IDC_INDSNDLIST)))
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_CHECK_NOTIFYSOUNDS:
			g_plugin.setByte(hContact, "EnableSounds", IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOTIFYSOUNDS) ? 1 : 0);
			break;
		case IDC_CHECK_NOTIFYPOPUPS:
			g_plugin.setByte(hContact, "EnablePopups", IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOTIFYPOPUPS) ? 1 : 0);
			break;
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == PSN_APPLY) {
			wchar_t buff[MAX_PATH];

			LVITEM lvi = { 0 };
			lvi.mask = LVIF_PARAM;
			//Cycle through the list reading the text associated to each status.
			for (lvi.iItem = ListView_GetItemCount(hList) - 1; lvi.iItem >= 0; lvi.iItem--) {
				ListView_GetItem(hList, &lvi);
				ListView_GetItemText(hList, lvi.iItem, 1, buff, _countof(buff));

				if (!mir_wstrcmp(buff, TranslateW(DEFAULT_SOUND))) {
					if (lvi.lParam < ID_STATUS_MIN)
						g_plugin.delSetting(hContact, StatusListEx[lvi.lParam].lpzSkinSoundName);
					else
						g_plugin.delSetting(hContact, StatusList[Index(lvi.lParam)].lpzSkinSoundName);
				}
				else {
					wchar_t stzSoundPath[MAX_PATH] = { 0 };
					PathToRelativeW(buff, stzSoundPath);
					if (lvi.lParam < ID_STATUS_MIN)
						g_plugin.setWString(hContact, StatusListEx[lvi.lParam].lpzSkinSoundName, stzSoundPath);
					else
						g_plugin.setWString(hContact, StatusList[Index(lvi.lParam)].lpzSkinSoundName, stzSoundPath);
				}
			}

			return TRUE;
		}

		int hlpControlID = (int)wParam;
		switch (hlpControlID) {
		case IDC_INDSNDLIST:
			if (((LPNMHDR)lParam)->code == NM_DBLCLK) {
				wchar_t stzFilePath[MAX_PATH];
				if (SelectSound(hwndDlg, stzFilePath, MAX_PATH - 1) != nullptr) {
					int iSel = -1;
					while ((iSel = ListView_GetNextItem(hList, iSel, LVNI_SELECTED)) != -1)
						ListView_SetItemText(hList, iSel, 1, stzFilePath);

					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				}
				return TRUE;
			}
			else if (((LPNMHDR)lParam)->code == LVN_KEYDOWN) {
				LPNMLVKEYDOWN pnkd = (LPNMLVKEYDOWN)lParam;
				if (pnkd->wVKey == VK_DELETE)
					RemoveSoundFromList(GetDlgItem(hwndDlg, IDC_INDSNDLIST));
			}

			break;
		}
		break;
	}
	return FALSE;
}

void ResetListOptions(HWND hwndList)
{
	SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | CLS_SHOWHIDDEN);
}

__inline int GetExtraImage(HWND hwndList, HANDLE hItem, int column)
{
	return SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(column, 0));
}

__inline void SetExtraImage(HWND hwndList, HANDLE hItem, int column, int imageID)
{
	SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(column, imageID));
}

void SetAllContactsIcons(HWND hwndList)
{
	BYTE EnableSounds, EnablePopups, EnableXStatus, EnableXLogging, EnableStatusMsg, EnableSMsgLogging;

	for (auto &hContact : Contacts()) {
		HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_FINDCONTACT, hContact, 0);
		if (hItem) {
			char *szProto = Proto_GetBaseAccountName(hContact);
			if (szProto) {
				EnableSounds = g_plugin.getByte(hContact, "EnableSounds", 1);
				EnablePopups = g_plugin.getByte(hContact, "EnablePopups", 1);
				EnableXStatus = g_plugin.getByte(hContact, "EnableXStatusNotify", 1);
				EnableXLogging = g_plugin.getByte(hContact, "EnableXLogging", 1);
				EnableStatusMsg = g_plugin.getByte(hContact, "EnableSMsgNotify", 1);
				EnableSMsgLogging = g_plugin.getByte(hContact, "EnableSMsgLogging", 1);
			}
			else
				EnableSounds = EnablePopups = EnableXStatus = EnableXLogging = EnableStatusMsg = EnableSMsgLogging = 0;

			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_SOUND, EnableSounds ? EXTRA_IMAGE_SOUND : EXTRA_IMAGE_DOT);
			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_POPUP, EnablePopups ? EXTRA_IMAGE_POPUP : EXTRA_IMAGE_DOT);
			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_XSTATUS, EnableXStatus ? EXTRA_IMAGE_XSTATUS : EXTRA_IMAGE_DOT);
			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_XLOGGING, EnableXLogging ? EXTRA_IMAGE_XLOGGING : EXTRA_IMAGE_DOT);
			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_STATUSMSG, EnableStatusMsg ? EXTRA_IMAGE_STATUSMSG : EXTRA_IMAGE_DOT);
			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_SMSGLOGGING, EnableSMsgLogging ? EXTRA_IMAGE_SMSGLOGGING : EXTRA_IMAGE_DOT);
			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_DISABLEALL, EXTRA_IMAGE_DISABLEALL);
			SetExtraImage(hwndList, hItem, EXTRA_IMAGE_ENABLEALL, EXTRA_IMAGE_ENABLEALL);
		}
	}
}

void SetGroupsIcons(HWND hwndList, HANDLE hFirstItem, HANDLE hParentItem, int *groupChildCount)
{
	int iconOn[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
	int childCount[8] = { 0 };
	HANDLE hItem;

	int typeOfFirst = SendMessage(hwndList, CLM_GETITEMTYPE, (WPARAM)hFirstItem, 0);
	if (typeOfFirst == CLCIT_GROUP)
		hItem = hFirstItem;
	else
		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, (LPARAM)hFirstItem);

	while (hItem) {
		HANDLE hChildItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem);
		if (hChildItem)
			SetGroupsIcons(hwndList, hChildItem, hItem, childCount);

		for (int i = 0; i < _countof(iconOn); i++) {
			if (iconOn[i] && GetExtraImage(hwndList, hItem, i) == EXTRA_IMAGE_DOT)
				iconOn[i] = 0;
		}

		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, (LPARAM)hItem);
	}

	//check contacts
	if (typeOfFirst == CLCIT_CONTACT)
		hItem = hFirstItem;
	else
		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, (LPARAM)hFirstItem);

	while (hItem) {
		for (int i = 0; i < _countof(iconOn); i++) {
			int image = GetExtraImage(hwndList, hItem, i);
			if (iconOn[i] && image == EXTRA_IMAGE_DOT)
				iconOn[i] = 0;

			if (image != EMPTY_EXTRA_ICON)
				childCount[i]++;
		}

		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, (LPARAM)hItem);
	}

	//set icons
	for (int i = 0; i < _countof(iconOn); i++) {
		SetExtraImage(hwndList, hParentItem, i, childCount[i] ? (iconOn[i] ? i : EXTRA_IMAGE_DOT) : EMPTY_EXTRA_ICON);
		if (groupChildCount)
			groupChildCount[i] += childCount[i];
	}
}

void SetAllChildrenIcons(HWND hwndList, HANDLE hFirstItem, int column, int image)
{
	HANDLE hItem, hChildItem;

	int typeOfFirst = SendMessage(hwndList, CLM_GETITEMTYPE, (WPARAM)hFirstItem, 0);
	if (typeOfFirst == CLCIT_GROUP)
		hItem = hFirstItem;
	else
		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, (LPARAM)hFirstItem);

	while (hItem) {
		hChildItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem);
		if (hChildItem)
			SetAllChildrenIcons(hwndList, hChildItem, column, image);

		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, (LPARAM)hItem);
	}

	if (typeOfFirst == CLCIT_CONTACT)
		hItem = hFirstItem;
	else
		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, (LPARAM)hFirstItem);

	while (hItem) {
		int oldIcon = GetExtraImage(hwndList, hItem, column);
		if (oldIcon != EMPTY_EXTRA_ICON && oldIcon != image)
			SetExtraImage(hwndList, hItem, column, image);

		hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, (LPARAM)hItem);
	}
}

INT_PTR CALLBACK DlgProcFiltering(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
{
	static HANDLE hItemAll;
	switch (msg) {
	case WM_INITDIALOG:
	{
		TranslateDialogDefault(hwndDlg);

		HIMAGELIST hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 3, 3);

		ImageList_AddIcon(hImageList, IcoLib_GetIconByHandle(iconList[ICO_SOUND].hIcolib));
		SendDlgItemMessage(hwndDlg, IDC_SOUNDICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_SOUND, ILD_NORMAL), 0);
		ImageList_AddIcon(hImageList, Skin_LoadIcon(SKINICON_OTHER_POPUP));
		SendDlgItemMessage(hwndDlg, IDC_POPUPICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_POPUP, ILD_NORMAL), 0);
		ImageList_AddIcon(hImageList, IcoLib_GetIconByHandle(iconList[ICO_XSTATUS].hIcolib));
		SendDlgItemMessage(hwndDlg, IDC_XSTATUSICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_XSTATUS, ILD_NORMAL), 0);
		ImageList_AddIcon(hImageList, IcoLib_GetIconByHandle(iconList[ICO_LOGGING_XSTATUS].hIcolib));
		SendDlgItemMessage(hwndDlg, IDC_XLOGGINGICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_XLOGGING, ILD_NORMAL), 0);
		ImageList_AddIcon(hImageList, IcoLib_GetIconByHandle(iconList[ICO_STATUS_MESSAGE].hIcolib));
		SendDlgItemMessage(hwndDlg, IDC_SMSGICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_STATUSMSG, ILD_NORMAL), 0);
		ImageList_AddIcon(hImageList, IcoLib_GetIconByHandle(iconList[ICO_LOGGING_SMSG].hIcolib));
		SendDlgItemMessage(hwndDlg, IDC_SMSGLOGGINGICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_SMSGLOGGING, ILD_NORMAL), 0);
		ImageList_AddIcon(hImageList, IcoLib_GetIconByHandle(iconList[ICO_DISABLEALL].hIcolib));
		SendDlgItemMessage(hwndDlg, IDC_DISABLEALLICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_DISABLEALL, ILD_NORMAL), 0);
		ImageList_AddIcon(hImageList, IcoLib_GetIconByHandle(iconList[ICO_ENABLEALL].hIcolib));
		SendDlgItemMessage(hwndDlg, IDC_ENABLEALLICON, STM_SETICON, (WPARAM)ImageList_GetIcon(hImageList, EXTRA_IMAGE_ENABLEALL, ILD_NORMAL), 0);

		ImageList_AddSkinIcon(hImageList, SKINICON_OTHER_SMALLDOT);

		SendDlgItemMessage(hwndDlg, IDC_INDSNDLIST, CLM_SETEXTRAIMAGELIST, 0, (LPARAM)hImageList);
		SendDlgItemMessage(hwndDlg, IDC_INDSNDLIST, CLM_SETEXTRACOLUMNS, 8, 0);

		HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
		ResetListOptions(hList);

		CLCINFOITEM cii = { 0 };
		cii.cbSize = sizeof(cii);
		cii.flags = CLCIIF_GROUPFONT;
		cii.pszText = TranslateT("** All contacts **");
		hItemAll = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_INDSNDLIST, CLM_ADDINFOITEM, 0, (LPARAM)&cii);

		return TRUE;
	}
	case WM_SETFOCUS:
		SetFocus(GetDlgItem(hwndDlg, IDC_INDSNDLIST));
		break;

	case WM_NOTIFY:
	{
		HWND hList = GetDlgItem(hwndDlg, IDC_INDSNDLIST);
		switch (((LPNMHDR)lParam)->idFrom) {
		case IDC_INDSNDLIST:
			switch (((LPNMHDR)lParam)->code) {
			case CLN_NEWCONTACT:
			case CLN_LISTREBUILT:
				SetAllContactsIcons(hList);
				//fall through
			case CLN_CONTACTMOVED:
				SetGroupsIcons(hList, (HANDLE)SendMessage(hList, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, nullptr);
				break;
			case CLN_OPTIONSCHANGED:
				ResetListOptions(hList);
				break;
			case NM_CLICK:
			{
				NMCLISTCONTROL *nm = (NMCLISTCONTROL *)lParam;
				DWORD hitFlags;

				// Make sure we have an extra column
				if (nm->iColumn == -1)
					break;

				// Find clicked item
				HANDLE hItem = (HANDLE)SendMessage(hList, CLM_HITTEST, (WPARAM)&hitFlags, MAKELPARAM(nm->pt.x, nm->pt.y));
				if (hItem == nullptr)
					break;
				if (!(hitFlags & CLCHT_ONITEMEXTRA))
					break;

				int itemType = SendMessage(hList, CLM_GETITEMTYPE, (WPARAM)hItem, 0);

				// Get image in clicked column 
				int image = GetExtraImage(hList, hItem, nm->iColumn);
				if (image == EXTRA_IMAGE_DOT)
					image = nm->iColumn;
				else if (image >= EXTRA_IMAGE_SOUND && image <= EXTRA_IMAGE_SMSGLOGGING)
					image = EXTRA_IMAGE_DOT;

				// Get item type (contact, group, etc...)
				if (itemType == CLCIT_CONTACT) {
					if (image == EXTRA_IMAGE_DISABLEALL) {
						for (int i = 0; i < 6; i++)
							SetExtraImage(hList, hItem, i, EXTRA_IMAGE_DOT);
					}
					else if (image == EXTRA_IMAGE_ENABLEALL) {
						for (int i = 0; i < 6; i++)
							SetExtraImage(hList, hItem, i, i);
					}
					else
						SetExtraImage(hList, hItem, nm->iColumn, image);
				}
				else if (itemType == CLCIT_INFO || itemType == CLCIT_GROUP) {
					if (itemType == CLCIT_GROUP)
						hItem = (HANDLE)SendMessage(hList, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem);

					if (hItem) {
						if (image == EXTRA_IMAGE_DISABLEALL) {
							for (int i = 0; i < 6; i++)
								SetAllChildrenIcons(hList, hItem, i, EXTRA_IMAGE_DOT);
						}
						else if (image == EXTRA_IMAGE_ENABLEALL) {
							for (int i = 0; i < 6; i++)
								SetAllChildrenIcons(hList, hItem, i, i);
						}
						else
							SetAllChildrenIcons(hList, hItem, nm->iColumn, image);
					}
				}

				// Update the all/none icons
				SetGroupsIcons(hList, (HANDLE)SendMessage(hList, CLM_GETNEXTITEM, CLGN_ROOT, 0), hItemAll, nullptr);
				// Activate Apply button
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			}
			}
			break;
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_APPLY:
				for (auto &hContact : Contacts()) {
					HANDLE hItem = (HANDLE)SendMessage(hList, CLM_FINDCONTACT, hContact, 0);
					if (hItem) {
						if (GetExtraImage(hList, hItem, EXTRA_IMAGE_SOUND) == EXTRA_IMAGE_SOUND)
							g_plugin.delSetting(hContact, "EnableSounds");
						else
							g_plugin.setByte(hContact, "EnableSounds", 0);

						if (GetExtraImage(hList, hItem, EXTRA_IMAGE_POPUP) == EXTRA_IMAGE_POPUP)
							g_plugin.delSetting(hContact, "EnablePopups");
						else
							g_plugin.setByte(hContact, "EnablePopups", 0);

						if (GetExtraImage(hList, hItem, EXTRA_IMAGE_XSTATUS) == EXTRA_IMAGE_XSTATUS)
							g_plugin.delSetting(hContact, "EnableXStatusNotify");
						else
							g_plugin.setByte(hContact, "EnableXStatusNotify", 0);

						if (GetExtraImage(hList, hItem, EXTRA_IMAGE_XLOGGING) == EXTRA_IMAGE_XLOGGING)
							g_plugin.delSetting(hContact, "EnableXLogging");
						else
							g_plugin.setByte(hContact, "EnableXLogging", 0);

						if (GetExtraImage(hList, hItem, EXTRA_IMAGE_STATUSMSG) == EXTRA_IMAGE_STATUSMSG)
							g_plugin.delSetting(hContact, "EnableSMsgNotify");
						else
							g_plugin.setByte(hContact, "EnableSMsgNotify", 0);

						if (GetExtraImage(hList, hItem, EXTRA_IMAGE_SMSGLOGGING) == EXTRA_IMAGE_SMSGLOGGING)
							g_plugin.delSetting(hContact, "EnableSMsgLogging");
						else
							g_plugin.setByte(hContact, "EnableSMsgLogging", 0);
					}
				}
				return TRUE;
			}
		}
	}
	break;

	case WM_DESTROY:
		HIMAGELIST hImageList = (HIMAGELIST)SendDlgItemMessage(hwndDlg, IDC_INDSNDLIST, CLM_GETEXTRAIMAGELIST, 0, 0);
		for (int i = 0; i < ImageList_GetImageCount(hImageList); i++)
			DestroyIcon(ImageList_GetIcon(hImageList, i, ILD_NORMAL));
		ImageList_Destroy(hImageList);
		break;
	}
	return FALSE;
}

int UserInfoInitialise(WPARAM wParam, LPARAM lParam)
{
	if (lParam) {
		OPTIONSDIALOGPAGE odp = {};
		odp.position = 100000000;
		odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_SOUNDS);
		odp.szTitle.a = LPGEN("Status Notify");
		odp.pfnDlgProc = DlgProcSoundUIPage;
		g_plugin.addUserInfo(wParam, &odp);
	}
	return 0;
}