3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #include "accountopt.h"
34 #include "savedstatuses.h"
38 #include "gtkaccount.h"
40 #include "gtkdialogs.h"
42 #include "gtkstatusbox.h"
43 #include "pidginstock.h"
44 #include "minidialog.h"
46 #include "gtk3compat.h"
61 PurpleAccount
*account
;
65 } PidginAccountAddUserData
;
72 GtkWidget
*modify_button
;
73 GtkWidget
*delete_button
;
77 GtkTreeIter drag_iter
;
79 GtkTreeViewColumn
*username_col
;
92 PidginAccountDialogType type
;
94 PurpleAccount
*account
;
96 PurpleProtocol
*protocol
;
98 PurpleProxyType new_proxy_type
;
100 GList
*user_split_entries
;
101 GList
*protocol_opt_entries
;
108 GtkWidget
*ok_button
;
109 GtkWidget
*register_button
;
112 GtkWidget
*login_frame
;
113 GtkWidget
*protocol_menu
;
114 GtkWidget
*password_box
;
116 GtkWidget
*username_entry
;
117 GdkRGBA username_entry_hint_color
;
118 GtkWidget
*password_entry
;
119 GtkWidget
*alias_entry
;
120 GtkWidget
*remember_pass_check
;
123 GtkWidget
*user_frame
;
124 GtkWidget
*new_mail_check
;
125 GtkWidget
*icon_hbox
;
126 GtkWidget
*icon_check
;
127 GtkWidget
*icon_entry
;
128 GtkWidget
*icon_filesel
;
129 GtkWidget
*icon_preview
;
130 GtkWidget
*icon_text
;
131 PurpleImage
*icon_img
;
133 /* Protocol Options */
134 GtkWidget
*protocol_frame
;
137 GtkWidget
*proxy_frame
;
138 GtkWidget
*proxy_vbox
;
139 GtkWidget
*proxy_dropdown
;
140 GtkWidget
*proxy_host_entry
;
141 GtkWidget
*proxy_port_entry
;
142 GtkWidget
*proxy_user_entry
;
143 GtkWidget
*proxy_pass_entry
;
145 /* Voice & Video Options*/
146 GtkWidget
*voice_frame
;
147 GtkWidget
*suppression_check
;
149 } AccountPrefsDialog
;
151 static AccountsWindow
*accounts_window
= NULL
;
152 static GHashTable
*account_pref_wins
;
154 static void add_account_to_liststore(PurpleAccount
*account
, gpointer user_data
);
155 static void set_account(GtkListStore
*store
, GtkTreeIter
*iter
,
156 PurpleAccount
*account
, GdkPixbuf
*global_buddyicon
);
158 /**************************************************************************
159 * Add/Modify Account dialog
160 **************************************************************************/
161 static void add_login_options(AccountPrefsDialog
*dialog
, GtkWidget
*parent
);
162 static void add_user_options(AccountPrefsDialog
*dialog
, GtkWidget
*parent
);
163 static void add_account_options(AccountPrefsDialog
*dialog
);
164 static void add_proxy_options(AccountPrefsDialog
*dialog
, GtkWidget
*parent
);
165 static void add_voice_options(AccountPrefsDialog
*dialog
);
168 add_pref_box(AccountPrefsDialog
*dialog
, GtkWidget
*parent
,
169 const char *text
, GtkWidget
*widget
)
171 return pidgin_add_widget_to_vbox(GTK_BOX(parent
), text
, dialog
->sg
, widget
, TRUE
, NULL
);
175 set_dialog_icon(AccountPrefsDialog
*dialog
, gpointer data
, size_t len
, gchar
*new_icon_path
)
177 GdkPixbuf
*pixbuf
= NULL
;
178 PurpleBuddyIconSpec
*icon_spec
= NULL
;
180 if (dialog
->icon_img
) {
181 g_object_unref(dialog
->icon_img
);
182 dialog
->icon_img
= NULL
;
185 if (new_icon_path
!= NULL
) {
186 dialog
->icon_img
= purple_image_new_from_file(new_icon_path
, NULL
);
187 purple_debug_warning("gtkaccount", "data was not necessary");
189 } else if (data
!= NULL
) {
191 dialog
->icon_img
= purple_image_new_take_data(data
, len
);
196 if (dialog
->icon_img
!= NULL
) {
197 pixbuf
= pidgin_pixbuf_from_image(dialog
->icon_img
);
200 if (dialog
->protocol
)
201 icon_spec
= purple_protocol_get_icon_spec(dialog
->protocol
);
203 if (pixbuf
&& icon_spec
&& (icon_spec
->scale_rules
& PURPLE_ICON_SCALE_DISPLAY
))
205 /* Scale the icon to something reasonable */
209 pidgin_buddy_icon_get_scale_size(pixbuf
, icon_spec
,
210 PURPLE_ICON_SCALE_DISPLAY
, &width
, &height
);
211 scale
= gdk_pixbuf_scale_simple(pixbuf
, width
, height
, GDK_INTERP_BILINEAR
);
213 g_object_unref(G_OBJECT(pixbuf
));
219 /* Show a placeholder icon */
220 gtk_image_set_from_icon_name(GTK_IMAGE(dialog
->icon_entry
),
221 "select-avatar", GTK_ICON_SIZE_LARGE_TOOLBAR
);
223 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog
->icon_entry
), pixbuf
);
224 g_object_unref(G_OBJECT(pixbuf
));
229 set_account_protocol_cb(GtkWidget
*widget
, const char *id
,
230 AccountPrefsDialog
*dialog
)
232 PurpleProtocol
*new_protocol
;
234 new_protocol
= purple_protocols_find(id
);
236 dialog
->protocol
= new_protocol
;
238 if (dialog
->protocol
!= NULL
)
240 PurpleProtocol
*old_protocol
= NULL
;
242 if (dialog
->protocol_id
)
243 old_protocol
= purple_protocols_find(dialog
->protocol_id
);
245 if (old_protocol
!= new_protocol
) {
246 g_free(dialog
->protocol_id
);
247 dialog
->protocol_id
= g_strdup(purple_protocol_get_id(dialog
->protocol
));
251 if (dialog
->account
!= NULL
)
252 purple_account_clear_settings(dialog
->account
);
254 add_login_options(dialog
, dialog
->top_vbox
);
255 add_user_options(dialog
, dialog
->top_vbox
);
256 add_account_options(dialog
);
257 add_voice_options(dialog
);
259 gtk_widget_grab_focus(dialog
->protocol_menu
);
261 if (!dialog
->protocol
|| !PURPLE_PROTOCOL_IMPLEMENTS(dialog
->protocol
, SERVER
, register_user
)) {
262 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
263 dialog
->register_button
), FALSE
);
264 gtk_widget_hide(dialog
->register_button
);
266 if (dialog
->protocol
!= NULL
&&
267 (purple_protocol_get_options(dialog
->protocol
) & OPT_PROTO_REGISTER_NOSCREENNAME
)) {
268 gtk_widget_set_sensitive(dialog
->register_button
, TRUE
);
270 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
271 dialog
->register_button
), FALSE
);
272 gtk_widget_set_sensitive(dialog
->register_button
, FALSE
);
274 gtk_widget_show(dialog
->register_button
);
279 username_changed_cb(GtkEntry
*entry
, AccountPrefsDialog
*dialog
)
281 gboolean opt_noscreenname
= (dialog
->protocol
!= NULL
&&
282 (purple_protocol_get_options(dialog
->protocol
) & OPT_PROTO_REGISTER_NOSCREENNAME
));
283 gboolean username_valid
= purple_validate(dialog
->protocol
,
284 gtk_entry_get_text(entry
));
286 if (dialog
->ok_button
) {
287 if (opt_noscreenname
&& dialog
->register_button
&&
288 gtk_toggle_button_get_active(
289 GTK_TOGGLE_BUTTON(dialog
->register_button
)))
290 gtk_widget_set_sensitive(dialog
->ok_button
, TRUE
);
292 gtk_widget_set_sensitive(dialog
->ok_button
,
296 if (dialog
->register_button
) {
297 if (opt_noscreenname
)
298 gtk_widget_set_sensitive(dialog
->register_button
, TRUE
);
300 gtk_widget_set_sensitive(dialog
->register_button
,
306 register_button_cb(GtkWidget
*checkbox
, AccountPrefsDialog
*dialog
)
308 int register_checked
= gtk_toggle_button_get_active(
309 GTK_TOGGLE_BUTTON(dialog
->register_button
));
310 int opt_noscreenname
= (dialog
->protocol
!= NULL
&&
311 (purple_protocol_get_options(dialog
->protocol
) & OPT_PROTO_REGISTER_NOSCREENNAME
));
312 int register_noscreenname
= (opt_noscreenname
&& register_checked
);
314 if (register_noscreenname
) {
315 gtk_entry_set_text(GTK_ENTRY(dialog
->username_entry
), "");
316 gtk_entry_set_text(GTK_ENTRY(dialog
->password_entry
), "");
317 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog
->remember_pass_check
), FALSE
);
319 gtk_widget_set_sensitive(dialog
->username_entry
, !register_noscreenname
);
320 gtk_widget_set_sensitive(dialog
->password_entry
, !register_noscreenname
);
321 gtk_widget_set_sensitive(dialog
->remember_pass_check
, !register_noscreenname
);
323 if (dialog
->ok_button
) {
324 gtk_widget_set_sensitive(dialog
->ok_button
,
325 (opt_noscreenname
&& register_checked
) ||
326 *gtk_entry_get_text(GTK_ENTRY(dialog
->username_entry
))
332 icon_filesel_choose_cb(const char *filename
, gpointer data
)
334 AccountPrefsDialog
*dialog
= data
;
336 if (filename
!= NULL
)
339 gpointer data
= pidgin_convert_buddy_icon(dialog
->protocol
, filename
, &len
);
340 set_dialog_icon(dialog
, data
, len
, g_strdup(filename
));
343 dialog
->icon_filesel
= NULL
;
347 icon_select_cb(GtkWidget
*button
, AccountPrefsDialog
*dialog
)
349 dialog
->icon_filesel
= pidgin_buddy_icon_chooser_new(GTK_WINDOW(dialog
->window
), icon_filesel_choose_cb
, dialog
);
350 gtk_widget_show_all(dialog
->icon_filesel
);
354 icon_reset_cb(GtkWidget
*button
, AccountPrefsDialog
*dialog
)
356 set_dialog_icon(dialog
, NULL
, 0, NULL
);
360 account_dnd_recv(GtkWidget
*widget
, GdkDragContext
*dc
, gint x
, gint y
,
361 GtkSelectionData
*sd
, guint info
, guint t
, AccountPrefsDialog
*dialog
)
363 const gchar
*name
= (gchar
*)gtk_selection_data_get_data(sd
);
364 gint length
= gtk_selection_data_get_length(sd
);
365 gint format
= gtk_selection_data_get_format(sd
);
367 if ((length
>= 0) && (format
== 8)) {
368 /* Well, it looks like the drag event was cool.
369 * Let's do something with it */
370 if (!g_ascii_strncasecmp(name
, "file://", 7)) {
371 GError
*converr
= NULL
;
376 /* It looks like we're dealing with a local file. */
377 if(!(tmp
= g_filename_from_uri(name
, NULL
, &converr
))) {
378 purple_debug(PURPLE_DEBUG_ERROR
, "buddyicon", "%s\n",
379 (converr
? converr
->message
:
380 "g_filename_from_uri error"));
383 if ((rtmp
= strchr(tmp
, '\r')) || (rtmp
= strchr(tmp
, '\n')))
386 data
= pidgin_convert_buddy_icon(dialog
->protocol
, tmp
, &len
);
387 /* This takes ownership of tmp */
388 set_dialog_icon(dialog
, data
, len
, tmp
);
390 gtk_drag_finish(dc
, TRUE
, FALSE
, t
);
392 gtk_drag_finish(dc
, FALSE
, FALSE
, t
);
396 update_editable(PurpleConnection
*gc
, AccountPrefsDialog
*dialog
)
398 GtkStyleContext
*style
;
402 if (dialog
->account
== NULL
)
405 if (gc
!= NULL
&& dialog
->account
!= purple_connection_get_account(gc
))
408 set
= !(purple_account_is_connected(dialog
->account
) || purple_account_is_connecting(dialog
->account
));
409 gtk_widget_set_sensitive(dialog
->protocol_menu
, set
);
410 gtk_editable_set_editable(GTK_EDITABLE(dialog
->username_entry
), set
);
411 style
= gtk_widget_get_style_context(dialog
->username_entry
);
414 gtk_style_context_remove_class(style
, "copyable-insensitive");
416 gtk_style_context_add_class(style
, "copyable-insensitive");
419 for (l
= dialog
->user_split_entries
; l
!= NULL
; l
= l
->next
) {
422 if (GTK_IS_EDITABLE(l
->data
)) {
423 gtk_editable_set_editable(GTK_EDITABLE(l
->data
), set
);
424 style
= gtk_widget_get_style_context(GTK_WIDGET(l
->data
));
426 gtk_style_context_remove_class(style
,
427 "copyable-insensitive");
429 gtk_style_context_add_class(style
,
430 "copyable-insensitive");
433 gtk_widget_set_sensitive(GTK_WIDGET(l
->data
), set
);
439 add_login_options(AccountPrefsDialog
*dialog
, GtkWidget
*parent
)
447 char *username
= NULL
;
448 GtkCssProvider
*entry_css
;
449 const gchar entry_style
[] =
450 "entry.copyable-insensitive {"
451 "color: @insensitive_fg_color;"
452 "background-color: @insensitive_bg_color;"
455 entry_css
= gtk_css_provider_new();
456 gtk_css_provider_load_from_data(entry_css
, entry_style
, -1, NULL
);
458 if (dialog
->protocol_menu
!= NULL
)
460 g_object_ref(G_OBJECT(dialog
->protocol_menu
));
461 hbox
= g_object_get_data(G_OBJECT(dialog
->protocol_menu
), "container");
462 gtk_container_remove(GTK_CONTAINER(hbox
), dialog
->protocol_menu
);
465 if (dialog
->login_frame
!= NULL
)
466 gtk_widget_destroy(dialog
->login_frame
);
468 /* Build the login options frame. */
469 frame
= pidgin_make_frame(parent
, _("Login Options"));
472 dialog
->login_frame
= gtk_widget_get_parent(gtk_widget_get_parent(frame
));
474 gtk_box_reorder_child(GTK_BOX(parent
), dialog
->login_frame
, 0);
475 gtk_widget_show(dialog
->login_frame
);
478 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
479 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
480 gtk_widget_show(vbox
);
483 if (dialog
->protocol_menu
== NULL
)
485 dialog
->protocol_menu
= pidgin_protocol_option_menu_new(
486 dialog
->protocol_id
, G_CALLBACK(set_account_protocol_cb
), dialog
);
487 g_object_ref(G_OBJECT(dialog
->protocol_menu
));
490 hbox
= add_pref_box(dialog
, vbox
, _("Pro_tocol:"), dialog
->protocol_menu
);
491 g_object_set_data(G_OBJECT(dialog
->protocol_menu
), "container", hbox
);
493 g_object_unref(G_OBJECT(dialog
->protocol_menu
));
496 dialog
->username_entry
= gtk_entry_new();
497 gtk_style_context_add_provider(
498 gtk_widget_get_style_context(dialog
->username_entry
),
499 GTK_STYLE_PROVIDER(entry_css
),
500 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
);
501 g_object_set(G_OBJECT(dialog
->username_entry
), "truncate-multiline", TRUE
, NULL
);
503 add_pref_box(dialog
, vbox
, _("_Username:"), dialog
->username_entry
);
505 if (dialog
->account
!= NULL
)
506 username
= g_strdup(purple_account_get_username(dialog
->account
));
508 if (!username
&& dialog
->protocol
509 && PURPLE_PROTOCOL_IMPLEMENTS(dialog
->protocol
, CLIENT
, get_account_text_table
)) {
512 table
= purple_protocol_client_iface_get_account_text_table(dialog
->protocol
, NULL
);
513 label
= g_hash_table_lookup(table
, "login_label");
515 gtk_entry_set_placeholder_text(GTK_ENTRY(dialog
->username_entry
), label
);
517 g_hash_table_destroy(table
);
520 g_signal_connect(G_OBJECT(dialog
->username_entry
), "changed",
521 G_CALLBACK(username_changed_cb
), dialog
);
523 /* Do the user split thang */
524 if (dialog
->protocol
== NULL
)
527 user_splits
= purple_protocol_get_user_splits(dialog
->protocol
);
529 if (dialog
->user_split_entries
!= NULL
) {
530 g_list_free(dialog
->user_split_entries
);
531 dialog
->user_split_entries
= NULL
;
534 for (l
= user_splits
; l
!= NULL
; l
= l
->next
) {
535 PurpleAccountUserSplit
*split
= l
->data
;
538 if (purple_account_user_split_is_constant(split
))
541 buf
= g_strdup_printf("_%s:", purple_account_user_split_get_text(split
));
542 entry
= gtk_entry_new();
543 gtk_style_context_add_provider(
544 gtk_widget_get_style_context(entry
),
545 GTK_STYLE_PROVIDER(entry_css
),
546 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
);
547 add_pref_box(dialog
, vbox
, buf
, entry
);
551 dialog
->user_split_entries
=
552 g_list_append(dialog
->user_split_entries
, entry
);
555 for (l
= g_list_last(dialog
->user_split_entries
),
556 l2
= g_list_last(user_splits
);
557 l
!= NULL
&& l2
!= NULL
;
558 l
= l
->prev
, l2
= l2
->prev
) {
560 GtkWidget
*entry
= l
->data
;
561 PurpleAccountUserSplit
*split
= l2
->data
;
562 const char *value
= NULL
;
565 if (dialog
->account
!= NULL
&& username
!= NULL
) {
566 if(purple_account_user_split_get_reverse(split
))
567 c
= strrchr(username
,
568 purple_account_user_split_get_separator(split
));
571 purple_account_user_split_get_separator(split
));
581 value
= purple_account_user_split_get_default_value(split
);
583 if (value
!= NULL
&& entry
!= NULL
)
584 gtk_entry_set_text(GTK_ENTRY(entry
), value
);
587 if (username
!= NULL
)
588 gtk_entry_set_text(GTK_ENTRY(dialog
->username_entry
), username
);
594 dialog
->password_entry
= gtk_entry_new();
595 gtk_entry_set_visibility(GTK_ENTRY(dialog
->password_entry
), FALSE
);
596 dialog
->password_box
= add_pref_box(dialog
, vbox
, _("_Password:"),
597 dialog
->password_entry
);
599 /* Remember Password */
600 dialog
->remember_pass_check
=
601 gtk_check_button_new_with_mnemonic(_("Remember pass_word"));
602 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog
->remember_pass_check
),
604 gtk_box_pack_start(GTK_BOX(vbox
), dialog
->remember_pass_check
,
606 gtk_widget_show(dialog
->remember_pass_check
);
608 /* Set the fields. */
609 if (dialog
->account
!= NULL
) {
610 if (dialog
->password
&& purple_account_get_remember_password(
612 gtk_entry_set_text(GTK_ENTRY(dialog
->password_entry
),
616 gtk_toggle_button_set_active(
617 GTK_TOGGLE_BUTTON(dialog
->remember_pass_check
),
618 purple_account_get_remember_password(dialog
->account
));
621 if (dialog
->protocol
!= NULL
&&
622 (purple_protocol_get_options(dialog
->protocol
) & OPT_PROTO_NO_PASSWORD
)) {
624 gtk_widget_hide(dialog
->password_box
);
625 gtk_widget_hide(dialog
->remember_pass_check
);
628 /* Do not let the user change the protocol/username while connected. */
629 update_editable(NULL
, dialog
);
630 purple_signal_connect(purple_connections_get_handle(), "signing-on", dialog
,
631 G_CALLBACK(update_editable
), dialog
);
632 purple_signal_connect(purple_connections_get_handle(), "signed-off", dialog
,
633 G_CALLBACK(update_editable
), dialog
);
635 g_object_unref(entry_css
);
639 icon_check_cb(GtkWidget
*checkbox
, AccountPrefsDialog
*dialog
)
641 gtk_widget_set_sensitive(dialog
->icon_hbox
, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog
->icon_check
)));
645 add_user_options(AccountPrefsDialog
*dialog
, GtkWidget
*parent
)
655 if (dialog
->user_frame
!= NULL
)
656 gtk_widget_destroy(dialog
->user_frame
);
658 /* Build the user options frame. */
659 frame
= pidgin_make_frame(parent
, _("User Options"));
660 dialog
->user_frame
= gtk_widget_get_parent(gtk_widget_get_parent(frame
));
662 gtk_box_reorder_child(GTK_BOX(parent
), dialog
->user_frame
, 1);
663 gtk_widget_show(dialog
->user_frame
);
666 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
667 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
668 gtk_widget_show(vbox
);
671 dialog
->alias_entry
= gtk_entry_new();
672 add_pref_box(dialog
, vbox
, _("_Local alias:"), dialog
->alias_entry
);
674 /* New mail notifications */
675 dialog
->new_mail_check
=
676 gtk_check_button_new_with_mnemonic(_("New _mail notifications"));
677 gtk_box_pack_start(GTK_BOX(vbox
), dialog
->new_mail_check
, FALSE
, FALSE
, 0);
678 gtk_widget_show(dialog
->new_mail_check
);
681 dialog
->icon_check
= gtk_check_button_new_with_mnemonic(_("Use this buddy _icon for this account:"));
682 g_signal_connect(G_OBJECT(dialog
->icon_check
), "toggled", G_CALLBACK(icon_check_cb
), dialog
);
683 gtk_widget_show(dialog
->icon_check
);
684 gtk_box_pack_start(GTK_BOX(vbox
), dialog
->icon_check
, FALSE
, FALSE
, 0);
686 dialog
->icon_hbox
= hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BOX_SPACE
);
687 gtk_widget_set_sensitive(hbox
, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog
->icon_check
)));
688 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
689 gtk_widget_show(hbox
);
691 label
= gtk_label_new(" ");
692 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
693 gtk_widget_show(label
);
695 button
= gtk_button_new();
696 gtk_box_pack_start(GTK_BOX(hbox
), button
, FALSE
, FALSE
, 0);
697 gtk_widget_show(button
);
698 g_signal_connect(G_OBJECT(button
), "clicked",
699 G_CALLBACK(icon_select_cb
), dialog
);
701 dialog
->icon_entry
= gtk_image_new();
702 gtk_container_add(GTK_CONTAINER(button
), dialog
->icon_entry
);
703 gtk_widget_show(dialog
->icon_entry
);
704 /* TODO: Uh, isn't this next line pretty useless? */
705 pidgin_set_accessible_label(dialog
->icon_entry
, GTK_LABEL(label
));
706 if (dialog
->icon_img
) {
707 g_object_unref(dialog
->icon_img
);
708 dialog
->icon_img
= NULL
;
711 vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
712 gtk_box_pack_start(GTK_BOX(hbox
), vbox2
, TRUE
, TRUE
, 0);
713 gtk_widget_show(vbox2
);
715 hbox2
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BOX_SPACE
);
716 gtk_box_pack_start(GTK_BOX(vbox2
), hbox2
, FALSE
, FALSE
, PIDGIN_HIG_BORDER
);
717 gtk_widget_show(hbox2
);
719 button
= gtk_button_new_with_mnemonic(_("_Remove"));
720 g_signal_connect(G_OBJECT(button
), "clicked",
721 G_CALLBACK(icon_reset_cb
), dialog
);
722 gtk_box_pack_start(GTK_BOX(hbox2
), button
, FALSE
, FALSE
, 0);
723 gtk_widget_show(button
);
725 if (dialog
->protocol
!= NULL
) {
726 PurpleBuddyIconSpec
*icon_spec
= purple_protocol_get_icon_spec(dialog
->protocol
);
727 if (!(purple_protocol_get_options(dialog
->protocol
) & OPT_PROTO_MAIL_CHECK
))
728 gtk_widget_hide(dialog
->new_mail_check
);
730 if (!icon_spec
|| icon_spec
->format
== NULL
) {
731 gtk_widget_hide(dialog
->icon_check
);
732 gtk_widget_hide(dialog
->icon_hbox
);
736 if (dialog
->account
!= NULL
) {
738 gpointer data
= NULL
;
741 if (purple_account_get_private_alias(dialog
->account
))
742 gtk_entry_set_text(GTK_ENTRY(dialog
->alias_entry
),
743 purple_account_get_private_alias(dialog
->account
));
745 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog
->new_mail_check
),
746 purple_account_get_check_mail(dialog
->account
));
748 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog
->icon_check
),
749 !purple_account_get_bool(dialog
->account
, "use-global-buddyicon",
752 img
= purple_buddy_icons_find_account_icon(dialog
->account
);
755 len
= purple_image_get_data_size(img
);
756 data
= g_memdup(purple_image_get_data(img
), len
);
758 set_dialog_icon(dialog
, data
, len
,
759 g_strdup(purple_account_get_buddy_icon_path(dialog
->account
)));
761 set_dialog_icon(dialog
, NULL
, 0, NULL
);
765 if (!dialog
->protocol
||
766 (!(purple_protocol_get_options(dialog
->protocol
) & OPT_PROTO_MAIL_CHECK
) &&
767 (purple_protocol_get_icon_spec(dialog
->protocol
).format
== NULL
))) {
769 /* Nothing to see :( aww. */
770 gtk_widget_hide(dialog
->user_frame
);
776 add_account_options(AccountPrefsDialog
*dialog
)
778 PurpleAccountOption
*option
;
779 PurpleAccount
*account
;
780 GtkWidget
*vbox
, *check
, *entry
, *combo
;
782 gint i
, idx
, int_value
;
785 GtkCellRenderer
*renderer
;
786 PurpleKeyValuePair
*kvp
;
790 const char *str_value
;
792 ProtocolOptEntry
*opt_entry
;
793 const GSList
*str_hints
;
795 if (dialog
->protocol_frame
!= NULL
) {
796 gtk_notebook_remove_page (GTK_NOTEBOOK(dialog
->notebook
), 1);
797 dialog
->protocol_frame
= NULL
;
800 while (dialog
->protocol_opt_entries
!= NULL
) {
801 ProtocolOptEntry
*opt_entry
= dialog
->protocol_opt_entries
->data
;
802 g_free(opt_entry
->setting
);
804 dialog
->protocol_opt_entries
= g_list_delete_link(dialog
->protocol_opt_entries
, dialog
->protocol_opt_entries
);
807 if (dialog
->protocol
== NULL
||
808 purple_protocol_get_account_options(dialog
->protocol
) == NULL
)
811 account
= dialog
->account
;
814 dialog
->protocol_frame
= vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
815 gtk_container_set_border_width(GTK_CONTAINER(vbox
), PIDGIN_HIG_BORDER
);
816 gtk_notebook_insert_page(GTK_NOTEBOOK(dialog
->notebook
), vbox
,
817 gtk_label_new_with_mnemonic(_("Ad_vanced")), 1);
818 gtk_widget_show(vbox
);
820 for (l
= purple_protocol_get_account_options(dialog
->protocol
); l
!= NULL
; l
= l
->next
)
822 option
= (PurpleAccountOption
*)l
->data
;
824 opt_entry
= g_new0(ProtocolOptEntry
, 1);
825 opt_entry
->type
= purple_account_option_get_pref_type(option
);
826 opt_entry
->setting
= g_strdup(purple_account_option_get_setting(option
));
828 switch (opt_entry
->type
)
830 case PURPLE_PREF_BOOLEAN
:
831 if (account
== NULL
||
832 !purple_strequal(purple_account_get_protocol_id(account
),
833 dialog
->protocol_id
))
835 bool_value
= purple_account_option_get_default_bool(option
);
839 bool_value
= purple_account_get_bool(account
,
840 purple_account_option_get_setting(option
),
841 purple_account_option_get_default_bool(option
));
844 tmp
= g_strconcat("_", purple_account_option_get_text(option
), NULL
);
845 opt_entry
->widget
= check
= gtk_check_button_new_with_mnemonic(tmp
);
848 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check
),
851 gtk_box_pack_start(GTK_BOX(vbox
), check
, FALSE
, FALSE
, 0);
852 gtk_widget_show(check
);
855 case PURPLE_PREF_INT
:
856 if (account
== NULL
||
857 !purple_strequal(purple_account_get_protocol_id(account
),
858 dialog
->protocol_id
))
860 int_value
= purple_account_option_get_default_int(option
);
864 int_value
= purple_account_get_int(account
,
865 purple_account_option_get_setting(option
),
866 purple_account_option_get_default_int(option
));
869 g_snprintf(buf
, sizeof(buf
), "%d", int_value
);
871 opt_entry
->widget
= entry
= gtk_entry_new();
872 gtk_entry_set_text(GTK_ENTRY(entry
), buf
);
874 title
= g_strdup_printf("_%s:",
875 purple_account_option_get_text(option
));
876 add_pref_box(dialog
, vbox
, title
, entry
);
880 case PURPLE_PREF_STRING
:
881 if (account
== NULL
||
882 !purple_strequal(purple_account_get_protocol_id(account
),
883 dialog
->protocol_id
))
885 str_value
= purple_account_option_get_default_string(option
);
889 str_value
= purple_account_get_string(account
,
890 purple_account_option_get_setting(option
),
891 purple_account_option_get_default_string(option
));
894 str_hints
= purple_account_option_string_get_hints(option
);
897 const GSList
*hint_it
= str_hints
;
898 entry
= gtk_combo_box_text_new_with_entry();
901 const gchar
*hint
= hint_it
->data
;
902 hint_it
= g_slist_next(hint_it
);
903 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(entry
),
908 entry
= gtk_entry_new();
910 opt_entry
->widget
= entry
;
911 if (purple_account_option_string_get_masked(option
) && str_hints
)
913 else if (purple_account_option_string_get_masked(option
))
915 gtk_entry_set_visibility(GTK_ENTRY(entry
), FALSE
);
918 if (str_value
!= NULL
&& str_hints
)
919 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entry
))),
922 gtk_entry_set_text(GTK_ENTRY(entry
), str_value
? str_value
: "");
924 title
= g_strdup_printf("_%s:",
925 purple_account_option_get_text(option
));
926 add_pref_box(dialog
, vbox
, title
, entry
);
930 case PURPLE_PREF_STRING_LIST
:
934 if (account
== NULL
||
935 !purple_strequal(purple_account_get_protocol_id(account
),
936 dialog
->protocol_id
))
938 str_value
= purple_account_option_get_default_list_value(option
);
942 str_value
= purple_account_get_string(account
,
943 purple_account_option_get_setting(option
),
944 purple_account_option_get_default_list_value(option
));
947 list
= purple_account_option_get_list(option
);
948 model
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_POINTER
);
949 opt_entry
->widget
= combo
= gtk_combo_box_new_with_model(GTK_TREE_MODEL(model
));
951 /* Loop through list of PurpleKeyValuePair items */
952 for (node
= list
; node
!= NULL
; node
= node
->next
) {
953 if (node
->data
!= NULL
) {
954 kvp
= (PurpleKeyValuePair
*) node
->data
;
955 if ((kvp
->value
!= NULL
) && (str_value
!= NULL
) &&
956 !g_utf8_collate(kvp
->value
, str_value
))
959 gtk_list_store_append(model
, &iter
);
960 gtk_list_store_set(model
, &iter
,
970 gtk_combo_box_set_active(GTK_COMBO_BOX(combo
), idx
);
972 /* Define renderer */
973 renderer
= gtk_cell_renderer_text_new();
974 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo
), renderer
,
976 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo
),
977 renderer
, "text", 0, NULL
);
979 title
= g_strdup_printf("_%s:",
980 purple_account_option_get_text(option
));
981 add_pref_box(dialog
, vbox
, title
, combo
);
986 purple_debug_error("gtkaccount", "Invalid Account Option pref type (%d)\n",
988 g_free(opt_entry
->setting
);
993 dialog
->protocol_opt_entries
=
994 g_list_append(dialog
->protocol_opt_entries
, opt_entry
);
1000 make_proxy_dropdown(void)
1002 GtkWidget
*dropdown
;
1003 GtkListStore
*model
;
1005 GtkCellRenderer
*renderer
;
1007 model
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_INT
);
1008 dropdown
= gtk_combo_box_new_with_model(GTK_TREE_MODEL(model
));
1010 gtk_list_store_append(model
, &iter
);
1011 gtk_list_store_set(model
, &iter
,
1012 0, purple_running_gnome() ? _("Use GNOME Proxy Settings")
1013 :_("Use Global Proxy Settings"),
1014 1, PURPLE_PROXY_USE_GLOBAL
,
1017 gtk_list_store_append(model
, &iter
);
1018 gtk_list_store_set(model
, &iter
,
1020 1, PURPLE_PROXY_NONE
,
1023 gtk_list_store_append(model
, &iter
);
1024 gtk_list_store_set(model
, &iter
,
1026 1, PURPLE_PROXY_SOCKS4
,
1029 gtk_list_store_append(model
, &iter
);
1030 gtk_list_store_set(model
, &iter
,
1032 1, PURPLE_PROXY_SOCKS5
,
1035 gtk_list_store_append(model
, &iter
);
1036 gtk_list_store_set(model
, &iter
,
1037 0, _("Tor/Privacy (SOCKS5)"),
1038 1, PURPLE_PROXY_TOR
,
1041 gtk_list_store_append(model
, &iter
);
1042 gtk_list_store_set(model
, &iter
,
1044 1, PURPLE_PROXY_HTTP
,
1047 gtk_list_store_append(model
, &iter
);
1048 gtk_list_store_set(model
, &iter
,
1049 0, _("Use Environmental Settings"),
1050 1, PURPLE_PROXY_USE_ENVVAR
,
1053 renderer
= gtk_cell_renderer_text_new();
1054 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropdown
), renderer
, TRUE
);
1055 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropdown
), renderer
,
1062 proxy_type_changed_cb(GtkWidget
*menu
, AccountPrefsDialog
*dialog
)
1066 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(menu
), &iter
)) {
1068 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(menu
)), &iter
,
1070 dialog
->new_proxy_type
= int_value
;
1073 if (dialog
->new_proxy_type
== PURPLE_PROXY_USE_GLOBAL
||
1074 dialog
->new_proxy_type
== PURPLE_PROXY_NONE
||
1075 dialog
->new_proxy_type
== PURPLE_PROXY_USE_ENVVAR
) {
1077 gtk_widget_hide(dialog
->proxy_vbox
);
1080 gtk_widget_show_all(dialog
->proxy_vbox
);
1084 port_popup_cb(GtkWidget
*w
, GtkMenu
*menu
, gpointer data
)
1089 /* This is an easter egg.
1090 It means one of two things, both intended as humourus:
1091 A) your network is really slow and you have nothing better to do than
1092 look at butterflies.
1093 B)You are looking really closely at something that shouldn't matter. */
1094 item1
= gtk_menu_item_new_with_label(_("If you look real closely"));
1096 /* This is an easter egg. See the comment on the previous line in the source. */
1097 item2
= gtk_menu_item_new_with_label(_("you can see the butterflies mating"));
1099 gtk_widget_show(item1
);
1100 gtk_widget_show(item2
);
1102 /* Prepend these in reverse order so they appear correctly. */
1103 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu
), item2
);
1104 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu
), item1
);
1108 add_proxy_options(AccountPrefsDialog
*dialog
, GtkWidget
*parent
)
1110 PurpleProxyInfo
*proxy_info
;
1114 GtkTreeModel
*proxy_model
;
1116 if (dialog
->proxy_frame
!= NULL
)
1117 gtk_widget_destroy(dialog
->proxy_frame
);
1120 dialog
->proxy_frame
= vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
1121 gtk_container_add(GTK_CONTAINER(parent
), vbox
);
1122 gtk_widget_show(vbox
);
1124 /* Proxy Type drop-down. */
1125 dialog
->proxy_dropdown
= make_proxy_dropdown();
1127 add_pref_box(dialog
, vbox
, _("Proxy _type:"), dialog
->proxy_dropdown
);
1129 /* Setup the second vbox, which may be hidden at times. */
1130 dialog
->proxy_vbox
= vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
1131 gtk_box_pack_start(GTK_BOX(vbox
), vbox2
, FALSE
, FALSE
, PIDGIN_HIG_BORDER
);
1132 gtk_widget_show(vbox2
);
1135 dialog
->proxy_host_entry
= gtk_entry_new();
1136 add_pref_box(dialog
, vbox2
, _("_Host:"), dialog
->proxy_host_entry
);
1139 dialog
->proxy_port_entry
= gtk_entry_new();
1140 add_pref_box(dialog
, vbox2
, _("_Port:"), dialog
->proxy_port_entry
);
1142 g_signal_connect(G_OBJECT(dialog
->proxy_port_entry
), "populate-popup",
1143 G_CALLBACK(port_popup_cb
), NULL
);
1146 dialog
->proxy_user_entry
= gtk_entry_new();
1148 add_pref_box(dialog
, vbox2
, _("_Username:"), dialog
->proxy_user_entry
);
1151 dialog
->proxy_pass_entry
= gtk_entry_new();
1152 gtk_entry_set_visibility(GTK_ENTRY(dialog
->proxy_pass_entry
), FALSE
);
1153 add_pref_box(dialog
, vbox2
, _("Pa_ssword:"), dialog
->proxy_pass_entry
);
1155 if (dialog
->account
!= NULL
&&
1156 (proxy_info
= purple_account_get_proxy_info(dialog
->account
)) != NULL
) {
1160 dialog
->new_proxy_type
= purple_proxy_info_get_proxy_type(proxy_info
);
1162 if ((value
= purple_proxy_info_get_host(proxy_info
)) != NULL
)
1163 gtk_entry_set_text(GTK_ENTRY(dialog
->proxy_host_entry
), value
);
1165 if ((int_val
= purple_proxy_info_get_port(proxy_info
)) != 0) {
1168 g_snprintf(buf
, sizeof(buf
), "%d", int_val
);
1170 gtk_entry_set_text(GTK_ENTRY(dialog
->proxy_port_entry
), buf
);
1173 if ((value
= purple_proxy_info_get_username(proxy_info
)) != NULL
)
1174 gtk_entry_set_text(GTK_ENTRY(dialog
->proxy_user_entry
), value
);
1176 if ((value
= purple_proxy_info_get_password(proxy_info
)) != NULL
)
1177 gtk_entry_set_text(GTK_ENTRY(dialog
->proxy_pass_entry
), value
);
1180 dialog
->new_proxy_type
= PURPLE_PROXY_USE_GLOBAL
;
1182 proxy_model
= gtk_combo_box_get_model(
1183 GTK_COMBO_BOX(dialog
->proxy_dropdown
));
1184 if (gtk_tree_model_get_iter_first(proxy_model
, &iter
)) {
1187 gtk_tree_model_get(proxy_model
, &iter
, 1, &int_val
, -1);
1188 if (int_val
== dialog
->new_proxy_type
) {
1189 gtk_combo_box_set_active_iter(
1190 GTK_COMBO_BOX(dialog
->proxy_dropdown
), &iter
);
1193 } while(gtk_tree_model_iter_next(proxy_model
, &iter
));
1196 proxy_type_changed_cb(dialog
->proxy_dropdown
, dialog
);
1198 /* Connect signals. */
1199 g_signal_connect(G_OBJECT(dialog
->proxy_dropdown
), "changed",
1200 G_CALLBACK(proxy_type_changed_cb
), dialog
);
1204 add_voice_options(AccountPrefsDialog
*dialog
)
1207 if (!dialog
->protocol
|| !PURPLE_PROTOCOL_IMPLEMENTS(dialog
->protocol
, MEDIA
, initiate_session
)) {
1208 if (dialog
->voice_frame
) {
1209 gtk_widget_destroy(dialog
->voice_frame
);
1210 dialog
->voice_frame
= NULL
;
1211 dialog
->suppression_check
= NULL
;
1216 if (!dialog
->voice_frame
) {
1217 dialog
->voice_frame
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
1218 gtk_container_set_border_width(GTK_CONTAINER(dialog
->voice_frame
),
1221 dialog
->suppression_check
=
1222 gtk_check_button_new_with_mnemonic(_("Use _silence suppression"));
1223 gtk_box_pack_start(GTK_BOX(dialog
->voice_frame
), dialog
->suppression_check
,
1226 gtk_notebook_append_page(GTK_NOTEBOOK(dialog
->notebook
),
1227 dialog
->voice_frame
, gtk_label_new_with_mnemonic(_("_Voice and Video")));
1228 gtk_widget_show_all(dialog
->voice_frame
);
1231 if (dialog
->account
) {
1232 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog
->suppression_check
),
1233 purple_account_get_silence_suppression(dialog
->account
));
1235 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog
->suppression_check
), FALSE
);
1241 account_win_destroy_cb(GtkWidget
*w
, GdkEvent
*event
,
1242 AccountPrefsDialog
*dialog
)
1244 g_hash_table_remove(account_pref_wins
, dialog
->account
);
1246 gtk_widget_destroy(dialog
->window
);
1248 g_list_free(dialog
->user_split_entries
);
1249 while (dialog
->protocol_opt_entries
!= NULL
) {
1250 ProtocolOptEntry
*opt_entry
= dialog
->protocol_opt_entries
->data
;
1251 g_free(opt_entry
->setting
);
1253 dialog
->protocol_opt_entries
= g_list_delete_link(dialog
->protocol_opt_entries
, dialog
->protocol_opt_entries
);
1255 g_free(dialog
->protocol_id
);
1256 g_object_unref(dialog
->sg
);
1258 if (dialog
->icon_img
)
1259 g_object_unref(dialog
->icon_img
);
1261 if (dialog
->icon_filesel
)
1262 gtk_widget_destroy(dialog
->icon_filesel
);
1264 purple_signals_disconnect_by_handle(dialog
);
1266 purple_str_wipe(dialog
->password
);
1273 cancel_account_prefs_cb(GtkWidget
*w
, AccountPrefsDialog
*dialog
)
1275 account_win_destroy_cb(NULL
, NULL
, dialog
);
1279 account_register_cb(PurpleAccount
*account
, gboolean succeeded
, void *user_data
)
1283 const PurpleSavedStatus
*saved_status
= purple_savedstatus_get_current();
1284 purple_signal_emit(pidgin_accounts_get_handle(), "account-modified", account
);
1286 if (saved_status
!= NULL
&& purple_account_get_remember_password(account
)) {
1287 purple_savedstatus_activate_for_account(saved_status
, account
);
1288 purple_account_set_enabled(account
, PIDGIN_UI
, TRUE
);
1292 purple_accounts_delete(account
);
1296 ok_account_prefs_cb(GtkWidget
*w
, AccountPrefsDialog
*dialog
)
1298 PurpleProxyInfo
*proxy_info
= NULL
;
1303 gboolean new_acct
= FALSE
, icon_change
= FALSE
;
1304 PurpleAccount
*account
;
1306 PurpleBuddyIconSpec
*icon_spec
= NULL
;
1308 /* Build the username string. */
1309 username
= g_strdup(gtk_entry_get_text(GTK_ENTRY(dialog
->username_entry
)));
1311 if (dialog
->protocol
!= NULL
)
1313 for (l
= purple_protocol_get_user_splits(dialog
->protocol
),
1314 l2
= dialog
->user_split_entries
;
1315 l
!= NULL
&& l2
!= NULL
;
1316 l
= l
->next
, l2
= l2
->next
)
1318 PurpleAccountUserSplit
*split
= l
->data
;
1319 GtkEntry
*entry
= l2
->data
;
1322 value
= entry
? gtk_entry_get_text(entry
) : "";
1326 *sep
= purple_account_user_split_get_separator(split
);
1328 tmp
= g_strconcat(username
, sep
,
1330 purple_account_user_split_get_default_value(split
)),
1338 if (dialog
->account
== NULL
)
1340 if (purple_accounts_find(username
, dialog
->protocol_id
) != NULL
) {
1341 purple_debug_warning("gtkaccount", "Trying to add a duplicate %s account (%s).\n",
1342 dialog
->protocol_id
, username
);
1344 purple_notify_error(NULL
, NULL
, _("Unable to save new account"),
1345 _("An account already exists with the specified criteria."), NULL
);
1351 if (purple_accounts_get_all() == NULL
) {
1352 /* We're adding our first account. Be polite and show the buddy list */
1353 PidginBuddyList
*blist
=
1354 pidgin_blist_get_default_gtk_blist();
1355 if (blist
!= NULL
&& blist
->window
!= NULL
) {
1356 gtk_window_present(GTK_WINDOW(blist
->window
));
1360 account
= purple_account_new(username
, dialog
->protocol_id
);
1365 account
= dialog
->account
;
1368 purple_account_set_protocol_id(account
, dialog
->protocol_id
);
1372 value
= gtk_entry_get_text(GTK_ENTRY(dialog
->alias_entry
));
1375 purple_account_set_private_alias(account
, value
);
1377 purple_account_set_private_alias(account
, NULL
);
1380 if (dialog
->protocol
!= NULL
)
1381 icon_spec
= purple_protocol_get_icon_spec(dialog
->protocol
);
1383 if (icon_spec
&& icon_spec
->format
!= NULL
)
1385 const char *filename
;
1387 if (new_acct
|| purple_account_get_bool(account
, "use-global-buddyicon", TRUE
) ==
1388 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog
->icon_check
)))
1392 purple_account_set_bool(account
, "use-global-buddyicon", !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog
->icon_check
)));
1394 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog
->icon_check
)))
1396 if (dialog
->icon_img
)
1398 size_t len
= purple_image_get_data_size(dialog
->icon_img
);
1399 purple_buddy_icons_set_account_icon(account
,
1400 g_memdup(purple_image_get_data(dialog
->icon_img
), len
), len
);
1401 purple_account_set_buddy_icon_path(account
,
1402 purple_image_get_path(dialog
->icon_img
));
1406 purple_buddy_icons_set_account_icon(account
, NULL
, 0);
1407 purple_account_set_buddy_icon_path(account
, NULL
);
1410 else if ((filename
= purple_prefs_get_path(PIDGIN_PREFS_ROOT
"/accounts/buddyicon")) && icon_change
)
1413 gpointer data
= pidgin_convert_buddy_icon(dialog
->protocol
, filename
, &len
);
1414 purple_account_set_buddy_icon_path(account
, filename
);
1415 purple_buddy_icons_set_account_icon(account
, data
, len
);
1420 /* Remember Password */
1421 remember
= gtk_toggle_button_get_active(
1422 GTK_TOGGLE_BUTTON(dialog
->remember_pass_check
));
1424 purple_keyring_set_password(account
, NULL
, NULL
, NULL
);
1426 purple_account_set_remember_password(account
, remember
);
1429 if (dialog
->protocol
&& purple_protocol_get_options(dialog
->protocol
) & OPT_PROTO_MAIL_CHECK
)
1430 purple_account_set_check_mail(account
,
1431 gtk_toggle_button_get_active(
1432 GTK_TOGGLE_BUTTON(dialog
->new_mail_check
)));
1435 value
= gtk_entry_get_text(GTK_ENTRY(dialog
->password_entry
));
1438 * We set the password if this is a new account because new accounts
1439 * will be set to online, and if the user has entered a password into
1440 * the account editor (but has not checked the 'save' box), then we
1441 * don't want to prompt them.
1443 if ((purple_account_get_remember_password(account
) || new_acct
) && (*value
!= '\0'))
1444 purple_account_set_password(account
, value
, NULL
, NULL
);
1446 purple_account_set_password(account
, NULL
, NULL
, NULL
);
1448 purple_account_set_username(account
, username
);
1451 /* Add the protocol settings */
1452 if (dialog
->protocol
) {
1453 ProtocolOptEntry
*opt_entry
;
1457 gboolean bool_value
;
1459 for (l2
= dialog
->protocol_opt_entries
; l2
; l2
= l2
->next
) {
1461 opt_entry
= l2
->data
;
1463 switch (opt_entry
->type
) {
1464 case PURPLE_PREF_STRING
:
1465 if (GTK_IS_COMBO_BOX(opt_entry
->widget
))
1466 value
= gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(opt_entry
->widget
));
1468 value
= gtk_entry_get_text(GTK_ENTRY(opt_entry
->widget
));
1469 purple_account_set_string(account
, opt_entry
->setting
, value
);
1472 case PURPLE_PREF_INT
:
1473 int_value
= atoi(gtk_entry_get_text(GTK_ENTRY(opt_entry
->widget
)));
1474 purple_account_set_int(account
, opt_entry
->setting
, int_value
);
1477 case PURPLE_PREF_BOOLEAN
:
1479 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(opt_entry
->widget
));
1480 purple_account_set_bool(account
, opt_entry
->setting
, bool_value
);
1483 case PURPLE_PREF_STRING_LIST
:
1485 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(opt_entry
->widget
), &iter
))
1486 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(opt_entry
->widget
)), &iter
, 1, &value2
, -1);
1487 purple_account_set_string(account
, opt_entry
->setting
, value2
);
1496 /* Set the proxy stuff. */
1497 proxy_info
= purple_account_get_proxy_info(account
);
1499 /* Create the proxy info if it doesn't exist. */
1500 if (proxy_info
== NULL
) {
1501 proxy_info
= purple_proxy_info_new();
1502 purple_account_set_proxy_info(account
, proxy_info
);
1505 /* Set the proxy info type. */
1506 purple_proxy_info_set_proxy_type(proxy_info
, dialog
->new_proxy_type
);
1509 value
= gtk_entry_get_text(GTK_ENTRY(dialog
->proxy_host_entry
));
1512 purple_proxy_info_set_host(proxy_info
, value
);
1514 purple_proxy_info_set_host(proxy_info
, NULL
);
1517 value
= gtk_entry_get_text(GTK_ENTRY(dialog
->proxy_port_entry
));
1520 purple_proxy_info_set_port(proxy_info
, atoi(value
));
1522 purple_proxy_info_set_port(proxy_info
, 0);
1525 value
= gtk_entry_get_text(GTK_ENTRY(dialog
->proxy_user_entry
));
1528 purple_proxy_info_set_username(proxy_info
, value
);
1530 purple_proxy_info_set_username(proxy_info
, NULL
);
1533 value
= gtk_entry_get_text(GTK_ENTRY(dialog
->proxy_pass_entry
));
1536 purple_proxy_info_set_password(proxy_info
, value
);
1538 purple_proxy_info_set_password(proxy_info
, NULL
);
1540 /* If there are no values set then proxy_info NULL */
1541 if ((purple_proxy_info_get_proxy_type(proxy_info
) == PURPLE_PROXY_USE_GLOBAL
) &&
1542 (purple_proxy_info_get_host(proxy_info
) == NULL
) &&
1543 (purple_proxy_info_get_port(proxy_info
) == 0) &&
1544 (purple_proxy_info_get_username(proxy_info
) == NULL
) &&
1545 (purple_proxy_info_get_password(proxy_info
) == NULL
))
1547 purple_account_set_proxy_info(account
, NULL
);
1551 /* Voice and Video settings */
1552 if (dialog
->voice_frame
) {
1553 purple_account_set_silence_suppression(account
,
1554 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog
->suppression_check
)));
1557 /* If this is a new account, add it to our list */
1559 purple_accounts_add(account
);
1561 purple_signal_emit(pidgin_accounts_get_handle(), "account-modified", account
);
1563 /* If this is a new account, then sign on! */
1564 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog
->register_button
))) {
1565 purple_account_set_register_callback(account
, account_register_cb
, NULL
);
1566 purple_account_register(account
);
1567 } else if (new_acct
) {
1568 const PurpleSavedStatus
*saved_status
;
1570 saved_status
= purple_savedstatus_get_current();
1571 if (saved_status
!= NULL
) {
1572 purple_savedstatus_activate_for_account(saved_status
, account
);
1573 purple_account_set_enabled(account
, PIDGIN_UI
, TRUE
);
1577 /* We no longer need the data from the dialog window */
1578 account_win_destroy_cb(NULL
, NULL
, dialog
);
1582 static const GtkTargetEntry dnd_targets
[] = {
1583 {"text/plain", 0, 0},
1584 {"text/uri-list", 0, 1},
1589 pidgin_account_dialog_show_continue(PurpleAccount
*account
,
1590 const gchar
*password
, GError
*error
, gpointer _type
)
1592 PidginAccountDialogType type
= GPOINTER_TO_INT(_type
);
1593 AccountPrefsDialog
*dialog
;
1595 GtkWidget
*main_vbox
;
1598 GtkWidget
*notebook
;
1601 if (accounts_window
!= NULL
&& account
!= NULL
&&
1602 (dialog
= g_hash_table_lookup(account_pref_wins
, account
)) != NULL
)
1604 gtk_window_present(GTK_WINDOW(dialog
->window
));
1608 dialog
= g_new0(AccountPrefsDialog
, 1);
1610 if (account
== NULL
) {
1611 /* Select the first protocol in the list*/
1612 GList
*protocol_list
= purple_protocols_get_all();
1613 if (protocol_list
!= NULL
) {
1614 dialog
->protocol_id
= g_strdup(purple_protocol_get_id(PURPLE_PROTOCOL(protocol_list
->data
)));
1615 g_list_free(protocol_list
);
1620 dialog
->protocol_id
=
1621 g_strdup(purple_account_get_protocol_id(account
));
1624 /* TODO if no protocols are loaded, this should inform the user that
1625 protocols need to be loaded instead of just doing nothing */
1626 if (!dialog
->protocol_id
) {
1631 if (accounts_window
!= NULL
&& account
!= NULL
)
1633 g_hash_table_insert(account_pref_wins
, account
, dialog
);
1636 dialog
->account
= account
;
1637 dialog
->password
= g_strdup(password
);
1638 dialog
->type
= type
;
1639 dialog
->sg
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
1640 dialog
->protocol
= purple_protocols_find(dialog
->protocol_id
);
1642 dialog
->window
= win
= pidgin_create_dialog((type
== PIDGIN_ADD_ACCOUNT_DIALOG
) ? _("Add Account") : _("Modify Account"),
1643 PIDGIN_HIG_BOX_SPACE
, "account", FALSE
);
1645 g_signal_connect(G_OBJECT(win
), "delete_event",
1646 G_CALLBACK(account_win_destroy_cb
), dialog
);
1648 /* Setup the vbox */
1649 main_vbox
= pidgin_dialog_get_vbox_with_properties(GTK_DIALOG(win
), FALSE
, PIDGIN_HIG_BOX_SPACE
);
1651 dialog
->notebook
= notebook
= gtk_notebook_new();
1652 gtk_box_pack_start(GTK_BOX(main_vbox
), notebook
, FALSE
, FALSE
, 0);
1653 gtk_widget_show(GTK_WIDGET(notebook
));
1655 /* Setup the inner vbox */
1656 dialog
->top_vbox
= vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
1657 gtk_container_set_border_width(GTK_CONTAINER(vbox
), PIDGIN_HIG_BORDER
);
1658 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), vbox
,
1659 gtk_label_new_with_mnemonic(_("_Basic")));
1660 gtk_widget_show(vbox
);
1662 /* Setup the top frames. */
1663 add_login_options(dialog
, vbox
);
1664 add_user_options(dialog
, vbox
);
1666 button
= gtk_check_button_new_with_mnemonic(
1667 _("Create _this new account on the server"));
1668 gtk_box_pack_start(GTK_BOX(main_vbox
), button
, FALSE
, FALSE
, 0);
1669 gtk_widget_show(button
);
1670 dialog
->register_button
= button
;
1671 g_signal_connect(G_OBJECT(dialog
->register_button
), "toggled", G_CALLBACK(register_button_cb
), dialog
);
1672 if (dialog
->account
== NULL
)
1673 gtk_widget_set_sensitive(button
, FALSE
);
1675 if (!dialog
->protocol
|| !PURPLE_PROTOCOL_IMPLEMENTS(dialog
->protocol
, SERVER
, register_user
))
1676 gtk_widget_hide(button
);
1678 /* Setup the page with 'Advanced' (protocol options). */
1679 add_account_options(dialog
);
1681 /* Setup the page with 'Proxy'. */
1682 dbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
1683 gtk_container_set_border_width(GTK_CONTAINER(dbox
), PIDGIN_HIG_BORDER
);
1684 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), dbox
,
1685 gtk_label_new_with_mnemonic(_("P_roxy")));
1686 gtk_widget_show(dbox
);
1687 add_proxy_options(dialog
, dbox
);
1689 add_voice_options(dialog
);
1692 pidgin_dialog_add_button(GTK_DIALOG(win
), _("_Cancel"),
1693 G_CALLBACK(cancel_account_prefs_cb
), dialog
);
1696 button
= pidgin_dialog_add_button(GTK_DIALOG(win
),
1697 (type
== PIDGIN_ADD_ACCOUNT_DIALOG
) ? _("_Add") : _("_Save"),
1698 G_CALLBACK(ok_account_prefs_cb
),
1700 if (dialog
->account
== NULL
)
1701 gtk_widget_set_sensitive(button
, FALSE
);
1702 dialog
->ok_button
= button
;
1705 gtk_drag_dest_set(dialog
->window
,
1706 GTK_DEST_DEFAULT_MOTION
|
1707 GTK_DEST_DEFAULT_DROP
,
1709 sizeof(dnd_targets
) / sizeof(GtkTargetEntry
),
1712 g_signal_connect(G_OBJECT(dialog
->window
), "drag_data_received",
1713 G_CALLBACK(account_dnd_recv
), dialog
);
1715 /* Show the window. */
1716 gtk_widget_show(win
);
1718 gtk_widget_grab_focus(dialog
->protocol_menu
);
1722 pidgin_account_dialog_show(PidginAccountDialogType type
, PurpleAccount
*account
)
1724 /* this is to make sure the password will be cached */
1725 purple_account_get_password(account
,
1726 pidgin_account_dialog_show_continue
, GINT_TO_POINTER(type
));
1729 /**************************************************************************
1731 **************************************************************************/
1733 signed_on_off_cb(PurpleConnection
*gc
, gpointer user_data
)
1735 PurpleAccount
*account
;
1736 GtkTreeModel
*model
;
1741 /* Don't need to do anything if the accounts window is not visible */
1742 if (accounts_window
== NULL
)
1745 account
= purple_connection_get_account(gc
);
1746 model
= GTK_TREE_MODEL(accounts_window
->model
);
1747 index
= g_list_index(purple_accounts_get_all(), account
);
1749 if (gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, index
))
1751 pixbuf
= pidgin_create_protocol_icon(account
, PIDGIN_PROTOCOL_ICON_MEDIUM
);
1752 if ((pixbuf
!= NULL
) && purple_account_is_disconnected(account
))
1753 gdk_pixbuf_saturate_and_pixelate(pixbuf
, pixbuf
, 0.0, FALSE
);
1755 gtk_list_store_set(accounts_window
->model
, &iter
,
1756 COLUMN_ICON
, pixbuf
,
1760 g_object_unref(G_OBJECT(pixbuf
));
1765 * Get the GtkTreeIter of the specified account in the
1769 accounts_window_find_account_in_treemodel(GtkTreeIter
*iter
, PurpleAccount
*account
)
1771 GtkTreeModel
*model
;
1774 g_return_val_if_fail(account
!= NULL
, FALSE
);
1775 g_return_val_if_fail(accounts_window
!= NULL
, FALSE
);
1777 model
= GTK_TREE_MODEL(accounts_window
->model
);
1779 if (!gtk_tree_model_get_iter_first(model
, iter
))
1782 gtk_tree_model_get(model
, iter
, COLUMN_DATA
, &cur
, -1);
1786 while (gtk_tree_model_iter_next(model
, iter
))
1788 gtk_tree_model_get(model
, iter
, COLUMN_DATA
, &cur
, -1);
1797 account_removed_cb(PurpleAccount
*account
, gpointer user_data
)
1799 AccountPrefsDialog
*dialog
;
1802 /* If the account was being modified, close the edit window */
1803 if ((dialog
= g_hash_table_lookup(account_pref_wins
, account
)) != NULL
)
1804 account_win_destroy_cb(NULL
, NULL
, dialog
);
1806 if (accounts_window
== NULL
)
1809 /* Remove the account from the GtkListStore */
1810 if (accounts_window_find_account_in_treemodel(&iter
, account
))
1811 gtk_list_store_remove(accounts_window
->model
, &iter
);
1813 if (purple_accounts_get_all() == NULL
)
1814 gtk_notebook_set_current_page(GTK_NOTEBOOK(accounts_window
->notebook
), 0);
1818 account_abled_cb(PurpleAccount
*account
, gpointer user_data
)
1822 if (accounts_window
== NULL
)
1825 /* update the account in the GtkListStore */
1826 if (accounts_window_find_account_in_treemodel(&iter
, account
))
1827 gtk_list_store_set(accounts_window
->model
, &iter
,
1828 COLUMN_ENABLED
, GPOINTER_TO_INT(user_data
),
1833 drag_data_get_cb(GtkWidget
*widget
, GdkDragContext
*ctx
,
1834 GtkSelectionData
*data
, guint info
, guint time
,
1835 AccountsWindow
*dialog
)
1837 GdkAtom target
= gtk_selection_data_get_target(data
);
1839 if (target
== gdk_atom_intern("PURPLE_ACCOUNT", FALSE
)) {
1840 GtkTreeRowReference
*ref
;
1841 GtkTreePath
*source_row
;
1843 PurpleAccount
*account
= NULL
;
1846 ref
= g_object_get_data(G_OBJECT(ctx
), "gtk-tree-view-source-row");
1847 source_row
= gtk_tree_row_reference_get_path(ref
);
1849 if (source_row
== NULL
)
1852 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog
->model
), &iter
,
1855 gtk_tree_model_get_value(GTK_TREE_MODEL(dialog
->model
), &iter
,
1858 dialog
->drag_iter
= iter
;
1860 account
= g_value_get_pointer(&val
);
1862 gtk_selection_data_set(data
, gdk_atom_intern("PURPLE_ACCOUNT", FALSE
),
1863 8, (void *)&account
, sizeof(account
));
1865 gtk_tree_path_free(source_row
);
1870 move_account_after(GtkListStore
*store
, GtkTreeIter
*iter
,
1871 GtkTreeIter
*position
)
1873 GtkTreeIter new_iter
;
1874 PurpleAccount
*account
;
1876 gtk_tree_model_get(GTK_TREE_MODEL(store
), iter
,
1877 COLUMN_DATA
, &account
,
1880 gtk_list_store_insert_after(store
, &new_iter
, position
);
1882 set_account(store
, &new_iter
, account
, NULL
);
1884 gtk_list_store_remove(store
, iter
);
1888 move_account_before(GtkListStore
*store
, GtkTreeIter
*iter
,
1889 GtkTreeIter
*position
)
1891 GtkTreeIter new_iter
;
1892 PurpleAccount
*account
;
1894 gtk_tree_model_get(GTK_TREE_MODEL(store
), iter
,
1895 COLUMN_DATA
, &account
,
1898 gtk_list_store_insert_before(store
, &new_iter
, position
);
1900 set_account(store
, &new_iter
, account
, NULL
);
1902 gtk_list_store_remove(store
, iter
);
1906 drag_data_received_cb(GtkWidget
*widget
, GdkDragContext
*ctx
,
1907 guint x
, guint y
, GtkSelectionData
*sd
,
1908 guint info
, guint t
, AccountsWindow
*dialog
)
1910 GdkAtom target
= gtk_selection_data_get_target(sd
);
1911 const guchar
*data
= gtk_selection_data_get_data(sd
);
1913 if (target
== gdk_atom_intern("PURPLE_ACCOUNT", FALSE
) && data
) {
1915 PurpleAccount
*a
= NULL
;
1916 GtkTreePath
*path
= NULL
;
1917 GtkTreeViewDropPosition position
;
1919 memcpy(&a
, data
, sizeof(a
));
1921 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget
), x
, y
,
1922 &path
, &position
)) {
1925 PurpleAccount
*account
;
1928 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog
->model
), &iter
, path
);
1930 gtk_tree_model_get_value(GTK_TREE_MODEL(dialog
->model
), &iter
,
1933 account
= g_value_get_pointer(&val
);
1936 case GTK_TREE_VIEW_DROP_AFTER
:
1937 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER
:
1938 move_account_after(dialog
->model
, &dialog
->drag_iter
,
1940 dest_index
= g_list_index(purple_accounts_get_all(),
1944 case GTK_TREE_VIEW_DROP_BEFORE
:
1945 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE
:
1946 dest_index
= g_list_index(purple_accounts_get_all(),
1949 move_account_before(dialog
->model
, &dialog
->drag_iter
,
1957 if (dest_index
>= 0)
1958 purple_accounts_reorder(a
, dest_index
);
1964 accedit_win_destroy_cb(GtkWidget
*w
, GdkEvent
*event
, AccountsWindow
*dialog
)
1966 dialog
->window
= NULL
;
1968 pidgin_accounts_window_hide();
1974 add_account_cb(GtkWidget
*w
, AccountsWindow
*dialog
)
1976 pidgin_account_dialog_show(PIDGIN_ADD_ACCOUNT_DIALOG
, NULL
);
1980 modify_account_sel(GtkTreeModel
*model
, GtkTreePath
*path
,
1981 GtkTreeIter
*iter
, gpointer data
)
1983 PurpleAccount
*account
;
1985 gtk_tree_model_get(model
, iter
, COLUMN_DATA
, &account
, -1);
1987 if (account
!= NULL
)
1988 pidgin_account_dialog_show(PIDGIN_MODIFY_ACCOUNT_DIALOG
, account
);
1992 modify_account_cb(GtkWidget
*w
, AccountsWindow
*dialog
)
1994 GtkTreeSelection
*selection
;
1996 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog
->treeview
));
1998 gtk_tree_selection_selected_foreach(selection
, modify_account_sel
, dialog
);
2002 delete_account_cb(PurpleAccount
*account
)
2004 purple_accounts_delete(account
);
2008 ask_delete_account_sel(GtkTreeModel
*model
, GtkTreePath
*path
,
2009 GtkTreeIter
*iter
, gpointer data
)
2011 PurpleAccount
*account
;
2013 gtk_tree_model_get(model
, iter
, COLUMN_DATA
, &account
, -1);
2015 if (account
!= NULL
) {
2018 buf
= g_strdup_printf(_("Are you sure you want to delete %s?"),
2019 purple_account_get_username(account
));
2021 purple_request_close_with_handle(account
);
2022 purple_request_action(account
, NULL
, buf
, NULL
,
2023 PURPLE_DEFAULT_ACTION_NONE
,
2024 purple_request_cpar_from_account(account
), account
, 2,
2025 _("Delete"), delete_account_cb
, _("Cancel"), NULL
);
2031 ask_delete_account_cb(GtkWidget
*w
, AccountsWindow
*dialog
)
2033 GtkTreeSelection
*selection
;
2035 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog
->treeview
));
2037 gtk_tree_selection_selected_foreach(selection
, ask_delete_account_sel
,
2042 close_accounts_cb(GtkWidget
*w
, AccountsWindow
*dialog
)
2044 pidgin_accounts_window_hide();
2049 enabled_cb(GtkCellRendererToggle
*renderer
, gchar
*path_str
,
2052 AccountsWindow
*dialog
= (AccountsWindow
*)data
;
2053 PurpleAccount
*account
;
2054 GtkTreeModel
*model
= GTK_TREE_MODEL(dialog
->model
);
2057 const PurpleSavedStatus
*saved_status
;
2059 gtk_tree_model_get_iter_from_string(model
, &iter
, path_str
);
2060 gtk_tree_model_get(model
, &iter
,
2061 COLUMN_DATA
, &account
,
2062 COLUMN_ENABLED
, &enabled
,
2066 * If we just enabled the account, then set the statuses
2067 * to the current status.
2071 saved_status
= purple_savedstatus_get_current();
2072 purple_savedstatus_activate_for_account(saved_status
, account
);
2075 purple_account_set_enabled(account
, PIDGIN_UI
, !enabled
);
2079 add_columns(GtkWidget
*treeview
, AccountsWindow
*dialog
)
2081 GtkCellRenderer
*renderer
;
2082 GtkTreeViewColumn
*column
;
2085 renderer
= gtk_cell_renderer_toggle_new();
2087 g_signal_connect(G_OBJECT(renderer
), "toggled",
2088 G_CALLBACK(enabled_cb
), dialog
);
2090 column
= gtk_tree_view_column_new_with_attributes(_("Enabled"),
2091 renderer
, "active", COLUMN_ENABLED
, NULL
);
2093 gtk_tree_view_column_set_resizable(column
, FALSE
);
2094 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview
), column
);
2096 /* Username column */
2097 column
= gtk_tree_view_column_new();
2098 gtk_tree_view_column_set_title(column
, _("Username"));
2099 gtk_tree_view_column_set_resizable(column
, TRUE
);
2100 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview
), column
);
2103 renderer
= gtk_cell_renderer_pixbuf_new();
2104 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
2105 gtk_tree_view_column_add_attribute(column
, renderer
,
2106 "pixbuf", COLUMN_BUDDYICON
);
2109 renderer
= gtk_cell_renderer_text_new();
2110 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
2111 gtk_tree_view_column_add_attribute(column
, renderer
,
2112 "text", COLUMN_USERNAME
);
2113 dialog
->username_col
= column
;
2117 column
= gtk_tree_view_column_new();
2118 gtk_tree_view_column_set_title(column
, _("Protocol"));
2119 gtk_tree_view_column_set_resizable(column
, FALSE
);
2120 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview
), column
);
2123 renderer
= gtk_cell_renderer_pixbuf_new();
2124 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
2125 gtk_tree_view_column_add_attribute(column
, renderer
,
2126 "pixbuf", COLUMN_ICON
);
2128 renderer
= gtk_cell_renderer_text_new();
2129 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
2130 gtk_tree_view_column_add_attribute(column
, renderer
,
2131 "text", COLUMN_PROTOCOL
);
2135 set_account(GtkListStore
*store
, GtkTreeIter
*iter
, PurpleAccount
*account
, GdkPixbuf
*global_buddyicon
)
2137 GdkPixbuf
*pixbuf
, *buddyicon
= NULL
;
2138 PurpleImage
*img
= NULL
;
2139 PurpleProtocol
*protocol
= NULL
;
2140 PurpleBuddyIconSpec
*icon_spec
= NULL
;
2142 pixbuf
= pidgin_create_protocol_icon(account
, PIDGIN_PROTOCOL_ICON_MEDIUM
);
2143 if ((pixbuf
!= NULL
) && purple_account_is_disconnected(account
))
2144 gdk_pixbuf_saturate_and_pixelate(pixbuf
, pixbuf
, 0.0, FALSE
);
2146 protocol
= purple_protocols_find(purple_account_get_protocol_id(account
));
2147 if (protocol
!= NULL
)
2148 icon_spec
= purple_protocol_get_icon_spec(protocol
);
2150 if (icon_spec
!= NULL
&& icon_spec
->format
!= NULL
) {
2151 if (purple_account_get_bool(account
, "use-global-buddyicon", TRUE
)) {
2152 if (global_buddyicon
!= NULL
)
2153 buddyicon
= GDK_PIXBUF(g_object_ref(G_OBJECT(global_buddyicon
)));
2155 /* This is for when set_account() is called for a single account */
2157 path
= purple_prefs_get_path(PIDGIN_PREFS_ROOT
"/accounts/buddyicon");
2158 if ((path
!= NULL
) && (*path
!= '\0')) {
2159 img
= purple_image_new_from_file(path
, NULL
);
2163 img
= purple_buddy_icons_find_account_icon(account
);
2168 GdkPixbuf
*buddyicon_pixbuf
;
2169 buddyicon_pixbuf
= pidgin_pixbuf_from_image(img
);
2170 g_object_unref(img
);
2172 if (buddyicon_pixbuf
!= NULL
) {
2173 buddyicon
= gdk_pixbuf_scale_simple(buddyicon_pixbuf
, 22, 22, GDK_INTERP_HYPER
);
2174 g_object_unref(G_OBJECT(buddyicon_pixbuf
));
2178 gtk_list_store_set(store
, iter
,
2179 COLUMN_ICON
, pixbuf
,
2180 COLUMN_BUDDYICON
, buddyicon
,
2181 COLUMN_USERNAME
, purple_account_get_username(account
),
2182 COLUMN_ENABLED
, purple_account_get_enabled(account
, PIDGIN_UI
),
2183 COLUMN_PROTOCOL
, purple_account_get_protocol_name(account
),
2184 COLUMN_DATA
, account
,
2188 g_object_unref(G_OBJECT(pixbuf
));
2189 if (buddyicon
!= NULL
)
2190 g_object_unref(G_OBJECT(buddyicon
));
2194 add_account_to_liststore(PurpleAccount
*account
, gpointer user_data
)
2197 GdkPixbuf
*global_buddyicon
= user_data
;
2199 if (accounts_window
== NULL
)
2202 gtk_list_store_append(accounts_window
->model
, &iter
);
2203 gtk_notebook_set_current_page(GTK_NOTEBOOK(accounts_window
->notebook
),1);
2205 set_account(accounts_window
->model
, &iter
, account
, global_buddyicon
);
2209 populate_accounts_list(AccountsWindow
*dialog
)
2212 gboolean ret
= FALSE
;
2213 GdkPixbuf
*global_buddyicon
= NULL
;
2216 gtk_list_store_clear(dialog
->model
);
2218 if ((path
= purple_prefs_get_path(PIDGIN_PREFS_ROOT
"/accounts/buddyicon")) != NULL
) {
2219 GdkPixbuf
*pixbuf
= pidgin_pixbuf_new_from_file(path
);
2220 if (pixbuf
!= NULL
) {
2221 global_buddyicon
= gdk_pixbuf_scale_simple(pixbuf
, 22, 22, GDK_INTERP_HYPER
);
2222 g_object_unref(G_OBJECT(pixbuf
));
2226 for (l
= purple_accounts_get_all(); l
!= NULL
; l
= l
->next
) {
2228 add_account_to_liststore((PurpleAccount
*)l
->data
, global_buddyicon
);
2231 if (global_buddyicon
!= NULL
)
2232 g_object_unref(G_OBJECT(global_buddyicon
));
2238 account_selected_cb(GtkTreeSelection
*sel
, AccountsWindow
*dialog
)
2240 gboolean selected
= FALSE
;
2242 selected
= (gtk_tree_selection_count_selected_rows(sel
) > 0);
2244 gtk_widget_set_sensitive(dialog
->modify_button
, selected
);
2245 gtk_widget_set_sensitive(dialog
->delete_button
, selected
);
2249 account_treeview_double_click_cb(GtkTreeView
*treeview
, GdkEventButton
*event
, gpointer user_data
)
2251 AccountsWindow
*dialog
;
2253 GtkTreeViewColumn
*column
;
2255 PurpleAccount
*account
;
2257 dialog
= (AccountsWindow
*)user_data
;
2259 if (event
->window
!= gtk_tree_view_get_bin_window(treeview
))
2262 /* Figure out which node was clicked */
2263 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(dialog
->treeview
), event
->x
, event
->y
, &path
, &column
, NULL
, NULL
))
2265 if (column
== gtk_tree_view_get_column(treeview
, 0)) {
2266 gtk_tree_path_free(path
);
2270 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog
->model
), &iter
, path
);
2271 gtk_tree_path_free(path
);
2272 gtk_tree_model_get(GTK_TREE_MODEL(dialog
->model
), &iter
, COLUMN_DATA
, &account
, -1);
2274 if ((account
!= NULL
) && (event
->button
== GDK_BUTTON_PRIMARY
) &&
2275 (event
->type
== GDK_2BUTTON_PRESS
))
2277 pidgin_account_dialog_show(PIDGIN_MODIFY_ACCOUNT_DIALOG
, account
);
2285 create_accounts_list(AccountsWindow
*dialog
)
2289 GtkWidget
*treeview
;
2290 GtkTreeSelection
*sel
;
2291 GtkTargetEntry gte
[] = {{"PURPLE_ACCOUNT", GTK_TARGET_SAME_APP
, 0}};
2294 frame
= gtk_frame_new(NULL
);
2295 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_IN
);
2297 accounts_window
->notebook
= gtk_notebook_new();
2298 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(accounts_window
->notebook
), FALSE
);
2299 gtk_notebook_set_show_border(GTK_NOTEBOOK(accounts_window
->notebook
), FALSE
);
2300 gtk_container_add(GTK_CONTAINER(frame
), accounts_window
->notebook
);
2302 /* Create a helpful first-time-use label */
2303 label
= gtk_label_new(NULL
);
2304 /* Translators: Please maintain the use of ⇦ or ⇨ to represent the menu hierarchy */
2305 text
= g_strdup_printf(_(
2306 "<span size='larger' weight='bold'>Welcome to %s!</span>\n\n"
2308 "You have no IM accounts configured. To start connecting with %s "
2309 "press the <b>Add...</b> button below and configure your first "
2310 "account. If you want %s to connect to multiple IM accounts, "
2311 "press <b>Add...</b> again to configure them all.\n\n"
2313 "You can come back to this window to add, edit, or remove "
2314 "accounts from <b>Accounts⇨Manage Accounts</b> in the Buddy "
2315 "List window"), PIDGIN_NAME
, PIDGIN_NAME
, PIDGIN_NAME
);
2316 gtk_label_set_markup(GTK_LABEL(label
), text
);
2319 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
2320 gtk_widget_show(label
);
2322 gtk_notebook_append_page(GTK_NOTEBOOK(accounts_window
->notebook
), label
, NULL
);
2324 /* Create the list model. */
2325 dialog
->model
= gtk_list_store_new(NUM_COLUMNS
,
2326 GDK_TYPE_PIXBUF
, /* COLUMN_ICON */
2327 GDK_TYPE_PIXBUF
, /* COLUMN_BUDDYICON */
2328 G_TYPE_STRING
, /* COLUMN_USERNAME */
2329 G_TYPE_BOOLEAN
, /* COLUMN_ENABLED */
2330 G_TYPE_STRING
, /* COLUMN_PROTOCOL */
2331 G_TYPE_POINTER
/* COLUMN_DATA */
2334 /* And now the actual treeview */
2335 treeview
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog
->model
));
2336 dialog
->treeview
= treeview
;
2337 g_object_unref(G_OBJECT(dialog
->model
));
2339 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
2340 gtk_tree_selection_set_mode(sel
, GTK_SELECTION_MULTIPLE
);
2341 g_signal_connect(G_OBJECT(sel
), "changed",
2342 G_CALLBACK(account_selected_cb
), dialog
);
2344 /* Handle double-clicking */
2345 g_signal_connect(G_OBJECT(treeview
), "button_press_event",
2346 G_CALLBACK(account_treeview_double_click_cb
), dialog
);
2348 gtk_notebook_append_page(GTK_NOTEBOOK(accounts_window
->notebook
),
2349 pidgin_make_scrollable(treeview
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
, GTK_SHADOW_NONE
, -1, -1),
2352 add_columns(treeview
, dialog
);
2353 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(treeview
));
2355 if (populate_accounts_list(dialog
))
2356 gtk_notebook_set_current_page(GTK_NOTEBOOK(accounts_window
->notebook
), 1);
2358 gtk_notebook_set_current_page(GTK_NOTEBOOK(accounts_window
->notebook
), 0);
2360 /* Setup DND. I wanna be an orc! */
2361 gtk_tree_view_enable_model_drag_source(
2362 GTK_TREE_VIEW(treeview
), GDK_BUTTON1_MASK
, gte
,
2363 1, GDK_ACTION_COPY
);
2364 gtk_tree_view_enable_model_drag_dest(
2365 GTK_TREE_VIEW(treeview
), gte
, 1,
2366 GDK_ACTION_COPY
| GDK_ACTION_MOVE
);
2368 g_signal_connect(G_OBJECT(treeview
), "drag-data-received",
2369 G_CALLBACK(drag_data_received_cb
), dialog
);
2370 g_signal_connect(G_OBJECT(treeview
), "drag-data-get",
2371 G_CALLBACK(drag_data_get_cb
), dialog
);
2373 gtk_widget_show_all(frame
);
2378 account_modified_cb(PurpleAccount
*account
, AccountsWindow
*window
)
2382 if (!accounts_window_find_account_in_treemodel(&iter
, account
))
2385 set_account(window
->model
, &iter
, account
, NULL
);
2389 global_buddyicon_changed(const char *name
, PurplePrefType type
,
2390 gconstpointer value
, gpointer window
)
2393 for (list
= purple_accounts_get_all(); list
; list
= list
->next
) {
2394 account_modified_cb(list
->data
, window
);
2399 pidgin_accounts_window_show(void)
2401 AccountsWindow
*dialog
;
2408 if (accounts_window
!= NULL
) {
2409 gtk_window_present(GTK_WINDOW(accounts_window
->window
));
2413 accounts_window
= dialog
= g_new0(AccountsWindow
, 1);
2415 width
= purple_prefs_get_int(PIDGIN_PREFS_ROOT
"/accounts/dialog/width");
2416 height
= purple_prefs_get_int(PIDGIN_PREFS_ROOT
"/accounts/dialog/height");
2418 dialog
->window
= win
= pidgin_create_dialog(_("Accounts"), 0, "accounts", TRUE
);
2419 gtk_window_set_default_size(GTK_WINDOW(win
), width
, height
);
2421 g_signal_connect(G_OBJECT(win
), "delete_event",
2422 G_CALLBACK(accedit_win_destroy_cb
), accounts_window
);
2424 /* Setup the vbox */
2425 vbox
= pidgin_dialog_get_vbox_with_properties(GTK_DIALOG(win
), FALSE
, PIDGIN_HIG_BORDER
);
2427 /* Setup the scrolled window that will contain the list of accounts. */
2428 sw
= create_accounts_list(dialog
);
2429 gtk_box_pack_start(GTK_BOX(vbox
), sw
, TRUE
, TRUE
, 0);
2430 gtk_widget_show(sw
);
2433 pidgin_dialog_add_button(GTK_DIALOG(win
), _("_Add..."),
2434 G_CALLBACK(add_account_cb
), dialog
);
2437 button
= pidgin_dialog_add_button(GTK_DIALOG(win
), _("_Modify..."),
2438 G_CALLBACK(modify_account_cb
), dialog
);
2439 dialog
->modify_button
= button
;
2440 gtk_widget_set_sensitive(button
, FALSE
);
2443 button
= pidgin_dialog_add_button(GTK_DIALOG(win
), _("_Delete"),
2444 G_CALLBACK(ask_delete_account_cb
), dialog
);
2445 dialog
->delete_button
= button
;
2446 gtk_widget_set_sensitive(button
, FALSE
);
2449 pidgin_dialog_add_button(GTK_DIALOG(win
), _("_Close"),
2450 G_CALLBACK(close_accounts_cb
), dialog
);
2452 purple_signal_connect(pidgin_accounts_get_handle(), "account-modified",
2454 PURPLE_CALLBACK(account_modified_cb
), accounts_window
);
2455 purple_prefs_connect_callback(accounts_window
,
2456 PIDGIN_PREFS_ROOT
"/accounts/buddyicon",
2457 global_buddyicon_changed
, accounts_window
);
2459 gtk_widget_show(win
);
2463 pidgin_accounts_window_hide(void)
2465 if (accounts_window
== NULL
)
2468 if (accounts_window
->window
!= NULL
)
2469 gtk_widget_destroy(accounts_window
->window
);
2471 purple_signals_disconnect_by_handle(accounts_window
);
2472 purple_prefs_disconnect_by_handle(accounts_window
);
2474 g_free(accounts_window
);
2475 accounts_window
= NULL
;
2479 free_add_user_data(PidginAccountAddUserData
*data
)
2481 g_free(data
->username
);
2482 g_free(data
->alias
);
2487 add_user_cb(PidginAccountAddUserData
*data
)
2489 PurpleConnection
*gc
= purple_account_get_connection(data
->account
);
2491 if (g_list_find(purple_connections_get_all(), gc
))
2493 purple_blist_request_add_buddy(data
->account
, data
->username
,
2497 free_add_user_data(data
);
2501 make_info(PurpleAccount
*account
, PurpleConnection
*gc
, const char *remote_user
,
2502 const char *id
, const char *alias
, const char *msg
)
2504 if (msg
!= NULL
&& *msg
== '\0')
2507 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"),
2509 (alias
!= NULL
? " (" : ""),
2510 (alias
!= NULL
? alias
: ""),
2511 (alias
!= NULL
? ")" : ""),
2514 : (purple_connection_get_display_name(gc
) != NULL
2515 ? purple_connection_get_display_name(gc
)
2516 : purple_account_get_username(account
))),
2517 (msg
!= NULL
? ": " : "."),
2518 (msg
!= NULL
? msg
: ""));
2522 pidgin_accounts_notify_added(PurpleAccount
*account
, const char *remote_user
,
2523 const char *id
, const char *alias
,
2527 PurpleConnection
*gc
;
2530 gc
= purple_account_get_connection(account
);
2532 buffer
= make_info(account
, gc
, remote_user
, id
, alias
, msg
);
2533 alert
= pidgin_make_mini_dialog(gc
, "dialog-information", buffer
,
2534 NULL
, NULL
, _("Close"), NULL
, NULL
);
2535 pidgin_blist_add_alert(alert
);
2541 pidgin_accounts_request_add(PurpleAccount
*account
, const char *remote_user
,
2542 const char *id
, const char *alias
,
2546 PurpleConnection
*gc
;
2547 PidginAccountAddUserData
*data
;
2550 gc
= purple_account_get_connection(account
);
2552 data
= g_new0(PidginAccountAddUserData
, 1);
2553 data
->account
= account
;
2554 data
->username
= g_strdup(remote_user
);
2555 data
->alias
= g_strdup(alias
);
2557 buffer
= make_info(account
, gc
, remote_user
, id
, alias
, msg
);
2558 alert
= pidgin_make_mini_dialog(gc
, "dialog-question",
2559 _("Add buddy to your list?"), buffer
, data
,
2560 _("Add"), G_CALLBACK(add_user_cb
),
2561 _("Cancel"), G_CALLBACK(free_add_user_data
), NULL
);
2562 pidgin_blist_add_alert(alert
);
2569 PurpleAccountRequestAuthorizationCb auth_cb
;
2570 PurpleAccountRequestAuthorizationCb deny_cb
;
2574 PurpleAccount
*account
;
2575 gboolean add_buddy_after_auth
;
2579 free_auth_request(struct auth_request
*ar
)
2581 g_free(ar
->username
);
2587 authorize_and_add_cb(struct auth_request
*ar
, const char *message
)
2589 ar
->auth_cb(message
, ar
->data
);
2590 if (ar
->add_buddy_after_auth
) {
2591 purple_blist_request_add_buddy(ar
->account
, ar
->username
, NULL
, ar
->alias
);
2596 authorize_noreason_cb(struct auth_request
*ar
)
2598 authorize_and_add_cb(ar
, NULL
);
2602 authorize_reason_cb(struct auth_request
*ar
)
2604 const char *protocol_id
;
2605 PurpleProtocol
*protocol
= NULL
;
2607 protocol_id
= purple_account_get_protocol_id(ar
->account
);
2608 protocol
= purple_protocols_find(protocol_id
);
2610 if (protocol
&& (purple_protocol_get_options(protocol
) & OPT_PROTO_AUTHORIZATION_GRANTED_MESSAGE
)) {
2611 /* Duplicate information because ar is freed by closing minidialog */
2612 struct auth_request
*aa
= g_new0(struct auth_request
, 1);
2613 aa
->auth_cb
= ar
->auth_cb
;
2614 aa
->deny_cb
= ar
->deny_cb
;
2615 aa
->data
= ar
->data
;
2616 aa
->account
= ar
->account
;
2617 aa
->username
= g_strdup(ar
->username
);
2618 aa
->alias
= g_strdup(ar
->alias
);
2619 aa
->add_buddy_after_auth
= ar
->add_buddy_after_auth
;
2620 purple_request_input(ar
->account
, NULL
, _("Authorization acceptance message:"),
2621 NULL
, _("No reason given."), TRUE
, FALSE
, NULL
,
2622 _("OK"), G_CALLBACK(authorize_and_add_cb
),
2623 _("Cancel"), G_CALLBACK(authorize_noreason_cb
),
2624 purple_request_cpar_from_account(ar
->account
),
2626 /* FIXME: aa is going to leak now. */
2628 authorize_noreason_cb(ar
);
2633 deny_no_add_cb(struct auth_request
*ar
, const char *message
)
2635 ar
->deny_cb(message
, ar
->data
);
2639 deny_noreason_cb(struct auth_request
*ar
)
2641 ar
->deny_cb(NULL
, ar
->data
);
2645 deny_reason_cb(struct auth_request
*ar
)
2647 const char *protocol_id
;
2648 PurpleProtocol
*protocol
= NULL
;
2650 protocol_id
= purple_account_get_protocol_id(ar
->account
);
2651 protocol
= purple_protocols_find(protocol_id
);
2653 if (protocol
&& (purple_protocol_get_options(protocol
) & OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE
)) {
2654 /* Duplicate information because ar is freed by closing minidialog */
2655 struct auth_request
*aa
= g_new0(struct auth_request
, 1);
2656 aa
->auth_cb
= ar
->auth_cb
;
2657 aa
->deny_cb
= ar
->deny_cb
;
2658 aa
->data
= ar
->data
;
2659 aa
->add_buddy_after_auth
= ar
->add_buddy_after_auth
;
2660 purple_request_input(ar
->account
, NULL
, _("Authorization denied message:"),
2661 NULL
, _("No reason given."), TRUE
, FALSE
, NULL
,
2662 _("OK"), G_CALLBACK(deny_no_add_cb
),
2663 _("Cancel"), G_CALLBACK(deny_noreason_cb
),
2664 purple_request_cpar_from_account(ar
->account
),
2666 /* FIXME: aa is going to leak now. */
2668 deny_noreason_cb(ar
);
2673 get_user_info_cb(GtkWidget
*label
,
2677 struct auth_request
*ar
= data
;
2678 if (purple_strequal(uri
, "viewinfo")) {
2679 pidgin_retrieve_user_info(purple_account_get_connection(ar
->account
), ar
->username
);
2686 send_im_cb(PidginMiniDialog
*mini_dialog
,
2690 struct auth_request
*ar
= data
;
2691 pidgin_dialogs_im_with_user(ar
->account
, ar
->username
);
2695 pidgin_accounts_request_authorization(PurpleAccount
*account
,
2696 const char *remote_user
,
2699 const char *message
,
2701 PurpleAccountRequestAuthorizationCb auth_cb
,
2702 PurpleAccountRequestAuthorizationCb deny_cb
,
2706 PurpleConnection
*gc
;
2708 PidginMiniDialog
*dialog
;
2709 GdkPixbuf
*protocol_icon
;
2710 struct auth_request
*aa
;
2711 const char *our_name
;
2712 gboolean have_valid_alias
;
2713 char *escaped_remote_user
;
2714 char *escaped_alias
;
2715 char *escaped_our_name
;
2716 char *escaped_message
;
2718 gc
= purple_account_get_connection(account
);
2719 if (message
!= NULL
&& *message
!= '\0')
2720 escaped_message
= g_markup_escape_text(message
, -1);
2722 escaped_message
= g_strdup("");
2724 our_name
= (id
!= NULL
) ? id
:
2725 (purple_connection_get_display_name(gc
) != NULL
) ? purple_connection_get_display_name(gc
) :
2726 purple_account_get_username(account
);
2727 escaped_our_name
= g_markup_escape_text(our_name
, -1);
2729 escaped_remote_user
= g_markup_escape_text(remote_user
, -1);
2731 have_valid_alias
= alias
&& *alias
;
2732 escaped_alias
= have_valid_alias
? g_markup_escape_text(alias
, -1) : g_strdup("");
2734 buffer
= g_strdup_printf(_("<a href=\"viewinfo\">%s</a>%s%s%s wants to add you (%s) to his or her buddy list%s%s"),
2735 escaped_remote_user
,
2736 (have_valid_alias
? " (" : ""),
2738 (have_valid_alias
? ")" : ""),
2740 (*escaped_message
? ": " : "."),
2743 g_free(escaped_remote_user
);
2744 g_free(escaped_alias
);
2745 g_free(escaped_our_name
);
2746 g_free(escaped_message
);
2748 protocol_icon
= pidgin_create_protocol_icon(account
, PIDGIN_PROTOCOL_ICON_SMALL
);
2750 aa
= g_new0(struct auth_request
, 1);
2751 aa
->auth_cb
= auth_cb
;
2752 aa
->deny_cb
= deny_cb
;
2753 aa
->data
= user_data
;
2754 aa
->username
= g_strdup(remote_user
);
2755 aa
->alias
= g_strdup(alias
);
2756 aa
->account
= account
;
2757 aa
->add_buddy_after_auth
= !on_list
;
2759 alert
= pidgin_make_mini_dialog_with_custom_icon(
2761 _("Authorize buddy?"), NULL
, aa
,
2762 _("Authorize"), authorize_reason_cb
,
2763 _("Deny"), deny_reason_cb
,
2766 dialog
= PIDGIN_MINI_DIALOG(alert
);
2767 pidgin_mini_dialog_enable_description_markup(dialog
);
2768 pidgin_mini_dialog_set_link_callback(dialog
, G_CALLBACK(get_user_info_cb
), aa
);
2769 pidgin_mini_dialog_set_description(dialog
, buffer
);
2770 pidgin_mini_dialog_add_non_closing_button(dialog
, _("Send Instant Message"), send_im_cb
, aa
);
2772 g_signal_connect_swapped(G_OBJECT(alert
), "destroy", G_CALLBACK(free_auth_request
), aa
);
2773 g_signal_connect(G_OBJECT(alert
), "destroy", G_CALLBACK(purple_account_request_close
), NULL
);
2774 pidgin_blist_add_alert(alert
);
2782 pidgin_accounts_request_close(void *ui_handle
)
2784 gtk_widget_destroy(GTK_WIDGET(ui_handle
));
2787 static PurpleAccountUiOps ui_ops
=
2789 pidgin_accounts_notify_added
,
2791 pidgin_accounts_request_add
,
2792 pidgin_accounts_request_authorization
,
2793 pidgin_accounts_request_close
,
2798 NULL
, NULL
, NULL
, NULL
2801 PurpleAccountUiOps
*
2802 pidgin_accounts_get_ui_ops(void)
2808 pidgin_accounts_get_handle(void) {
2815 pidgin_accounts_init(void)
2817 char *default_avatar
= NULL
;
2818 purple_prefs_add_none(PIDGIN_PREFS_ROOT
"/accounts");
2819 purple_prefs_add_none(PIDGIN_PREFS_ROOT
"/accounts/dialog");
2820 purple_prefs_add_int(PIDGIN_PREFS_ROOT
"/accounts/dialog/width", 520);
2821 purple_prefs_add_int(PIDGIN_PREFS_ROOT
"/accounts/dialog/height", 321);
2822 default_avatar
= g_build_filename(g_get_home_dir(), ".face.icon", NULL
);
2823 if (!g_file_test(default_avatar
, G_FILE_TEST_EXISTS
)) {
2824 g_free(default_avatar
);
2825 default_avatar
= g_build_filename(g_get_home_dir(), ".face", NULL
);
2826 if (!g_file_test(default_avatar
, G_FILE_TEST_EXISTS
)) {
2827 g_free(default_avatar
);
2828 default_avatar
= NULL
;
2832 purple_prefs_add_path(PIDGIN_PREFS_ROOT
"/accounts/buddyicon", default_avatar
);
2833 g_free(default_avatar
);
2835 purple_signal_register(pidgin_accounts_get_handle(), "account-modified",
2836 purple_marshal_VOID__POINTER
, G_TYPE_NONE
, 1,
2837 PURPLE_TYPE_ACCOUNT
);
2839 /* Setup some purple signal handlers. */
2840 purple_signal_connect(purple_connections_get_handle(), "signed-on",
2841 pidgin_accounts_get_handle(),
2842 PURPLE_CALLBACK(signed_on_off_cb
), NULL
);
2843 purple_signal_connect(purple_connections_get_handle(), "signed-off",
2844 pidgin_accounts_get_handle(),
2845 PURPLE_CALLBACK(signed_on_off_cb
), NULL
);
2846 purple_signal_connect(purple_accounts_get_handle(), "account-added",
2847 pidgin_accounts_get_handle(),
2848 PURPLE_CALLBACK(add_account_to_liststore
), NULL
);
2849 purple_signal_connect(purple_accounts_get_handle(), "account-removed",
2850 pidgin_accounts_get_handle(),
2851 PURPLE_CALLBACK(account_removed_cb
), NULL
);
2852 purple_signal_connect(purple_accounts_get_handle(), "account-disabled",
2853 pidgin_accounts_get_handle(),
2854 PURPLE_CALLBACK(account_abled_cb
), GINT_TO_POINTER(FALSE
));
2855 purple_signal_connect(purple_accounts_get_handle(), "account-enabled",
2856 pidgin_accounts_get_handle(),
2857 PURPLE_CALLBACK(account_abled_cb
), GINT_TO_POINTER(TRUE
));
2860 g_hash_table_new_full(g_direct_hash
, g_direct_equal
, NULL
, NULL
);
2864 pidgin_accounts_uninit(void)
2867 * TODO: Need to free all the dialogs in here. Could probably create
2868 * a callback function to use for the free-some-data-function
2869 * parameter of g_hash_table_new_full, above.
2871 g_hash_table_destroy(account_pref_wins
);
2873 purple_signals_disconnect_by_handle(pidgin_accounts_get_handle());
2874 purple_signals_unregister_by_instance(pidgin_accounts_get_handle());