Mercurial > pidgin
annotate finch/gntaccount.c @ 17069:4876375de307
Plug a leak when the flags for a user in a chat changes.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 13 May 2007 08:54:50 +0000 |
parents | 4b6d81d26b56 |
children | 46f2f86e08e4 |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntaccount.c GNT Account API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
15870
diff
changeset
|
3 * @ingroup finch |
15817 | 4 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
5 * finch |
15817 | 6 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <gnt.h> | |
26 #include <gntbox.h> | |
27 #include <gntbutton.h> | |
28 #include <gntcheckbox.h> | |
29 #include <gntcombobox.h> | |
30 #include <gntentry.h> | |
31 #include <gntlabel.h> | |
32 #include <gntline.h> | |
33 #include <gnttree.h> | |
34 | |
35 #include <account.h> | |
36 #include <accountopt.h> | |
37 #include <connection.h> | |
38 #include <notify.h> | |
39 #include <plugin.h> | |
40 #include <request.h> | |
41 | |
42 #include "gntaccount.h" | |
15822 | 43 #include "finch.h" |
15817 | 44 |
45 #include <string.h> | |
46 | |
47 typedef struct | |
48 { | |
49 GntWidget *window; | |
50 GntWidget *tree; | |
51 } FinchAccountList; | |
52 | |
53 static FinchAccountList accounts; | |
54 | |
55 typedef struct | |
56 { | |
15822 | 57 PurpleAccount *account; /* NULL for a new account */ |
15817 | 58 |
59 GntWidget *window; | |
60 | |
61 GntWidget *protocol; | |
62 GntWidget *screenname; | |
63 GntWidget *password; | |
64 GntWidget *alias; | |
65 | |
66 GntWidget *splits; | |
67 GList *split_entries; | |
68 | |
69 GList *prpl_entries; | |
70 GntWidget *prpls; | |
71 | |
72 GntWidget *newmail; | |
73 GntWidget *remember; | |
74 } AccountEditDialog; | |
75 | |
76 /* This is necessary to close an edit-dialog when an account is deleted */ | |
77 static GList *accountdialogs; | |
78 | |
79 static void | |
15822 | 80 account_add(PurpleAccount *account) |
15817 | 81 { |
82 gnt_tree_add_choice(GNT_TREE(accounts.tree), account, | |
83 gnt_tree_create_row(GNT_TREE(accounts.tree), | |
15822 | 84 purple_account_get_username(account), |
85 purple_account_get_protocol_name(account)), | |
15817 | 86 NULL, NULL); |
87 gnt_tree_set_choice(GNT_TREE(accounts.tree), account, | |
15822 | 88 purple_account_get_enabled(account, FINCH_UI)); |
15817 | 89 } |
90 | |
91 static void | |
92 edit_dialog_destroy(AccountEditDialog *dialog) | |
93 { | |
94 accountdialogs = g_list_remove(accountdialogs, dialog); | |
95 g_list_free(dialog->prpl_entries); | |
96 g_list_free(dialog->split_entries); | |
97 g_free(dialog); | |
98 } | |
99 | |
100 static void | |
101 save_account_cb(AccountEditDialog *dialog) | |
102 { | |
15822 | 103 PurpleAccount *account; |
104 PurplePlugin *plugin; | |
105 PurplePluginProtocolInfo *prplinfo; | |
15817 | 106 const char *value; |
107 GString *username; | |
108 | |
109 /* XXX: Do some error checking first. */ | |
110 | |
111 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
15822 | 112 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 113 |
114 /* Screenname && user-splits */ | |
115 value = gnt_entry_get_text(GNT_ENTRY(dialog->screenname)); | |
116 | |
117 if (value == NULL || *value == '\0') | |
118 { | |
15822 | 119 purple_notify_error(NULL, _("Error"), _("Account was not added"), |
15817 | 120 _("Screenname of an account must be non-empty.")); |
121 return; | |
122 } | |
123 | |
124 username = g_string_new(value); | |
125 | |
126 if (prplinfo != NULL) | |
127 { | |
128 GList *iter, *entries; | |
129 for (iter = prplinfo->user_splits, entries = dialog->split_entries; | |
130 iter && entries; iter = iter->next, entries = entries->next) | |
131 { | |
15822 | 132 PurpleAccountUserSplit *split = iter->data; |
15817 | 133 GntWidget *entry = entries->data; |
134 | |
135 value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
136 if (value == NULL || *value == '\0') | |
15822 | 137 value = purple_account_user_split_get_default_value(split); |
15817 | 138 g_string_append_printf(username, "%c%s", |
15822 | 139 purple_account_user_split_get_separator(split), |
15817 | 140 value); |
141 } | |
142 } | |
143 | |
144 if (dialog->account == NULL) | |
145 { | |
15822 | 146 account = purple_account_new(username->str, purple_plugin_get_id(plugin)); |
147 purple_accounts_add(account); | |
15817 | 148 } |
149 else | |
150 { | |
151 account = dialog->account; | |
152 | |
153 /* Protocol */ | |
15822 | 154 purple_account_set_protocol_id(account, purple_plugin_get_id(plugin)); |
155 purple_account_set_username(account, username->str); | |
15817 | 156 } |
157 g_string_free(username, TRUE); | |
158 | |
159 /* Alias */ | |
160 value = gnt_entry_get_text(GNT_ENTRY(dialog->alias)); | |
161 if (value && *value) | |
15822 | 162 purple_account_set_alias(account, value); |
15817 | 163 |
164 /* Remember password and password */ | |
15822 | 165 purple_account_set_remember_password(account, |
15817 | 166 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->remember))); |
167 value = gnt_entry_get_text(GNT_ENTRY(dialog->password)); | |
15822 | 168 if (value && *value && purple_account_get_remember_password(account)) |
169 purple_account_set_password(account, value); | |
15817 | 170 else |
15822 | 171 purple_account_set_password(account, NULL); |
15817 | 172 |
173 /* Mail notification */ | |
15822 | 174 purple_account_set_check_mail(account, |
15817 | 175 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->newmail))); |
176 | |
177 /* Protocol options */ | |
178 if (prplinfo) | |
179 { | |
180 GList *iter, *entries; | |
181 | |
182 for (iter = prplinfo->protocol_options, entries = dialog->prpl_entries; | |
183 iter && entries; iter = iter->next, entries = entries->next) | |
184 { | |
15822 | 185 PurpleAccountOption *option = iter->data; |
15817 | 186 GntWidget *entry = entries->data; |
15822 | 187 PurplePrefType type = purple_account_option_get_type(option); |
188 const char *setting = purple_account_option_get_setting(option); | |
15817 | 189 |
15822 | 190 if (type == PURPLE_PREF_STRING) |
15817 | 191 { |
192 const char *value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
15822 | 193 purple_account_set_string(account, setting, value); |
15817 | 194 } |
15822 | 195 else if (type == PURPLE_PREF_INT) |
15817 | 196 { |
197 const char *str = gnt_entry_get_text(GNT_ENTRY(entry)); | |
198 int value = 0; | |
199 if (str) | |
200 value = atoi(str); | |
15822 | 201 purple_account_set_int(account, setting, value); |
15817 | 202 } |
15822 | 203 else if (type == PURPLE_PREF_BOOLEAN) |
15817 | 204 { |
205 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(entry)); | |
15822 | 206 purple_account_set_bool(account, setting, value); |
15817 | 207 } |
15822 | 208 else if (type == PURPLE_PREF_STRING_LIST) |
15817 | 209 { |
210 /* TODO: */ | |
211 } | |
212 else | |
213 { | |
214 g_assert_not_reached(); | |
215 } | |
216 } | |
217 } | |
218 | |
219 /* XXX: Proxy options */ | |
220 | |
221 gnt_widget_destroy(dialog->window); | |
222 } | |
223 | |
224 static void | |
225 update_user_splits(AccountEditDialog *dialog) | |
226 { | |
227 GntWidget *hbox; | |
15822 | 228 PurplePlugin *plugin; |
229 PurplePluginProtocolInfo *prplinfo; | |
15817 | 230 GList *iter, *entries; |
231 char *username = NULL; | |
232 | |
233 if (dialog->splits) | |
234 { | |
235 gnt_box_remove_all(GNT_BOX(dialog->splits)); | |
236 g_list_free(dialog->split_entries); | |
237 } | |
238 else | |
239 { | |
240 dialog->splits = gnt_vbox_new(FALSE); | |
241 gnt_box_set_pad(GNT_BOX(dialog->splits), 0); | |
242 gnt_box_set_fill(GNT_BOX(dialog->splits), TRUE); | |
243 } | |
244 | |
245 dialog->split_entries = NULL; | |
246 | |
247 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
248 if (!plugin) | |
249 return; | |
15822 | 250 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 251 |
15822 | 252 username = dialog->account ? g_strdup(purple_account_get_username(dialog->account)) : NULL; |
15817 | 253 |
254 for (iter = prplinfo->user_splits; iter; iter = iter->next) | |
255 { | |
15822 | 256 PurpleAccountUserSplit *split = iter->data; |
15817 | 257 GntWidget *entry; |
258 char *buf; | |
259 | |
260 hbox = gnt_hbox_new(TRUE); | |
261 gnt_box_add_widget(GNT_BOX(dialog->splits), hbox); | |
262 | |
15822 | 263 buf = g_strdup_printf("%s:", purple_account_user_split_get_text(split)); |
15817 | 264 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(buf)); |
265 | |
266 entry = gnt_entry_new(NULL); | |
267 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
268 | |
269 dialog->split_entries = g_list_append(dialog->split_entries, entry); | |
270 g_free(buf); | |
271 } | |
272 | |
273 for (iter = g_list_last(prplinfo->user_splits), entries = g_list_last(dialog->split_entries); | |
274 iter && entries; iter = iter->prev, entries = entries->prev) | |
275 { | |
276 GntWidget *entry = entries->data; | |
15822 | 277 PurpleAccountUserSplit *split = iter->data; |
15817 | 278 const char *value = NULL; |
279 char *s; | |
280 | |
281 if (dialog->account) | |
282 { | |
15822 | 283 s = strrchr(username, purple_account_user_split_get_separator(split)); |
15817 | 284 if (s != NULL) |
285 { | |
286 *s = '\0'; | |
287 s++; | |
288 value = s; | |
289 } | |
290 } | |
291 if (value == NULL) | |
15822 | 292 value = purple_account_user_split_get_default_value(split); |
15817 | 293 |
294 if (value != NULL) | |
295 gnt_entry_set_text(GNT_ENTRY(entry), value); | |
296 } | |
297 | |
298 if (username != NULL) | |
299 gnt_entry_set_text(GNT_ENTRY(dialog->screenname), username); | |
300 | |
301 g_free(username); | |
302 } | |
303 | |
304 static void | |
305 add_protocol_options(AccountEditDialog *dialog) | |
306 { | |
15822 | 307 PurplePlugin *plugin; |
308 PurplePluginProtocolInfo *prplinfo; | |
15817 | 309 GList *iter; |
310 GntWidget *vbox, *box; | |
15822 | 311 PurpleAccount *account; |
15817 | 312 |
313 if (dialog->prpls) | |
314 gnt_box_remove_all(GNT_BOX(dialog->prpls)); | |
315 else | |
316 { | |
317 dialog->prpls = vbox = gnt_vbox_new(FALSE); | |
318 gnt_box_set_pad(GNT_BOX(vbox), 0); | |
319 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_LEFT); | |
320 gnt_box_set_fill(GNT_BOX(vbox), TRUE); | |
321 } | |
322 | |
323 if (dialog->prpl_entries) | |
324 { | |
325 g_list_free(dialog->prpl_entries); | |
326 dialog->prpl_entries = NULL; | |
327 } | |
328 | |
329 vbox = dialog->prpls; | |
330 | |
331 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
332 if (!plugin) | |
333 return; | |
334 | |
15822 | 335 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 336 |
337 account = dialog->account; | |
338 | |
339 for (iter = prplinfo->protocol_options; iter; iter = iter->next) | |
340 { | |
15822 | 341 PurpleAccountOption *option = iter->data; |
342 PurplePrefType type = purple_account_option_get_type(option); | |
15817 | 343 |
344 box = gnt_hbox_new(TRUE); | |
345 gnt_box_set_pad(GNT_BOX(box), 0); | |
346 gnt_box_add_widget(GNT_BOX(vbox), box); | |
347 | |
15822 | 348 if (type == PURPLE_PREF_BOOLEAN) |
15817 | 349 { |
15822 | 350 GntWidget *widget = gnt_check_box_new(purple_account_option_get_text(option)); |
15817 | 351 gnt_box_add_widget(GNT_BOX(box), widget); |
352 dialog->prpl_entries = g_list_append(dialog->prpl_entries, widget); | |
353 | |
354 if (account) | |
355 gnt_check_box_set_checked(GNT_CHECK_BOX(widget), | |
15822 | 356 purple_account_get_bool(account, |
357 purple_account_option_get_setting(option), | |
358 purple_account_option_get_default_bool(option))); | |
15817 | 359 else |
360 gnt_check_box_set_checked(GNT_CHECK_BOX(widget), | |
15822 | 361 purple_account_option_get_default_bool(option)); |
15817 | 362 } |
363 else | |
364 { | |
365 gnt_box_add_widget(GNT_BOX(box), | |
15822 | 366 gnt_label_new(purple_account_option_get_text(option))); |
15817 | 367 |
15822 | 368 if (type == PURPLE_PREF_STRING_LIST) |
15817 | 369 { |
370 /* TODO: Use a combobox */ | |
371 /* Don't forget to append the widget to prpl_entries */ | |
372 } | |
373 else | |
374 { | |
375 GntWidget *entry = gnt_entry_new(NULL); | |
376 gnt_box_add_widget(GNT_BOX(box), entry); | |
377 dialog->prpl_entries = g_list_append(dialog->prpl_entries, entry); | |
378 | |
15822 | 379 if (type == PURPLE_PREF_STRING) |
15817 | 380 { |
15822 | 381 const char *dv = purple_account_option_get_default_string(option); |
15817 | 382 |
383 if (account) | |
384 gnt_entry_set_text(GNT_ENTRY(entry), | |
15822 | 385 purple_account_get_string(account, |
386 purple_account_option_get_setting(option), dv)); | |
15817 | 387 else |
388 gnt_entry_set_text(GNT_ENTRY(entry), dv); | |
389 } | |
15822 | 390 else if (type == PURPLE_PREF_INT) |
15817 | 391 { |
392 char str[32]; | |
15822 | 393 int value = purple_account_option_get_default_int(option); |
15817 | 394 if (account) |
15822 | 395 value = purple_account_get_int(account, |
396 purple_account_option_get_setting(option), value); | |
15817 | 397 snprintf(str, sizeof(str), "%d", value); |
398 gnt_entry_set_flag(GNT_ENTRY(entry), GNT_ENTRY_FLAG_INT); | |
399 gnt_entry_set_text(GNT_ENTRY(entry), str); | |
400 } | |
401 else | |
402 { | |
403 g_assert_not_reached(); | |
404 } | |
405 } | |
406 } | |
407 } | |
408 } | |
409 | |
410 static void | |
411 update_user_options(AccountEditDialog *dialog) | |
412 { | |
15822 | 413 PurplePlugin *plugin; |
414 PurplePluginProtocolInfo *prplinfo; | |
15817 | 415 |
416 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
417 if (!plugin) | |
418 return; | |
419 | |
15822 | 420 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 421 |
422 if (dialog->newmail == NULL) | |
423 dialog->newmail = gnt_check_box_new(_("New mail notifications")); | |
424 if (dialog->account) | |
425 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->newmail), | |
15822 | 426 purple_account_get_check_mail(dialog->account)); |
15817 | 427 if (!prplinfo || !(prplinfo->options & OPT_PROTO_MAIL_CHECK)) |
428 gnt_widget_set_visible(dialog->newmail, FALSE); | |
429 else | |
430 gnt_widget_set_visible(dialog->newmail, TRUE); | |
431 | |
432 if (dialog->remember == NULL) | |
433 dialog->remember = gnt_check_box_new(_("Remember password")); | |
434 if (dialog->account) | |
435 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->remember), | |
15822 | 436 purple_account_get_remember_password(dialog->account)); |
15817 | 437 } |
438 | |
439 static void | |
15822 | 440 prpl_changed_cb(GntWidget *combo, PurplePlugin *old, PurplePlugin *new, AccountEditDialog *dialog) |
15817 | 441 { |
442 update_user_splits(dialog); | |
443 add_protocol_options(dialog); | |
444 update_user_options(dialog); /* This may not be necessary here */ | |
445 gnt_box_readjust(GNT_BOX(dialog->window)); | |
446 gnt_widget_draw(dialog->window); | |
447 } | |
448 | |
449 static void | |
15822 | 450 edit_account(PurpleAccount *account) |
15817 | 451 { |
452 GntWidget *window, *hbox; | |
453 GntWidget *combo, *button, *entry; | |
454 GList *list, *iter; | |
455 AccountEditDialog *dialog; | |
456 | |
457 if (account) | |
458 { | |
459 GList *iter; | |
460 for (iter = accountdialogs; iter; iter = iter->next) | |
461 { | |
462 AccountEditDialog *dlg = iter->data; | |
463 if (dlg->account == account) | |
464 return; | |
465 } | |
466 } | |
467 | |
468 dialog = g_new0(AccountEditDialog, 1); | |
469 accountdialogs = g_list_prepend(accountdialogs, dialog); | |
470 | |
471 dialog->window = window = gnt_vbox_new(FALSE); | |
472 dialog->account = account; | |
473 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
474 gnt_box_set_title(GNT_BOX(window), account ? _("Modify Account") : _("New Account")); | |
475 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
476 gnt_box_set_pad(GNT_BOX(window), 0); | |
477 gnt_widget_set_name(window, "edit-account"); | |
478 gnt_box_set_fill(GNT_BOX(window), TRUE); | |
479 | |
480 hbox = gnt_hbox_new(TRUE); | |
481 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
482 gnt_box_add_widget(GNT_BOX(window), hbox); | |
483 | |
484 dialog->protocol = combo = gnt_combo_box_new(); | |
15822 | 485 list = purple_plugins_get_protocols(); |
15817 | 486 for (iter = list; iter; iter = iter->next) |
487 { | |
488 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), iter->data, | |
15822 | 489 ((PurplePlugin*)iter->data)->info->name); |
15817 | 490 } |
491 | |
492 if (account) | |
493 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
15822 | 494 purple_plugins_find_with_id(purple_account_get_protocol_id(account))); |
15817 | 495 else |
496 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), list->data); | |
497 | |
498 g_signal_connect(G_OBJECT(combo), "selection-changed", G_CALLBACK(prpl_changed_cb), dialog); | |
499 | |
500 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Protocol:"))); | |
501 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
502 | |
503 hbox = gnt_hbox_new(TRUE); | |
504 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
505 gnt_box_add_widget(GNT_BOX(window), hbox); | |
506 | |
507 dialog->screenname = entry = gnt_entry_new(NULL); | |
508 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Screen name:"))); | |
509 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
510 | |
511 /* User splits */ | |
512 update_user_splits(dialog); | |
513 gnt_box_add_widget(GNT_BOX(window), dialog->splits); | |
514 | |
515 hbox = gnt_hbox_new(TRUE); | |
516 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
517 gnt_box_add_widget(GNT_BOX(window), hbox); | |
518 | |
519 dialog->password = entry = gnt_entry_new(NULL); | |
520 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); | |
521 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Password:"))); | |
522 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
523 if (account) | |
15822 | 524 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_password(account)); |
15817 | 525 |
526 hbox = gnt_hbox_new(TRUE); | |
527 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
528 gnt_box_add_widget(GNT_BOX(window), hbox); | |
529 | |
530 dialog->alias = entry = gnt_entry_new(NULL); | |
531 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Alias:"))); | |
532 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
533 if (account) | |
15822 | 534 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_alias(account)); |
15817 | 535 |
536 /* User options */ | |
537 update_user_options(dialog); | |
538 gnt_box_add_widget(GNT_BOX(window), dialog->remember); | |
539 gnt_box_add_widget(GNT_BOX(window), dialog->newmail); | |
540 | |
541 gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE)); | |
542 | |
543 /* The advanced box */ | |
544 add_protocol_options(dialog); | |
545 gnt_box_add_widget(GNT_BOX(window), dialog->prpls); | |
546 | |
547 /* TODO: Add proxy options */ | |
548 | |
549 /* The button box */ | |
550 hbox = gnt_hbox_new(FALSE); | |
551 gnt_box_add_widget(GNT_BOX(window), hbox); | |
552 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
553 | |
554 button = gnt_button_new(_("Cancel")); | |
555 gnt_box_add_widget(GNT_BOX(hbox), button); | |
556 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); | |
557 | |
558 button = gnt_button_new(_("Save")); | |
559 gnt_box_add_widget(GNT_BOX(hbox), button); | |
560 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(save_account_cb), dialog); | |
561 | |
562 g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(edit_dialog_destroy), dialog); | |
563 | |
564 gnt_widget_show(window); | |
565 gnt_box_readjust(GNT_BOX(window)); | |
566 gnt_widget_draw(window); | |
567 } | |
568 | |
569 static void | |
570 add_account_cb(GntWidget *widget, gpointer null) | |
571 { | |
572 edit_account(NULL); | |
573 } | |
574 | |
575 static void | |
576 modify_account_cb(GntWidget *widget, GntTree *tree) | |
577 { | |
15822 | 578 PurpleAccount *account = gnt_tree_get_selection_data(tree); |
15817 | 579 if (!account) |
580 return; | |
581 edit_account(account); | |
582 } | |
583 | |
584 static void | |
15822 | 585 really_delete_account(PurpleAccount *account) |
15817 | 586 { |
587 GList *iter; | |
588 for (iter = accountdialogs; iter; iter = iter->next) | |
589 { | |
590 AccountEditDialog *dlg = iter->data; | |
591 if (dlg->account == account) | |
592 { | |
593 gnt_widget_destroy(dlg->window); | |
594 break; | |
595 } | |
596 } | |
15822 | 597 purple_request_close_with_handle(account); /* Close any other opened delete window */ |
598 purple_accounts_delete(account); | |
15817 | 599 } |
600 | |
601 static void | |
602 delete_account_cb(GntWidget *widget, GntTree *tree) | |
603 { | |
15822 | 604 PurpleAccount *account; |
15817 | 605 char *prompt; |
606 | |
607 account = gnt_tree_get_selection_data(tree); | |
608 if (!account) | |
609 return; | |
610 | |
611 prompt = g_strdup_printf(_("Are you sure you want to delete %s?"), | |
15822 | 612 purple_account_get_username(account)); |
15817 | 613 |
16462
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16439
diff
changeset
|
614 purple_request_action(account, _("Delete Account"), prompt, NULL, 0, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16439
diff
changeset
|
615 account, NULL, NULL, account, 2, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16439
diff
changeset
|
616 _("Delete"), really_delete_account, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16439
diff
changeset
|
617 _("Cancel"), NULL); |
15817 | 618 g_free(prompt); |
619 } | |
620 | |
621 static void | |
622 account_toggled(GntWidget *widget, void *key, gpointer null) | |
623 { | |
15822 | 624 PurpleAccount *account = key; |
15817 | 625 |
15822 | 626 purple_account_set_enabled(account, FINCH_UI, gnt_tree_get_choice(GNT_TREE(widget), key)); |
15817 | 627 } |
628 | |
629 static void | |
630 reset_accounts_win(GntWidget *widget, gpointer null) | |
631 { | |
632 accounts.window = NULL; | |
633 accounts.tree = NULL; | |
634 } | |
635 | |
636 void finch_accounts_show_all() | |
637 { | |
638 GList *iter; | |
639 GntWidget *box, *button; | |
640 | |
641 if (accounts.window) | |
642 return; | |
643 | |
644 accounts.window = gnt_vbox_new(FALSE); | |
645 gnt_box_set_toplevel(GNT_BOX(accounts.window), TRUE); | |
646 gnt_box_set_title(GNT_BOX(accounts.window), _("Accounts")); | |
647 gnt_box_set_pad(GNT_BOX(accounts.window), 0); | |
648 gnt_box_set_alignment(GNT_BOX(accounts.window), GNT_ALIGN_MID); | |
649 gnt_widget_set_name(accounts.window, "accounts"); | |
650 | |
651 gnt_box_add_widget(GNT_BOX(accounts.window), | |
652 gnt_label_new(_("You can enable/disable accounts from the following list."))); | |
653 | |
654 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); | |
655 | |
656 accounts.tree = gnt_tree_new_with_columns(2); | |
657 GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER); | |
658 | |
15822 | 659 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15817 | 660 { |
15822 | 661 PurpleAccount *account = iter->data; |
15817 | 662 account_add(account); |
663 } | |
664 | |
665 g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL); | |
666 | |
667 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 0, 40); | |
668 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 1, 10); | |
669 gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree); | |
670 | |
671 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); | |
672 | |
673 box = gnt_hbox_new(FALSE); | |
674 | |
675 button = gnt_button_new(_("Add")); | |
676 gnt_box_add_widget(GNT_BOX(box), button); | |
677 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(add_account_cb), NULL); | |
678 | |
679 button = gnt_button_new(_("Modify")); | |
680 gnt_box_add_widget(GNT_BOX(box), button); | |
681 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(modify_account_cb), accounts.tree); | |
682 | |
683 button = gnt_button_new(_("Delete")); | |
684 gnt_box_add_widget(GNT_BOX(box), button); | |
685 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(delete_account_cb), accounts.tree); | |
686 | |
687 gnt_box_add_widget(GNT_BOX(accounts.window), box); | |
688 | |
689 g_signal_connect(G_OBJECT(accounts.window), "destroy", G_CALLBACK(reset_accounts_win), NULL); | |
690 | |
691 gnt_widget_show(accounts.window); | |
692 } | |
693 | |
694 static gpointer | |
695 finch_accounts_get_handle() | |
696 { | |
697 static int handle; | |
698 | |
699 return &handle; | |
700 } | |
701 | |
702 static void | |
15822 | 703 account_added_callback(PurpleAccount *account) |
15817 | 704 { |
705 if (accounts.window == NULL) | |
706 return; | |
707 account_add(account); | |
708 gnt_widget_draw(accounts.tree); | |
709 } | |
710 | |
711 static void | |
15822 | 712 account_removed_callback(PurpleAccount *account) |
15817 | 713 { |
714 if (accounts.window == NULL) | |
715 return; | |
716 | |
717 gnt_tree_remove(GNT_TREE(accounts.tree), account); | |
718 } | |
719 | |
720 void finch_accounts_init() | |
721 { | |
722 GList *iter; | |
723 | |
15822 | 724 purple_signal_connect(purple_accounts_get_handle(), "account-added", |
725 finch_accounts_get_handle(), PURPLE_CALLBACK(account_added_callback), | |
15817 | 726 NULL); |
15822 | 727 purple_signal_connect(purple_accounts_get_handle(), "account-removed", |
728 finch_accounts_get_handle(), PURPLE_CALLBACK(account_removed_callback), | |
15817 | 729 NULL); |
730 | |
15822 | 731 for (iter = purple_accounts_get_all(); iter; iter = iter->next) { |
732 if (purple_account_get_enabled(iter->data, FINCH_UI)) | |
15817 | 733 break; |
734 } | |
735 if (!iter) | |
736 finch_accounts_show_all(); | |
737 } | |
738 | |
739 void finch_accounts_uninit() | |
740 { | |
741 if (accounts.window) | |
742 gnt_widget_destroy(accounts.window); | |
743 } | |
744 | |
745 /* The following uiops stuff are copied from gtkaccount.c */ | |
746 typedef struct | |
747 { | |
15822 | 748 PurpleAccount *account; |
15817 | 749 char *username; |
750 char *alias; | |
751 } AddUserData; | |
752 | |
753 static char * | |
15822 | 754 make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user, |
15817 | 755 const char *id, const char *alias, const char *msg) |
756 { | |
757 if (msg != NULL && *msg == '\0') | |
758 msg = NULL; | |
759 | |
760 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"), | |
761 remote_user, | |
762 (alias != NULL ? " (" : ""), | |
763 (alias != NULL ? alias : ""), | |
764 (alias != NULL ? ")" : ""), | |
765 (id != NULL | |
766 ? id | |
15822 | 767 : (purple_connection_get_display_name(gc) != NULL |
768 ? purple_connection_get_display_name(gc) | |
769 : purple_account_get_username(account))), | |
15817 | 770 (msg != NULL ? ": " : "."), |
771 (msg != NULL ? msg : "")); | |
772 } | |
773 | |
774 static void | |
15822 | 775 notify_added(PurpleAccount *account, const char *remote_user, |
15817 | 776 const char *id, const char *alias, |
777 const char *msg) | |
778 { | |
779 char *buffer; | |
15822 | 780 PurpleConnection *gc; |
15817 | 781 |
15822 | 782 gc = purple_account_get_connection(account); |
15817 | 783 |
784 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
785 | |
15822 | 786 purple_notify_info(NULL, NULL, buffer, NULL); |
15817 | 787 |
788 g_free(buffer); | |
789 } | |
790 | |
791 static void | |
792 free_add_user_data(AddUserData *data) | |
793 { | |
794 g_free(data->username); | |
795 | |
796 if (data->alias != NULL) | |
797 g_free(data->alias); | |
798 | |
799 g_free(data); | |
800 } | |
801 | |
802 static void | |
803 add_user_cb(AddUserData *data) | |
804 { | |
15822 | 805 PurpleConnection *gc = purple_account_get_connection(data->account); |
15817 | 806 |
15822 | 807 if (g_list_find(purple_connections_get_all(), gc)) |
15817 | 808 { |
15822 | 809 purple_blist_request_add_buddy(data->account, data->username, |
15817 | 810 NULL, data->alias); |
811 } | |
812 | |
813 free_add_user_data(data); | |
814 } | |
815 | |
816 static void | |
15822 | 817 request_add(PurpleAccount *account, const char *remote_user, |
15817 | 818 const char *id, const char *alias, |
819 const char *msg) | |
820 { | |
821 char *buffer; | |
15822 | 822 PurpleConnection *gc; |
15817 | 823 AddUserData *data; |
824 | |
15822 | 825 gc = purple_account_get_connection(account); |
15817 | 826 |
827 data = g_new0(AddUserData, 1); | |
828 data->account = account; | |
829 data->username = g_strdup(remote_user); | |
830 data->alias = (alias != NULL ? g_strdup(alias) : NULL); | |
831 | |
832 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
15822 | 833 purple_request_action(NULL, NULL, _("Add buddy to your list?"), |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
834 buffer, PURPLE_DEFAULT_ACTION_NONE, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
835 account, remote_user, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
836 data, 2, |
15817 | 837 _("Add"), G_CALLBACK(add_user_cb), |
838 _("Cancel"), G_CALLBACK(free_add_user_data)); | |
839 g_free(buffer); | |
840 } | |
841 | |
842 /* Copied from gtkaccount.c */ | |
843 typedef struct { | |
15822 | 844 PurpleAccountRequestAuthorizationCb auth_cb; |
845 PurpleAccountRequestAuthorizationCb deny_cb; | |
15817 | 846 void *data; |
847 char *username; | |
848 char *alias; | |
15822 | 849 PurpleAccount *account; |
15817 | 850 } auth_and_add; |
851 | |
852 static void | |
853 authorize_and_add_cb(auth_and_add *aa) | |
854 { | |
855 aa->auth_cb(aa->data); | |
15822 | 856 purple_blist_request_add_buddy(aa->account, aa->username, |
15817 | 857 NULL, aa->alias); |
858 | |
859 g_free(aa->username); | |
860 g_free(aa->alias); | |
861 g_free(aa); | |
862 } | |
863 | |
864 static void | |
865 deny_no_add_cb(auth_and_add *aa) | |
866 { | |
867 aa->deny_cb(aa->data); | |
868 | |
869 g_free(aa->username); | |
870 g_free(aa->alias); | |
871 g_free(aa); | |
872 } | |
873 | |
874 static void * | |
15822 | 875 finch_request_authorize(PurpleAccount *account, const char *remote_user, |
15817 | 876 const char *id, const char *alias, const char *message, gboolean on_list, |
877 GCallback auth_cb, GCallback deny_cb, void *user_data) | |
878 { | |
879 char *buffer; | |
15822 | 880 PurpleConnection *gc; |
15817 | 881 void *uihandle; |
882 | |
15822 | 883 gc = purple_account_get_connection(account); |
15817 | 884 if (message != NULL && *message == '\0') |
885 message = NULL; | |
886 | |
887 buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"), | |
888 remote_user, | |
889 (alias != NULL ? " (" : ""), | |
890 (alias != NULL ? alias : ""), | |
891 (alias != NULL ? ")" : ""), | |
892 (id != NULL | |
893 ? id | |
15822 | 894 : (purple_connection_get_display_name(gc) != NULL |
895 ? purple_connection_get_display_name(gc) | |
896 : purple_account_get_username(account))), | |
15817 | 897 (message != NULL ? ": " : "."), |
898 (message != NULL ? message : "")); | |
899 if (!on_list) { | |
900 auth_and_add *aa = g_new(auth_and_add, 1); | |
15822 | 901 aa->auth_cb = (PurpleAccountRequestAuthorizationCb)auth_cb; |
902 aa->deny_cb = (PurpleAccountRequestAuthorizationCb)deny_cb; | |
15817 | 903 aa->data = user_data; |
904 aa->username = g_strdup(remote_user); | |
905 aa->alias = g_strdup(alias); | |
906 aa->account = account; | |
15822 | 907 uihandle = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL, |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
908 PURPLE_DEFAULT_ACTION_NONE, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
909 account, remote_user, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
910 aa, 2, |
15817 | 911 _("Authorize"), authorize_and_add_cb, |
912 _("Deny"), deny_no_add_cb); | |
913 } else { | |
15822 | 914 uihandle = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL, |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
915 PURPLE_DEFAULT_ACTION_NONE, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
916 account, remote_user, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16194
diff
changeset
|
917 user_data, 2, |
15817 | 918 _("Authorize"), auth_cb, |
919 _("Deny"), deny_cb); | |
920 } | |
921 g_free(buffer); | |
922 return uihandle; | |
923 } | |
924 | |
925 static void | |
926 finch_request_close(void *uihandle) | |
927 { | |
15822 | 928 purple_request_close(PURPLE_REQUEST_ACTION, uihandle); |
15817 | 929 } |
930 | |
15822 | 931 static PurpleAccountUiOps ui_ops = |
15817 | 932 { |
933 .notify_added = notify_added, | |
934 .status_changed = NULL, | |
935 .request_add = request_add, | |
936 .request_authorize = finch_request_authorize, | |
937 .close_account_request = finch_request_close | |
938 }; | |
939 | |
15822 | 940 PurpleAccountUiOps *finch_accounts_get_ui_ops() |
15817 | 941 { |
942 return &ui_ops; | |
943 } | |
944 |