Mercurial > pidgin.yaz
annotate finch/gntaccount.c @ 17712:43a55528ff26
propagate from branch 'im.pidgin.pidgin' (head b5c55520ae8ff7186733fd82db23a6e4452976cc)
to branch 'im.pidgin.soc.2007.finchfeat' (head 93037197c5356731d62e75b4050ca7d01b1017d6)
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Mon, 04 Jun 2007 15:12:50 +0000 |
parents | 8c3a3407af58 |
children | f8e3b38f8e12 e3e42a99070e |
rev | line source |
---|---|
15818 | 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:
15871
diff
changeset
|
3 * @ingroup finch |
15818 | 4 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 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" | |
15823 | 43 #include "finch.h" |
15818 | 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 { | |
15823 | 57 PurpleAccount *account; /* NULL for a new account */ |
15818 | 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 | |
15823 | 80 account_add(PurpleAccount *account) |
15818 | 81 { |
82 gnt_tree_add_choice(GNT_TREE(accounts.tree), account, | |
83 gnt_tree_create_row(GNT_TREE(accounts.tree), | |
15823 | 84 purple_account_get_username(account), |
85 purple_account_get_protocol_name(account)), | |
15818 | 86 NULL, NULL); |
87 gnt_tree_set_choice(GNT_TREE(accounts.tree), account, | |
15823 | 88 purple_account_get_enabled(account, FINCH_UI)); |
15818 | 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 { | |
15823 | 103 PurpleAccount *account; |
104 PurplePlugin *plugin; | |
105 PurplePluginProtocolInfo *prplinfo; | |
15818 | 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)); | |
15823 | 112 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 113 |
114 /* Screenname && user-splits */ | |
115 value = gnt_entry_get_text(GNT_ENTRY(dialog->screenname)); | |
116 | |
117 if (value == NULL || *value == '\0') | |
118 { | |
15823 | 119 purple_notify_error(NULL, _("Error"), _("Account was not added"), |
15818 | 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 { | |
15823 | 132 PurpleAccountUserSplit *split = iter->data; |
15818 | 133 GntWidget *entry = entries->data; |
134 | |
135 value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
136 if (value == NULL || *value == '\0') | |
15823 | 137 value = purple_account_user_split_get_default_value(split); |
15818 | 138 g_string_append_printf(username, "%c%s", |
15823 | 139 purple_account_user_split_get_separator(split), |
15818 | 140 value); |
141 } | |
142 } | |
143 | |
144 if (dialog->account == NULL) | |
145 { | |
15823 | 146 account = purple_account_new(username->str, purple_plugin_get_id(plugin)); |
147 purple_accounts_add(account); | |
15818 | 148 } |
149 else | |
150 { | |
151 account = dialog->account; | |
152 | |
153 /* Protocol */ | |
15823 | 154 purple_account_set_protocol_id(account, purple_plugin_get_id(plugin)); |
155 purple_account_set_username(account, username->str); | |
15818 | 156 } |
157 g_string_free(username, TRUE); | |
158 | |
159 /* Alias */ | |
160 value = gnt_entry_get_text(GNT_ENTRY(dialog->alias)); | |
161 if (value && *value) | |
15823 | 162 purple_account_set_alias(account, value); |
15818 | 163 |
164 /* Remember password and password */ | |
15823 | 165 purple_account_set_remember_password(account, |
15818 | 166 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->remember))); |
167 value = gnt_entry_get_text(GNT_ENTRY(dialog->password)); | |
15823 | 168 if (value && *value && purple_account_get_remember_password(account)) |
169 purple_account_set_password(account, value); | |
15818 | 170 else |
15823 | 171 purple_account_set_password(account, NULL); |
15818 | 172 |
173 /* Mail notification */ | |
15823 | 174 purple_account_set_check_mail(account, |
15818 | 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 { | |
15823 | 185 PurpleAccountOption *option = iter->data; |
15818 | 186 GntWidget *entry = entries->data; |
15823 | 187 PurplePrefType type = purple_account_option_get_type(option); |
188 const char *setting = purple_account_option_get_setting(option); | |
15818 | 189 |
15823 | 190 if (type == PURPLE_PREF_STRING) |
15818 | 191 { |
192 const char *value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
15823 | 193 purple_account_set_string(account, setting, value); |
15818 | 194 } |
15823 | 195 else if (type == PURPLE_PREF_INT) |
15818 | 196 { |
197 const char *str = gnt_entry_get_text(GNT_ENTRY(entry)); | |
198 int value = 0; | |
199 if (str) | |
200 value = atoi(str); | |
15823 | 201 purple_account_set_int(account, setting, value); |
15818 | 202 } |
15823 | 203 else if (type == PURPLE_PREF_BOOLEAN) |
15818 | 204 { |
205 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(entry)); | |
15823 | 206 purple_account_set_bool(account, setting, value); |
15818 | 207 } |
15823 | 208 else if (type == PURPLE_PREF_STRING_LIST) |
15818 | 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; | |
15823 | 228 PurplePlugin *plugin; |
229 PurplePluginProtocolInfo *prplinfo; | |
15818 | 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; | |
15823 | 250 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 251 |
15823 | 252 username = dialog->account ? g_strdup(purple_account_get_username(dialog->account)) : NULL; |
15818 | 253 |
254 for (iter = prplinfo->user_splits; iter; iter = iter->next) | |
255 { | |
15823 | 256 PurpleAccountUserSplit *split = iter->data; |
15818 | 257 GntWidget *entry; |
258 char *buf; | |
259 | |
260 hbox = gnt_hbox_new(TRUE); | |
261 gnt_box_add_widget(GNT_BOX(dialog->splits), hbox); | |
262 | |
15823 | 263 buf = g_strdup_printf("%s:", purple_account_user_split_get_text(split)); |
15818 | 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; | |
15823 | 277 PurpleAccountUserSplit *split = iter->data; |
15818 | 278 const char *value = NULL; |
279 char *s; | |
280 | |
281 if (dialog->account) | |
282 { | |
15823 | 283 s = strrchr(username, purple_account_user_split_get_separator(split)); |
15818 | 284 if (s != NULL) |
285 { | |
286 *s = '\0'; | |
287 s++; | |
288 value = s; | |
289 } | |
290 } | |
291 if (value == NULL) | |
15823 | 292 value = purple_account_user_split_get_default_value(split); |
15818 | 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 { | |
15823 | 307 PurplePlugin *plugin; |
308 PurplePluginProtocolInfo *prplinfo; | |
15818 | 309 GList *iter; |
310 GntWidget *vbox, *box; | |
15823 | 311 PurpleAccount *account; |
15818 | 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 | |
15823 | 335 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 336 |
337 account = dialog->account; | |
338 | |
339 for (iter = prplinfo->protocol_options; iter; iter = iter->next) | |
340 { | |
15823 | 341 PurpleAccountOption *option = iter->data; |
342 PurplePrefType type = purple_account_option_get_type(option); | |
15818 | 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 | |
15823 | 348 if (type == PURPLE_PREF_BOOLEAN) |
15818 | 349 { |
15823 | 350 GntWidget *widget = gnt_check_box_new(purple_account_option_get_text(option)); |
15818 | 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), | |
15823 | 356 purple_account_get_bool(account, |
357 purple_account_option_get_setting(option), | |
358 purple_account_option_get_default_bool(option))); | |
15818 | 359 else |
360 gnt_check_box_set_checked(GNT_CHECK_BOX(widget), | |
15823 | 361 purple_account_option_get_default_bool(option)); |
15818 | 362 } |
363 else | |
364 { | |
365 gnt_box_add_widget(GNT_BOX(box), | |
15823 | 366 gnt_label_new(purple_account_option_get_text(option))); |
15818 | 367 |
15823 | 368 if (type == PURPLE_PREF_STRING_LIST) |
15818 | 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 | |
15823 | 379 if (type == PURPLE_PREF_STRING) |
15818 | 380 { |
15823 | 381 const char *dv = purple_account_option_get_default_string(option); |
15818 | 382 |
383 if (account) | |
384 gnt_entry_set_text(GNT_ENTRY(entry), | |
15823 | 385 purple_account_get_string(account, |
386 purple_account_option_get_setting(option), dv)); | |
15818 | 387 else |
388 gnt_entry_set_text(GNT_ENTRY(entry), dv); | |
389 } | |
15823 | 390 else if (type == PURPLE_PREF_INT) |
15818 | 391 { |
392 char str[32]; | |
15823 | 393 int value = purple_account_option_get_default_int(option); |
15818 | 394 if (account) |
15823 | 395 value = purple_account_get_int(account, |
396 purple_account_option_get_setting(option), value); | |
15818 | 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 { | |
15823 | 413 PurplePlugin *plugin; |
414 PurplePluginProtocolInfo *prplinfo; | |
15818 | 415 |
416 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
417 if (!plugin) | |
418 return; | |
419 | |
15823 | 420 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 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), | |
15823 | 426 purple_account_get_check_mail(dialog->account)); |
15818 | 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), | |
15823 | 436 purple_account_get_remember_password(dialog->account)); |
15818 | 437 } |
438 | |
439 static void | |
15823 | 440 prpl_changed_cb(GntWidget *combo, PurplePlugin *old, PurplePlugin *new, AccountEditDialog *dialog) |
15818 | 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 | |
15823 | 450 edit_account(PurpleAccount *account) |
15818 | 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(); | |
15823 | 485 list = purple_plugins_get_protocols(); |
15818 | 486 for (iter = list; iter; iter = iter->next) |
487 { | |
488 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), iter->data, | |
15823 | 489 ((PurplePlugin*)iter->data)->info->name); |
15818 | 490 } |
491 | |
492 if (account) | |
493 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
15823 | 494 purple_plugins_find_with_id(purple_account_get_protocol_id(account))); |
15818 | 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) | |
15823 | 524 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_password(account)); |
15818 | 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) | |
15823 | 534 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_alias(account)); |
15818 | 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 { | |
15823 | 578 PurpleAccount *account = gnt_tree_get_selection_data(tree); |
15818 | 579 if (!account) |
580 return; | |
581 edit_account(account); | |
582 } | |
583 | |
584 static void | |
15823 | 585 really_delete_account(PurpleAccount *account) |
15818 | 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 } | |
15823 | 597 purple_request_close_with_handle(account); /* Close any other opened delete window */ |
598 purple_accounts_delete(account); | |
15818 | 599 } |
600 | |
601 static void | |
602 delete_account_cb(GntWidget *widget, GntTree *tree) | |
603 { | |
15823 | 604 PurpleAccount *account; |
15818 | 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?"), | |
15823 | 612 purple_account_get_username(account)); |
15818 | 613 |
16465
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
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:
16442
diff
changeset
|
615 account, NULL, NULL, account, 2, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
diff
changeset
|
616 _("Delete"), really_delete_account, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
diff
changeset
|
617 _("Cancel"), NULL); |
15818 | 618 g_free(prompt); |
619 } | |
620 | |
621 static void | |
622 account_toggled(GntWidget *widget, void *key, gpointer null) | |
623 { | |
15823 | 624 PurpleAccount *account = key; |
15818 | 625 |
15823 | 626 purple_account_set_enabled(account, FINCH_UI, gnt_tree_get_choice(GNT_TREE(widget), key)); |
15818 | 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 | |
15823 | 659 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15818 | 660 { |
15823 | 661 PurpleAccount *account = iter->data; |
15818 | 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 | |
15823 | 703 account_added_callback(PurpleAccount *account) |
15818 | 704 { |
705 if (accounts.window == NULL) | |
706 return; | |
707 account_add(account); | |
708 gnt_widget_draw(accounts.tree); | |
709 } | |
710 | |
711 static void | |
15823 | 712 account_removed_callback(PurpleAccount *account) |
15818 | 713 { |
714 if (accounts.window == NULL) | |
715 return; | |
716 | |
717 gnt_tree_remove(GNT_TREE(accounts.tree), account); | |
718 } | |
719 | |
17419
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
720 static void |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
721 account_abled_cb(PurpleAccount *account, gpointer user_data) |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
722 { |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
723 if (accounts.window == NULL) |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
724 return; |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
725 gnt_tree_set_choice(GNT_TREE(accounts.tree), account, |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
726 GPOINTER_TO_INT(user_data)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
727 } |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
728 |
15818 | 729 void finch_accounts_init() |
730 { | |
731 GList *iter; | |
732 | |
15823 | 733 purple_signal_connect(purple_accounts_get_handle(), "account-added", |
734 finch_accounts_get_handle(), PURPLE_CALLBACK(account_added_callback), | |
15818 | 735 NULL); |
15823 | 736 purple_signal_connect(purple_accounts_get_handle(), "account-removed", |
737 finch_accounts_get_handle(), PURPLE_CALLBACK(account_removed_callback), | |
15818 | 738 NULL); |
17419
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
739 purple_signal_connect(purple_accounts_get_handle(), "account-disabled", |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
740 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
741 PURPLE_CALLBACK(account_abled_cb), GINT_TO_POINTER(FALSE)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
742 purple_signal_connect(purple_accounts_get_handle(), "account-enabled", |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
743 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
744 PURPLE_CALLBACK(account_abled_cb), GINT_TO_POINTER(TRUE)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
745 |
15823 | 746 for (iter = purple_accounts_get_all(); iter; iter = iter->next) { |
747 if (purple_account_get_enabled(iter->data, FINCH_UI)) | |
15818 | 748 break; |
749 } | |
750 if (!iter) | |
751 finch_accounts_show_all(); | |
752 } | |
753 | |
754 void finch_accounts_uninit() | |
755 { | |
756 if (accounts.window) | |
757 gnt_widget_destroy(accounts.window); | |
758 } | |
759 | |
760 /* The following uiops stuff are copied from gtkaccount.c */ | |
761 typedef struct | |
762 { | |
15823 | 763 PurpleAccount *account; |
15818 | 764 char *username; |
765 char *alias; | |
766 } AddUserData; | |
767 | |
768 static char * | |
15823 | 769 make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user, |
15818 | 770 const char *id, const char *alias, const char *msg) |
771 { | |
772 if (msg != NULL && *msg == '\0') | |
773 msg = NULL; | |
774 | |
775 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"), | |
776 remote_user, | |
777 (alias != NULL ? " (" : ""), | |
778 (alias != NULL ? alias : ""), | |
779 (alias != NULL ? ")" : ""), | |
780 (id != NULL | |
781 ? id | |
15823 | 782 : (purple_connection_get_display_name(gc) != NULL |
783 ? purple_connection_get_display_name(gc) | |
784 : purple_account_get_username(account))), | |
15818 | 785 (msg != NULL ? ": " : "."), |
786 (msg != NULL ? msg : "")); | |
787 } | |
788 | |
789 static void | |
15823 | 790 notify_added(PurpleAccount *account, const char *remote_user, |
15818 | 791 const char *id, const char *alias, |
792 const char *msg) | |
793 { | |
794 char *buffer; | |
15823 | 795 PurpleConnection *gc; |
15818 | 796 |
15823 | 797 gc = purple_account_get_connection(account); |
15818 | 798 |
799 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
800 | |
15823 | 801 purple_notify_info(NULL, NULL, buffer, NULL); |
15818 | 802 |
803 g_free(buffer); | |
804 } | |
805 | |
806 static void | |
807 free_add_user_data(AddUserData *data) | |
808 { | |
809 g_free(data->username); | |
810 | |
811 if (data->alias != NULL) | |
812 g_free(data->alias); | |
813 | |
814 g_free(data); | |
815 } | |
816 | |
817 static void | |
818 add_user_cb(AddUserData *data) | |
819 { | |
15823 | 820 PurpleConnection *gc = purple_account_get_connection(data->account); |
15818 | 821 |
15823 | 822 if (g_list_find(purple_connections_get_all(), gc)) |
15818 | 823 { |
15823 | 824 purple_blist_request_add_buddy(data->account, data->username, |
15818 | 825 NULL, data->alias); |
826 } | |
827 | |
828 free_add_user_data(data); | |
829 } | |
830 | |
831 static void | |
15823 | 832 request_add(PurpleAccount *account, const char *remote_user, |
15818 | 833 const char *id, const char *alias, |
834 const char *msg) | |
835 { | |
836 char *buffer; | |
15823 | 837 PurpleConnection *gc; |
15818 | 838 AddUserData *data; |
839 | |
15823 | 840 gc = purple_account_get_connection(account); |
15818 | 841 |
842 data = g_new0(AddUserData, 1); | |
843 data->account = account; | |
844 data->username = g_strdup(remote_user); | |
845 data->alias = (alias != NULL ? g_strdup(alias) : NULL); | |
846 | |
847 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
15823 | 848 purple_request_action(NULL, NULL, _("Add buddy to your list?"), |
16442
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
|
849 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
|
850 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
|
851 data, 2, |
15818 | 852 _("Add"), G_CALLBACK(add_user_cb), |
853 _("Cancel"), G_CALLBACK(free_add_user_data)); | |
854 g_free(buffer); | |
855 } | |
856 | |
857 /* Copied from gtkaccount.c */ | |
858 typedef struct { | |
15823 | 859 PurpleAccountRequestAuthorizationCb auth_cb; |
860 PurpleAccountRequestAuthorizationCb deny_cb; | |
15818 | 861 void *data; |
862 char *username; | |
863 char *alias; | |
15823 | 864 PurpleAccount *account; |
15818 | 865 } auth_and_add; |
866 | |
867 static void | |
868 authorize_and_add_cb(auth_and_add *aa) | |
869 { | |
870 aa->auth_cb(aa->data); | |
15823 | 871 purple_blist_request_add_buddy(aa->account, aa->username, |
15818 | 872 NULL, aa->alias); |
873 | |
874 g_free(aa->username); | |
875 g_free(aa->alias); | |
876 g_free(aa); | |
877 } | |
878 | |
879 static void | |
880 deny_no_add_cb(auth_and_add *aa) | |
881 { | |
882 aa->deny_cb(aa->data); | |
883 | |
884 g_free(aa->username); | |
885 g_free(aa->alias); | |
886 g_free(aa); | |
887 } | |
888 | |
889 static void * | |
15823 | 890 finch_request_authorize(PurpleAccount *account, const char *remote_user, |
15818 | 891 const char *id, const char *alias, const char *message, gboolean on_list, |
892 GCallback auth_cb, GCallback deny_cb, void *user_data) | |
893 { | |
894 char *buffer; | |
15823 | 895 PurpleConnection *gc; |
15818 | 896 void *uihandle; |
897 | |
15823 | 898 gc = purple_account_get_connection(account); |
15818 | 899 if (message != NULL && *message == '\0') |
900 message = NULL; | |
901 | |
902 buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"), | |
903 remote_user, | |
904 (alias != NULL ? " (" : ""), | |
905 (alias != NULL ? alias : ""), | |
906 (alias != NULL ? ")" : ""), | |
907 (id != NULL | |
908 ? id | |
15823 | 909 : (purple_connection_get_display_name(gc) != NULL |
910 ? purple_connection_get_display_name(gc) | |
911 : purple_account_get_username(account))), | |
15818 | 912 (message != NULL ? ": " : "."), |
913 (message != NULL ? message : "")); | |
914 if (!on_list) { | |
915 auth_and_add *aa = g_new(auth_and_add, 1); | |
15823 | 916 aa->auth_cb = (PurpleAccountRequestAuthorizationCb)auth_cb; |
917 aa->deny_cb = (PurpleAccountRequestAuthorizationCb)deny_cb; | |
15818 | 918 aa->data = user_data; |
919 aa->username = g_strdup(remote_user); | |
920 aa->alias = g_strdup(alias); | |
921 aa->account = account; | |
15823 | 922 uihandle = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL, |
16442
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
|
923 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
|
924 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
|
925 aa, 2, |
15818 | 926 _("Authorize"), authorize_and_add_cb, |
927 _("Deny"), deny_no_add_cb); | |
928 } else { | |
15823 | 929 uihandle = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL, |
16442
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
|
930 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
|
931 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
|
932 user_data, 2, |
15818 | 933 _("Authorize"), auth_cb, |
934 _("Deny"), deny_cb); | |
935 } | |
936 g_free(buffer); | |
937 return uihandle; | |
938 } | |
939 | |
940 static void | |
941 finch_request_close(void *uihandle) | |
942 { | |
15823 | 943 purple_request_close(PURPLE_REQUEST_ACTION, uihandle); |
15818 | 944 } |
945 | |
15823 | 946 static PurpleAccountUiOps ui_ops = |
15818 | 947 { |
17104
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
948 notify_added, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
949 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
950 request_add, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
951 finch_request_authorize, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
952 finch_request_close, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
953 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
954 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
955 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
956 NULL |
15818 | 957 }; |
958 | |
15823 | 959 PurpleAccountUiOps *finch_accounts_get_ui_ops() |
15818 | 960 { |
961 return &ui_ops; | |
962 } | |
963 |