From f2a05888a258cf7a9cc1ea0b000641215839ac76 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 3 Mar 2014 20:32:43 +0000 Subject: metacontact creation fix git-svn-id: http://svn.miranda-ng.org/main/trunk@8391 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/metacontacts/meta_menu.cpp | 5 +++++ src/modules/metacontacts/meta_utils.cpp | 20 ++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src/modules') diff --git a/src/modules/metacontacts/meta_menu.cpp b/src/modules/metacontacts/meta_menu.cpp index 79500d7325..217d7b1895 100644 --- a/src/modules/metacontacts/meta_menu.cpp +++ b/src/modules/metacontacts/meta_menu.cpp @@ -60,7 +60,12 @@ INT_PTR Meta_Convert(WPARAM wParam, LPARAM lParam) // Create a new metacontact MCONTACT hMetaContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (hMetaContact) { + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMetaContact); + if (cc == NULL) + return 0; + db_set_dw(hMetaContact, META_PROTO, "NumContacts", 0); + cc->nSubs = 0; // Add the MetaContact protocol to the new meta contact CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hMetaContact, (LPARAM)META_PROTO); diff --git a/src/modules/metacontacts/meta_utils.cpp b/src/modules/metacontacts/meta_utils.cpp index f4f47cae94..6bd8690232 100644 --- a/src/modules/metacontacts/meta_utils.cpp +++ b/src/modules/metacontacts/meta_utils.cpp @@ -209,7 +209,6 @@ int Meta_SetNick(char *szProto) BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default) { - DWORD num_contacts; char buffer[512], szId[40]; WORD status; MCONTACT most_online; @@ -218,11 +217,6 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default) 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; - } - char *szProto = GetContactProto(src); if (szProto == NULL) { MessageBox(0, TranslateT("Could not retreive contact protocol"), TranslateT("Assignment error"), MB_OK | MB_ICONWARNING); @@ -244,8 +238,8 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default) return FALSE; } - num_contacts++; - if (num_contacts >= MAX_CONTACTS) { + ccDest->nSubs++; + if (ccDest->nSubs >= MAX_CONTACTS) { MessageBox(0, TranslateT("MetaContact is full"), TranslateT("Assignment error"), MB_OK | MB_ICONWARNING); db_free(&dbv); return FALSE; @@ -253,7 +247,7 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default) // write the contact's protocol strcpy(buffer, "Protocol"); - strcat(buffer, _itoa(num_contacts - 1, szId, 10)); + strcat(buffer, _itoa(ccDest->nSubs - 1, szId, 10)); if (db_set_s(dest, META_PROTO, buffer, szProto)) { MessageBox(0, TranslateT("Could not write contact protocol to MetaContact"), TranslateT("Assignment error"), MB_OK | MB_ICONWARNING); @@ -305,7 +299,7 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default) // write the handle strcpy(buffer, "Handle"); strcat(buffer, szId); - db_set_dw(dest, META_PROTO, buffer, (DWORD)src); + db_set_dw(dest, META_PROTO, buffer, src); // write status string strcpy(buffer, "StatusString"); @@ -319,10 +313,12 @@ BOOL Meta_Assign(MCONTACT src, MCONTACT dest, BOOL set_as_default) db_set_b(src, META_PROTO, "IsSubcontact", true); // update count of contacts - db_set_dw(dest, META_PROTO, "NumContacts", num_contacts); + db_set_dw(dest, META_PROTO, "NumContacts", ccDest->nSubs); + ccDest->pSubs = (MCONTACT*)mir_realloc(ccDest->pSubs, sizeof(MCONTACT)*ccDest->nSubs); + ccDest->pSubs[ccDest->nSubs - 1] = src; if (set_as_default) { - ccDest->nDefault = num_contacts - 1; + ccDest->nDefault = ccDest->nSubs - 1; currDb->MetaSetDefault(ccDest); NotifyEventHooks(hEventDefaultChanged, (WPARAM)dest, (LPARAM)src); } -- cgit v1.2.3