summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-04-10 08:55:29 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-04-10 08:55:29 +0000
commit548bb3a6a8ed6f0dbc9b88693e513597a3d0141a (patch)
tree192c9e2dcff4ed16cbbada96524f2237ce41dcb9
parentc298f440904a5506cd9413b767075fe47381e63c (diff)
dbx_tree merged with the cache management code
git-svn-id: http://svn.miranda-ng.org/main/trunk@4408 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/Dbx_tree/src/Compatibility.cpp55
-rw-r--r--plugins/Dbx_tree/src/DataBase.h2
2 files changed, 53 insertions, 4 deletions
diff --git a/plugins/Dbx_tree/src/Compatibility.cpp b/plugins/Dbx_tree/src/Compatibility.cpp
index 95836bb5d5..a7d4934f39 100644
--- a/plugins/Dbx_tree/src/Compatibility.cpp
+++ b/plugins/Dbx_tree/src/Compatibility.cpp
@@ -40,6 +40,29 @@ HANDLE hEventDeletedEvent,
hContactDeletedEvent,
hContactAddedEvent;
+int CDataBase::CheckProto(HANDLE hContact, const char *proto)
+{
+ DBCachedContact *cc = m_cache->GetCachedContact(hContact);
+ if (cc == NULL)
+ cc = m_cache->AddContactToCache(hContact);
+
+ if (cc->szProto == NULL) {
+ char protobuf[MAX_PATH] = {0};
+ DBVARIANT dbv;
+ DBCONTACTGETSETTING sVal = { "Protocol", "p", &dbv };
+
+ dbv.type = DBVT_ASCIIZ;
+ dbv.pszVal = protobuf;
+ dbv.cchVal = sizeof(protobuf);
+ if ( GetContactSettingStatic(hContact, &sVal) != 0 || (dbv.type != DBVT_ASCIIZ))
+ return 0;
+
+ cc->szProto = m_cache->GetCachedSetting(NULL, protobuf, 0, (int)strlen(protobuf));
+ }
+
+ return !strcmp(cc->szProto, proto);
+}
+
STDMETHODIMP_(HANDLE) CDataBase::AddContact(void)
{
TDBTEntity entity = {0,0,0,0};
@@ -62,6 +85,9 @@ STDMETHODIMP_(LONG) CDataBase::DeleteContact(HANDLE hContact)
if (res == DBT_INVALIDPARAM)
return 1;
+ if (res == 0)
+ m_cache->FreeCachedContact(hContact);
+
return res;
}
@@ -97,16 +123,37 @@ STDMETHODIMP_(LONG) CDataBase::GetContactCount(void)
return c;
}
-//!!!!!!!!!!!!!!!!!!!! szProto ignored
STDMETHODIMP_(HANDLE) CDataBase::FindFirstContact(const char* szProto)
{
- return (HANDLE)getEntities().compFirstContact();
+ HANDLE hContact = (HANDLE)getEntities().compFirstContact();
+ if (!szProto || CheckProto(hContact, szProto))
+ return hContact;
+
+ return FindNextContact(hContact, szProto);
}
-//!!!!!!!!!!!!!!!!!!!! szProto ignored
STDMETHODIMP_(HANDLE) CDataBase::FindNextContact(HANDLE hContact, const char* szProto)
{
- return (HANDLE)getEntities().compNextContact((WPARAM)hContact);
+ while (hContact) {
+ DBCachedContact *VL = m_cache->GetCachedContact(hContact);
+ if (VL == NULL)
+ VL = m_cache->AddContactToCache(hContact);
+
+ if (VL->hNext != NULL) {
+ if (!szProto || CheckProto(VL->hNext, szProto))
+ return VL->hNext;
+
+ hContact = VL->hNext;
+ continue;
+ }
+
+ VL->hNext = (HANDLE)getEntities().compNextContact((WPARAM)hContact);
+ if (VL->hNext != NULL && (!szProto || CheckProto(VL->hNext, szProto)))
+ return VL->hNext;
+
+ hContact = VL->hNext;
+ }
+ return NULL;
}
STDMETHODIMP_(BOOL) CDataBase::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs)
diff --git a/plugins/Dbx_tree/src/DataBase.h b/plugins/Dbx_tree/src/DataBase.h
index cf0832877e..25de54551b 100644
--- a/plugins/Dbx_tree/src/DataBase.h
+++ b/plugins/Dbx_tree/src/DataBase.h
@@ -230,4 +230,6 @@ protected: // to be compatible with the standard Miranda databases
STDMETHODIMP_(BOOL) EnumContactSettings(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces);
STDMETHODIMP_(BOOL) SetSettingResident(BOOL bIsResident, const char *pszSettingName);
STDMETHODIMP_(BOOL) EnumResidentSettings(DBMODULEENUMPROC pFunc, void *pParam);
+
+ int CheckProto(HANDLE hContact, const char *proto);
};