1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
31 #include <glade/glade.h>
32 #include <glib/gi18n.h>
33 #include <dbus/dbus-glib.h>
35 #include <libmissioncontrol/mc-account.h>
36 #include <libmissioncontrol/mc-profile.h>
37 #include <libmissioncontrol/mission-control.h>
38 #include <libmissioncontrol/mc-account-monitor.h>
39 #include <libtelepathy/tp-constants.h>
41 #include <libempathy/empathy-debug.h>
42 #include <libempathy/empathy-utils.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include "empathy-accounts-dialog.h"
46 #include "empathy-profile-chooser.h"
47 #include "empathy-account-widget-generic.h"
48 #include "empathy-account-widget-jabber.h"
49 #include "empathy-account-widget-msn.h"
50 #include "empathy-account-widget-salut.h"
52 #define DEBUG_DOMAIN "AccountDialog"
54 /* Flashing delay for icons (milliseconds). */
55 #define FLASH_TIMEOUT 500
60 GtkWidget
*alignment_settings
;
62 GtkWidget
*vbox_details
;
63 GtkWidget
*frame_no_account
;
64 GtkWidget
*label_no_account
;
65 GtkWidget
*label_no_account_blurb
;
69 GtkWidget
*button_add
;
70 GtkWidget
*button_remove
;
71 GtkWidget
*button_connect
;
73 GtkWidget
*frame_new_account
;
74 GtkWidget
*combobox_profile
;
76 GtkWidget
*button_create
;
77 GtkWidget
*button_back
;
79 GtkWidget
*image_type
;
80 GtkWidget
*label_name
;
81 GtkWidget
*label_type
;
82 GtkWidget
*settings_widget
;
84 gboolean connecting_show
;
86 gboolean account_changed
;
89 McAccountMonitor
*monitor
;
90 } EmpathyAccountsDialog
;
99 static void accounts_dialog_setup (EmpathyAccountsDialog
*dialog
);
100 static void accounts_dialog_update_account (EmpathyAccountsDialog
*dialog
,
102 static void accounts_dialog_model_setup (EmpathyAccountsDialog
*dialog
);
103 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog
*dialog
);
104 static void accounts_dialog_model_select_first (EmpathyAccountsDialog
*dialog
);
105 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn
*tree_column
,
106 GtkCellRenderer
*cell
,
109 EmpathyAccountsDialog
*dialog
);
110 static McAccount
*accounts_dialog_model_get_selected (EmpathyAccountsDialog
*dialog
);
111 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog
*dialog
,
113 static gboolean
accounts_dialog_model_remove_selected (EmpathyAccountsDialog
*dialog
);
114 static void accounts_dialog_model_selection_changed (GtkTreeSelection
*selection
,
115 EmpathyAccountsDialog
*dialog
);
116 static void accounts_dialog_add_account (EmpathyAccountsDialog
*dialog
,
118 static void accounts_dialog_account_added_cb (McAccountMonitor
*monitor
,
120 EmpathyAccountsDialog
*dialog
);
121 static void accounts_dialog_account_removed_cb (McAccountMonitor
*monitor
,
123 EmpathyAccountsDialog
*dialog
);
124 static gboolean
accounts_dialog_row_changed_foreach (GtkTreeModel
*model
,
128 static gboolean
accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog
*dialog
);
129 static void accounts_dialog_status_changed_cb (MissionControl
*mc
,
130 TelepathyConnectionStatus status
,
132 TelepathyConnectionStatusReason reason
,
133 const gchar
*unique_name
,
134 EmpathyAccountsDialog
*dialog
);
135 static void accounts_dialog_button_create_clicked_cb (GtkWidget
*button
,
136 EmpathyAccountsDialog
*dialog
);
137 static void accounts_dialog_button_back_clicked_cb (GtkWidget
*button
,
138 EmpathyAccountsDialog
*dialog
);
139 static void accounts_dialog_button_connect_clicked_cb (GtkWidget
*button
,
140 EmpathyAccountsDialog
*dialog
);
141 static void accounts_dialog_button_add_clicked_cb (GtkWidget
*button
,
142 EmpathyAccountsDialog
*dialog
);
143 static void accounts_dialog_remove_response_cb (GtkWidget
*dialog
,
146 static void accounts_dialog_button_remove_clicked_cb (GtkWidget
*button
,
147 EmpathyAccountsDialog
*dialog
);
148 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView
*tree_view
,
150 GtkTreeViewColumn
*column
,
151 EmpathyAccountsDialog
*dialog
);
152 static void accounts_dialog_response_cb (GtkWidget
*widget
,
154 EmpathyAccountsDialog
*dialog
);
155 static void accounts_dialog_destroy_cb (GtkWidget
*widget
,
156 EmpathyAccountsDialog
*dialog
);
159 accounts_dialog_setup (EmpathyAccountsDialog
*dialog
)
166 view
= GTK_TREE_VIEW (dialog
->treeview
);
167 store
= GTK_LIST_STORE (gtk_tree_view_get_model (view
));
169 accounts
= mc_accounts_list ();
171 for (l
= accounts
; l
; l
= l
->next
) {
174 TelepathyConnectionStatus status
;
178 name
= mc_account_get_display_name (account
);
183 status
= mission_control_get_connection_status (dialog
->mc
, account
, NULL
);
185 gtk_list_store_insert_with_values (store
, &iter
,
189 COL_ACCOUNT_POINTER
, account
,
192 accounts_dialog_status_changed_cb (dialog
->mc
,
195 TP_CONN_STATUS_REASON_NONE_SPECIFIED
,
196 mc_account_get_unique_name (account
),
199 g_object_unref (account
);
202 g_list_free (accounts
);
206 accounts_dialog_update_connect_button (EmpathyAccountsDialog
*dialog
)
210 const gchar
*stock_id
;
213 account
= accounts_dialog_model_get_selected (dialog
);
215 gtk_widget_set_sensitive (dialog
->button_connect
, account
!= NULL
);
217 if (account
&& mc_account_is_enabled (account
)) {
218 label
= _("Disable");
219 stock_id
= GTK_STOCK_DISCONNECT
;
222 stock_id
= GTK_STOCK_CONNECT
;
225 image
= gtk_image_new_from_stock (stock_id
, GTK_ICON_SIZE_BUTTON
);
227 gtk_button_set_label (GTK_BUTTON (dialog
->button_connect
), label
);
228 gtk_button_set_image (GTK_BUTTON (dialog
->button_connect
), image
);
232 accounts_dialog_update_account (EmpathyAccountsDialog
*dialog
,
235 if (dialog
->settings_widget
) {
236 gtk_widget_destroy (dialog
->settings_widget
);
237 dialog
->settings_widget
= NULL
;
246 gtk_widget_show (dialog
->frame_no_account
);
247 gtk_widget_hide (dialog
->vbox_details
);
249 gtk_widget_set_sensitive (dialog
->button_connect
, FALSE
);
250 gtk_widget_set_sensitive (dialog
->button_remove
, FALSE
);
252 view
= GTK_TREE_VIEW (dialog
->treeview
);
253 model
= gtk_tree_view_get_model (view
);
255 if (empathy_profile_chooser_n_profiles (dialog
->combobox_profile
) > 0) {
256 string
= g_string_new (_("To add a new account, you can click on the "
257 "'Add' button and a new entry will be created "
258 "for you to start configuring."));
260 string
= g_string_new (_("To add a new account, you first have to "
261 "install a backend for each protocol "
262 "you want to use."));
265 if (gtk_tree_model_iter_n_children (model
, NULL
) > 0) {
266 gtk_label_set_markup (GTK_LABEL (dialog
->label_no_account
),
267 _("<b>No Account Selected</b>"));
268 g_string_append (string
, _("\n\n"
269 "If you do not want to add an account, simply "
270 "click on the account you want to configure in "
271 "the list on the left."));
273 gtk_label_set_markup (GTK_LABEL (dialog
->label_no_account
),
274 _("<b>No Accounts Configured</b>"));
277 str
= g_string_free (string
, FALSE
);
278 gtk_label_set_markup (GTK_LABEL (dialog
->label_no_account_blurb
),
283 const gchar
*config_ui
;
285 gtk_widget_hide (dialog
->frame_no_account
);
286 gtk_widget_show (dialog
->vbox_details
);
288 profile
= mc_account_get_profile (account
);
289 config_ui
= mc_profile_get_configuration_ui (profile
);
290 g_object_unref (profile
);
292 if (!empathy_strdiff (config_ui
, "jabber")) {
293 dialog
->settings_widget
=
294 empathy_account_widget_jabber_new (account
);
296 else if (!empathy_strdiff (config_ui
, "msn")) {
297 dialog
->settings_widget
=
298 empathy_account_widget_msn_new (account
);
300 else if (!empathy_strdiff (config_ui
, "local-xmpp")) {
301 dialog
->settings_widget
=
302 empathy_account_widget_salut_new (account
);
305 dialog
->settings_widget
=
306 empathy_account_widget_generic_new (account
);
309 gtk_widget_grab_focus (dialog
->settings_widget
);
312 if (dialog
->settings_widget
) {
313 gtk_container_add (GTK_CONTAINER (dialog
->alignment_settings
),
314 dialog
->settings_widget
);
321 profile
= mc_account_get_profile (account
);
322 gtk_image_set_from_icon_name (GTK_IMAGE (dialog
->image_type
),
323 mc_profile_get_icon_name (profile
),
324 GTK_ICON_SIZE_DIALOG
);
325 gtk_widget_set_tooltip_text (dialog
->image_type
,
326 mc_profile_get_display_name (profile
));
328 text
= g_strdup_printf ("<big><b>%s</b></big>", mc_account_get_display_name (account
));
329 gtk_label_set_markup (GTK_LABEL (dialog
->label_name
), text
);
335 accounts_dialog_model_setup (EmpathyAccountsDialog
*dialog
)
338 GtkTreeSelection
*selection
;
340 store
= gtk_list_store_new (COL_COUNT
,
341 G_TYPE_STRING
, /* name */
342 G_TYPE_UINT
, /* status */
343 MC_TYPE_ACCOUNT
); /* account */
345 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog
->treeview
),
346 GTK_TREE_MODEL (store
));
348 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog
->treeview
));
349 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_SINGLE
);
351 g_signal_connect (selection
, "changed",
352 G_CALLBACK (accounts_dialog_model_selection_changed
),
355 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
356 COL_NAME
, GTK_SORT_ASCENDING
);
358 accounts_dialog_model_add_columns (dialog
);
360 g_object_unref (store
);
364 accounts_dialog_name_edited_cb (GtkCellRendererText
*renderer
,
367 EmpathyAccountsDialog
*dialog
)
371 GtkTreePath
*treepath
;
374 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (dialog
->treeview
));
375 treepath
= gtk_tree_path_new_from_string (path
);
376 gtk_tree_model_get_iter (model
, &iter
, treepath
);
377 gtk_tree_model_get (model
, &iter
,
378 COL_ACCOUNT_POINTER
, &account
,
380 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
383 gtk_tree_path_free (treepath
);
385 mc_account_set_display_name (account
, new_text
);
386 g_object_unref (account
);
390 accounts_dialog_model_add_columns (EmpathyAccountsDialog
*dialog
)
393 GtkTreeViewColumn
*column
;
394 GtkCellRenderer
*cell
;
396 view
= GTK_TREE_VIEW (dialog
->treeview
);
397 gtk_tree_view_set_headers_visible (view
, TRUE
);
399 /* account name/status */
400 column
= gtk_tree_view_column_new ();
401 gtk_tree_view_column_set_title (column
, _("Accounts"));
403 cell
= gtk_cell_renderer_pixbuf_new ();
404 gtk_tree_view_column_pack_start (column
, cell
, FALSE
);
405 gtk_tree_view_column_set_cell_data_func (column
, cell
,
406 (GtkTreeCellDataFunc
)
407 accounts_dialog_model_pixbuf_data_func
,
411 cell
= gtk_cell_renderer_text_new ();
413 "ellipsize", PANGO_ELLIPSIZE_END
,
416 gtk_tree_view_column_pack_start (column
, cell
, TRUE
);
417 gtk_tree_view_column_add_attribute (column
,
420 g_signal_connect (cell
, "edited",
421 G_CALLBACK (accounts_dialog_name_edited_cb
),
424 gtk_tree_view_column_set_expand (column
, TRUE
);
425 gtk_tree_view_append_column (view
, column
);
429 accounts_dialog_model_select_first (EmpathyAccountsDialog
*dialog
)
433 GtkTreeSelection
*selection
;
437 view
= GTK_TREE_VIEW (dialog
->treeview
);
438 model
= gtk_tree_view_get_model (view
);
440 if (gtk_tree_model_get_iter_first (model
, &iter
)) {
441 selection
= gtk_tree_view_get_selection (view
);
442 gtk_tree_selection_select_iter (selection
, &iter
);
444 accounts_dialog_update_account (dialog
, NULL
);
449 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn
*tree_column
,
450 GtkCellRenderer
*cell
,
453 EmpathyAccountsDialog
*dialog
)
456 const gchar
*icon_name
;
458 TelepathyConnectionStatus status
;
460 gtk_tree_model_get (model
, iter
,
462 COL_ACCOUNT_POINTER
, &account
,
465 icon_name
= empathy_icon_name_from_account (account
);
466 pixbuf
= empathy_pixbuf_from_icon_name (icon_name
, GTK_ICON_SIZE_BUTTON
);
469 if (status
== TP_CONN_STATUS_DISCONNECTED
||
470 (status
== TP_CONN_STATUS_CONNECTING
&&
471 !dialog
->connecting_show
)) {
472 GdkPixbuf
*modded_pixbuf
;
474 modded_pixbuf
= gdk_pixbuf_new (GDK_COLORSPACE_RGB
,
477 gdk_pixbuf_get_width (pixbuf
),
478 gdk_pixbuf_get_height (pixbuf
));
480 gdk_pixbuf_saturate_and_pixelate (pixbuf
,
484 g_object_unref (pixbuf
);
485 pixbuf
= modded_pixbuf
;
494 g_object_unref (account
);
496 g_object_unref (pixbuf
);
501 accounts_dialog_model_get_selected (EmpathyAccountsDialog
*dialog
)
505 GtkTreeSelection
*selection
;
509 view
= GTK_TREE_VIEW (dialog
->treeview
);
510 selection
= gtk_tree_view_get_selection (view
);
512 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
)) {
516 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT_POINTER
, &account
, -1);
522 accounts_dialog_model_set_selected (EmpathyAccountsDialog
*dialog
,
526 GtkTreeSelection
*selection
;
531 view
= GTK_TREE_VIEW (dialog
->treeview
);
532 model
= gtk_tree_view_get_model (view
);
533 selection
= gtk_tree_view_get_selection (view
);
535 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
537 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
538 McAccount
*this_account
;
541 gtk_tree_model_get (model
, &iter
,
542 COL_ACCOUNT_POINTER
, &this_account
,
545 equal
= empathy_account_equal (this_account
, account
);
546 g_object_unref (this_account
);
549 gtk_tree_selection_select_iter (selection
, &iter
);
556 accounts_dialog_model_remove_selected (EmpathyAccountsDialog
*dialog
)
560 GtkTreeSelection
*selection
;
563 view
= GTK_TREE_VIEW (dialog
->treeview
);
564 selection
= gtk_tree_view_get_selection (view
);
566 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
)) {
570 return gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
574 accounts_dialog_model_selection_changed (GtkTreeSelection
*selection
,
575 EmpathyAccountsDialog
*dialog
)
580 gboolean is_selection
;
582 is_selection
= gtk_tree_selection_get_selected (selection
, &model
, &iter
);
584 gtk_widget_set_sensitive (dialog
->button_add
, TRUE
);
585 gtk_widget_set_sensitive (dialog
->button_remove
, is_selection
);
586 gtk_widget_set_sensitive (dialog
->button_connect
, is_selection
);
588 accounts_dialog_update_connect_button (dialog
);
590 account
= accounts_dialog_model_get_selected (dialog
);
591 accounts_dialog_update_account (dialog
, account
);
594 g_object_unref (account
);
597 /* insure new account frame is hidden when a row is selected*/
598 gtk_widget_hide (dialog
->frame_new_account
);
602 accounts_dialog_add_account (EmpathyAccountsDialog
*dialog
,
605 TelepathyConnectionStatus status
;
613 view
= GTK_TREE_VIEW (dialog
->treeview
);
614 model
= gtk_tree_view_get_model (view
);
615 store
= GTK_LIST_STORE (model
);
617 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
619 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
620 McAccount
*this_account
;
623 gtk_tree_model_get (model
, &iter
,
624 COL_ACCOUNT_POINTER
, &this_account
,
627 equal
= empathy_account_equal (this_account
, account
);
628 g_object_unref (this_account
);
635 status
= mission_control_get_connection_status (dialog
->mc
, account
, NULL
);
636 name
= mc_account_get_display_name (account
);
638 g_return_if_fail (name
!= NULL
);
640 empathy_debug (DEBUG_DOMAIN
, "Adding new account: %s", name
);
642 gtk_list_store_insert_with_values (store
, &iter
,
646 COL_ACCOUNT_POINTER
, account
,
651 accounts_dialog_account_added_cb (McAccountMonitor
*monitor
,
653 EmpathyAccountsDialog
*dialog
)
657 account
= mc_account_lookup (unique_name
);
658 accounts_dialog_add_account (dialog
, account
);
659 g_object_unref (account
);
663 accounts_dialog_account_removed_cb (McAccountMonitor
*monitor
,
665 EmpathyAccountsDialog
*dialog
)
669 account
= mc_account_lookup (unique_name
);
671 accounts_dialog_model_set_selected (dialog
, account
);
672 accounts_dialog_model_remove_selected (dialog
);
674 g_object_unref (account
);
678 accounts_dialog_row_changed_foreach (GtkTreeModel
*model
,
683 gtk_tree_model_row_changed (model
, path
, iter
);
689 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog
*dialog
)
694 dialog
->connecting_show
= !dialog
->connecting_show
;
696 view
= GTK_TREE_VIEW (dialog
->treeview
);
697 model
= gtk_tree_view_get_model (view
);
699 gtk_tree_model_foreach (model
, accounts_dialog_row_changed_foreach
, NULL
);
705 accounts_dialog_status_changed_cb (MissionControl
*mc
,
706 TelepathyConnectionStatus status
,
708 TelepathyConnectionStatusReason reason
,
709 const gchar
*unique_name
,
710 EmpathyAccountsDialog
*dialog
)
713 GtkTreeSelection
*selection
;
719 gboolean found
= FALSE
;
721 /* Update the status in the model */
722 view
= GTK_TREE_VIEW (dialog
->treeview
);
723 selection
= gtk_tree_view_get_selection (view
);
724 model
= gtk_tree_view_get_model (view
);
725 account
= mc_account_lookup (unique_name
);
727 empathy_debug (DEBUG_DOMAIN
, "Status changed for account %s: "
728 "status=%d presence=%d",
729 unique_name
, status
, presence
);
731 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
733 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
734 McAccount
*this_account
;
737 gtk_tree_model_get (model
, &iter
,
738 COL_ACCOUNT_POINTER
, &this_account
,
741 equal
= empathy_account_equal (this_account
, account
);
742 g_object_unref (this_account
);
747 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
751 path
= gtk_tree_model_get_path (model
, &iter
);
752 gtk_tree_model_row_changed (model
, path
, &iter
);
753 gtk_tree_path_free (path
);
758 g_object_unref (account
);
760 /* Check if there is still accounts in CONNECTING state */
761 accounts
= mc_accounts_list ();
762 for (l
= accounts
; l
; l
= l
->next
) {
763 McAccount
*this_account
;
764 TelepathyConnectionStatus status
;
766 this_account
= l
->data
;
768 status
= mission_control_get_connection_status (mc
, this_account
, NULL
);
769 if (status
== TP_CONN_STATUS_CONNECTING
) {
774 g_object_unref (this_account
);
776 g_list_free (accounts
);
778 if (!found
&& dialog
->connecting_id
) {
779 g_source_remove (dialog
->connecting_id
);
780 dialog
->connecting_id
= 0;
782 if (found
&& !dialog
->connecting_id
) {
783 dialog
->connecting_id
= g_timeout_add (FLASH_TIMEOUT
,
784 (GSourceFunc
) accounts_dialog_flash_connecting_cb
,
790 accounts_dialog_button_create_clicked_cb (GtkWidget
*button
,
791 EmpathyAccountsDialog
*dialog
)
798 gtk_widget_show (dialog
->vbox_details
);
799 gtk_widget_hide (dialog
->frame_no_account
);
800 gtk_widget_hide (dialog
->frame_new_account
);
802 profile
= empathy_profile_chooser_get_selected (dialog
->combobox_profile
);
805 account
= mc_account_create (profile
);
807 str
= mc_account_get_unique_name (account
);
808 mc_account_set_display_name (account
, str
);
810 accounts_dialog_add_account (dialog
, account
);
811 accounts_dialog_model_set_selected (dialog
, account
);
813 g_object_unref (account
);
814 g_object_unref (profile
);
818 accounts_dialog_button_back_clicked_cb (GtkWidget
*button
,
819 EmpathyAccountsDialog
*dialog
)
823 gtk_widget_hide (dialog
->vbox_details
);
824 gtk_widget_hide (dialog
->frame_no_account
);
825 gtk_widget_hide (dialog
->frame_new_account
);
827 gtk_widget_set_sensitive (dialog
->button_add
, TRUE
);
829 account
= accounts_dialog_model_get_selected (dialog
);
830 accounts_dialog_update_account (dialog
, account
);
834 accounts_dialog_button_connect_clicked_cb (GtkWidget
*button
,
835 EmpathyAccountsDialog
*dialog
)
840 account
= accounts_dialog_model_get_selected (dialog
);
841 enable
= (!mc_account_is_enabled (account
));
842 mc_account_set_enabled (account
, enable
);
843 accounts_dialog_update_connect_button (dialog
);
845 g_object_unref (account
);
849 accounts_dialog_button_add_clicked_cb (GtkWidget
*button
,
850 EmpathyAccountsDialog
*dialog
)
853 GtkTreeSelection
*selection
;
855 view
= GTK_TREE_VIEW (dialog
->treeview
);
856 selection
= gtk_tree_view_get_selection (view
);
857 gtk_tree_selection_unselect_all (selection
);
859 gtk_widget_set_sensitive (dialog
->button_add
, FALSE
);
860 gtk_widget_hide (dialog
->vbox_details
);
861 gtk_widget_hide (dialog
->frame_no_account
);
862 gtk_widget_show (dialog
->frame_new_account
);
864 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->combobox_profile
), 0);
865 gtk_widget_grab_focus (dialog
->combobox_profile
);
869 accounts_dialog_remove_response_cb (GtkWidget
*dialog
,
873 if (response
== GTK_RESPONSE_YES
) {
874 mc_account_delete (account
);
877 gtk_widget_destroy (dialog
);
881 accounts_dialog_button_remove_clicked_cb (GtkWidget
*button
,
882 EmpathyAccountsDialog
*dialog
)
885 GtkWidget
*message_dialog
;
887 account
= accounts_dialog_model_get_selected (dialog
);
889 if (!mc_account_is_complete (account
)) {
890 accounts_dialog_model_remove_selected (dialog
);
893 message_dialog
= gtk_message_dialog_new
894 (GTK_WINDOW (dialog
->window
),
895 GTK_DIALOG_DESTROY_WITH_PARENT
,
896 GTK_MESSAGE_QUESTION
,
898 _("You are about to remove your %s account!\n"
899 "Are you sure you want to proceed?"),
900 mc_account_get_display_name (account
));
902 gtk_message_dialog_format_secondary_text
903 (GTK_MESSAGE_DIALOG (message_dialog
),
904 _("Any associated conversations and chat rooms will NOT be "
905 "removed if you decide to proceed.\n"
907 "Should you decide to add the account back at a later time, "
908 "they will still be available."));
910 gtk_dialog_add_button (GTK_DIALOG (message_dialog
),
913 gtk_dialog_add_button (GTK_DIALOG (message_dialog
),
917 g_signal_connect (message_dialog
, "response",
918 G_CALLBACK (accounts_dialog_remove_response_cb
),
921 gtk_widget_show (message_dialog
);
925 accounts_dialog_treeview_row_activated_cb (GtkTreeView
*tree_view
,
927 GtkTreeViewColumn
*column
,
928 EmpathyAccountsDialog
*dialog
)
931 accounts_dialog_button_connect_clicked_cb (dialog
->button_connect
,
936 accounts_dialog_response_cb (GtkWidget
*widget
,
938 EmpathyAccountsDialog
*dialog
)
940 gtk_widget_destroy (widget
);
944 accounts_dialog_destroy_cb (GtkWidget
*widget
,
945 EmpathyAccountsDialog
*dialog
)
949 /* Disconnect signals */
950 g_signal_handlers_disconnect_by_func (dialog
->monitor
,
951 accounts_dialog_account_added_cb
,
953 g_signal_handlers_disconnect_by_func (dialog
->monitor
,
954 accounts_dialog_account_removed_cb
,
956 g_signal_handlers_disconnect_by_func (dialog
->monitor
,
957 accounts_dialog_update_connect_button
,
959 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog
->mc
),
960 "AccountStatusChanged",
961 G_CALLBACK (accounts_dialog_status_changed_cb
),
964 /* Delete incomplete accounts */
965 accounts
= mc_accounts_list ();
966 for (l
= accounts
; l
; l
= l
->next
) {
970 if (!mc_account_is_complete (account
)) {
971 /* FIXME: Warn the user the account is not complete
972 * and is going to be removed. */
973 mc_account_delete (account
);
976 g_object_unref (account
);
978 g_list_free (accounts
);
980 if (dialog
->connecting_id
) {
981 g_source_remove (dialog
->connecting_id
);
984 g_object_unref (dialog
->mc
);
985 g_object_unref (dialog
->monitor
);
991 empathy_accounts_dialog_show (GtkWindow
*parent
)
993 static EmpathyAccountsDialog
*dialog
= NULL
;
996 GtkWidget
*button_close
;
999 gtk_window_present (GTK_WINDOW (dialog
->window
));
1000 return dialog
->window
;
1003 dialog
= g_new0 (EmpathyAccountsDialog
, 1);
1005 glade
= empathy_glade_get_file ("empathy-accounts-dialog.glade",
1008 "accounts_dialog", &dialog
->window
,
1009 "vbox_details", &dialog
->vbox_details
,
1010 "frame_no_account", &dialog
->frame_no_account
,
1011 "label_no_account", &dialog
->label_no_account
,
1012 "label_no_account_blurb", &dialog
->label_no_account_blurb
,
1013 "alignment_settings", &dialog
->alignment_settings
,
1014 "dialog-action_area", &bbox
,
1015 "treeview", &dialog
->treeview
,
1016 "frame_new_account", &dialog
->frame_new_account
,
1017 "hbox_type", &dialog
->hbox_type
,
1018 "button_create", &dialog
->button_create
,
1019 "button_back", &dialog
->button_back
,
1020 "image_type", &dialog
->image_type
,
1021 "label_name", &dialog
->label_name
,
1022 "button_add", &dialog
->button_add
,
1023 "button_remove", &dialog
->button_remove
,
1024 "button_connect", &dialog
->button_connect
,
1025 "button_close", &button_close
,
1028 empathy_glade_connect (glade
,
1030 "accounts_dialog", "destroy", accounts_dialog_destroy_cb
,
1031 "accounts_dialog", "response", accounts_dialog_response_cb
,
1032 "button_create", "clicked", accounts_dialog_button_create_clicked_cb
,
1033 "button_back", "clicked", accounts_dialog_button_back_clicked_cb
,
1034 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb
,
1035 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb
,
1036 "button_add", "clicked", accounts_dialog_button_add_clicked_cb
,
1037 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb
,
1040 g_object_add_weak_pointer (G_OBJECT (dialog
->window
), (gpointer
) &dialog
);
1042 g_object_unref (glade
);
1044 /* Create profile chooser */
1045 dialog
->combobox_profile
= empathy_profile_chooser_new ();
1046 gtk_box_pack_end (GTK_BOX (dialog
->hbox_type
),
1047 dialog
->combobox_profile
,
1049 gtk_widget_show (dialog
->combobox_profile
);
1050 if (empathy_profile_chooser_n_profiles (dialog
->combobox_profile
) <= 0) {
1051 gtk_widget_set_sensitive (dialog
->button_add
, FALSE
);
1054 /* Set up signalling */
1055 dialog
->mc
= empathy_mission_control_new ();
1056 dialog
->monitor
= mc_account_monitor_new ();
1058 g_signal_connect (dialog
->monitor
, "account-created",
1059 G_CALLBACK (accounts_dialog_account_added_cb
),
1061 g_signal_connect (dialog
->monitor
, "account-deleted",
1062 G_CALLBACK (accounts_dialog_account_removed_cb
),
1064 g_signal_connect_swapped (dialog
->monitor
, "account-enabled",
1065 G_CALLBACK (accounts_dialog_update_connect_button
),
1067 g_signal_connect_swapped (dialog
->monitor
, "account-disabled",
1068 G_CALLBACK (accounts_dialog_update_connect_button
),
1070 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog
->mc
), "AccountStatusChanged",
1071 G_CALLBACK (accounts_dialog_status_changed_cb
),
1074 accounts_dialog_model_setup (dialog
);
1075 accounts_dialog_setup (dialog
);
1076 accounts_dialog_model_select_first (dialog
);
1079 gtk_window_set_transient_for (GTK_WINDOW (dialog
->window
),
1080 GTK_WINDOW (parent
));
1083 gtk_widget_show (dialog
->window
);
1085 return dialog
->window
;