From d15bd517fb0eb4bbdb1b118b44398b00bc8f6d6a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 9 Feb 2018 16:13:50 +0300 Subject: all duplicate "Request auth", "Grant auth" & "Revoke auth" menu items eliminated --- src/mir_app/src/menu_clist.cpp | 2 ++ src/mir_app/src/menu_utils.cpp | 8 ++--- src/mir_app/src/proto_opts.cpp | 4 +-- src/mir_app/src/proto_utils.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 6 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/menu_clist.cpp b/src/mir_app/src/menu_clist.cpp index b4aa1f4d3a..70fbf68454 100644 --- a/src/mir_app/src/menu_clist.cpp +++ b/src/mir_app/src/menu_clist.cpp @@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void InitGroupMenus(void); void InitFramesMenus(void); +void InitProtoMenus(void); void InitTrayMenus(void); #define MS_CLIST_HKSTATUS "Clist/HK/SetStatus" @@ -1134,6 +1135,7 @@ void InitCustomMenus(void) // other menus InitGroupMenus(); InitFramesMenus(); + InitProtoMenus(); InitTrayMenus(); // initialize hotkeys diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp index 74f502ead0..6fd467fdfd 100644 --- a/src/mir_app/src/menu_utils.cpp +++ b/src/mir_app/src/menu_utils.cpp @@ -223,9 +223,9 @@ MIR_APP_DLL(HGENMENU) Menu_GetProtocolRoot(PROTO_INTERFACE *pThis) return nullptr; if (db_get_b(0, "CList", "MoveProtoMenus", TRUE)) { - if (pThis->m_hMainMenuItem != nullptr) { - Menu_RemoveItem(pThis->m_hMainMenuItem); - pThis->m_hMainMenuItem = nullptr; + if (pThis->m_hmiMainMenu != nullptr) { + Menu_RemoveItem(pThis->m_hmiMainMenu); + pThis->m_hmiMainMenu = nullptr; } return cli.pfnGetProtocolMenu(pThis->m_szModuleName); } @@ -255,7 +255,7 @@ MIR_APP_DLL(HGENMENU) Menu_GetProtocolRoot(PROTO_INTERFACE *pThis) } hex2bin(szUid, &mi.uid, sizeof(mi.uid)); - return pThis->m_hMainMenuItem = Menu_AddMainMenuItem(&mi); + return pThis->m_hmiMainMenu = Menu_AddMainMenuItem(&mi); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp index ca48ba145e..d7090a080f 100644 --- a/src/mir_app/src/proto_opts.cpp +++ b/src/mir_app/src/proto_opts.cpp @@ -1014,8 +1014,8 @@ static int OnAccListChanged(WPARAM eventCode, LPARAM lParam) replaceStrW(pa->ppro->m_tszUserName, pa->tszAccountName); pa->ppro->OnEvent(EV_PROTO_ONRENAME, 0, lParam); - if (pa->ppro->m_hMainMenuItem) - Menu_ModifyItem(pa->ppro->m_hMainMenuItem, pa->tszAccountName); + if (pa->ppro->m_hmiMainMenu) + Menu_ModifyItem(pa->ppro->m_hmiMainMenu, pa->tszAccountName); } } diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 199e730fd8..41c97b9a79 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -76,6 +76,74 @@ void PROTO_INTERFACE::setAllContactStatuses(int iStatus, bool bSkipChats) } } +///////////////////////////////////////////////////////////////////////////////////////// +// protocol menus + +static HGENMENU hReqAuth = nullptr, hGrantAuth = nullptr, hRevokeAuth = nullptr; + +static INT_PTR __cdecl stubRequestAuth(WPARAM hContact, LPARAM) +{ + const char *szProto = GetContactProto(hContact); + if (szProto) + ProtoCallService(szProto, PS_MENU_REQAUTH, hContact, 0); + return 0; +} + +static INT_PTR __cdecl stubGrantAuth(WPARAM hContact, LPARAM) +{ + const char *szProto = GetContactProto(hContact); + if (szProto) + ProtoCallService(szProto, PS_MENU_GRANTAUTH, hContact, 0); + return 0; +} + +static INT_PTR __cdecl stubRevokeAuth(WPARAM hContact, LPARAM) +{ + const char *szProto = GetContactProto(hContact); + if (szProto) + ProtoCallService(szProto, PS_MENU_REVOKEAUTH, hContact, 0); + return 0; +} + +static int __cdecl ProtoPrebuildContactMenu(WPARAM, LPARAM) +{ + Menu_ShowItem(hReqAuth, false); + Menu_ShowItem(hGrantAuth, false); + Menu_ShowItem(hRevokeAuth, false); + return 0; +} + +void InitProtoMenus(void) +{ + // "Request authorization" + CMenuItem mi; + SET_UID(mi, 0x36375a1f, 0xc142, 0x4d6e, 0xa6, 0x57, 0xe4, 0x76, 0x5d, 0xbc, 0x59, 0x8e); + mi.pszService = "Proto/Menu/ReqAuth"; + mi.name.a = LPGEN("Request authorization"); + mi.position = -2000001002; + mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REQUEST); + hReqAuth = Menu_AddContactMenuItem(&mi); + CreateServiceFunction(mi.pszService, stubRequestAuth); + + // "Grant authorization" + SET_UID(mi, 0x4c90452a, 0x869a, 0x4a81, 0xaf, 0xa8, 0x28, 0x34, 0xaf, 0x2b, 0x6b, 0x30); + mi.pszService = "Proto/Menu/GrantAuth"; + mi.name.a = LPGEN("Grant authorization"); + mi.position = -2000001001; + mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_GRANT); + hGrantAuth = Menu_AddContactMenuItem(&mi); + + // "Revoke authorization" + SET_UID(mi, 0x619efdcb, 0x99c0, 0x44a8, 0xbf, 0x28, 0xc3, 0xe0, 0x2f, 0xb3, 0x7e, 0x77); + mi.pszService = "Proto/Menu/RevokeAuth"; + mi.name.a = LPGEN("Revoke authorization"); + mi.position = -2000001000; + mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REVOKE); + hRevokeAuth = Menu_AddContactMenuItem(&mi); + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, ProtoPrebuildContactMenu); +} + ///////////////////////////////////////////////////////////////////////////////////////// // protocol constructor & destructor @@ -87,6 +155,10 @@ PROTO_INTERFACE::PROTO_INTERFACE(const char *pszModuleName, const wchar_t *ptszU m_hProtoIcon = IcoLib_IsManaged(Skin_LoadProtoIcon(pszModuleName, ID_STATUS_ONLINE)); m_tszUserName = mir_wstrdup(ptszUserName); db_set_resident(m_szModuleName, "Status"); + + m_hmiReqAuth = hReqAuth; + m_hmiGrantAuth = hGrantAuth; + m_hmiRevokeAuth = hRevokeAuth; } PROTO_INTERFACE::~PROTO_INTERFACE() -- cgit v1.2.3