diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2012-05-17 17:37:22 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2012-05-17 17:37:22 +0000 |
commit | 78d71d2cad6f243c6ff31d41380b8c5b58407de5 (patch) | |
tree | d0c05983b315352c5e66d23420da4b8fd8b5aff4 /plugins/FavContacts/src/favlist.h | |
parent | a9e8daee448c229aa3f8ded0c5f5c0fe7aa42529 (diff) |
added some plugins
git-svn-id: http://svn.miranda-ng.org/main/trunk@20 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/FavContacts/src/favlist.h')
-rw-r--r-- | plugins/FavContacts/src/favlist.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/plugins/FavContacts/src/favlist.h b/plugins/FavContacts/src/favlist.h new file mode 100644 index 0000000000..6201126b44 --- /dev/null +++ b/plugins/FavContacts/src/favlist.h @@ -0,0 +1,134 @@ +#ifndef favlist_h__
+#define favlist_h__
+
+struct TContactInfo
+{
+private:
+ HANDLE hContact;
+ DWORD status;
+ TCHAR *name;
+ TCHAR *group;
+ bool bManual;
+ float fRate;
+
+public:
+ TContactInfo(HANDLE hContact, bool bManual, float fRate = 0)
+ {
+ DBVARIANT dbv = {0};
+
+ this->hContact = hContact;
+ this->bManual = bManual;
+ this->fRate = fRate;
+ name = mir_tstrdup((TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR));
+ if (g_Options.bUseGroups && !DBGetContactSettingTString(hContact, "CList", "Group", &dbv))
+ {
+ group = mir_tstrdup(dbv.ptszVal);
+ DBFreeVariant(&dbv);
+ } else
+ if (g_Options.bUseGroups)
+ {
+ group = mir_tstrdup(TranslateT("<no group>"));
+ } else
+ {
+ group = mir_tstrdup(TranslateT("Favourite Contacts"));
+ }
+ status = DBGetContactSettingWord(hContact, (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0), "Status", ID_STATUS_OFFLINE);
+ }
+
+ ~TContactInfo()
+ {
+ mir_free(name);
+ mir_free(group);
+ }
+
+ HANDLE getHandle() const
+ {
+ return hContact;
+ }
+
+ TCHAR *getGroup() const
+ {
+ return group;
+ }
+
+ static int cmp(const TContactInfo *p1, const TContactInfo *p2)
+ {
+ if (p1->bManual && !p2->bManual) return -1;
+ if (!p1->bManual && p2->bManual) return 1;
+
+ if (!p1->bManual)
+ {
+ if (p1->fRate > p2->fRate) return -1;
+ if (p1->fRate < p2->fRate) return 1;
+ }
+
+ 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<TContactInfo>
+{
+private:
+ int nGroups;
+
+public:
+ TFavContacts(): LIST<TContactInfo>(5, TContactInfo::cmp) {}
+ ~TFavContacts()
+ {
+ for (int i = 0; i < this->getCount(); ++i)
+ delete (*this)[i];
+ }
+
+ int groupCount()
+ {
+ return nGroups;
+ }
+
+ TContactInfo *addContact(HANDLE hContact, bool bManual)
+ {
+ TContactInfo *info = new TContactInfo(hContact, bManual);
+ this->insert(info);
+ return info;
+ }
+
+ void build()
+ {
+ TCHAR *prevGroup = NULL;
+ int i;
+
+ nGroups = 1;
+
+ HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
+ for ( ; hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
+ if (DBGetContactSettingByte(hContact, "FavContacts", "IsFavourite", 0))
+ {
+ TCHAR *group = addContact(hContact, true)->getGroup();
+ if (prevGroup && lstrcmp(prevGroup, group))
+ ++nGroups;
+ prevGroup = group;
+ }
+
+ int nRecent = 0;
+ for (i = 0; nRecent < g_Options.wMaxRecent; ++i)
+ {
+ hContact = g_contactCache->get(i);
+ if (!hContact) break;
+ if (!DBGetContactSettingByte(hContact, "FavContacts", "IsFavourite", 0))
+ {
+ TCHAR *group = addContact(hContact, false)->getGroup();
+ if (prevGroup && lstrcmp(prevGroup, group))
+ ++nGroups;
+ prevGroup = group;
+
+ ++nRecent;
+ }
+ }
+ }
+};
+
+#endif // favlist_h__
|