Mercurial > pidgin
annotate finch/gntaccount.c @ 20207:48770cf120f1
applied changes from 11fef11dff49357783d6656f9e83bf59403163d0
through b888347e5e58acfcc7d520ae290c34986442acb6
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 28 Sep 2007 15:36:48 +0000 |
parents | 41cad24fd6df |
children | 2c495b5e2193 6bf32c9e15a7 |
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 | |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19392
diff
changeset
|
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15817 | 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> | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18432
diff
changeset
|
34 #include <gntutils.h> |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
35 #include <gntwindow.h> |
15817 | 36 |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18063
diff
changeset
|
37 #include "finch.h" |
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18063
diff
changeset
|
38 |
15817 | 39 #include <account.h> |
40 #include <accountopt.h> | |
41 #include <connection.h> | |
42 #include <notify.h> | |
43 #include <plugin.h> | |
44 #include <request.h> | |
45 | |
46 #include "gntaccount.h" | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
47 #include "gntblist.h" |
15817 | 48 |
49 #include <string.h> | |
50 | |
51 typedef struct | |
52 { | |
53 GntWidget *window; | |
54 GntWidget *tree; | |
55 } FinchAccountList; | |
56 | |
57 static FinchAccountList accounts; | |
58 | |
59 typedef struct | |
60 { | |
15822 | 61 PurpleAccount *account; /* NULL for a new account */ |
15817 | 62 |
63 GntWidget *window; | |
64 | |
65 GntWidget *protocol; | |
66 GntWidget *screenname; | |
67 GntWidget *password; | |
68 GntWidget *alias; | |
69 | |
70 GntWidget *splits; | |
71 GList *split_entries; | |
72 | |
73 GList *prpl_entries; | |
74 GntWidget *prpls; | |
75 | |
76 GntWidget *newmail; | |
77 GntWidget *remember; | |
78 } AccountEditDialog; | |
79 | |
80 /* This is necessary to close an edit-dialog when an account is deleted */ | |
81 static GList *accountdialogs; | |
82 | |
83 static void | |
15822 | 84 account_add(PurpleAccount *account) |
15817 | 85 { |
86 gnt_tree_add_choice(GNT_TREE(accounts.tree), account, | |
87 gnt_tree_create_row(GNT_TREE(accounts.tree), | |
15822 | 88 purple_account_get_username(account), |
89 purple_account_get_protocol_name(account)), | |
15817 | 90 NULL, NULL); |
91 gnt_tree_set_choice(GNT_TREE(accounts.tree), account, | |
15822 | 92 purple_account_get_enabled(account, FINCH_UI)); |
15817 | 93 } |
94 | |
95 static void | |
96 edit_dialog_destroy(AccountEditDialog *dialog) | |
97 { | |
98 accountdialogs = g_list_remove(accountdialogs, dialog); | |
99 g_list_free(dialog->prpl_entries); | |
100 g_list_free(dialog->split_entries); | |
101 g_free(dialog); | |
102 } | |
103 | |
104 static void | |
105 save_account_cb(AccountEditDialog *dialog) | |
106 { | |
15822 | 107 PurpleAccount *account; |
108 PurplePlugin *plugin; | |
109 PurplePluginProtocolInfo *prplinfo; | |
15817 | 110 const char *value; |
111 GString *username; | |
112 | |
113 /* XXX: Do some error checking first. */ | |
114 | |
115 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
15822 | 116 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 117 |
118 /* Screenname && user-splits */ | |
119 value = gnt_entry_get_text(GNT_ENTRY(dialog->screenname)); | |
120 | |
121 if (value == NULL || *value == '\0') | |
122 { | |
15822 | 123 purple_notify_error(NULL, _("Error"), _("Account was not added"), |
15817 | 124 _("Screenname of an account must be non-empty.")); |
125 return; | |
126 } | |
127 | |
128 username = g_string_new(value); | |
129 | |
130 if (prplinfo != NULL) | |
131 { | |
132 GList *iter, *entries; | |
133 for (iter = prplinfo->user_splits, entries = dialog->split_entries; | |
134 iter && entries; iter = iter->next, entries = entries->next) | |
135 { | |
15822 | 136 PurpleAccountUserSplit *split = iter->data; |
15817 | 137 GntWidget *entry = entries->data; |
138 | |
139 value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
140 if (value == NULL || *value == '\0') | |
15822 | 141 value = purple_account_user_split_get_default_value(split); |
15817 | 142 g_string_append_printf(username, "%c%s", |
15822 | 143 purple_account_user_split_get_separator(split), |
15817 | 144 value); |
145 } | |
146 } | |
147 | |
148 if (dialog->account == NULL) | |
149 { | |
15822 | 150 account = purple_account_new(username->str, purple_plugin_get_id(plugin)); |
151 purple_accounts_add(account); | |
15817 | 152 } |
153 else | |
154 { | |
155 account = dialog->account; | |
156 | |
157 /* Protocol */ | |
15822 | 158 purple_account_set_protocol_id(account, purple_plugin_get_id(plugin)); |
159 purple_account_set_username(account, username->str); | |
15817 | 160 } |
161 g_string_free(username, TRUE); | |
162 | |
163 /* Alias */ | |
164 value = gnt_entry_get_text(GNT_ENTRY(dialog->alias)); | |
165 if (value && *value) | |
15822 | 166 purple_account_set_alias(account, value); |
15817 | 167 |
168 /* Remember password and password */ | |
15822 | 169 purple_account_set_remember_password(account, |
15817 | 170 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->remember))); |
171 value = gnt_entry_get_text(GNT_ENTRY(dialog->password)); | |
19762
656506d8935e
Don't prompt for the password again if the user entered it once in the account window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
172 if (value && *value) |
15822 | 173 purple_account_set_password(account, value); |
15817 | 174 else |
15822 | 175 purple_account_set_password(account, NULL); |
15817 | 176 |
177 /* Mail notification */ | |
15822 | 178 purple_account_set_check_mail(account, |
15817 | 179 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->newmail))); |
180 | |
181 /* Protocol options */ | |
182 if (prplinfo) | |
183 { | |
184 GList *iter, *entries; | |
185 | |
186 for (iter = prplinfo->protocol_options, entries = dialog->prpl_entries; | |
187 iter && entries; iter = iter->next, entries = entries->next) | |
188 { | |
15822 | 189 PurpleAccountOption *option = iter->data; |
15817 | 190 GntWidget *entry = entries->data; |
15822 | 191 PurplePrefType type = purple_account_option_get_type(option); |
192 const char *setting = purple_account_option_get_setting(option); | |
15817 | 193 |
15822 | 194 if (type == PURPLE_PREF_STRING) |
15817 | 195 { |
196 const char *value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
15822 | 197 purple_account_set_string(account, setting, value); |
15817 | 198 } |
15822 | 199 else if (type == PURPLE_PREF_INT) |
15817 | 200 { |
201 const char *str = gnt_entry_get_text(GNT_ENTRY(entry)); | |
202 int value = 0; | |
203 if (str) | |
204 value = atoi(str); | |
15822 | 205 purple_account_set_int(account, setting, value); |
15817 | 206 } |
15822 | 207 else if (type == PURPLE_PREF_BOOLEAN) |
15817 | 208 { |
209 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(entry)); | |
15822 | 210 purple_account_set_bool(account, setting, value); |
15817 | 211 } |
15822 | 212 else if (type == PURPLE_PREF_STRING_LIST) |
15817 | 213 { |
214 /* TODO: */ | |
215 } | |
216 else | |
217 { | |
218 g_assert_not_reached(); | |
219 } | |
220 } | |
221 } | |
222 | |
223 /* XXX: Proxy options */ | |
224 | |
19392
74f7d5e4a605
Focus the modified/created account in the accounts window after modifying/
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18829
diff
changeset
|
225 if (accounts.window && accounts.tree) { |
74f7d5e4a605
Focus the modified/created account in the accounts window after modifying/
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18829
diff
changeset
|
226 gnt_tree_set_selected(GNT_TREE(accounts.tree), account); |
74f7d5e4a605
Focus the modified/created account in the accounts window after modifying/
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18829
diff
changeset
|
227 gnt_box_give_focus_to_child(GNT_BOX(accounts.window), accounts.tree); |
74f7d5e4a605
Focus the modified/created account in the accounts window after modifying/
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18829
diff
changeset
|
228 } |
74f7d5e4a605
Focus the modified/created account in the accounts window after modifying/
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18829
diff
changeset
|
229 |
15817 | 230 gnt_widget_destroy(dialog->window); |
231 } | |
232 | |
233 static void | |
234 update_user_splits(AccountEditDialog *dialog) | |
235 { | |
236 GntWidget *hbox; | |
15822 | 237 PurplePlugin *plugin; |
238 PurplePluginProtocolInfo *prplinfo; | |
15817 | 239 GList *iter, *entries; |
240 char *username = NULL; | |
241 | |
242 if (dialog->splits) | |
243 { | |
244 gnt_box_remove_all(GNT_BOX(dialog->splits)); | |
245 g_list_free(dialog->split_entries); | |
246 } | |
247 else | |
248 { | |
249 dialog->splits = gnt_vbox_new(FALSE); | |
250 gnt_box_set_pad(GNT_BOX(dialog->splits), 0); | |
251 gnt_box_set_fill(GNT_BOX(dialog->splits), TRUE); | |
252 } | |
253 | |
254 dialog->split_entries = NULL; | |
255 | |
256 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
257 if (!plugin) | |
258 return; | |
15822 | 259 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 260 |
15822 | 261 username = dialog->account ? g_strdup(purple_account_get_username(dialog->account)) : NULL; |
15817 | 262 |
263 for (iter = prplinfo->user_splits; iter; iter = iter->next) | |
264 { | |
15822 | 265 PurpleAccountUserSplit *split = iter->data; |
15817 | 266 GntWidget *entry; |
267 char *buf; | |
268 | |
269 hbox = gnt_hbox_new(TRUE); | |
270 gnt_box_add_widget(GNT_BOX(dialog->splits), hbox); | |
271 | |
15822 | 272 buf = g_strdup_printf("%s:", purple_account_user_split_get_text(split)); |
15817 | 273 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(buf)); |
274 | |
275 entry = gnt_entry_new(NULL); | |
276 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
277 | |
278 dialog->split_entries = g_list_append(dialog->split_entries, entry); | |
279 g_free(buf); | |
280 } | |
281 | |
282 for (iter = g_list_last(prplinfo->user_splits), entries = g_list_last(dialog->split_entries); | |
283 iter && entries; iter = iter->prev, entries = entries->prev) | |
284 { | |
285 GntWidget *entry = entries->data; | |
15822 | 286 PurpleAccountUserSplit *split = iter->data; |
15817 | 287 const char *value = NULL; |
288 char *s; | |
289 | |
290 if (dialog->account) | |
291 { | |
18037
e3e42a99070e
jabber can contain @ symbols and / in the resource, so we have to look for
Nathan Walp <nwalp@pidgin.im>
parents:
17346
diff
changeset
|
292 if(purple_account_user_split_get_reverse(split)) |
e3e42a99070e
jabber can contain @ symbols and / in the resource, so we have to look for
Nathan Walp <nwalp@pidgin.im>
parents:
17346
diff
changeset
|
293 s = strrchr(username, purple_account_user_split_get_separator(split)); |
e3e42a99070e
jabber can contain @ symbols and / in the resource, so we have to look for
Nathan Walp <nwalp@pidgin.im>
parents:
17346
diff
changeset
|
294 else |
e3e42a99070e
jabber can contain @ symbols and / in the resource, so we have to look for
Nathan Walp <nwalp@pidgin.im>
parents:
17346
diff
changeset
|
295 s = strchr(username, purple_account_user_split_get_separator(split)); |
e3e42a99070e
jabber can contain @ symbols and / in the resource, so we have to look for
Nathan Walp <nwalp@pidgin.im>
parents:
17346
diff
changeset
|
296 |
15817 | 297 if (s != NULL) |
298 { | |
299 *s = '\0'; | |
300 s++; | |
301 value = s; | |
302 } | |
303 } | |
304 if (value == NULL) | |
15822 | 305 value = purple_account_user_split_get_default_value(split); |
15817 | 306 |
307 if (value != NULL) | |
308 gnt_entry_set_text(GNT_ENTRY(entry), value); | |
309 } | |
310 | |
311 if (username != NULL) | |
312 gnt_entry_set_text(GNT_ENTRY(dialog->screenname), username); | |
313 | |
314 g_free(username); | |
315 } | |
316 | |
317 static void | |
318 add_protocol_options(AccountEditDialog *dialog) | |
319 { | |
15822 | 320 PurplePlugin *plugin; |
321 PurplePluginProtocolInfo *prplinfo; | |
15817 | 322 GList *iter; |
323 GntWidget *vbox, *box; | |
15822 | 324 PurpleAccount *account; |
15817 | 325 |
326 if (dialog->prpls) | |
327 gnt_box_remove_all(GNT_BOX(dialog->prpls)); | |
328 else | |
329 { | |
330 dialog->prpls = vbox = gnt_vbox_new(FALSE); | |
331 gnt_box_set_pad(GNT_BOX(vbox), 0); | |
332 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_LEFT); | |
333 gnt_box_set_fill(GNT_BOX(vbox), TRUE); | |
334 } | |
335 | |
336 if (dialog->prpl_entries) | |
337 { | |
338 g_list_free(dialog->prpl_entries); | |
339 dialog->prpl_entries = NULL; | |
340 } | |
341 | |
342 vbox = dialog->prpls; | |
343 | |
344 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
345 if (!plugin) | |
346 return; | |
347 | |
15822 | 348 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 349 |
350 account = dialog->account; | |
351 | |
352 for (iter = prplinfo->protocol_options; iter; iter = iter->next) | |
353 { | |
15822 | 354 PurpleAccountOption *option = iter->data; |
355 PurplePrefType type = purple_account_option_get_type(option); | |
15817 | 356 |
357 box = gnt_hbox_new(TRUE); | |
358 gnt_box_set_pad(GNT_BOX(box), 0); | |
359 gnt_box_add_widget(GNT_BOX(vbox), box); | |
360 | |
15822 | 361 if (type == PURPLE_PREF_BOOLEAN) |
15817 | 362 { |
15822 | 363 GntWidget *widget = gnt_check_box_new(purple_account_option_get_text(option)); |
15817 | 364 gnt_box_add_widget(GNT_BOX(box), widget); |
365 dialog->prpl_entries = g_list_append(dialog->prpl_entries, widget); | |
366 | |
367 if (account) | |
368 gnt_check_box_set_checked(GNT_CHECK_BOX(widget), | |
15822 | 369 purple_account_get_bool(account, |
370 purple_account_option_get_setting(option), | |
371 purple_account_option_get_default_bool(option))); | |
15817 | 372 else |
373 gnt_check_box_set_checked(GNT_CHECK_BOX(widget), | |
15822 | 374 purple_account_option_get_default_bool(option)); |
15817 | 375 } |
376 else | |
377 { | |
378 gnt_box_add_widget(GNT_BOX(box), | |
15822 | 379 gnt_label_new(purple_account_option_get_text(option))); |
15817 | 380 |
15822 | 381 if (type == PURPLE_PREF_STRING_LIST) |
15817 | 382 { |
383 /* TODO: Use a combobox */ | |
384 /* Don't forget to append the widget to prpl_entries */ | |
385 } | |
386 else | |
387 { | |
388 GntWidget *entry = gnt_entry_new(NULL); | |
389 gnt_box_add_widget(GNT_BOX(box), entry); | |
390 dialog->prpl_entries = g_list_append(dialog->prpl_entries, entry); | |
391 | |
15822 | 392 if (type == PURPLE_PREF_STRING) |
15817 | 393 { |
15822 | 394 const char *dv = purple_account_option_get_default_string(option); |
15817 | 395 |
396 if (account) | |
397 gnt_entry_set_text(GNT_ENTRY(entry), | |
15822 | 398 purple_account_get_string(account, |
399 purple_account_option_get_setting(option), dv)); | |
15817 | 400 else |
401 gnt_entry_set_text(GNT_ENTRY(entry), dv); | |
402 } | |
15822 | 403 else if (type == PURPLE_PREF_INT) |
15817 | 404 { |
405 char str[32]; | |
15822 | 406 int value = purple_account_option_get_default_int(option); |
15817 | 407 if (account) |
15822 | 408 value = purple_account_get_int(account, |
409 purple_account_option_get_setting(option), value); | |
15817 | 410 snprintf(str, sizeof(str), "%d", value); |
411 gnt_entry_set_flag(GNT_ENTRY(entry), GNT_ENTRY_FLAG_INT); | |
412 gnt_entry_set_text(GNT_ENTRY(entry), str); | |
413 } | |
414 else | |
415 { | |
416 g_assert_not_reached(); | |
417 } | |
418 } | |
419 } | |
420 } | |
421 } | |
422 | |
423 static void | |
424 update_user_options(AccountEditDialog *dialog) | |
425 { | |
15822 | 426 PurplePlugin *plugin; |
427 PurplePluginProtocolInfo *prplinfo; | |
15817 | 428 |
429 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
430 if (!plugin) | |
431 return; | |
432 | |
15822 | 433 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15817 | 434 |
435 if (dialog->newmail == NULL) | |
436 dialog->newmail = gnt_check_box_new(_("New mail notifications")); | |
437 if (dialog->account) | |
438 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->newmail), | |
15822 | 439 purple_account_get_check_mail(dialog->account)); |
15817 | 440 if (!prplinfo || !(prplinfo->options & OPT_PROTO_MAIL_CHECK)) |
441 gnt_widget_set_visible(dialog->newmail, FALSE); | |
442 else | |
443 gnt_widget_set_visible(dialog->newmail, TRUE); | |
444 | |
445 if (dialog->remember == NULL) | |
446 dialog->remember = gnt_check_box_new(_("Remember password")); | |
447 if (dialog->account) | |
448 gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->remember), | |
15822 | 449 purple_account_get_remember_password(dialog->account)); |
15817 | 450 } |
451 | |
452 static void | |
15822 | 453 prpl_changed_cb(GntWidget *combo, PurplePlugin *old, PurplePlugin *new, AccountEditDialog *dialog) |
15817 | 454 { |
455 update_user_splits(dialog); | |
456 add_protocol_options(dialog); | |
457 update_user_options(dialog); /* This may not be necessary here */ | |
458 gnt_box_readjust(GNT_BOX(dialog->window)); | |
459 gnt_widget_draw(dialog->window); | |
460 } | |
461 | |
462 static void | |
15822 | 463 edit_account(PurpleAccount *account) |
15817 | 464 { |
465 GntWidget *window, *hbox; | |
466 GntWidget *combo, *button, *entry; | |
467 GList *list, *iter; | |
468 AccountEditDialog *dialog; | |
469 | |
470 if (account) | |
471 { | |
472 GList *iter; | |
473 for (iter = accountdialogs; iter; iter = iter->next) | |
474 { | |
475 AccountEditDialog *dlg = iter->data; | |
476 if (dlg->account == account) | |
477 return; | |
478 } | |
479 } | |
480 | |
18432
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
481 list = purple_plugins_get_protocols(); |
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
482 if (list == NULL) { |
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
483 purple_notify_error(NULL, _("Error"), |
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
484 _("There's no protocol plugins installed."), |
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
485 _("(You probably forgot to 'make install'.)")); |
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
486 return; |
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
487 } |
f5a17e7e4bfa
Do not crash when people run finch without 'make install'ing first.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
488 |
15817 | 489 dialog = g_new0(AccountEditDialog, 1); |
490 accountdialogs = g_list_prepend(accountdialogs, dialog); | |
491 | |
492 dialog->window = window = gnt_vbox_new(FALSE); | |
493 dialog->account = account; | |
494 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
495 gnt_box_set_title(GNT_BOX(window), account ? _("Modify Account") : _("New Account")); | |
496 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
497 gnt_box_set_pad(GNT_BOX(window), 0); | |
498 gnt_widget_set_name(window, "edit-account"); | |
499 gnt_box_set_fill(GNT_BOX(window), TRUE); | |
500 | |
501 hbox = gnt_hbox_new(TRUE); | |
502 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
503 gnt_box_add_widget(GNT_BOX(window), hbox); | |
504 | |
505 dialog->protocol = combo = gnt_combo_box_new(); | |
506 for (iter = list; iter; iter = iter->next) | |
507 { | |
508 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), iter->data, | |
15822 | 509 ((PurplePlugin*)iter->data)->info->name); |
15817 | 510 } |
511 | |
512 if (account) | |
513 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
15822 | 514 purple_plugins_find_with_id(purple_account_get_protocol_id(account))); |
15817 | 515 else |
516 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), list->data); | |
517 | |
518 g_signal_connect(G_OBJECT(combo), "selection-changed", G_CALLBACK(prpl_changed_cb), dialog); | |
519 | |
520 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Protocol:"))); | |
521 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
522 | |
523 hbox = gnt_hbox_new(TRUE); | |
524 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
525 gnt_box_add_widget(GNT_BOX(window), hbox); | |
526 | |
527 dialog->screenname = entry = gnt_entry_new(NULL); | |
528 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Screen name:"))); | |
529 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
530 | |
531 /* User splits */ | |
532 update_user_splits(dialog); | |
533 gnt_box_add_widget(GNT_BOX(window), dialog->splits); | |
534 | |
535 hbox = gnt_hbox_new(TRUE); | |
536 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
537 gnt_box_add_widget(GNT_BOX(window), hbox); | |
538 | |
539 dialog->password = entry = gnt_entry_new(NULL); | |
540 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); | |
541 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Password:"))); | |
542 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
543 if (account) | |
15822 | 544 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_password(account)); |
15817 | 545 |
546 hbox = gnt_hbox_new(TRUE); | |
547 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
548 gnt_box_add_widget(GNT_BOX(window), hbox); | |
549 | |
550 dialog->alias = entry = gnt_entry_new(NULL); | |
551 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Alias:"))); | |
552 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
553 if (account) | |
15822 | 554 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_alias(account)); |
15817 | 555 |
556 /* User options */ | |
557 update_user_options(dialog); | |
558 gnt_box_add_widget(GNT_BOX(window), dialog->remember); | |
559 gnt_box_add_widget(GNT_BOX(window), dialog->newmail); | |
560 | |
561 gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE)); | |
562 | |
563 /* The advanced box */ | |
564 add_protocol_options(dialog); | |
565 gnt_box_add_widget(GNT_BOX(window), dialog->prpls); | |
566 | |
567 /* TODO: Add proxy options */ | |
568 | |
569 /* The button box */ | |
570 hbox = gnt_hbox_new(FALSE); | |
571 gnt_box_add_widget(GNT_BOX(window), hbox); | |
572 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
573 | |
574 button = gnt_button_new(_("Cancel")); | |
575 gnt_box_add_widget(GNT_BOX(hbox), button); | |
576 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); | |
577 | |
578 button = gnt_button_new(_("Save")); | |
579 gnt_box_add_widget(GNT_BOX(hbox), button); | |
580 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(save_account_cb), dialog); | |
581 | |
582 g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(edit_dialog_destroy), dialog); | |
583 | |
584 gnt_widget_show(window); | |
585 gnt_box_readjust(GNT_BOX(window)); | |
586 gnt_widget_draw(window); | |
587 } | |
588 | |
589 static void | |
590 add_account_cb(GntWidget *widget, gpointer null) | |
591 { | |
592 edit_account(NULL); | |
593 } | |
594 | |
595 static void | |
596 modify_account_cb(GntWidget *widget, GntTree *tree) | |
597 { | |
15822 | 598 PurpleAccount *account = gnt_tree_get_selection_data(tree); |
15817 | 599 if (!account) |
600 return; | |
601 edit_account(account); | |
602 } | |
603 | |
604 static void | |
15822 | 605 really_delete_account(PurpleAccount *account) |
15817 | 606 { |
607 GList *iter; | |
608 for (iter = accountdialogs; iter; iter = iter->next) | |
609 { | |
610 AccountEditDialog *dlg = iter->data; | |
611 if (dlg->account == account) | |
612 { | |
613 gnt_widget_destroy(dlg->window); | |
614 break; | |
615 } | |
616 } | |
15822 | 617 purple_request_close_with_handle(account); /* Close any other opened delete window */ |
618 purple_accounts_delete(account); | |
15817 | 619 } |
620 | |
621 static void | |
622 delete_account_cb(GntWidget *widget, GntTree *tree) | |
623 { | |
15822 | 624 PurpleAccount *account; |
15817 | 625 char *prompt; |
626 | |
627 account = gnt_tree_get_selection_data(tree); | |
628 if (!account) | |
629 return; | |
630 | |
631 prompt = g_strdup_printf(_("Are you sure you want to delete %s?"), | |
15822 | 632 purple_account_get_username(account)); |
15817 | 633 |
16462
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16439
diff
changeset
|
634 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
|
635 account, NULL, NULL, account, 2, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16439
diff
changeset
|
636 _("Delete"), really_delete_account, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16439
diff
changeset
|
637 _("Cancel"), NULL); |
15817 | 638 g_free(prompt); |
639 } | |
640 | |
641 static void | |
642 account_toggled(GntWidget *widget, void *key, gpointer null) | |
643 { | |
15822 | 644 PurpleAccount *account = key; |
15817 | 645 |
15822 | 646 purple_account_set_enabled(account, FINCH_UI, gnt_tree_get_choice(GNT_TREE(widget), key)); |
15817 | 647 } |
648 | |
649 static void | |
650 reset_accounts_win(GntWidget *widget, gpointer null) | |
651 { | |
652 accounts.window = NULL; | |
653 accounts.tree = NULL; | |
654 } | |
655 | |
656 void finch_accounts_show_all() | |
657 { | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
658 GList *iter; |
15817 | 659 GntWidget *box, *button; |
660 | |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
661 if (accounts.window) { |
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
662 gnt_window_present(accounts.window); |
15817 | 663 return; |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
664 } |
15817 | 665 |
666 accounts.window = gnt_vbox_new(FALSE); | |
667 gnt_box_set_toplevel(GNT_BOX(accounts.window), TRUE); | |
668 gnt_box_set_title(GNT_BOX(accounts.window), _("Accounts")); | |
669 gnt_box_set_pad(GNT_BOX(accounts.window), 0); | |
670 gnt_box_set_alignment(GNT_BOX(accounts.window), GNT_ALIGN_MID); | |
671 gnt_widget_set_name(accounts.window, "accounts"); | |
672 | |
673 gnt_box_add_widget(GNT_BOX(accounts.window), | |
674 gnt_label_new(_("You can enable/disable accounts from the following list."))); | |
675 | |
676 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); | |
677 | |
678 accounts.tree = gnt_tree_new_with_columns(2); | |
679 GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER); | |
680 | |
15822 | 681 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15817 | 682 { |
15822 | 683 PurpleAccount *account = iter->data; |
15817 | 684 account_add(account); |
685 } | |
686 | |
687 g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL); | |
688 | |
689 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 0, 40); | |
690 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 1, 10); | |
691 gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree); | |
692 | |
693 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); | |
694 | |
695 box = gnt_hbox_new(FALSE); | |
696 | |
697 button = gnt_button_new(_("Add")); | |
698 gnt_box_add_widget(GNT_BOX(box), button); | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18432
diff
changeset
|
699 gnt_util_set_trigger_widget(GNT_WIDGET(accounts.tree), GNT_KEY_INS, button); |
15817 | 700 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(add_account_cb), NULL); |
701 | |
702 button = gnt_button_new(_("Modify")); | |
703 gnt_box_add_widget(GNT_BOX(box), button); | |
704 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(modify_account_cb), accounts.tree); | |
705 | |
706 button = gnt_button_new(_("Delete")); | |
707 gnt_box_add_widget(GNT_BOX(box), button); | |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18432
diff
changeset
|
708 gnt_util_set_trigger_widget(GNT_WIDGET(accounts.tree), GNT_KEY_DEL, button); |
15817 | 709 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(delete_account_cb), accounts.tree); |
710 | |
711 gnt_box_add_widget(GNT_BOX(accounts.window), box); | |
712 | |
713 g_signal_connect(G_OBJECT(accounts.window), "destroy", G_CALLBACK(reset_accounts_win), NULL); | |
714 | |
715 gnt_widget_show(accounts.window); | |
716 } | |
717 | |
19768
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19762
diff
changeset
|
718 void finch_account_dialog_show(PurpleAccount *account) |
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19762
diff
changeset
|
719 { |
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19762
diff
changeset
|
720 edit_account(account); |
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19762
diff
changeset
|
721 } |
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19762
diff
changeset
|
722 |
15817 | 723 static gpointer |
724 finch_accounts_get_handle() | |
725 { | |
726 static int handle; | |
727 | |
728 return &handle; | |
729 } | |
730 | |
731 static void | |
15822 | 732 account_added_callback(PurpleAccount *account) |
15817 | 733 { |
734 if (accounts.window == NULL) | |
735 return; | |
736 account_add(account); | |
737 gnt_widget_draw(accounts.tree); | |
738 } | |
739 | |
740 static void | |
15822 | 741 account_removed_callback(PurpleAccount *account) |
15817 | 742 { |
743 if (accounts.window == NULL) | |
744 return; | |
745 | |
746 gnt_tree_remove(GNT_TREE(accounts.tree), account); | |
747 } | |
748 | |
17346
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
749 static void |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
750 account_abled_cb(PurpleAccount *account, gpointer user_data) |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
751 { |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
752 if (accounts.window == NULL) |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
753 return; |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
754 gnt_tree_set_choice(GNT_TREE(accounts.tree), account, |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
755 GPOINTER_TO_INT(user_data)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
756 } |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
757 |
15817 | 758 void finch_accounts_init() |
759 { | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
760 GList *iter; |
15817 | 761 |
15822 | 762 purple_signal_connect(purple_accounts_get_handle(), "account-added", |
763 finch_accounts_get_handle(), PURPLE_CALLBACK(account_added_callback), | |
15817 | 764 NULL); |
15822 | 765 purple_signal_connect(purple_accounts_get_handle(), "account-removed", |
766 finch_accounts_get_handle(), PURPLE_CALLBACK(account_removed_callback), | |
15817 | 767 NULL); |
17346
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
768 purple_signal_connect(purple_accounts_get_handle(), "account-disabled", |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
769 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
770 PURPLE_CALLBACK(account_abled_cb), GINT_TO_POINTER(FALSE)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
771 purple_signal_connect(purple_accounts_get_handle(), "account-enabled", |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
772 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
773 PURPLE_CALLBACK(account_abled_cb), GINT_TO_POINTER(TRUE)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
774 |
17816
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
775 iter = purple_accounts_get_all(); |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
776 if (iter) { |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
777 for (; iter; iter = iter->next) { |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
778 if (purple_account_get_enabled(iter->data, FINCH_UI)) |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
779 break; |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
780 } |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
781 if (!iter) |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
782 finch_accounts_show_all(); |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
783 } else { |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
784 edit_account(NULL); |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17807
diff
changeset
|
785 finch_accounts_show_all(); |
15817 | 786 } |
787 } | |
788 | |
789 void finch_accounts_uninit() | |
790 { | |
791 if (accounts.window) | |
792 gnt_widget_destroy(accounts.window); | |
793 } | |
794 | |
795 /* The following uiops stuff are copied from gtkaccount.c */ | |
796 typedef struct | |
797 { | |
15822 | 798 PurpleAccount *account; |
15817 | 799 char *username; |
800 char *alias; | |
801 } AddUserData; | |
802 | |
803 static char * | |
15822 | 804 make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user, |
15817 | 805 const char *id, const char *alias, const char *msg) |
806 { | |
807 if (msg != NULL && *msg == '\0') | |
808 msg = NULL; | |
809 | |
810 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"), | |
811 remote_user, | |
812 (alias != NULL ? " (" : ""), | |
813 (alias != NULL ? alias : ""), | |
814 (alias != NULL ? ")" : ""), | |
815 (id != NULL | |
816 ? id | |
15822 | 817 : (purple_connection_get_display_name(gc) != NULL |
818 ? purple_connection_get_display_name(gc) | |
819 : purple_account_get_username(account))), | |
15817 | 820 (msg != NULL ? ": " : "."), |
821 (msg != NULL ? msg : "")); | |
822 } | |
823 | |
824 static void | |
15822 | 825 notify_added(PurpleAccount *account, const char *remote_user, |
15817 | 826 const char *id, const char *alias, |
827 const char *msg) | |
828 { | |
829 char *buffer; | |
15822 | 830 PurpleConnection *gc; |
15817 | 831 |
15822 | 832 gc = purple_account_get_connection(account); |
15817 | 833 |
834 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
835 | |
15822 | 836 purple_notify_info(NULL, NULL, buffer, NULL); |
15817 | 837 |
838 g_free(buffer); | |
839 } | |
840 | |
841 static void | |
842 free_add_user_data(AddUserData *data) | |
843 { | |
844 g_free(data->username); | |
845 | |
846 if (data->alias != NULL) | |
847 g_free(data->alias); | |
848 | |
849 g_free(data); | |
850 } | |
851 | |
852 static void | |
853 add_user_cb(AddUserData *data) | |
854 { | |
15822 | 855 PurpleConnection *gc = purple_account_get_connection(data->account); |
15817 | 856 |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
857 if (g_list_find(purple_connections_get_all(), gc)) |
15817 | 858 { |
15822 | 859 purple_blist_request_add_buddy(data->account, data->username, |
15817 | 860 NULL, data->alias); |
861 } | |
862 | |
863 free_add_user_data(data); | |
864 } | |
865 | |
866 static void | |
15822 | 867 request_add(PurpleAccount *account, const char *remote_user, |
15817 | 868 const char *id, const char *alias, |
869 const char *msg) | |
870 { | |
871 char *buffer; | |
15822 | 872 PurpleConnection *gc; |
15817 | 873 AddUserData *data; |
874 | |
15822 | 875 gc = purple_account_get_connection(account); |
15817 | 876 |
877 data = g_new0(AddUserData, 1); | |
878 data->account = account; | |
879 data->username = g_strdup(remote_user); | |
880 data->alias = (alias != NULL ? g_strdup(alias) : NULL); | |
881 | |
882 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
15822 | 883 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
|
884 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
|
885 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
|
886 data, 2, |
15817 | 887 _("Add"), G_CALLBACK(add_user_cb), |
888 _("Cancel"), G_CALLBACK(free_add_user_data)); | |
889 g_free(buffer); | |
890 } | |
891 | |
892 /* Copied from gtkaccount.c */ | |
893 typedef struct { | |
15822 | 894 PurpleAccountRequestAuthorizationCb auth_cb; |
895 PurpleAccountRequestAuthorizationCb deny_cb; | |
15817 | 896 void *data; |
897 char *username; | |
898 char *alias; | |
15822 | 899 PurpleAccount *account; |
15817 | 900 } auth_and_add; |
901 | |
902 static void | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
903 free_auth_and_add(auth_and_add *aa) |
15817 | 904 { |
905 g_free(aa->username); | |
906 g_free(aa->alias); | |
907 g_free(aa); | |
908 } | |
909 | |
910 static void | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
911 authorize_and_add_cb(auth_and_add *aa) |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
912 { |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
913 aa->auth_cb(aa->data); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
914 purple_blist_request_add_buddy(aa->account, aa->username, |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
915 NULL, aa->alias); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
916 } |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
917 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
918 static void |
15817 | 919 deny_no_add_cb(auth_and_add *aa) |
920 { | |
921 aa->deny_cb(aa->data); | |
922 } | |
923 | |
924 static void * | |
18829
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
925 finch_request_authorize(PurpleAccount *account, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
926 const char *remote_user, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
927 const char *id, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
928 const char *alias, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
929 const char *message, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
930 gboolean on_list, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
931 PurpleAccountRequestAuthorizationCb auth_cb, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
932 PurpleAccountRequestAuthorizationCb deny_cb, |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
933 void *user_data) |
15817 | 934 { |
935 char *buffer; | |
15822 | 936 PurpleConnection *gc; |
15817 | 937 void *uihandle; |
938 | |
15822 | 939 gc = purple_account_get_connection(account); |
15817 | 940 if (message != NULL && *message == '\0') |
941 message = NULL; | |
942 | |
18516
15f0c935e699
I changed a string during a string freeze\! Sorry\!
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
943 buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"), |
15817 | 944 remote_user, |
945 (alias != NULL ? " (" : ""), | |
946 (alias != NULL ? alias : ""), | |
947 (alias != NULL ? ")" : ""), | |
948 (id != NULL | |
949 ? id | |
15822 | 950 : (purple_connection_get_display_name(gc) != NULL |
951 ? purple_connection_get_display_name(gc) | |
952 : purple_account_get_username(account))), | |
18516
15f0c935e699
I changed a string during a string freeze\! Sorry\!
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
953 (message != NULL ? ": " : "."), |
15817 | 954 (message != NULL ? message : "")); |
955 if (!on_list) { | |
17805
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
956 GntWidget *widget; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
957 GList *iter; |
15817 | 958 auth_and_add *aa = g_new(auth_and_add, 1); |
17805
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
959 |
18829
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
960 aa->auth_cb = auth_cb; |
7a594763c229
Correct the types of the authorize_cb and deny_cb parameters of
Will Thompson <will.thompson@collabora.co.uk>
parents:
18516
diff
changeset
|
961 aa->deny_cb = deny_cb; |
15817 | 962 aa->data = user_data; |
963 aa->username = g_strdup(remote_user); | |
964 aa->alias = g_strdup(alias); | |
965 aa->account = account; | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
966 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
967 uihandle = gnt_vwindow_new(FALSE); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
968 gnt_box_set_title(GNT_BOX(uihandle), _("Authorize buddy?")); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
969 gnt_box_set_pad(GNT_BOX(uihandle), 0); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
970 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
971 widget = 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
|
972 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
|
973 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
|
974 aa, 2, |
15817 | 975 _("Authorize"), authorize_and_add_cb, |
976 _("Deny"), deny_no_add_cb); | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
977 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
978 gnt_box_set_toplevel(GNT_BOX(widget), FALSE); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
979 gnt_box_add_widget(GNT_BOX(uihandle), widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
980 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
981 gnt_box_add_widget(GNT_BOX(uihandle), gnt_hline_new()); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
982 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
983 widget = finch_retrieve_user_info(account->gc, remote_user); |
17805
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
984 for (iter = GNT_BOX(widget)->list; iter; iter = iter->next) { |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
985 if (GNT_IS_BUTTON(iter->data)) { |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
986 gnt_widget_destroy(iter->data); |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
987 gnt_box_remove(GNT_BOX(widget), iter->data); |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
988 break; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
989 } |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
990 } |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
991 gnt_box_set_toplevel(GNT_BOX(widget), FALSE); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
992 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
993 gnt_box_add_widget(GNT_BOX(uihandle), widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
994 gnt_widget_show(uihandle); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
995 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
996 g_signal_connect_swapped(G_OBJECT(uihandle), "destroy", G_CALLBACK(free_auth_and_add), aa); |
15817 | 997 } else { |
15822 | 998 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
|
999 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
|
1000 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
|
1001 user_data, 2, |
15817 | 1002 _("Authorize"), auth_cb, |
1003 _("Deny"), deny_cb); | |
1004 } | |
1005 g_free(buffer); | |
1006 return uihandle; | |
1007 } | |
1008 | |
1009 static void | |
1010 finch_request_close(void *uihandle) | |
1011 { | |
15822 | 1012 purple_request_close(PURPLE_REQUEST_ACTION, uihandle); |
15817 | 1013 } |
1014 | |
15822 | 1015 static PurpleAccountUiOps ui_ops = |
15817 | 1016 { |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1017 notify_added, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1018 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1019 request_add, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1020 finch_request_authorize, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1021 finch_request_close, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1022 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1023 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1024 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1025 NULL |
15817 | 1026 }; |
1027 | |
15822 | 1028 PurpleAccountUiOps *finch_accounts_get_ui_ops() |
15817 | 1029 { |
1030 return &ui_ops; | |
1031 } | |
1032 |