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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/*
Miranda IM: the free IM client for Microsoft* Windows*
Copyright 2000-2003 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "commonheaders.h"
#include "m_clui.h"
#include "m_clc.h"
#include "clist.h"
TCHAR *GetNameForContact(HANDLE hContact,int flag,boolean *isUnknown);
char *GetProtoForContact(HANDLE hContact);
int GetStatusForContact(HANDLE hContact,char *szProto);
TCHAR *UnknownConctactTranslatedName;
extern boolean OnModulesLoadedCalled;
void InvalidateDisplayNameCacheEntryByPDNE(HANDLE hContact,ClcCacheEntry *pdnce,int SettingType);
static int handleCompare( ClcCacheEntry* c1, ClcCacheEntry* c2 )
{
return (char*)c1->hContact - (char*)c2->hContact;
}
void InitDisplayNameCache(SortedList *list)
{
int i, idx;
HANDLE hContact;
memset(list,0,sizeof(SortedList));
list->sortFunc = (FSortFunc)handleCompare;
list->increment = CallService(MS_DB_CONTACT_GETCOUNT,0,0)+1;
i = 0;
for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
ClcCacheEntry *pdnce = (ClcCacheEntry *)mir_calloc(sizeof(ClcCacheEntry));
pdnce->hContact = hContact;
InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,0);
List_GetIndex(list,pdnce,&idx);
List_Insert(list,pdnce,idx);
i++;
} }
void FreeDisplayNameCacheItem(ClcCacheEntry *p)
{
if ( p->tszName) { mir_free(p->tszName); p->tszName = NULL; }
if ( p->szProto) { mir_free(p->szProto); p->szProto = NULL; }
if ( p->tszGroup) { mir_free(p->tszGroup); p->tszGroup = NULL; }
}
void FreeDisplayNameCache(SortedList *list)
{
for (int i = 0; i < list->realCount; i++) {
FreeDisplayNameCacheItem((ClcCacheEntry*)list->items[i] );
mir_free(list->items[i]);
}
List_Destroy(list);
}
void CheckPDNCE(ClcCacheEntry *_pdnce)
{
ClcCacheEntry *pdnce = (ClcCacheEntry *)_pdnce;
if (pdnce == NULL)
return;
if (pdnce->szProto == NULL && pdnce->protoNotExists == FALSE) {
pdnce->szProto = GetProtoForContact(pdnce->hContact);
if (pdnce->szProto == NULL)
pdnce->protoNotExists = FALSE;
else {
if (CallService(MS_PROTO_ISPROTOCOLLOADED,0,(LPARAM)pdnce->szProto) == 0)
pdnce->protoNotExists = TRUE;
else {
if ( pdnce->szProto && pdnce->tszName ) {
mir_free(pdnce->tszName);
pdnce->tszName = NULL;
} } } }
if (pdnce->tszName == NULL)
{
if (pdnce->protoNotExists)
pdnce->tszName = mir_tstrdup(TranslateT("_NoProtocol_"));
else {
if (OnModulesLoadedCalled)
pdnce->tszName = GetNameForContact(pdnce->hContact,0,&pdnce->isUnknown);
else
pdnce->tszName = GetNameForContact(pdnce->hContact,0,NULL);
}
}
else {
if (pdnce->isUnknown&&pdnce->szProto&&pdnce->protoNotExists == TRUE&&OnModulesLoadedCalled) {
pdnce->protoNotExists = FALSE;
mir_free(pdnce->tszName);
pdnce->tszName = GetNameForContact(pdnce->hContact,0,&pdnce->isUnknown);
} }
if (pdnce->status == 0)
pdnce->status = GetStatusForContact(pdnce->hContact,pdnce->szProto);
if (pdnce->tszGroup == NULL)
{
DBVARIANT dbv;
if ( !db_get_ts(pdnce->hContact,"CList","Group",&dbv))
{
pdnce->tszGroup = mir_tstrdup(dbv.ptszVal);
mir_free(dbv.pszVal);
}
else pdnce->tszGroup = mir_tstrdup( _T(""));
}
if (pdnce->bIsHidden == -1)
pdnce->bIsHidden = db_get_b(pdnce->hContact,"CList","Hidden",0);
if (pdnce->noHiddenOffline == -1)
pdnce->noHiddenOffline = db_get_b(pdnce->hContact,"CList","noOffline",0);
if ( pdnce->IdleTS == -1 )
pdnce->IdleTS = db_get_dw(pdnce->hContact,pdnce->szProto,"IdleTS",0);
if (pdnce->ApparentMode == -1)
pdnce->ApparentMode = db_get_w(pdnce->hContact,pdnce->szProto,"ApparentMode",0);
if (pdnce->NotOnList == -1)
pdnce->NotOnList = db_get_b(pdnce->hContact,"CList","NotOnList",0);
if (pdnce->IsExpanded == -1)
pdnce->IsExpanded = db_get_b(pdnce->hContact,"CList","Expanded",0);
}
void InvalidateDisplayNameCacheEntryByPDNE(HANDLE hContact,ClcCacheEntry *pdnce,int SettingType)
{
if ( hContact == NULL || pdnce == NULL )
return;
if ( SettingType == -1 || SettingType == DBVT_DELETED )
{
mir_free(pdnce->tszName);
pdnce->tszName = NULL;
mir_free(pdnce->tszGroup);
pdnce->tszGroup = NULL;
pdnce->bIsHidden = -1;
pdnce->protoNotExists = FALSE;
mir_free(pdnce->szProto);
pdnce->szProto = NULL;
pdnce->status = 0;
pdnce->IdleTS = -1;
pdnce->ApparentMode = -1;
pdnce->NotOnList = -1;
pdnce->isUnknown = FALSE;
pdnce->noHiddenOffline = -1;
pdnce->IsExpanded = -1;
return;
}
if (SettingType >= DBVT_WCHAR)
{
mir_free(pdnce->tszName);
pdnce->tszName = NULL;
mir_free(pdnce->tszGroup);
pdnce->tszGroup = NULL;
mir_free(pdnce->szProto);
pdnce->szProto = NULL;
return;
}
// in other cases clear all binary cache
pdnce->bIsHidden = -1;
pdnce->protoNotExists = FALSE;
pdnce->status = 0;
pdnce->IdleTS = -1;
pdnce->ApparentMode = -1;
pdnce->NotOnList = -1;
pdnce->isUnknown = FALSE;
pdnce->noHiddenOffline = -1;
pdnce->IsExpanded = -1;
}
char *GetContactCachedProtocol(HANDLE hContact)
{
ClcCacheEntry *cacheEntry = (ClcCacheEntry *)pcli->pfnGetCacheEntry(hContact);
if (cacheEntry&&cacheEntry->szProto)
return cacheEntry->szProto;
return NULL;
}
char *GetProtoForContact(HANDLE hContact)
{
DBVARIANT dbv;
DBCONTACTGETSETTING dbcgs;
char name[32];
dbv.type = DBVT_ASCIIZ;
dbv.pszVal = name;
dbv.cchVal = SIZEOF(name);
dbcgs.pValue = &dbv;
dbcgs.szModule = "Protocol";
dbcgs.szSetting = "p";
if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC,(WPARAM)hContact,(LPARAM)&dbcgs)) return NULL;
return mir_strdup(dbcgs.pValue->pszVal);
}
int GetStatusForContact(HANDLE hContact,char *szProto)
{
int status = ID_STATUS_OFFLINE;
if (szProto)
status = db_get_w((HANDLE)hContact,szProto,"Status",ID_STATUS_OFFLINE);
return (status);
}
TCHAR* GetNameForContact(HANDLE hContact,int flag,boolean *isUnknown)
{
TCHAR* result = pcli->pfnGetContactDisplayName(hContact, flag | GCDNF_NOCACHE);
if (isUnknown) {
if (UnknownConctactTranslatedName == NULL)
UnknownConctactTranslatedName = TranslateT("(Unknown Contact)");
*isUnknown = lstrcmp(result ,UnknownConctactTranslatedName) == 0;
}
return result;
}
ClcCacheEntry *GetContactFullCacheEntry(HANDLE hContact)
{
ClcCacheEntry *cacheEntry = (ClcCacheEntry *)pcli->pfnGetCacheEntry(hContact);
if (cacheEntry != NULL)
return(cacheEntry);
return NULL;
}
int GetContactInfosForSort(HANDLE hContact,char **Proto,TCHAR **Name,int *Status)
{
ClcCacheEntry *cacheEntry = (ClcCacheEntry *)pcli->pfnGetCacheEntry(hContact);
if (cacheEntry != NULL)
{
if (Proto != NULL) *Proto = cacheEntry->szProto;
if (Name != NULL) *Name = cacheEntry->tszName;
if (Status != NULL) *Status = cacheEntry->status;
}
return 0;
}
int GetContactCachedStatus(HANDLE hContact)
{
ClcCacheEntry *cacheEntry = (ClcCacheEntry *)pcli->pfnGetCacheEntry(hContact);
if (cacheEntry&&cacheEntry->status != 0) return cacheEntry->status;
return 0;
}
int ContactSettingChanged(WPARAM wParam,LPARAM lParam)
{
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
HANDLE hContact = (HANDLE)wParam;
// Early exit
if (hContact == NULL)
return 0;
__try
{
ClcCacheEntry *pdnce = (ClcCacheEntry *)pcli->pfnGetCacheEntry(hContact);
if (pdnce == NULL) {
OutputDebugStringA("!!! Very bad pdnce not found.");
return 0;
}
if (pdnce && pdnce->protoNotExists == FALSE && pdnce->szProto) {
if ( !strcmp(cws->szModule,pdnce->szProto)) {
InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,cws->value.type);
if (cws->value.type == DBVT_WORD && !strcmp(cws->szSetting, "Status")) {
if ( !(pdnce->bIsHidden == 1)) {
if ( db_get_b((HANDLE)NULL,"CList","ShowStatusMsg",0)||db_get_b(hContact,"CList","StatusMsgAuto",0))
db_set_s(hContact, "CList", "StatusMsg", "");
if ( db_get_b(NULL, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT)) {
// User's state is changing, and we are hideOffline-ing
if (cws->value.wVal == ID_STATUS_OFFLINE) {
ChangeContactIcon(hContact, ExtIconFromStatusMode(hContact,cws->szModule, cws->value.wVal), 0); //by FYR
return 0;
}
ChangeContactIcon(hContact, ExtIconFromStatusMode(hContact,cws->szModule, cws->value.wVal), 0); //by FYR
}
else ChangeContactIcon(hContact, ExtIconFromStatusMode(hContact,cws->szModule, cws->value.wVal), 0); //by FYR
}
}
else if ( !strcmp(cws->szModule,"MetaContacts")) {
PostMessage(pcli->hwndContactTree,CLM_AUTOREBUILD,0,0);
return 0;
}
else return 0;
SortContacts();
}
}
if ( !strcmp(cws->szModule,"CList")) {
if (pdnce->tszName == NULL || !strcmp(cws->szSetting,"MyHandle"))
InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,cws->value.type);
if ((!strcmp(cws->szSetting,"Group")))
InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,cws->value.type);
if ( !strcmp(cws->szSetting,"Hidden")) {
InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,cws->value.type);
if (cws->value.type == DBVT_DELETED || cws->value.bVal == 0) {
char *szProto = GetContactProto((HANDLE)wParam);
ChangeContactIcon(hContact,ExtIconFromStatusMode(hContact, szProto, szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE)), 1); //by FYR
}
}
if ( !strcmp(cws->szSetting, "noOffline"))
InvalidateDisplayNameCacheEntryByPDNE(hContact, pdnce, cws->value.type);
}
if ( !strcmp(cws->szModule, "Protocol")) {
if ( !strcmp(cws->szSetting,"p")) {
OutputDebugStringA("CHANGE: proto\r\n");
InvalidateDisplayNameCacheEntryByPDNE(hContact, pdnce, cws->value.type);
char *szProto = (cws->value.type == DBVT_DELETED) ? NULL : cws->value.pszVal;
ChangeContactIcon(hContact, ExtIconFromStatusMode(hContact, szProto, szProto == NULL?ID_STATUS_OFFLINE:db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE)),0); //by FYR
}
}
}
__except (exceptFunction(GetExceptionInformation()))
{
}
return 0;
}
|