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