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/Steam | |
parent | c2bb7727483b9b5620e8cc0ce6adae35ee78d0a4 (diff) |
common protocol instance management code went into template
Diffstat (limited to 'protocols/Steam')
-rw-r--r-- | protocols/Steam/src/main.cpp | 13 | ||||
-rw-r--r-- | protocols/Steam/src/steam_accounts.cpp | 35 | ||||
-rw-r--r-- | protocols/Steam/src/steam_menus.cpp | 15 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 17 |
4 files changed, 15 insertions, 65 deletions
diff --git a/protocols/Steam/src/main.cpp b/protocols/Steam/src/main.cpp index 57632115d9..7464db16e2 100644 --- a/protocols/Steam/src/main.cpp +++ b/protocols/Steam/src/main.cpp @@ -2,6 +2,7 @@ int hLangpack;
HINSTANCE g_hInstance;
+CMPlugin g_plugin;
HANDLE hExtraXStatus;
@@ -52,15 +53,3 @@ extern "C" int __declspec(dllexport) Unload(void) {
return 0;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-struct CMPlugin : public CMPluginBase
-{
- CMPlugin() :
- CMPluginBase("STEAM")
- {
- RegisterProtocol(PROTOTYPE_PROTOCOL, (pfnInitProto)CSteamProto::InitAccount, (pfnUninitProto)CSteamProto::UninitAccount);
- }
-}
- g_plugin;
diff --git a/protocols/Steam/src/steam_accounts.cpp b/protocols/Steam/src/steam_accounts.cpp deleted file mode 100644 index 8fedcc6181..0000000000 --- a/protocols/Steam/src/steam_accounts.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "stdafx.h" - -LIST<CSteamProto> CSteamProto::Accounts(1, CSteamProto::CompareProtos); - -int CSteamProto::CompareProtos(const CSteamProto *p1, const CSteamProto *p2) -{ - return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName); -} - -CSteamProto* CSteamProto::InitAccount(const char* protoName, const wchar_t* userName) -{ - CSteamProto *ppro = new CSteamProto(protoName, userName); - Accounts.insert(ppro); - return ppro; -} - -int CSteamProto::UninitAccount(CSteamProto* ppro) -{ - Accounts.remove(ppro); - delete ppro; - return 0; -} - -CSteamProto* CSteamProto::GetContactAccount(MCONTACT hContact) -{ - char *proto = GetContactProto(hContact); - if (proto == nullptr) - return nullptr; - - for (auto &it : Accounts) - if (!mir_strcmp(proto, it->m_szModuleName)) - return it; - - return nullptr; -}
\ No newline at end of file diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp index 30b6550293..40f84551d1 100644 --- a/protocols/Steam/src/steam_menus.cpp +++ b/protocols/Steam/src/steam_menus.cpp @@ -4,10 +4,10 @@ int CSteamProto::hChooserMenu; HGENMENU CSteamProto::contactMenuItems[CMI_MAX];
template<int(__cdecl CSteamProto::*Service)(WPARAM, LPARAM)>
-INT_PTR GlobalService(WPARAM wParam, LPARAM lParam)
+INT_PTR GlobalService(WPARAM hContact, LPARAM lParam)
{
- CSteamProto *ppro = CSteamProto::GetContactAccount((MCONTACT)wParam);
- return ppro ? (ppro->*Service)(wParam, lParam) : 0;
+ CSteamProto *ppro = CMPlugin::getInstance((MCONTACT)hContact);
+ return ppro ? (ppro->*Service)(hContact, lParam) : 0;
}
INT_PTR CSteamProto::AuthRequestCommand(WPARAM hContact, LPARAM)
@@ -81,9 +81,8 @@ INT_PTR CSteamProto::OpenBlockListCommand(WPARAM, LPARAM) return 0;
}
-int CSteamProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
+int CSteamProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
- MCONTACT hContact = (MCONTACT)wParam;
if (!hContact)
return 0;
@@ -106,13 +105,13 @@ int CSteamProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM) return 0;
}
-int CSteamProto::PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
+int CSteamProto::PrebuildContactMenu(WPARAM hContact, LPARAM lParam)
{
for (int i = 0; i < CMI_MAX; i++)
Menu_ShowItem(CSteamProto::contactMenuItems[i], false);
- CSteamProto* ppro = CSteamProto::GetContactAccount((MCONTACT)wParam);
- return (ppro) ? ppro->OnPrebuildContactMenu(wParam, lParam) : 0;
+ CSteamProto* ppro = CMPlugin::getInstance((MCONTACT)hContact);
+ return (ppro) ? ppro->OnPrebuildContactMenu(hContact, lParam) : 0;
}
void CSteamProto::OnInitStatusMenu()
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 1f41dfec84..93e8aca4be 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -75,12 +75,6 @@ public: virtual int __cdecl OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam);
- // instances
- static CSteamProto* InitAccount(const char* protoName, const wchar_t *userName);
- static int UninitAccount(CSteamProto* ppro);
-
- static CSteamProto* GetContactAccount(MCONTACT hContact);
-
// menus
static void InitMenus();
@@ -110,10 +104,6 @@ protected: */
time_t m_lastMessageTS;
- // instances
- static LIST<CSteamProto> Accounts;
- static int CompareProtos(const CSteamProto *p1, const CSteamProto *p2);
-
// requests
void SendRequest(HttpRequest *request);
void SendRequest(HttpRequest *request, HttpCallback callback, void *param = nullptr);
@@ -284,6 +274,13 @@ protected: }
};
+struct CMPlugin : public ACCPROTOPLUGIN<CSteamProto>
+{
+ CMPlugin() :
+ ACCPROTOPLUGIN<CSteamProto>("STEAM")
+ {}
+};
+
int OnReloadIcons(WPARAM wParam, LPARAM lParam);
void SetContactExtraIcon(MCONTACT hContact, int status);
|