diff options
author | George Hazan <george.hazan@gmail.com> | 2013-03-26 20:54:17 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-03-26 20:54:17 +0000 |
commit | 315ffb3628684434969b1f740860036a280dddfc (patch) | |
tree | 06519021523088cc7db59b1e0f20a52cfdddbb51 | |
parent | 474dc76177b2f518f24a0800d62df97171da7c9a (diff) |
Google account autodetect
git-svn-id: http://svn.miranda-ng.org/main/trunk@4208 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/GTalkExt/src/db.h | 2 | ||||
-rw-r--r-- | protocols/GTalkExt/src/handlers.cpp | 35 | ||||
-rw-r--r-- | protocols/GTalkExt/src/menu.cpp | 27 | ||||
-rw-r--r-- | protocols/GTalkExt/src/options.cpp | 10 |
4 files changed, 51 insertions, 23 deletions
diff --git a/protocols/GTalkExt/src/db.h b/protocols/GTalkExt/src/db.h index cb8c3f3f4c..2a688dcad0 100644 --- a/protocols/GTalkExt/src/db.h +++ b/protocols/GTalkExt/src/db.h @@ -27,3 +27,5 @@ static const LPSTR LAST_THREAD_ID_FROM_JID = SHORT_PLUGIN_NAME ".LastThreadIdFro LPTSTR ReadJidSetting(LPCSTR name, LPCTSTR jid);
void WriteJidSetting(LPCSTR name, LPCTSTR jid, LPCTSTR setting);
+
+IJabberInterface* IsGoogleAccount(LPCSTR szModuleName);
diff --git a/protocols/GTalkExt/src/handlers.cpp b/protocols/GTalkExt/src/handlers.cpp index 83e4c036ad..157c890205 100644 --- a/protocols/GTalkExt/src/handlers.cpp +++ b/protocols/GTalkExt/src/handlers.cpp @@ -403,12 +403,31 @@ BOOL SendHandler(IJabberInterface *ji, HXML node, void *pUserData) }
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+IJabberInterface* IsGoogleAccount(LPCSTR szModuleName)
+{
+ IJabberInterface *japi = getJabberApi(szModuleName);
+ if (!japi) return NULL;
+
+ DBVARIANT dbv;
+ if ( DBGetContactSettingString(NULL, szModuleName, "ManualHost", &dbv))
+ return NULL;
+
+ __try {
+ return (!strcmp(dbv.pszVal, "talk.google.com")) ? japi : NULL;
+ }
+ __finally {
+ db_free(&dbv);
+ }
+}
+
int AccListChanged(WPARAM wParam, LPARAM lParam)
{
- if (PRAC_ADDED == wParam) {
- IJabberInterface *japi = getJabberApi(((PROTOACCOUNT*)lParam)->szModuleName);
- if (japi)
- japi->Net()->AddSendHandler(SendHandler);
+ if (wParam == PRAC_ADDED) {
+ IJabberInterface *ji = IsGoogleAccount(((PROTOACCOUNT*)lParam)->szModuleName);
+ if (ji)
+ ji->Net()->AddSendHandler(SendHandler);
}
return 0;
}
@@ -418,10 +437,10 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) int count;
PROTOACCOUNT **protos;
ProtoEnumAccounts(&count, &protos);
- for (int i = 0; i < count; i++) {
- IJabberInterface *japi = getJabberApi(protos[i]->szModuleName);
- if (japi)
- japi->Net()->AddSendHandler(SendHandler);
+ for (int i=0; i < count; i++) {
+ IJabberInterface *ji = IsGoogleAccount(protos[i]->szModuleName);
+ if (ji)
+ ji->Net()->AddSendHandler(SendHandler);
}
HookEvent(ME_JABBER_MENUINIT, InitMenus);
diff --git a/protocols/GTalkExt/src/menu.cpp b/protocols/GTalkExt/src/menu.cpp index ea241e6f55..31aa364710 100644 --- a/protocols/GTalkExt/src/menu.cpp +++ b/protocols/GTalkExt/src/menu.cpp @@ -20,6 +20,7 @@ //***************************************************************************************
#include "stdafx.h"
+#include "db.h"
#include "resources.h"
#include "options.h"
#include "inbox.h"
@@ -37,18 +38,20 @@ INT_PTR OpenMailboxMenuHandler(WPARAM wParam, LPARAM lParam, LPARAM param) int InitMenus(WPARAM wParam, LPARAM lParam)
{
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);
- char szServiceName[100];
- mir_snprintf(szServiceName, SIZEOF(szServiceName), "%s/%s", ji->Sys()->GetModuleName(), MS_GTALKEXT_OPENMAILBOX);
- CreateServiceFunctionParam(szServiceName, OpenMailboxMenuHandler, (LPARAM)ji->Sys()->GetModuleName());
-
- CLISTMENUITEM cmi = { sizeof(cmi) };
- cmi.flags = CMIF_CHILDPOPUP;
- cmi.hParentMenu = HGENMENU(wParam);
- cmi.hIcon = g_hPopupIcon;
- cmi.position = 200101;
- cmi.pszName = LPGEN("Open mailbox");
- cmi.pszService = szServiceName;
- Menu_AddProtoMenuItem(&cmi);
+ CLISTMENUITEM cmi = { sizeof(cmi) };
+ cmi.flags = CMIF_CHILDPOPUP;
+ cmi.hParentMenu = HGENMENU(wParam);
+ cmi.hIcon = g_hPopupIcon;
+ cmi.position = 200101;
+ cmi.pszName = LPGEN("Open mailbox");
+ cmi.pszService = szServiceName;
+ Menu_AddProtoMenuItem(&cmi);
+ }
return 0;
}
diff --git a/protocols/GTalkExt/src/options.cpp b/protocols/GTalkExt/src/options.cpp index 7df8c2c7d3..37191383f8 100644 --- a/protocols/GTalkExt/src/options.cpp +++ b/protocols/GTalkExt/src/options.cpp @@ -20,6 +20,7 @@ //***************************************************************************************
#include "stdafx.h"
+#include "db.h"
#include "options.h"
static const LPTSTR ACCOUNT_PROP_NAME = _T("{BF447EBA-27AE-4DB7-893C-FC42A3F74D75}");
@@ -258,11 +259,14 @@ int OptionsInitialization(WPARAM wParam, LPARAM lParam) int count;
PROTOACCOUNT **accs;
CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&count, (LPARAM)&accs);
- for (int i = 0; i < count; i++)
- if ( getJabberApi(accs[i]->szModuleName))
+ for (int i = 0; i < count; i++) {
+ IJabberInterface *ji = IsGoogleAccount(accs[i]->szModuleName);
+ if (ji)
AddAccPage(accs[i]->tszAccountName, accs[i]->szModuleName, wParam);
+ }
- if (ServiceExists(MS_POPUP_ADDPOPUPT)) AddPopupsPage(wParam);
+ if (ServiceExists(MS_POPUP_ADDPOPUPT))
+ AddPopupsPage(wParam);
return FALSE;
}
|