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-2008 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 <telepathy-glib/util.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy-gtk/empathy-ui-utils.h>
43 #include <libempathy-gtk/empathy-profile-chooser.h>
44 #include <libempathy-gtk/empathy-account-widget.h>
45 #include <libempathy-gtk/empathy-account-widget-irc.h>
46 #include <libempathy-gtk/empathy-account-widget-sip.h>
48 #include "empathy-accounts-dialog.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
51 #include <libempathy/empathy-debug.h>
53 /* Flashing delay for icons (milliseconds). */
54 #define FLASH_TIMEOUT 500
59 GtkWidget *alignment_settings;
61 GtkWidget *vbox_details;
62 GtkWidget *frame_no_account;
63 GtkWidget *label_no_account;
64 GtkWidget *label_no_account_blurb;
68 GtkWidget *button_add;
69 GtkWidget *button_remove;
71 GtkWidget *frame_new_account;
72 GtkWidget *combobox_profile;
74 GtkWidget *button_create;
75 GtkWidget *button_back;
77 GtkWidget *image_type;
78 GtkWidget *label_name;
79 GtkWidget *label_type;
80 GtkWidget *settings_widget;
82 gboolean connecting_show;
84 gboolean account_changed;
87 McAccountMonitor *monitor;
89 } 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 TpConnectionStatus status,
132 TpConnectionStatusReason 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_add_clicked_cb (GtkWidget *button,
140 EmpathyAccountsDialog *dialog);
141 static void accounts_dialog_button_help_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_response_cb (GtkWidget *widget,
150 EmpathyAccountsDialog *dialog);
151 static void accounts_dialog_destroy_cb (GtkWidget *widget,
152 EmpathyAccountsDialog *dialog);
155 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
162 view = GTK_TREE_VIEW (dialog->treeview);
163 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
165 accounts = mc_accounts_list ();
167 for (l = accounts; l; l = l->next) {
170 TpConnectionStatus status;
175 name = mc_account_get_display_name (account);
177 g_object_unref (account);
181 status = mission_control_get_connection_status (dialog->mc, account, NULL);
182 enabled = mc_account_is_enabled (account);
184 gtk_list_store_insert_with_values (store, &iter,
186 COL_ENABLED, enabled,
189 COL_ACCOUNT_POINTER, account,
192 accounts_dialog_status_changed_cb (dialog->mc,
195 TP_CONNECTION_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_account (EmpathyAccountsDialog *dialog,
209 if (dialog->settings_widget) {
210 gtk_widget_destroy (dialog->settings_widget);
211 dialog->settings_widget = NULL;
220 gtk_widget_show (dialog->frame_no_account);
221 gtk_widget_hide (dialog->vbox_details);
223 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
225 view = GTK_TREE_VIEW (dialog->treeview);
226 model = gtk_tree_view_get_model (view);
228 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
229 string = g_string_new (_("To add a new account, you can click on the "
230 "'Add' button and a new entry will be created "
231 "for you to start configuring."));
233 string = g_string_new (_("To add a new account, you first have to "
234 "install a backend for each protocol "
235 "you want to use."));
238 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
239 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
240 _("<b>No Account Selected</b>"));
241 g_string_append (string, _("\n\n"
242 "If you do not want to add an account, simply "
243 "click on the account you want to configure in "
244 "the list on the left."));
246 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
247 _("<b>No Accounts Configured</b>"));
250 str = g_string_free (string, FALSE);
251 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
256 const gchar *config_ui;
258 gtk_widget_hide (dialog->frame_no_account);
259 gtk_widget_show (dialog->vbox_details);
261 profile = mc_account_get_profile (account);
262 config_ui = mc_profile_get_configuration_ui (profile);
263 g_object_unref (profile);
265 if (!tp_strdiff (config_ui, "jabber")) {
266 dialog->settings_widget =
267 empathy_account_widget_jabber_new (account);
269 else if (!tp_strdiff (config_ui, "msn")) {
270 dialog ->settings_widget =
271 empathy_account_widget_msn_new (account);
273 else if (!tp_strdiff (config_ui, "local-xmpp")) {
274 dialog->settings_widget =
275 empathy_account_widget_salut_new (account);
277 else if (!tp_strdiff (config_ui, "irc")) {
278 dialog->settings_widget =
279 empathy_account_widget_irc_new (account);
281 else if (!tp_strdiff(config_ui, "icq")) {
282 dialog->settings_widget =
283 empathy_account_widget_icq_new (account);
285 else if (!tp_strdiff(config_ui, "aim")) {
286 dialog->settings_widget =
287 empathy_account_widget_aim_new (account);
289 else if (!tp_strdiff (config_ui, "yahoo")) {
290 dialog->settings_widget =
291 empathy_account_widget_yahoo_new (account);
293 else if (!tp_strdiff (config_ui, "sofiasip")) {
294 dialog->settings_widget =
295 empathy_account_widget_sip_new (account);
297 else if (!tp_strdiff (config_ui, "groupwise")) {
298 dialog->settings_widget =
299 empathy_account_widget_groupwise_new (account);
302 dialog->settings_widget =
303 empathy_account_widget_generic_new (account);
307 if (dialog->settings_widget) {
308 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
309 dialog->settings_widget);
316 profile = mc_account_get_profile (account);
317 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
318 mc_profile_get_icon_name (profile),
319 GTK_ICON_SIZE_DIALOG);
320 gtk_widget_set_tooltip_text (dialog->image_type,
321 mc_profile_get_display_name (profile));
323 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
324 mc_account_get_display_name (account));
325 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
331 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
334 GtkTreeSelection *selection;
336 store = gtk_list_store_new (COL_COUNT,
337 G_TYPE_BOOLEAN, /* enabled */
338 G_TYPE_STRING, /* name */
339 G_TYPE_UINT, /* status */
340 MC_TYPE_ACCOUNT); /* account */
342 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
343 GTK_TREE_MODEL (store));
345 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
346 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
348 g_signal_connect (selection, "changed",
349 G_CALLBACK (accounts_dialog_model_selection_changed),
352 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
353 COL_NAME, GTK_SORT_ASCENDING);
355 accounts_dialog_model_add_columns (dialog);
357 g_object_unref (store);
361 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
364 EmpathyAccountsDialog *dialog)
368 GtkTreePath *treepath;
371 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
372 treepath = gtk_tree_path_new_from_string (path);
373 gtk_tree_model_get_iter (model, &iter, treepath);
374 gtk_tree_model_get (model, &iter,
375 COL_ACCOUNT_POINTER, &account,
377 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
380 gtk_tree_path_free (treepath);
382 mc_account_set_display_name (account, new_text);
383 g_object_unref (account);
387 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
389 EmpathyAccountsDialog *dialog)
393 GtkTreePath *treepath;
397 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
398 treepath = gtk_tree_path_new_from_string (path);
399 gtk_tree_model_get_iter (model, &iter, treepath);
400 gtk_tree_model_get (model, &iter,
401 COL_ACCOUNT_POINTER, &account,
403 gtk_tree_path_free (treepath);
405 enabled = mc_account_is_enabled (account);
406 mc_account_set_enabled (account, !enabled);
408 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
409 mc_account_get_display_name(account));
411 g_object_unref (account);
415 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
418 GtkTreeViewColumn *column;
419 GtkCellRenderer *cell;
421 view = GTK_TREE_VIEW (dialog->treeview);
422 gtk_tree_view_set_headers_visible (view, TRUE);
425 cell = gtk_cell_renderer_toggle_new ();
426 gtk_tree_view_insert_column_with_attributes (view, -1,
429 "active", COL_ENABLED,
431 g_signal_connect (cell, "toggled",
432 G_CALLBACK (accounts_dialog_enable_toggled_cb),
436 column = gtk_tree_view_column_new ();
437 gtk_tree_view_column_set_title (column, _("Accounts"));
438 gtk_tree_view_column_set_expand (column, TRUE);
439 gtk_tree_view_append_column (view, column);
442 cell = gtk_cell_renderer_pixbuf_new ();
443 gtk_tree_view_column_pack_start (column, cell, FALSE);
444 gtk_tree_view_column_set_cell_data_func (column, cell,
445 (GtkTreeCellDataFunc)
446 accounts_dialog_model_pixbuf_data_func,
451 cell = gtk_cell_renderer_text_new ();
453 "ellipsize", PANGO_ELLIPSIZE_END,
456 gtk_tree_view_column_pack_start (column, cell, TRUE);
457 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
458 g_signal_connect (cell, "edited",
459 G_CALLBACK (accounts_dialog_name_edited_cb),
464 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
468 GtkTreeSelection *selection;
472 view = GTK_TREE_VIEW (dialog->treeview);
473 model = gtk_tree_view_get_model (view);
475 if (gtk_tree_model_get_iter_first (model, &iter)) {
476 selection = gtk_tree_view_get_selection (view);
477 gtk_tree_selection_select_iter (selection, &iter);
479 accounts_dialog_update_account (dialog, NULL);
484 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
485 GtkCellRenderer *cell,
488 EmpathyAccountsDialog *dialog)
491 const gchar *icon_name;
493 TpConnectionStatus status;
495 gtk_tree_model_get (model, iter,
497 COL_ACCOUNT_POINTER, &account,
500 icon_name = empathy_icon_name_from_account (account);
501 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
504 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
505 (status == TP_CONNECTION_STATUS_CONNECTING &&
506 !dialog->connecting_show)) {
507 GdkPixbuf *modded_pixbuf;
509 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
512 gdk_pixbuf_get_width (pixbuf),
513 gdk_pixbuf_get_height (pixbuf));
515 gdk_pixbuf_saturate_and_pixelate (pixbuf,
519 g_object_unref (pixbuf);
520 pixbuf = modded_pixbuf;
529 g_object_unref (account);
531 g_object_unref (pixbuf);
536 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
541 GtkTreeSelection *selection;
545 /* Update the status in the model */
546 view = GTK_TREE_VIEW (dialog->treeview);
547 selection = gtk_tree_view_get_selection (view);
548 model = gtk_tree_view_get_model (view);
550 for (ok = gtk_tree_model_get_iter_first (model, iter);
552 ok = gtk_tree_model_iter_next (model, iter)) {
553 McAccount *this_account;
556 gtk_tree_model_get (model, iter,
557 COL_ACCOUNT_POINTER, &this_account,
560 equal = empathy_account_equal (this_account, account);
561 g_object_unref (this_account);
572 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
576 GtkTreeSelection *selection;
580 view = GTK_TREE_VIEW (dialog->treeview);
581 selection = gtk_tree_view_get_selection (view);
583 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
587 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
593 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
596 GtkTreeSelection *selection;
599 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
600 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
601 gtk_tree_selection_select_iter (selection, &iter);
606 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
610 GtkTreeSelection *selection;
613 view = GTK_TREE_VIEW (dialog->treeview);
614 selection = gtk_tree_view_get_selection (view);
616 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
620 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
624 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
625 EmpathyAccountsDialog *dialog)
630 gboolean is_selection;
632 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
634 gtk_widget_set_sensitive (dialog->button_add, TRUE);
635 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
637 account = accounts_dialog_model_get_selected (dialog);
638 accounts_dialog_update_account (dialog, account);
641 g_object_unref (account);
644 /* insure new account frame is hidden when a row is selected*/
645 gtk_widget_hide (dialog->frame_new_account);
649 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
654 TpConnectionStatus status;
658 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
662 status = mission_control_get_connection_status (dialog->mc, account, NULL);
663 name = mc_account_get_display_name (account);
664 enabled = mc_account_is_enabled (account);
666 g_return_if_fail (name != NULL);
668 DEBUG ("Adding new account: %s", name);
670 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
671 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter,
673 COL_ENABLED, enabled,
676 COL_ACCOUNT_POINTER, account,
681 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
683 EmpathyAccountsDialog *dialog)
687 account = mc_account_lookup (unique_name);
688 accounts_dialog_add_account (dialog, account);
689 g_object_unref (account);
693 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
695 EmpathyAccountsDialog *dialog)
699 account = mc_account_lookup (unique_name);
701 accounts_dialog_model_set_selected (dialog, account);
702 accounts_dialog_model_remove_selected (dialog);
704 g_object_unref (account);
708 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
713 gtk_tree_model_row_changed (model, path, iter);
719 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
724 dialog->connecting_show = !dialog->connecting_show;
726 view = GTK_TREE_VIEW (dialog->treeview);
727 model = gtk_tree_view_get_model (view);
729 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
735 accounts_dialog_status_changed_cb (MissionControl *mc,
736 TpConnectionStatus status,
738 TpConnectionStatusReason reason,
739 const gchar *unique_name,
740 EmpathyAccountsDialog *dialog)
746 gboolean found = FALSE;
748 /* Update the status in the model */
749 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
750 account = mc_account_lookup (unique_name);
752 DEBUG ("Status changed for account %s: status=%d presence=%d",
753 unique_name, status, presence);
755 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
758 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
762 path = gtk_tree_model_get_path (model, &iter);
763 gtk_tree_model_row_changed (model, path, &iter);
764 gtk_tree_path_free (path);
766 g_object_unref (account);
768 /* Check if there is still accounts in CONNECTING state */
769 accounts = mc_accounts_list_by_enabled (TRUE);
770 for (l = accounts; l; l = l->next) {
771 McAccount *this_account = l->data;
772 TpConnectionStatus status;
775 g_object_unref (this_account);
779 status = mission_control_get_connection_status (mc, this_account, NULL);
780 if (status == TP_CONNECTION_STATUS_CONNECTING) {
784 g_object_unref (this_account);
786 g_list_free (accounts);
788 if (!found && dialog->connecting_id) {
789 g_source_remove (dialog->connecting_id);
790 dialog->connecting_id = 0;
792 if (found && !dialog->connecting_id) {
793 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
794 (GSourceFunc) accounts_dialog_flash_connecting_cb,
800 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
802 EmpathyAccountsDialog *dialog)
809 /* Update the status in the model */
810 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
811 account = mc_account_lookup (unique_name);
812 enabled = mc_account_is_enabled (account);
814 DEBUG ("Account %s is now %s",
815 mc_account_get_display_name (account),
816 enabled ? "enabled" : "disabled");
818 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
819 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
820 COL_ENABLED, enabled,
824 g_object_unref (account);
828 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
829 EmpathyAccountsDialog *dialog)
836 gtk_widget_show (dialog->vbox_details);
837 gtk_widget_hide (dialog->frame_no_account);
838 gtk_widget_hide (dialog->frame_new_account);
840 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
843 account = mc_account_create (profile);
845 str = mc_account_get_unique_name (account);
846 mc_account_set_display_name (account, str);
848 accounts_dialog_add_account (dialog, account);
849 accounts_dialog_model_set_selected (dialog, account);
851 g_object_unref (account);
852 g_object_unref (profile);
856 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
857 EmpathyAccountsDialog *dialog)
861 gtk_widget_hide (dialog->vbox_details);
862 gtk_widget_hide (dialog->frame_no_account);
863 gtk_widget_hide (dialog->frame_new_account);
865 gtk_widget_set_sensitive (dialog->button_add, TRUE);
867 account = accounts_dialog_model_get_selected (dialog);
868 accounts_dialog_update_account (dialog, account);
872 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
873 EmpathyAccountsDialog *dialog)
876 GtkTreeSelection *selection;
878 view = GTK_TREE_VIEW (dialog->treeview);
879 selection = gtk_tree_view_get_selection (view);
880 gtk_tree_selection_unselect_all (selection);
882 gtk_widget_set_sensitive (dialog->button_add, FALSE);
883 gtk_widget_hide (dialog->vbox_details);
884 gtk_widget_hide (dialog->frame_no_account);
885 gtk_widget_show (dialog->frame_new_account);
887 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
888 gtk_widget_grab_focus (dialog->combobox_profile);
892 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
893 EmpathyAccountsDialog *dialog)
895 empathy_url_show ("ghelp:empathy?empathy-create-account");
899 accounts_dialog_remove_response_cb (GtkWidget *dialog,
903 if (response == GTK_RESPONSE_YES) {
904 mc_account_delete (account);
907 gtk_widget_destroy (dialog);
911 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
912 EmpathyAccountsDialog *dialog)
915 GtkWidget *message_dialog;
917 account = accounts_dialog_model_get_selected (dialog);
919 if (!mc_account_is_complete (account)) {
920 accounts_dialog_model_remove_selected (dialog);
923 message_dialog = gtk_message_dialog_new
924 (GTK_WINDOW (dialog->window),
925 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
926 GTK_MESSAGE_QUESTION,
928 _("You are about to remove your %s account!\n"
929 "Are you sure you want to proceed?"),
930 mc_account_get_display_name (account));
932 gtk_message_dialog_format_secondary_text
933 (GTK_MESSAGE_DIALOG (message_dialog),
934 _("Any associated conversations and chat rooms will NOT be "
935 "removed if you decide to proceed.\n"
937 "Should you decide to add the account back at a later time, "
938 "they will still be available."));
940 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
943 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
947 g_signal_connect (message_dialog, "response",
948 G_CALLBACK (accounts_dialog_remove_response_cb),
951 gtk_widget_show (message_dialog);
955 accounts_dialog_response_cb (GtkWidget *widget,
957 EmpathyAccountsDialog *dialog)
959 if (response == GTK_RESPONSE_CLOSE) {
960 gtk_widget_destroy (widget);
965 accounts_dialog_destroy_cb (GtkWidget *widget,
966 EmpathyAccountsDialog *dialog)
970 /* Disconnect signals */
971 g_signal_handlers_disconnect_by_func (dialog->monitor,
972 accounts_dialog_account_added_cb,
974 g_signal_handlers_disconnect_by_func (dialog->monitor,
975 accounts_dialog_account_removed_cb,
977 g_signal_handlers_disconnect_by_func (dialog->monitor,
978 accounts_dialog_account_enabled_cb,
980 empathy_disconnect_account_status_changed (dialog->token);
982 /* Delete incomplete accounts */
983 accounts = mc_accounts_list ();
984 for (l = accounts; l; l = l->next) {
988 if (!mc_account_is_complete (account)) {
989 /* FIXME: Warn the user the account is not complete
990 * and is going to be removed. */
991 mc_account_delete (account);
994 g_object_unref (account);
996 g_list_free (accounts);
998 if (dialog->connecting_id) {
999 g_source_remove (dialog->connecting_id);
1002 g_object_unref (dialog->mc);
1003 g_object_unref (dialog->monitor);
1009 empathy_accounts_dialog_show (GtkWindow *parent,
1010 McAccount *selected_account)
1012 static EmpathyAccountsDialog *dialog = NULL;
1017 gtk_window_present (GTK_WINDOW (dialog->window));
1018 return dialog->window;
1021 dialog = g_new0 (EmpathyAccountsDialog, 1);
1023 filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
1025 glade = empathy_glade_get_file (filename,
1028 "accounts_dialog", &dialog->window,
1029 "vbox_details", &dialog->vbox_details,
1030 "frame_no_account", &dialog->frame_no_account,
1031 "label_no_account", &dialog->label_no_account,
1032 "label_no_account_blurb", &dialog->label_no_account_blurb,
1033 "alignment_settings", &dialog->alignment_settings,
1034 "treeview", &dialog->treeview,
1035 "frame_new_account", &dialog->frame_new_account,
1036 "hbox_type", &dialog->hbox_type,
1037 "button_create", &dialog->button_create,
1038 "button_back", &dialog->button_back,
1039 "image_type", &dialog->image_type,
1040 "label_name", &dialog->label_name,
1041 "button_add", &dialog->button_add,
1042 "button_remove", &dialog->button_remove,
1046 empathy_glade_connect (glade,
1048 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1049 "accounts_dialog", "response", accounts_dialog_response_cb,
1050 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1051 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1052 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1053 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1054 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1057 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1059 g_object_unref (glade);
1061 /* Create profile chooser */
1062 dialog->combobox_profile = empathy_profile_chooser_new ();
1063 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1064 dialog->combobox_profile,
1066 gtk_widget_show (dialog->combobox_profile);
1067 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) <= 0) {
1068 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1071 /* Set up signalling */
1072 dialog->mc = empathy_mission_control_new ();
1073 dialog->monitor = mc_account_monitor_new ();
1075 g_signal_connect (dialog->monitor, "account-created",
1076 G_CALLBACK (accounts_dialog_account_added_cb),
1078 g_signal_connect (dialog->monitor, "account-deleted",
1079 G_CALLBACK (accounts_dialog_account_removed_cb),
1081 g_signal_connect (dialog->monitor, "account-enabled",
1082 G_CALLBACK (accounts_dialog_account_enabled_cb),
1084 g_signal_connect (dialog->monitor, "account-disabled",
1085 G_CALLBACK (accounts_dialog_account_enabled_cb),
1087 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1088 G_CALLBACK (accounts_dialog_status_changed_cb),
1091 accounts_dialog_model_setup (dialog);
1092 accounts_dialog_setup (dialog);
1094 if (selected_account) {
1095 accounts_dialog_model_set_selected (dialog, selected_account);
1097 accounts_dialog_model_select_first (dialog);
1101 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1102 GTK_WINDOW (parent));
1105 gtk_widget_show (dialog->window);
1107 return dialog->window;