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>
44 #include "empathy-accounts-dialog.h"
45 #include "empathy-profile-chooser.h"
46 #include "empathy-account-widget.h"
47 #include "empathy-account-widget-irc.h"
48 #include "empathy-account-widget-sip.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_remove_response_cb (GtkWidget *dialog,
144 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
145 EmpathyAccountsDialog *dialog);
146 static void accounts_dialog_response_cb (GtkWidget *widget,
148 EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_destroy_cb (GtkWidget *widget,
150 EmpathyAccountsDialog *dialog);
153 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
160 view = GTK_TREE_VIEW (dialog->treeview);
161 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
163 accounts = mc_accounts_list ();
165 for (l = accounts; l; l = l->next) {
168 TpConnectionStatus status;
173 name = mc_account_get_display_name (account);
178 status = mission_control_get_connection_status (dialog->mc, account, NULL);
179 enabled = mc_account_is_enabled (account);
181 gtk_list_store_insert_with_values (store, &iter,
183 COL_ENABLED, enabled,
186 COL_ACCOUNT_POINTER, account,
189 accounts_dialog_status_changed_cb (dialog->mc,
192 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
193 mc_account_get_unique_name (account),
196 g_object_unref (account);
199 g_list_free (accounts);
203 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
206 if (dialog->settings_widget) {
207 gtk_widget_destroy (dialog->settings_widget);
208 dialog->settings_widget = NULL;
217 gtk_widget_show (dialog->frame_no_account);
218 gtk_widget_hide (dialog->vbox_details);
220 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
222 view = GTK_TREE_VIEW (dialog->treeview);
223 model = gtk_tree_view_get_model (view);
225 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
226 string = g_string_new (_("To add a new account, you can click on the "
227 "'Add' button and a new entry will be created "
228 "for you to start configuring."));
230 string = g_string_new (_("To add a new account, you first have to "
231 "install a backend for each protocol "
232 "you want to use."));
235 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
236 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
237 _("<b>No Account Selected</b>"));
238 g_string_append (string, _("\n\n"
239 "If you do not want to add an account, simply "
240 "click on the account you want to configure in "
241 "the list on the left."));
243 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
244 _("<b>No Accounts Configured</b>"));
247 str = g_string_free (string, FALSE);
248 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
253 const gchar *config_ui;
255 gtk_widget_hide (dialog->frame_no_account);
256 gtk_widget_show (dialog->vbox_details);
258 profile = mc_account_get_profile (account);
259 config_ui = mc_profile_get_configuration_ui (profile);
260 g_object_unref (profile);
262 if (!tp_strdiff (config_ui, "jabber")) {
263 dialog->settings_widget =
264 empathy_account_widget_jabber_new (account);
266 else if (!tp_strdiff (config_ui, "msn")) {
267 dialog ->settings_widget =
268 empathy_account_widget_msn_new (account);
270 else if (!tp_strdiff (config_ui, "local-xmpp")) {
271 dialog->settings_widget =
272 empathy_account_widget_salut_new (account);
274 else if (!tp_strdiff (config_ui, "irc")) {
275 dialog->settings_widget =
276 empathy_account_widget_irc_new (account);
278 else if (!tp_strdiff(config_ui, "icq")) {
279 dialog->settings_widget =
280 empathy_account_widget_icq_new (account);
282 else if (!tp_strdiff(config_ui, "aim")) {
283 dialog->settings_widget =
284 empathy_account_widget_aim_new (account);
286 else if (!tp_strdiff (config_ui, "yahoo")) {
287 dialog->settings_widget =
288 empathy_account_widget_yahoo_new (account);
290 else if (!tp_strdiff (config_ui, "sofiasip")) {
291 dialog->settings_widget =
292 empathy_account_widget_sip_new (account);
294 else if (!tp_strdiff (config_ui, "groupwise")) {
295 dialog->settings_widget =
296 empathy_account_widget_groupwise_new (account);
299 dialog->settings_widget =
300 empathy_account_widget_generic_new (account);
304 if (dialog->settings_widget) {
305 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
306 dialog->settings_widget);
313 profile = mc_account_get_profile (account);
314 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
315 mc_profile_get_icon_name (profile),
316 GTK_ICON_SIZE_DIALOG);
317 gtk_widget_set_tooltip_text (dialog->image_type,
318 mc_profile_get_display_name (profile));
320 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
321 mc_account_get_display_name (account));
322 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
328 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
331 GtkTreeSelection *selection;
333 store = gtk_list_store_new (COL_COUNT,
334 G_TYPE_BOOLEAN, /* enabled */
335 G_TYPE_STRING, /* name */
336 G_TYPE_UINT, /* status */
337 MC_TYPE_ACCOUNT); /* account */
339 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
340 GTK_TREE_MODEL (store));
342 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
343 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
345 g_signal_connect (selection, "changed",
346 G_CALLBACK (accounts_dialog_model_selection_changed),
349 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
350 COL_NAME, GTK_SORT_ASCENDING);
352 accounts_dialog_model_add_columns (dialog);
354 g_object_unref (store);
358 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
361 EmpathyAccountsDialog *dialog)
365 GtkTreePath *treepath;
368 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
369 treepath = gtk_tree_path_new_from_string (path);
370 gtk_tree_model_get_iter (model, &iter, treepath);
371 gtk_tree_model_get (model, &iter,
372 COL_ACCOUNT_POINTER, &account,
374 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
377 gtk_tree_path_free (treepath);
379 mc_account_set_display_name (account, new_text);
380 g_object_unref (account);
384 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
386 EmpathyAccountsDialog *dialog)
390 GtkTreePath *treepath;
394 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
395 treepath = gtk_tree_path_new_from_string (path);
396 gtk_tree_model_get_iter (model, &iter, treepath);
397 gtk_tree_model_get (model, &iter,
398 COL_ACCOUNT_POINTER, &account,
400 gtk_tree_path_free (treepath);
402 enabled = mc_account_is_enabled (account);
403 mc_account_set_enabled (account, !enabled);
405 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
406 mc_account_get_display_name(account));
408 g_object_unref (account);
412 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
415 GtkTreeViewColumn *column;
416 GtkCellRenderer *cell;
418 view = GTK_TREE_VIEW (dialog->treeview);
419 gtk_tree_view_set_headers_visible (view, TRUE);
422 cell = gtk_cell_renderer_toggle_new ();
423 gtk_tree_view_insert_column_with_attributes (view, -1,
426 "active", COL_ENABLED,
428 g_signal_connect (cell, "toggled",
429 G_CALLBACK (accounts_dialog_enable_toggled_cb),
433 column = gtk_tree_view_column_new ();
434 gtk_tree_view_column_set_title (column, _("Accounts"));
435 gtk_tree_view_column_set_expand (column, TRUE);
436 gtk_tree_view_append_column (view, column);
439 cell = gtk_cell_renderer_pixbuf_new ();
440 gtk_tree_view_column_pack_start (column, cell, FALSE);
441 gtk_tree_view_column_set_cell_data_func (column, cell,
442 (GtkTreeCellDataFunc)
443 accounts_dialog_model_pixbuf_data_func,
448 cell = gtk_cell_renderer_text_new ();
450 "ellipsize", PANGO_ELLIPSIZE_END,
453 gtk_tree_view_column_pack_start (column, cell, TRUE);
454 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
455 g_signal_connect (cell, "edited",
456 G_CALLBACK (accounts_dialog_name_edited_cb),
461 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
465 GtkTreeSelection *selection;
469 view = GTK_TREE_VIEW (dialog->treeview);
470 model = gtk_tree_view_get_model (view);
472 if (gtk_tree_model_get_iter_first (model, &iter)) {
473 selection = gtk_tree_view_get_selection (view);
474 gtk_tree_selection_select_iter (selection, &iter);
476 accounts_dialog_update_account (dialog, NULL);
481 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
482 GtkCellRenderer *cell,
485 EmpathyAccountsDialog *dialog)
488 const gchar *icon_name;
490 TpConnectionStatus status;
492 gtk_tree_model_get (model, iter,
494 COL_ACCOUNT_POINTER, &account,
497 icon_name = empathy_icon_name_from_account (account);
498 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
501 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
502 (status == TP_CONNECTION_STATUS_CONNECTING &&
503 !dialog->connecting_show)) {
504 GdkPixbuf *modded_pixbuf;
506 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
509 gdk_pixbuf_get_width (pixbuf),
510 gdk_pixbuf_get_height (pixbuf));
512 gdk_pixbuf_saturate_and_pixelate (pixbuf,
516 g_object_unref (pixbuf);
517 pixbuf = modded_pixbuf;
526 g_object_unref (account);
528 g_object_unref (pixbuf);
533 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
538 GtkTreeSelection *selection;
542 /* Update the status in the model */
543 view = GTK_TREE_VIEW (dialog->treeview);
544 selection = gtk_tree_view_get_selection (view);
545 model = gtk_tree_view_get_model (view);
547 for (ok = gtk_tree_model_get_iter_first (model, iter);
549 ok = gtk_tree_model_iter_next (model, iter)) {
550 McAccount *this_account;
553 gtk_tree_model_get (model, iter,
554 COL_ACCOUNT_POINTER, &this_account,
557 equal = empathy_account_equal (this_account, account);
558 g_object_unref (this_account);
569 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
573 GtkTreeSelection *selection;
577 view = GTK_TREE_VIEW (dialog->treeview);
578 selection = gtk_tree_view_get_selection (view);
580 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
584 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
590 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
593 GtkTreeSelection *selection;
596 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
597 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
598 gtk_tree_selection_select_iter (selection, &iter);
603 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
607 GtkTreeSelection *selection;
610 view = GTK_TREE_VIEW (dialog->treeview);
611 selection = gtk_tree_view_get_selection (view);
613 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
617 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
621 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
622 EmpathyAccountsDialog *dialog)
627 gboolean is_selection;
629 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
631 gtk_widget_set_sensitive (dialog->button_add, TRUE);
632 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
634 account = accounts_dialog_model_get_selected (dialog);
635 accounts_dialog_update_account (dialog, account);
638 g_object_unref (account);
641 /* insure new account frame is hidden when a row is selected*/
642 gtk_widget_hide (dialog->frame_new_account);
646 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
651 TpConnectionStatus status;
655 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
659 status = mission_control_get_connection_status (dialog->mc, account, NULL);
660 name = mc_account_get_display_name (account);
661 enabled = mc_account_is_enabled (account);
663 g_return_if_fail (name != NULL);
665 DEBUG ("Adding new account: %s", name);
667 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
668 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter,
670 COL_ENABLED, enabled,
673 COL_ACCOUNT_POINTER, account,
678 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
680 EmpathyAccountsDialog *dialog)
684 account = mc_account_lookup (unique_name);
685 accounts_dialog_add_account (dialog, account);
686 g_object_unref (account);
690 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
692 EmpathyAccountsDialog *dialog)
696 account = mc_account_lookup (unique_name);
698 accounts_dialog_model_set_selected (dialog, account);
699 accounts_dialog_model_remove_selected (dialog);
701 g_object_unref (account);
705 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
710 gtk_tree_model_row_changed (model, path, iter);
716 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
721 dialog->connecting_show = !dialog->connecting_show;
723 view = GTK_TREE_VIEW (dialog->treeview);
724 model = gtk_tree_view_get_model (view);
726 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
732 accounts_dialog_status_changed_cb (MissionControl *mc,
733 TpConnectionStatus status,
735 TpConnectionStatusReason reason,
736 const gchar *unique_name,
737 EmpathyAccountsDialog *dialog)
743 gboolean found = FALSE;
745 /* Update the status in the model */
746 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
747 account = mc_account_lookup (unique_name);
749 DEBUG ("Status changed for account %s: status=%d presence=%d",
750 unique_name, status, presence);
752 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
755 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
759 path = gtk_tree_model_get_path (model, &iter);
760 gtk_tree_model_row_changed (model, path, &iter);
761 gtk_tree_path_free (path);
763 g_object_unref (account);
765 /* Check if there is still accounts in CONNECTING state */
766 accounts = mc_accounts_list ();
767 for (l = accounts; l; l = l->next) {
768 McAccount *this_account;
769 TpConnectionStatus status;
771 this_account = l->data;
773 status = mission_control_get_connection_status (mc, this_account, NULL);
774 if (status == TP_CONNECTION_STATUS_CONNECTING) {
779 g_object_unref (this_account);
781 g_list_free (accounts);
783 if (!found && dialog->connecting_id) {
784 g_source_remove (dialog->connecting_id);
785 dialog->connecting_id = 0;
787 if (found && !dialog->connecting_id) {
788 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
789 (GSourceFunc) accounts_dialog_flash_connecting_cb,
795 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
797 EmpathyAccountsDialog *dialog)
804 /* Update the status in the model */
805 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
806 account = mc_account_lookup (unique_name);
807 enabled = mc_account_is_enabled (account);
809 DEBUG ("Account %s is now %s",
810 mc_account_get_display_name (account),
811 enabled ? "enabled" : "disabled");
813 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
814 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
815 COL_ENABLED, enabled,
819 g_object_unref (account);
823 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
824 EmpathyAccountsDialog *dialog)
831 gtk_widget_show (dialog->vbox_details);
832 gtk_widget_hide (dialog->frame_no_account);
833 gtk_widget_hide (dialog->frame_new_account);
835 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
838 account = mc_account_create (profile);
840 str = mc_account_get_unique_name (account);
841 mc_account_set_display_name (account, str);
843 accounts_dialog_add_account (dialog, account);
844 accounts_dialog_model_set_selected (dialog, account);
846 g_object_unref (account);
847 g_object_unref (profile);
851 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
852 EmpathyAccountsDialog *dialog)
856 gtk_widget_hide (dialog->vbox_details);
857 gtk_widget_hide (dialog->frame_no_account);
858 gtk_widget_hide (dialog->frame_new_account);
860 gtk_widget_set_sensitive (dialog->button_add, TRUE);
862 account = accounts_dialog_model_get_selected (dialog);
863 accounts_dialog_update_account (dialog, account);
867 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
868 EmpathyAccountsDialog *dialog)
871 GtkTreeSelection *selection;
873 view = GTK_TREE_VIEW (dialog->treeview);
874 selection = gtk_tree_view_get_selection (view);
875 gtk_tree_selection_unselect_all (selection);
877 gtk_widget_set_sensitive (dialog->button_add, FALSE);
878 gtk_widget_hide (dialog->vbox_details);
879 gtk_widget_hide (dialog->frame_no_account);
880 gtk_widget_show (dialog->frame_new_account);
882 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
883 gtk_widget_grab_focus (dialog->combobox_profile);
887 accounts_dialog_remove_response_cb (GtkWidget *dialog,
891 if (response == GTK_RESPONSE_YES) {
892 mc_account_delete (account);
895 gtk_widget_destroy (dialog);
899 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
900 EmpathyAccountsDialog *dialog)
903 GtkWidget *message_dialog;
905 account = accounts_dialog_model_get_selected (dialog);
907 if (!mc_account_is_complete (account)) {
908 accounts_dialog_model_remove_selected (dialog);
911 message_dialog = gtk_message_dialog_new
912 (GTK_WINDOW (dialog->window),
913 GTK_DIALOG_DESTROY_WITH_PARENT,
914 GTK_MESSAGE_QUESTION,
916 _("You are about to remove your %s account!\n"
917 "Are you sure you want to proceed?"),
918 mc_account_get_display_name (account));
920 gtk_message_dialog_format_secondary_text
921 (GTK_MESSAGE_DIALOG (message_dialog),
922 _("Any associated conversations and chat rooms will NOT be "
923 "removed if you decide to proceed.\n"
925 "Should you decide to add the account back at a later time, "
926 "they will still be available."));
928 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
931 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
935 g_signal_connect (message_dialog, "response",
936 G_CALLBACK (accounts_dialog_remove_response_cb),
939 gtk_widget_show (message_dialog);
943 accounts_dialog_response_cb (GtkWidget *widget,
945 EmpathyAccountsDialog *dialog)
947 gtk_widget_destroy (widget);
951 accounts_dialog_destroy_cb (GtkWidget *widget,
952 EmpathyAccountsDialog *dialog)
956 /* Disconnect signals */
957 g_signal_handlers_disconnect_by_func (dialog->monitor,
958 accounts_dialog_account_added_cb,
960 g_signal_handlers_disconnect_by_func (dialog->monitor,
961 accounts_dialog_account_removed_cb,
963 g_signal_handlers_disconnect_by_func (dialog->monitor,
964 accounts_dialog_account_enabled_cb,
966 empathy_disconnect_account_status_changed (dialog->token);
968 /* Delete incomplete accounts */
969 accounts = mc_accounts_list ();
970 for (l = accounts; l; l = l->next) {
974 if (!mc_account_is_complete (account)) {
975 /* FIXME: Warn the user the account is not complete
976 * and is going to be removed. */
977 mc_account_delete (account);
980 g_object_unref (account);
982 g_list_free (accounts);
984 if (dialog->connecting_id) {
985 g_source_remove (dialog->connecting_id);
988 g_object_unref (dialog->mc);
989 g_object_unref (dialog->monitor);
995 empathy_accounts_dialog_show (GtkWindow *parent)
997 static EmpathyAccountsDialog *dialog = NULL;
1001 GtkWidget *button_close;
1004 gtk_window_present (GTK_WINDOW (dialog->window));
1005 return dialog->window;
1008 dialog = g_new0 (EmpathyAccountsDialog, 1);
1010 filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
1012 glade = empathy_glade_get_file (filename,
1015 "accounts_dialog", &dialog->window,
1016 "vbox_details", &dialog->vbox_details,
1017 "frame_no_account", &dialog->frame_no_account,
1018 "label_no_account", &dialog->label_no_account,
1019 "label_no_account_blurb", &dialog->label_no_account_blurb,
1020 "alignment_settings", &dialog->alignment_settings,
1021 "dialog-action_area", &bbox,
1022 "treeview", &dialog->treeview,
1023 "frame_new_account", &dialog->frame_new_account,
1024 "hbox_type", &dialog->hbox_type,
1025 "button_create", &dialog->button_create,
1026 "button_back", &dialog->button_back,
1027 "image_type", &dialog->image_type,
1028 "label_name", &dialog->label_name,
1029 "button_add", &dialog->button_add,
1030 "button_remove", &dialog->button_remove,
1031 "button_close", &button_close,
1035 empathy_glade_connect (glade,
1037 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1038 "accounts_dialog", "response", accounts_dialog_response_cb,
1039 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1040 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1041 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1042 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1045 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1047 g_object_unref (glade);
1049 /* Create profile chooser */
1050 dialog->combobox_profile = empathy_profile_chooser_new ();
1051 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1052 dialog->combobox_profile,
1054 gtk_widget_show (dialog->combobox_profile);
1055 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) <= 0) {
1056 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1059 /* Set up signalling */
1060 dialog->mc = empathy_mission_control_new ();
1061 dialog->monitor = mc_account_monitor_new ();
1063 g_signal_connect (dialog->monitor, "account-created",
1064 G_CALLBACK (accounts_dialog_account_added_cb),
1066 g_signal_connect (dialog->monitor, "account-deleted",
1067 G_CALLBACK (accounts_dialog_account_removed_cb),
1069 g_signal_connect (dialog->monitor, "account-enabled",
1070 G_CALLBACK (accounts_dialog_account_enabled_cb),
1072 g_signal_connect (dialog->monitor, "account-disabled",
1073 G_CALLBACK (accounts_dialog_account_enabled_cb),
1075 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1076 G_CALLBACK (accounts_dialog_status_changed_cb),
1079 accounts_dialog_model_setup (dialog);
1080 accounts_dialog_setup (dialog);
1081 accounts_dialog_model_select_first (dialog);
1084 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1085 GTK_WINDOW (parent));
1088 gtk_widget_show (dialog->window);
1090 return dialog->window;