diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-28 16:34:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-28 16:34:30 +0300 |
commit | 81ce57622c3166830b23eae534dacc6b008c659d (patch) | |
tree | 6d6ac74667f733a20b94fa27cc01c2f45688c533 /protocols/JabberG/src | |
parent | c2bb7727483b9b5620e8cc0ce6adae35ee78d0a4 (diff) |
common protocol instance management code went into template
Diffstat (limited to 'protocols/JabberG/src')
-rwxr-xr-x | protocols/JabberG/src/jabber.cpp | 35 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_menu.cpp | 92 | ||||
-rwxr-xr-x | protocols/JabberG/src/jabber_proto.h | 7 |
3 files changed, 47 insertions, 87 deletions
diff --git a/protocols/JabberG/src/jabber.cpp b/protocols/JabberG/src/jabber.cpp index 06523ae7eb..b5860eb292 100755 --- a/protocols/JabberG/src/jabber.cpp +++ b/protocols/JabberG/src/jabber.cpp @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. HINSTANCE hInst;
HMODULE hMsftedit;
+CMPlugin g_plugin;
int hLangpack;
unsigned int g_nTempFileId;
CHAT_MANAGER *pci;
@@ -71,14 +72,6 @@ void JabberUserInfoUninit(void); bool bSecureIM, bMirOTR, bNewGPG, bPlatform;
/////////////////////////////////////////////////////////////////////////////
-// Protocol instances
-static int sttCompareProtocols(const CJabberProto *p1, const CJabberProto *p2)
-{
- return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName);
-}
-
-LIST<CJabberProto> g_Instances(1, sttCompareProtocols);
-/////////////////////////////////////////////////////////////////////////////
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD, LPVOID)
{
@@ -227,29 +220,3 @@ extern "C" int __declspec(dllexport) Unload(void) g_MenuUninit();
return 0;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static PROTO_INTERFACE* jabberProtoInit(const char* pszProtoName, const wchar_t *tszUserName)
-{
- CJabberProto *ppro = new CJabberProto(pszProtoName, tszUserName);
- g_Instances.insert(ppro);
- return ppro;
-}
-
-static int jabberProtoUninit(PROTO_INTERFACE *ppro)
-{
- g_Instances.remove((CJabberProto*)ppro);
- delete (CJabberProto*)ppro;
- return 0;
-}
-
-struct CMPlugin : public CMPluginBase
-{
- CMPlugin() :
- CMPluginBase(GLOBAL_SETTING_MODULE)
- {
- RegisterProtocol(PROTOTYPE_PROTOCOL, jabberProtoInit, jabberProtoUninit);
- }
-}
- g_plugin;
diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp index 63f4cd2899..585f7c2b58 100644 --- a/protocols/JabberG/src/jabber_menu.cpp +++ b/protocols/JabberG/src/jabber_menu.cpp @@ -72,74 +72,61 @@ static INT_PTR JabberMenuChooseService(WPARAM wParam, LPARAM lParam) return 0;
}
-static CJabberProto* JabberGetInstanceByHContact(MCONTACT hContact)
+static INT_PTR JabberMenuConvertChatContact(WPARAM hContact, LPARAM lParam)
{
- char *szProto = GetContactProto(hContact);
- if (szProto == nullptr)
- return nullptr;
-
- for (auto &it : g_Instances)
- if (!mir_strcmp(szProto, it->m_szModuleName))
- return it;
-
- return nullptr;
-}
-
-static INT_PTR JabberMenuConvertChatContact(WPARAM wParam, LPARAM lParam)
-{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuConvertChatContact(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuConvertChatContact(hContact, lParam) : 0;
}
-static INT_PTR JabberMenuRosterAdd(WPARAM wParam, LPARAM lParam)
+static INT_PTR JabberMenuRosterAdd(WPARAM hContact, LPARAM lParam)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuRosterAdd(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuRosterAdd(hContact, lParam) : 0;
}
-static INT_PTR JabberMenuBookmarkAdd(WPARAM wParam, LPARAM lParam)
+static INT_PTR JabberMenuBookmarkAdd(WPARAM hContact, LPARAM lParam)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuBookmarkAdd(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuBookmarkAdd(hContact, lParam) : 0;
}
-static INT_PTR JabberMenuTransportLogin(WPARAM wParam, LPARAM lParam)
+static INT_PTR JabberMenuTransportLogin(WPARAM hContact, LPARAM lParam)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuTransportLogin(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuTransportLogin(hContact, lParam) : 0;
}
-static INT_PTR JabberMenuTransportResolve(WPARAM wParam, LPARAM lParam)
+static INT_PTR JabberMenuTransportResolve(WPARAM hContact, LPARAM lParam)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuTransportResolve(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuTransportResolve(hContact, lParam) : 0;
}
-static INT_PTR JabberContactMenuRunCommands(WPARAM wParam, LPARAM lParam)
+static INT_PTR JabberContactMenuRunCommands(WPARAM hContact, LPARAM lParam)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->ContactMenuRunCommands(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->ContactMenuRunCommands(hContact, lParam) : 0;
}
-static INT_PTR JabberMenuSendNote(WPARAM wParam, LPARAM lParam)
+static INT_PTR JabberMenuSendNote(WPARAM hContact, LPARAM lParam)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuSendNote(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuSendNote(hContact, lParam) : 0;
}
-static INT_PTR JabberMenuHandleResource(WPARAM wParam, LPARAM lParam, LPARAM lRes)
+static INT_PTR JabberMenuHandleResource(WPARAM hContact, LPARAM lParam, LPARAM lRes)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuHandleResource(wParam, lParam, lRes) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuHandleResource(hContact, lParam, lRes) : 0;
}
-static INT_PTR JabberMenuHandleDirectPresence(WPARAM wParam, LPARAM lParam, LPARAM lRes)
+static INT_PTR JabberMenuHandleDirectPresence(WPARAM hContact, LPARAM lParam, LPARAM lRes)
{
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnMenuHandleDirectPresence(wParam, lParam, lRes) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnMenuHandleDirectPresence(hContact, lParam, lRes) : 0;
}
-static int JabberPrebuildContactMenu(WPARAM wParam, LPARAM lParam)
+static int JabberPrebuildContactMenu(WPARAM hContact, LPARAM lParam)
{
Menu_ShowItem(g_hMenuCommands, FALSE);
Menu_ShowItem(g_hMenuSendNote, FALSE);
@@ -151,8 +138,8 @@ static int JabberPrebuildContactMenu(WPARAM wParam, LPARAM lParam) Menu_ShowItem(g_hMenuResourcesRoot, FALSE);
Menu_ShowItem(g_hMenuDirectPresence[0], FALSE);
- CJabberProto *ppro = JabberGetInstanceByHContact(wParam);
- return(ppro) ? ppro->OnPrebuildContactMenu(wParam, lParam) : 0;
+ CJabberProto *ppro = CMPlugin::getInstance(hContact);
+ return(ppro) ? ppro->OnPrebuildContactMenu(hContact, lParam) : 0;
}
void g_MenuInit(void)
@@ -790,7 +777,7 @@ static INT_PTR g_ToolbarHandleServiceDiscovery(WPARAM w, LPARAM l) int g_OnToolbarInit(WPARAM, LPARAM)
{
- if (g_Instances.getCount() == 0)
+ if (CMPlugin::g_arInstances.getCount() == 0)
return 0;
TTBButton ttb = {};
@@ -1043,25 +1030,26 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleDirectPresence(WPARAM hContact, LPARAM CJabberProto* JabberChooseInstance(bool bIsLink)
{
- if (g_Instances.getCount() == 0)
+ if (CMPlugin::g_arInstances.getCount() == 0)
return nullptr;
- if (g_Instances.getCount() == 1) {
- if (g_Instances[0]->m_iStatus != ID_STATUS_OFFLINE && g_Instances[0]->m_iStatus != ID_STATUS_CONNECTING)
- return g_Instances[0];
+ if (CMPlugin::g_arInstances.getCount() == 1) {
+ if (CMPlugin::g_arInstances[0].m_iStatus != ID_STATUS_OFFLINE && CMPlugin::g_arInstances[0].m_iStatus != ID_STATUS_CONNECTING)
+ return &CMPlugin::g_arInstances[0];
+
return nullptr;
}
if (bIsLink)
- for (auto &it : g_Instances)
+ for (auto &it : CMPlugin::g_arInstances)
if (it->m_bProcessXMPPLinks)
return it;
int nItems = 0, lastItemId = 0;
- for (auto &ppro : g_Instances) {
+ for (auto &ppro : CMPlugin::g_arInstances) {
if (ppro->m_iStatus != ID_STATUS_OFFLINE && ppro->m_iStatus != ID_STATUS_CONNECTING) {
++nItems;
- lastItemId = g_Instances.indexOf(&ppro) + 1;
+ lastItemId = CMPlugin::g_arInstances.indexOf(&ppro) + 1;
Menu_ModifyItem(ppro->m_hChooseMenuItem, nullptr, Skin_LoadProtoIcon(ppro->m_szModuleName, ppro->m_iStatus));
}
else Menu_ShowItem(ppro->m_hChooseMenuItem, false);
@@ -1085,5 +1073,5 @@ CJabberProto* JabberChooseInstance(bool bIsLink) return nullptr;
}
- return lastItemId ? g_Instances[lastItemId - 1] : nullptr;
+ return lastItemId ? &CMPlugin::g_arInstances[lastItemId - 1] : nullptr;
}
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 729ca52efe..15ce0aeb26 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -933,6 +933,11 @@ private: JabberFeatCapPairDynamic *FindFeature(const wchar_t *szFeature);
};
-extern LIST<CJabberProto> g_Instances;
+struct CMPlugin : public ACCPROTOPLUGIN<CJabberProto>
+{
+ CMPlugin() :
+ ACCPROTOPLUGIN<CJabberProto>("JABBER")
+ {}
+};
#endif
|