summaryrefslogtreecommitdiff
path: root/protocols/GTalkExt/src/menu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/GTalkExt/src/menu.cpp')
-rw-r--r--protocols/GTalkExt/src/menu.cpp72
1 files changed, 56 insertions, 16 deletions
diff --git a/protocols/GTalkExt/src/menu.cpp b/protocols/GTalkExt/src/menu.cpp
index 31aa364710..6cbe2f2209 100644
--- a/protocols/GTalkExt/src/menu.cpp
+++ b/protocols/GTalkExt/src/menu.cpp
@@ -26,32 +26,72 @@
#include "inbox.h"
static const LPSTR MS_GTALKEXT_OPENMAILBOX = SHORT_PLUGIN_NAME "/OpenMailbox";
+static const LPTSTR _T(OPEN_MAILBOX_ITEM_CAPTION) = LPGENT("Open mailbox");
extern HICON g_hPopupIcon;
-INT_PTR OpenMailboxMenuHandler(WPARAM wParam, LPARAM lParam, LPARAM param)
+HANDLE hOpenMailboxService = 0;
+HANDLE hOnPrebuildMenu = 0;
+
+HGENMENU hOpenMailboxMenuItem = 0;
+
+INT_PTR OpenMailboxMenuHandler(WPARAM wParam, LPARAM lParam)
+{
+ HANDLE hContact = (HANDLE)wParam;
+ if (db_get_b(hContact, SHORT_PLUGIN_NAME, PSEUDOCONTACT_FLAG, 0))
+ OpenContactInbox(hContact);
+ return 0;
+}
+
+int OnPrebuildMenu(WPARAM wParam, LPARAM lParam)
{
- OpenContactInbox((LPCSTR)param);
+ CLISTMENUITEM cmi = { sizeof(cmi) };
+ cmi.flags = CMIM_FLAGS;
+ if (!db_get_b((HANDLE)wParam, SHORT_PLUGIN_NAME, PSEUDOCONTACT_FLAG, 0))
+ cmi.flags |= CMIF_HIDDEN;
+ Menu_ModifyItem(hOpenMailboxMenuItem, &cmi);
return 0;
}
-int InitMenus(WPARAM wParam, LPARAM lParam)
+BOOL InitMenus(BOOL init)
{
- IJabberInterface *ji = (IJabberInterface*)lParam;
- LPCSTR szModuleName = ji->Sys()->GetModuleName();
- if ( IsGoogleAccount(szModuleName)) {
- char szServiceName[100];
- mir_snprintf(szServiceName, SIZEOF(szServiceName), "%s/%s", szModuleName, MS_GTALKEXT_OPENMAILBOX);
- CreateServiceFunctionParam(szServiceName, OpenMailboxMenuHandler, (LPARAM)szModuleName);
+ if (init) {
+ hOpenMailboxService = (HANDLE)CreateServiceFunction(MS_GTALKEXT_OPENMAILBOX, OpenMailboxMenuHandler);
+ if (!hOpenMailboxService) {
+ InitMenus(FALSE);
+ return FALSE;
+ }
+
+ extern HICON g_hPopupIcon;
CLISTMENUITEM cmi = { sizeof(cmi) };
- cmi.flags = CMIF_CHILDPOPUP;
- cmi.hParentMenu = HGENMENU(wParam);
+ cmi.flags = CMIF_TCHAR;
cmi.hIcon = g_hPopupIcon;
- cmi.position = 200101;
- cmi.pszName = LPGEN("Open mailbox");
- cmi.pszService = szServiceName;
- Menu_AddProtoMenuItem(&cmi);
+ cmi.ptszName = _T(OPEN_MAILBOX_ITEM_CAPTION);
+ cmi.pszService = MS_GTALKEXT_OPENMAILBOX;
+ hOpenMailboxMenuItem = Menu_AddContactMenuItem(&cmi);
+
+ if (!hOpenMailboxMenuItem) {
+ InitMenus(FALSE);
+ return FALSE;
+ }
+
+ hOnPrebuildMenu = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildMenu);
+ if (!hOnPrebuildMenu) {
+ InitMenus(FALSE);
+ return FALSE;
+ }
}
- return 0;
+ else {
+ if (hOnPrebuildMenu) {
+ UnhookEvent(hOnPrebuildMenu);
+ hOnPrebuildMenu = 0;
+ }
+ if (hOpenMailboxService) {
+ DestroyServiceFunction(hOpenMailboxService);
+ hOpenMailboxService = 0;
+ }
+ }
+
+ return TRUE;
}