summaryrefslogtreecommitdiff
path: root/src/modules/metacontacts/meta_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/metacontacts/meta_utils.cpp')
-rw-r--r--src/modules/metacontacts/meta_utils.cpp313
1 files changed, 146 insertions, 167 deletions
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()