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