From 21e7268a503be780b35e367564d711e79a61dffc Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 28 Feb 2015 06:48:33 +0000 Subject: Tox: - added support of tox1 dns resolving - added request/grant items in contact menu - added copy id item in statum menu - code reordering - fixed minor bugs git-svn-id: http://svn.miranda-ng.org/main/trunk@12281 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_menus.cpp | 96 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 11 deletions(-) (limited to 'protocols/Tox/src/tox_menus.cpp') diff --git a/protocols/Tox/src/tox_menus.cpp b/protocols/Tox/src/tox_menus.cpp index 2afa6fd218..60daad3090 100644 --- a/protocols/Tox/src/tox_menus.cpp +++ b/protocols/Tox/src/tox_menus.cpp @@ -1,5 +1,72 @@ #include "common.h" +HGENMENU CToxProto::ContactMenuItems[CMI_MAX]; + +int CToxProto::OnPrebuildContactMenu(MCONTACT hContact, LPARAM) +{ + if (!hContact) + return 0; + + if (!this->IsOnline()) + return 0; + + if (this->isChatRoom(hContact)) + return 0; + + bool isCtrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0; + bool isAuthNeed = getByte(hContact, "Auth", 0) > 0; + bool isGrantNeed = getByte(hContact, "Grant", 0) > 0; + //bool isOffline = GetContactStatus(hContact) == ID_STATUS_OFFLINE; + //bool isLongOffline = ((time(NULL) - getDword(hContact, "LastEventDateTS", 0)) / (1000 * 60 * 60 * 24 * 7)) > 0; + //bool hasDnsID = mir_strlen(ptrA(getStringA(hContact, TOX_SETTINGS_DNS))) > 0; + + Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], isCtrlPressed || isAuthNeed); + Menu_ShowItem(ContactMenuItems[CMI_AUTH_GRANT], isCtrlPressed || isGrantNeed); + + return 0; +} + +int CToxProto::PrebuildContactMenu(MCONTACT hContact, LPARAM lParam) +{ + for (int i = 0; i < SIZEOF(ContactMenuItems); i++) + { + Menu_ShowItem(ContactMenuItems[i], false); + } + CToxProto *proto = CToxProto::GetContactAccount(hContact); + return proto ? proto->OnPrebuildContactMenu(hContact, lParam) : 0; +} + +void CToxProto::InitMenus() +{ + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, &CToxProto::PrebuildContactMenu); + + //hChooserMenu = MO_CreateMenuObject("SkypeAccountChooser", LPGEN("Skype menu chooser"), 0, "Skype/MenuChoose"); + + CLISTMENUITEM mi = { sizeof(CLISTMENUITEM) }; + mi.flags = CMIF_TCHAR; + + // Request authorization + mi.pszService = MODULE"/RequestAuth"; + mi.ptszName = LPGENT("Request authorization"); + mi.position = CMI_POSITION + CMI_AUTH_REQUEST; + mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REQUEST); + ContactMenuItems[CMI_AUTH_REQUEST] = Menu_AddContactMenuItem(&mi); + CreateServiceFunction(mi.pszService, GlobalService<&CToxProto::OnRequestAuth>); + + // Grant authorization + mi.pszService = MODULE"/GrantAuth"; + mi.ptszName = LPGENT("Grant authorization"); + mi.position = CMI_POSITION + CMI_AUTH_GRANT; + mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_GRANT); + ContactMenuItems[CMI_AUTH_GRANT] = Menu_AddContactMenuItem(&mi); + CreateServiceFunction(mi.pszService, GlobalService<&CToxProto::OnGrantAuth>); +} + +void CToxProto::UninitMenus() +{ +} + + int CToxProto::OnInitStatusMenu() { char text[MAX_PATH]; @@ -16,26 +83,33 @@ int CToxProto::OnInitStatusMenu() mi.position = -1999901006; mi.hParentMenu = HGENMENU_ROOT; mi.flags = CMIF_ROOTPOPUP | CMIF_TCHAR | CMIF_KEEPUNTRANSLATED; - //mi.icolibItem = CToxProto::GetSkinIconHandle("main"); + mi.icolibItem = GetSkinIconHandle("main"); hStatusMunuRoot = /*m_hMenuRoot = */Menu_AddProtoMenuItem(&mi); } - else + /*else { - //if (m_hMenuRoot) - // CallService(MO_REMOVEMENUITEM, (WPARAM)m_hMenuRoot, 0); - //m_hMenuRoot = NULL; - } + if (m_hMenuRoot) + CallService(MO_REMOVEMENUITEM, (WPARAM)m_hMenuRoot, 0); + m_hMenuRoot = NULL; + }*/ mi.hParentMenu = hStatusMunuRoot; mi.flags = CMIF_CHILDPOPUP | CMIF_TCHAR; - // Create chat room command - mir_strcpy(tDest, "/CreateChatRoom"); + // Create copy tox id command + mir_strcpy(tDest, "/CopyToxID"); + CreateProtoService(tDest, &CToxProto::OnCopyToxID); + mi.ptszName = LPGENT("Copy Tox ID"); + mi.position = SMI_POSITION + SMI_TOXID_COPY; + Menu_AddProtoMenuItem(&mi); + + // Create group chat command + /*mir_strcpy(tDest, "/CreateChatRoom"); CreateProtoService(tDest, &CToxProto::OnCreateChatRoom); mi.ptszName = LPGENT("Create group chat"); - mi.position = 200000;// +SMI_CHAT_CREATE; - //mi.icolibItem = CToxProto::GetSkinIconHandle("conference"); - Menu_AddProtoMenuItem(&mi); + mi.position = SMI_POSITION + SMI_GROUPCHAT_CREATE; + mi.icolibItem = GetSkinIconHandle("conference"); + Menu_AddProtoMenuItem(&mi);*/ return 0; } \ No newline at end of file -- cgit v1.2.3