summaryrefslogtreecommitdiff
path: root/plugins/AuthState/src/main.cpp
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-03-19 14:25:05 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-03-19 14:25:05 +0000
commit49ef96492c4a5a65ca234eaebcfa9846be527975 (patch)
treeb4ac82ecb0c7203b72a9cdfeaf2025a83af49269 /plugins/AuthState/src/main.cpp
parent8b99a8b3a16763267cb2339bb822c2595b659935 (diff)
AuthState: fix extraicon 'corruption'; code optimization
git-svn-id: http://svn.miranda-ng.org/main/trunk@16510 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AuthState/src/main.cpp')
-rw-r--r--plugins/AuthState/src/main.cpp120
1 files changed, 49 insertions, 71 deletions
diff --git a/plugins/AuthState/src/main.cpp b/plugins/AuthState/src/main.cpp
index 230edfd5c6..253463fa31 100644
--- a/plugins/AuthState/src/main.cpp
+++ b/plugins/AuthState/src/main.cpp
@@ -20,20 +20,25 @@
#include "stdafx.h"
HINSTANCE g_hInst;
-static HANDLE hOptInitialise;
-static HANDLE hHookExtraIconsRebuild, hHookExtraIconsApply;
-static HANDLE hAuthMenuSelected;
static HGENMENU hUserMenu;
HANDLE hExtraIcon;
int hLangpack;
-BYTE bUseAuthIcon = 0, bUseGrantIcon = 0, bContactMenuItem = 0, bIconsForRecentContacts = 0, bUseAuthGroup = 0;
+Opts Options;
-enum {
- icon_none,
- icon_auth,
- icon_grant,
- icon_both
+static IconItem iconList[] =
+{
+ { LPGEN("Request"), "auth_icon", IDI_AUTH },
+ { LPGEN("Grant"), "grant_icon", IDI_GRANT },
+ { LPGEN("Request & Grant"), "authgrant_icon", IDI_AUTHGRANT }
+};
+
+enum
+{
+ ICON_NONE = -1,
+ ICON_AUTH,
+ ICON_GRANT,
+ ICON_BOTH
};
PLUGININFOEX pluginInfo = {
@@ -63,54 +68,45 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
INT_PTR getIconToUse(MCONTACT hContact, LPARAM)
{
- char *proto = GetContactProto(hContact);
+ const char *proto = GetContactProto(hContact);
// if (lParam == 1) return icon_none;
- if (!db_get_b(hContact, "AuthState", "ShowIcons", !bIconsForRecentContacts)) return icon_none;
+ if (!db_get_b(hContact, "AuthState", "ShowIcons", !Options.bIconsForRecentContacts)) return ICON_NONE;
if (db_get_b(0, "ICQ", "UseServerCList", 0))
if (db_get_dw(hContact, proto, "ServerId", 1) == 0)
- return icon_both;
+ return ICON_BOTH;
// Facebook contact type
int type = db_get_b(hContact, proto, "ContactType", 0);
- if (bUseAuthIcon & bUseGrantIcon)
+ if (Options.bUseAuthIcon & Options.bUseGrantIcon)
if ((db_get_b(hContact, proto, "Auth", 0) && db_get_b(hContact, proto, "Grant", 0)) || type == 2)
- return icon_both;
+ return ICON_BOTH;
- if (bUseAuthIcon)
+ if (Options.bUseAuthIcon)
if (db_get_b(hContact, proto, "Auth", 0) || type == 3)
- return icon_auth;
+ return ICON_AUTH;
- if (bUseGrantIcon)
+ if (Options.bUseGrantIcon)
if (db_get_b(hContact, proto, "Grant", 0) || type == 4)
- return icon_grant;
+ return ICON_GRANT;
- return icon_none;
+ return ICON_NONE;
}
int onExtraImageApplying(WPARAM hContact, LPARAM lParam)
{
if (hContact == NULL)
return 0;
-
- int usedIcon = getIconToUse((MCONTACT)hContact, lParam);
-
- const char *icon;
- switch (usedIcon) {
- case icon_both: icon = "authgrant_icon"; break;
- case icon_grant: icon = "grant_icon"; break;
- case icon_auth: icon = "auth_icon"; break;
- default: icon = NULL; break;
- }
- ExtraIcon_SetIconByName(hExtraIcon, (MCONTACT)hContact, icon);
+ int iIcon = getIconToUse((MCONTACT)hContact, lParam);
+ ExtraIcon_SetIcon(hExtraIcon, (MCONTACT)hContact, iIcon == -1 ? NULL : iconList[iIcon].hIcolib);
return 0;
}
int onContactSettingChanged(WPARAM hContact, LPARAM lParam)
{
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
- char *proto = GetContactProto((MCONTACT)hContact);
+ const char *proto = GetContactProto((MCONTACT)hContact);
if (!proto) return 0;
if (!strcmp(cws->szModule, proto))
@@ -122,24 +118,26 @@ int onContactSettingChanged(WPARAM hContact, LPARAM lParam)
int onDBContactAdded(WPARAM hContact, LPARAM)
{
- // A new contact added, mark it as recent
db_set_b((MCONTACT)hContact, MODULENAME, "ShowIcons", 1);
onExtraImageApplying(hContact, 0);
-
return 0;
}
INT_PTR onAuthMenuSelected(WPARAM hContact, LPARAM)
{
- byte enabled = db_get_b((MCONTACT)hContact, "AuthState", "ShowIcons", 1);
- db_set_b((MCONTACT)hContact, MODULENAME, "ShowIcons", !enabled);
-
+ db_set_b((MCONTACT)hContact, MODULENAME, "ShowIcons", 1 - db_get_b((MCONTACT)hContact, "AuthState", "ShowIcons", 1));
onExtraImageApplying(hContact, 0);
return 0;
}
int onPrebuildContactMenu(WPARAM hContact, LPARAM)
{
+ if (!Options.bContactMenuItem)
+ {
+ Menu_ShowItem(hUserMenu, false);
+ return 0;
+ }
+
char *proto = GetContactProto((MCONTACT)hContact);
if (!proto)
return 0;
@@ -153,65 +151,45 @@ int onPrebuildContactMenu(WPARAM hContact, LPARAM)
return 0;
}
-static IconItem iconList[] =
-{
- { LPGEN("Request"), "auth_icon", IDI_AUTH },
- { LPGEN("Grant"), "grant_icon", IDI_GRANT },
- { LPGEN("Request & Grant"), "authgrant_icon", IDI_AUTHGRANT }
-};
int onModulesLoaded(WPARAM, LPARAM)
{
+ // extra icons
+ hExtraIcon = ExtraIcon_RegisterIcolib("authstate", LPGEN("Auth state"), iconList[ICON_BOTH].szName);
+
// Set initial value for all contacts
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
onExtraImageApplying((WPARAM)hContact, 1);
- hOptInitialise = HookEvent(ME_OPT_INITIALISE, onOptInitialise);
- if (bContactMenuItem)
- HookEvent(ME_CLIST_PREBUILDCONTACTMENU, onPrebuildContactMenu);
+ HookEvent(ME_OPT_INITIALISE, onOptInitialise);
+ HookEvent(ME_CLIST_PREBUILDCONTACTMENU, onPrebuildContactMenu);
return 0;
}
-static int onShutdown(WPARAM, LPARAM)
-{
- DestroyServiceFunction(hAuthMenuSelected);
- return 0;
-}
-
extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfo);
HookEvent(ME_SYSTEM_MODULESLOADED, onModulesLoaded);
- HookEvent(ME_SYSTEM_PRESHUTDOWN, onShutdown);
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, onContactSettingChanged);
-
- bUseAuthIcon = db_get_b(NULL, MODULENAME, "EnableAuthIcon", 1);
- bUseGrantIcon = db_get_b(NULL, MODULENAME, "EnableGrantIcon", 1);
- bContactMenuItem = db_get_b(NULL, MODULENAME, "MenuItem", 0);
- bIconsForRecentContacts = db_get_b(NULL, MODULENAME, "EnableOnlyForRecent", 0);
-
+ HookEvent(ME_CLIST_EXTRA_IMAGE_APPLY, onExtraImageApplying);
HookEvent(ME_DB_CONTACT_ADDED, onDBContactAdded);
+ CreateServiceFunction("AuthState/MenuItem", onAuthMenuSelected);
- if (bContactMenuItem) {
- hAuthMenuSelected = CreateServiceFunction("AuthState/MenuItem", onAuthMenuSelected);
+ Options.Load();
- CMenuItem mi;
- SET_UID(mi, 0xc5a784ea, 0x8b07, 0x4b95, 0xa2, 0xb2, 0x84, 0x9d, 0x87, 0x43, 0x7e, 0xda);
- mi.position = -1999901005;
- mi.flags = CMIF_TCHAR;
- mi.name.t = LPGENT("Enable AuthState icons");
- mi.pszService = "AuthState/MenuItem";
- hUserMenu = Menu_AddContactMenuItem(&mi);
- }
+ CMenuItem mi;
+ SET_UID(mi, 0xc5a784ea, 0x8b07, 0x4b95, 0xa2, 0xb2, 0x84, 0x9d, 0x87, 0x43, 0x7e, 0xda);
+ mi.position = -1999901005;
+ mi.flags = CMIF_TCHAR;
+ mi.name.t = LPGENT("Enable AuthState icons");
+ mi.pszService = "AuthState/MenuItem";
+ hUserMenu = Menu_AddContactMenuItem(&mi);
// IcoLib support
Icon_Register(g_hInst, LPGEN("Auth state"), iconList, _countof(iconList));
- // extra icons
- hExtraIcon = ExtraIcon_RegisterIcolib("authstate", LPGEN("Auth state"), "authgrant_icon");
-
return 0;
}