summaryrefslogtreecommitdiff
path: root/src/mir_app
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-01 19:38:46 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-01 19:38:46 +0300
commit38853f0f252956930d6bd5bcd864fb76670d548b (patch)
treee89aee35e969228d5bd60ae099d20fa317ab6c5b /src/mir_app
parent1ad3f46ba54b0b2e57e4ab3ec66acf6da73cdde4 (diff)
four forgotten meta services removed
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/src/meta_api.cpp160
-rw-r--r--src/mir_app/src/meta_main.cpp2
-rw-r--r--src/mir_app/src/meta_services.cpp31
-rw-r--r--src/mir_app/src/meta_utils.cpp9
-rw-r--r--src/mir_app/src/metacontacts.h6
-rw-r--r--src/mir_app/src/mir_app.def17
-rw-r--r--src/mir_app/src/mir_app64.def17
7 files changed, 184 insertions, 58 deletions
diff --git a/src/mir_app/src/meta_api.cpp b/src/mir_app/src/meta_api.cpp
index ba704ade6e..ddb6411cec 100644
--- a/src/mir_app/src/meta_api.cpp
+++ b/src/mir_app/src/meta_api.cpp
@@ -24,49 +24,157 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "metacontacts.h"
-// gets the handle for the 'most online' contact
-// wParam=(MCONTACT)hMetaContact
-// lParam=0
-// returns a handle to the 'most online' contact
+MIR_APP_DLL(BOOL) db_mc_isEnabled(void)
+{
+ return g_bMetaEnabled;
+}
+
+MIR_APP_DLL(void) db_mc_enable(BOOL bEnabled)
+{
+ g_bMetaEnabled = bEnabled != 0;
+
+ NotifyEventHooks(hEventEnabled, g_bMetaEnabled, 0);
+}
+
+MIR_APP_DLL(BOOL) db_mc_isMeta(MCONTACT hContact)
+{
+ if (currDb == nullptr || !g_bMetaEnabled) return FALSE;
+
+ DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ return (cc == nullptr) ? FALSE : cc->nSubs != -1;
+}
+
+MIR_APP_DLL(BOOL) db_mc_isSub(MCONTACT hContact)
+{
+ if (currDb == nullptr || !g_bMetaEnabled) return FALSE;
+
+ DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ return (cc == nullptr) ? FALSE : cc->parentID != 0;
+}
-static INT_PTR MetaAPI_GetMostOnline(WPARAM hMetaContact, LPARAM)
+// returns a handle to the default contact, or null on failure
+MIR_APP_DLL(MCONTACT) db_mc_getDefault(MCONTACT hMetaContact)
{
DBCachedContact *cc = CheckMeta(hMetaContact);
- return (cc == nullptr) ? 0 : Meta_GetMostOnline(cc);
+ if (cc == nullptr)
+ return 0;
+
+ return (cc->nDefault != -1) ? Meta_GetContactHandle(cc, cc->nDefault) : 0;
}
-// wParam=(HANDLE)hContact
-// lParam=0
-// convert a given contact into a metacontact
+// returns the default contact number, or -1 on failure
+MIR_APP_DLL(int) db_mc_getDefaultNum(MCONTACT hMetaContact)
+{
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ return (cc == nullptr) ? -1 : cc->nDefault;
+}
-static INT_PTR MetaAPI_ConvertToMeta(WPARAM wParam, LPARAM lParam)
+// returns the number of subcontacts, or -1 on failure
+MIR_APP_DLL(int) db_mc_getSubCount(MCONTACT hMetaContact)
{
- return Meta_Convert(wParam, lParam);
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ return (cc == nullptr) ? -1 : cc->nSubs;
}
-// wParam=(HANDLE)hContact
-// lParam=(HANDLE)hMeta
-// add an existing contact to a metacontact
+// returns parent hContact for a subcontact or NULL if it's not a sub
+MIR_APP_DLL(MCONTACT) db_mc_getMeta(MCONTACT hSubContact)
+{
+ if (currDb == nullptr) return NULL;
+
+ DBCachedContact *cc = currDb->getCache()->GetCachedContact(hSubContact);
+ return (cc == nullptr) ? NULL : cc->parentID;
+}
-static INT_PTR MetaAPI_AddToMeta(WPARAM wParam, LPARAM lParam)
+// returns parent hContact for a subcontact or hContact itself if it's not a sub
+MIR_APP_DLL(MCONTACT) db_mc_tryMeta(MCONTACT hContact)
{
- return Meta_Assign(wParam, lParam, FALSE);
+ if (currDb == nullptr) return hContact;
+
+ DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ if (cc == nullptr) return hContact;
+
+ return (cc->IsSub()) ? cc->parentID : hContact;
}
-// wParam=0
-// lParam=(HANDLE)hContact
-// remove a contact from a metacontact
+// returns a subcontact with the given index
+MIR_APP_DLL(MCONTACT) db_mc_getSub(MCONTACT hMetaContact, int iNum)
+{
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ return (cc == nullptr) ? 0 : Meta_GetContactHandle(cc, iNum);
+}
+
+// gets the handle for the 'most online' contact
+MIR_APP_DLL(MCONTACT) db_mc_getMostOnline(MCONTACT hMetaContact)
+{
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ return (cc == nullptr) ? 0 : Meta_GetMostOnline(cc);
+}
+
+// returns manually chosen sub in the meta window
+MIR_APP_DLL(MCONTACT) db_mc_getSrmmSub(MCONTACT hContact)
+{
+ MetaSrmmData tmp = { hContact };
+ if (MetaSrmmData *p = arMetaWindows.find(&tmp))
+ return p->m_hSub;
+
+ return db_mc_getMostOnline(hContact);
+}
+
+// converts a given contact into a metacontact
+MIR_APP_DLL(MCONTACT) db_mc_convertToMeta(MCONTACT hContact)
+{
+ return Meta_Convert(hContact, 0);
+}
-static INT_PTR MetaAPI_RemoveFromMeta(WPARAM wParam, LPARAM lParam)
+// adds an existing contact to a metacontact
+MIR_APP_DLL(int) db_mc_addToMeta(MCONTACT hSub, MCONTACT hMetaContact)
+{
+ return Meta_Assign(hSub, hMetaContact, FALSE);
+}
+
+// removes a contact from a metacontact
+MIR_APP_DLL(int) db_mc_removeFromMeta(MCONTACT hSub)
{
// notice we switch args - to keep the API function consistent with the others
- return Meta_Delete(lParam, wParam);
+ return Meta_Delete(hSub, true);
}
-void CreateApiServices()
+// sets the default contact, using the subcontact's handle
+MIR_APP_DLL(int) db_mc_setDefault(MCONTACT hMetaContact, MCONTACT hSub, BOOL bWriteDb)
{
- CreateServiceFunction(MS_MC_GETMOSTONLINECONTACT, MetaAPI_GetMostOnline);
- CreateServiceFunction(MS_MC_CONVERTTOMETA, MetaAPI_ConvertToMeta);
- CreateServiceFunction(MS_MC_ADDTOMETA, MetaAPI_AddToMeta);
- CreateServiceFunction(MS_MC_REMOVEFROMMETA, MetaAPI_RemoveFromMeta);
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == nullptr)
+ return 1;
+
+ int contact_number = Meta_GetContactNumber(cc, hSub);
+ if (contact_number == -1)
+ return 1;
+
+ if (cc->nDefault != contact_number) {
+ cc->nDefault = contact_number;
+ if (bWriteDb)
+ currDb->MetaSetDefault(cc);
+
+ NotifyEventHooks(hEventDefaultChanged, hMetaContact, hSub);
+ }
+ return 0;
+}
+
+// sets the default contact, using the subcontact's number
+MIR_APP_DLL(int) db_mc_setDefaultNum(MCONTACT hMetaContact, int iNum, BOOL bWriteDb)
+{
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == nullptr)
+ return 1;
+ if (iNum >= cc->nSubs || iNum < 0)
+ return 1;
+
+ if (cc->nDefault != iNum) {
+ cc->nDefault = iNum;
+ if (bWriteDb)
+ currDb->MetaSetDefault(cc);
+
+ NotifyEventHooks(hEventDefaultChanged, hMetaContact, Meta_GetContactHandle(cc, iNum));
+ }
+ return 0;
}
diff --git a/src/mir_app/src/meta_main.cpp b/src/mir_app/src/meta_main.cpp
index 8e1be3ecd1..f15865ab3e 100644
--- a/src/mir_app/src/meta_main.cpp
+++ b/src/mir_app/src/meta_main.cpp
@@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "metacontacts.h"
+bool g_bMetaEnabled;
+
/////////////////////////////////////////////////////////////////////////////////////////
// icolib support
diff --git a/src/mir_app/src/meta_services.cpp b/src/mir_app/src/meta_services.cpp
index f8062a5bd8..39874a71c9 100644
--- a/src/mir_app/src/meta_services.cpp
+++ b/src/mir_app/src/meta_services.cpp
@@ -27,16 +27,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "clc.h"
#include "metacontacts.h"
-extern "C" MIR_CORE_DLL(void) db_mc_notifyDefChange(WPARAM wParam, LPARAM lParam);
-
char *pendingACK = nullptr; // Name of the protocol in which an ACK is about to come.
int previousMode, // Previous status of the MetaContacts Protocol
mcStatus; // Current status of the MetaContacts Protocol
-HANDLE
-hSubcontactsChanged, // HANDLE to the 'contacts changed' event
-hEventNudge;
+HANDLE hSubcontactsChanged; // ME_MC_SUBCONTACTSCHANGED
+HANDLE hEventDefaultChanged; // ME_MC_DEFAULTTCHANGED
+HANDLE hEventEnabled; // ME_MC_ENABLED
UINT_PTR setStatusTimerId = 0;
BOOL firstSetOnline = TRUE; // see Meta_SetStatus function
@@ -424,7 +422,7 @@ int Meta_SettingChanged(WPARAM hContact, LPARAM lParam)
// set status to that of most online contact
MCONTACT hMostOnline = Meta_GetMostOnline(ccMeta);
if (hMostOnline != db_mc_getDefault(ccMeta->contactID))
- db_mc_notifyDefChange(ccMeta->contactID, hMostOnline);
+ NotifyEventHooks(hEventDefaultChanged, ccMeta->contactID, hMostOnline);
Meta_CopyContactNick(ccMeta, hMostOnline);
Meta_FixStatus(ccMeta);
@@ -560,18 +558,6 @@ static int Meta_MessageWindowEvent(WPARAM, LPARAM lParam)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// returns manually chosen sub in the meta window
-
-static INT_PTR Meta_SrmmCurrentSub(WPARAM hMeta, LPARAM)
-{
- MetaSrmmData tmp = { (MCONTACT)hMeta };
- if (MetaSrmmData *p = arMetaWindows.find(&tmp))
- return p->m_hSub;
-
- return db_mc_getMostOnline(hMeta);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// we assume that it could be called only for the metacontacts
static int Meta_SrmmIconClicked(WPARAM hMeta, LPARAM lParam)
@@ -872,15 +858,14 @@ void Meta_InitServices()
CreateProtoServiceFunction(META_FILTER, PSR_MESSAGE, MetaFilter_RecvMessage);
// API services and events
- CreateApiServices();
-
CreateServiceFunction("MetaContacts/OnOff", Meta_OnOff);
- CreateServiceFunction(MS_MC_GETSRMMSUB, Meta_SrmmCurrentSub);
CreateProtoServiceFunction(META_PROTO, PS_SEND_NUDGE, Meta_SendNudge);
// create our hookable events
+ hEventEnabled = CreateHookableEvent(ME_MC_ENABLED);
hSubcontactsChanged = CreateHookableEvent(ME_MC_SUBCONTACTSCHANGED);
+ hEventDefaultChanged = CreateHookableEvent(ME_MC_DEFAULTTCHANGED);
// hook other module events we need
HookEvent(ME_PROTO_ACK, Meta_HandleACK);
@@ -892,9 +877,6 @@ void Meta_InitServices()
// hook our own events, used to call Meta_GetMostOnline which sets nick for metacontact
HookEvent(ME_MC_DEFAULTTCHANGED, Meta_CallMostOnline);
-
- // redirect nudge events
- hEventNudge = CreateHookableEvent(META_PROTO PE_NUDGE);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -903,5 +885,4 @@ void Meta_InitServices()
void Meta_CloseHandles()
{
DestroyHookableEvent(hSubcontactsChanged);
- DestroyHookableEvent(hEventNudge);
}
diff --git a/src/mir_app/src/meta_utils.cpp b/src/mir_app/src/meta_utils.cpp
index 753e514101..5b8d752c04 100644
--- a/src/mir_app/src/meta_utils.cpp
+++ b/src/mir_app/src/meta_utils.cpp
@@ -296,16 +296,17 @@ DBCachedContact* CheckMeta(MCONTACT hMeta)
int Meta_GetContactNumber(DBCachedContact *cc, MCONTACT hContact)
{
- for (int i = 0; i < cc->nSubs; i++)
- if (cc->pSubs[i] == hContact)
- return i;
+ if (g_bMetaEnabled)
+ for (int i = 0; i < cc->nSubs; i++)
+ if (cc->pSubs[i] == hContact)
+ return i;
return -1;
}
MCONTACT Meta_GetContactHandle(DBCachedContact *cc, int contact_number)
{
- if (contact_number >= cc->nSubs || contact_number < 0)
+ if (contact_number >= cc->nSubs || contact_number < 0 || !g_bMetaEnabled)
return 0;
return cc->pSubs[contact_number];
diff --git a/src/mir_app/src/metacontacts.h b/src/mir_app/src/metacontacts.h
index 3c7cbdd90d..590c886a84 100644
--- a/src/mir_app/src/metacontacts.h
+++ b/src/mir_app/src/metacontacts.h
@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// contact menu items
void InitMenus();
extern int mcStatus;
+extern bool g_bMetaEnabled;
struct MetaSrmmData
{
@@ -98,14 +99,13 @@ extern MetaOptions g_metaOptions;
int Meta_OptInit(WPARAM wParam, LPARAM lParam);
int Meta_ReadOptions();
-// API function headers
-void CreateApiServices();
+/////////////////////////////////////////////////////////////////////////////////////////
typedef enum {I_MENUOFF, I_MENU, I_CONVERT, I_ADD, I_EDIT, I_SETDEFAULT, I_REMOVE} IconIndex;
HICON Meta_LoadIconEx(IconIndex i, bool big = false);
HANDLE Meta_GetIconHandle(IconIndex i);
-extern HANDLE hEventForceSend, hEventUnforceSend, hSubcontactsChanged;
+extern HANDLE hSubcontactsChanged, hEventDefaultChanged, hEventEnabled;
extern POINT menuMousePoint;
#define MAX_PROTOCOLS 20
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index b7feb9939b..82d6345ebf 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -678,3 +678,20 @@ Chat_SetGroup @706
??6@YGPAUMHttpRequest@@PAU0@ABUWCHAR_PARAM@@@Z @713 NONAME
??6@YGPAUMHttpRequest@@PAU0@ABUINT64_PARAM@@@Z @714 NONAME
?AddHeader@MHttpRequest@@QAEXPBD0@Z @715 NONAME
+db_mc_addToMeta @716
+db_mc_convertToMeta @717
+db_mc_enable @718
+db_mc_getDefault @719
+db_mc_getDefaultNum @720
+db_mc_getMeta @721
+db_mc_getMostOnline @722
+db_mc_getSrmmSub @723
+db_mc_getSub @724
+db_mc_getSubCount @725
+db_mc_isEnabled @726
+db_mc_isMeta @727
+db_mc_isSub @728
+db_mc_removeFromMeta @729
+db_mc_setDefault @730
+db_mc_setDefaultNum @731
+db_mc_tryMeta @732
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index f4fc8d7df4..f17e4dc692 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -678,3 +678,20 @@ Chat_SetGroup @706
??6@YAPEAUMHttpRequest@@PEAU0@AEBUWCHAR_PARAM@@@Z @713 NONAME
??6@YAPEAUMHttpRequest@@PEAU0@AEBUINT64_PARAM@@@Z @714 NONAME
?AddHeader@MHttpRequest@@QEAAXPEBD0@Z @715 NONAME
+db_mc_addToMeta @716
+db_mc_convertToMeta @717
+db_mc_enable @718
+db_mc_getDefault @719
+db_mc_getDefaultNum @720
+db_mc_getMeta @721
+db_mc_getMostOnline @722
+db_mc_getSrmmSub @723
+db_mc_getSub @724
+db_mc_getSubCount @725
+db_mc_isEnabled @726
+db_mc_isMeta @727
+db_mc_isSub @728
+db_mc_removeFromMeta @729
+db_mc_setDefault @730
+db_mc_setDefaultNum @731
+db_mc_tryMeta @732