15817
|
1 /**
|
|
2 * @file gntaccount.c GNT Account API
|
|
3 * @ingroup gntui
|
|
4 *
|
15822
|
5 * purple
|
15817
|
6 *
|
15822
|
7 * Purple 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
|
15822
|
614 purple_request_action(account, _("Delete Account"), prompt, NULL, 0, account, 2,
|
15817
|
615 _("Delete"), really_delete_account, _("Cancel"), NULL);
|
|
616 g_free(prompt);
|
|
617 }
|
|
618
|
|
619 static void
|
|
620 account_toggled(GntWidget *widget, void *key, gpointer null)
|
|
621 {
|
15822
|
622 PurpleAccount *account = key;
|
15817
|
623
|
15822
|
624 purple_account_set_enabled(account, FINCH_UI, gnt_tree_get_choice(GNT_TREE(widget), key));
|
15817
|
625 }
|
|
626
|
|
627 static void
|
|
628 reset_accounts_win(GntWidget *widget, gpointer null)
|
|
629 {
|
|
630 accounts.window = NULL;
|
|
631 accounts.tree = NULL;
|
|
632 }
|
|
633
|
|
634 void finch_accounts_show_all()
|
|
635 {
|
|
636 GList *iter;
|
|
637 GntWidget *box, *button;
|
|
638
|
|
639 if (accounts.window)
|
|
640 return;
|
|
641
|
|
642 accounts.window = gnt_vbox_new(FALSE);
|
|
643 gnt_box_set_toplevel(GNT_BOX(accounts.window), TRUE);
|
|
644 gnt_box_set_title(GNT_BOX(accounts.window), _("Accounts"));
|
|
645 gnt_box_set_pad(GNT_BOX(accounts.window), 0);
|
|
646 gnt_box_set_alignment(GNT_BOX(accounts.window), GNT_ALIGN_MID);
|
|
647 gnt_widget_set_name(accounts.window, "accounts");
|
|
648
|
|
649 gnt_box_add_widget(GNT_BOX(accounts.window),
|
|
650 gnt_label_new(_("You can enable/disable accounts from the following list.")));
|
|
651
|
|
652 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE));
|
|
653
|
|
654 accounts.tree = gnt_tree_new_with_columns(2);
|
|
655 GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER);
|
|
656
|
15822
|
657 for (iter = purple_accounts_get_all(); iter; iter = iter->next)
|
15817
|
658 {
|
15822
|
659 PurpleAccount *account = iter->data;
|
15817
|
660 account_add(account);
|
|
661 }
|
|
662
|
|
663 g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL);
|
|
664
|
|
665 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 0, 40);
|
|
666 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 1, 10);
|
|
667 gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree);
|
|
668
|
|
669 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE));
|
|
670
|
|
671 box = gnt_hbox_new(FALSE);
|
|
672
|
|
673 button = gnt_button_new(_("Add"));
|
|
674 gnt_box_add_widget(GNT_BOX(box), button);
|
|
675 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(add_account_cb), NULL);
|
|
676
|
|
677 button = gnt_button_new(_("Modify"));
|
|
678 gnt_box_add_widget(GNT_BOX(box), button);
|
|
679 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(modify_account_cb), accounts.tree);
|
|
680
|
|
681 button = gnt_button_new(_("Delete"));
|
|
682 gnt_box_add_widget(GNT_BOX(box), button);
|
|
683 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(delete_account_cb), accounts.tree);
|
|
684
|
|
685 gnt_box_add_widget(GNT_BOX(accounts.window), box);
|
|
686
|
|
687 g_signal_connect(G_OBJECT(accounts.window), "destroy", G_CALLBACK(reset_accounts_win), NULL);
|
|
688
|
|
689 gnt_widget_show(accounts.window);
|
|
690 }
|
|
691
|
|
692 static gpointer
|
|
693 finch_accounts_get_handle()
|
|
694 {
|
|
695 static int handle;
|
|
696
|
|
697 return &handle;
|
|
698 }
|
|
699
|
|
700 static void
|
15822
|
701 account_added_callback(PurpleAccount *account)
|
15817
|
702 {
|
|
703 if (accounts.window == NULL)
|
|
704 return;
|
|
705 account_add(account);
|
|
706 gnt_widget_draw(accounts.tree);
|
|
707 }
|
|
708
|
|
709 static void
|
15822
|
710 account_removed_callback(PurpleAccount *account)
|
15817
|
711 {
|
|
712 if (accounts.window == NULL)
|
|
713 return;
|
|
714
|
|
715 gnt_tree_remove(GNT_TREE(accounts.tree), account);
|
|
716 }
|
|
717
|
|
718 void finch_accounts_init()
|
|
719 {
|
|
720 GList *iter;
|
|
721
|
15822
|
722 purple_signal_connect(purple_accounts_get_handle(), "account-added",
|
|
723 finch_accounts_get_handle(), PURPLE_CALLBACK(account_added_callback),
|
15817
|
724 NULL);
|
15822
|
725 purple_signal_connect(purple_accounts_get_handle(), "account-removed",
|
|
726 finch_accounts_get_handle(), PURPLE_CALLBACK(account_removed_callback),
|
15817
|
727 NULL);
|
|
728
|
15822
|
729 for (iter = purple_accounts_get_all(); iter; iter = iter->next) {
|
|
730 if (purple_account_get_enabled(iter->data, FINCH_UI))
|
15817
|
731 break;
|
|
732 }
|
|
733 if (!iter)
|
|
734 finch_accounts_show_all();
|
|
735 }
|
|
736
|
|
737 void finch_accounts_uninit()
|
|
738 {
|
|
739 if (accounts.window)
|
|
740 gnt_widget_destroy(accounts.window);
|
|
741 }
|
|
742
|
|
743 /* The following uiops stuff are copied from gtkaccount.c */
|
|
744 typedef struct
|
|
745 {
|
15822
|
746 PurpleAccount *account;
|
15817
|
747 char *username;
|
|
748 char *alias;
|
|
749 } AddUserData;
|
|
750
|
|
751 static char *
|
15822
|
752 make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user,
|
15817
|
753 const char *id, const char *alias, const char *msg)
|
|
754 {
|
|
755 if (msg != NULL && *msg == '\0')
|
|
756 msg = NULL;
|
|
757
|
|
758 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"),
|
|
759 remote_user,
|
|
760 (alias != NULL ? " (" : ""),
|
|
761 (alias != NULL ? alias : ""),
|
|
762 (alias != NULL ? ")" : ""),
|
|
763 (id != NULL
|
|
764 ? id
|
15822
|
765 : (purple_connection_get_display_name(gc) != NULL
|
|
766 ? purple_connection_get_display_name(gc)
|
|
767 : purple_account_get_username(account))),
|
15817
|
768 (msg != NULL ? ": " : "."),
|
|
769 (msg != NULL ? msg : ""));
|
|
770 }
|
|
771
|
|
772 static void
|
15822
|
773 notify_added(PurpleAccount *account, const char *remote_user,
|
15817
|
774 const char *id, const char *alias,
|
|
775 const char *msg)
|
|
776 {
|
|
777 char *buffer;
|
15822
|
778 PurpleConnection *gc;
|
15817
|
779
|
15822
|
780 gc = purple_account_get_connection(account);
|
15817
|
781
|
|
782 buffer = make_info(account, gc, remote_user, id, alias, msg);
|
|
783
|
15822
|
784 purple_notify_info(NULL, NULL, buffer, NULL);
|
15817
|
785
|
|
786 g_free(buffer);
|
|
787 }
|
|
788
|
|
789 static void
|
|
790 free_add_user_data(AddUserData *data)
|
|
791 {
|
|
792 g_free(data->username);
|
|
793
|
|
794 if (data->alias != NULL)
|
|
795 g_free(data->alias);
|
|
796
|
|
797 g_free(data);
|
|
798 }
|
|
799
|
|
800 static void
|
|
801 add_user_cb(AddUserData *data)
|
|
802 {
|
15822
|
803 PurpleConnection *gc = purple_account_get_connection(data->account);
|
15817
|
804
|
15822
|
805 if (g_list_find(purple_connections_get_all(), gc))
|
15817
|
806 {
|
15822
|
807 purple_blist_request_add_buddy(data->account, data->username,
|
15817
|
808 NULL, data->alias);
|
|
809 }
|
|
810
|
|
811 free_add_user_data(data);
|
|
812 }
|
|
813
|
|
814 static void
|
15822
|
815 request_add(PurpleAccount *account, const char *remote_user,
|
15817
|
816 const char *id, const char *alias,
|
|
817 const char *msg)
|
|
818 {
|
|
819 char *buffer;
|
15822
|
820 PurpleConnection *gc;
|
15817
|
821 AddUserData *data;
|
|
822
|
15822
|
823 gc = purple_account_get_connection(account);
|
15817
|
824
|
|
825 data = g_new0(AddUserData, 1);
|
|
826 data->account = account;
|
|
827 data->username = g_strdup(remote_user);
|
|
828 data->alias = (alias != NULL ? g_strdup(alias) : NULL);
|
|
829
|
|
830 buffer = make_info(account, gc, remote_user, id, alias, msg);
|
15822
|
831 purple_request_action(NULL, NULL, _("Add buddy to your list?"),
|
|
832 buffer, PURPLE_DEFAULT_ACTION_NONE, data, 2,
|
15817
|
833 _("Add"), G_CALLBACK(add_user_cb),
|
|
834 _("Cancel"), G_CALLBACK(free_add_user_data));
|
|
835 g_free(buffer);
|
|
836 }
|
|
837
|
|
838 /* Copied from gtkaccount.c */
|
|
839 typedef struct {
|
15822
|
840 PurpleAccountRequestAuthorizationCb auth_cb;
|
|
841 PurpleAccountRequestAuthorizationCb deny_cb;
|
15817
|
842 void *data;
|
|
843 char *username;
|
|
844 char *alias;
|
15822
|
845 PurpleAccount *account;
|
15817
|
846 } auth_and_add;
|
|
847
|
|
848 static void
|
|
849 authorize_and_add_cb(auth_and_add *aa)
|
|
850 {
|
|
851 aa->auth_cb(aa->data);
|
15822
|
852 purple_blist_request_add_buddy(aa->account, aa->username,
|
15817
|
853 NULL, aa->alias);
|
|
854
|
|
855 g_free(aa->username);
|
|
856 g_free(aa->alias);
|
|
857 g_free(aa);
|
|
858 }
|
|
859
|
|
860 static void
|
|
861 deny_no_add_cb(auth_and_add *aa)
|
|
862 {
|
|
863 aa->deny_cb(aa->data);
|
|
864
|
|
865 g_free(aa->username);
|
|
866 g_free(aa->alias);
|
|
867 g_free(aa);
|
|
868 }
|
|
869
|
|
870 static void *
|
15822
|
871 finch_request_authorize(PurpleAccount *account, const char *remote_user,
|
15817
|
872 const char *id, const char *alias, const char *message, gboolean on_list,
|
|
873 GCallback auth_cb, GCallback deny_cb, void *user_data)
|
|
874 {
|
|
875 char *buffer;
|
15822
|
876 PurpleConnection *gc;
|
15817
|
877 void *uihandle;
|
|
878
|
15822
|
879 gc = purple_account_get_connection(account);
|
15817
|
880 if (message != NULL && *message == '\0')
|
|
881 message = NULL;
|
|
882
|
|
883 buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"),
|
|
884 remote_user,
|
|
885 (alias != NULL ? " (" : ""),
|
|
886 (alias != NULL ? alias : ""),
|
|
887 (alias != NULL ? ")" : ""),
|
|
888 (id != NULL
|
|
889 ? id
|
15822
|
890 : (purple_connection_get_display_name(gc) != NULL
|
|
891 ? purple_connection_get_display_name(gc)
|
|
892 : purple_account_get_username(account))),
|
15817
|
893 (message != NULL ? ": " : "."),
|
|
894 (message != NULL ? message : ""));
|
|
895 if (!on_list) {
|
|
896 auth_and_add *aa = g_new(auth_and_add, 1);
|
15822
|
897 aa->auth_cb = (PurpleAccountRequestAuthorizationCb)auth_cb;
|
|
898 aa->deny_cb = (PurpleAccountRequestAuthorizationCb)deny_cb;
|
15817
|
899 aa->data = user_data;
|
|
900 aa->username = g_strdup(remote_user);
|
|
901 aa->alias = g_strdup(alias);
|
|
902 aa->account = account;
|
15822
|
903 uihandle = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL,
|
|
904 PURPLE_DEFAULT_ACTION_NONE, aa, 2,
|
15817
|
905 _("Authorize"), authorize_and_add_cb,
|
|
906 _("Deny"), deny_no_add_cb);
|
|
907 } else {
|
15822
|
908 uihandle = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL,
|
|
909 PURPLE_DEFAULT_ACTION_NONE, user_data, 2,
|
15817
|
910 _("Authorize"), auth_cb,
|
|
911 _("Deny"), deny_cb);
|
|
912 }
|
|
913 g_free(buffer);
|
|
914 return uihandle;
|
|
915 }
|
|
916
|
|
917 static void
|
|
918 finch_request_close(void *uihandle)
|
|
919 {
|
15822
|
920 purple_request_close(PURPLE_REQUEST_ACTION, uihandle);
|
15817
|
921 }
|
|
922
|
15822
|
923 static PurpleAccountUiOps ui_ops =
|
15817
|
924 {
|
|
925 .notify_added = notify_added,
|
|
926 .status_changed = NULL,
|
|
927 .request_add = request_add,
|
|
928 .request_authorize = finch_request_authorize,
|
|
929 .close_account_request = finch_request_close
|
|
930 };
|
|
931
|
15822
|
932 PurpleAccountUiOps *finch_accounts_get_ui_ops()
|
15817
|
933 {
|
|
934 return &ui_ops;
|
|
935 }
|
|
936
|