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