Mercurial > pidgin.yaz
annotate src/protocols/gg/gg.c @ 11837:fa742ad8068c
[gaim-migrate @ 14128]
Don't pass our active GaimStatus to the login PRPL callback...
It's not used by most PRPLS, and that ones that DO use it
probably shouldn't. Ideally the PRPLs won't store any info
about their own status, message, etc. All that should be in
the core status API, and when it needs some info it should
query the core to get it.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 26 Oct 2005 05:40:02 +0000 |
parents | 11e95968c9ff |
children | 1b029c5898af |
rev | line source |
---|---|
11394 | 1 /** |
2 * @file gg.c Gadu-Gadu protocol plugin | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us> | |
7 * | |
8 * Some parts of the code are adapted or taken for the previous implementation | |
9 * of this plugin written by Arkadiusz Miskiewicz <misiek@pld.org.pl> | |
10 * | |
11 * Thanks to Google's Summer of Code Program. | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 */ | |
27 | |
11360 | 28 |
2393 | 29 /* |
11360 | 30 * NOTES |
2393 | 31 * |
11360 | 32 * I don't like automatic updates of the buddylist stored on the server, so not |
33 * going to implement this. Maybe some kind of option to enable/disable this | |
34 * feature. | |
2393 | 35 */ |
11360 | 36 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
37 #include "internal.h" |
2393 | 38 |
11360 | 39 #include "plugin.h" |
40 #include "version.h" | |
41 #include "notify.h" | |
42 #include "status.h" | |
9030 | 43 #include "blist.h" |
11360 | 44 #include "accountopt.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
45 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
46 #include "util.h" |
11360 | 47 #include "request.h" |
2393 | 48 |
11360 | 49 #include "lib/libgadu.h" |
5603 | 50 |
11414 | 51 #include "gg.h" |
52 #include "confer.h" | |
53 #include "search.h" | |
54 #include "buddylist.h" | |
55 #include "utils.h" | |
11394 | 56 |
11414 | 57 static GaimPlugin *my_protocol = NULL; |
11394 | 58 |
11360 | 59 /* ---------------------------------------------------------------------- */ |
11414 | 60 /* ----- EXTERNAL CALLBACKS --------------------------------------------- */ |
11360 | 61 /* ---------------------------------------------------------------------- */ |
9950 | 62 |
11360 | 63 /** |
64 * Request buddylist from the server. | |
65 * Buddylist is received in the ggp_callback_recv(). | |
66 * | |
67 * @param Current action handler. | |
68 */ | |
69 /* static void ggp_action_buddylist_get(GaimPluginAction *action) {{{ */ | |
70 static void ggp_action_buddylist_get(GaimPluginAction *action) | |
71 { | |
72 GaimConnection *gc = (GaimConnection *)action->context; | |
73 GGPInfo *info = gc->proto_data; | |
74 | |
75 gaim_debug_info("gg", "Downloading...\n"); | |
76 | |
77 gg_userlist_request(info->session, GG_USERLIST_GET, NULL); | |
78 } | |
79 /* }}} */ | |
80 | |
81 /** | |
82 * Upload the buddylist to the server. | |
83 * | |
84 * @param action Current action handler. | |
85 */ | |
86 /* static void ggp_action_buddylist_put(GaimPluginAction *action) {{{ */ | |
87 static void ggp_action_buddylist_put(GaimPluginAction *action) | |
88 { | |
89 GaimConnection *gc = (GaimConnection *)action->context; | |
90 GGPInfo *info = gc->proto_data; | |
91 | |
92 char *buddylist = ggp_buddylist_dump(gaim_connection_get_account(gc)); | |
93 | |
94 gaim_debug_info("gg", "Uploading...\n"); | |
95 | |
96 if (buddylist == NULL) | |
97 return; | |
98 | |
99 gg_userlist_request(info->session, GG_USERLIST_PUT, buddylist); | |
100 g_free(buddylist); | |
101 } | |
102 /* }}} */ | |
103 | |
104 /** | |
105 * Delete buddylist from the server. | |
106 * | |
107 * @param action Current action handler. | |
108 */ | |
109 /* static void ggp_action_buddylist_delete(GaimPluginAction *action) {{{ */ | |
110 static void ggp_action_buddylist_delete(GaimPluginAction *action) | |
111 { | |
112 GaimConnection *gc = (GaimConnection *)action->context; | |
113 GGPInfo *info = gc->proto_data; | |
114 | |
115 gaim_debug_info("gg", "Deleting...\n"); | |
116 | |
117 gg_userlist_request(info->session, GG_USERLIST_PUT, NULL); | |
118 } | |
119 /* }}} */ | |
120 | |
121 /* | |
122 */ | |
123 /* static void ggp_callback_buddylist_save_ok(GaimConnection *gc, gchar *file) {{{ */ | |
124 static void ggp_callback_buddylist_save_ok(GaimConnection *gc, gchar *file) | |
125 { | |
126 GaimAccount *account = gaim_connection_get_account(gc); | |
127 | |
128 FILE *fh; | |
129 char *buddylist = ggp_buddylist_dump(account); | |
130 gchar *msg; | |
131 | |
132 gaim_debug_info("gg", "Saving...\n"); | |
133 gaim_debug_info("gg", "file = %s\n", file); | |
134 | |
135 if (buddylist == NULL) { | |
136 gaim_notify_info(account, _("Save Buddylist..."), | |
137 _("Your buddylist is empty, nothing was written to the file."), | |
138 NULL); | |
2792
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
139 return; |
9123abd0db92
[gaim-migrate @ 2805]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
140 } |
2393 | 141 |
11360 | 142 if ((fh = g_fopen(file, "wb")) == NULL) { |
143 msg = g_strconcat(_("Couldn't open file"), ": ", file, "\n", NULL); | |
144 gaim_debug_error("gg", "Could not open file: %s\n", file); | |
145 gaim_notify_error(account, _("Couldn't open file"), msg, NULL); | |
146 g_free(msg); | |
147 g_free(file); | |
148 return; | |
149 } | |
150 | |
151 fwrite(buddylist, sizeof(char), g_utf8_strlen(buddylist, -1), fh); | |
152 fclose(fh); | |
153 g_free(buddylist); | |
154 | |
155 gaim_notify_info(account, _("Save Buddylist..."), | |
156 _("Buddylist saved successfully!"), NULL); | |
157 } | |
158 /* }}} */ | |
2806
1ffac7cf4e94
[gaim-migrate @ 2819]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
159 |
11360 | 160 /* |
161 */ | |
162 /* static void ggp_callback_buddylist_load_ok(GaimConnection *gc, gchar *file) {{{ */ | |
163 static void ggp_callback_buddylist_load_ok(GaimConnection *gc, gchar *file) | |
164 { | |
165 GaimAccount *account = gaim_connection_get_account(gc); | |
166 char *buddylist, *tmp, *ptr; | |
167 FILE *fh; | |
168 gchar *msg; | |
2806
1ffac7cf4e94
[gaim-migrate @ 2819]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
169 |
11360 | 170 buddylist = g_strdup(""); |
171 tmp = g_new0(gchar, 50); | |
172 | |
173 gaim_debug_info("gg", "file_name = %s\n", file); | |
174 | |
175 if ((fh = g_fopen(file, "rb")) == NULL) { | |
176 msg = g_strconcat(_("Couldn't open file"), ": ", file, "\n", NULL); | |
177 gaim_debug_error("gg", "Could not open file: %s\n", file); | |
178 gaim_notify_error(account, _("Could't open file"), msg, NULL); | |
179 g_free(msg); | |
180 g_free(file); | |
2806
1ffac7cf4e94
[gaim-migrate @ 2819]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
181 return; |
1ffac7cf4e94
[gaim-migrate @ 2819]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
182 } |
11360 | 183 |
184 while (fread(tmp, sizeof(gchar), 49, fh) == 49) { | |
185 tmp[49] = '\0'; | |
186 /* gaim_debug_info("gg", "read: %s\n", tmp); */ | |
187 ptr = g_strconcat(buddylist, tmp, NULL); | |
188 memset(tmp, '\0', 50); | |
189 g_free(buddylist); | |
190 buddylist = ptr; | |
191 } | |
192 fclose(fh); | |
193 g_free(tmp); | |
194 | |
195 ggp_buddylist_load(gc, buddylist); | |
196 g_free(buddylist); | |
197 | |
198 gaim_notify_info(account, | |
199 _("Load Buddylist..."), | |
200 _("Buddylist loaded successfully!"), NULL); | |
2806
1ffac7cf4e94
[gaim-migrate @ 2819]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
201 } |
11360 | 202 /* }}} */ |
203 | |
204 /* | |
205 */ | |
206 /* static void ggp_action_buddylist_save(GaimPluginAction *action) {{{ */ | |
207 static void ggp_action_buddylist_save(GaimPluginAction *action) | |
208 { | |
209 GaimConnection *gc = (GaimConnection *)action->context; | |
210 | |
211 gaim_request_file(action, _("Save buddylist..."), NULL, TRUE, | |
212 G_CALLBACK(ggp_callback_buddylist_save_ok), NULL, gc); | |
213 } | |
214 /* }}} */ | |
2806
1ffac7cf4e94
[gaim-migrate @ 2819]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2792
diff
changeset
|
215 |
11360 | 216 /* |
217 */ | |
218 /* static void ggp_action_buddylist_load(GaimPluginAction *action) {{{ */ | |
219 static void ggp_action_buddylist_load(GaimPluginAction *action) | |
220 { | |
221 GaimConnection *gc = (GaimConnection *)action->context; | |
222 | |
223 gaim_request_file(action, "Load buddylist from file...", NULL, FALSE, | |
224 G_CALLBACK(ggp_callback_buddylist_load_ok), NULL, gc); | |
225 } | |
226 /* }}} */ | |
227 | |
228 /* | |
229 */ | |
11414 | 230 /* static void ggp_callback_register_account_ok(GaimConnection *gc, GaimRequestFields *fields) {{{ */ |
231 static void ggp_callback_register_account_ok(GaimConnection *gc, GaimRequestFields *fields) | |
232 { | |
233 GaimAccount *account; | |
234 GGPInfo *info = gc->proto_data; | |
235 struct gg_http *h = NULL; | |
236 struct gg_pubdir *s; | |
237 uin_t uin; | |
238 gchar *email, *p1, *p2, *t; | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
239 GGPToken *token = info->register_token; |
11414 | 240 |
241 email = charset_convert(gaim_request_fields_get_string(fields, "email"), | |
242 "UTF-8", "CP1250"); | |
243 p1 = charset_convert(gaim_request_fields_get_string(fields, "password1"), | |
244 "UTF-8", "CP1250"); | |
245 p2 = charset_convert(gaim_request_fields_get_string(fields, "password2"), | |
246 "UTF-8", "CP1250"); | |
247 t = charset_convert(gaim_request_fields_get_string(fields, "token"), | |
248 "UTF-8", "CP1250"); | |
249 | |
250 account = gaim_connection_get_account(gc); | |
251 | |
252 if (email == NULL || p1 == NULL || p2 == NULL || t == NULL || | |
253 *email == '\0' || *p1 == '\0' || *p2 == '\0' || *t == '\0') { | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
254 gaim_connection_error(gc, _("Fill in the registration fields.")); |
11414 | 255 goto exit_err; |
256 } | |
257 | |
258 if (g_utf8_collate(p1, p2) != 0) { | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
259 gaim_connection_error(gc, _("Passwords do not match.")); |
11414 | 260 goto exit_err; |
261 } | |
262 | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
263 h = gg_register3(email, p1, token->token_id, t, 0); |
11414 | 264 if (h == NULL || !(s = h->data) || !s->success) { |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
265 gaim_connection_error(gc, |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
266 _("Unable to register new account. Error occurred.\n")); |
11414 | 267 goto exit_err; |
268 } | |
269 | |
270 uin = s->uin; | |
271 gaim_debug_info("gg", "registered uin: %d\n", uin); | |
272 | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
273 g_free(t); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
274 t = g_strdup_printf("%u", uin); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
275 gaim_account_set_username(account, t); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
276 /* Save the password if remembering passwords for the account */ |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
277 gaim_account_set_password(account, p1); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
278 |
11414 | 279 gaim_notify_info(NULL, _("New Gadu-Gadu Account Registered"), |
280 _("Registration completed successfully!"), NULL); | |
281 | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
282 /* TODO: the currently open Accounts Window will not be updated withthe new username and etc, we need to somehow have it refresh at this point */ |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
283 |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
284 /* Need to disconnect or actually log in. For now, we disconnect. */ |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
285 gaim_connection_destroy(gc); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
286 |
11414 | 287 exit_err: |
288 gg_register_free(h); | |
289 g_free(email); | |
290 g_free(p1); | |
291 g_free(p2); | |
292 g_free(t); | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
293 g_free(token->token_id); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
294 g_free(token); |
11414 | 295 } |
296 /* }}} */ | |
297 | |
11565 | 298 /* |
299 */ | |
300 /* static void ggp_callback_register_account_cancel(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
301 static void ggp_callback_register_account_cancel(GaimConnection *gc, GaimRequestFields *fields) |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
302 { |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
303 GGPInfo *info = gc->proto_data; |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
304 GGPToken *token = info->register_token; |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
305 |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
306 gaim_connection_destroy(gc); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
307 |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
308 g_free(token->token_id); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
309 g_free(token); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
310 |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
311 } |
11565 | 312 /* }}} */ |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
313 |
11414 | 314 /* ----- PUBLIC DIRECTORY SEARCH ---------------------------------------- */ |
315 | |
316 /* | |
317 */ | |
318 /* static void ggp_callback_show_next(GaimConnection *gc, GList *row) {{{ */ | |
319 static void ggp_callback_show_next(GaimConnection *gc, GList *row) | |
320 { | |
321 GGPInfo *info = gc->proto_data; | |
322 | |
323 g_free(info->search_form->offset); | |
324 info->search_form->offset = g_strdup(info->search_form->last_uin); | |
325 ggp_search_start(gc, info->search_form); | |
326 } | |
327 /* }}} */ | |
328 | |
329 /* | |
330 */ | |
331 /* static void ggp_callback_add_buddy(GaimConnection *gc, GList *row) {{{ */ | |
332 static void ggp_callback_add_buddy(GaimConnection *gc, GList *row) | |
333 { | |
334 gaim_blist_request_add_buddy(gaim_connection_get_account(gc), | |
335 g_list_nth_data(row, 0), NULL, NULL); | |
336 } | |
337 /* }}} */ | |
338 | |
339 /* | |
340 */ | |
341 /* static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
342 static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields) | |
343 { | |
344 GGPInfo *info = gc->proto_data; | |
345 GGPSearchForm *form; | |
346 | |
347 form = ggp_search_form_new(); | |
348 /* | |
349 * TODO: Fail if we have already a form attached. Only one search | |
350 * at a time will be allowed for now. | |
351 */ | |
352 info->search_form = form; | |
353 | |
354 form->lastname = charset_convert(gaim_request_fields_get_string(fields, "lastname"), | |
355 "UTF-8", "CP1250"); | |
356 form->firstname = charset_convert(gaim_request_fields_get_string(fields, "firstname"), | |
357 "UTF-8", "CP1250"); | |
358 form->nickname = charset_convert(gaim_request_fields_get_string(fields, "nickname"), | |
359 "UTF-8", "CP1250"); | |
360 form->city = charset_convert(gaim_request_fields_get_string(fields, "city"), | |
361 "UTF-8", "CP1250"); | |
362 form->birthyear = charset_convert(gaim_request_fields_get_string(fields, "year"), | |
363 "UTF-8", "CP1250"); | |
364 | |
365 switch (gaim_request_fields_get_choice(fields, "gender")) { | |
366 case 1: | |
367 form->gender = g_strdup(GG_PUBDIR50_GENDER_MALE); | |
368 break; | |
369 case 2: | |
370 form->gender = g_strdup(GG_PUBDIR50_GENDER_FEMALE); | |
371 break; | |
372 default: | |
373 form->gender = NULL; | |
374 break; | |
375 } | |
376 | |
377 form->active = gaim_request_fields_get_bool(fields, "active") | |
378 ? g_strdup(GG_PUBDIR50_ACTIVE_TRUE) : NULL; | |
379 | |
380 form->offset = g_strdup("0"); | |
381 | |
382 ggp_search_start(gc, form); | |
383 } | |
384 /* }}} */ | |
385 | |
386 /* | |
387 */ | |
388 /* static void ggp_find_buddies(GaimPluginAction *action) {{{ */ | |
389 static void ggp_find_buddies(GaimPluginAction *action) | |
390 { | |
391 GaimConnection *gc = (GaimConnection *)action->context; | |
392 | |
393 GaimRequestFields *fields; | |
394 GaimRequestFieldGroup *group; | |
395 GaimRequestField *field; | |
396 | |
397 fields = gaim_request_fields_new(); | |
398 group = gaim_request_field_group_new(NULL); | |
399 gaim_request_fields_add_group(fields, group); | |
400 | |
401 field = gaim_request_field_string_new("lastname", _("Last name"), NULL, FALSE); | |
402 gaim_request_field_string_set_masked(field, FALSE); | |
403 gaim_request_field_group_add_field(group, field); | |
404 | |
405 field = gaim_request_field_string_new("firstname", _("First name"), NULL, FALSE); | |
406 gaim_request_field_string_set_masked(field, FALSE); | |
407 gaim_request_field_group_add_field(group, field); | |
408 | |
409 field = gaim_request_field_string_new("nickname", _("Nickname"), NULL, FALSE); | |
410 gaim_request_field_string_set_masked(field, FALSE); | |
411 gaim_request_field_group_add_field(group, field); | |
412 | |
413 field = gaim_request_field_string_new("city", _("City"), NULL, FALSE); | |
414 gaim_request_field_string_set_masked(field, FALSE); | |
415 gaim_request_field_group_add_field(group, field); | |
416 | |
417 field = gaim_request_field_string_new("year", _("Year of birth"), NULL, FALSE); | |
418 gaim_request_field_group_add_field(group, field); | |
419 | |
420 field = gaim_request_field_choice_new("gender", "Gender", 0); | |
421 gaim_request_field_choice_add(field, "Male or female"); | |
422 gaim_request_field_choice_add(field, "Male"); | |
423 gaim_request_field_choice_add(field, "Female"); | |
424 gaim_request_field_group_add_field(group, field); | |
425 | |
426 field = gaim_request_field_bool_new("active", _("Only online"), FALSE); | |
427 gaim_request_field_group_add_field(group, field); | |
428 | |
429 gaim_request_fields(gc, | |
430 _("Find buddies"), | |
431 _("Find buddies"), | |
432 _("Please, enter your search criteria below"), | |
433 fields, | |
434 _("OK"), G_CALLBACK(ggp_callback_find_buddies), | |
435 _("Cancel"), NULL, | |
436 gc); | |
437 } | |
438 /* }}} */ | |
439 | |
440 /* ----- CHANGE PASSWORD ------------------------------------------------ */ | |
441 | |
442 /* | |
443 */ | |
11360 | 444 /* static void ggp_callback_change_passwd_ok(GaimConnection *gc, GaimRequestFields *fields) {{{ */ |
445 static void ggp_callback_change_passwd_ok(GaimConnection *gc, GaimRequestFields *fields) | |
2393 | 446 { |
11360 | 447 GaimAccount *account; |
448 GGPInfo *info = gc->proto_data; | |
449 struct gg_http *h; | |
450 gchar *cur, *p1, *p2, *t; | |
451 | |
452 cur = charset_convert(gaim_request_fields_get_string(fields, "password_cur"), | |
453 "UTF-8", "CP1250"); | |
454 p1 = charset_convert(gaim_request_fields_get_string(fields, "password1"), | |
455 "UTF-8", "CP1250"); | |
456 p2 = charset_convert(gaim_request_fields_get_string(fields, "password2"), | |
457 "UTF-8", "CP1250"); | |
458 t = charset_convert(gaim_request_fields_get_string(fields, "token"), | |
459 "UTF-8", "CP1250"); | |
460 | |
461 account = gaim_connection_get_account(gc); | |
462 | |
463 if (cur == NULL || p1 == NULL || p2 == NULL || t == NULL || | |
464 *cur == '\0' || *p1 == '\0' || *p2 == '\0' || *t == '\0') { | |
465 gaim_notify_error(account, NULL, _("Fill in the fields."), NULL); | |
466 goto exit_err; | |
467 } | |
468 | |
469 if (g_utf8_collate(p1, p2) != 0) { | |
470 gaim_notify_error(account, NULL, _("New passwords do not match."), NULL); | |
471 goto exit_err; | |
472 } | |
2393 | 473 |
11360 | 474 if (g_utf8_collate(cur, gaim_account_get_password(account)) != 0) { |
475 gaim_notify_error(account, NULL, | |
476 _("Your current password is different from the one that you specified."), | |
477 NULL); | |
478 goto exit_err; | |
479 } | |
480 | |
481 gaim_debug_info("gg", "change_passwd: old=%s; p1=%s; token=%s\n", | |
482 cur, p1, info->chpasswd_token->token_id); | |
483 | |
484 /* XXX: this e-mail should be a pref... */ | |
485 h = gg_change_passwd4(ggp_get_uin(account), | |
486 "user@example.net", gaim_account_get_password(account), | |
487 p1, info->chpasswd_token->token_id, t, 0); | |
2393 | 488 |
11360 | 489 if (h == NULL) { |
490 gaim_notify_error(account, NULL, | |
491 _("Unable to change password. Error occured.\n"), | |
492 NULL); | |
493 goto exit_err; | |
494 } | |
495 | |
496 gaim_account_set_password(account, p1); | |
497 | |
498 gg_change_passwd_free(h); | |
499 | |
500 gaim_notify_info(account, _("Change password for the Gadu-Gadu account"), | |
501 _("Password was changed successfully!"), NULL); | |
502 | |
503 exit_err: | |
504 g_free(cur); | |
505 g_free(p1); | |
506 g_free(p2); | |
507 g_free(t); | |
508 g_free(info->chpasswd_token->token_id); | |
509 g_free(info->chpasswd_token); | |
510 } | |
511 /* }}} */ | |
2393 | 512 |
11360 | 513 /* |
514 */ | |
515 /* static void ggp_change_passwd(GaimPluginAction *action) {{{ */ | |
516 static void ggp_change_passwd(GaimPluginAction *action) | |
517 { | |
518 GaimConnection *gc = (GaimConnection *)action->context; | |
519 GGPInfo *info = gc->proto_data; | |
520 GGPToken *token; | |
521 | |
522 GaimRequestFields *fields; | |
523 GaimRequestFieldGroup *group; | |
524 GaimRequestField *field; | |
525 | |
526 struct gg_http *req; | |
527 struct gg_token *t; | |
528 gchar *msg; | |
529 | |
530 gaim_debug_info("gg", "token: requested.\n"); | |
531 | |
532 /* TODO: This should be async. */ | |
533 if ((req = gg_token(0)) == NULL) { | |
534 gaim_notify_error(gaim_connection_get_account(gc), | |
535 _("Token Error"), | |
536 _("Unable to fetch the token.\n"), NULL); | |
2393 | 537 return; |
538 } | |
11360 | 539 |
540 t = req->data; | |
541 | |
542 token = g_new0(GGPToken, 1); | |
543 token->token_id = g_strdup(t->tokenid); | |
544 info->chpasswd_token = token; | |
545 | |
546 | |
547 fields = gaim_request_fields_new(); | |
548 group = gaim_request_field_group_new(NULL); | |
549 gaim_request_fields_add_group(fields, group); | |
550 | |
551 field = gaim_request_field_string_new("password_cur", _("Current password"), "", FALSE); | |
552 gaim_request_field_string_set_masked(field, TRUE); | |
553 gaim_request_field_group_add_field(group, field); | |
554 | |
555 field = gaim_request_field_string_new("password1", _("Password"), "", FALSE); | |
556 gaim_request_field_string_set_masked(field, TRUE); | |
557 gaim_request_field_group_add_field(group, field); | |
558 | |
559 field = gaim_request_field_string_new("password2", _("Password (retype)"), "", FALSE); | |
560 gaim_request_field_string_set_masked(field, TRUE); | |
561 gaim_request_field_group_add_field(group, field); | |
562 | |
563 field = gaim_request_field_string_new("token", _("Enter current token"), "", FALSE); | |
564 gaim_request_field_string_set_masked(field, FALSE); | |
565 gaim_request_field_group_add_field(group, field); | |
566 | |
567 /* original size: 60x24 */ | |
568 field = gaim_request_field_image_new("token_img", _("Current token"), req->body, req->body_size); | |
569 gaim_request_field_group_add_field(group, field); | |
570 | |
571 gg_token_free(req); | |
572 | |
573 msg = g_strdup_printf("%s %d", | |
574 _("Please, enter your current password and your new password for UIN: "), | |
575 ggp_get_uin(gaim_connection_get_account(gc))); | |
576 | |
577 gaim_request_fields(gc, | |
578 _("Change Gadu-Gadu Password"), | |
579 _("Change Gadu-Gadu Password"), | |
580 msg, | |
581 fields, _("OK"), G_CALLBACK(ggp_callback_change_passwd_ok), | |
582 _("Cancel"), NULL, gc); | |
583 | |
584 g_free(msg); | |
585 } | |
586 /* }}} */ | |
587 | |
11414 | 588 /* ----- CONFERENCES ---------------------------------------------------- */ |
589 | |
11394 | 590 /* |
591 */ | |
592 /* static void ggp_callback_add_to_chat_ok(GaimConnection *gc, GaimRequestFields *fields) {{{ */ | |
593 static void ggp_callback_add_to_chat_ok(GaimConnection *gc, GaimRequestFields *fields) | |
594 { | |
595 GGPInfo *info = gc->proto_data; | |
596 GaimRequestField *field; | |
597 const GList *sel, *l; | |
598 | |
599 field = gaim_request_fields_get_field(fields, "name"); | |
600 sel = gaim_request_field_list_get_selected(field); | |
601 gaim_debug_info("gg", "selected chat %s for buddy %s\n", sel->data, info->tmp_buddy); | |
602 | |
603 for (l = info->chats; l != NULL; l = l->next) { | |
604 GGPChat *chat = l->data; | |
605 | |
606 if (g_utf8_collate(chat->name, sel->data) == 0) { | |
607 chat->participants = g_list_append(chat->participants, info->tmp_buddy); | |
608 break; | |
609 } | |
610 } | |
611 } | |
612 /* }}} */ | |
613 | |
614 /* | |
615 */ | |
616 /* static void ggp_bmenu_add_to_chat(GaimBlistNode *node, gpointer ignored) {{{ */ | |
617 static void ggp_bmenu_add_to_chat(GaimBlistNode *node, gpointer ignored) | |
618 { | |
619 GaimBuddy *buddy; | |
620 GaimConnection *gc; | |
621 GGPInfo *info; | |
622 | |
623 GaimRequestFields *fields; | |
624 GaimRequestFieldGroup *group; | |
625 GaimRequestField *field; | |
626 | |
627 GList *l; | |
628 gchar *msg; | |
629 | |
630 buddy = (GaimBuddy *)node; | |
631 gc = gaim_account_get_connection(gaim_buddy_get_account(buddy)); | |
632 info = gc->proto_data; | |
633 | |
634 /* TODO: It tmp_buddy != NULL then stop! */ | |
635 info->tmp_buddy = g_strdup(gaim_buddy_get_name(buddy)); | |
636 | |
637 fields = gaim_request_fields_new(); | |
638 group = gaim_request_field_group_new(NULL); | |
639 gaim_request_fields_add_group(fields, group); | |
640 | |
641 field = gaim_request_field_list_new("name", "Chat name"); | |
642 for (l = info->chats; l != NULL; l = l->next) { | |
643 GGPChat *chat = l->data; | |
644 gaim_debug_info("gg", "adding chat %s\n", chat->name); | |
645 gaim_request_field_list_add(field, g_strdup(chat->name), g_strdup(chat->name)); | |
646 } | |
647 gaim_request_field_group_add_field(group, field); | |
648 | |
649 msg = g_strdup_printf(_("Select a chat for buddy: %s"), gaim_buddy_get_name(buddy)); | |
650 gaim_request_fields(gc, | |
651 _("Add to chat..."), | |
652 _("Add to chat..."), | |
653 msg, | |
654 fields, | |
655 _("Add"), G_CALLBACK(ggp_callback_add_to_chat_ok), | |
656 _("Cancel"), NULL, gc); | |
657 g_free(msg); | |
658 } | |
659 /* }}} */ | |
660 | |
11414 | 661 /* ----- BLOCK BUDDIES -------------------------------------------------- */ |
662 | |
11410 | 663 /* |
664 */ | |
665 /* static void ggp_bmenu_block(GaimBlistNode *node, gpointer ignored) {{{ */ | |
666 static void ggp_bmenu_block(GaimBlistNode *node, gpointer ignored) | |
667 { | |
668 GaimConnection *gc; | |
669 GaimBuddy *buddy; | |
670 GGPInfo *info; | |
671 uin_t uin; | |
672 | |
673 buddy = (GaimBuddy *)node; | |
674 gc = gaim_account_get_connection(gaim_buddy_get_account(buddy)); | |
675 info = gc->proto_data; | |
676 | |
677 uin = ggp_str_to_uin(gaim_buddy_get_name(buddy)); | |
678 | |
679 if (gaim_blist_node_get_bool(node, "blocked")) { | |
680 gaim_blist_node_set_bool(node, "blocked", FALSE); | |
681 gg_remove_notify_ex(info->session, uin, GG_USER_BLOCKED); | |
682 gg_add_notify_ex(info->session, uin, GG_USER_NORMAL); | |
683 gaim_debug_info("gg", "send: uin=%d; mode=NORMAL\n", uin); | |
684 } else { | |
685 gaim_blist_node_set_bool(node, "blocked", TRUE); | |
686 gg_remove_notify_ex(info->session, uin, GG_USER_NORMAL); | |
687 gg_add_notify_ex(info->session, uin, GG_USER_BLOCKED); | |
688 gaim_debug_info("gg", "send: uin=%d; mode=BLOCKED\n", uin); | |
689 } | |
690 } | |
691 /* }}} */ | |
692 | |
11360 | 693 /* ---------------------------------------------------------------------- */ |
11414 | 694 /* ----- INTERNAL CALLBACKS --------------------------------------------- */ |
695 /* ---------------------------------------------------------------------- */ | |
696 | |
697 /** | |
698 * Handle change of the status of the buddy. | |
699 * | |
700 * @param gc GaimConnection | |
701 * @param uin UIN of the buddy. | |
702 * @param status ID of the status. | |
703 * @param descr Description. | |
704 */ | |
705 /* static void ggp_generic_status_handler(GaimConnection *gc, uin_t uin, int status, const char *descr) {{{ */ | |
706 static void ggp_generic_status_handler(GaimConnection *gc, uin_t uin, int status, const char *descr) | |
707 { | |
708 gchar *from; | |
709 const char *st; | |
710 gchar *msg; | |
711 | |
712 from = g_strdup_printf("%ld", (unsigned long int)uin); | |
713 switch (status) { | |
714 case GG_STATUS_NOT_AVAIL: | |
715 case GG_STATUS_NOT_AVAIL_DESCR: | |
716 st = "offline"; | |
717 break; | |
718 case GG_STATUS_AVAIL: | |
719 case GG_STATUS_AVAIL_DESCR: | |
11638 | 720 st = "available"; |
11414 | 721 break; |
722 case GG_STATUS_BUSY: | |
723 case GG_STATUS_BUSY_DESCR: | |
724 st = "away"; | |
725 break; | |
726 case GG_STATUS_BLOCKED: | |
727 /* user is blocking us.... */ | |
728 st = "blocked"; | |
729 break; | |
730 default: | |
11638 | 731 st = "available"; |
11414 | 732 gaim_debug_info("gg", "GG_EVENT_NOTIFY: Unknown status: %d\n", status); |
733 break; | |
734 } | |
735 | |
736 gaim_debug_info("gg", "st = %s\n", st); | |
737 msg = charset_convert(descr, "CP1250", "UTF-8"); | |
738 gaim_prpl_got_user_status(gaim_connection_get_account(gc), from, st, "message", msg, NULL); | |
739 g_free(from); | |
740 g_free(msg); | |
741 } | |
742 /* }}} */ | |
743 | |
744 /** | |
745 * Dispatch a message received from a buddy. | |
746 * | |
747 * @param gc GaimConnection. | |
748 * @param ev Gadu-Gadu event structure. | |
749 */ | |
750 /* static void ggp_recv_message_handler(GaimConnection *gc, const struct gg_event *ev) {{{ */ | |
751 static void ggp_recv_message_handler(GaimConnection *gc, const struct gg_event *ev) | |
752 { | |
753 GGPInfo *info = gc->proto_data; | |
754 GaimConversation *conv; | |
755 gchar *from; | |
756 gchar *msg; | |
757 gchar *tmp; | |
758 const char *chat_name; | |
759 int chat_id; | |
760 | |
761 from = g_strdup_printf("%lu", (unsigned long int)ev->event.msg.sender); | |
762 | |
763 msg = charset_convert((const char *)ev->event.msg.message, | |
764 "CP1250", "UTF-8"); | |
765 gaim_str_strip_cr(msg); | |
766 tmp = g_markup_escape_text(msg, -1); | |
767 | |
768 gaim_debug_info("gg", "msg form (%s): %s (class = %d; rcpt_count = %d)\n", | |
769 from, tmp, ev->event.msg.msgclass, ev->event.msg.recipients_count); | |
770 | |
771 /* | |
772 * Chat between only two presons will be treated as a private message. | |
773 * It's due to some broken clients that send private messages | |
774 * with msgclass == CHAT | |
775 */ | |
776 if (ev->event.msg.recipients_count == 0) { | |
777 serv_got_im(gc, from, tmp, 0, ev->event.msg.time); | |
778 } else { | |
779 chat_name = ggp_confer_find_by_participants(gc, | |
780 ev->event.msg.recipients, | |
781 ev->event.msg.recipients_count); | |
782 if (chat_name == NULL) { | |
783 chat_name = ggp_confer_add_new(gc, NULL); | |
784 serv_got_joined_chat(gc, info->chats_count, chat_name); | |
785 ggp_confer_participants_add_uin(gc, chat_name, ev->event.msg.sender); | |
786 ggp_confer_participants_add(gc, chat_name, ev->event.msg.recipients, | |
787 ev->event.msg.recipients_count); | |
788 } | |
789 conv = ggp_confer_find_by_name(gc, chat_name); | |
790 chat_id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)); | |
791 serv_got_chat_in(gc, chat_id, ggp_buddy_get_name(gc, ev->event.msg.sender), | |
792 0, msg, ev->event.msg.time); | |
793 } | |
794 g_free(msg); | |
795 g_free(tmp); | |
796 g_free(from); | |
797 } | |
798 /* }}} */ | |
799 | |
800 /* | |
801 */ | |
802 /* static void ggp_callback_recv(gpointer _gc, gint fd, GaimInputCondition cond) {{{ */ | |
803 static void ggp_callback_recv(gpointer _gc, gint fd, GaimInputCondition cond) | |
804 { | |
805 GaimConnection *gc = _gc; | |
806 GGPInfo *info = gc->proto_data; | |
807 struct gg_event *ev; | |
808 int i; | |
809 | |
810 if (!(ev = gg_watch_fd(info->session))) { | |
811 gaim_debug_error("gg", "ggp_callback_recv: gg_watch_fd failed -- CRITICAL!\n"); | |
812 gaim_connection_error(gc, _("Unable to read socket")); | |
813 return; | |
814 } | |
815 | |
816 switch (ev->type) { | |
817 case GG_EVENT_NONE: | |
818 /* Nothing happened. */ | |
819 break; | |
820 case GG_EVENT_MSG: | |
821 ggp_recv_message_handler(gc, ev); | |
822 break; | |
823 case GG_EVENT_ACK: | |
824 gaim_debug_info("gg", "message sent to: %ld, delivery status=%d, seq=%d\n", | |
825 ev->event.ack.recipient, ev->event.ack.status, ev->event.ack.seq); | |
826 break; | |
827 case GG_EVENT_NOTIFY: | |
828 case GG_EVENT_NOTIFY_DESCR: | |
829 { | |
830 struct gg_notify_reply *n; | |
831 char *descr; | |
832 | |
833 gaim_debug_info("gg", "notify_pre: (%d) status: %d\n", | |
834 ev->event.notify->uin, | |
835 ev->event.notify->status); | |
836 | |
837 n = (ev->type == GG_EVENT_NOTIFY) ? ev->event.notify | |
838 : ev->event.notify_descr.notify; | |
839 | |
840 for (; n->uin; n++) { | |
841 descr = (ev->type == GG_EVENT_NOTIFY) ? NULL | |
842 : ev->event.notify_descr.descr; | |
843 gaim_debug_info("gg", "notify: (%d) status: %d; descr: %s\n", | |
844 n->uin, n->status, descr); | |
845 | |
846 ggp_generic_status_handler(gc, | |
847 n->uin, n->status, descr); | |
848 } | |
849 } | |
850 break; | |
851 case GG_EVENT_NOTIFY60: | |
852 gaim_debug_info("gg", "notify60_pre: (%d) status=%d; version=%d; descr=%s\n", | |
853 ev->event.notify60->uin, ev->event.notify60->status, | |
854 ev->event.notify60->version, ev->event.notify60->descr); | |
855 | |
856 for (i = 0; ev->event.notify60[i].uin; i++) { | |
857 gaim_debug_info("gg", "notify60: (%d) status=%d; version=%d; descr=%s\n", | |
858 ev->event.notify60[i].uin, ev->event.notify60[i].status, | |
859 ev->event.notify60[i].version, ev->event.notify60[i].descr); | |
860 | |
861 ggp_generic_status_handler(gc, | |
862 ev->event.notify60[i].uin, | |
863 ev->event.notify60[i].status, | |
864 ev->event.notify60[i].descr); | |
865 } | |
866 break; | |
867 case GG_EVENT_STATUS: | |
868 gaim_debug_info("gg", "status: (%d) status=%d; descr=%s\n", | |
869 ev->event.status.uin, ev->event.status.status, | |
870 ev->event.status.descr); | |
871 | |
872 ggp_generic_status_handler(gc, | |
873 ev->event.status.uin, | |
874 ev->event.status.status, | |
875 ev->event.status.descr); | |
876 break; | |
877 case GG_EVENT_STATUS60: | |
878 gaim_debug_info("gg", "status60: (%d) status=%d; version=%d; descr=%s\n", | |
879 ev->event.status60.uin, | |
880 ev->event.status60.status, | |
881 ev->event.status60.version, | |
882 ev->event.status60.descr); | |
883 | |
884 ggp_generic_status_handler(gc, | |
885 ev->event.status60.uin, | |
886 ev->event.status60.status, | |
887 ev->event.status60.descr); | |
888 break; | |
889 case GG_EVENT_USERLIST: | |
890 if (ev->event.userlist.type == GG_USERLIST_GET_REPLY) { | |
891 gaim_debug_info("gg", "GG_USERLIST_GET_REPLY\n"); | |
892 if (ev->event.userlist.reply != NULL) { | |
893 ggp_buddylist_load(gc, ev->event.userlist.reply); | |
894 } | |
895 break; | |
896 } else { | |
897 gaim_debug_info("gg", "GG_USERLIST_PUT_REPLY. Userlist stored on the server.\n"); | |
898 } | |
899 break; | |
900 case GG_EVENT_PUBDIR50_SEARCH_REPLY: | |
901 { | |
902 GaimNotifySearchResults *results; | |
903 GaimNotifySearchColumn *column; | |
904 gg_pubdir50_t req = ev->event.pubdir50; | |
905 int res_count = 0; | |
906 int start; | |
907 int i; | |
908 | |
909 res_count = gg_pubdir50_count(req); | |
910 if (res_count < 1) { | |
911 gaim_debug_info("gg", "GG_EVENT_PUBDIR50_SEARCH_REPLY: Nothing found\n"); | |
912 return; | |
913 } | |
914 res_count = (res_count > 20) ? 20 : res_count; | |
915 | |
916 results = gaim_notify_searchresults_new(); | |
917 | |
918 column = gaim_notify_searchresults_column_new("UIN"); | |
919 gaim_notify_searchresults_column_add(results, column); | |
920 | |
921 column = gaim_notify_searchresults_column_new("First name"); | |
922 gaim_notify_searchresults_column_add(results, column); | |
923 | |
924 column = gaim_notify_searchresults_column_new("Nick name"); | |
925 gaim_notify_searchresults_column_add(results, column); | |
926 | |
927 column = gaim_notify_searchresults_column_new("City"); | |
928 gaim_notify_searchresults_column_add(results, column); | |
929 | |
930 column = gaim_notify_searchresults_column_new("Birth year"); | |
931 gaim_notify_searchresults_column_add(results, column); | |
932 | |
933 gaim_debug_info("gg", "Going with %d entries\n", res_count); | |
934 | |
935 start = (int)ggp_str_to_uin(gg_pubdir50_get(req, 0, GG_PUBDIR50_START)); | |
936 gaim_debug_info("gg", "start = %d\n", start); | |
937 | |
938 for (i = 0; i < res_count; i++) { | |
939 GList *row = NULL; | |
940 char *birth = ggp_search_get_result(req, i, GG_PUBDIR50_BIRTHYEAR); | |
941 | |
942 /* TODO: Status will be displayed as an icon. */ | |
943 /* row = g_list_append(row, ggp_search_get_result(req, i, GG_PUBDIR50_STATUS)); */ | |
944 row = g_list_append(row, ggp_search_get_result(req, i, GG_PUBDIR50_UIN)); | |
945 row = g_list_append(row, ggp_search_get_result(req, i, GG_PUBDIR50_FIRSTNAME)); | |
946 row = g_list_append(row, ggp_search_get_result(req, i, GG_PUBDIR50_NICKNAME)); | |
947 row = g_list_append(row, ggp_search_get_result(req, i, GG_PUBDIR50_CITY)); | |
948 row = g_list_append(row, (birth && strncmp(birth, "0", 1)) ? birth : g_strdup("-")); | |
949 gaim_notify_searchresults_row_add(results, row); | |
950 if (i == res_count - 1) { | |
951 g_free(info->search_form->last_uin); | |
952 info->search_form->last_uin = ggp_search_get_result(req, i, GG_PUBDIR50_UIN); | |
953 } | |
954 } | |
955 | |
956 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_CONTINUE, ggp_callback_show_next); | |
957 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_ADD_BUDDY, ggp_callback_add_buddy); | |
958 if (info->searchresults_window == NULL) { | |
959 void *h = gaim_notify_searchresults(gc, _("Gadu-Gadu Public Directory"), | |
960 _("Search results"), NULL, results, NULL, NULL); | |
961 info->searchresults_window = h; | |
962 } else { | |
963 gaim_notify_searchresults_new_rows(gc, results, info->searchresults_window, NULL); | |
964 } | |
965 } | |
966 break; | |
967 default: | |
968 gaim_debug_error("gg", "unsupported event type=%d\n", ev->type); | |
969 break; | |
970 } | |
971 | |
972 gg_free_event(ev); | |
973 } | |
974 /* }}} */ | |
975 | |
976 /* ---------------------------------------------------------------------- */ | |
11360 | 977 /* ----- GaimPluginProtocolInfo ----------------------------------------- */ |
978 /* ---------------------------------------------------------------------- */ | |
979 | |
980 /* static const char *ggp_list_icon(GaimAccount *account, GaimBuddy *buddy) {{{ */ | |
981 static const char *ggp_list_icon(GaimAccount *account, GaimBuddy *buddy) | |
982 { | |
983 return "gadu-gadu"; | |
984 } | |
985 /* }}} */ | |
986 | |
987 /* static void ggp_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) {{{ */ | |
988 static void ggp_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) | |
989 { | |
990 GaimPresence *presence = gaim_buddy_get_presence(b); | |
991 | |
992 /* | |
993 * Note to myself: | |
994 * The only valid status types are those defined | |
995 * in prpl_info->status_types. | |
996 * | |
997 * Usable icons: away, blocked, dnd, extendedaway, | |
998 * freeforchat, ignored, invisible, na, offline. | |
999 */ | |
1000 | |
1001 if (!GAIM_BUDDY_IS_ONLINE(b)) { | |
1002 *se = "offline"; | |
1003 } else if (gaim_presence_is_status_active(presence, "away")) { | |
1004 *se = "away"; | |
11638 | 1005 } else if (gaim_presence_is_status_active(presence, "available")) { |
11360 | 1006 *se = "online"; |
1007 } else if (gaim_presence_is_status_active(presence, "offline")) { | |
1008 *se = "offline"; | |
1009 } else if (gaim_presence_is_status_active(presence, "blocked")) { | |
1010 *se = "blocked"; | |
1011 } else { | |
1012 *se = "offline"; | |
1013 gaim_debug_info("gg", "ggp_list_emblems: unknown status\n"); | |
1014 } | |
2393 | 1015 } |
11360 | 1016 /* }}} */ |
2393 | 1017 |
11360 | 1018 /* static char *ggp_status_text(GaimBuddy *b) {{{ */ |
1019 static char *ggp_status_text(GaimBuddy *b) | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2835
diff
changeset
|
1020 { |
11360 | 1021 GaimStatus *status; |
1022 const char *msg; | |
1023 char *text; | |
1024 char *tmp; | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2835
diff
changeset
|
1025 |
11360 | 1026 status = gaim_presence_get_active_status(gaim_buddy_get_presence(b)); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2835
diff
changeset
|
1027 |
11360 | 1028 msg = gaim_status_get_attr_string(status, "message"); |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2835
diff
changeset
|
1029 |
11360 | 1030 if (msg != NULL) { |
1031 tmp = gaim_markup_strip_html(msg); | |
1032 text = g_markup_escape_text(tmp, -1); | |
1033 g_free(tmp); | |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2835
diff
changeset
|
1034 |
11360 | 1035 return text; |
1036 } else { | |
1037 tmp = g_strdup(gaim_status_get_name(status)); | |
1038 text = g_markup_escape_text(tmp, -1); | |
1039 g_free(tmp); | |
1040 | |
1041 return text; | |
8997 | 1042 } |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2835
diff
changeset
|
1043 } |
11360 | 1044 /* }}} */ |
2846
4b3f17ca66bf
[gaim-migrate @ 2859]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2835
diff
changeset
|
1045 |
11360 | 1046 /* static char *ggp_tooltip_text(GaimBuddy *b) {{{ */ |
1047 static char *ggp_tooltip_text(GaimBuddy *b) | |
1048 { | |
1049 GaimStatus *status; | |
1050 char *text; | |
1051 gchar *ret; | |
1052 const char *msg, *name; | |
1053 | |
1054 status = gaim_presence_get_active_status(gaim_buddy_get_presence(b)); | |
1055 msg = gaim_status_get_attr_string(status, "message"); | |
1056 name = gaim_status_get_name(status); | |
1057 | |
1058 if (msg != NULL) { | |
1059 char *tmp = gaim_markup_strip_html(msg); | |
1060 text = g_markup_escape_text(tmp, -1); | |
1061 g_free(tmp); | |
1062 | |
1063 ret = g_strdup_printf("\n<b>%s:</b> %s: %s", | |
1064 _("Status"), name, text); | |
1065 | |
1066 g_free(text); | |
1067 } else { | |
1068 ret = g_strdup_printf("\n<b>%s:</b> %s", | |
1069 _("Status"), name); | |
1070 } | |
1071 | |
1072 return ret; | |
1073 } | |
1074 /* }}} */ | |
1075 | |
1076 /* static GList *ggp_status_types(GaimAccount *account) {{{ */ | |
1077 static GList *ggp_status_types(GaimAccount *account) | |
1078 { | |
1079 GaimStatusType *type; | |
1080 GList *types = NULL; | |
1081 | |
1082 type = gaim_status_type_new_with_attrs(GAIM_STATUS_OFFLINE, "offline", _("Offline"), | |
1083 TRUE, TRUE, FALSE, "message", _("Message"), | |
1084 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
1085 types = g_list_append(types, type); | |
1086 | |
11638 | 1087 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, "available", _("Online"), |
11360 | 1088 TRUE, TRUE, FALSE, "message", _("Message"), |
1089 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
1090 types = g_list_append(types, type); | |
1091 | |
1092 /* | |
11638 | 1093 * Without this selecting Invisible as own status doesn't |
11360 | 1094 * work. It's not used and not needed to show status of buddies. |
1095 */ | |
1096 type = gaim_status_type_new_with_attrs(GAIM_STATUS_HIDDEN, "invisible", _("Invisible"), | |
1097 TRUE, TRUE, FALSE, "message", _("Message"), | |
1098 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
1099 types = g_list_append(types, type); | |
1100 | |
1101 /* type = gaim_status_type_new_with_attrs(GAIM_STATUS_UNAVAILABLE, "not-available", "Not Available", */ | |
1102 /* TRUE, TRUE, FALSE, "message", _("Message"), */ | |
1103 /* gaim_value_new(GAIM_TYPE_STRING), NULL); */ | |
1104 /* types = g_list_append(types, type); */ | |
1105 | |
1106 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, "away", _("Busy"), | |
1107 TRUE, TRUE, FALSE, "message", _("Message"), | |
1108 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
1109 types = g_list_append(types, type); | |
1110 | |
1111 type = gaim_status_type_new_with_attrs(GAIM_STATUS_HIDDEN, "blocked", _("Blocked"), | |
1112 TRUE, TRUE, FALSE, "message", _("Message"), | |
1113 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
1114 types = g_list_append(types, type); | |
1115 | |
1116 return types; | |
1117 } | |
1118 /* }}} */ | |
1119 | |
1120 /* static GList *ggp_blist_node_menu(GaimBlistNode *node) {{{ */ | |
1121 static GList *ggp_blist_node_menu(GaimBlistNode *node) | |
2393 | 1122 { |
11394 | 1123 GaimBlistNodeAction *act; |
2393 | 1124 GList *m = NULL; |
4333 | 1125 |
11360 | 1126 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) |
1127 return NULL; | |
4333 | 1128 |
11410 | 1129 act = gaim_blist_node_action_new(_("Add to chat"), ggp_bmenu_add_to_chat, NULL, NULL); |
1130 m = g_list_append(m, act); | |
1131 | |
1132 if (gaim_blist_node_get_bool(node, "blocked")) | |
1133 act = gaim_blist_node_action_new(_("Unblock"), ggp_bmenu_block, NULL, NULL); | |
1134 else | |
1135 act = gaim_blist_node_action_new(_("Block"), ggp_bmenu_block, NULL, NULL); | |
11394 | 1136 m = g_list_append(m, act); |
2393 | 1137 |
1138 return m; | |
1139 } | |
11360 | 1140 /* }}} */ |
2393 | 1141 |
11394 | 1142 /* static GList *ggp_chat_info(GaimConnection *gc) {{{ */ |
1143 static GList *ggp_chat_info(GaimConnection *gc) | |
1144 { | |
1145 GList *m = NULL; | |
1146 struct proto_chat_entry *pce; | |
1147 | |
1148 pce = g_new0(struct proto_chat_entry, 1); | |
1149 pce->label = _("Chat _name:"); | |
1150 pce->identifier = "name"; | |
1151 pce->required = TRUE; | |
1152 m = g_list_append(m, pce); | |
1153 | |
1154 return m; | |
1155 } | |
1156 /* }}} */ | |
1157 | |
11360 | 1158 /* static void ggp_login(GaimAccount *account, GaimStatus *status) {{{ */ |
11837 | 1159 static void ggp_login(GaimAccount *account) |
2393 | 1160 { |
11360 | 1161 GaimConnection *gc = gaim_account_get_connection(account); |
1162 struct gg_login_params *glp = g_new0(struct gg_login_params, 1); | |
1163 GGPInfo *info = g_new0(GGPInfo, 1); | |
1164 | |
11394 | 1165 /* Probably this should be move to some *_new() function. */ |
11360 | 1166 info->session = NULL; |
1167 info->searchresults_window = NULL; | |
11394 | 1168 info->chats = NULL; |
1169 info->chats_count = 0; | |
11360 | 1170 |
1171 gc->proto_data = info; | |
1172 | |
1173 glp->uin = ggp_get_uin(account); | |
1174 glp->password = (char *)gaim_account_get_password(account); | |
1175 | |
1176 glp->async = 0; | |
11837 | 1177 /* TODO: Set the status correctly here. */ |
11360 | 1178 glp->status = GG_STATUS_AVAIL; |
1179 glp->tls = 0; | |
1180 | |
1181 info->session = gg_login(glp); | |
1182 if (info->session == NULL) { | |
1183 gaim_connection_error(gc, _("Connection failed.")); | |
1184 g_free(glp); | |
1185 return; | |
1186 } | |
1187 gaim_debug_info("gg", "ggp_login: so far so good.\n"); | |
1188 | |
1189 gc->inpa = gaim_input_add(info->session->fd, GAIM_INPUT_READ, ggp_callback_recv, gc); | |
2393 | 1190 |
11360 | 1191 gg_change_status(info->session, GG_STATUS_AVAIL); |
1192 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
1193 ggp_buddylist_send(gc); | |
1194 } | |
1195 /* }}} */ | |
1196 | |
1197 /* static void ggp_close(GaimConnection *gc) {{{ */ | |
1198 static void ggp_close(GaimConnection *gc) | |
1199 { | |
8997 | 1200 |
11360 | 1201 if (gc == NULL) { |
1202 gaim_debug_info("gg", "gc == NULL\n"); | |
1203 return; | |
1204 } | |
1205 | |
11538
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1206 if (gc->proto_data) { |
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1207 GGPInfo *info = gc->proto_data; |
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1208 /* XXX: Any way to pass description here? */ |
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1209 if (info->session != NULL) { |
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1210 gg_change_status(info->session, GG_STATUS_NOT_AVAIL); |
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1211 gg_logoff(info->session); |
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1212 gg_free_session(info->session); |
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1213 } |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
1214 g_free(info); |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
1215 gc->proto_data = NULL; |
11538
5c6c2e893803
[gaim-migrate @ 13792]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11522
diff
changeset
|
1216 } |
11360 | 1217 |
1218 if (gc->inpa > 0) | |
1219 gaim_input_remove(gc->inpa); | |
1220 | |
1221 ggp_buddylist_offline(gc); | |
2393 | 1222 |
11360 | 1223 gaim_debug_info("gg", "Connection closed.\n"); |
1224 } | |
1225 /* }}} */ | |
1226 | |
1227 /* static int ggp_send_im(GaimConnection *gc, const char *who, const char *msg, GaimConvImFlags flags) {{{ */ | |
1228 static int ggp_send_im(GaimConnection *gc, const char *who, const char *msg, GaimConvImFlags flags) | |
1229 { | |
1230 GGPInfo *info = gc->proto_data; | |
11394 | 1231 char *tmp; |
11360 | 1232 |
1233 if (strlen(msg) == 0) | |
1234 return 1; | |
1235 | |
11565 | 1236 gaim_debug_info("gg", "ggp_send_im: msg = %s\n", msg); |
11360 | 1237 tmp = charset_convert(msg, "UTF-8", "CP1250"); |
2393 | 1238 |
11360 | 1239 if (tmp != NULL && strlen(tmp) > 0) { |
11565 | 1240 if (gg_send_message(info->session, GG_CLASS_CHAT, ggp_str_to_uin(who), |
1241 (unsigned char *)tmp) < 0) { | |
11360 | 1242 return -1; |
1243 } | |
1244 } | |
11565 | 1245 g_free(tmp); |
11360 | 1246 |
1247 return 1; | |
1248 } | |
1249 /* }}} */ | |
1250 | |
1251 /* static void ggp_get_info(GaimConnection *gc, const char *name) { {{{ */ | |
1252 static void ggp_get_info(GaimConnection *gc, const char *name) | |
1253 { | |
1254 GGPInfo *info = gc->proto_data; | |
1255 GGPSearchForm *form; | |
2393 | 1256 |
11414 | 1257 form = ggp_search_form_new(); |
11360 | 1258 info->search_form = form; |
1259 | |
1260 form->uin = g_strdup(name); | |
1261 form->offset = g_strdup("0"); | |
1262 form->last_uin = g_strdup("0"); | |
1263 | |
11414 | 1264 ggp_search_start(gc, form); |
11360 | 1265 } |
1266 /* }}} */ | |
1267 | |
1268 /* static void ggp_set_status(GaimAccount *account, GaimStatus *status) {{{ */ | |
1269 static void ggp_set_status(GaimAccount *account, GaimStatus *status) | |
1270 { | |
1271 GaimStatusPrimitive prim; | |
1272 GaimConnection *gc; | |
1273 GGPInfo *info; | |
11397 | 1274 const char *status_id, *msg; |
11360 | 1275 int new_status, new_status_descr; |
1276 | |
1277 prim = gaim_status_type_get_primitive(gaim_status_get_type(status)); | |
1278 | |
1279 if (!gaim_status_is_active(status)) | |
1280 return; | |
1281 | |
1282 gc = gaim_account_get_connection(account); | |
1283 info = gc->proto_data; | |
1284 | |
1285 status_id = gaim_status_get_id(status); | |
1286 | |
1287 gaim_debug_info("gg", "ggp_set_status: Requested status = %s\n", status_id); | |
2393 | 1288 |
11360 | 1289 if (strcmp(status_id, "available") == 0) { |
1290 new_status = GG_STATUS_AVAIL; | |
1291 new_status_descr = GG_STATUS_AVAIL_DESCR; | |
1292 } else if (strcmp(status_id, "away") == 0) { | |
1293 new_status = GG_STATUS_BUSY; | |
1294 new_status_descr = GG_STATUS_BUSY_DESCR; | |
1295 } else if (strcmp(status_id, "invisible") == 0) { | |
1296 new_status = GG_STATUS_INVISIBLE; | |
1297 new_status_descr = GG_STATUS_INVISIBLE_DESCR; | |
1298 } else { | |
1299 new_status = GG_STATUS_AVAIL; | |
1300 new_status_descr = GG_STATUS_AVAIL_DESCR; | |
1301 gaim_debug_info("gg", "ggp_set_status: uknown status requested (status_id=%s)\n", status_id); | |
1302 } | |
4916 | 1303 |
11397 | 1304 msg = gaim_status_get_attr_string(status, "message"); |
11360 | 1305 |
1306 if (msg == NULL) { | |
1307 gaim_debug_info("gg", "ggp_set_status: msg == NULL\n"); | |
1308 gg_change_status(info->session, new_status); | |
1309 } else { | |
1310 char *tmp = charset_convert(msg, "UTF-8", "CP1250"); | |
1311 gaim_debug_info("gg", "ggp_set_status: msg != NULL. msg = %s\n", tmp); | |
1312 gaim_debug_info("gg", "ggp_set_status: gg_change_status_descr() = %d\n", | |
1313 gg_change_status_descr(info->session, new_status_descr, tmp)); | |
1314 g_free(tmp); | |
1315 } | |
9944 | 1316 |
11360 | 1317 } |
1318 /* }}} */ | |
1319 | |
1320 /* static void ggp_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) {{{ */ | |
1321 static void ggp_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
1322 { | |
1323 GGPInfo *info = gc->proto_data; | |
1324 | |
1325 gg_add_notify(info->session, ggp_str_to_uin(buddy->name)); | |
1326 } | |
1327 /* }}} */ | |
1328 | |
1329 /* static void ggp_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) {{{ */ | |
1330 static void ggp_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
1331 { | |
1332 GGPInfo *info = gc->proto_data; | |
1333 | |
1334 gg_remove_notify(info->session, ggp_str_to_uin(buddy->name)); | |
1335 } | |
1336 /* }}} */ | |
1337 | |
11394 | 1338 /* static void ggp_join_chat(GaimConnection *gc, GHashTable *data) {{{ */ |
1339 static void ggp_join_chat(GaimConnection *gc, GHashTable *data) | |
1340 { | |
1341 GGPInfo *info = gc->proto_data; | |
1342 GGPChat *chat; | |
1343 char *chat_name; | |
1344 GList *l; | |
1345 | |
1346 chat_name = g_hash_table_lookup(data, "name"); | |
1347 | |
1348 if (chat_name == NULL) | |
1349 return; | |
1350 | |
1351 gaim_debug_info("gg", "joined %s chat\n", chat_name); | |
1352 | |
1353 for (l = info->chats; l != NULL; l = l->next) { | |
1354 chat = l->data; | |
1355 | |
1356 if (chat != NULL && g_utf8_collate(chat->name, chat_name) == 0) { | |
1357 gaim_notify_error(gc, _("Chat error"), | |
1358 _("This chat name is already in use"), NULL); | |
1359 return; | |
1360 } | |
1361 } | |
1362 | |
11414 | 1363 ggp_confer_add_new(gc, chat_name); |
11394 | 1364 serv_got_joined_chat(gc, info->chats_count, chat_name); |
1365 } | |
1366 /* }}} */ | |
1367 | |
1368 /* static char *ggp_get_chat_name(GHashTable *data) { {{{ */ | |
1369 static char *ggp_get_chat_name(GHashTable *data) { | |
1370 return g_strdup(g_hash_table_lookup(data, "name")); | |
1371 } | |
1372 /* }}} */ | |
1373 | |
1374 /* static int ggp_chat_send(GaimConnection *gc, int id, const char *message) {{{ */ | |
1375 static int ggp_chat_send(GaimConnection *gc, int id, const char *message) | |
1376 { | |
1377 GaimConversation *conv; | |
1378 GGPInfo *info = gc->proto_data; | |
1379 GGPChat *chat = NULL; | |
1380 GList *l; | |
1381 char *msg; | |
1382 uin_t *uins; | |
1383 int count = 0; | |
1384 | |
1385 if ((conv = gaim_find_chat(gc, id)) == NULL) | |
1386 return -EINVAL; | |
1387 | |
1388 for (l = info->chats; l != NULL; l = l->next) { | |
1389 chat = l->data; | |
1390 | |
1391 if (g_utf8_collate(chat->name, conv->name) == 0) { | |
1392 gaim_debug_info("gg", "found conv!\n"); | |
1393 break; | |
1394 } | |
1395 | |
1396 chat = NULL; | |
1397 } | |
1398 | |
1399 if (chat == NULL) { | |
1400 gaim_debug_error("gg", "ggp_chat_send: Hm... that's strange. No such chat?\n"); | |
1401 return -EINVAL; | |
1402 } | |
1403 | |
1404 uins = g_new0(uin_t, g_list_length(chat->participants)); | |
1405 for (l = chat->participants; l != NULL; l = l->next) { | |
1406 gchar *name = l->data; | |
1407 uin_t uin; | |
1408 | |
1409 if ((uin = ggp_str_to_uin(name)) != 0) | |
1410 uins[count++] = uin; | |
1411 } | |
1412 | |
1413 msg = charset_convert(message, "UTF-8", "CP1250"); | |
1414 gg_send_message_confer(info->session, GG_CLASS_CHAT, count, uins, (unsigned char *)msg); | |
1415 g_free(msg); | |
1416 g_free(uins); | |
1417 | |
1418 serv_got_chat_in(gc, id, gaim_account_get_username(gaim_connection_get_account(gc)), | |
1419 0, message, time(NULL)); | |
1420 | |
1421 return 0; | |
1422 } | |
1423 /* }}} */ | |
1424 | |
11360 | 1425 /* static void ggp_keepalive(GaimConnection *gc) {{{ */ |
1426 static void ggp_keepalive(GaimConnection *gc) | |
1427 { | |
1428 GGPInfo *info = gc->proto_data; | |
1429 | |
1430 /* gaim_debug_info("gg", "Keeping connection alive....\n"); */ | |
1431 | |
1432 if (gg_ping(info->session) < 0) { | |
1433 gaim_debug_info("gg", "Not connected to the server " | |
1434 "or gg_session is not correct\n"); | |
1435 gaim_connection_error(gc, _("Not connected to the server.")); | |
4916 | 1436 } |
2393 | 1437 } |
11360 | 1438 /* }}} */ |
1439 | |
1440 /* static void ggp_register_user(GaimAccount *account) {{{ */ | |
1441 static void ggp_register_user(GaimAccount *account) | |
1442 { | |
11542
cda814bad7f8
[gaim-migrate @ 13797]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11541
diff
changeset
|
1443 GaimConnection *gc = gaim_account_get_connection(account); |
11360 | 1444 GaimRequestFields *fields; |
1445 GaimRequestFieldGroup *group; | |
1446 GaimRequestField *field; | |
1447 GGPInfo *info; | |
1448 GGPToken *token; | |
1449 | |
1450 struct gg_http *req; | |
1451 struct gg_token *t; | |
1452 | |
1453 gaim_debug_info("gg", "token: requested.\n"); | |
1454 | |
1455 if ((req = gg_token(0)) == NULL) { | |
11544 | 1456 gaim_connection_error(gc, _("Token Error: Unable to fetch the token.\n")); |
11360 | 1457 return; |
1458 } | |
1459 t = req->data; | |
1460 | |
1461 info = g_new0(GGPInfo, 1); | |
1462 gc->proto_data = info; | |
1463 | |
1464 token = g_new0(GGPToken, 1); | |
1465 token->token_id = g_strdup(t->tokenid); | |
1466 info->register_token = token; | |
1467 | |
1468 fields = gaim_request_fields_new(); | |
1469 group = gaim_request_field_group_new(NULL); | |
1470 gaim_request_fields_add_group(fields, group); | |
1471 | |
1472 field = gaim_request_field_string_new("email", _("e-Mail"), "", FALSE); | |
1473 gaim_request_field_string_set_masked(field, FALSE); | |
1474 gaim_request_field_group_add_field(group, field); | |
1475 | |
1476 field = gaim_request_field_string_new("password1", _("Password"), "", FALSE); | |
1477 gaim_request_field_string_set_masked(field, TRUE); | |
1478 gaim_request_field_group_add_field(group, field); | |
1479 | |
1480 field = gaim_request_field_string_new("password2", _("Password (retype)"), "", FALSE); | |
1481 gaim_request_field_string_set_masked(field, TRUE); | |
1482 gaim_request_field_group_add_field(group, field); | |
1483 | |
1484 field = gaim_request_field_string_new("token", _("Enter current token"), "", FALSE); | |
1485 gaim_request_field_string_set_masked(field, FALSE); | |
1486 gaim_request_field_group_add_field(group, field); | |
1487 | |
1488 /* original size: 60x24 */ | |
1489 field = gaim_request_field_image_new("token_img", _("Current token"), req->body, req->body_size); | |
1490 gaim_request_field_group_add_field(group, field); | |
1491 | |
1492 gg_token_free(req); | |
4916 | 1493 |
11360 | 1494 gaim_request_fields(account, |
1495 _("Register New Gadu-Gadu Account"), | |
1496 _("Register New Gadu-Gadu Account"), | |
1497 _("Please, fill in the following fields"), | |
1498 fields, _("OK"), G_CALLBACK(ggp_callback_register_account_ok), | |
11545
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
1499 _("Cancel"), G_CALLBACK(ggp_callback_register_account_cancel), |
85abf1deac05
[gaim-migrate @ 13800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11544
diff
changeset
|
1500 gc); |
2393 | 1501 } |
11360 | 1502 /* }}} */ |
2393 | 1503 |
11360 | 1504 /* static GList *ggp_actions(GaimPlugin *plugin, gpointer context) {{{ */ |
1505 static GList *ggp_actions(GaimPlugin *plugin, gpointer context) | |
8775 | 1506 { |
11360 | 1507 GList *m = NULL; |
1508 GaimPluginAction *act; | |
1509 | |
1510 act = gaim_plugin_action_new(_("Find buddies"), ggp_find_buddies); | |
1511 m = g_list_append(m, act); | |
1512 | |
1513 m = g_list_append(m, NULL); | |
1514 | |
1515 act = gaim_plugin_action_new(_("Change password"), ggp_change_passwd); | |
1516 m = g_list_append(m, act); | |
1517 | |
1518 m = g_list_append(m, NULL); | |
1519 | |
1520 act = gaim_plugin_action_new(_("Upload buddylist to Server"), ggp_action_buddylist_put); | |
1521 m = g_list_append(m, act); | |
8775 | 1522 |
11360 | 1523 act = gaim_plugin_action_new(_("Download buddylist from Server"), ggp_action_buddylist_get); |
1524 m = g_list_append(m, act); | |
1525 | |
1526 act = gaim_plugin_action_new(_("Delete buddylist from Server"), ggp_action_buddylist_delete); | |
1527 m = g_list_append(m, act); | |
1528 | |
1529 act = gaim_plugin_action_new(_("Save buddylist to file"), ggp_action_buddylist_save); | |
1530 m = g_list_append(m, act); | |
8775 | 1531 |
11360 | 1532 act = gaim_plugin_action_new(_("Load buddylist from file"), ggp_action_buddylist_load); |
1533 m = g_list_append(m, act); | |
1534 | |
1535 return m; | |
8775 | 1536 } |
11360 | 1537 /* }}} */ |
8775 | 1538 |
11360 | 1539 /* prpl_info setup {{{ */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1540 static GaimPluginProtocolInfo prpl_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1541 { |
11360 | 1542 OPT_PROTO_REGISTER_NOSCREENNAME, |
1543 NULL, /* user_splits */ | |
1544 NULL, /* protocol_options */ | |
9950 | 1545 NO_BUDDY_ICONS, /* icon_spec */ |
11360 | 1546 ggp_list_icon, /* list_icon */ |
1547 ggp_list_emblems, /* list_emblems */ | |
1548 ggp_status_text, /* status_text */ | |
1549 ggp_tooltip_text, /* tooltip_text */ | |
1550 ggp_status_types, /* status_types */ | |
1551 ggp_blist_node_menu, /* blist_node_menu */ | |
11394 | 1552 ggp_chat_info, /* chat_info */ |
11360 | 1553 NULL, /* chat_info_defaults */ |
1554 ggp_login, /* login */ | |
1555 ggp_close, /* close */ | |
1556 ggp_send_im, /* send_im */ | |
1557 NULL, /* set_info */ | |
1558 NULL, /* send_typing */ | |
1559 ggp_get_info, /* get_info */ | |
1560 ggp_set_status, /* set_away */ | |
1561 NULL, /* set_idle */ | |
1562 NULL, /* change_passwd */ | |
1563 ggp_add_buddy, /* add_buddy */ | |
1564 NULL, /* add_buddies */ | |
1565 ggp_remove_buddy, /* remove_buddy */ | |
1566 NULL, /* remove_buddies */ | |
1567 NULL, /* add_permit */ | |
1568 NULL, /* add_deny */ | |
1569 NULL, /* rem_permit */ | |
1570 NULL, /* rem_deny */ | |
1571 NULL, /* set_permit_deny */ | |
11394 | 1572 ggp_join_chat, /* join_chat */ |
11360 | 1573 NULL, /* reject_chat */ |
11394 | 1574 ggp_get_chat_name, /* get_chat_name */ |
11360 | 1575 NULL, /* chat_invite */ |
1576 NULL, /* chat_leave */ | |
1577 NULL, /* chat_whisper */ | |
11394 | 1578 ggp_chat_send, /* chat_send */ |
11360 | 1579 ggp_keepalive, /* keepalive */ |
1580 ggp_register_user, /* register_user */ | |
1581 NULL, /* get_cb_info */ | |
1582 NULL, /* get_cb_away */ | |
1583 NULL, /* alias_buddy */ | |
1584 NULL, /* group_buddy */ | |
1585 NULL, /* rename_group */ | |
1586 NULL, /* buddy_free */ | |
1587 NULL, /* convo_closed */ | |
1588 NULL, /* normalize */ | |
1589 NULL, /* set_buddy_icon */ | |
1590 NULL, /* remove_group */ | |
1591 NULL, /* get_cb_real_name */ | |
1592 NULL, /* set_chat_topic */ | |
1593 NULL, /* find_blist_chat */ | |
1594 NULL, /* roomlist_get_list */ | |
1595 NULL, /* roomlist_cancel */ | |
1596 NULL, /* roomlist_expand_category */ | |
1597 NULL, /* can_receive_file */ | |
1598 NULL /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1599 }; |
11360 | 1600 /* }}} */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1601 |
11360 | 1602 /* GaimPluginInfo setup {{{ */ |
1603 static GaimPluginInfo info = { | |
1604 GAIM_PLUGIN_MAGIC, /* magic */ | |
1605 GAIM_MAJOR_VERSION, /* major_version */ | |
1606 GAIM_MINOR_VERSION, /* minor_version */ | |
1607 GAIM_PLUGIN_PROTOCOL, /* plugin type */ | |
1608 NULL, /* ui_requirement */ | |
1609 0, /* flags */ | |
1610 NULL, /* dependencies */ | |
1611 GAIM_PRIORITY_DEFAULT, /* priority */ | |
1612 | |
1613 "prpl-gg", /* id */ | |
1614 "Gadu-Gadu", /* name */ | |
1615 VERSION, /* version */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1616 |
11360 | 1617 N_("Gadu-Gadu Protocol Plugin"), /* summary */ |
1618 N_("Polish popular IM"), /* description */ | |
1619 "boler@sourceforge.net", /* author */ | |
1620 GAIM_WEBSITE, /* homepage */ | |
1621 | |
1622 NULL, /* load */ | |
1623 NULL, /* unload */ | |
1624 NULL, /* destroy */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1625 |
11360 | 1626 NULL, /* ui_info */ |
1627 &prpl_info, /* extra_info */ | |
1628 NULL, /* prefs_info */ | |
1629 ggp_actions /* actions */ | |
1630 }; | |
1631 /* }}} */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1632 |
11565 | 1633 /* static void gaim_gg_debug_handler(int level, const char * format, va_list args) {{{ */ |
11541
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1634 static void gaim_gg_debug_handler(int level, const char * format, va_list args) { |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1635 GaimDebugLevel gaim_level; |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1636 char *msg = g_strdup_vprintf(format, args); |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1637 |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1638 /* This is pretty pointless since the GG_DEBUG levels don't correspond to |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1639 * the gaim ones */ |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1640 switch (level) { |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1641 case GG_DEBUG_FUNCTION: |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1642 gaim_level = GAIM_DEBUG_INFO; |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1643 break; |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1644 case GG_DEBUG_MISC: |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1645 case GG_DEBUG_NET: |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1646 case GG_DEBUG_DUMP: |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1647 case GG_DEBUG_TRAFFIC: |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1648 default: |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1649 gaim_level = GAIM_DEBUG_MISC; |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1650 break; |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1651 } |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1652 |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1653 gaim_debug(gaim_level, "gg", msg); |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1654 g_free(msg); |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1655 } |
11565 | 1656 /* }}} */ |
11541
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1657 |
11360 | 1658 /* |
1659 */ | |
1660 /* static void init_plugin(GaimPlugin *plugin) {{{ */ | |
1661 static void init_plugin(GaimPlugin *plugin) | |
2393 | 1662 { |
5638
0bdfa28c678e
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5618
diff
changeset
|
1663 GaimAccountOption *option; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1664 |
11360 | 1665 option = gaim_account_option_string_new(_("Nickname"), "nick", _("Gadu-Gadu User")); |
1666 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
3572 | 1667 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5136
diff
changeset
|
1668 my_protocol = plugin; |
11541
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1669 |
5fc015909164
[gaim-migrate @ 13796]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11538
diff
changeset
|
1670 gg_debug_handler = gaim_gg_debug_handler; |
2393 | 1671 } |
11360 | 1672 /* }}} */ |
2393 | 1673 |
11360 | 1674 GAIM_INIT_PLUGIN(gadu-gadu, init_plugin, info); |
1675 | |
1676 /* vim: set ts=4 sts=0 sw=4 noet: */ | |
11394 | 1677 |