From ac13aa1584ca595da727308406c87ec1bd9f5a21 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 8 Jul 2014 12:14:56 +0000 Subject: FavContacts: - broken group functionality restored; - metacontacts support (patch by bio); - built-in http server wiped out; - optimized memory usage; - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@9730 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/FavContacts/src/favlist.h | 85 ++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'plugins/FavContacts/src/favlist.h') diff --git a/plugins/FavContacts/src/favlist.h b/plugins/FavContacts/src/favlist.h index b420f49c23..4aeeed62e8 100644 --- a/plugins/FavContacts/src/favlist.h +++ b/plugins/FavContacts/src/favlist.h @@ -12,26 +12,19 @@ private: float fRate; public: - TContactInfo(MCONTACT hContact, bool bManual, float fRate = 0) + TContactInfo(MCONTACT _hContact, bool _bManual, float _fRate = 0) : + hContact(_hContact), + bManual(_bManual), + fRate(_fRate) { - DBVARIANT dbv = {0}; + name = mir_tstrdup(pcli->pfnGetContactDisplayName(hContact, 0)); - this->hContact = hContact; - this->bManual = bManual; - this->fRate = fRate; - name = mir_tstrdup((TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR)); - if (g_Options.bUseGroups && !db_get_ts(hContact, "CList", "Group", &dbv)) - { - group = mir_tstrdup(dbv.ptszVal); - db_free(&dbv); - } else - if (g_Options.bUseGroups) - { - group = mir_tstrdup(TranslateT("")); - } else - { - group = mir_tstrdup(TranslateT("Favorite Contacts")); + if (g_Options.bUseGroups) { + if ((group = db_get_tsa(hContact, "CList", "Group")) == NULL) + group = mir_tstrdup(TranslateT("")); } + else group = mir_tstrdup(TranslateT("Favorite Contacts")); + status = db_get_w(hContact, GetContactProto(hContact), "Status", ID_STATUS_OFFLINE); } @@ -64,30 +57,45 @@ public: int res = 0; if (res = lstrcmp(p1->group, p2->group)) return res; - //if (p1->status < p2->status) return -1; - //if (p1->status < p2->status) return +1; if (res = lstrcmp(p1->name, p2->name)) return res; return 0; } }; -class TFavContacts: public LIST +class TFavContacts : public LIST < TContactInfo > { private: int nGroups; + TCHAR *prevGroup; + + void addContact(MIDatabase *db, MCONTACT hContact, bool bManual) + { + DBCachedContact *cc = db->m_cache->GetCachedContact(hContact); + if (cc == NULL) + return; + + if (db_mc_isEnabled()) { + if (cc->IsSub()) // skip subcontacts if MC is enabled + return; + } + else if (cc->IsMeta()) // skip metacontacts if MC is not enabled + return; + + TCHAR *group = addContact(hContact, bManual)->getGroup(); + if (prevGroup && lstrcmp(prevGroup, group)) + ++nGroups; + prevGroup = group; + } public: - TFavContacts(): LIST(5, TContactInfo::cmp) {} + TFavContacts() : LIST(5, TContactInfo::cmp) {} ~TFavContacts() { for (int i = 0; i < this->getCount(); ++i) delete (*this)[i]; } - int groupCount() - { - return nGroups; - } + __forceinline int groupCount() const { return nGroups; } TContactInfo *addContact(MCONTACT hContact, bool bManual) { @@ -98,31 +106,24 @@ public: void build() { - TCHAR *prevGroup = NULL; - + prevGroup = NULL; + MIDatabase *db = GetCurrentDatabase(); + nGroups = 1; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (db_get_b(hContact, "FavContacts", "IsFavourite", 0)) - { - TCHAR *group = addContact(hContact, true)->getGroup(); - if (prevGroup && lstrcmp(prevGroup, group)) - ++nGroups; - prevGroup = group; - } + addContact(db, hContact, true); int nRecent = 0; for (int i = 0; nRecent < g_Options.wMaxRecent; ++i) { MCONTACT hContact = g_contactCache->get(i); - if (!hContact) break; - if (!db_get_b(hContact, "FavContacts", "IsFavourite", 0)) - { - TCHAR *group = addContact(hContact, false)->getGroup(); - if (prevGroup && lstrcmp(prevGroup, group)) - ++nGroups; - prevGroup = group; - - ++nRecent; + if (!hContact) + break; + + if (!db_get_b(hContact, "FavContacts", "IsFavourite", 0)) { + addContact(db, hContact, false); + nRecent++; } } } -- cgit v1.2.3