summaryrefslogtreecommitdiff
path: root/spamfilter/menuitems.c
blob: ff0412e66c4fd13adea974ca1249095be7de0891 (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
/*

"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/Hooks
HANDLE hHookPreBuildContactMenu;
HANDLE hHookIconsChanged;


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


// -- Contact Menu Items --

void SetContactMenuItem_Mark(BOOL bShowItem)
{
	static HANDLE hContactMenuItemMark = NULL;
	CLISTMENUITEM cmi;

	ZeroMemory(&cmi, sizeof(cmi));
	cmi.cbSize = sizeof(cmi);
	cmi.flags = CMIF_NOTONLIST;
	if (!bShowItem) cmi.flags |= CMIF_HIDDEN;
	cmi.hIcon = SkinGetIcon(DB_ICON_SPAMMANUALLY_SETTING, IDI_DEFAULT, FALSE);

	if (hContactMenuItemMark)
	{
		cmi.flags |= CMIM_FLAGS|CMIM_ICON;
		CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuItemMark, (LPARAM)&cmi);

	} else {

		cmi.pszName = Translate("&Mark as spammer");
		cmi.position = -2050000001; // "Add user to contact list"/"Add permanently to list" is -2050000000
		cmi.pszService = MS_SPAMFILTER_CONTACT_SHOWSETASSPAMMERDIALOG;
	
		hContactMenuItemMark = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM)&cmi);
	}
}


void SetContactMenuItem_Unmark(BOOL bShowItem)
{
	static HANDLE hContactMenuItemUnmark = NULL;
	CLISTMENUITEM cmi;

	ZeroMemory(&cmi, sizeof(cmi));
	cmi.cbSize = sizeof(cmi);
	cmi.flags = CMIF_NOTOFFLIST;
	if (!bShowItem) cmi.flags |= CMIF_HIDDEN;
	cmi.hIcon = SkinGetIcon(DB_ICON_SPAMMANUALLY_SETTING, IDI_DEFAULT, FALSE);

	if (hContactMenuItemUnmark)
	{
		cmi.flags |= CMIM_FLAGS|CMIM_ICON;
		CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuItemUnmark, (LPARAM)&cmi);

	} else {

		cmi.pszName = Translate("&Unmark spammer");
		cmi.position = -2050000001; // "Add user to contact list"/"Add permanently to list" is -2050000000
		cmi.pszService = MS_SPAMFILTER_CONTACT_UNSETSPAMMER;
	
		hContactMenuItemUnmark = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM)&cmi);
	}
}


static int IconsChanged(WPARAM wParam, LPARAM lParam)
{
	// Update menu item
	SetContactMenuItem_Mark(TRUE);
	SetContactMenuItem_Unmark(FALSE);
	return 0;
}


static int PreBuildContactMenu(WPARAM wParam, LPARAM lParam)
{
	HANDLE hContact = (HANDLE)wParam;
	char* pszProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
	
	if (hContact && pszProto)
		if (!DBGetContactSettingByte(hContact, pszProto, "ChatRoom", 0))
		{
			BOOL bNotOnList = DBGetContactSettingByte(hContact, "CList", "NotOnList", 0);
			BOOL bIsSpammer = DBGetContactSettingByte((HANDLE)wParam, DB_MODULE_NAME, DB_SETTING_ISSPAMMER, (BYTE)FALSE);

			SetContactMenuItem_Mark(bNotOnList && !bIsSpammer);
			SetContactMenuItem_Unmark(bIsSpammer && !IsWindow(hwndSpammersInfo));
		}

	return 0;
}


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


void InitMenuItems(void)
{
	if (ServiceExists(MS_SKIN2_GETICON))
		hHookIconsChanged = HookEvent(ME_SKIN2_ICONSCHANGED, IconsChanged);

	hHookPreBuildContactMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PreBuildContactMenu);
	
	SetContactMenuItem_Mark(TRUE);
	SetContactMenuItem_Unmark(FALSE);
}

void UninitMenuItems(void)
{
	if (hHookPreBuildContactMenu) UnhookEvent(hHookPreBuildContactMenu);
	if (hHookIconsChanged) UnhookEvent(hHookIconsChanged);
}