summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-28 16:34:30 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-28 16:34:30 +0300
commit81ce57622c3166830b23eae534dacc6b008c659d (patch)
tree6d6ac74667f733a20b94fa27cc01c2f45688c533 /protocols/FacebookRM
parentc2bb7727483b9b5620e8cc0ce6adae35ee78d0a4 (diff)
common protocol instance management code went into template
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/src/main.cpp35
-rw-r--r--protocols/FacebookRM/src/proto.h7
-rw-r--r--protocols/FacebookRM/src/theme.cpp19
3 files changed, 10 insertions, 51 deletions
diff --git a/protocols/FacebookRM/src/main.cpp b/protocols/FacebookRM/src/main.cpp
index 28bc66d172..2e7f7849dd 100644
--- a/protocols/FacebookRM/src/main.cpp
+++ b/protocols/FacebookRM/src/main.cpp
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// TODO: Make following as "globals" structure?
+CMPlugin g_plugin;
CLIST_INTERFACE *pcli;
int hLangpack;
@@ -44,15 +45,6 @@ PLUGININFOEX pluginInfo = {
{ 0x8432b009, 0xff32, 0x4727, { 0xaa, 0xe6, 0xa9, 0x3, 0x50, 0x38, 0xfd, 0x58 } }
};
-/////////////////////////////////////////////////////////////////////////////
-// Protocol instances
-static int compare_protos(const FacebookProto *p1, const FacebookProto *p2)
-{
- return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName);
-}
-
-OBJLIST<FacebookProto> g_Instances(1, compare_protos);
-
DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
{
g_hInstance = hInstance;
@@ -73,19 +65,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOC
/////////////////////////////////////////////////////////////////////////////////////////
// Load
-static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username)
-{
- FacebookProto *proto = new FacebookProto(proto_name, username);
- g_Instances.insert(proto);
- return proto;
-}
-
-static int protoUninit(PROTO_INTERFACE* proto)
-{
- g_Instances.remove((FacebookProto*)proto);
- return EXIT_SUCCESS;
-}
-
extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfo);
@@ -120,15 +99,3 @@ extern "C" int __declspec(dllexport) Unload(void)
{
return 0;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-struct CMPlugin : public CMPluginBase
-{
- CMPlugin() :
- CMPluginBase(FACEBOOK_NAME)
- {
- RegisterProtocol(PROTOTYPE_PROTOCOL, protoInit, protoUninit);
- }
-}
- g_plugin;
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index 98262699ff..8f4b547e61 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -286,3 +286,10 @@ public:
HWND NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url = nullptr, std::string *notification_id = nullptr, const char *icon = nullptr);
void ShowNotifications();
};
+
+struct CMPlugin : public ACCPROTOPLUGIN<FacebookProto>
+{
+ CMPlugin() :
+ ACCPROTOPLUGIN<FacebookProto>(FACEBOOK_NAME)
+ {}
+};
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp
index 91d7931076..ce5fb25df3 100644
--- a/protocols/FacebookRM/src/theme.cpp
+++ b/protocols/FacebookRM/src/theme.cpp
@@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-extern OBJLIST<FacebookProto> g_Instances;
-
// Contact menu items
HGENMENU g_hContactMenuVisitProfile;
HGENMENU g_hContactMenuVisitFriendship;
@@ -69,23 +67,10 @@ HANDLE GetIconHandle(const char* name)
}
// Helper functions
-static FacebookProto * GetInstanceByHContact(MCONTACT hContact)
-{
- char *proto = GetContactProto(hContact);
- if (!proto)
- return nullptr;
-
- for (auto &it : g_Instances)
- if (!mir_strcmp(proto, it->m_szModuleName))
- return it;
-
- return nullptr;
-}
-
template<INT_PTR(__cdecl FacebookProto::*Fcn)(WPARAM, LPARAM)>
INT_PTR GlobalService(WPARAM wParam, LPARAM lParam)
{
- FacebookProto *proto = GetInstanceByHContact(MCONTACT(wParam));
+ FacebookProto *proto = CMPlugin::getInstance(MCONTACT(wParam));
return proto ? (proto->*Fcn)(wParam, lParam) : 0;
}
@@ -102,7 +87,7 @@ static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
Menu_ShowItem(g_hContactMenuLoadHistory, false);
// Process them in correct account
- FacebookProto *proto = GetInstanceByHContact(MCONTACT(wParam));
+ FacebookProto *proto = CMPlugin::getInstance(MCONTACT(wParam));
return proto ? proto->OnPrebuildContactMenu(wParam, lParam) : 0;
}