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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
/*
Copyright (C) 2009 Ricardo Pescuma Domenecci
Copyright (C) 2012-14 Miranda NG project
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "..\..\core\commonheaders.h"
#include "m_cluiframes.h"
#include "ExtraIcon.h"
#include "extraicons.h"
ExtraIcon* GetExtraIcon(HANDLE id);
////////////////////////////////////////////////////////////////////////////////////////
// DB extra icons
HANDLE hExtraVisibility, hExtraChat, hExtraGender, hExtraProto;
static void SetVisibility(MCONTACT hContact, int apparentMode, bool clear)
{
if (hContact == NULL)
return;
char *proto = GetContactProto(hContact);
if (IsEmpty(proto))
return;
if (apparentMode <= 0)
apparentMode = db_get_w(hContact, proto, "ApparentMode", 0);
HANDLE hExtraIcon, hIcolib = NULL;
if (db_get_b(hContact, proto, "ChatRoom", 0)) {
// Is chat
hExtraIcon = hExtraChat;
if (apparentMode == ID_STATUS_OFFLINE)
hIcolib = Skin_GetIconHandle("ChatActivity");
}
else {
// Not chat
hExtraIcon = hExtraVisibility;
if (apparentMode == ID_STATUS_OFFLINE)
hIcolib = LoadSkinnedIconHandle(SKINICON_OTHER_INVISIBLE_ALL);
else if (apparentMode == ID_STATUS_ONLINE)
hIcolib = LoadSkinnedIconHandle(SKINICON_OTHER_VISIBLE_ALL);
}
if (hIcolib != NULL || clear) {
ExtraIcon *extra = GetExtraIcon(hExtraIcon);
if (extra)
extra->setIcon((int)hExtraIcon, hContact, hIcolib);
}
}
static void SetGender(MCONTACT hContact, int gender, bool clear)
{
if (hContact == NULL)
return;
char *proto = GetContactProto(hContact);
if (IsEmpty(proto))
return;
if (gender <= 0)
gender = db_get_b(hContact, proto, "Gender", 0);
if (gender <= 0)
gender = db_get_b(hContact, "UserInfo", "Gender", 0);
const char *ico;
if (gender == 'M')
ico = "gender_male";
else if (gender == 'F')
ico = "gender_female";
else
ico = NULL;
if (ico != NULL || clear) {
ExtraIcon *extra = GetExtraIcon(hExtraGender);
if (extra)
extra->setIconByName((int)hExtraGender, hContact, ico);
}
}
struct Info
{
const char *name;
const char *desc;
int iSkinIcon;
const char *db[8];
void(*OnClick)(Info *info, const char *text);
HANDLE hIcolib, hExtraIcon;
};
static void EmailOnClick(Info *info, const char *text)
{
char cmd[1024];
mir_snprintf(cmd, SIZEOF(cmd), "mailto:%s", text);
ShellExecuteA(NULL, "open", cmd, NULL, NULL, SW_SHOW);
}
static void HomepageOnClick(Info *info, const char *text)
{
ShellExecuteA(NULL, "open", text, NULL, NULL, SW_SHOW);
}
static Info infos[] =
{
{ "homepage", "Homepage", SKINICON_EVENT_URL,
{ NULL, "Homepage", "UserInfo", "Homepage" },
&HomepageOnClick },
{ "sms", "Phone/SMS", SKINICON_OTHER_SMS,
{ NULL, "Cellular", "UserInfo", "Cellular", "UserInfo", "Phone", "UserInfo", "MyPhone0" },
NULL },
{ "email", "E-mail", SKINICON_OTHER_SENDEMAIL,
{ NULL, "e-mail", "UserInfo", "e-mail", "UserInfo", "Mye-mail0" },
&EmailOnClick },
};
static void SetExtraIcons(MCONTACT hContact)
{
if (hContact == NULL)
return;
char *proto = GetContactProto(hContact);
if ( IsEmpty(proto))
return;
for (unsigned int i = 0; i < SIZEOF(infos); i++) {
Info &p = infos[i];
for (unsigned int j = 0; j < SIZEOF(p.db); j += 2) {
if (p.db[j + 1] == NULL)
break;
ptrA szValue(db_get_sa(hContact, p.db[j] == NULL ? proto : p.db[j], p.db[j + 1]));
if (!IsEmpty(szValue)) {
ExtraIcon_SetIcon(p.hExtraIcon, hContact, p.hIcolib);
break;
}
}
}
}
static int SettingChanged(WPARAM hContact, LPARAM lParam)
{
if (hContact == NULL)
return 0;
char *proto = GetContactProto(hContact);
if (IsEmpty(proto))
return 0;
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
bool isProto = (strcmp(cws->szModule, proto) == 0);
if (isProto && strcmp(cws->szSetting, "ApparentMode") == 0) {
SetVisibility(hContact, cws->value.type == DBVT_DELETED ? 0 : cws->value.wVal, true);
return 0;
}
if (strcmp(cws->szSetting, "Gender") == 0 && (isProto || strcmp(cws->szModule, "UserInfo") == 0)) {
SetGender(hContact, cws->value.type == DBVT_DELETED ? 0 : cws->value.bVal, true);
return 0;
}
for (int i = 0; i < SIZEOF(infos); i++) {
Info &p = infos[i];
for (int j = 0; j < SIZEOF(p.db); j += 2) {
if (p.db[j + 1] == NULL)
break;
if (p.db[j] == NULL && !isProto)
continue;
if (p.db[j] != NULL && strcmp(cws->szModule, p.db[j]))
continue;
if (strcmp(cws->szSetting, p.db[j + 1]))
continue;
bool show = (cws->value.type != DBVT_DELETED && !IsEmpty(cws->value.pszVal));
ExtraIcon_SetIcon(p.hExtraIcon, hContact, show ? p.hIcolib : NULL);
break;
}
}
return 0;
}
static int DefaultOnClick(WPARAM hContact, LPARAM lParam, LPARAM param)
{
Info *p = (Info*)param;
if (p == NULL)
return 0;
if (hContact == NULL)
return 0;
char *proto = GetContactProto(hContact);
if (IsEmpty(proto))
return 0;
bool found = false;
for (int j = 0; !found && j < SIZEOF(p->db); j += 2) {
if (p->db[j + 1] == NULL)
break;
ptrA szValue(db_get_sa(hContact, p->db[j] == NULL ? proto : p->db[j], p->db[j + 1]));
if (!IsEmpty(szValue)) {
p->OnClick(p, szValue);
found = true;
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// Protocol icon
struct ProtoInfo
{
ProtoInfo(LPCSTR _proto, HANDLE _image) :
proto(mir_strdup(_proto)),
hImage(_image)
{}
ptrA proto;
HANDLE hImage;
};
static int CompareProtos(const ProtoInfo *p1, const ProtoInfo *p2)
{ return strcmp(p1->proto, p2->proto);
}
OBJLIST<ProtoInfo> arProtos(10, CompareProtos);
static int ProtocolRebuildIcons(WPARAM wParam, LPARAM lParam)
{
arProtos.destroy();
return 0;
}
static ProtoInfo* FindProto(const char *proto)
{
ProtoInfo *p = arProtos.find((ProtoInfo*)&proto);
if (p)
return p;
HICON hIcon = LoadSkinnedProtoIcon(proto, ID_STATUS_ONLINE);
if (hIcon == NULL)
return NULL;
HANDLE hImage = ExtraIcon_Add(hIcon);
if (hImage == INVALID_HANDLE_VALUE)
return NULL;
p = new ProtoInfo(proto, hImage);
arProtos.insert(p);
return p;
}
static int ProtocolApplyIcon(WPARAM hContact, LPARAM lParam)
{
char *proto = GetContactProto(hContact);
if (IsEmpty(proto))
return 0;
HANDLE hImage = INVALID_HANDLE_VALUE;
ProtoInfo *pi = FindProto(proto);
if (pi != NULL)
hImage = pi->hImage;
ExtraIcon_SetIcon(hExtraProto, hContact, hImage);
return 0;
}
static int ProtocolOnClick(WPARAM wParam, LPARAM lParam, LPARAM param)
{
if (wParam)
CallService(MS_USERINFO_SHOWDIALOG, wParam, 0);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
void DefaultExtraIcons_Load()
{
hExtraChat = ExtraIcon_Register("chat_activity", LPGEN("Chat activity"), "ChatActivity");
hExtraVisibility = ExtraIcon_Register("visibility", "Visibility", LoadSkinnedIconName(SKINICON_OTHER_VISIBLE_ALL));
hExtraGender = ExtraIcon_Register("gender", "Gender", "gender_male");
hExtraProto = ExtraIcon_Register("protocol", "Account", LoadSkinnedIconName(SKINICON_OTHER_ACCMGR),
&ProtocolRebuildIcons, &ProtocolApplyIcon, &ProtocolOnClick);
for (int i = 0; i < SIZEOF(infos); i++) {
Info &p = infos[i];
p.hIcolib = LoadSkinnedIconHandle(p.iSkinIcon);
if (p.OnClick)
p.hExtraIcon = ExtraIcon_Register(p.name, p.desc, LoadSkinnedIconName(p.iSkinIcon), DefaultOnClick, (LPARAM)&p);
else
p.hExtraIcon = ExtraIcon_Register(p.name, p.desc, LoadSkinnedIconName(p.iSkinIcon));
}
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
SetExtraIcons(hContact);
SetVisibility(hContact, -1, false);
SetGender(hContact, -1, false);
}
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged);
}
|