/* "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); }