summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-02 23:05:24 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-02 23:05:24 +0000
commit02f30a6b6b2e36fab71d0425c1bc95c7d5b26c50 (patch)
tree3136860092617b56a1a4cb28d7b920377912b799
parent0749bac971a90ae89d095d2ef81a27f4988f72f0 (diff)
next compilable mc version - all api rewritten to use the cache
git-svn-id: http://svn.miranda-ng.org/main/trunk@8366 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--src/miranda32_10.vcxproj1
-rw-r--r--src/miranda32_10.vcxproj.filters17
-rw-r--r--src/modules/metacontacts/meta_api.cpp135
-rw-r--r--src/modules/metacontacts/meta_edit.cpp50
-rw-r--r--src/modules/metacontacts/meta_main.cpp3
-rw-r--r--src/modules/metacontacts/meta_menu.cpp86
-rw-r--r--src/modules/metacontacts/meta_services.cpp423
-rw-r--r--src/modules/metacontacts/meta_utils.cpp313
-rw-r--r--src/modules/metacontacts/metacontacts.h31
9 files changed, 544 insertions, 515 deletions
diff --git a/src/miranda32_10.vcxproj b/src/miranda32_10.vcxproj
index 81927e0bbf..b5defb0ab5 100644
--- a/src/miranda32_10.vcxproj
+++ b/src/miranda32_10.vcxproj
@@ -263,6 +263,7 @@
<ClInclude Include="modules\extraicons\extraicons.h" />
<ClInclude Include="modules\extraicons\usedIcons.h" />
<ClInclude Include="modules\findadd\findadd.h" />
+ <ClInclude Include="modules\metacontacts\metacontacts.h" />
<ClInclude Include="modules\netlib\netlib.h" />
<ClInclude Include="modules\options\filter.h" />
<ClInclude Include="..\include\m_protoint.h" />
diff --git a/src/miranda32_10.vcxproj.filters b/src/miranda32_10.vcxproj.filters
index 77ed2ccd0f..d383b34980 100644
--- a/src/miranda32_10.vcxproj.filters
+++ b/src/miranda32_10.vcxproj.filters
@@ -258,18 +258,9 @@
<ClInclude Include="..\include\m_utils.h">
<Filter>Modules\utils</Filter>
</ClInclude>
- <ClInclude Include="..\include\m_chat_int.h">
- <Filter>Modules\chat</Filter>
- </ClInclude>
- <ClInclude Include="..\include\m_chat.h">
- <Filter>Modules\chat</Filter>
- </ClInclude>
<ClInclude Include="modules\chat\chat.h">
<Filter>Modules\chat</Filter>
</ClInclude>
- <ClInclude Include="..\include\m_string.h">
- <Filter>SDK</Filter>
- </ClInclude>
<ClInclude Include="modules\metacontacts\metacontacts.h">
<Filter>Modules\metacontacts</Filter>
</ClInclude>
@@ -596,12 +587,6 @@
<ClCompile Include="modules\chat\tools.cpp">
<Filter>Modules\chat</Filter>
</ClCompile>
- <ClCompile Include="modules\metacontacts\addto.cpp">
- <Filter>Modules\metacontacts</Filter>
- </ClCompile>
- <ClCompile Include="modules\metacontacts\edit.cpp">
- <Filter>Modules\metacontacts</Filter>
- </ClCompile>
<ClCompile Include="modules\metacontacts\meta_api.cpp">
<Filter>Modules\metacontacts</Filter>
</ClCompile>
@@ -620,6 +605,8 @@
<ClCompile Include="modules\metacontacts\meta_utils.cpp">
<Filter>Modules\metacontacts</Filter>
</ClCompile>
+ <ClCompile Include="modules\metacontacts\meta_addto.cpp" />
+ <ClCompile Include="modules\metacontacts\meta_edit.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc">
diff --git a/src/modules/metacontacts/meta_api.cpp b/src/modules/metacontacts/meta_api.cpp
index 1d94f15be9..af114f4bd3 100644
--- a/src/modules/metacontacts/meta_api.cpp
+++ b/src/modules/metacontacts/meta_api.cpp
@@ -28,11 +28,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//wParam=(MCONTACT)hMetaContact
//lParam=0
//returns a handle to the default contact, or null on failure
-INT_PTR MetaAPI_GetDefault(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_GetDefault(WPARAM hMetaContact, LPARAM)
{
- DWORD default_contact_number = db_get_dw(wParam, META_PROTO, "Default", -1);
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == NULL)
+ return 1;
+
+ DWORD default_contact_number = db_get_dw(hMetaContact, META_PROTO, "Default", -1);
if (default_contact_number != -1)
- return (INT_PTR)Meta_GetContactHandle(wParam, default_contact_number);
+ return (INT_PTR)Meta_GetContactHandle(cc, default_contact_number);
return 0;
}
@@ -41,71 +45,87 @@ INT_PTR MetaAPI_GetDefault(WPARAM wParam, LPARAM lParam)
//wParam=(MCONTACT)hMetaContact
//lParam=0
//returns a DWORD contact number, or -1 on failure
-INT_PTR MetaAPI_GetDefaultNum(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_GetDefaultNum(WPARAM hMetaContact, LPARAM)
{
- return db_get_dw(wParam, META_PROTO, "Default", -1);
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == NULL)
+ return 1;
+
+ // !!!!!!!!!!!!!!!!!!!!!!!
+ // return db_get_dw(hMetaContact, META_PROTO, "Default", -1);
+ return -1;
}
//gets the handle for the 'most online' contact
//wParam=(MCONTACT)hMetaContact
//lParam=0
//returns a handle to the 'most online' contact
-INT_PTR MetaAPI_GetMostOnline(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_GetMostOnline(WPARAM hMetaContact, LPARAM)
{
- return (INT_PTR)Meta_GetMostOnline(wParam);
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == NULL)
+ return 1;
+
+ return Meta_GetMostOnline(cc);
}
//gets the number of subcontacts for a metacontact
//wParam=(MCONTACT)hMetaContact
//lParam=0
//returns a DWORD representing the number of subcontacts for the given metacontact
-INT_PTR MetaAPI_GetNumContacts(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_GetNumContacts(WPARAM hMetaContact, LPARAM)
{
- DWORD num_contacts = db_get_dw(wParam, META_PROTO, "NumContacts", -1);
- return num_contacts;
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ return (cc == NULL) ? -1 : cc->nSubs;
}
//gets the handle of a subcontact, using the subcontact's number
//wParam=(MCONTACT)hMetaContact
//lParam=(DWORD)contact number
//returns a handle to the specified subcontact
-INT_PTR MetaAPI_GetContact(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_GetContact(WPARAM hMetaContact, LPARAM lParam)
{
- return (INT_PTR)Meta_GetContactHandle(wParam, (DWORD)lParam);
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ return (cc == NULL) ? 0 : Meta_GetContactHandle(cc, lParam);
}
//sets the default contact, using the subcontact's contact number
//wParam=(MCONTACT)hMetaContact
//lParam=(DWORD)contact number
//returns 0 on success
-INT_PTR MetaAPI_SetDefaultContactNum(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_SetDefaultContactNum(WPARAM hMetaContact, LPARAM lParam)
{
- DWORD num_contacts = db_get_dw(wParam, META_PROTO, "NumContacts", -1);
- if (num_contacts == -1)
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == NULL)
return 1;
- if ((DWORD)lParam >= num_contacts || (DWORD)lParam < 0)
+ if ((int)lParam >= cc->nSubs || (int)lParam < 0)
return 1;
- if (db_set_dw(wParam, META_PROTO, "Default", (DWORD)lParam))
+ if (db_set_dw(hMetaContact, META_PROTO, "Default", (DWORD)lParam))
return 1;
- NotifyEventHooks(hEventDefaultChanged, wParam, (LPARAM)Meta_GetContactHandle(wParam, (int)lParam));
+ NotifyEventHooks(hEventDefaultChanged, hMetaContact, Meta_GetContactHandle(cc, (int)lParam));
return 0;
}
//sets the default contact, using the subcontact's handle
//wParam=(MCONTACT)hMetaContact
-//lParam=(HANDLE)hSubcontact
+//lParam=(MCONTACT)hSubcontact
//returns 0 on success
-INT_PTR MetaAPI_SetDefaultContact(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_SetDefaultContact(WPARAM hMetaContact, LPARAM lParam)
{
- MCONTACT hMeta = (MCONTACT)db_get_dw(lParam, META_PROTO, "Handle", 0);
- DWORD contact_number = Meta_GetContactNumber(lParam);
- if (contact_number == -1 || !hMeta || hMeta != wParam)
+ DBCachedContact *cc = CheckMeta(lParam);
+ if (cc == NULL)
+ return 1;
+
+ int contact_number = Meta_GetContactNumber(cc, lParam);
+ if (contact_number == -1)
return 1;
- if (db_set_dw(hMeta, META_PROTO, "Default", contact_number))
+
+ // currDb->Meta_SetDefaultSub(cc, lParam); !!!!!!!!!!!!!!!!!!!!
+ if (db_set_dw(cc->contactID, META_PROTO, "Default", contact_number))
return 1;
- NotifyEventHooks(hEventDefaultChanged, wParam, lParam);
+ NotifyEventHooks(hEventDefaultChanged, hMetaContact, lParam);
return 0;
}
@@ -113,33 +133,41 @@ INT_PTR MetaAPI_SetDefaultContact(WPARAM wParam, LPARAM lParam)
//wParam=(MCONTACT)hMetaContact
//lParam=(DWORD)contact number
//returns 0 on success
-INT_PTR MetaAPI_ForceSendContactNum(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_ForceSendContactNum(WPARAM hMetaContact, LPARAM lParam)
{
- MCONTACT hContact = Meta_GetContactHandle(wParam, (int)lParam);
- MCONTACT hMeta = (MCONTACT)db_get_dw(hContact, META_PROTO, "Handle", 0);
- if (!hContact || !hMeta || hMeta != wParam || db_get_b(hMeta, META_PROTO, "ForceDefault", 0))
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == NULL)
return 1;
- db_set_dw(hMeta, META_PROTO, "ForceSend", (DWORD)hContact);
+ MCONTACT hContact = Meta_GetContactHandle(cc, (int)lParam);
+ if (!hContact || db_get_b(cc->contactID, META_PROTO, "ForceDefault", 0))
+ return 1;
+
+ db_set_dw(cc->contactID, META_PROTO, "ForceSend", hContact);
- NotifyEventHooks(hEventForceSend, wParam, (LPARAM)hContact);
+ NotifyEventHooks(hEventForceSend, hMetaContact, hContact);
return 0;
}
//forces the metacontact to send using a specific subcontact, using the subcontact's handle
//wParam=(MCONTACT)hMetaContact
-//lParam=(HANDLE)hSubcontact
+//lParam=(MCONTACT)hSubcontact
//returns 0 on success (will fail if 'force default' is in effect)
-INT_PTR MetaAPI_ForceSendContact(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_ForceSendContact(WPARAM hMetaContact, LPARAM lParam)
{
- MCONTACT hContact = lParam;
- MCONTACT hMeta = (MCONTACT)db_get_dw(hContact, META_PROTO, "Handle", 0);
- if (!hContact || !hMeta || hMeta != wParam || db_get_b(hMeta, META_PROTO, "ForceDefault", 0))
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == NULL)
+ return 1;
+
+ if (Meta_GetContactNumber(cc, lParam) == -1)
return 1;
- db_set_dw(hMeta, META_PROTO, "ForceSend", (DWORD)hContact);
+ if (!db_get_b(cc->contactID, META_PROTO, "ForceDefault", 0))
+ return 1;
+
+ db_set_dw(cc->contactID, META_PROTO, "ForceSend", lParam);
- NotifyEventHooks(hEventForceSend, wParam, lParam);
+ NotifyEventHooks(hEventForceSend, hMetaContact, lParam);
return 0;
}
@@ -147,14 +175,14 @@ INT_PTR MetaAPI_ForceSendContact(WPARAM wParam, LPARAM lParam)
//wParam=(MCONTACT)hMetaContact
//lParam=0
//returns 0 on success (will fail if 'force default' is in effect)
-INT_PTR MetaAPI_UnforceSendContact(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_UnforceSendContact(WPARAM hMetaContact, LPARAM lParam)
{
- if (db_get_b(wParam, META_PROTO, "ForceDefault", 0))
+ if (db_get_b(hMetaContact, META_PROTO, "ForceDefault", 0))
return 1;
- db_set_dw(wParam, META_PROTO, "ForceSend", 0);
+ db_set_dw(hMetaContact, META_PROTO, "ForceSend", 0);
- NotifyEventHooks(hEventUnforceSend, wParam, lParam);
+ NotifyEventHooks(hEventUnforceSend, hMetaContact, lParam);
return 0;
}
@@ -165,11 +193,11 @@ INT_PTR MetaAPI_UnforceSendContact(WPARAM wParam, LPARAM lParam)
//wParam=(MCONTACT)hMetaContact
//lParam=0
//returns 1(true) or 0(false) representing new state of 'force default'
-INT_PTR MetaAPI_ForceDefault(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_ForceDefault(WPARAM hMetaContact, LPARAM lParam)
{
// forward to menu function
- Meta_ForceDefault(wParam, lParam);
- return db_get_b(wParam, META_PROTO, "ForceDefault", 0);
+ Meta_ForceDefault(hMetaContact, lParam);
+ return db_get_b(hMetaContact, META_PROTO, "ForceDefault", 0);
}
// method to get state of 'force' for a metacontact
@@ -178,22 +206,23 @@ INT_PTR MetaAPI_ForceDefault(WPARAM wParam, LPARAM lParam)
// if lparam supplied, the contact_number of the contatct 'in force' will be copied to the address it points to,
// or if none is in force, the value INVALID_CONTACT_ID will be copied
// (v0.8.0.8+ returns 1 if 'force default' is true with *lParam == default contact number, else returns 0 with *lParam as above)
-INT_PTR MetaAPI_GetForceState(WPARAM wParam, LPARAM lParam)
+INT_PTR MetaAPI_GetForceState(WPARAM hMetaContact, LPARAM lParam)
{
- MCONTACT hMeta = wParam;
- if ( !hMeta) return 0;
-
- if (db_get_b(hMeta, META_PROTO, "ForceDefault", 0)) {
- if (lParam) *(DWORD *)lParam = db_get_dw(wParam, META_PROTO, "Default", -1);
+ DBCachedContact *cc = CheckMeta(hMetaContact);
+ if (cc == NULL)
+ return 0;
+
+ if (db_get_b(hMetaContact, META_PROTO, "ForceDefault", 0)) {
+ if (lParam) *(DWORD *)lParam = db_get_dw(hMetaContact, META_PROTO, "Default", -1);
return 1;
}
- MCONTACT hContact = (MCONTACT)db_get_dw(hMeta, META_PROTO, "ForceSend", 0);
+ MCONTACT hContact = (MCONTACT)db_get_dw(hMetaContact, META_PROTO, "ForceSend", 0);
if (!hContact) {
if (lParam) *(DWORD *)lParam = -1;
}
else {
- if (lParam) *(DWORD *)lParam = (DWORD)Meta_GetContactNumber(hContact);
+ if (lParam) *(DWORD *)lParam = (DWORD)Meta_GetContactNumber(cc, hContact);
}
return 0;
diff --git a/src/modules/metacontacts/meta_edit.cpp b/src/modules/metacontacts/meta_edit.cpp
index 5fda2d5f8e..bb9aa2eec3 100644
--- a/src/modules/metacontacts/meta_edit.cpp
+++ b/src/modules/metacontacts/meta_edit.cpp
@@ -25,18 +25,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "metacontacts.h"
//! Holds the differents changes that have to made
-typedef struct tag_CHANGES {
- MCONTACT hMeta; //!< \c HANDLE of the MetaContact that is edited.
- MCONTACT hDefaultContact; //!< \c HANDLE of the new default contact
+struct CHANGES
+{
+ MCONTACT hMeta; // HANDLE of the MetaContact that is edited.
+ DBCachedContact *cc;
+ MCONTACT hDefaultContact; // HANDLE of the new default contact
MCONTACT hOfflineContact;
- int num_deleted, //!< \c DWORD number of deleted contacts
- num_contacts; //!< \c DWORD number of contacts
- MCONTACT hDeletedContacts[MAX_CONTACTS]; //!< \c HANDLEs of the subcontacts to be removed from this metacontact
- MCONTACT hContact[MAX_CONTACTS]; //!< \c HANDLEs of the subcontacts, in the order they should be in
+ int num_deleted, // DWORD number of deleted contacts
+ num_contacts; // DWORD number of contacts
+ MCONTACT hDeletedContacts[MAX_CONTACTS]; // HANDLEs of the subcontacts to be removed from this metacontact
+ MCONTACT hContact[MAX_CONTACTS]; // HANDLEs of the subcontacts, in the order they should be in
int force_default;
-} CHANGES;
+};
-CHANGES changes; //!< \c global CHANGES structure
+CHANGES changes; // global CHANGES structure
/** Fills the list of contacts
*
@@ -143,35 +145,34 @@ void ApplyChanges(CHANGES *chg)
}
// set contact positions
- for (i = 0; i < chg->num_contacts; i++) {
- if (Meta_GetContactNumber(chg->hContact[i]) != i)
- Meta_SwapContacts(chg->hMeta, Meta_GetContactNumber(chg->hContact[i]), i);
- }
+ for (i = 0; i < chg->num_contacts; i++)
+ if (Meta_GetContactNumber(chg->cc, chg->hContact[i]) != i)
+ Meta_SwapContacts(chg->cc, Meta_GetContactNumber(chg->cc, chg->hContact[i]), i);
- NotifyEventHooks(hSubcontactsChanged, (WPARAM)chg->hMeta, (LPARAM)chg->hDefaultContact);
+ NotifyEventHooks(hSubcontactsChanged, chg->hMeta, chg->hDefaultContact);
// set default
if (chg->hDefaultContact)
- db_set_dw(chg->hMeta, META_PROTO, "Default", Meta_GetContactNumber(chg->hDefaultContact));
+ db_set_dw(chg->hMeta, META_PROTO, "Default", Meta_GetContactNumber(chg->cc, chg->hDefaultContact));
else
db_set_dw(chg->hMeta, META_PROTO, "Default", 0);
- NotifyEventHooks(hEventDefaultChanged, (WPARAM)chg->hMeta, (LPARAM)chg->hDefaultContact);
+ NotifyEventHooks(hEventDefaultChanged, chg->hMeta, chg->hDefaultContact);
// set offline
if (chg->hOfflineContact)
- db_set_dw(chg->hMeta, META_PROTO, "OfflineSend", Meta_GetContactNumber(chg->hOfflineContact));
+ db_set_dw(chg->hMeta, META_PROTO, "OfflineSend", Meta_GetContactNumber(chg->cc, chg->hOfflineContact));
else
db_set_dw(chg->hMeta, META_PROTO, "OfflineSend", INVALID_CONTACT_ID);
// fix nick
- MCONTACT most_online = Meta_GetMostOnline(chg->hMeta);
- Meta_CopyContactNick(chg->hMeta, most_online);
+ MCONTACT most_online = Meta_GetMostOnline(chg->cc);
+ Meta_CopyContactNick(chg->cc, most_online);
// fix status
- Meta_FixStatus(chg->hMeta);
+ Meta_FixStatus(chg->cc);
// fix avatar
- most_online = Meta_GetMostOnlineSupporting(chg->hMeta, PFLAGNUM_4, PF4_AVATARS);
+ most_online = Meta_GetMostOnlineSupporting(chg->cc, PFLAGNUM_4, PF4_AVATARS);
if (most_online) {
PROTO_AVATAR_INFORMATIONT AI;
@@ -272,12 +273,13 @@ INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
int offline_contact_number = db_get_dw(lParam, META_PROTO, "OfflineSend", INVALID_CONTACT_ID);
changes.hMeta = lParam;
+ changes.cc = currDb->m_cache->GetCachedContact(lParam);
changes.num_contacts = nb_contacts;
changes.num_deleted = 0;
- changes.hDefaultContact = Meta_GetContactHandle(lParam, default_contact_number);
- changes.hOfflineContact = Meta_GetContactHandle(lParam, offline_contact_number);
+ changes.hDefaultContact = Meta_GetContactHandle(changes.cc, default_contact_number);
+ changes.hOfflineContact = Meta_GetContactHandle(changes.cc, offline_contact_number);
for (i = 0; i < nb_contacts; i++)
- changes.hContact[i] = Meta_GetContactHandle(lParam, i);
+ changes.hContact[i] = Meta_GetContactHandle(changes.cc, i);
changes.force_default = MetaAPI_GetForceState((WPARAM)lParam, 0);
SendMessage(hwndDlg, WMU_SETTITLE, 0, lParam);
diff --git a/src/modules/metacontacts/meta_main.cpp b/src/modules/metacontacts/meta_main.cpp
index 0a1efc6d24..ac7a888fb5 100644
--- a/src/modules/metacontacts/meta_main.cpp
+++ b/src/modules/metacontacts/meta_main.cpp
@@ -84,8 +84,5 @@ int LoadMetacontacts(void)
// further db setup done in modules loaded (nick [protocol string required] & clist display name)
Meta_InitServices();
-
- // for clist_meta_mw - write hidden group name to DB
- db_set_s(0, META_PROTO, "HiddenGroupName", META_HIDDEN_GROUP);
return 0;
}
diff --git a/src/modules/metacontacts/meta_menu.cpp b/src/modules/metacontacts/meta_menu.cpp
index 9647ad1642..aeed077a18 100644
--- a/src/modules/metacontacts/meta_menu.cpp
+++ b/src/modules/metacontacts/meta_menu.cpp
@@ -118,13 +118,16 @@ INT_PTR Meta_Edit(WPARAM wParam,LPARAM lParam)
void Meta_RemoveContactNumber(MCONTACT hMeta, int number)
{
- int num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", 0);
- int default_contact = db_get_dw(hMeta, META_PROTO, "Default", -1);
- if (number < 0 && number >= num_contacts)
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc == NULL)
+ return;
+
+ if (number < 0 && number >= cc->nSubs)
return;
// get the handle
- MCONTACT hContact = Meta_GetContactHandle(hMeta, number);
+ MCONTACT hContact = Meta_GetContactHandle(cc, number);
+ int default_contact = db_get_dw(hMeta, META_PROTO, "Default", -1);
// make sure this contact thinks it's part of this metacontact
if (db_get_dw(hContact, META_PROTO, "Handle", 0) == hMeta) {
@@ -132,7 +135,6 @@ void Meta_RemoveContactNumber(MCONTACT hMeta, int number)
db_unset(hContact, META_PROTO, META_LINK);
db_unset(hContact, META_PROTO, "Handle");
// unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus)
- Meta_RestoreGroup(hContact);
db_unset(hContact, META_PROTO, "OldCListGroup");
// stop ignoring, if we were
@@ -142,12 +144,12 @@ void Meta_RemoveContactNumber(MCONTACT hMeta, int number)
// each contact from 'number' upwards will be moved down one
// and the last one will be deleted
- for (int i = number + 1; i < num_contacts; i++)
- Meta_SwapContacts(hMeta, i, i-1);
+ for (int i = number + 1; i < cc->nSubs; i++)
+ Meta_SwapContacts(cc, i, i-1);
// remove the last one
char buffer[512], idStr[20];
- _itoa(num_contacts-1, idStr, 10);
+ _itoa(cc->nSubs - 1, idStr, 10);
strcpy(buffer, "Protocol"); strcat(buffer, idStr);
db_unset(hMeta, META_PROTO, buffer);
@@ -175,21 +177,21 @@ void Meta_RemoveContactNumber(MCONTACT hMeta, int number)
if (default_contact < 0)
default_contact = 0;
- db_set_dw(hMeta, META_PROTO, "Default", (DWORD)default_contact);
- NotifyEventHooks(hEventDefaultChanged, (WPARAM)hMeta, (LPARAM)Meta_GetContactHandle(hMeta, default_contact));
+ db_set_dw(hMeta, META_PROTO, "Default", default_contact);
+ NotifyEventHooks(hEventDefaultChanged, hMeta, Meta_GetContactHandle(cc, default_contact));
}
- num_contacts--;
- db_set_dw(hMeta, META_PROTO, "NumContacts", (DWORD)num_contacts);
+ cc->nSubs--;
+ db_set_dw(hMeta, META_PROTO, "NumContacts", cc->nSubs);
// fix nick
- hContact = Meta_GetMostOnline(hMeta);
- Meta_CopyContactNick(hMeta, hContact);
+ hContact = Meta_GetMostOnline(cc);
+ Meta_CopyContactNick(cc, hContact);
// fix status
- Meta_FixStatus(hMeta);
+ Meta_FixStatus(cc);
// fix avatar
- hContact = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS);
+ hContact = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS);
if (hContact) {
PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) };
AI.hContact = hMeta;
@@ -230,7 +232,6 @@ INT_PTR Meta_Delete(WPARAM wParam, LPARAM lParam)
db_unset(hContact, META_PROTO, "Handle");
// unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus)
- Meta_RestoreGroup(hContact);
db_unset(hContact, META_PROTO, "OldCListGroup");
// stop ignoring, if we were
@@ -262,18 +263,16 @@ INT_PTR Meta_Delete(WPARAM wParam, LPARAM lParam)
*
* Set the given contact to be the default one for the metacontact to which it is linked.
*
-* @param wParam : \c HANDLE to the MetaContact to be set as default
-* @param lParam : \c HWND to the clist window
+* @param wParam : HANDLE to the MetaContact to be set as default
+* @param lParam : HWND to the clist window
(This means the function has been called via the contact menu).
*/
-INT_PTR Meta_Default(WPARAM wParam, LPARAM lParam)
+INT_PTR Meta_Default(WPARAM hMeta, LPARAM wParam)
{
- MCONTACT hMeta;
-
- // the wParam is a subcontact
- if ((hMeta = (MCONTACT)db_get_dw(wParam, META_PROTO, "Handle", 0)) != 0) {
- db_set_dw(hMeta, META_PROTO, "Default", (DWORD)Meta_GetContactNumber(wParam));
- NotifyEventHooks(hEventDefaultChanged, (WPARAM)hMeta, (LPARAM)wParam);
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc) {
+ db_set_dw(hMeta, META_PROTO, "Default", Meta_GetContactNumber(cc, wParam));
+ NotifyEventHooks(hEventDefaultChanged, hMeta, wParam);
}
return 0;
}
@@ -287,20 +286,21 @@ INT_PTR Meta_Default(WPARAM wParam, LPARAM lParam)
(This means the function has been called via the contact menu).
*/
-INT_PTR Meta_ForceDefault(WPARAM wParam, LPARAM lParam)
+INT_PTR Meta_ForceDefault(WPARAM hMeta, LPARAM)
{
// the wParam is a MetaContact
- if (db_get_dw(wParam, META_PROTO, META_ID, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
- BOOL current = db_get_b(wParam, META_PROTO, "ForceDefault", 0);
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc) {
+ BOOL current = db_get_b(hMeta, META_PROTO, "ForceDefault", 0);
current = !current;
- db_set_b(wParam, META_PROTO, "ForceDefault", (BYTE)current);
+ db_set_b(hMeta, META_PROTO, "ForceDefault", (BYTE)current);
- db_set_dw(wParam, META_PROTO, "ForceSend", 0);
+ db_set_dw(hMeta, META_PROTO, "ForceSend", 0);
if (current)
- NotifyEventHooks(hEventForceSend, wParam, (LPARAM)Meta_GetContactHandle(wParam, db_get_dw(wParam, META_PROTO, "Default", -1)));
+ NotifyEventHooks(hEventForceSend, hMeta, Meta_GetContactHandle(cc, db_get_dw(hMeta, META_PROTO, "Default", -1)));
else
- NotifyEventHooks(hEventUnforceSend, wParam, 0);
+ NotifyEventHooks(hEventUnforceSend, hMeta, 0);
}
return 0;
}
@@ -314,12 +314,16 @@ INT_PTR Meta_ForceDefault(WPARAM wParam, LPARAM lParam)
* @param lParam : Always set to 0;
*/
-int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam)
+int Meta_ModifyMenu(WPARAM hMeta, LPARAM lParam)
{
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc == NULL)
+ return 0;
+
CLISTMENUITEM mi = { sizeof(mi) };
Menu_ShowItem(hMenuRoot, false);
- if (db_get_dw(wParam, META_PROTO, META_ID, -1) != INVALID_CONTACT_ID) {
+ if (db_get_dw(hMeta, META_PROTO, META_ID, -1) != INVALID_CONTACT_ID) {
// save the mouse pos in case they open a subcontact menu
GetCursorPos(&menuMousePoint);
@@ -335,14 +339,14 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam)
Menu_ModifyItem(hMenuDelete, &mi);
//show subcontact menu items
- int num_contacts = db_get_dw(wParam, META_PROTO, "NumContacts", 0);
+ int num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", 0);
for (int i = 0; i < MAX_CONTACTS; i++) {
if (i >= num_contacts) {
Menu_ShowItem(hMenuContact[i], false);
continue;
}
- MCONTACT hContact = Meta_GetContactHandle(wParam, i);
+ MCONTACT hContact = Meta_GetContactHandle(cc, i);
char *szProto = GetContactProto(hContact);
if (options.menu_contact_label == DNT_UID) {
@@ -351,7 +355,7 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam)
strcat(buf, _itoa(i, idStr, 10));
DBVARIANT dbv;
- db_get(wParam, META_PROTO, buf, &dbv);
+ db_get(hMeta, META_PROTO, buf, &dbv);
switch (dbv.type) {
case DBVT_ASCIIZ:
mir_snprintf(buf, 512, "%s", dbv.pszVal);
@@ -390,7 +394,7 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam)
// show hide nudge menu item
char serviceFunc[256];
- mir_snprintf(serviceFunc, 256, "%s%s", GetContactProto(Meta_GetMostOnline(wParam)), PS_SEND_NUDGE);
+ mir_snprintf(serviceFunc, 256, "%s%s", GetContactProto(Meta_GetMostOnline(cc)), PS_SEND_NUDGE);
CallService(MS_NUDGE_SHOWMENU, (WPARAM)META_PROTO, (LPARAM)ServiceExists(serviceFunc));
}
else { // This is a simple contact
@@ -402,7 +406,7 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam)
Menu_ShowItem(hMenuConvert, false);
Menu_ShowItem(hMenuEdit, false);
}
- else if (db_get_dw(wParam, META_PROTO, META_LINK, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
+ else if (db_get_dw(hMeta, META_PROTO, META_LINK, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
// The contact is affected to a metacontact.
Menu_ShowItem(hMenuDefault, true);
@@ -520,7 +524,7 @@ void InitMenus()
int meta_id;
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
if ((meta_id = db_get_dw(hContact, META_PROTO, META_ID, INVALID_CONTACT_ID)) != INVALID_CONTACT_ID)
- Meta_CopyData(hContact);
+ Meta_CopyData(CheckMeta(hContact));
}
Meta_HideLinkedContacts();
diff --git a/src/modules/metacontacts/meta_services.cpp b/src/modules/metacontacts/meta_services.cpp
index 2ce161b191..01817d525e 100644
--- a/src/modules/metacontacts/meta_services.cpp
+++ b/src/modules/metacontacts/meta_services.cpp
@@ -249,8 +249,12 @@ INT_PTR MetaFilter_SendMessage(WPARAM wParam,LPARAM lParam)
INT_PTR Meta_SendNudge(WPARAM wParam,LPARAM lParam)
{
- MCONTACT hSubContact = Meta_GetMostOnline(wParam);
- return ProtoCallService(GetContactProto(hSubContact), PS_SEND_NUDGE, (WPARAM)hSubContact, lParam);
+ DBCachedContact *cc = CheckMeta(wParam);
+ if (cc == NULL)
+ return 1;
+
+ MCONTACT hSubContact = Meta_GetMostOnline(cc);
+ return ProtoCallService(GetContactProto(hSubContact), PS_SEND_NUDGE, hSubContact, lParam);
}
/////////////////////////////////////////////////////////////////
@@ -277,29 +281,28 @@ INT_PTR Meta_SendMessage(WPARAM wParam,LPARAM lParam)
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
}
- MCONTACT most_online = Meta_GetMostOnline(ccs->hContact);
-
- if ( !most_online) {
- DWORD dwThreadId;
- HANDLE hEvent;
- TFakeAckParams *tfap;
+ DBCachedContact *cc = CheckMeta(ccs->hContact);
+ if (cc == NULL)
+ return 1;
+ MCONTACT most_online = Meta_GetMostOnline(cc);
+ if (!most_online) {
// send failure to notify user of reason
- hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- tfap = (TFakeAckParams *)mir_alloc(sizeof(TFakeAckParams));
+ TFakeAckParams *tfap = (TFakeAckParams *)mir_alloc(sizeof(TFakeAckParams));
tfap->hContact = ccs->hContact;
tfap->hEvent = hEvent;
tfap->id = 10;
strcpy(tfap->msg, Translate("No online contacts found."));
- CloseHandle( CreateThread( NULL, 0, sttFakeAckFail, tfap, 0, &dwThreadId ));
- SetEvent( hEvent );
-
+ DWORD dwThreadId;
+ CloseHandle(CreateThread(NULL, 0, sttFakeAckFail, tfap, 0, &dwThreadId));
+ SetEvent(hEvent);
return 10;
}
- Meta_CopyContactNick(ccs->hContact, most_online);
+ Meta_CopyContactNick(cc, most_online);
ccs->hContact = most_online;
proto = GetContactProto(most_online);
@@ -451,8 +454,12 @@ INT_PTR Meta_RecvMessage(WPARAM wParam, LPARAM lParam)
return 0;
if (options.use_proto_recv) {
+ DBCachedContact *cc = CheckMeta(wParam);
+ if (cc == NULL)
+ return 0;
+
// use the subcontact's protocol to add the db if possible (AIMOSCAR removes HTML here!)
- MCONTACT most_online = Meta_GetMostOnline(ccs->hContact);
+ MCONTACT most_online = Meta_GetMostOnline(cc);
if (char *subProto = GetContactProto(most_online))
if ( ProtoCallService(subProto, PSR_MESSAGE, wParam, lParam) != CALLSERVICE_NOTFOUND)
return 0;
@@ -488,23 +495,17 @@ information about the ACK.
int Meta_HandleACK(WPARAM wParam, LPARAM lParam)
{
ACKDATA *ack = (ACKDATA*) lParam;
- MCONTACT hUser;
-
- if (ack->hContact == 0 || (hUser = (MCONTACT)db_get_dw(ack->hContact, META_PROTO, "Handle",0)) == 0)
- return 0; // Can't find the MetaID, let through the protocol chain
+ DBCachedContact *cc = CheckMeta(ack->hContact);
+ if (cc == NULL)
+ return 0;
- if ( !strcmp(ack->szModule, META_PROTO)) {
+ if (!strcmp(ack->szModule, META_PROTO))
return 0; // don't rebroadcast our own acks
- }
// if it's for something we don't support, ignore
- if (ack->type != ACKTYPE_MESSAGE && ack->type != ACKTYPE_CHAT && ack->type != ACKTYPE_FILE && ack->type != ACKTYPE_AWAYMSG
- && ack->type != ACKTYPE_AVATAR && ack->type != ACKTYPE_GETINFO)
-
- {
+ if (ack->type != ACKTYPE_MESSAGE && ack->type != ACKTYPE_CHAT && ack->type != ACKTYPE_FILE && ack->type != ACKTYPE_AWAYMSG && ack->type != ACKTYPE_AVATAR && ack->type != ACKTYPE_GETINFO)
return 0;
- }
// change the hContact in the avatar info struct, if it's the avatar we're using - else drop it
if (ack->type == ACKTYPE_AVATAR) {
@@ -512,15 +513,14 @@ int Meta_HandleACK(WPARAM wParam, LPARAM lParam)
DBVARIANT dbv;
// change avatar if the most online supporting avatars changes, or if we don't have one
- MCONTACT most_online = Meta_GetMostOnlineSupporting(hUser, PFLAGNUM_4, PF4_AVATARS);
+ MCONTACT most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS);
//if (AI.hContact == 0 || AI.hContact != most_online) {
if (ack->hContact == 0 || ack->hContact != most_online) {
return 0;
}
- //if ( !db_get(AI.hContact, "ContactPhoto", "File", &dbv)) {
if ( !db_get(ack->hContact, "ContactPhoto", "File", &dbv)) {
- db_set_ts(hUser, "ContactPhoto", "File", dbv.ptszVal);
+ db_set_ts(cc->contactID, "ContactPhoto", "File", dbv.ptszVal);
db_free(&dbv);
}
@@ -528,15 +528,16 @@ int Meta_HandleACK(WPARAM wParam, LPARAM lParam)
PROTO_AVATAR_INFORMATIONT AI;
memcpy(&AI, (PROTO_AVATAR_INFORMATIONT *)ack->hProcess, sizeof(PROTO_AVATAR_INFORMATIONT));
if (AI.hContact)
- AI.hContact = hUser;
+ AI.hContact = cc->contactID;
- return ProtoBroadcastAck(META_PROTO, hUser,ack->type,ack->result, (HANDLE)&AI, ack->lParam);
- } else
- return ProtoBroadcastAck(META_PROTO, hUser,ack->type,ack->result, 0, ack->lParam);
+ return ProtoBroadcastAck(META_PROTO, cc->contactID, ack->type, ack->result, (HANDLE)&AI, ack->lParam);
+ }
+
+ return ProtoBroadcastAck(META_PROTO, cc->contactID, ack->type, ack->result, 0, ack->lParam);
}
}
- return ProtoBroadcastAck(META_PROTO, hUser,ack->type,ack->result,ack->hProcess,ack->lParam);
+ return ProtoBroadcastAck(META_PROTO, cc->contactID, ack->type, ack->result, ack->hProcess, ack->lParam);
}
// hiding contacts on "CList/UseGroups" setting changed can cause a crash - do it in a seperate thread during idle time
@@ -548,7 +549,7 @@ static DWORD sttHideContacts( BOOL param )
/** Call whenever a contact changes one of its settings (for example, the status)
**
-* @param wParam \c HANDLE to the contact that has change of its setting.
+* @param wParam HANDLE to the contact that has change of its setting.
* @param lParam Reference to a structure that contains the setting that has changed (not used)
*/
int Meta_SettingChanged(WPARAM wParam, LPARAM lParam)
@@ -556,7 +557,7 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam)
DBCONTACTWRITESETTING *dcws = (DBCONTACTWRITESETTING *)lParam;
char buffer[512], szId[40];
int contact_number;
- MCONTACT hMeta, most_online;
+ MCONTACT most_online;
// hide metacontacts when groups disabled
if (wParam == 0
@@ -571,170 +572,173 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam)
if (wParam == 0)
return 0;
- if ((hMeta = (MCONTACT)db_get_dw(wParam, META_PROTO, "Handle", 0)) != 0 && CallService(MS_DB_CONTACT_IS, (WPARAM)hMeta, 0)) // just to be safe
- {
- // This contact is attached to a MetaContact.
-
- contact_number = Meta_GetContactNumber(wParam);
- if (contact_number == -1) return 0; // exit - db corruption
+ DBCachedContact *cc = CheckMeta(wParam);
+ if (cc == NULL)
+ return 0;
- if (!strcmp(dcws->szSetting, "IP")) {
- if (dcws->value.type == DBVT_DWORD)
- db_set_dw(hMeta, META_PROTO, "IP", dcws->value.dVal);
- else
- db_unset(hMeta, META_PROTO, "IP");
- }
- else if (!strcmp(dcws->szSetting, "RealIP")) {
- if (dcws->value.type == DBVT_DWORD)
- db_set_dw(hMeta, META_PROTO, "RealIP", dcws->value.dVal);
- else
- db_unset(hMeta, META_PROTO, "RealIP");
+ // This contact is attached to a MetaContact.
+ contact_number = Meta_GetContactNumber(cc, wParam);
+ if (contact_number == -1)
+ return 0; // exit - db corruption
+ if (!strcmp(dcws->szSetting, "IP")) {
+ if (dcws->value.type == DBVT_DWORD)
+ db_set_dw(cc->contactID, META_PROTO, "IP", dcws->value.dVal);
+ else
+ db_unset(cc->contactID, META_PROTO, "IP");
+ }
+ else if (!strcmp(dcws->szSetting, "RealIP")) {
+ if (dcws->value.type == DBVT_DWORD)
+ db_set_dw(cc->contactID, META_PROTO, "RealIP", dcws->value.dVal);
+ else
+ db_unset(cc->contactID, META_PROTO, "RealIP");
+ }
+ else if (!strcmp(dcws->szSetting, "ListeningTo")) {
+ switch (dcws->value.type) {
+ case DBVT_ASCIIZ:
+ db_set_s(cc->contactID, META_PROTO, "ListeningTo", dcws->value.pszVal);
+ break;
+ case DBVT_UTF8:
+ db_set_utf(cc->contactID, META_PROTO, "ListeningTo", dcws->value.pszVal);
+ break;
+ case DBVT_WCHAR:
+ db_set_ws(cc->contactID, META_PROTO, "ListeningTo", dcws->value.pwszVal);
+ break;
+ case DBVT_DELETED:
+ db_unset(cc->contactID, META_PROTO, "ListeningTo");
+ break;
}
- else if (!strcmp(dcws->szSetting, "ListeningTo")) {
- switch (dcws->value.type) {
- case DBVT_ASCIIZ:
- db_set_s(hMeta, META_PROTO, "ListeningTo", dcws->value.pszVal);
- break;
- case DBVT_UTF8:
- db_set_utf(hMeta, META_PROTO, "ListeningTo", dcws->value.pszVal);
- break;
- case DBVT_WCHAR:
- db_set_ws(hMeta, META_PROTO, "ListeningTo", dcws->value.pwszVal);
- break;
- case DBVT_DELETED:
- db_unset(hMeta, META_PROTO, "ListeningTo");
- break;
- }
+ }
+ else if (!strcmp(dcws->szSetting, "Nick") && !dcws->value.type == DBVT_DELETED) {
+ // subcontact nick has changed - update metacontact
+ strcpy(buffer, "Nick");
+ strcat(buffer, _itoa(contact_number, szId, 10));
+ db_set(cc->contactID, META_PROTO, buffer, &dcws->value);
+
+ DBVARIANT dbv;
+ if (Mydb_get(wParam, "CList", "MyHandle", &dbv)) {
+ strcpy(buffer, "CListName");
+ strcat(buffer, _itoa(contact_number, szId, 10));
+ db_set(cc->contactID, META_PROTO, buffer, &dcws->value);
}
- else if (!strcmp(dcws->szSetting, "Nick") && !dcws->value.type == DBVT_DELETED) {
- // subcontact nick has changed - update metacontact
- strcpy(buffer, "Nick");
+ else db_free(&dbv);
+
+ // copy nick to metacontact, if it's the most online
+ MCONTACT most_online = Meta_GetMostOnline(cc);
+ Meta_CopyContactNick(cc, most_online);
+
+ return 0;
+ }
+ else if (!strcmp(dcws->szSetting, "IdleTS")) {
+ if (dcws->value.type == DBVT_DWORD)
+ db_set_dw(cc->contactID, META_PROTO, "IdleTS", dcws->value.dVal);
+ else if (dcws->value.type == DBVT_DELETED)
+ db_set_dw(cc->contactID, META_PROTO, "IdleTS", 0);
+ }
+ else if (!strcmp(dcws->szSetting, "LogonTS")) {
+ if (dcws->value.type == DBVT_DWORD)
+ db_set_dw(cc->contactID, META_PROTO, "LogonTS", dcws->value.dVal);
+ else if (dcws->value.type == DBVT_DELETED)
+ db_set_dw(cc->contactID, META_PROTO, "LogonTS", 0);
+ }
+ else if (!strcmp(dcws->szModule, "CList") && !strcmp(dcws->szSetting, "MyHandle")) {
+ if (dcws->value.type == DBVT_DELETED) {
+ char *proto = GetContactProto(wParam);
+ strcpy(buffer, "CListName");
strcat(buffer, _itoa(contact_number, szId, 10));
- db_set(hMeta, META_PROTO, buffer, &dcws->value);
DBVARIANT dbv;
- if (Mydb_get(wParam, "CList", "MyHandle", &dbv)) {
- strcpy(buffer, "CListName");
- strcat(buffer, _itoa(contact_number, szId, 10));
- db_set(hMeta, META_PROTO, buffer, &dcws->value);
+ if (proto && !Mydb_get(wParam, proto, "Nick", &dbv)) {
+ db_set(cc->contactID, META_PROTO, buffer, &dbv);
+ db_free(&dbv);
}
- else db_free(&dbv);
-
- // copy nick to metacontact, if it's the most online
- MCONTACT most_online = Meta_GetMostOnline(hMeta);
- Meta_CopyContactNick(hMeta, most_online);
-
- return 0;
+ else db_unset(cc->contactID, META_PROTO, buffer);
}
- else if (!strcmp(dcws->szSetting, "IdleTS")) {
- if (dcws->value.type == DBVT_DWORD)
- db_set_dw(hMeta, META_PROTO, "IdleTS", dcws->value.dVal);
- else if (dcws->value.type == DBVT_DELETED)
- db_set_dw(hMeta, META_PROTO, "IdleTS", 0);
- }
- else if (!strcmp(dcws->szSetting, "LogonTS")) {
- if (dcws->value.type == DBVT_DWORD)
- db_set_dw(hMeta, META_PROTO, "LogonTS", dcws->value.dVal);
- else if (dcws->value.type == DBVT_DELETED)
- db_set_dw(hMeta, META_PROTO, "LogonTS", 0);
+ else {
+ // subcontact clist displayname has changed - update metacontact
+ strcpy(buffer, "CListName");
+ strcat(buffer, _itoa(contact_number, szId, 10));
+ db_set(cc->contactID, META_PROTO, buffer, &dcws->value);
}
- else if (!strcmp(dcws->szModule, "CList") && !strcmp(dcws->szSetting, "MyHandle")) {
- if (dcws->value.type == DBVT_DELETED) {
- char *proto = GetContactProto(wParam);
- strcpy(buffer, "CListName");
- strcat(buffer, _itoa(contact_number, szId, 10));
-
- DBVARIANT dbv;
- if (proto && !Mydb_get(wParam, proto, "Nick", &dbv)) {
- db_set(hMeta, META_PROTO, buffer, &dbv);
- db_free(&dbv);
- }
- else db_unset(hMeta, META_PROTO, buffer);
- }
- else {
- // subcontact clist displayname has changed - update metacontact
- strcpy(buffer, "CListName");
- strcat(buffer, _itoa(contact_number, szId, 10));
- db_set(hMeta, META_PROTO, buffer, &dcws->value);
- }
- // copy nick to metacontact, if it's the most online
- MCONTACT most_online = Meta_GetMostOnline(hMeta);
- Meta_CopyContactNick(hMeta, most_online);
+ // copy nick to metacontact, if it's the most online
+ MCONTACT most_online = Meta_GetMostOnline(cc);
+ Meta_CopyContactNick(cc, most_online);
- return 0;
+ return 0;
+ }
+ else if (!strcmp(dcws->szSetting, "Status") && !dcws->value.type == DBVT_DELETED) {
+ // subcontact changing status
+
+ // update subcontact status setting
+ strcpy(buffer, "Status");
+ strcat(buffer, _itoa(contact_number, szId, 10));
+ db_set_w(cc->contactID, META_PROTO, buffer, dcws->value.wVal);
+
+ strcpy(buffer, "StatusString");
+ strcat(buffer, _itoa(contact_number, szId, 10));
+ db_set_ts(cc->contactID, META_PROTO, buffer, cli.pfnGetStatusModeDescription(dcws->value.wVal, 0));
+
+ // if the contact was forced, unforce it (which updates status)
+ if ((HANDLE)db_get_dw(cc->contactID, META_PROTO, "ForceSend", 0) == (HANDLE)wParam)
+ MetaAPI_UnforceSendContact((WPARAM)cc->contactID, 0);
+ else {
+ // set status to that of most online contact
+ most_online = Meta_GetMostOnline(cc);
+ Meta_CopyContactNick(cc, most_online);
+
+ Meta_FixStatus(cc);
+ Meta_CopyData(cc);
}
- else if (!strcmp(dcws->szSetting, "Status") && !dcws->value.type == DBVT_DELETED) {
- // subcontact changing status
- // update subcontact status setting
- strcpy(buffer, "Status");
- strcat(buffer, _itoa(contact_number, szId, 10));
- db_set_w(hMeta, META_PROTO, buffer, dcws->value.wVal);
+ // most online contact with avatar support might have changed - update avatar
+ most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS);
+ if (most_online) {
+ PROTO_AVATAR_INFORMATIONT AI;
- strcpy(buffer, "StatusString");
- strcat(buffer, _itoa(contact_number, szId, 10));
- db_set_ts(hMeta, META_PROTO, buffer, cli.pfnGetStatusModeDescription(dcws->value.wVal, 0));
-
- // if the contact was forced, unforce it (which updates status)
- if ((HANDLE)db_get_dw(hMeta, META_PROTO, "ForceSend", 0) == (HANDLE)wParam)
- MetaAPI_UnforceSendContact((WPARAM)hMeta, 0);
- else {
- // set status to that of most online contact
- most_online = Meta_GetMostOnline(hMeta);
- Meta_CopyContactNick(hMeta, most_online);
-
- Meta_FixStatus(hMeta);
- Meta_CopyData(hMeta);
- }
+ AI.cbSize = sizeof(AI);
+ AI.hContact = cc->contactID;
+ AI.format = PA_FORMAT_UNKNOWN;
+ _tcscpy(AI.filename, _T("X"));
- // most online contact with avatar support might have changed - update avatar
- most_online = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS);
- if (most_online) {
- PROTO_AVATAR_INFORMATIONT AI;
-
- AI.cbSize = sizeof(AI);
- AI.hContact = hMeta;
- AI.format = PA_FORMAT_UNKNOWN;
- _tcscpy(AI.filename, _T("X"));
-
- if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS)
- db_set_ts(hMeta, "ContactPhoto", "File", AI.filename);
- }
+ if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS)
+ db_set_ts(cc->contactID, "ContactPhoto", "File", AI.filename);
}
- else if (strcmp(dcws->szSetting, "XStatusId") == 0 || strcmp(dcws->szSetting, "XStatusMsg") == 0 || strcmp(dcws->szSetting, "XStatusName") == 0 || strcmp(dcws->szSetting, "StatusMsg") == 0) {
- Meta_CopyData(hMeta);
- }
- else if (strcmp(dcws->szSetting, "MirVer") == 0)
- Meta_CopyData(hMeta);
}
+ else if (strcmp(dcws->szSetting, "XStatusId") == 0 || strcmp(dcws->szSetting, "XStatusMsg") == 0 || strcmp(dcws->szSetting, "XStatusName") == 0 || strcmp(dcws->szSetting, "StatusMsg") == 0) {
+ Meta_CopyData(cc);
+ }
+ else if (strcmp(dcws->szSetting, "MirVer") == 0)
+ Meta_CopyData(cc);
return 0;
}
-int Meta_ContactDeleted(WPARAM wParam, LPARAM lParam)
+int Meta_ContactDeleted(WPARAM hContact, LPARAM lParam)
{
+ DBCachedContact *cc = CheckMeta(hContact);
+ if (cc == NULL)
+ return 0;
+
// is a subcontact - update meta contact
- MCONTACT hMeta = (MCONTACT)db_get_dw(wParam, META_PROTO, "Handle", 0);
+ MCONTACT hMeta = db_get_dw(hContact, META_PROTO, "Handle", 0);
if (hMeta) {
- Meta_RemoveContactNumber(hMeta, wParam);
+ Meta_RemoveContactNumber(hMeta, hContact);
NotifyEventHooks(hSubcontactsChanged, (WPARAM)hMeta, 0);
return 0;
}
// not a subcontact - is it a metacontact?
- int num_contacts = db_get_dw(wParam, META_PROTO, "NumContacts", 0);
+ int num_contacts = db_get_dw(hContact, META_PROTO, "NumContacts", 0);
if (num_contacts)
- NotifyEventHooks(hSubcontactsChanged, (WPARAM)wParam, 0);
+ NotifyEventHooks(hSubcontactsChanged, hContact, 0);
// remove & restore all subcontacts
for (int i = 0; i < num_contacts; i++) {
- MCONTACT hContact = Meta_GetContactHandle(wParam, i);
- if (hContact && (HANDLE)db_get_dw(hContact, META_PROTO, "Handle", 0) == (HANDLE)wParam) {
+ MCONTACT hContact = Meta_GetContactHandle(cc, i);
+ if (hContact && db_get_dw(hContact, META_PROTO, "Handle", 0) == hContact) {
db_unset(hContact, META_PROTO, META_LINK);
db_unset(hContact, META_PROTO, "Handle");
- Meta_RestoreGroup(hContact);
db_unset(hContact, META_PROTO, "OldCListGroup");
// stop ignoring, if we were
@@ -750,16 +754,15 @@ int Meta_ContactDeleted(WPARAM wParam, LPARAM lParam)
* @param wParam \c HANDLE to the contact that we are typing to
* @param lParam either PROTOTYPE_SELFTYPING_ON or PROTOTYPE_SELFTYPING_OFF
*/
-INT_PTR Meta_UserIsTyping(WPARAM wParam, LPARAM lParam)
+INT_PTR Meta_UserIsTyping(WPARAM hMeta, LPARAM lParam)
{
- // This is a simple contact, let through the stack of protocols
- if (db_get_dw(wParam, META_PROTO, META_ID, INVALID_CONTACT_ID) == INVALID_CONTACT_ID)
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc == NULL)
return 0;
// forward to sending protocol, if supported
-
- MCONTACT most_online = Meta_GetMostOnline(wParam);
- Meta_CopyContactNick(wParam, most_online);
+ MCONTACT most_online = Meta_GetMostOnline(cc);
+ Meta_CopyContactNick(cc, most_online);
if (!most_online)
return 0;
@@ -799,14 +802,17 @@ int Meta_ContactIsTyping(WPARAM wParam, LPARAM lParam)
*
*/
-int Meta_UserInfo(WPARAM wParam, LPARAM lParam)
+int Meta_UserInfo(WPARAM wParam, LPARAM hMeta)
{
- DWORD default_contact_number = db_get_dw(lParam, META_PROTO, "Default", INVALID_CONTACT_ID);
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc == NULL)
+ return 0;
+ DWORD default_contact_number = db_get_dw(hMeta, META_PROTO, "Default", INVALID_CONTACT_ID);
if (default_contact_number == -1) // not a meta contact
return 0;
- CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)Meta_GetContactHandle(lParam, default_contact_number), 0);
+ CallService(MS_USERINFO_SHOWDIALOG, Meta_GetContactHandle(cc, default_contact_number), 0);
return 1;
}
@@ -833,13 +839,17 @@ int Meta_MessageWindowEvent(WPARAM wParam, LPARAM lParam)
return 0;
}
-int Meta_ClistDoubleClicked(WPARAM wParam, LPARAM lParam)
+int Meta_ClistDoubleClicked(WPARAM hMeta, LPARAM lParam)
{
- if (db_get_dw(wParam, META_PROTO, "Default", (WORD)-1) == (WORD)-1)
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc == NULL)
+ return 0;
+
+ if (db_get_dw(hMeta, META_PROTO, "Default", (WORD)-1) == (WORD)-1)
return 0;
// -1 indicates no specific capability but respect 'ForceDefault'
- MCONTACT most_online = Meta_GetMostOnlineSupporting(wParam, PFLAGNUM_1, -1);
+ MCONTACT most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_1, -1);
if (!most_online)
return 0;
@@ -925,9 +935,13 @@ static VOID CALLBACK sttMenuThread(PVOID param)
DestroyMenu(hMenu);
}
-INT_PTR Meta_ContactMenuFunc(WPARAM wParam, LPARAM lParam)
+INT_PTR Meta_ContactMenuFunc(WPARAM hMeta, LPARAM lParam)
{
- MCONTACT hContact = Meta_GetContactHandle(wParam, (int)lParam);
+ DBCachedContact *cc = CheckMeta(hMeta);
+ if (cc == NULL)
+ return 0;
+
+ MCONTACT hContact = Meta_GetContactHandle(cc, (int)lParam);
if (options.menu_function == FT_MSG) {
// open message window if protocol supports message sending or chat, else simulate double click
@@ -940,9 +954,9 @@ INT_PTR Meta_ContactMenuFunc(WPARAM wParam, LPARAM lParam)
int caps = CallService(buffer, (WPARAM)PFLAGNUM_1, 0);
if ((caps & PF1_IMSEND) || (caps & PF1_CHAT) || (proto && strcmp(proto, "IRC") == 0)) {
// set default contact for sending/status and open message window
- db_set_dw(wParam, META_PROTO, "Default", (DWORD)(int)lParam);
- NotifyEventHooks(hEventDefaultChanged, wParam, (LPARAM)hContact);
- CallService(MS_MSG_SENDMESSAGE, wParam, 0);
+ db_set_dw(hMeta, META_PROTO, "Default", (DWORD)(int)lParam);
+ NotifyEventHooks(hEventDefaultChanged, hMeta, (LPARAM)hContact);
+ CallService(MS_MSG_SENDMESSAGE, hMeta, 0);
}
else // protocol does not support messaging - simulate double click
CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0);
@@ -966,8 +980,12 @@ INT_PTR Meta_FileSend(WPARAM wParam, LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA*)lParam;
char *proto = 0;
- DWORD default_contact_number;
+ DBCachedContact *cc = CheckMeta(ccs->hContact);
+ if (cc == NULL)
+ return 0;
+
+ DWORD default_contact_number;
if ((default_contact_number = db_get_dw(ccs->hContact, META_PROTO, "Default", INVALID_CONTACT_ID)) == INVALID_CONTACT_ID) {
// This is a simple contact
// (this should normally not happen, since linked contacts do not appear on the list.)
@@ -975,7 +993,7 @@ INT_PTR Meta_FileSend(WPARAM wParam, LPARAM lParam)
return 0;
}
else {
- MCONTACT most_online = Meta_GetMostOnlineSupporting(ccs->hContact, PFLAGNUM_1, PF1_FILESEND);
+ MCONTACT most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_1, PF1_FILESEND);
if (!most_online) {
//PUShowMessage("no most online for ft", SM_NOTIFY);
return 0;
@@ -992,15 +1010,19 @@ INT_PTR Meta_GetAwayMsg(WPARAM wParam, LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA*)lParam;
char *proto = 0;
- DWORD default_contact_number;
+ DBCachedContact *cc = CheckMeta(ccs->hContact);
+ if (cc == NULL)
+ return 0;
+
+ DWORD default_contact_number;
if ((default_contact_number = db_get_dw(ccs->hContact, META_PROTO, "Default", INVALID_CONTACT_ID)) == INVALID_CONTACT_ID) {
// This is a simple contact
// (this should normally not happen, since linked contacts do not appear on the list.)
return 0;
}
else {
- MCONTACT most_online = Meta_GetMostOnlineSupporting(ccs->hContact, PFLAGNUM_1, PF1_MODEMSGRECV);
+ MCONTACT most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_1, PF1_MODEMSGRECV);
if (!most_online)
return 0;
@@ -1028,8 +1050,11 @@ INT_PTR Meta_GetAvatarInfo(WPARAM wParam, LPARAM lParam)
return 0;
}
else {
- MCONTACT hMeta = AI->hContact;
- MCONTACT hSub = Meta_GetMostOnlineSupporting(AI->hContact, PFLAGNUM_4, PF4_AVATARS);
+ DBCachedContact *cc = CheckMeta(AI->hContact);
+ if (cc == NULL)
+ return GAIR_NOAVATAR;
+
+ MCONTACT hSub = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS);
if (!hSub)
return GAIR_NOAVATAR;
@@ -1039,7 +1064,7 @@ INT_PTR Meta_GetAvatarInfo(WPARAM wParam, LPARAM lParam)
AI->hContact = hSub;
INT_PTR result = ProtoCallService(proto, PS_GETAVATARINFOT, wParam, lParam);
- AI->hContact = hMeta;
+ AI->hContact = cc->contactID;
if (result != CALLSERVICE_NOTFOUND)
return result;
}
@@ -1052,11 +1077,15 @@ INT_PTR Meta_GetInfo(WPARAM wParam, LPARAM lParam)
// This is a simple contact
// (this should normally not happen, since linked contacts do not appear on the list.)
+ DBCachedContact *cc = CheckMeta(ccs->hContact);
+ if (cc == NULL)
+ return 0;
+
MCONTACT default_contact_number = db_get_dw(ccs->hContact, META_PROTO, "Default", INVALID_CONTACT_ID);
if (default_contact_number == INVALID_CONTACT_ID)
return 0;
- MCONTACT most_online = Meta_GetMostOnlineSupporting(ccs->hContact, PFLAGNUM_4, PF4_AVATARS);
+ MCONTACT most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS);
if (!most_online)
return 0;
@@ -1072,8 +1101,8 @@ INT_PTR Meta_GetInfo(WPARAM wParam, LPARAM lParam)
if (CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS)
db_set_ts(ccs->hContact, "ContactPhoto", "File", AI.filename);
- most_online = Meta_GetMostOnline(ccs->hContact);
- Meta_CopyContactNick(ccs->hContact, most_online);
+ most_online = Meta_GetMostOnline(cc);
+ Meta_CopyContactNick(cc, most_online);
if (!most_online)
return 0;
@@ -1087,16 +1116,20 @@ INT_PTR Meta_GetInfo(WPARAM wParam, LPARAM lParam)
int Meta_CallMostOnline(WPARAM hContact, LPARAM lParam)
{
- MCONTACT most_online_im = Meta_GetMostOnline(hContact);
+ DBCachedContact *cc = CheckMeta(hContact);
+ if (cc == NULL)
+ return 0;
+
+ MCONTACT most_online_im = Meta_GetMostOnline(cc);
// fix nick
- Meta_CopyContactNick(hContact, most_online_im);
+ Meta_CopyContactNick(cc, most_online_im);
// fix status
- Meta_FixStatus(hContact);
+ Meta_FixStatus(cc);
// copy all other data
- Meta_CopyData(hContact);
+ Meta_CopyData(cc);
return 0;
}
diff --git a/src/modules/metacontacts/meta_utils.cpp b/src/modules/metacontacts/meta_utils.cpp
index 87a4f5279d..07297afdc8 100644
--- a/src/modules/metacontacts/meta_utils.cpp
+++ b/src/modules/metacontacts/meta_utils.cpp
@@ -213,7 +213,11 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default)
WORD status;
MCONTACT most_online;
- if ((num_contacts = db_get_dw(dest, META_PROTO, "NumContacts",INVALID_CONTACT_ID))==-1) {
+ DBCachedContact *ccDest = CheckMeta(dest);
+ if (ccDest == NULL)
+ return FALSE;
+
+ if ((num_contacts = db_get_dw(dest, META_PROTO, "NumContacts", INVALID_CONTACT_ID)) == -1) {
MessageBox(0, TranslateT("Could not retreive MetaContact contact count"), TranslateT("Assignment error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
@@ -324,14 +328,14 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default)
}
// set nick to most online contact that can message
- most_online = Meta_GetMostOnline(dest);
- Meta_CopyContactNick(dest, most_online);
+ most_online = Meta_GetMostOnline(ccDest);
+ Meta_CopyContactNick(ccDest, most_online);
// set status to that of most online contact
- Meta_FixStatus(dest);
+ Meta_FixStatus(ccDest);
// if the new contact is the most online contact with avatar support, get avatar info
- most_online = Meta_GetMostOnlineSupporting(dest, PFLAGNUM_4, PF4_AVATARS);
+ most_online = Meta_GetMostOnlineSupporting(ccDest, PFLAGNUM_4, PF4_AVATARS);
if (most_online == src) {
PROTO_AVATAR_INFORMATIONT AI;
AI.cbSize = sizeof(AI);
@@ -343,9 +347,6 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default)
db_set_ts(dest, "ContactPhoto", "File",AI.filename);
}
- // Hide the contact
- Meta_SetGroup(src);
-
// !!!!!!!!!!!!!!!!!!!!!!!!!
// copyHistory(src, dest);
@@ -354,7 +355,7 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default)
CallService(MS_IGNORE_IGNORE, (WPARAM)src, (WPARAM)IGNOREEVENT_USERONLINE);
// copy other data
- Meta_CopyData(dest);
+ Meta_CopyData(ccDest);
NotifyEventHooks(hSubcontactsChanged, (WPARAM)dest, 0);
return TRUE;
@@ -364,9 +365,11 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default)
* Convenience method - get most online contact supporting messaging
*
*/
-MCONTACT Meta_GetMostOnline(MCONTACT hMeta) {
- return Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_1, PF1_IM);
+MCONTACT Meta_GetMostOnline(DBCachedContact *cc)
+{
+ return Meta_GetMostOnlineSupporting(cc, PFLAGNUM_1, PF1_IM);
}
+
/** Get the 'most online' contact for a meta contact (according to above order) which supports the specified
* protocol service, and copies nick from that contact
*
@@ -375,13 +378,17 @@ MCONTACT Meta_GetMostOnline(MCONTACT hMeta) {
* @return \c HANDLE to a contact
*/
-MCONTACT Meta_GetMostOnlineSupporting(MCONTACT hMeta, int pflagnum, unsigned long capability) {
+MCONTACT Meta_GetMostOnlineSupporting(DBCachedContact *cc, int pflagnum, unsigned long capability)
+{
+ if (cc == NULL)
+ return 0;
+
int most_online_status = ID_STATUS_OFFLINE;
MCONTACT hContact;
int i, default_contact_number, num_contacts;
// you can't get more online than having the default contact ONLINE - so check that first
- if ((default_contact_number = db_get_dw(hMeta, META_PROTO, "Default",INVALID_CONTACT_ID)) == INVALID_CONTACT_ID)
+ if ((default_contact_number = db_get_dw(cc->contactID, META_PROTO, "Default",INVALID_CONTACT_ID)) == INVALID_CONTACT_ID)
{
// This is a simple contact - return NULL to signify error.
// (this should normally not happen, since all meta contacts have a default contact)
@@ -389,26 +396,26 @@ MCONTACT Meta_GetMostOnlineSupporting(MCONTACT hMeta, int pflagnum, unsigned lon
}
// if the default is beyond the end of the list (eek!) return null
- if (default_contact_number >= (num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", 0)))
+ if (default_contact_number >= (num_contacts = db_get_dw(cc->contactID, META_PROTO, "NumContacts", 0)))
return NULL;
- MCONTACT most_online_contact = Meta_GetContactHandle(hMeta, default_contact_number);
+ MCONTACT most_online_contact = Meta_GetContactHandle(cc, default_contact_number);
char *szProto = GetContactProto(most_online_contact);
DWORD caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM;
// we are forced to do use default for sending - '-1' capability indicates no specific capability, but respect 'Force Default'
- if (szProto && db_get_b(hMeta, META_PROTO, "ForceDefault", 0) && capability != 0 && (capability == -1 || (caps & capability) == capability)) // capability is 0 when we're working out status
+ if (szProto && db_get_b(cc->contactID, META_PROTO, "ForceDefault", 0) && capability != 0 && (capability == -1 || (caps & capability) == capability)) // capability is 0 when we're working out status
return most_online_contact;
// a subcontact is being temporarily 'forced' to do sending
- if ((most_online_contact = (MCONTACT)db_get_dw(hMeta, META_PROTO, "ForceSend", 0))) {
+ if ((most_online_contact = db_get_dw(cc->contactID, META_PROTO, "ForceSend", 0))) {
caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM;
if (szProto && (caps & capability) == capability && capability != 0) // capability is 0 when we're working out status
return most_online_contact;
}
- most_online_contact = Meta_GetContactHandle(hMeta, default_contact_number);
+ most_online_contact = Meta_GetContactHandle(cc, default_contact_number);
szProto = GetContactProto(most_online_contact);
if (szProto && CallProtoService(szProto, PS_GETSTATUS, 0, 0) >= ID_STATUS_ONLINE) {
caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
@@ -431,7 +438,7 @@ MCONTACT Meta_GetMostOnlineSupporting(MCONTACT hMeta, int pflagnum, unsigned lon
if (i == default_contact_number) // already checked that (i.e. initial value of most_online_contact and most_online_status are those of the default contact)
continue;
- hContact = Meta_GetContactHandle(hMeta, i);
+ hContact = Meta_GetContactHandle(cc, i);
szProto = GetContactProto(hContact);
if ( !szProto || CallProtoService(szProto, PS_GETSTATUS, 0, 0) < ID_STATUS_ONLINE) // szProto offline or connecting
@@ -459,7 +466,7 @@ MCONTACT Meta_GetMostOnlineSupporting(MCONTACT hMeta, int pflagnum, unsigned lon
// no online contacts? if we're trying to message, use 'send offline' contact
if (most_online_status == ID_STATUS_OFFLINE && capability == PF1_IM) {
- MCONTACT hOffline = Meta_GetContactHandle(hMeta, db_get_dw(hMeta, META_PROTO, "OfflineSend", INVALID_CONTACT_ID));
+ MCONTACT hOffline = Meta_GetContactHandle(cc, db_get_dw(cc->contactID, META_PROTO, "OfflineSend", INVALID_CONTACT_ID));
if (hOffline)
most_online_contact = hOffline;
}
@@ -467,12 +474,23 @@ MCONTACT Meta_GetMostOnlineSupporting(MCONTACT hMeta, int pflagnum, unsigned lon
return most_online_contact;
}
-int Meta_GetContactNumber(MCONTACT hContact)
+DBCachedContact* CheckMeta(MCONTACT hMeta)
+{
+ DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMeta);
+ return (cc == NULL || cc->nSubs == -1) ? NULL : cc;
+}
+
+int Meta_GetContactNumber(DBCachedContact *cc, MCONTACT hContact)
{
- return hContact; // !!!!!!!!!!!!!!!!!!!!!!!!!
+ for (int i = 0; i < cc->nSubs; i++)
+ if (cc->pSubs[i] == hContact)
+ return i;
+
+ return -1;
}
-BOOL dbv_same(DBVARIANT *dbv1, DBVARIANT *dbv2) {
+BOOL dbv_same(DBVARIANT *dbv1, DBVARIANT *dbv2)
+{
if (dbv1->type != dbv2->type) return FALSE;
switch(dbv1->type) {
@@ -492,11 +510,11 @@ BOOL dbv_same(DBVARIANT *dbv1, DBVARIANT *dbv2) {
}
}
-void copy_settings_array(MCONTACT hMeta, char *module, const char *settings[], int num_settings)
+void copy_settings_array(DBCachedContact *ccMeta, char *module, const char *settings[], int num_settings)
{
- int num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", INVALID_CONTACT_ID),
- default_contact = db_get_dw(hMeta, META_PROTO, "Default", INVALID_CONTACT_ID),
- most_online = Meta_GetContactNumber(Meta_GetMostOnline(hMeta));
+ int num_contacts = db_get_dw(ccMeta->contactID, META_PROTO, "NumContacts", INVALID_CONTACT_ID),
+ default_contact = db_get_dw(ccMeta->contactID, META_PROTO, "Default", INVALID_CONTACT_ID),
+ most_online = Meta_GetContactNumber(ccMeta, Meta_GetMostOnline(ccMeta));
BOOL use_default = FALSE;
int source_contact = (use_default ? default_contact : most_online);
@@ -509,11 +527,11 @@ void copy_settings_array(MCONTACT hMeta, char *module, const char *settings[], i
// do source (most online) first
MCONTACT hContact;
if (j == 0)
- hContact = Meta_GetContactHandle(hMeta, source_contact);
+ hContact = Meta_GetContactHandle(ccMeta, source_contact);
else if (j <= source_contact)
- hContact = Meta_GetContactHandle(hMeta, j - 1);
+ hContact = Meta_GetContactHandle(ccMeta, j - 1);
else
- hContact = Meta_GetContactHandle(hMeta, j);
+ hContact = Meta_GetContactHandle(ccMeta, j);
if (hContact == 0)
continue;
@@ -527,24 +545,24 @@ void copy_settings_array(MCONTACT hMeta, char *module, const char *settings[], i
else used_mod = module;
if (j == 0 && strcmp(settings[i], "MirVer") == 0) //Always reset MirVer
- db_unset(hMeta, (module ? used_mod : META_PROTO), settings[i]);
+ db_unset(ccMeta->contactID, (module ? used_mod : META_PROTO), settings[i]);
DBVARIANT dbv1, dbv2;
BOOL bFree, got_val = !Mydb_get(hContact, used_mod, settings[i], &dbv2);
if (got_val) {
- bFree = !Mydb_get(hMeta, (module ? used_mod : META_PROTO), settings[i], &dbv1);
+ bFree = !Mydb_get(ccMeta->contactID, (module ? used_mod : META_PROTO), settings[i], &dbv1);
if (strcmp(settings[i], "MirVer") == 0) {
if (db_get_w(hContact, used_mod, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) {
if (!bFree || (dbv1.pszVal == NULL || strcmp(dbv1.pszVal, "") == 0 || strlen(dbv1.pszVal) < 2)) {
- db_set(hMeta, (module ? used_mod : META_PROTO), settings[i], &dbv2);
+ db_set(ccMeta->contactID, (module ? used_mod : META_PROTO), settings[i], &dbv2);
bDataWritten = TRUE; //only break if found something to copy
}
}
}
else {
if (!bFree || !dbv_same(&dbv1, &dbv2)) {
- db_set(hMeta, (module ? used_mod : META_PROTO), settings[i], &dbv2);
+ db_set(ccMeta->contactID, (module ? used_mod : META_PROTO), settings[i], &dbv2);
if (dbv2.type == DBVT_ASCIIZ || dbv2.type == DBVT_UTF8) {
if (dbv2.pszVal != NULL && strcmp(dbv2.pszVal, "") != 0)
bDataWritten = TRUE; //only break if found something to copy
@@ -594,42 +612,42 @@ const char *MBirthdaySettings[3] =
// szProto:
// clist: "StatusMsg"
-void CopyStatusData(MCONTACT hMeta)
+void CopyStatusData(DBCachedContact *ccMeta)
{
- int num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", INVALID_CONTACT_ID),
- most_online = Meta_GetContactNumber(Meta_GetMostOnline(hMeta));
- WORD status = db_get_w(hMeta, META_PROTO, "Status", ID_STATUS_OFFLINE);
+ int num_contacts = db_get_dw(ccMeta->contactID, META_PROTO, "NumContacts", INVALID_CONTACT_ID),
+ most_online = Meta_GetContactNumber(ccMeta, Meta_GetMostOnline(ccMeta));
+ WORD status = db_get_w(ccMeta->contactID, META_PROTO, "Status", ID_STATUS_OFFLINE);
MCONTACT hContact;
BOOL bDoneStatus = FALSE, bDoneXStatus = FALSE;
for (int i = 0; i < num_contacts; i++) {
if (i == 0)
- hContact = Meta_GetContactHandle(hMeta, most_online);
+ hContact = Meta_GetContactHandle(ccMeta, most_online);
else if (i <= most_online)
- hContact = Meta_GetContactHandle(hMeta, i - 1);
+ hContact = Meta_GetContactHandle(ccMeta, i - 1);
else
- hContact = Meta_GetContactHandle(hMeta, i);
+ hContact = Meta_GetContactHandle(ccMeta, i);
char *szProto = GetContactProto(hContact);
if (szProto && db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE) == status) {
DBVARIANT dbv;
if (!bDoneStatus && !Mydb_get(hContact, "CList", "StatusMsg", &dbv)) {
- db_set(hMeta, "CList", "StatusMsg", &dbv);
+ db_set(ccMeta->contactID, "CList", "StatusMsg", &dbv);
db_free(&dbv);
bDoneStatus = TRUE;
}
if ((!bDoneXStatus) && (!Mydb_get(hContact, szProto, "XStatusId", &dbv)) && dbv.type != DBVT_DELETED) {
- db_set_s(hMeta, META_PROTO, "XStatusProto", szProto);
- db_set(hMeta, META_PROTO, "XStatusId", &dbv);
+ db_set_s(ccMeta->contactID, META_PROTO, "XStatusProto", szProto);
+ db_set(ccMeta->contactID, META_PROTO, "XStatusId", &dbv);
db_free(&dbv);
if (!Mydb_get(hContact, szProto, "XStatusMsg", &dbv)) {
- db_set(hMeta, META_PROTO, "XStatusMsg", &dbv);
+ db_set(ccMeta->contactID, META_PROTO, "XStatusMsg", &dbv);
db_free(&dbv);
}
if (!Mydb_get(hContact, szProto, "XStatusName", &dbv)) {
- db_set(hMeta, META_PROTO, "XStatusName", &dbv);
+ db_set(ccMeta->contactID, META_PROTO, "XStatusName", &dbv);
db_free(&dbv);
}
bDoneXStatus = TRUE;
@@ -640,40 +658,37 @@ void CopyStatusData(MCONTACT hMeta)
break;
}
- if (!bDoneStatus) db_unset(hMeta, "CList", "StatusMsg");
+ if (!bDoneStatus)
+ db_unset(ccMeta->contactID, "CList", "StatusMsg");
+
if (!bDoneXStatus) {
- db_unset(hMeta, META_PROTO, "XStatusId");
- db_unset(hMeta, META_PROTO, "XStatusMsg");
- db_unset(hMeta, META_PROTO, "XStatusName");
+ db_unset(ccMeta->contactID, META_PROTO, "XStatusId");
+ db_unset(ccMeta->contactID, META_PROTO, "XStatusMsg");
+ db_unset(ccMeta->contactID, META_PROTO, "XStatusName");
}
}
-void Meta_CopyData(MCONTACT hMeta)
+void Meta_CopyData(DBCachedContact *cc)
{
- if (!options.copydata)
+ if (!options.copydata || cc == NULL)
return;
- CopyStatusData(hMeta);
+ CopyStatusData(cc);
- copy_settings_array(hMeta, 0, ProtoSettings, 25);
- copy_settings_array(hMeta, "mBirthday", UserInfoSettings, 3);
- copy_settings_array(hMeta, "ContactPhoto", ContactPhotoSettings, 5);
+ copy_settings_array(cc, 0, ProtoSettings, 25);
+ copy_settings_array(cc, "mBirthday", UserInfoSettings, 3);
+ copy_settings_array(cc, "ContactPhoto", ContactPhotoSettings, 5);
if (options.copy_userinfo)
- copy_settings_array(hMeta, "UserInfo", UserInfoSettings, 71);
+ copy_settings_array(cc, "UserInfo", UserInfoSettings, 71);
}
-MCONTACT Meta_GetContactHandle(MCONTACT hMeta, int contact_number)
+MCONTACT Meta_GetContactHandle(DBCachedContact *cc, int contact_number)
{
- char buffer[512], buffer2[512];
- int num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", 0);
-
- if (contact_number >= num_contacts || contact_number < 0)
+ if (contact_number >= cc->nSubs || contact_number < 0)
return 0;
-
- strcpy(buffer, "Handle");
- strcat(buffer, _itoa(contact_number, buffer2, 10));
- return (MCONTACT)db_get_dw(hMeta, META_PROTO, buffer, 0);
+
+ return cc->pSubs[contact_number];
}
/** Hide all contacts linked to any meta contact, and set handle links
@@ -705,9 +720,6 @@ int Meta_HideLinkedContacts(void)
// prepare to update metacontact record of subcontat status
char *szProto = GetContactProto(hContact);
- // save old group and move to invisible group (i.e. non-existent group)
- Meta_SetGroup(hContact);
-
// find metacontact
for (MCONTACT hContact2 = db_find_first(); hContact2; hContact2 = db_find_next(hContact2)) {
if (db_get_dw(hContact2, META_PROTO, META_ID, INVALID_CONTACT_ID) != meta_id)
@@ -758,13 +770,13 @@ int Meta_HideLinkedContacts(void)
// do metacontacts after handles set properly above
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (db_get_dw(hContact, META_PROTO, META_ID, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
- // is a meta contact
- MCONTACT hMostOnline = Meta_GetMostOnline(hContact); // set nick
- Meta_CopyContactNick(hContact, hMostOnline);
+ DBCachedContact *cc = CheckMeta(hContact);
+ if (cc == NULL)
+ continue;
- Meta_FixStatus(hContact);
- }
+ MCONTACT hMostOnline = Meta_GetMostOnline(cc); // set nick
+ Meta_CopyContactNick(cc, hMostOnline);
+ Meta_FixStatus(cc);
}
return 0;
@@ -775,22 +787,16 @@ int Meta_HideLinkedContacts(void)
*/
int Meta_UnhideLinkedContacts(void)
{
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (db_get_dw(hContact, META_PROTO, META_LINK, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
- // has a link - unhide it
- // restore old group
- Meta_RestoreGroup(hContact);
- }
- }
-
return 0;
}
int Meta_HideMetaContacts(int hide)
{
// set status suppression
- if (hide) Meta_SuppressStatus(FALSE);
- else Meta_SuppressStatus(options.suppress_status);
+ if (hide)
+ Meta_SuppressStatus(FALSE);
+ else
+ Meta_SuppressStatus(options.suppress_status);
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
if (db_get_dw(hContact, META_PROTO, META_ID, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
@@ -800,26 +806,11 @@ int Meta_HideMetaContacts(int hide)
else
db_unset(hContact, "CList", "Hidden");
}
- else if (db_get_dw(hContact, META_PROTO, META_LINK, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
- // when metacontacts are hidden, show subcontacts, and vice versa
- if (hide)
- Meta_RestoreGroup(hContact);
- else
- Meta_SetGroup(hContact);
- }
}
return 0;
}
-void Meta_RestoreGroup(MCONTACT hContact)
-{
-}
-
-void Meta_SetGroup(MCONTACT hContact)
-{
-}
-
int Meta_SuppressStatus(BOOL suppress)
{
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
@@ -835,13 +826,13 @@ int Meta_SuppressStatus(BOOL suppress)
return 0;
}
-int Meta_CopyContactNick(MCONTACT hMeta, MCONTACT hContact)
+int Meta_CopyContactNick(DBCachedContact *ccMeta, MCONTACT hContact)
{
DBVARIANT dbv, dbv_proto;
char *szProto;
if (options.lockHandle) {
- hContact = Meta_GetContactHandle(hMeta, 0);
+ hContact = Meta_GetContactHandle(ccMeta, 0);
}
if (!hContact) return 1;
@@ -853,7 +844,7 @@ int Meta_CopyContactNick(MCONTACT hMeta, MCONTACT hContact)
szProto = dbv_proto.pszVal;
if (options.clist_contact_name == CNNT_NICK && szProto) {
if (!Mydb_get(hContact, szProto, "Nick", &dbv)) {
- db_set(hMeta, META_PROTO, "Nick", &dbv);
+ db_set(ccMeta->contactID, META_PROTO, "Nick", &dbv);
db_free(&dbv);
//CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)hMeta, 0);
//CallService(MS_CLUI_CONTACTRENAMED, (WPARAM)hMeta, 0);
@@ -864,7 +855,7 @@ int Meta_CopyContactNick(MCONTACT hMeta, MCONTACT hContact)
else if (options.clist_contact_name == CNNT_DISPLAYNAME) {
TCHAR *name = cli.pfnGetContactDisplayName(hContact, GCDNF_TCHAR);
if (name && _tcscmp(name, TranslateT("(Unknown Contact)")) != 0) {
- db_set_ts(hMeta, META_PROTO, "Nick", name);
+ db_set_ts(ccMeta->contactID, META_PROTO, "Nick", name);
db_free(&dbv_proto);
return 0;
}
@@ -877,31 +868,22 @@ int Meta_CopyContactNick(MCONTACT hMeta, MCONTACT hContact)
int Meta_SetAllNicks()
{
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (db_get_dw(hContact, META_PROTO, META_ID, INVALID_CONTACT_ID) != INVALID_CONTACT_ID) {
- MCONTACT most_online = Meta_GetMostOnline(hContact);
- Meta_CopyContactNick(hContact, most_online);
- Meta_FixStatus(hContact);
- Meta_CopyData(hContact);
- }
-
+ DBCachedContact *cc = CheckMeta(hContact);
+ if (cc == NULL)
+ continue;
+ MCONTACT most_online = Meta_GetMostOnline(cc);
+ Meta_CopyContactNick(cc, most_online);
+ Meta_FixStatus(cc);
+ Meta_CopyData(cc);
}
return 0;
}
-int Meta_IsHiddenGroup(const char *group_name)
-{
- if (group_name && !strcmp(group_name, META_HIDDEN_GROUP))
- return 1;
-
- return 0;
-}
-
-int Meta_SwapContacts(MCONTACT hMeta, DWORD contact_number1, DWORD contact_number2)
+int Meta_SwapContacts(DBCachedContact *cc, DWORD contact_number1, DWORD contact_number2)
{
DBVARIANT dbv1, dbv2;
- MCONTACT hContact1 = Meta_GetContactHandle(hMeta, contact_number1),
- hContact2 = Meta_GetContactHandle(hMeta, contact_number2);
+ MCONTACT hContact1 = Meta_GetContactHandle(cc, contact_number1), hContact2 = Meta_GetContactHandle(cc, contact_number2);
char buff1[512], buff12[512], buff2[512], buff22[512];
BOOL ok1, ok2;
@@ -910,14 +892,14 @@ int Meta_SwapContacts(MCONTACT hMeta, DWORD contact_number1, DWORD contact_numbe
strcat(buff1, _itoa(contact_number1, buff12, 10));
strcpy(buff2, "Protocol");
strcat(buff2, _itoa(contact_number2, buff22, 10));
- ok1 = !Mydb_get(hMeta, META_PROTO, buff1, &dbv1);
- ok2 = !Mydb_get(hMeta, META_PROTO, buff2, &dbv2);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff1, &dbv1);
+ ok2 = !Mydb_get(cc->contactID, META_PROTO, buff2, &dbv2);
if (ok1) {
- db_set(hMeta, META_PROTO, buff2, &dbv1);
+ db_set(cc->contactID, META_PROTO, buff2, &dbv1);
db_free(&dbv1);
}
if (ok2) {
- db_set(hMeta, META_PROTO, buff1, &dbv2);
+ db_set(cc->contactID, META_PROTO, buff1, &dbv2);
db_free(&dbv2);
}
@@ -926,14 +908,14 @@ int Meta_SwapContacts(MCONTACT hMeta, DWORD contact_number1, DWORD contact_numbe
strcat(buff1, _itoa(contact_number1, buff12, 10));
strcpy(buff2, "Status");
strcat(buff2, _itoa(contact_number2, buff22, 10));
- ok1 = !Mydb_get(hMeta, META_PROTO, buff1, &dbv1);
- ok1 = !Mydb_get(hMeta, META_PROTO, buff2, &dbv2);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff1, &dbv1);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff2, &dbv2);
if (ok1) {
- db_set(hMeta, META_PROTO, buff2, &dbv1);
+ db_set(cc->contactID, META_PROTO, buff2, &dbv1);
db_free(&dbv1);
}
if (ok2) {
- db_set(hMeta, META_PROTO, buff1, &dbv2);
+ db_set(cc->contactID, META_PROTO, buff1, &dbv2);
db_free(&dbv2);
}
@@ -942,14 +924,14 @@ int Meta_SwapContacts(MCONTACT hMeta, DWORD contact_number1, DWORD contact_numbe
strcat(buff1, _itoa(contact_number1, buff12, 10));
strcpy(buff2, "StatusString");
strcat(buff2, _itoa(contact_number2, buff22, 10));
- ok1 = !Mydb_get(hMeta, META_PROTO, buff1, &dbv1);
- ok2 = !Mydb_get(hMeta, META_PROTO, buff2, &dbv2);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff1, &dbv1);
+ ok2 = !Mydb_get(cc->contactID, META_PROTO, buff2, &dbv2);
if (ok1) {
- db_set(hMeta, META_PROTO, buff2, &dbv1);
+ db_set(cc->contactID, META_PROTO, buff2, &dbv1);
db_free(&dbv1);
}
if (ok2) {
- db_set(hMeta, META_PROTO, buff1, &dbv2);
+ db_set(cc->contactID, META_PROTO, buff1, &dbv2);
db_free(&dbv2);
}
@@ -958,16 +940,16 @@ int Meta_SwapContacts(MCONTACT hMeta, DWORD contact_number1, DWORD contact_numbe
strcat(buff1, _itoa(contact_number1, buff12, 10));
strcpy(buff2, "Login");
strcat(buff2, _itoa(contact_number2, buff22, 10));
- ok1 = !Mydb_get(hMeta, META_PROTO, buff1, &dbv1);
- ok2 = !Mydb_get(hMeta, META_PROTO, buff2, &dbv2);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff1, &dbv1);
+ ok2 = !Mydb_get(cc->contactID, META_PROTO, buff2, &dbv2);
if (ok1) {
- db_unset(hMeta, META_PROTO, buff2);
- db_set(hMeta, META_PROTO, buff2, &dbv1);
+ db_unset(cc->contactID, META_PROTO, buff2);
+ db_set(cc->contactID, META_PROTO, buff2, &dbv1);
db_free(&dbv1);
}
if (ok2) {
- db_unset(hMeta, META_PROTO, buff1);
- db_set(hMeta, META_PROTO, buff1, &dbv2);
+ db_unset(cc->contactID, META_PROTO, buff1);
+ db_set(cc->contactID, META_PROTO, buff1, &dbv2);
db_free(&dbv2);
}
@@ -976,61 +958,58 @@ int Meta_SwapContacts(MCONTACT hMeta, DWORD contact_number1, DWORD contact_numbe
strcat(buff1, _itoa(contact_number1, buff12, 10));
strcpy(buff2, "Nick");
strcat(buff2, _itoa(contact_number2, buff22, 10));
- ok1 = !Mydb_get(hMeta, META_PROTO, buff1, &dbv1);
- ok2 = !Mydb_get(hMeta, META_PROTO, buff2, &dbv2);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff1, &dbv1);
+ ok2 = !Mydb_get(cc->contactID, META_PROTO, buff2, &dbv2);
if (ok1) {
- db_set(hMeta, META_PROTO, buff2, &dbv1);
+ db_set(cc->contactID, META_PROTO, buff2, &dbv1);
db_free(&dbv1);
}
- else db_unset(hMeta, META_PROTO, buff2);
+ else db_unset(cc->contactID, META_PROTO, buff2);
if (ok2) {
- db_set(hMeta, META_PROTO, buff1, &dbv2);
+ db_set(cc->contactID, META_PROTO, buff1, &dbv2);
db_free(&dbv2);
}
- else db_unset(hMeta, META_PROTO, buff1);
+ else db_unset(cc->contactID, META_PROTO, buff1);
// swap the clist name
strcpy(buff1, "CListName");
strcat(buff1, _itoa(contact_number1, buff12, 10));
strcpy(buff2, "CListName");
strcat(buff2, _itoa(contact_number2, buff22, 10));
- ok1 = !Mydb_get(hMeta, META_PROTO, buff1, &dbv1);
- ok2 = !Mydb_get(hMeta, META_PROTO, buff2, &dbv2);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff1, &dbv1);
+ ok2 = !Mydb_get(cc->contactID, META_PROTO, buff2, &dbv2);
if (ok1) {
- db_set(hMeta, META_PROTO, buff2, &dbv1);
+ db_set(cc->contactID, META_PROTO, buff2, &dbv1);
db_free(&dbv1);
}
- else db_unset(hMeta, META_PROTO, buff2);
+ else db_unset(cc->contactID, META_PROTO, buff2);
if (ok2) {
- db_set(hMeta, META_PROTO, buff1, &dbv2);
+ db_set(cc->contactID, META_PROTO, buff1, &dbv2);
db_free(&dbv2);
}
- else db_unset(hMeta, META_PROTO, buff1);
+ else db_unset(cc->contactID, META_PROTO, buff1);
// swap the handle
strcpy(buff1, "Handle");
strcat(buff1, _itoa(contact_number1, buff12, 10));
strcpy(buff2, "Handle");
strcat(buff2, _itoa(contact_number2, buff22, 10));
- ok1 = !Mydb_get(hMeta, META_PROTO, buff1, &dbv1);
- ok2 = !Mydb_get(hMeta, META_PROTO, buff2, &dbv2);
+ ok1 = !Mydb_get(cc->contactID, META_PROTO, buff1, &dbv1);
+ ok2 = !Mydb_get(cc->contactID, META_PROTO, buff2, &dbv2);
if (ok1) {
- db_set(hMeta, META_PROTO, buff2, &dbv1);
+ db_set(cc->contactID, META_PROTO, buff2, &dbv1);
db_free(&dbv1);
}
- else db_unset(hMeta, META_PROTO, buff2);
+ else db_unset(cc->contactID, META_PROTO, buff2);
if (ok2) {
- db_set(hMeta, META_PROTO, buff1, &dbv2);
+ db_set(cc->contactID, META_PROTO, buff1, &dbv2);
db_free(&dbv2);
}
- else db_unset(hMeta, META_PROTO, buff1);
+ else db_unset(cc->contactID, META_PROTO, buff1);
- // finally, inform the contacts of their change in position
- db_set_dw(hContact1, META_PROTO, "ContactNumber", (DWORD)contact_number2);
- db_set_dw(hContact2, META_PROTO, "ContactNumber", (DWORD)contact_number1);
return 0;
}
@@ -1048,18 +1027,18 @@ INT_PTR CALLBACK DlgProcNull(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
return FALSE;
}
-void Meta_FixStatus(MCONTACT hMeta)
+void Meta_FixStatus(DBCachedContact *cc)
{
- MCONTACT most_online = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_1, 0);
+ MCONTACT most_online = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_1, 0);
if (most_online) {
char *szProto = GetContactProto(most_online);
if (szProto) {
- WORD status = (WORD)db_get_w(most_online, szProto, "Status", (WORD)ID_STATUS_OFFLINE);
- db_set_w(hMeta, META_PROTO, "Status", status);
+ WORD status = db_get_w(most_online, szProto, "Status", ID_STATUS_OFFLINE);
+ db_set_w(cc->contactID, META_PROTO, "Status", status);
}
- else db_set_w(hMeta, META_PROTO, "Status", (WORD)ID_STATUS_OFFLINE);
+ else db_set_w(cc->contactID, META_PROTO, "Status", ID_STATUS_OFFLINE);
}
- else db_set_w(hMeta, META_PROTO, "Status", (WORD)ID_STATUS_OFFLINE);
+ else db_set_w(cc->contactID, META_PROTO, "Status", ID_STATUS_OFFLINE);
}
INT_PTR Meta_IsEnabled()
diff --git a/src/modules/metacontacts/metacontacts.h b/src/modules/metacontacts/metacontacts.h
index a4d876aa35..bf314ca577 100644
--- a/src/modules/metacontacts/metacontacts.h
+++ b/src/modules/metacontacts/metacontacts.h
@@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define META_FILTER_ID "MetaFilterID"
#define META_LINK "MetaLink"
-#define META_HIDDEN_GROUP "MetaContacts Hidden Group"
#define MAX_CONTACTS 20
// I can't think of a way around this - mental block
@@ -51,34 +50,32 @@ INT_PTR Meta_OnOff(WPARAM wParam, LPARAM lParam);
int Meta_EqualDBV(DBVARIANT *dbv, DBVARIANT *id);
int Meta_ModifyMenu(WPARAM wParam,LPARAM lParam);
BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default);
-MCONTACT Meta_GetHandle(const char *protocol, DBVARIANT *id);
int Meta_SetNick(char *proto);
-MCONTACT Meta_GetMostOnline(MCONTACT hMeta);
-MCONTACT Meta_GetMostOnlineSupporting(MCONTACT hMeta, int pflagnum, unsigned long capability);
int Meta_HideLinkedContacts(void);
int Meta_UnhideLinkedContacts(void);
-int Meta_GetContactNumber(MCONTACT hContact);
-MCONTACT Meta_GetContactHandle(MCONTACT hMeta, int contact_number);
-void Meta_RestoreGroup(MCONTACT hContact);
-void Meta_SetGroup(MCONTACT hContact);
+int Meta_GetContactNumber(DBCachedContact *cc, MCONTACT hContact);
int Meta_HideMetaContacts(int hide);
int Meta_SuppressStatus(int suppress);
-int Meta_CopyContactNick(MCONTACT hMeta, MCONTACT hContact);
-void Meta_CopyData(MCONTACT hMeta);
+int Meta_CopyContactNick(DBCachedContact *cc, MCONTACT hContact);
+void Meta_CopyData(DBCachedContact *cc);
int Meta_SetAllNicks();
-int Meta_IsHiddenGroup(const char *group_name);
-int Meta_SwapContacts(MCONTACT hMeta, DWORD contact_number1, DWORD contact_number2);
+int Meta_SwapContacts(DBCachedContact *cc, DWORD contact_number1, DWORD contact_number2);
+
+MCONTACT Meta_GetHandle(const char *protocol, DBVARIANT *id);
+MCONTACT Meta_GetMostOnline(DBCachedContact *cc);
+MCONTACT Meta_GetMostOnlineSupporting(DBCachedContact *cc, int pflagnum, unsigned long capability);
+MCONTACT Meta_GetContactHandle(DBCachedContact *cc, int contact_number);
+
+DBCachedContact* CheckMeta(MCONTACT hMeta);
+
// function to copy history from one contact to another - courtesy JdGordon with mods (thx)
-void copyHistory(MCONTACT hContactFrom, MCONTACT hContactTo);
-// inverse
-//void Meta_RemoveHistory(HANDLE hContactRemoveFrom, HANDLE hContactSource);
-void Meta_FixStatus(MCONTACT hMeta);
+void Meta_FixStatus(DBCachedContact *cc);
char *Meta_GetUniqueIdentifier(MCONTACT hContact, DWORD *pused);
INT_PTR Meta_GetCaps(WPARAM wParam,LPARAM lParam);
INT_PTR Meta_GetName(WPARAM wParam,LPARAM lParam);
-INT_PTR Meta_LoadIcon(WPARAM wParam,LPARAM lParam);
+INT_PTR Meta_LoadIcon(WPARAM wParam,LPARAM lParam);
INT_PTR Meta_SetStatus(WPARAM wParam,LPARAM lParam);
INT_PTR Meta_GetStatus(WPARAM wParam,LPARAM lParam);
INT_PTR Meta_SendMessage(WPARAM wParam,LPARAM lParam);