1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#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 && !db_get_ts(hContact, "CList", "Group", &dbv))
{
group = mir_tstrdup(dbv.ptszVal);
db_free(&dbv);
} else
if (g_Options.bUseGroups)
{
group = mir_tstrdup(TranslateT("<no group>"));
} else
{
group = mir_tstrdup(TranslateT("Favorite Contacts"));
}
status = db_get_w(hContact, GetContactProto(hContact), "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;
nGroups = 1;
for (HANDLE 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;
}
int nRecent = 0;
for (int i = 0; nRecent < g_Options.wMaxRecent; ++i) {
HANDLE 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;
}
}
}
};
#endif // favlist_h__
|