summaryrefslogtreecommitdiff
path: root/spamfilter/extraimg.c
blob: 59cd79eae7f19c2ff1bb79af1a4248460e554124 (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
/*

"Spam Filter"-Plugin for Miranda IM

Copyright 2003-2006 Heiko Herkenrath

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 ("SpamFilter-License.txt"); if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/


// -- Includes
#include "common.h"

// -- Variables: Events/Services
HANDLE hHookExtraListRebuild = NULL;
HANDLE hHookExtraImageApply = NULL;
HANDLE hHookDbSettingChanged = NULL;

// -- Variables
HANDLE hSpammerImage;


// -----------------------------------------


void SetSpammerIcon(HANDLE hContact, BOOL bShow)
{
	IconExtraColumn iec;

	ZeroMemory(&iec, sizeof(iec));
	iec.cbSize = sizeof(iec);
	iec.ColumnType = EXTRA_ICON_ADV2;
	iec.hImage = bShow?hSpammerImage:INVALID_HANDLE_VALUE;

	CallService(MS_CLIST_EXTRA_SET_ICON, (WPARAM)hContact, (LPARAM)&iec);
}


static int ExtraImageApply(WPARAM wParam, LPARAM lParam)
{
	// Assign extra icon to contact 
	if (DBGetContactSettingByte((HANDLE)wParam, DB_MODULE_NAME, DB_SETTING_ISSPAMMER, (BYTE)FALSE))
		SetSpammerIcon((HANDLE)wParam, TRUE);

	return 0;
}


static int ExtraImageListRebuild(WPARAM wParam, LPARAM lParam)
{
	HANDLE hContact;

	// Add spam icon to image list of clist extra images
	hSpammerImage = (HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON, (WPARAM)SkinGetIcon(DB_ICON_ISSPAMMER_SETTING, IDI_DEFAULT, FALSE), 0);

	// Update spammer icons for all contacts in list
	for (hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
		ExtraImageApply(wParam, lParam);

	return 0;
}


static int DbSettingChanged(WPARAM wParam, LPARAM lParam)
{
	DBCONTACTWRITESETTING* pdcws = (DBCONTACTWRITESETTING*)lParam;

	// Watch DB_SETTING_ISSPAMMER to be in sync with spammer icon
	if (StrCmpA(pdcws->szModule, DB_MODULE_NAME) == 0)
		if (StrCmpA(pdcws->szSetting, DB_SETTING_ISSPAMMER) == 0)
		{
			BOOL bIsSpammer = (pdcws->value.type==DBVT_DELETED) ? FALSE : (pdcws->value.bVal?TRUE:FALSE);
			SetSpammerIcon((HANDLE)wParam, bIsSpammer);
			NotifySpammerStateChanged((HANDLE)wParam, bIsSpammer);

			if (IsWindow(hwndSpammersInfo))
				PostMessage(hwndSpammersInfo, SFM_REFRESH_SPAMMERS, 0, 0);
		}

	return 0;
}


// ------------------------------------


void InitExtraImg(void)
{
	// Enable CList extra image support (in clist clones)
	if (ServiceExists(MS_CLIST_EXTRA_SET_ICON) && ServiceExists(MS_CLIST_EXTRA_ADD_ICON))
	{
		SkinAddNewIcon(DB_ICON_ISSPAMMER_SETTING, TranslateT("Spam Filter"), TranslateT("Spammer Indicator"), IDI_DEFAULT, FALSE);

		hHookExtraListRebuild = HookEvent(ME_CLIST_EXTRA_LIST_REBUILD, ExtraImageListRebuild);
		hHookExtraImageApply = HookEvent(ME_CLIST_EXTRA_IMAGE_APPLY, ExtraImageApply);
		hHookDbSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DbSettingChanged);
	}
}


void UninitExtraImg(void)
{
	if (hHookExtraListRebuild) UnhookEvent(hHookExtraListRebuild);
	if (hHookExtraImageApply) UnhookEvent(hHookExtraImageApply);
	if (hHookDbSettingChanged) UnhookEvent(hHookDbSettingChanged);
}