Mercurial > pidgin
annotate finch/gntaccount.c @ 19616:f3c83871a442
Do not crash for hidden convs after changing prefs.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 03 Sep 2007 20:31:47 +0000 |
parents | 74f7d5e4a605 |
children | 44b4e8bd759b 315151da0dc6 |
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> | |
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)); | |
15822 | 172 if (value && *value && purple_account_get_remember_password(account)) |
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 | |
718 static gpointer | |
719 finch_accounts_get_handle() | |
720 { | |
721 static int handle; | |
722 | |
723 return &handle; | |
724 } | |
725 | |
726 static void | |
15822 | 727 account_added_callback(PurpleAccount *account) |
15817 | 728 { |
729 if (accounts.window == NULL) | |
730 return; | |
731 account_add(account); | |
732 gnt_widget_draw(accounts.tree); | |
733 } | |
734 | |
735 static void | |
15822 | 736 account_removed_callback(PurpleAccount *account) |
15817 | 737 { |
738 if (accounts.window == NULL) | |
739 return; | |
740 | |
741 gnt_tree_remove(GNT_TREE(accounts.tree), account); | |
742 } | |
743 | |
17346
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
744 static void |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
745 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
|
746 { |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
747 if (accounts.window == NULL) |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
748 return; |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
749 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
|
750 GPOINTER_TO_INT(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 |
15817 | 753 void finch_accounts_init() |
754 { | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
755 GList *iter; |
15817 | 756 |
15822 | 757 purple_signal_connect(purple_accounts_get_handle(), "account-added", |
758 finch_accounts_get_handle(), PURPLE_CALLBACK(account_added_callback), | |
15817 | 759 NULL); |
15822 | 760 purple_signal_connect(purple_accounts_get_handle(), "account-removed", |
761 finch_accounts_get_handle(), PURPLE_CALLBACK(account_removed_callback), | |
15817 | 762 NULL); |
17346
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
763 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
|
764 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
765 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
|
766 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
|
767 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17091
diff
changeset
|
768 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
|
769 |
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
|
770 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
|
771 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
|
772 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
|
773 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
|
774 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
|
775 } |
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 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
|
778 } 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
|
779 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
|
780 finch_accounts_show_all(); |
15817 | 781 } |
782 } | |
783 | |
784 void finch_accounts_uninit() | |
785 { | |
786 if (accounts.window) | |
787 gnt_widget_destroy(accounts.window); | |
788 } | |
789 | |
790 /* The following uiops stuff are copied from gtkaccount.c */ | |
791 typedef struct | |
792 { | |
15822 | 793 PurpleAccount *account; |
15817 | 794 char *username; |
795 char *alias; | |
796 } AddUserData; | |
797 | |
798 static char * | |
15822 | 799 make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user, |
15817 | 800 const char *id, const char *alias, const char *msg) |
801 { | |
802 if (msg != NULL && *msg == '\0') | |
803 msg = NULL; | |
804 | |
805 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"), | |
806 remote_user, | |
807 (alias != NULL ? " (" : ""), | |
808 (alias != NULL ? alias : ""), | |
809 (alias != NULL ? ")" : ""), | |
810 (id != NULL | |
811 ? id | |
15822 | 812 : (purple_connection_get_display_name(gc) != NULL |
813 ? purple_connection_get_display_name(gc) | |
814 : purple_account_get_username(account))), | |
15817 | 815 (msg != NULL ? ": " : "."), |
816 (msg != NULL ? msg : "")); | |
817 } | |
818 | |
819 static void | |
15822 | 820 notify_added(PurpleAccount *account, const char *remote_user, |
15817 | 821 const char *id, const char *alias, |
822 const char *msg) | |
823 { | |
824 char *buffer; | |
15822 | 825 PurpleConnection *gc; |
15817 | 826 |
15822 | 827 gc = purple_account_get_connection(account); |
15817 | 828 |
829 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
830 | |
15822 | 831 purple_notify_info(NULL, NULL, buffer, NULL); |
15817 | 832 |
833 g_free(buffer); | |
834 } | |
835 | |
836 static void | |
837 free_add_user_data(AddUserData *data) | |
838 { | |
839 g_free(data->username); | |
840 | |
841 if (data->alias != NULL) | |
842 g_free(data->alias); | |
843 | |
844 g_free(data); | |
845 } | |
846 | |
847 static void | |
848 add_user_cb(AddUserData *data) | |
849 { | |
15822 | 850 PurpleConnection *gc = purple_account_get_connection(data->account); |
15817 | 851 |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
852 if (g_list_find(purple_connections_get_all(), gc)) |
15817 | 853 { |
15822 | 854 purple_blist_request_add_buddy(data->account, data->username, |
15817 | 855 NULL, data->alias); |
856 } | |
857 | |
858 free_add_user_data(data); | |
859 } | |
860 | |
861 static void | |
15822 | 862 request_add(PurpleAccount *account, const char *remote_user, |
15817 | 863 const char *id, const char *alias, |
864 const char *msg) | |
865 { | |
866 char *buffer; | |
15822 | 867 PurpleConnection *gc; |
15817 | 868 AddUserData *data; |
869 | |
15822 | 870 gc = purple_account_get_connection(account); |
15817 | 871 |
872 data = g_new0(AddUserData, 1); | |
873 data->account = account; | |
874 data->username = g_strdup(remote_user); | |
875 data->alias = (alias != NULL ? g_strdup(alias) : NULL); | |
876 | |
877 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
15822 | 878 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
|
879 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
|
880 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
|
881 data, 2, |
15817 | 882 _("Add"), G_CALLBACK(add_user_cb), |
883 _("Cancel"), G_CALLBACK(free_add_user_data)); | |
884 g_free(buffer); | |
885 } | |
886 | |
887 /* Copied from gtkaccount.c */ | |
888 typedef struct { | |
15822 | 889 PurpleAccountRequestAuthorizationCb auth_cb; |
890 PurpleAccountRequestAuthorizationCb deny_cb; | |
15817 | 891 void *data; |
892 char *username; | |
893 char *alias; | |
15822 | 894 PurpleAccount *account; |
15817 | 895 } auth_and_add; |
896 | |
897 static void | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
898 free_auth_and_add(auth_and_add *aa) |
15817 | 899 { |
900 g_free(aa->username); | |
901 g_free(aa->alias); | |
902 g_free(aa); | |
903 } | |
904 | |
905 static void | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
906 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
|
907 { |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
908 aa->auth_cb(aa->data); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
909 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
|
910 NULL, aa->alias); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
911 } |
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 static void |
15817 | 914 deny_no_add_cb(auth_and_add *aa) |
915 { | |
916 aa->deny_cb(aa->data); | |
917 } | |
918 | |
919 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
|
920 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
|
921 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
|
922 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
|
923 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
|
924 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
|
925 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
|
926 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
|
927 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
|
928 void *user_data) |
15817 | 929 { |
930 char *buffer; | |
15822 | 931 PurpleConnection *gc; |
15817 | 932 void *uihandle; |
933 | |
15822 | 934 gc = purple_account_get_connection(account); |
15817 | 935 if (message != NULL && *message == '\0') |
936 message = NULL; | |
937 | |
18516
15f0c935e699
I changed a string during a string freeze\! Sorry\!
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
938 buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"), |
15817 | 939 remote_user, |
940 (alias != NULL ? " (" : ""), | |
941 (alias != NULL ? alias : ""), | |
942 (alias != NULL ? ")" : ""), | |
943 (id != NULL | |
944 ? id | |
15822 | 945 : (purple_connection_get_display_name(gc) != NULL |
946 ? purple_connection_get_display_name(gc) | |
947 : 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
|
948 (message != NULL ? ": " : "."), |
15817 | 949 (message != NULL ? message : "")); |
950 if (!on_list) { | |
17805
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
951 GntWidget *widget; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
952 GList *iter; |
15817 | 953 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
|
954 |
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
|
955 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
|
956 aa->deny_cb = deny_cb; |
15817 | 957 aa->data = user_data; |
958 aa->username = g_strdup(remote_user); | |
959 aa->alias = g_strdup(alias); | |
960 aa->account = account; | |
17804
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 uihandle = gnt_vwindow_new(FALSE); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
963 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
|
964 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
|
965 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
966 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
|
967 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
|
968 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
|
969 aa, 2, |
15817 | 970 _("Authorize"), authorize_and_add_cb, |
971 _("Deny"), deny_no_add_cb); | |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
972 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
973 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
|
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 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
976 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
|
977 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
978 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
|
979 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
|
980 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
|
981 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
|
982 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
|
983 break; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
984 } |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
985 } |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
986 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
|
987 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
988 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
|
989 gnt_widget_show(uihandle); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
990 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17091
diff
changeset
|
991 g_signal_connect_swapped(G_OBJECT(uihandle), "destroy", G_CALLBACK(free_auth_and_add), aa); |
15817 | 992 } else { |
15822 | 993 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
|
994 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
|
995 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
|
996 user_data, 2, |
15817 | 997 _("Authorize"), auth_cb, |
998 _("Deny"), deny_cb); | |
999 } | |
1000 g_free(buffer); | |
1001 return uihandle; | |
1002 } | |
1003 | |
1004 static void | |
1005 finch_request_close(void *uihandle) | |
1006 { | |
15822 | 1007 purple_request_close(PURPLE_REQUEST_ACTION, uihandle); |
15817 | 1008 } |
1009 | |
15822 | 1010 static PurpleAccountUiOps ui_ops = |
15817 | 1011 { |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1012 notify_added, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1013 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1014 request_add, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1015 finch_request_authorize, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1016 finch_request_close, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1017 NULL, |
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 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16462
diff
changeset
|
1020 NULL |
15817 | 1021 }; |
1022 | |
15822 | 1023 PurpleAccountUiOps *finch_accounts_get_ui_ops() |
15817 | 1024 { |
1025 return &ui_ops; | |
1026 } | |
1027 |