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
|
/*
MetaContacts Plugin for Miranda IM.
Copyright © 2004 Universite Louis PASTEUR, STRASBOURG.
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.
*/
/** @file addto.c
*
* Functions for the <b>'Add To'</b> Dialog.
* Contains all the functions and all the structures
* needed to display and control the <b>'Add To'</b> Dialog.
*/
#include "metacontacts.h"
//! Holds information about a contact.
typedef struct {
char *name; //!< Name of the contact
char *proto; //!< Protocol under which the contact has been registered
HANDLE hUser; //!< Identifier of the contact in the DB.
}USERINFO;
//! Holds information for the callback function.
typedef struct {
USERINFO uInfo; //!< Information about the contact to add
}ADDTO_INFO;
/** Adds all the metacontacts desired in the listview.
*
* Adds all the metacontacts present in the database in the list,
*
* @param list : \c HANDLE to the list which will contain the columns.
* @param nb_contacts : Number of loaded contacts.
* @param contacts : A list of the contacts' identifiers
*
* @param id : Reference to a list of the MetaContacts IDs loaded in the listview.
* Since this list is resized, its address must be passed.
*
* @return An integer specifying the number of rows added in the list.
*/
int FillList(HWND list, BOOL sort)
{
DWORD metaID;
HANDLE hMetaUser = db_find_first();
int i=0;
int index;
//BOOL mbs = FALSE;
while(hMetaUser) // The DB is searched through, to get all the metacontacts
{
if ((metaID = db_get_dw(hMetaUser, META_PROTO, META_ID,(DWORD)-1))==(DWORD)-1)
{
// This isn't a MetaContact, go to the next
hMetaUser = db_find_next(hMetaUser);
continue;
}
{
// get contact display name from clist
char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hMetaUser, 0);
if (os_unicode_enabled) {
wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hMetaUser, GCDNF_UNICODE),
*swzContactDisplayName;
// detect if the clist provided unicode display name by comparing with non-unicode
if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0) {
swzContactDisplayName = swzCDN;
} else {
// no? convert to unicode
if (szCDN) {
swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1));
MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1);
} else {
swzContactDisplayName = TranslateW(L"(Unknown Contact)");
}
}
// don't insert huge strings that we have to compare with later
if (wcslen(swzContactDisplayName) > 1023)
swzContactDisplayName[1024] = 0;
if (sort) {
int j;
wchar_t buff[1024];
for (j = 0; j < i; j++) {
SendMessageW(list, LB_GETTEXT, j, (LPARAM)buff);
if (wcscmp(buff, swzContactDisplayName) > 0) break;
}
index = SendMessageW(list, LB_INSERTSTRING, (WPARAM)j, (LPARAM)swzContactDisplayName);
} else {
index = SendMessageW(list, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)swzContactDisplayName);
}
} else {
// don't insert huge strings that we have to compare with later
if (strlen(szCDN) > 1023)
szCDN[1024] = 0;
if (sort) {
int j;
char buff[1024];
for (j = 0; j < i; j++) {
SendMessage(list, LB_GETTEXT, j, (LPARAM)buff);
if (strcmp(buff, szCDN) > 0) break;
}
index = SendMessage(list, LB_INSERTSTRING, (WPARAM)j, (LPARAM)szCDN);
} else {
index = SendMessage(list, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szCDN);
}
}
SendMessage(list, LB_SETITEMDATA, (WPARAM)index, (LPARAM)hMetaUser);
}
i++;
hMetaUser = db_find_next(hMetaUser);
}
return i;
}
/** Build or update the list.
*
* @param list : \c HANDLE to the list which will contain the columns
* @param id : Reference to a list that will contain all the MetaContacts IDs loaded in the listview
* otherwise the list is only refilled \n (Warning : this value must be
* set to \c TRUE only once per Dialog display, otherwise all columns will be doubled)
*
* @returns An integer specifying the number of rows inserted or \c -1 if there was a problem
*/
int BuildList(HWND list, BOOL sort)
{
int ret=-1;
SendMessage(list, LB_RESETCONTENT, 0, 0);
ret = FillList(list, sort);
return ret;
}
/** Callback function for the <b>'Add To'</b> Dialog.
*
* All the UI is controlled here, from display to functionnalities.
*
* @param hwndDlg : \c HANDLE to the <b>'Add To'</b> \c Dialog.
* @param uMsg : Specifies the message received by this dialog.
* @param wParam : Specifies additional message-specific information.
* @param lParam : Specifies additional message-specific information.
*
* @return \c TRUE if the dialog processed the message, \c FALSE if it did not.
*/
INT_PTR CALLBACK Meta_SelectDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
{
TranslateDialogDefault( hwndDlg );
if (db_get_dw((HANDLE)lParam, META_PROTO, META_ID,(DWORD)-1)!=(DWORD)-1)
{
MessageBox(hwndDlg,Translate("This contact is a MetaContact.\nYou can't add a MetaContact to another MetaContact.\n\nPlease choose another."),
Translate("MetaContact Conflict"),MB_ICONERROR);
DestroyWindow(hwndDlg);
return TRUE;
}
if (db_get_dw((HANDLE)lParam, META_PROTO, META_LINK,(DWORD)-1)!=(DWORD)-1)
{
MessageBox(hwndDlg,Translate("This contact is already associated to a MetaContact.\nYou cannot add a contact to multiple MetaContacts."),
Translate("Multiple MetaContacts"),MB_ICONERROR);
DestroyWindow(hwndDlg);
return TRUE;
}
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); // user data is contact handle
SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_ADD));
//SendMessage(GetDlgItem(hwndDlg,IDC_METALIST),LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);
// Initialize the graphical part
CheckDlgButton(hwndDlg,IDC_ONLYAVAIL,BST_CHECKED); // Initially checked; display all metacontacts is only an option
// Besides, we can check if there is at least one metacontact to add the contact to.
if (BuildList(GetDlgItem(hwndDlg,IDC_METALIST), FALSE)<=0)
{
if (MessageBox(hwndDlg,Translate("Either there is no MetaContact in the database (in this case you should first convert a contact into one)\n"
"or there is none that can host this contact.\n"
"Another solution could be to convert this contact into a new MetaContact.\n\nConvert this contact into a new MetaContact?"),
Translate("No suitable MetaContact found"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)==IDYES)
Meta_Convert((WPARAM)lParam,0);
DestroyWindow(hwndDlg);
return TRUE;
}
else
{
// Get the name displayed in the CList...
// get contact display name from clist
char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, 0);
if (os_unicode_enabled) {
wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE),
*swzContactDisplayName;
wchar_t buf[256];
// detect if the clist provided unicode display name by comparing with non-unicode
if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0) {
swzContactDisplayName = swzCDN;
} else {
// no? convert to unicode
if (szCDN) {
swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1));
MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1);
} else {
swzContactDisplayName = TranslateW(L"a contact");
}
}
// ... and set it to the Window title.
//MessageBoxW(hwndDlg, swzContactDisplayName, L"Setting window title", MB_OK);
// note - the swprintf function has changed (includes size_t for vc8+)
//swprintf(buf, 256, TranslateW(L"Adding %s..."), swzContactDisplayName);
// this *should* work for vc6, 7, and 8 (thx George)
_snwprintf(buf, 256, TranslateW(L"Adding %s..."), swzContactDisplayName);
SetWindowTextW(hwndDlg, buf);
} else {
char buf[256];
sprintf(buf,Translate("Adding %s..."), szCDN);
SetWindowText(hwndDlg, buf);
}
ShowWindow(hwndDlg,SW_SHOWNORMAL);
return TRUE;
}
}
case WM_COMMAND:
if (HIWORD(wParam)!=BN_CLICKED)
break; // Only clicks of buttons are relevant, let other COMMANDs through
switch(LOWORD(wParam))
{
case IDOK:
{
HANDLE hMeta, hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
int item; // Get the index of the selected metacontact
if ((item = SendMessage(GetDlgItem(hwndDlg, IDC_METALIST),LB_GETCURSEL, 0, 0))==-1)
return IDOK == MessageBox(hwndDlg,Translate("Please select a MetaContact"),Translate("No MetaContact selected"),MB_ICONHAND);
hMeta = (HANDLE)SendMessage(GetDlgItem(hwndDlg, IDC_METALIST), LB_GETITEMDATA, (WPARAM)item, 0);
{
if ( !Meta_Assign(hContact,hMeta, FALSE))
{
MessageBox(hwndDlg, Translate("Assignment to the MetaContact failed."), Translate("Assignment failure"),MB_ICONERROR);
}
}
}
case IDCANCEL:
DestroyWindow(hwndDlg);
break;
case IDC_CHK_SRT:
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE) ^ LBS_SORT);
if (BuildList(GetDlgItem(hwndDlg,IDC_METALIST), IsDlgButtonChecked(hwndDlg, IDC_CHK_SRT) ? TRUE : FALSE)<=0)
{
if (MessageBox(hwndDlg,Translate("Either there is no MetaContact in the database (in this case you should first convert a contact into one)\n"
"or there is none that can host this contact.\n"
"Another solution could be to convert this contact into a new MetaContact.\n\nConvert this contact into a new MetaContact?"),
Translate("No suitable MetaContact found"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)==IDYES)
Meta_Convert((WPARAM)lParam,0);
DestroyWindow(hwndDlg);
return TRUE;
}
break;
}
break;
case WM_DESTROY:
{ // Free all allocated memory and return the focus to the CList
HWND clist = GetParent(hwndDlg);
ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
EndDialog(hwndDlg,TRUE);
SetFocus(clist);
return TRUE;
}
}
return FALSE; // All other Message are not handled
}
|