Mercurial > pidgin.yaz
annotate finch/gntaccount.c @ 20914:74ec24deb267
Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sat, 13 Oct 2007 16:36:06 +0000 |
parents | 6bf32c9e15a7 |
children | 591267f6f1d5 |
rev | line source |
---|---|
15818 | 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:
15871
diff
changeset
|
3 * @ingroup finch |
20074
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19944
diff
changeset
|
4 */ |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19944
diff
changeset
|
5 |
6bf32c9e15a7
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents:
19944
diff
changeset
|
6 /* finch |
15818 | 7 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
8 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 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 | |
19680
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 |
15818 | 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> |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
36 #include <gntwindow.h> |
15818 | 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 |
15818 | 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" | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
48 #include "gntblist.h" |
15818 | 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 { | |
15823 | 62 PurpleAccount *account; /* NULL for a new account */ |
15818 | 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 | |
15823 | 85 account_add(PurpleAccount *account) |
15818 | 86 { |
87 gnt_tree_add_choice(GNT_TREE(accounts.tree), account, | |
88 gnt_tree_create_row(GNT_TREE(accounts.tree), | |
15823 | 89 purple_account_get_username(account), |
90 purple_account_get_protocol_name(account)), | |
15818 | 91 NULL, NULL); |
92 gnt_tree_set_choice(GNT_TREE(accounts.tree), account, | |
15823 | 93 purple_account_get_enabled(account, FINCH_UI)); |
15818 | 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 { | |
15823 | 108 PurpleAccount *account; |
109 PurplePlugin *plugin; | |
110 PurplePluginProtocolInfo *prplinfo; | |
15818 | 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)); | |
15823 | 117 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 118 |
119 /* Screenname && user-splits */ | |
120 value = gnt_entry_get_text(GNT_ENTRY(dialog->screenname)); | |
121 | |
122 if (value == NULL || *value == '\0') | |
123 { | |
15823 | 124 purple_notify_error(NULL, _("Error"), _("Account was not added"), |
15818 | 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 { | |
15823 | 137 PurpleAccountUserSplit *split = iter->data; |
15818 | 138 GntWidget *entry = entries->data; |
139 | |
140 value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
141 if (value == NULL || *value == '\0') | |
15823 | 142 value = purple_account_user_split_get_default_value(split); |
15818 | 143 g_string_append_printf(username, "%c%s", |
15823 | 144 purple_account_user_split_get_separator(split), |
15818 | 145 value); |
146 } | |
147 } | |
148 | |
149 if (dialog->account == NULL) | |
150 { | |
15823 | 151 account = purple_account_new(username->str, purple_plugin_get_id(plugin)); |
152 purple_accounts_add(account); | |
15818 | 153 } |
154 else | |
155 { | |
156 account = dialog->account; | |
157 | |
158 /* Protocol */ | |
15823 | 159 purple_account_set_protocol_id(account, purple_plugin_get_id(plugin)); |
160 purple_account_set_username(account, username->str); | |
15818 | 161 } |
162 g_string_free(username, TRUE); | |
163 | |
164 /* Alias */ | |
165 value = gnt_entry_get_text(GNT_ENTRY(dialog->alias)); | |
166 if (value && *value) | |
15823 | 167 purple_account_set_alias(account, value); |
15818 | 168 |
169 /* Remember password and password */ | |
15823 | 170 purple_account_set_remember_password(account, |
15818 | 171 gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->remember))); |
172 value = gnt_entry_get_text(GNT_ENTRY(dialog->password)); | |
19938
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:
19680
diff
changeset
|
173 if (value && *value) |
15823 | 174 purple_account_set_password(account, value); |
15818 | 175 else |
15823 | 176 purple_account_set_password(account, NULL); |
15818 | 177 |
178 /* Mail notification */ | |
15823 | 179 purple_account_set_check_mail(account, |
15818 | 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 { | |
15823 | 190 PurpleAccountOption *option = iter->data; |
15818 | 191 GntWidget *entry = entries->data; |
15823 | 192 PurplePrefType type = purple_account_option_get_type(option); |
193 const char *setting = purple_account_option_get_setting(option); | |
15818 | 194 |
15823 | 195 if (type == PURPLE_PREF_STRING) |
15818 | 196 { |
197 const char *value = gnt_entry_get_text(GNT_ENTRY(entry)); | |
15823 | 198 purple_account_set_string(account, setting, value); |
15818 | 199 } |
15823 | 200 else if (type == PURPLE_PREF_INT) |
15818 | 201 { |
202 const char *str = gnt_entry_get_text(GNT_ENTRY(entry)); | |
203 int value = 0; | |
204 if (str) | |
205 value = atoi(str); | |
15823 | 206 purple_account_set_int(account, setting, value); |
15818 | 207 } |
15823 | 208 else if (type == PURPLE_PREF_BOOLEAN) |
15818 | 209 { |
210 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(entry)); | |
15823 | 211 purple_account_set_bool(account, setting, value); |
15818 | 212 } |
15823 | 213 else if (type == PURPLE_PREF_STRING_LIST) |
15818 | 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 |
15818 | 231 gnt_widget_destroy(dialog->window); |
232 } | |
233 | |
234 static void | |
235 update_user_splits(AccountEditDialog *dialog) | |
236 { | |
237 GntWidget *hbox; | |
15823 | 238 PurplePlugin *plugin; |
239 PurplePluginProtocolInfo *prplinfo; | |
15818 | 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; | |
15823 | 260 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 261 |
15823 | 262 username = dialog->account ? g_strdup(purple_account_get_username(dialog->account)) : NULL; |
15818 | 263 |
264 for (iter = prplinfo->user_splits; iter; iter = iter->next) | |
265 { | |
15823 | 266 PurpleAccountUserSplit *split = iter->data; |
15818 | 267 GntWidget *entry; |
268 char *buf; | |
269 | |
270 hbox = gnt_hbox_new(TRUE); | |
271 gnt_box_add_widget(GNT_BOX(dialog->splits), hbox); | |
272 | |
15823 | 273 buf = g_strdup_printf("%s:", purple_account_user_split_get_text(split)); |
15818 | 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; | |
15823 | 287 PurpleAccountUserSplit *split = iter->data; |
15818 | 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:
17419
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:
17419
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:
17419
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:
17419
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:
17419
diff
changeset
|
297 |
15818 | 298 if (s != NULL) |
299 { | |
300 *s = '\0'; | |
301 s++; | |
302 value = s; | |
303 } | |
304 } | |
305 if (value == NULL) | |
15823 | 306 value = purple_account_user_split_get_default_value(split); |
15818 | 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 { | |
15823 | 321 PurplePlugin *plugin; |
322 PurplePluginProtocolInfo *prplinfo; | |
15818 | 323 GList *iter; |
324 GntWidget *vbox, *box; | |
15823 | 325 PurpleAccount *account; |
15818 | 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 | |
15823 | 349 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 350 |
351 account = dialog->account; | |
352 | |
353 for (iter = prplinfo->protocol_options; iter; iter = iter->next) | |
354 { | |
15823 | 355 PurpleAccountOption *option = iter->data; |
356 PurplePrefType type = purple_account_option_get_type(option); | |
15818 | 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 | |
15823 | 362 if (type == PURPLE_PREF_BOOLEAN) |
15818 | 363 { |
15823 | 364 GntWidget *widget = gnt_check_box_new(purple_account_option_get_text(option)); |
15818 | 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), | |
15823 | 370 purple_account_get_bool(account, |
371 purple_account_option_get_setting(option), | |
372 purple_account_option_get_default_bool(option))); | |
15818 | 373 else |
374 gnt_check_box_set_checked(GNT_CHECK_BOX(widget), | |
15823 | 375 purple_account_option_get_default_bool(option)); |
15818 | 376 } |
377 else | |
378 { | |
379 gnt_box_add_widget(GNT_BOX(box), | |
15823 | 380 gnt_label_new(purple_account_option_get_text(option))); |
15818 | 381 |
15823 | 382 if (type == PURPLE_PREF_STRING_LIST) |
15818 | 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 | |
15823 | 393 if (type == PURPLE_PREF_STRING) |
15818 | 394 { |
15823 | 395 const char *dv = purple_account_option_get_default_string(option); |
15818 | 396 |
397 if (account) | |
398 gnt_entry_set_text(GNT_ENTRY(entry), | |
15823 | 399 purple_account_get_string(account, |
400 purple_account_option_get_setting(option), dv)); | |
15818 | 401 else |
402 gnt_entry_set_text(GNT_ENTRY(entry), dv); | |
403 } | |
15823 | 404 else if (type == PURPLE_PREF_INT) |
15818 | 405 { |
406 char str[32]; | |
15823 | 407 int value = purple_account_option_get_default_int(option); |
15818 | 408 if (account) |
15823 | 409 value = purple_account_get_int(account, |
410 purple_account_option_get_setting(option), value); | |
15818 | 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 { | |
15823 | 427 PurplePlugin *plugin; |
428 PurplePluginProtocolInfo *prplinfo; | |
15818 | 429 |
430 plugin = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->protocol)); | |
431 if (!plugin) | |
432 return; | |
433 | |
15823 | 434 prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
15818 | 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), | |
15823 | 440 purple_account_get_check_mail(dialog->account)); |
15818 | 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), | |
15823 | 450 purple_account_get_remember_password(dialog->account)); |
15818 | 451 } |
452 | |
453 static void | |
15823 | 454 prpl_changed_cb(GntWidget *combo, PurplePlugin *old, PurplePlugin *new, AccountEditDialog *dialog) |
15818 | 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 | |
15823 | 464 edit_account(PurpleAccount *account) |
15818 | 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 |
15818 | 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, | |
15823 | 510 ((PurplePlugin*)iter->data)->info->name); |
15818 | 511 } |
512 | |
513 if (account) | |
514 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
15823 | 515 purple_plugins_find_with_id(purple_account_get_protocol_id(account))); |
15818 | 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) | |
15823 | 545 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_password(account)); |
15818 | 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) | |
15823 | 555 gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_alias(account)); |
15818 | 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 { | |
15823 | 599 PurpleAccount *account = gnt_tree_get_selection_data(tree); |
15818 | 600 if (!account) |
601 return; | |
602 edit_account(account); | |
603 } | |
604 | |
605 static void | |
15823 | 606 really_delete_account(PurpleAccount *account) |
15818 | 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 } | |
15823 | 618 purple_request_close_with_handle(account); /* Close any other opened delete window */ |
619 purple_accounts_delete(account); | |
15818 | 620 } |
621 | |
622 static void | |
623 delete_account_cb(GntWidget *widget, GntTree *tree) | |
624 { | |
15823 | 625 PurpleAccount *account; |
15818 | 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?"), | |
15823 | 633 purple_account_get_username(account)); |
15818 | 634 |
16465
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
diff
changeset
|
635 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:
16442
diff
changeset
|
636 account, NULL, NULL, account, 2, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
diff
changeset
|
637 _("Delete"), really_delete_account, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
diff
changeset
|
638 _("Cancel"), NULL); |
15818 | 639 g_free(prompt); |
640 } | |
641 | |
642 static void | |
643 account_toggled(GntWidget *widget, void *key, gpointer null) | |
644 { | |
15823 | 645 PurpleAccount *account = key; |
15818 | 646 |
15823 | 647 purple_account_set_enabled(account, FINCH_UI, gnt_tree_get_choice(GNT_TREE(widget), key)); |
15818 | 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; |
15818 | 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); |
15818 | 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 } |
15818 | 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 | |
15823 | 682 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15818 | 683 { |
15823 | 684 PurpleAccount *account = iter->data; |
15818 | 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); |
15818 | 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); |
15818 | 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 | |
19944
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19938
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:
19938
diff
changeset
|
720 { |
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19938
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:
19938
diff
changeset
|
722 } |
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19938
diff
changeset
|
723 |
15818 | 724 static gpointer |
725 finch_accounts_get_handle() | |
726 { | |
727 static int handle; | |
728 | |
729 return &handle; | |
730 } | |
731 | |
732 static void | |
15823 | 733 account_added_callback(PurpleAccount *account) |
15818 | 734 { |
735 if (accounts.window == NULL) | |
736 return; | |
737 account_add(account); | |
738 gnt_widget_draw(accounts.tree); | |
739 } | |
740 | |
741 static void | |
15823 | 742 account_removed_callback(PurpleAccount *account) |
15818 | 743 { |
744 if (accounts.window == NULL) | |
745 return; | |
746 | |
747 gnt_tree_remove(GNT_TREE(accounts.tree), account); | |
748 } | |
749 | |
17419
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
750 static void |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
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:
17104
diff
changeset
|
752 { |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
753 if (accounts.window == NULL) |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
754 return; |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
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:
17104
diff
changeset
|
756 GPOINTER_TO_INT(user_data)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
757 } |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
758 |
15818 | 759 void finch_accounts_init() |
760 { | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
761 GList *iter; |
15818 | 762 |
15823 | 763 purple_signal_connect(purple_accounts_get_handle(), "account-added", |
764 finch_accounts_get_handle(), PURPLE_CALLBACK(account_added_callback), | |
15818 | 765 NULL); |
15823 | 766 purple_signal_connect(purple_accounts_get_handle(), "account-removed", |
767 finch_accounts_get_handle(), PURPLE_CALLBACK(account_removed_callback), | |
15818 | 768 NULL); |
17419
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
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:
17104
diff
changeset
|
770 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
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:
17104
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:
17104
diff
changeset
|
773 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
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:
17104
diff
changeset
|
775 |
17532
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17523
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:
17523
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:
17523
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:
17523
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:
17523
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:
17523
diff
changeset
|
781 } |
e2e709e5446b
If there's no account at startup, sohw the 'New Account' dialog too.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17523
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:
17523
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:
17523
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:
17523
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:
17523
diff
changeset
|
786 finch_accounts_show_all(); |
15818 | 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 { | |
15823 | 799 PurpleAccount *account; |
15818 | 800 char *username; |
801 char *alias; | |
802 } AddUserData; | |
803 | |
804 static char * | |
15823 | 805 make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user, |
15818 | 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 | |
15823 | 818 : (purple_connection_get_display_name(gc) != NULL |
819 ? purple_connection_get_display_name(gc) | |
820 : purple_account_get_username(account))), | |
15818 | 821 (msg != NULL ? ": " : "."), |
822 (msg != NULL ? msg : "")); | |
823 } | |
824 | |
825 static void | |
15823 | 826 notify_added(PurpleAccount *account, const char *remote_user, |
15818 | 827 const char *id, const char *alias, |
828 const char *msg) | |
829 { | |
830 char *buffer; | |
15823 | 831 PurpleConnection *gc; |
15818 | 832 |
15823 | 833 gc = purple_account_get_connection(account); |
15818 | 834 |
835 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
836 | |
15823 | 837 purple_notify_info(NULL, NULL, buffer, NULL); |
15818 | 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 { | |
15823 | 856 PurpleConnection *gc = purple_account_get_connection(data->account); |
15818 | 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)) |
15818 | 859 { |
15823 | 860 purple_blist_request_add_buddy(data->account, data->username, |
15818 | 861 NULL, data->alias); |
862 } | |
863 | |
864 free_add_user_data(data); | |
865 } | |
866 | |
867 static void | |
15823 | 868 request_add(PurpleAccount *account, const char *remote_user, |
15818 | 869 const char *id, const char *alias, |
870 const char *msg) | |
871 { | |
872 char *buffer; | |
15823 | 873 PurpleConnection *gc; |
15818 | 874 AddUserData *data; |
875 | |
15823 | 876 gc = purple_account_get_connection(account); |
15818 | 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); | |
15823 | 884 purple_request_action(NULL, NULL, _("Add buddy to your list?"), |
16442
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, |
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
|
887 data, 2, |
15818 | 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 { | |
15823 | 895 PurpleAccountRequestAuthorizationCb auth_cb; |
896 PurpleAccountRequestAuthorizationCb deny_cb; | |
15818 | 897 void *data; |
898 char *username; | |
899 char *alias; | |
15823 | 900 PurpleAccount *account; |
15818 | 901 } auth_and_add; |
902 | |
903 static void | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
904 free_auth_and_add(auth_and_add *aa) |
15818 | 905 { |
906 g_free(aa->username); | |
907 g_free(aa->alias); | |
908 g_free(aa); | |
909 } | |
910 | |
911 static void | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
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:
17104
diff
changeset
|
913 { |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
914 aa->auth_cb(aa->data); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
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:
17104
diff
changeset
|
916 NULL, aa->alias); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
917 } |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
918 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
919 static void |
15818 | 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) |
15818 | 935 { |
936 char *buffer; | |
15823 | 937 PurpleConnection *gc; |
15818 | 938 void *uihandle; |
939 | |
15823 | 940 gc = purple_account_get_connection(account); |
15818 | 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"), |
15818 | 945 remote_user, |
946 (alias != NULL ? " (" : ""), | |
947 (alias != NULL ? alias : ""), | |
948 (alias != NULL ? ")" : ""), | |
949 (id != NULL | |
950 ? id | |
15823 | 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 ? ": " : "."), |
15818 | 955 (message != NULL ? message : "")); |
956 if (!on_list) { | |
17521
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
957 GntWidget *widget; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
958 GList *iter; |
15818 | 959 auth_and_add *aa = g_new(auth_and_add, 1); |
17521
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
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; |
15818 | 963 aa->data = user_data; |
964 aa->username = g_strdup(remote_user); | |
965 aa->alias = g_strdup(alias); | |
966 aa->account = account; | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
967 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
968 uihandle = gnt_vwindow_new(FALSE); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
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:
17104
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:
17104
diff
changeset
|
971 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
972 widget = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL, |
16442
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, |
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
|
975 aa, 2, |
15818 | 976 _("Authorize"), authorize_and_add_cb, |
977 _("Deny"), deny_no_add_cb); | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
978 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
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:
17104
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:
17104
diff
changeset
|
981 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
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:
17104
diff
changeset
|
983 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
984 widget = finch_retrieve_user_info(account->gc, remote_user); |
17521
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
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:
17520
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:
17520
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:
17520
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:
17520
diff
changeset
|
989 break; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
990 } |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
991 } |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
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:
17104
diff
changeset
|
993 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
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:
17104
diff
changeset
|
995 gnt_widget_show(uihandle); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
996 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
997 g_signal_connect_swapped(G_OBJECT(uihandle), "destroy", G_CALLBACK(free_auth_and_add), aa); |
15818 | 998 } else { |
15823 | 999 uihandle = purple_request_action(NULL, _("Authorize buddy?"), buffer, NULL, |
16442
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, |
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
|
1002 user_data, 2, |
15818 | 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 { | |
15823 | 1013 purple_request_close(PURPLE_REQUEST_ACTION, uihandle); |
15818 | 1014 } |
1015 | |
15823 | 1016 static PurpleAccountUiOps ui_ops = |
15818 | 1017 { |
17104
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1018 notify_added, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1019 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1020 request_add, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1021 finch_request_authorize, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1022 finch_request_close, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1023 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1024 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1025 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1026 NULL |
15818 | 1027 }; |
1028 | |
15823 | 1029 PurpleAccountUiOps *finch_accounts_get_ui_ops() |
15818 | 1030 { |
1031 return &ui_ops; | |
1032 } | |
1033 |