/* Show Contact Gender plugin for Miranda-IM (www.miranda-im.org) (c) 2006-2011 by Thief 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 File name : $URL: http://svn.miranda.im/mainrepo/gender/trunk/main.cpp $ Revision : $Rev: 1688 $ Last change on : $Date: 2011-01-22 19:44:43 +0200 (Сб, 22 янв 2011) $ Last change by : $Author: Thief $ */ #include "commonheaders.h" HINSTANCE g_hInst; static HANDLE hContactMenu = NULL, hContactMenuMale = NULL, hContactMenuFemale = NULL, hContactMenuNotDef = NULL; static HANDLE hSetMale = NULL, hSetFemale = NULL, hSetUndef = NULL, hGenderGetIcon = NULL; HANDLE g_hExtraIcon = NULL; HANDLE g_hIconMale, g_hIconFemale, g_hIconMenu; byte bEnableClistIcon = 1; // do we need clist icon? byte bDrawNoGenderIcon = 0; // enable icon when no info? byte bContactMenuItems = 1; // do we need a contact menu items? byte bMetaAvail = 0; // metacontacts installed? int hLangpack; extern int onOptInitialise(WPARAM wParam, LPARAM lParam); PLUGININFOEX pluginInfo={ sizeof(PLUGININFOEX), "Show Contact Gender", PLUGIN_MAKE_VERSION(0,0,2,1), "Shows contacts gender as an icon in contact list.", "Thief, idea by nile, icons by a0x", "thief@miranda.im", "2006-2011 Alexander Turyak", "http://miranda-ng.org/", UNICODE_AWARE, //doesn't replace anything built-in {0xfb1c17e0, 0x77fc, 0x45a7, {0x9c, 0x8b, 0xe2, 0xbe, 0xf4, 0xf5, 0x6b, 0x28}} /* FB1C17E0-77FC-45A7-9C8B-E2BEF4F56B28 */ }; extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) { g_hInst = hinstDLL; return TRUE; } /* 0FF3991A-5505-479D-A2E0-53DD31C6DFA7 */ #define MIID_GENDER {0x0ff3991a, 0x5505, 0x479d, {0xa2, 0xe0, 0x53, 0xdd, 0x31, 0xc6, 0xdf, 0xa7}} extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_GENDER, MIID_LAST}; extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) { return &pluginInfo; } void setIcon(HANDLE hContact, unsigned int gender) { char *ico; switch (gender) { case 77: ico = "male_icon"; break; case 70: ico = "female_icon"; break; default: ico = (bDrawNoGenderIcon ? "menu_icon" : NULL); break; } ExtraIcon_SetIcon(g_hExtraIcon, hContact, ico); } int applyExtraImage(HANDLE hContact) { if (!bEnableClistIcon) return 0; if (bMetaAvail) { HANDLE hMetacontact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0); if (hMetacontact != NULL) hContact = hMetacontact; } char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); if (!proto) return 0; if ( DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)) return 0; unsigned int gender = DBGetContactSettingByte(hContact, "UserInfo", "Gender", DBGetContactSettingByte(hContact, proto, "Gender", 0)); setIcon(hContact, gender); return 0; } // Returns gender icon for specific contact INT_PTR GetIcon(WPARAM wParam, LPARAM lParam) { char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); unsigned short gender = DBGetContactSettingByte((HANDLE)wParam, "UserInfo", "Gender", DBGetContactSettingByte((HANDLE)wParam, proto, "Gender", 0)); if (gender > 0) { if (gender == 77) return (INT_PTR)Skin_GetIconByHandle(g_hIconMale); if (gender == 70) return (INT_PTR)Skin_GetIconByHandle(g_hIconFemale); } return 0; } int onPrebuildContactMenu(WPARAM wParam, LPARAM lParam) { char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); if (!proto) return 0; CLISTMENUITEM mi = {0}; mi.cbSize = sizeof(CLISTMENUITEM); if (DBGetContactSettingByte((HANDLE)wParam, proto, "ChatRoom", 0) || !(CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND)) mi.flags = CMIM_FLAGS | CMIF_HIDDEN; else mi.flags = CMIM_FLAGS; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenu, (LPARAM)&mi); unsigned short gender = DBGetContactSettingByte((HANDLE)wParam, proto, "Gender", DBGetContactSettingByte((HANDLE)wParam, "UserInfo", "Gender", 0)); CLISTMENUITEM mitem = {0}; mitem.cbSize = sizeof(CLISTMENUITEM); mitem.flags = CMIM_FLAGS; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuMale, (LPARAM)&mitem); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuFemale, (LPARAM)&mitem); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuNotDef, (LPARAM)&mitem); mitem.flags = CMIM_FLAGS | CMIF_CHECKED; switch (gender) { case 77: CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuMale, (LPARAM)&mitem); break; case 70: CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuFemale, (LPARAM)&mitem); break; case 0: CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuNotDef, (LPARAM)&mitem); break; } return 0; } void setGender(HANDLE hContact, unsigned int gender) { DBWriteContactSettingByte(hContact, "UserInfo", "Gender", gender); setIcon(hContact, gender); int metasnum = (bMetaAvail ? CallService(MS_MC_GETNUMCONTACTS,(WPARAM)hContact,0) : 0); for(int i=0; i