diff options
author | George Hazan <george.hazan@gmail.com> | 2014-02-25 21:19:01 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-02-25 21:19:01 +0000 |
commit | 831890a8024a9519cdf725c5a098898734e54e93 (patch) | |
tree | 2a124d40ecb90fd74b331230ce966dee374719c5 | |
parent | d84c40216b5e60224eb365f633b5f142d459fc9e (diff) |
metacontacts in the database cache
git-svn-id: http://svn.miranda-ng.org/main/trunk@8276 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | include/m_db_int.h | 6 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbcontacts.cpp | 13 | ||||
-rw-r--r-- | src/modules/database/mdatabasecache.cpp | 28 |
3 files changed, 34 insertions, 13 deletions
diff --git a/include/m_db_int.h b/include/m_db_int.h index f3affcb1c5..9733d0ddf5 100644 --- a/include/m_db_int.h +++ b/include/m_db_int.h @@ -50,6 +50,12 @@ struct DBCachedContact DWORD dwDriverData;
char *szProto;
DBCachedContactValue *first, *last;
+
+ // metacontacts
+ int nSubs; // == -1 -> not a metacontact at all
+ MCONTACT *pSubs;
+ MCONTACT parentID, // == 0 -> not a subcontact
+ activeID; // manually chosen active sub
};
interface MIDatabaseCache : public MZeroedObject
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index 576b19a4f8..09bb9a3e91 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -245,6 +245,19 @@ void CDb3Mmap::FillContacts() DBCachedContact *cc = m_cache->AddContactToCache(dwContactID);
cc->dwDriverData = dwOffset;
CheckProto(cc, "");
+
+ DBVARIANT dbv; dbv.type = DBVT_DWORD;
+ cc->nSubs = (0 != GetContactSetting(dwContactID, "MetaContacts", "NumContacts", &dbv)) ? -1 : dbv.dVal;
+ if (cc->nSubs != -1) {
+ cc->pSubs = (MCONTACT*)malloc(cc->nSubs*sizeof(MCONTACT));
+ for (int i = 0; i < cc->nSubs; i++) {
+ char setting[100];
+ mir_snprintf(setting, sizeof(setting), "Handle%d", i);
+ cc->pSubs[i] = (0 != GetContactSetting(dwContactID, "MetaContacts", setting, &dbv)) ? INVALID_CONTACT_ID : dbv.dVal;
+ }
+ }
+ cc->activeID = (0 != GetContactSetting(dwContactID, "MetaContacts", "Default", &dbv)) ? INVALID_CONTACT_ID : dbv.dVal;
+ cc->parentID = (0 != GetContactSetting(dwContactID, "MetaContacts", "Handle", &dbv)) ? INVALID_CONTACT_ID : dbv.dVal;
dwOffset = p->ofsNext;
}
diff --git a/src/modules/database/mdatabasecache.cpp b/src/modules/database/mdatabasecache.cpp index 1dcd29861e..2a2812515d 100644 --- a/src/modules/database/mdatabasecache.cpp +++ b/src/modules/database/mdatabasecache.cpp @@ -24,12 +24,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\..\core\commonheaders.h"
#include "database.h"
-static int stringCompare(const char* p1, const char* p2)
+static int stringCompare(const char *p1, const char *p2)
{
return strcmp(p1, p2);
}
-static int compareGlobals(const DBCachedGlobalValue* p1, const DBCachedGlobalValue* p2)
+static int compareGlobals(const DBCachedGlobalValue *p1, const DBCachedGlobalValue *p2)
{
return strcmp(p1->name, p2->name);
}
@@ -56,14 +56,14 @@ DBCachedContact* MDatabaseCache::AddContactToCache(MCONTACT contactID) mir_cslock lck(m_cs);
int index = m_lContacts.getIndex((DBCachedContact*)&contactID);
- if (index == -1) {
- DBCachedContact* VL = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContact));
- VL->contactID = contactID;
- m_lContacts.insert(VL);
- return VL;
- }
-
- return m_lContacts[index];
+ if (index != -1)
+ return m_lContacts[index];
+
+ DBCachedContact *cc = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContact));
+ cc->contactID = contactID;
+ cc->nSubs = -1;
+ m_lContacts.insert(cc);
+ return cc;
}
DBCachedContact* MDatabaseCache::GetCachedContact(MCONTACT contactID)
@@ -96,15 +96,17 @@ void MDatabaseCache::FreeCachedContact(MCONTACT contactID) if (index == -1)
return;
- DBCachedContact* VL = m_lContacts[index];
- DBCachedContactValue* V = VL->first;
+ DBCachedContact *cc = m_lContacts[index];
+ DBCachedContactValue* V = cc->first;
while (V != NULL) {
DBCachedContactValue* V1 = V->next;
FreeCachedVariant(&V->value);
HeapFree(m_hCacheHeap, 0, V);
V = V1;
}
- HeapFree(m_hCacheHeap, 0, VL);
+
+ free(cc->pSubs);
+ HeapFree(m_hCacheHeap, 0, cc);
m_lContacts.remove(index);
}
|