Mercurial > pidgin.yaz
annotate finch/gntaccount.c @ 22898:5d833ca5a265
Make pidgin_blist_toggle_visibility() hide the buddy list when it is
partially obscured but has the focus. This ensures we do something
reasonable if the buddy list is obscured by an "always on top" window.
Fixes #5145.
author | Casey Harkins <charkins@pidgin.im> |
---|---|
date | Fri, 27 Jun 2008 00:01:41 +0000 |
parents | cc8903c59d6b |
children | 02ef6c5c6650 |
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"), |
22770
cc8903c59d6b
Change the string "screen name" to "username" everywhere. I think most
Mark Doliner <mark@kingant.net>
parents:
22257
diff
changeset
|
125 _("Username of an account must be non-empty.")); |
15818 | 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); | |
22770
cc8903c59d6b
Change the string "screen name" to "username" everywhere. I think most
Mark Doliner <mark@kingant.net>
parents:
22257
diff
changeset
|
529 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Username:"))); |
15818 | 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 |
22257
8233bbcf3e86
The Gnome Human Interface Guidelines say, "if pressing this button by
Mark Doliner <mark@kingant.net>
parents:
22213
diff
changeset
|
635 purple_request_action(account, _("Delete Account"), prompt, NULL, |
8233bbcf3e86
The Gnome Human Interface Guidelines say, "if pressing this button by
Mark Doliner <mark@kingant.net>
parents:
22213
diff
changeset
|
636 PURPLE_DEFAULT_ACTION_NONE, |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
637 account, NULL, NULL, account, 2, |
16465
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
diff
changeset
|
638 _("Delete"), really_delete_account, |
4b6d81d26b56
Fix a warning introduced with the request api changes.
Gary Kramlich <grim@reaperworld.com>
parents:
16442
diff
changeset
|
639 _("Cancel"), NULL); |
15818 | 640 g_free(prompt); |
641 } | |
642 | |
643 static void | |
644 account_toggled(GntWidget *widget, void *key, gpointer null) | |
645 { | |
15823 | 646 PurpleAccount *account = key; |
15818 | 647 |
15823 | 648 purple_account_set_enabled(account, FINCH_UI, gnt_tree_get_choice(GNT_TREE(widget), key)); |
15818 | 649 } |
650 | |
651 static void | |
652 reset_accounts_win(GntWidget *widget, gpointer null) | |
653 { | |
654 accounts.window = NULL; | |
655 accounts.tree = NULL; | |
656 } | |
657 | |
658 void finch_accounts_show_all() | |
659 { | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
660 GList *iter; |
15818 | 661 GntWidget *box, *button; |
662 | |
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
|
663 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
|
664 gnt_window_present(accounts.window); |
15818 | 665 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
|
666 } |
15818 | 667 |
668 accounts.window = gnt_vbox_new(FALSE); | |
669 gnt_box_set_toplevel(GNT_BOX(accounts.window), TRUE); | |
670 gnt_box_set_title(GNT_BOX(accounts.window), _("Accounts")); | |
671 gnt_box_set_pad(GNT_BOX(accounts.window), 0); | |
672 gnt_box_set_alignment(GNT_BOX(accounts.window), GNT_ALIGN_MID); | |
673 gnt_widget_set_name(accounts.window, "accounts"); | |
674 | |
675 gnt_box_add_widget(GNT_BOX(accounts.window), | |
676 gnt_label_new(_("You can enable/disable accounts from the following list."))); | |
677 | |
678 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); | |
679 | |
680 accounts.tree = gnt_tree_new_with_columns(2); | |
681 GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER); | |
682 | |
15823 | 683 for (iter = purple_accounts_get_all(); iter; iter = iter->next) |
15818 | 684 { |
15823 | 685 PurpleAccount *account = iter->data; |
15818 | 686 account_add(account); |
687 } | |
688 | |
689 g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL); | |
22213
16ff37f64e29
Update finch to not touch the internals of PurpleAccount. This also includes a change I made to reduce the Cyclomatic Complexity of one of the functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
690 |
15818 | 691 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 0, 40); |
692 gnt_tree_set_col_width(GNT_TREE(accounts.tree), 1, 10); | |
693 gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree); | |
694 | |
695 gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); | |
696 | |
697 box = gnt_hbox_new(FALSE); | |
698 | |
699 button = gnt_button_new(_("Add")); | |
700 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
|
701 gnt_util_set_trigger_widget(GNT_WIDGET(accounts.tree), GNT_KEY_INS, button); |
15818 | 702 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(add_account_cb), NULL); |
703 | |
704 button = gnt_button_new(_("Modify")); | |
705 gnt_box_add_widget(GNT_BOX(box), button); | |
706 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(modify_account_cb), accounts.tree); | |
707 | |
708 button = gnt_button_new(_("Delete")); | |
709 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
|
710 gnt_util_set_trigger_widget(GNT_WIDGET(accounts.tree), GNT_KEY_DEL, button); |
15818 | 711 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(delete_account_cb), accounts.tree); |
22213
16ff37f64e29
Update finch to not touch the internals of PurpleAccount. This also includes a change I made to reduce the Cyclomatic Complexity of one of the functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
712 |
15818 | 713 gnt_box_add_widget(GNT_BOX(accounts.window), box); |
714 | |
715 g_signal_connect(G_OBJECT(accounts.window), "destroy", G_CALLBACK(reset_accounts_win), NULL); | |
22213
16ff37f64e29
Update finch to not touch the internals of PurpleAccount. This also includes a change I made to reduce the Cyclomatic Complexity of one of the functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
716 |
15818 | 717 gnt_widget_show(accounts.window); |
718 } | |
719 | |
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
|
720 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
|
721 { |
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 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
|
723 } |
41cad24fd6df
Instead of just notifying the user about a connection error, give him options
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19938
diff
changeset
|
724 |
15818 | 725 static gpointer |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
21570
diff
changeset
|
726 finch_accounts_get_handle(void) |
15818 | 727 { |
728 static int handle; | |
729 | |
730 return &handle; | |
731 } | |
732 | |
733 static void | |
15823 | 734 account_added_callback(PurpleAccount *account) |
15818 | 735 { |
736 if (accounts.window == NULL) | |
737 return; | |
738 account_add(account); | |
739 gnt_widget_draw(accounts.tree); | |
740 } | |
741 | |
742 static void | |
15823 | 743 account_removed_callback(PurpleAccount *account) |
15818 | 744 { |
745 if (accounts.window == NULL) | |
746 return; | |
747 | |
748 gnt_tree_remove(GNT_TREE(accounts.tree), account); | |
749 } | |
750 | |
17419
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
751 static void |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
752 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
|
753 { |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
754 if (accounts.window == NULL) |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
755 return; |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
756 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
|
757 GPOINTER_TO_INT(user_data)); |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
758 } |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
759 |
15818 | 760 void finch_accounts_init() |
761 { | |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
762 GList *iter; |
15818 | 763 |
15823 | 764 purple_signal_connect(purple_accounts_get_handle(), "account-added", |
765 finch_accounts_get_handle(), PURPLE_CALLBACK(account_added_callback), | |
15818 | 766 NULL); |
15823 | 767 purple_signal_connect(purple_accounts_get_handle(), "account-removed", |
768 finch_accounts_get_handle(), PURPLE_CALLBACK(account_removed_callback), | |
15818 | 769 NULL); |
17419
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
770 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
|
771 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
772 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
|
773 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
|
774 finch_accounts_get_handle(), |
8c3a3407af58
Finch autoreconnecting (largely copy/paste from pidgin)
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
775 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
|
776 |
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
|
777 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
|
778 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
|
779 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
|
780 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
|
781 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
|
782 } |
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 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
|
784 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
|
785 } 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
|
786 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
|
787 finch_accounts_show_all(); |
15818 | 788 } |
789 } | |
790 | |
791 void finch_accounts_uninit() | |
792 { | |
793 if (accounts.window) | |
794 gnt_widget_destroy(accounts.window); | |
795 } | |
796 | |
797 /* The following uiops stuff are copied from gtkaccount.c */ | |
798 typedef struct | |
799 { | |
15823 | 800 PurpleAccount *account; |
15818 | 801 char *username; |
802 char *alias; | |
803 } AddUserData; | |
804 | |
805 static char * | |
15823 | 806 make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user, |
15818 | 807 const char *id, const char *alias, const char *msg) |
808 { | |
809 if (msg != NULL && *msg == '\0') | |
810 msg = NULL; | |
811 | |
812 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"), | |
813 remote_user, | |
814 (alias != NULL ? " (" : ""), | |
815 (alias != NULL ? alias : ""), | |
816 (alias != NULL ? ")" : ""), | |
817 (id != NULL | |
818 ? id | |
15823 | 819 : (purple_connection_get_display_name(gc) != NULL |
820 ? purple_connection_get_display_name(gc) | |
821 : purple_account_get_username(account))), | |
15818 | 822 (msg != NULL ? ": " : "."), |
823 (msg != NULL ? msg : "")); | |
824 } | |
825 | |
826 static void | |
15823 | 827 notify_added(PurpleAccount *account, const char *remote_user, |
15818 | 828 const char *id, const char *alias, |
829 const char *msg) | |
830 { | |
831 char *buffer; | |
15823 | 832 PurpleConnection *gc; |
15818 | 833 |
15823 | 834 gc = purple_account_get_connection(account); |
15818 | 835 |
836 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
837 | |
15823 | 838 purple_notify_info(NULL, NULL, buffer, NULL); |
15818 | 839 |
840 g_free(buffer); | |
841 } | |
842 | |
843 static void | |
844 free_add_user_data(AddUserData *data) | |
845 { | |
846 g_free(data->username); | |
847 | |
848 if (data->alias != NULL) | |
849 g_free(data->alias); | |
850 | |
851 g_free(data); | |
852 } | |
853 | |
854 static void | |
855 add_user_cb(AddUserData *data) | |
856 { | |
15823 | 857 PurpleConnection *gc = purple_account_get_connection(data->account); |
15818 | 858 |
18063
926ccb104da0
disapproval of revision '1411afd7660760db59966c3a9f18e2adab8eb27e'
Richard Laager <rlaager@wiktel.com>
parents:
18058
diff
changeset
|
859 if (g_list_find(purple_connections_get_all(), gc)) |
15818 | 860 { |
15823 | 861 purple_blist_request_add_buddy(data->account, data->username, |
15818 | 862 NULL, data->alias); |
863 } | |
864 | |
865 free_add_user_data(data); | |
866 } | |
867 | |
868 static void | |
15823 | 869 request_add(PurpleAccount *account, const char *remote_user, |
15818 | 870 const char *id, const char *alias, |
871 const char *msg) | |
872 { | |
873 char *buffer; | |
15823 | 874 PurpleConnection *gc; |
15818 | 875 AddUserData *data; |
876 | |
15823 | 877 gc = purple_account_get_connection(account); |
15818 | 878 |
879 data = g_new0(AddUserData, 1); | |
880 data->account = account; | |
881 data->username = g_strdup(remote_user); | |
882 data->alias = (alias != NULL ? g_strdup(alias) : NULL); | |
883 | |
884 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
885 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
|
886 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
|
887 account, remote_user, NULL, |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
888 data, 2, |
15818 | 889 _("Add"), G_CALLBACK(add_user_cb), |
890 _("Cancel"), G_CALLBACK(free_add_user_data)); | |
891 g_free(buffer); | |
892 } | |
893 | |
894 /* Copied from gtkaccount.c */ | |
895 typedef struct { | |
15823 | 896 PurpleAccountRequestAuthorizationCb auth_cb; |
897 PurpleAccountRequestAuthorizationCb deny_cb; | |
15818 | 898 void *data; |
899 char *username; | |
900 char *alias; | |
15823 | 901 PurpleAccount *account; |
15818 | 902 } auth_and_add; |
903 | |
904 static void | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
905 free_auth_and_add(auth_and_add *aa) |
15818 | 906 { |
907 g_free(aa->username); | |
908 g_free(aa->alias); | |
909 g_free(aa); | |
910 } | |
911 | |
912 static void | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
913 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
|
914 { |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
915 aa->auth_cb(aa->data); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
916 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
|
917 NULL, aa->alias); |
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 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
920 static void |
15818 | 921 deny_no_add_cb(auth_and_add *aa) |
922 { | |
923 aa->deny_cb(aa->data); | |
924 } | |
925 | |
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 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
|
935 void *user_data) |
15818 | 936 { |
937 char *buffer; | |
15823 | 938 PurpleConnection *gc; |
15818 | 939 void *uihandle; |
940 | |
15823 | 941 gc = purple_account_get_connection(account); |
15818 | 942 if (message != NULL && *message == '\0') |
943 message = NULL; | |
944 | |
18516
15f0c935e699
I changed a string during a string freeze\! Sorry\!
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
945 buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"), |
15818 | 946 remote_user, |
947 (alias != NULL ? " (" : ""), | |
948 (alias != NULL ? alias : ""), | |
949 (alias != NULL ? ")" : ""), | |
950 (id != NULL | |
951 ? id | |
15823 | 952 : (purple_connection_get_display_name(gc) != NULL |
953 ? purple_connection_get_display_name(gc) | |
954 : 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
|
955 (message != NULL ? ": " : "."), |
15818 | 956 (message != NULL ? message : "")); |
957 if (!on_list) { | |
17521
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
958 GntWidget *widget; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
959 GList *iter; |
15818 | 960 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
|
961 |
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
|
962 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
|
963 aa->deny_cb = deny_cb; |
15818 | 964 aa->data = user_data; |
965 aa->username = g_strdup(remote_user); | |
966 aa->alias = g_strdup(alias); | |
967 aa->account = account; | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
968 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
969 uihandle = gnt_vwindow_new(FALSE); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
970 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
|
971 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
|
972 |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
973 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
|
974 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
|
975 account, remote_user, NULL, |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
976 aa, 2, |
15818 | 977 _("Authorize"), authorize_and_add_cb, |
978 _("Deny"), deny_no_add_cb); | |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
979 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
980 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
|
981 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
|
982 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
983 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
|
984 |
22213
16ff37f64e29
Update finch to not touch the internals of PurpleAccount. This also includes a change I made to reduce the Cyclomatic Complexity of one of the functions.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22007
diff
changeset
|
985 widget = finch_retrieve_user_info(purple_account_get_connection(account), remote_user); |
17521
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
986 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
|
987 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
|
988 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
|
989 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
|
990 break; |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
991 } |
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17520
diff
changeset
|
992 } |
17520
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
993 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
|
994 gnt_screen_release(widget); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
995 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
|
996 gnt_widget_show(uihandle); |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
997 |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17104
diff
changeset
|
998 g_signal_connect_swapped(G_OBJECT(uihandle), "destroy", G_CALLBACK(free_auth_and_add), aa); |
15818 | 999 } else { |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
1000 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
|
1001 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
|
1002 account, remote_user, NULL, |
21570
dccfd999ffe7
merge of '76c07fcb434a2a7aa289734bb221c171a376d73b'
Evan Schoenberg <evan.s@dreskin.net>
parents:
21244
diff
changeset
|
1003 user_data, 2, |
15818 | 1004 _("Authorize"), auth_cb, |
1005 _("Deny"), deny_cb); | |
1006 } | |
1007 g_free(buffer); | |
1008 return uihandle; | |
1009 } | |
1010 | |
1011 static void | |
1012 finch_request_close(void *uihandle) | |
1013 { | |
15823 | 1014 purple_request_close(PURPLE_REQUEST_ACTION, uihandle); |
15818 | 1015 } |
1016 | |
15823 | 1017 static PurpleAccountUiOps ui_ops = |
15818 | 1018 { |
17104
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1019 notify_added, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1020 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1021 request_add, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1022 finch_request_authorize, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1023 finch_request_close, |
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, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16465
diff
changeset
|
1027 NULL |
15818 | 1028 }; |
1029 | |
15823 | 1030 PurpleAccountUiOps *finch_accounts_get_ui_ops() |
15818 | 1031 { |
1032 return &ui_ops; | |
1033 } | |
1034 |