diff options
author | George Hazan <george.hazan@gmail.com> | 2016-04-27 13:14:43 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-04-27 13:14:43 +0000 |
commit | fb5f50bc10318b32d3d99480874813a05551d740 (patch) | |
tree | 0a15ed6ba91db7a3ceeaf01767bf2ef7e34c41dd /src | |
parent | 6524ac4e637dba2de42df5ca6eac4a9a5501a4d2 (diff) |
persistent cache, no need to call pfnGetCacheEntry each time
git-svn-id: http://svn.miranda-ng.org/main/trunk@16774 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/clcitems.cpp | 99 | ||||
-rw-r--r-- | src/mir_app/src/clistmod.cpp | 4 | ||||
-rw-r--r-- | src/mir_app/src/clistsettings.cpp | 19 | ||||
-rw-r--r-- | src/mir_app/src/extraicons.cpp | 4 | ||||
-rw-r--r-- | src/mir_app/src/skinicons.cpp | 5 |
5 files changed, 69 insertions, 62 deletions
diff --git a/src/mir_app/src/clcitems.cpp b/src/mir_app/src/clcitems.cpp index 7a3c203e8b..acb04a8f5f 100644 --- a/src/mir_app/src/clcitems.cpp +++ b/src/mir_app/src/clcitems.cpp @@ -185,39 +185,39 @@ int fnAddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact) index = i; } - i = cli.pfnAddItemToGroup(group, index + 1); char *szProto = GetContactProto(hContact); - group->cl.items[i]->type = CLCIT_CONTACT; - group->cl.items[i]->iImage = cli.pfnGetContactIcon(hContact); - group->cl.items[i]->hContact = hContact; - group->cl.items[i]->proto = szProto; + + ClcCacheEntry *pce = cli.pfnGetCacheEntry(hContact); + replaceStrT(pce->tszGroup, NULL); + + i = cli.pfnAddItemToGroup(group, index + 1); + + ClcContact *cc = group->cl.items[i]; + cc->type = CLCIT_CONTACT; + cc->iImage = cli.pfnGetContactIcon(hContact); + cc->hContact = hContact; + cc->proto = szProto; + cc->pce = pce; if (szProto != NULL && !cli.pfnIsHiddenMode(dat, db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE))) - group->cl.items[i]->flags |= CONTACTF_ONLINE; + cc->flags |= CONTACTF_ONLINE; WORD apparentMode = szProto != NULL ? db_get_w(hContact, szProto, "ApparentMode", 0) : 0; if (apparentMode == ID_STATUS_OFFLINE) - group->cl.items[i]->flags |= CONTACTF_INVISTO; + cc->flags |= CONTACTF_INVISTO; else if (apparentMode == ID_STATUS_ONLINE) - group->cl.items[i]->flags |= CONTACTF_VISTO; + cc->flags |= CONTACTF_VISTO; else if (apparentMode) - group->cl.items[i]->flags |= CONTACTF_VISTO | CONTACTF_INVISTO; + cc->flags |= CONTACTF_VISTO | CONTACTF_INVISTO; if (db_get_b(hContact, "CList", "NotOnList", 0)) - group->cl.items[i]->flags |= CONTACTF_NOTONLIST; + cc->flags |= CONTACTF_NOTONLIST; DWORD idleMode = szProto != NULL ? db_get_dw(hContact, szProto, "IdleTS", 0) : 0; if (idleMode) - group->cl.items[i]->flags |= CONTACTF_IDLE; - mir_tstrncpy(group->cl.items[i]->szText, cli.pfnGetContactDisplayName(hContact, 0), _countof(group->cl.items[i]->szText)); - - ClcCacheEntry *p = cli.pfnGetCacheEntry(hContact); - if (p != NULL) - replaceStrT(p->tszGroup, NULL); - + cc->flags |= CONTACTF_IDLE; + mir_tstrncpy(cc->szText, cli.pfnGetContactDisplayName(hContact, 0), _countof(cc->szText)); return i; } void fnAddContactToTree(HWND hwnd, struct ClcData *dat, MCONTACT hContact, int updateTotalCount, int checkHideOffline) { - ClcGroup *group; - DBVARIANT dbv; DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); WORD status = ID_STATUS_OFFLINE; char *szProto = GetContactProto(hContact); @@ -229,49 +229,46 @@ void fnAddContactToTree(HWND hwnd, struct ClcData *dat, MCONTACT hContact, int u if (szProto != NULL) status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); - if (db_get_ts(hContact, "CList", "Group", &dbv)) + int i; + DWORD groupFlags; + ClcGroup *group; + ptrT tszGroup(db_get_tsa(hContact, "CList", "Group")); + if (tszGroup == NULL) group = &dat->list; else { - group = cli.pfnAddGroup(hwnd, dat, dbv.ptszVal, (DWORD) - 1, 0, 0); + group = cli.pfnAddGroup(hwnd, dat, tszGroup, (DWORD)-1, 0, 0); if (group == NULL) { - int i; - DWORD groupFlags; - TCHAR *szGroupName; - if (!(style & CLS_HIDEEMPTYGROUPS)) { - mir_free(dbv.ptszVal); + if (!(style & CLS_HIDEEMPTYGROUPS)) return; - } + if (checkHideOffline && cli.pfnIsHiddenMode(dat, status)) { for (i = 1;; i++) { - szGroupName = Clist_GroupGetName(i, &groupFlags); - if (szGroupName == NULL) { - mir_free(dbv.ptszVal); + TCHAR *szGroupName = Clist_GroupGetName(i, &groupFlags); + if (szGroupName == NULL) return; - } - if (!mir_tstrcmp(szGroupName, dbv.ptszVal)) + + if (!mir_tstrcmp(szGroupName, tszGroup)) break; } - if (groupFlags & GROUPF_HIDEOFFLINE) { - mir_free(dbv.ptszVal); + if (groupFlags & GROUPF_HIDEOFFLINE) return; - } } for (i = 1;; i++) { - szGroupName = Clist_GroupGetName(i, &groupFlags); - if (szGroupName == NULL) { - mir_free(dbv.ptszVal); + TCHAR *szGroupName = Clist_GroupGetName(i, &groupFlags); + if (szGroupName == NULL) return; - } - if (!mir_tstrcmp(szGroupName, dbv.ptszVal)) + + if (!mir_tstrcmp(szGroupName, tszGroup)) break; + size_t len = mir_tstrlen(szGroupName); - if (!_tcsncmp(szGroupName, dbv.ptszVal, len) && dbv.ptszVal[len] == '\\') + if (!_tcsncmp(szGroupName, tszGroup, len) && tszGroup[len] == '\\') cli.pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 1); } - group = cli.pfnAddGroup(hwnd, dat, dbv.ptszVal, groupFlags, i, 1); + group = cli.pfnAddGroup(hwnd, dat, tszGroup, groupFlags, i, 1); } - mir_free(dbv.ptszVal); } + if (checkHideOffline) { if (cli.pfnIsHiddenMode(dat, status) && (style & CLS_HIDEOFFLINE || group->hideOffline)) { if (updateTotalCount) @@ -286,17 +283,15 @@ void fnAddContactToTree(HWND hwnd, struct ClcData *dat, MCONTACT hContact, int u ClcGroup* fnRemoveItemFromGroup(HWND hwnd, ClcGroup *group, ClcContact *contact, int updateTotalCount) { - int iContact; - if ((iContact = List_IndexOf((SortedList*)&group->cl, contact)) == -1) + int iContact = List_IndexOf((SortedList*)&group->cl, contact); + if (iContact == -1) return group; if (contact->type == CLCIT_CONTACT) { if (updateTotalCount) group->totalMembers--; - ClcCacheEntry *p = cli.pfnGetCacheEntry(contact->hContact); - if (p != NULL) - replaceStrT(p->tszGroup, NULL); + cli.pfnInvalidateDisplayNameCacheEntry(contact->hContact); } cli.pfnFreeContact(group->cl.items[iContact]); @@ -332,9 +327,11 @@ void fnDeleteItemFromTree(HWND hwnd, MCONTACT hItem) for (i=0;; i++) { if (group->scanIndex == group->cl.count) break; - if (group->cl.items[i]->type == CLCIT_GROUP) { - size_t len = mir_tstrlen(group->cl.items[i]->szText); - if (!_tcsncmp(group->cl.items[i]->szText, dbv.ptszVal + nameOffset, len) && + + ClcContact *cc = group->cl.items[i]; + if (cc->type == CLCIT_GROUP) { + size_t len = mir_tstrlen(cc->szText); + if (!_tcsncmp(cc->szText, dbv.ptszVal + nameOffset, len) && (dbv.ptszVal[nameOffset + len] == '\\' || dbv.ptszVal[nameOffset + len] == '\0')) { group->totalMembers--; if (dbv.ptszVal[nameOffset + len] == '\0') diff --git a/src/mir_app/src/clistmod.cpp b/src/mir_app/src/clistmod.cpp index 9ea47517ce..60b6023cb3 100644 --- a/src/mir_app/src/clistmod.cpp +++ b/src/mir_app/src/clistmod.cpp @@ -30,7 +30,8 @@ int InitCListEvents(void); void UninitCListEvents(void);
void UninitGroupServices(void);
int ContactSettingChanged(WPARAM wParam, LPARAM lParam);
-int ContactAdded(WPARAM wParam, LPARAM lParam);
+int ContactAdded(WPARAM hContact, LPARAM);
+int ContactDeleted(WPARAM hContact, LPARAM);
INT_PTR GetContactDisplayName(WPARAM wParam, LPARAM lParam);
INT_PTR InvalidateDisplayName(WPARAM wParam, LPARAM lParam);
int InitGroupServices(void);
@@ -421,6 +422,7 @@ int LoadContactListModule2(void) HookEvent(ME_PROTO_ACCLISTCHANGED, ContactListAccountsChanged);
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, ContactSettingChanged);
HookEvent(ME_DB_CONTACT_ADDED, ContactAdded);
+ HookEvent(ME_DB_CONTACT_DELETED, ContactDeleted);
HookEvent(ME_PROTO_ACK, ProtocolAck);
hContactDoubleClicked = CreateHookableEvent(ME_CLIST_DOUBLECLICKED);
diff --git a/src/mir_app/src/clistsettings.cpp b/src/mir_app/src/clistsettings.cpp index 55aa9ec808..b74bd28139 100644 --- a/src/mir_app/src/clistsettings.cpp +++ b/src/mir_app/src/clistsettings.cpp @@ -119,7 +119,7 @@ TCHAR* fnGetContactDisplayName(MCONTACT hContact, int mode) if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
if (ci.type == CNFT_ASCIIZ) {
if (cacheEntry != NULL)
- cacheEntry->tszName = ci.pszVal;
+ replaceStrT(cacheEntry->tszName, ci.pszVal);
return ci.pszVal;
}
@@ -127,7 +127,7 @@ TCHAR* fnGetContactDisplayName(MCONTACT hContact, int mode) TCHAR *buffer = (TCHAR*)mir_alloc(15 * sizeof(TCHAR));
_ltot(ci.dVal, buffer, 10);
if (cacheEntry != NULL)
- cacheEntry->tszName = buffer;
+ replaceStrT(cacheEntry->tszName, buffer);
return buffer;
}
}
@@ -137,9 +137,20 @@ TCHAR* fnGetContactDisplayName(MCONTACT hContact, int mode) return (cacheEntry == NULL) ? mir_tstrdup(buffer) : buffer;
}
-int ContactAdded(WPARAM wParam, LPARAM)
+int ContactAdded(WPARAM hContact, LPARAM)
{
- cli.pfnChangeContactIcon(wParam, cli.pfnIconFromStatusMode(GetContactProto(wParam), ID_STATUS_OFFLINE, NULL));
+ cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(GetContactProto(hContact), ID_STATUS_OFFLINE, NULL));
+ return 0;
+}
+
+int ContactDeleted(WPARAM hContact, LPARAM)
+{
+ int idx = clistCache.getIndex((ClcCacheEntry*)&hContact);
+ if (idx != -1) {
+ cli.pfnFreeCacheItem(clistCache[idx]);
+ mir_free(clistCache[idx]);
+ clistCache.remove(idx);
+ }
return 0;
}
diff --git a/src/mir_app/src/extraicons.cpp b/src/mir_app/src/extraicons.cpp index f6ef9ac916..bdaa2d746f 100644 --- a/src/mir_app/src/extraicons.cpp +++ b/src/mir_app/src/extraicons.cpp @@ -319,10 +319,6 @@ void fnSetAllExtraIcons(MCONTACT hContact) hContact = db_find_first();
for (; hContact; hContact = db_find_next(hContact)) {
- ClcCacheEntry* pdnce = (ClcCacheEntry*)cli.pfnGetCacheEntry(hContact);
- if (pdnce == NULL)
- continue;
-
NotifyEventHooks(hEventExtraImageApplying, hContact, 0);
if (hcontgiven)
break;
diff --git a/src/mir_app/src/skinicons.cpp b/src/mir_app/src/skinicons.cpp index a6db6c3a7c..360e1742d5 100644 --- a/src/mir_app/src/skinicons.cpp +++ b/src/mir_app/src/skinicons.cpp @@ -226,7 +226,7 @@ MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) INT_PTR caps2;
if (szProto == NULL)
caps2 = -1;
- else if ((caps2 = CallProtoServiceInt(NULL,szProto, PS_GETCAPS, PFLAGNUM_2, 0)) == CALLSERVICE_NOTFOUND)
+ else if ((caps2 = CallProtoServiceInt(NULL, szProto, PS_GETCAPS, PFLAGNUM_2, 0)) == CALLSERVICE_NOTFOUND)
caps2 = 0;
if (IsStatusConnecting(status)) {
@@ -306,7 +306,7 @@ MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) else
lowidx = 0, highidx = _countof(statusIcons);
- for (int i = lowidx; i < highidx; i++)
+ for (int i = lowidx; i < highidx; i++) {
if (caps2 == 0 || (caps2 & statusIcons[i].pf2)) {
// format: core_%s%d
mir_snprintf(iconName, "%s%s%d", statusIconsFmt, szProto, i);
@@ -315,6 +315,7 @@ MIR_APP_DLL(HICON) Skin_LoadProtoIcon(const char *szProto, int status, bool big) sid.iDefaultIndex = statusIcons[i].resource_id;
IcoLib_AddIcon(&sid, 0);
}
+ }
}
// format: core_status_%s%d
|