diff options
Diffstat (limited to 'spamfilter/popup.c')
-rw-r--r-- | spamfilter/popup.c | 285 |
1 files changed, 285 insertions, 0 deletions
diff --git a/spamfilter/popup.c b/spamfilter/popup.c new file mode 100644 index 0000000..818d3a9 --- /dev/null +++ b/spamfilter/popup.c @@ -0,0 +1,285 @@ +/*
+
+"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"
+
+// -----------------------------------------
+
+
+// -- Popup Menu Item --
+
+static int InternalServicePopupMenuItemCommand(WPARAM wParam, LPARAM lParam)
+{
+ BOOL bPopupState = !DBGetContactSettingByte(NULL, DB_MODULE_NAME, DB_SETTING_POPUP, DEFAULT_SETTING_POPUP);
+
+ DBWriteContactSettingByte(NULL, DB_MODULE_NAME, DB_SETTING_POPUP, (BYTE)bPopupState);
+ SetPopupMenuItem(bPopupState, FALSE);
+
+ return 0;
+}
+
+void SetPopupMenuItem(BOOL bPopupsActivated, BOOL bGrayItem)
+{
+ static HANDLE hPopupMenuItem = NULL;
+
+ CLISTMENUITEM cmi;
+
+ ZeroMemory(&cmi, sizeof(cmi));
+ cmi.cbSize = sizeof(cmi);
+
+ if (bPopupsActivated)
+ {
+ cmi.pszName = Translate("Disable &spam popups");
+ // Getting icons out of from popup.dll (Plus/Non-Plus) (so they are always up-to-date)
+ cmi.hIcon = SkinGetIcon("popup_enabled", 0, FALSE);
+ if (!cmi.hIcon)
+ cmi.hIcon = GetModuleHandle(_T("popup")) ? (HICON)LoadImage(GetModuleHandleA("popup"), MAKEINTRESOURCE(118), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED) : NULL;
+
+ } else {
+ cmi.pszName = Translate("Enable &spam popups");
+ // Getting icons out of from popup.dll (Plus/Non-Plus) (so they are always up-to-date)
+ cmi.hIcon = SkinGetIcon("popup_disabled", 0, FALSE);
+ if (!cmi.hIcon)
+ cmi.hIcon = GetModuleHandle(_T("popup")) ? (HICON)LoadImage(GetModuleHandleA("popup"), MAKEINTRESOURCE(120), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED) : NULL;
+ }
+
+ if (hPopupMenuItem)
+ {
+ cmi.flags = CMIM_NAME|CMIM_ICON|CMIM_FLAGS;
+
+ if (bGrayItem)
+ cmi.flags |= CMIF_GRAYED;
+
+ CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hPopupMenuItem, (LPARAM)&cmi);
+
+ } else {
+
+ // Item can't be grayed out the first time
+ //cmi.flags = bGrayItem ? CMIF_GRAYED : 0;
+
+ cmi.pszPopupName = Translate("PopUps");
+ cmi.pszService = "SpamFilter/PopupMenuItemCommand";
+
+ CreateServiceFunction(cmi.pszService, InternalServicePopupMenuItemCommand);
+ hPopupMenuItem = (HANDLE)CallService(MS_CLIST_ADDMAINMENUITEM, (WPARAM)0, (LPARAM)&cmi);
+
+ // Call twice to initilialize the grayed out setting
+ if (bGrayItem)
+ SetPopupMenuItem(bPopupsActivated, bGrayItem);
+ }
+}
+
+
+
+// -- Spam Popup --
+BOOL ShowSpamPopup(const char* pszMsgTypeSection, const char* pszMsgTypeName, const WCHAR* pszCustomUserName, HANDLE hContact, DWORD dwFilterType)
+{
+ BOOL bReturn = FALSE;
+ int iMsgType;
+
+ // Support for Popup / PopupPlus
+ #if defined(UNICODE)
+ if (ServiceExists(MS_POPUP_ADDPOPUPW))
+ {
+ POPUPDATAW ppd;
+ HICON hIconBuf;
+ WCHAR* pszText;
+
+ switch (dwFilterType)
+ {
+ case SFT_DISLIKEDMESSAGES_FILTER:
+ pszText = TranslateW("Disliked Message Alert!");
+ break;
+ case SFT_ADVERTISMENT_FILTER:
+ pszText = TranslateW("Advertisment Alert!");
+ break;
+ case SFT_ROBOT_FILTER:
+ pszText = TranslateW("Robot Alert!");
+ break;
+ default:
+ pszText = NULL;
+ }
+
+ ZeroMemory(&ppd, sizeof(ppd));
+ ppd.lchContact = hContact;
+ ppd.colorText = SkinGetColor(DB_COLOR_POPUPTEXT_SETTING, Translate("Popup Text"), Translate("Spam Filter"), RGB(255,255,255), FALSE);
+ ppd.colorBack = SkinGetColor(DB_COLOR_POPUPBACKGROUND_SETTING, Translate("Popup Background"), Translate("Spam Filter"), RGB(0,0,0), FALSE);
+ if (pszText) mir_sntprintf(ppd.lpwzText, ARRAYSIZE(ppd.lpwzText), _T("%s"), pszText);
+ if (pszCustomUserName) mir_sntprintf(ppd.lpwzContactName, ARRAYSIZE(ppd.lpwzContactName), _T("%s"), pszCustomUserName);
+
+ // Determine main icon
+ EnterCriticalSection(&csMsgTypes); // thread safety
+ iMsgType = GetMsgTypeID(pszMsgTypeSection, pszMsgTypeName);
+
+ if ((iMsgType >= 0) && ((int)pamtdMsgTypes[iMsgType].hIcon < 0))
+ hIconBuf = LoadSkinnedIcon((-1)*(int)pamtdMsgTypes[iMsgType].hIcon); // skinned icon
+ else if ((iMsgType >= 0) && pamtdMsgTypes[iMsgType].hIcon)
+ hIconBuf = pamtdMsgTypes[iMsgType].hIcon;
+ else
+ hIconBuf = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_DEFAULT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
+
+ LeaveCriticalSection(&csMsgTypes); // thread safety
+
+ // Overlay small spam icon
+ if (hIconBuf)
+ ppd.lchIcon = OverlayIcon(hIconBuf, SkinGetIcon(DB_ICON_SPAMLAYER_SETTING, IDI_SPAM_LAYER, FALSE), GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
+
+ // I don't know if popup module author made it thread safe...
+ if (CallServiceSync(MS_POPUP_ADDPOPUPW, (WPARAM)&ppd, 0) > 0)
+ bReturn = TRUE;
+
+ if (ppd.lchIcon) DestroyIcon(ppd.lchIcon);
+ }
+ #else
+ if (ServiceExists(MS_POPUP_ADDPOPUPEX))
+ {
+ POPUPDATAEX ppd;
+ HICON hIconBuf;
+ char* pszText;
+
+ switch (dwFilterType)
+ {
+ case SFT_DISLIKEDMESSAGES_FILTER:
+ pszText = Translate("Disliked Message Alert!");
+ break;
+ case SFT_ADVERTISMENT_FILTER:
+ pszText = Translate("Advertisment Alert!");
+ break;
+ case SFT_ROBOT_FILTER:
+ pszText = Translate("Robot Alert!");
+ break;
+ default:
+ pszText = NULL;
+ }
+
+ ZeroMemory(&ppd, sizeof(ppd));
+ ppd.lchContact = hContact;
+ ppd.colorText = SkinGetColor(DB_COLOR_POPUPTEXT_SETTING, Translate("Popup Text"), Translate("Spam Filter"), RGB(255,255,255), FALSE);
+ ppd.colorBack = SkinGetColor(DB_COLOR_POPUPBACKGROUND_SETTING, Translate("Popup Background"), Translate("Spam Filter"), RGB(0,0,0), FALSE);
+ if (pszText)
+ mir_snprintf(ppd.lpzText, ARRAYSIZE(ppd.lpzText), "%s", pszText);
+ if (pszCustomUserName)
+ mir_snprintf(ppd.lpzContactName, ARRAYSIZE(ppd.lpzContactName), "%s", pszCustomUserName);
+
+ // Determine main icon
+ EnterCriticalSection(&csMsgTypes); // thread safety
+ iMsgType = GetMsgTypeID(pszMsgTypeSection, pszMsgTypeName);
+
+ if ((iMsgType >= 0) && ((int)pamtdMsgTypes[iMsgType].hIcon < 0))
+ hIconBuf = LoadSkinnedIcon((-1)*(int)pamtdMsgTypes[iMsgType].hIcon); // skinned icon
+ else if ((iMsgType >= 0) && pamtdMsgTypes[iMsgType].hIcon)
+ hIconBuf = pamtdMsgTypes[iMsgType].hIcon;
+ else
+ hIconBuf = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_DEFAULT), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
+
+ LeaveCriticalSection(&csMsgTypes); // thread safety
+
+ // Overlay small spam icon
+ if (hIconBuf)
+ ppd.lchIcon = OverlayIcon(hIconBuf, SkinGetIcon(DB_ICON_SPAMLAYER_SETTING, IDI_SPAM_LAYER, FALSE), GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
+
+ // Support for Popup Plus
+ if (ServiceExists(MS_POPUP_ADDCLASS))
+ {
+ ppd.skinBack = ppd.colorBack;
+ ppd.colorBack = POPUP_USE_SKINNED_BG;
+ ppd.lpzClass = (LPCTSTR)POPUP_CLASS_SPAM; // type "LPCTSTR" of lpzClass is wrong (or: POPUP_CLASS_DEFAULT)
+ }
+
+ // I don't know if popup module author made it thread safe...
+ if (CallServiceSync(MS_POPUP_ADDPOPUPEX, (WPARAM)&ppd, 0) > 0)
+ bReturn = TRUE;
+
+ if (ppd.lchIcon) DestroyIcon(ppd.lchIcon);
+ }
+ #endif
+
+ // Support for OSD / WanneBeOSD
+ if (ServiceExists("OSD/Announce")) // no m_osd.h file yet available.. .don't like it :-/
+ {
+ WCHAR* pszText;
+
+ switch (dwFilterType)
+ {
+ case SFT_DISLIKEDMESSAGES_FILTER:
+ pszText = TranslateT("Disliked Message Alert!");
+ break;
+
+ case SFT_ADVERTISMENT_FILTER:
+ pszText = TranslateT("Advertisment Alert!");
+ break;
+
+ case SFT_ROBOT_FILTER:
+ pszText = TranslateT("Robot Alert!");
+ break;
+
+ default:
+ pszText = NULL;
+ }
+
+ if (pszText)
+ {
+ // I don't know if OSD module author made it thread safe...
+ // quite bad: return value of OSDAnnounce does not indicate anything (SendMessage result)
+ // bad unicode implementation (simply expects unicode text when wbosdW.dll is used)
+ // -> might cuase crashes (buffer overruns) when SF-Unicode is run with OSD-Ansi
+ if (CallService("OSD/Announce", (WPARAM)pszText, (LPARAM)0) == 0);
+ bReturn = TRUE;
+ }
+ }
+
+ return bReturn;
+}
+
+
+// -- Popup Available --
+
+BOOL IsPopupAvailable(BOOL bAlsoOSD)
+{
+ #if defined(UNICODE)
+ return (ServiceExists(MS_POPUP_ADDPOPUPW) || (bAlsoOSD ? ServiceExists("OSD/Announce") : FALSE));
+ #else
+ return (ServiceExists(MS_POPUP_ADDPOPUPEX) || (bAlsoOSD ? ServiceExists("OSD/Announce") : FALSE));
+ #endif
+}
+
+
+// ------------------------------------
+
+
+void InitPopup(void)
+{
+ // Add class (Support for PopupPlus)
+ #if !defined(UNICODE)
+ if (ServiceExists(MS_POPUP_ADDCLASS))
+ CallService(MS_POPUP_ADDCLASS, 0, (LPARAM)POPUP_CLASS_SPAM);
+ #endif
+
+ if (IsPopupAvailable(FALSE))
+ SkinAddNewIcon(DB_ICON_SPAMLAYER_SETTING, TranslateT("Spam Filter"), TranslateT("Spam Message Overlay"), IDI_SPAM_LAYER, FALSE);
+}
+
+
+void UninitPopup(void)
+{
+}
\ No newline at end of file |