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 <telepathy-glib/util.h>
40 #include <libtelepathy/tp-constants.h>
42 #include <libempathy/empathy-debug.h>
43 #include <libempathy/empathy-utils.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
46 #include "empathy-accounts-dialog.h"
47 #include "empathy-profile-chooser.h"
48 #include "empathy-account-widget-generic.h"
49 #include "empathy-account-widget-jabber.h"
50 #include "empathy-account-widget-msn.h"
51 #include "empathy-account-widget-salut.h"
53 #define DEBUG_DOMAIN "AccountDialog"
55 /* Flashing delay for icons (milliseconds). */
56 #define FLASH_TIMEOUT 500
61 GtkWidget *alignment_settings;
63 GtkWidget *vbox_details;
64 GtkWidget *frame_no_account;
65 GtkWidget *label_no_account;
66 GtkWidget *label_no_account_blurb;
70 GtkWidget *button_add;
71 GtkWidget *button_remove;
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;
100 static void accounts_dialog_setup (EmpathyAccountsDialog *dialog);
101 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
103 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
104 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
105 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
106 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
107 GtkCellRenderer *cell,
110 EmpathyAccountsDialog *dialog);
111 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
112 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
114 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
115 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
116 EmpathyAccountsDialog *dialog);
117 static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
119 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
121 EmpathyAccountsDialog *dialog);
122 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
124 EmpathyAccountsDialog *dialog);
125 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
129 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
130 static void accounts_dialog_status_changed_cb (MissionControl *mc,
131 TpConnectionStatus status,
133 TpConnectionStatusReason reason,
134 const gchar *unique_name,
135 EmpathyAccountsDialog *dialog);
136 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
137 EmpathyAccountsDialog *dialog);
138 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
139 EmpathyAccountsDialog *dialog);
140 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
145 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
146 EmpathyAccountsDialog *dialog);
147 static void accounts_dialog_response_cb (GtkWidget *widget,
149 EmpathyAccountsDialog *dialog);
150 static void accounts_dialog_destroy_cb (GtkWidget *widget,
151 EmpathyAccountsDialog *dialog);
154 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
161 view = GTK_TREE_VIEW (dialog->treeview);
162 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
164 accounts = mc_accounts_list ();
166 for (l = accounts; l; l = l->next) {
169 TpConnectionStatus status;
174 name = mc_account_get_display_name (account);
179 status = mission_control_get_connection_status (dialog->mc, account, NULL);
180 enabled = mc_account_is_enabled (account);
182 gtk_list_store_insert_with_values (store, &iter,
184 COL_ENABLED, enabled,
187 COL_ACCOUNT_POINTER, account,
190 accounts_dialog_status_changed_cb (dialog->mc,
193 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
194 mc_account_get_unique_name (account),
197 g_object_unref (account);
200 g_list_free (accounts);
204 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
207 if (dialog->settings_widget) {
208 gtk_widget_destroy (dialog->settings_widget);
209 dialog->settings_widget = NULL;
218 gtk_widget_show (dialog->frame_no_account);
219 gtk_widget_hide (dialog->vbox_details);
221 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
223 view = GTK_TREE_VIEW (dialog->treeview);
224 model = gtk_tree_view_get_model (view);
226 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
227 string = g_string_new (_("To add a new account, you can click on the "
228 "'Add' button and a new entry will be created "
229 "for you to start configuring."));
231 string = g_string_new (_("To add a new account, you first have to "
232 "install a backend for each protocol "
233 "you want to use."));
236 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
237 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
238 _("<b>No Account Selected</b>"));
239 g_string_append (string, _("\n\n"
240 "If you do not want to add an account, simply "
241 "click on the account you want to configure in "
242 "the list on the left."));
244 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
245 _("<b>No Accounts Configured</b>"));
248 str = g_string_free (string, FALSE);
249 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
254 const gchar *config_ui;
256 gtk_widget_hide (dialog->frame_no_account);
257 gtk_widget_show (dialog->vbox_details);
259 profile = mc_account_get_profile (account);
260 config_ui = mc_profile_get_configuration_ui (profile);
261 g_object_unref (profile);
263 if (!tp_strdiff (config_ui, "jabber")) {
264 dialog->settings_widget =
265 empathy_account_widget_jabber_new (account);
267 else if (!tp_strdiff (config_ui, "msn")) {
268 dialog ->settings_widget =
269 empathy_account_widget_msn_new (account);
271 else if (!tp_strdiff (config_ui, "local-xmpp")) {
272 dialog->settings_widget =
273 empathy_account_widget_salut_new (account);
276 dialog->settings_widget =
277 empathy_account_widget_generic_new (account);
281 if (dialog->settings_widget) {
282 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
283 dialog->settings_widget);
290 profile = mc_account_get_profile (account);
291 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
292 mc_profile_get_icon_name (profile),
293 GTK_ICON_SIZE_DIALOG);
294 gtk_widget_set_tooltip_text (dialog->image_type,
295 mc_profile_get_display_name (profile));
297 text = g_strdup_printf ("<big><b>%s</b></big>", mc_account_get_display_name (account));
298 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
304 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
307 GtkTreeSelection *selection;
309 store = gtk_list_store_new (COL_COUNT,
310 G_TYPE_BOOLEAN, /* enabled */
311 G_TYPE_STRING, /* name */
312 G_TYPE_UINT, /* status */
313 MC_TYPE_ACCOUNT); /* account */
315 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
316 GTK_TREE_MODEL (store));
318 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
319 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
321 g_signal_connect (selection, "changed",
322 G_CALLBACK (accounts_dialog_model_selection_changed),
325 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
326 COL_NAME, GTK_SORT_ASCENDING);
328 accounts_dialog_model_add_columns (dialog);
330 g_object_unref (store);
334 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
337 EmpathyAccountsDialog *dialog)
341 GtkTreePath *treepath;
344 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
345 treepath = gtk_tree_path_new_from_string (path);
346 gtk_tree_model_get_iter (model, &iter, treepath);
347 gtk_tree_model_get (model, &iter,
348 COL_ACCOUNT_POINTER, &account,
350 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
353 gtk_tree_path_free (treepath);
355 mc_account_set_display_name (account, new_text);
356 g_object_unref (account);
360 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
362 EmpathyAccountsDialog *dialog)
366 GtkTreePath *treepath;
370 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
371 treepath = gtk_tree_path_new_from_string (path);
372 gtk_tree_model_get_iter (model, &iter, treepath);
373 gtk_tree_model_get (model, &iter,
374 COL_ACCOUNT_POINTER, &account,
376 gtk_tree_path_free (treepath);
378 enabled = mc_account_is_enabled (account);
379 mc_account_set_enabled (account, !enabled);
381 empathy_debug (DEBUG_DOMAIN, "%s account %s",
382 enabled ? "Disabled" : "Enable",
383 mc_account_get_display_name(account));
385 g_object_unref (account);
389 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
392 GtkTreeViewColumn *column;
393 GtkCellRenderer *cell;
395 view = GTK_TREE_VIEW (dialog->treeview);
396 gtk_tree_view_set_headers_visible (view, TRUE);
399 cell = gtk_cell_renderer_toggle_new ();
400 gtk_tree_view_insert_column_with_attributes (view, -1,
402 "active", COL_ENABLED,
404 g_signal_connect (cell, "toggled",
405 G_CALLBACK (accounts_dialog_enable_toggled_cb),
408 column = gtk_tree_view_column_new ();
409 gtk_tree_view_column_set_title (column, _("Accounts"));
412 cell = gtk_cell_renderer_pixbuf_new ();
413 gtk_tree_view_column_pack_start (column, cell, FALSE);
414 gtk_tree_view_column_set_cell_data_func (column, cell,
415 (GtkTreeCellDataFunc)
416 accounts_dialog_model_pixbuf_data_func,
421 cell = gtk_cell_renderer_text_new ();
423 "ellipsize", PANGO_ELLIPSIZE_END,
426 gtk_tree_view_column_pack_start (column, cell, TRUE);
427 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
428 g_signal_connect (cell, "edited",
429 G_CALLBACK (accounts_dialog_name_edited_cb),
432 gtk_tree_view_column_set_expand (column, TRUE);
433 gtk_tree_view_append_column (view, column);
437 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
441 GtkTreeSelection *selection;
445 view = GTK_TREE_VIEW (dialog->treeview);
446 model = gtk_tree_view_get_model (view);
448 if (gtk_tree_model_get_iter_first (model, &iter)) {
449 selection = gtk_tree_view_get_selection (view);
450 gtk_tree_selection_select_iter (selection, &iter);
452 accounts_dialog_update_account (dialog, NULL);
457 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
458 GtkCellRenderer *cell,
461 EmpathyAccountsDialog *dialog)
464 const gchar *icon_name;
466 TpConnectionStatus status;
468 gtk_tree_model_get (model, iter,
470 COL_ACCOUNT_POINTER, &account,
473 icon_name = empathy_icon_name_from_account (account);
474 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
477 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
478 (status == TP_CONNECTION_STATUS_CONNECTING &&
479 !dialog->connecting_show)) {
480 GdkPixbuf *modded_pixbuf;
482 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
485 gdk_pixbuf_get_width (pixbuf),
486 gdk_pixbuf_get_height (pixbuf));
488 gdk_pixbuf_saturate_and_pixelate (pixbuf,
492 g_object_unref (pixbuf);
493 pixbuf = modded_pixbuf;
502 g_object_unref (account);
504 g_object_unref (pixbuf);
509 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
514 GtkTreeSelection *selection;
518 /* Update the status in the model */
519 view = GTK_TREE_VIEW (dialog->treeview);
520 selection = gtk_tree_view_get_selection (view);
521 model = gtk_tree_view_get_model (view);
523 for (ok = gtk_tree_model_get_iter_first (model, iter);
525 ok = gtk_tree_model_iter_next (model, iter)) {
526 McAccount *this_account;
529 gtk_tree_model_get (model, iter,
530 COL_ACCOUNT_POINTER, &this_account,
533 equal = empathy_account_equal (this_account, account);
534 g_object_unref (this_account);
545 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
549 GtkTreeSelection *selection;
553 view = GTK_TREE_VIEW (dialog->treeview);
554 selection = gtk_tree_view_get_selection (view);
556 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
560 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
566 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
569 GtkTreeSelection *selection;
572 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
573 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
574 gtk_tree_selection_select_iter (selection, &iter);
579 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
583 GtkTreeSelection *selection;
586 view = GTK_TREE_VIEW (dialog->treeview);
587 selection = gtk_tree_view_get_selection (view);
589 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
593 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
597 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
598 EmpathyAccountsDialog *dialog)
603 gboolean is_selection;
605 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
607 gtk_widget_set_sensitive (dialog->button_add, TRUE);
608 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
610 account = accounts_dialog_model_get_selected (dialog);
611 accounts_dialog_update_account (dialog, account);
614 g_object_unref (account);
617 /* insure new account frame is hidden when a row is selected*/
618 gtk_widget_hide (dialog->frame_new_account);
622 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
627 TpConnectionStatus status;
631 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
635 status = mission_control_get_connection_status (dialog->mc, account, NULL);
636 name = mc_account_get_display_name (account);
637 enabled = mc_account_is_enabled (account);
639 g_return_if_fail (name != NULL);
641 empathy_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
643 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
644 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter,
646 COL_ENABLED, enabled,
649 COL_ACCOUNT_POINTER, account,
654 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
656 EmpathyAccountsDialog *dialog)
660 account = mc_account_lookup (unique_name);
661 accounts_dialog_add_account (dialog, account);
662 g_object_unref (account);
666 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
668 EmpathyAccountsDialog *dialog)
672 account = mc_account_lookup (unique_name);
674 accounts_dialog_model_set_selected (dialog, account);
675 accounts_dialog_model_remove_selected (dialog);
677 g_object_unref (account);
681 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
686 gtk_tree_model_row_changed (model, path, iter);
692 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
697 dialog->connecting_show = !dialog->connecting_show;
699 view = GTK_TREE_VIEW (dialog->treeview);
700 model = gtk_tree_view_get_model (view);
702 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
708 accounts_dialog_status_changed_cb (MissionControl *mc,
709 TpConnectionStatus status,
711 TpConnectionStatusReason reason,
712 const gchar *unique_name,
713 EmpathyAccountsDialog *dialog)
719 gboolean found = FALSE;
721 /* Update the status in the model */
722 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
723 account = mc_account_lookup (unique_name);
725 empathy_debug (DEBUG_DOMAIN, "Status changed for account %s: "
726 "status=%d presence=%d",
727 unique_name, status, presence);
729 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
732 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
736 path = gtk_tree_model_get_path (model, &iter);
737 gtk_tree_model_row_changed (model, path, &iter);
738 gtk_tree_path_free (path);
740 g_object_unref (account);
742 /* Check if there is still accounts in CONNECTING state */
743 accounts = mc_accounts_list ();
744 for (l = accounts; l; l = l->next) {
745 McAccount *this_account;
746 TpConnectionStatus status;
748 this_account = l->data;
750 status = mission_control_get_connection_status (mc, this_account, NULL);
751 if (status == TP_CONNECTION_STATUS_CONNECTING) {
756 g_object_unref (this_account);
758 g_list_free (accounts);
760 if (!found && dialog->connecting_id) {
761 g_source_remove (dialog->connecting_id);
762 dialog->connecting_id = 0;
764 if (found && !dialog->connecting_id) {
765 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
766 (GSourceFunc) accounts_dialog_flash_connecting_cb,
772 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
774 EmpathyAccountsDialog *dialog)
781 /* Update the status in the model */
782 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
783 account = mc_account_lookup (unique_name);
784 enabled = mc_account_is_enabled (account);
786 empathy_debug (DEBUG_DOMAIN, "Account %s is now %s",
787 mc_account_get_display_name (account),
788 enabled ? "enabled" : "disabled");
790 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
791 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
792 COL_ENABLED, enabled,
796 g_object_unref (account);
800 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
801 EmpathyAccountsDialog *dialog)
808 gtk_widget_show (dialog->vbox_details);
809 gtk_widget_hide (dialog->frame_no_account);
810 gtk_widget_hide (dialog->frame_new_account);
812 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
815 account = mc_account_create (profile);
817 str = mc_account_get_unique_name (account);
818 mc_account_set_display_name (account, str);
820 accounts_dialog_add_account (dialog, account);
821 accounts_dialog_model_set_selected (dialog, account);
823 g_object_unref (account);
824 g_object_unref (profile);
828 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
829 EmpathyAccountsDialog *dialog)
833 gtk_widget_hide (dialog->vbox_details);
834 gtk_widget_hide (dialog->frame_no_account);
835 gtk_widget_hide (dialog->frame_new_account);
837 gtk_widget_set_sensitive (dialog->button_add, TRUE);
839 account = accounts_dialog_model_get_selected (dialog);
840 accounts_dialog_update_account (dialog, account);
844 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
845 EmpathyAccountsDialog *dialog)
848 GtkTreeSelection *selection;
850 view = GTK_TREE_VIEW (dialog->treeview);
851 selection = gtk_tree_view_get_selection (view);
852 gtk_tree_selection_unselect_all (selection);
854 gtk_widget_set_sensitive (dialog->button_add, FALSE);
855 gtk_widget_hide (dialog->vbox_details);
856 gtk_widget_hide (dialog->frame_no_account);
857 gtk_widget_show (dialog->frame_new_account);
859 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
860 gtk_widget_grab_focus (dialog->combobox_profile);
864 accounts_dialog_remove_response_cb (GtkWidget *dialog,
868 if (response == GTK_RESPONSE_YES) {
869 mc_account_delete (account);
872 gtk_widget_destroy (dialog);
876 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
877 EmpathyAccountsDialog *dialog)
880 GtkWidget *message_dialog;
882 account = accounts_dialog_model_get_selected (dialog);
884 if (!mc_account_is_complete (account)) {
885 accounts_dialog_model_remove_selected (dialog);
888 message_dialog = gtk_message_dialog_new
889 (GTK_WINDOW (dialog->window),
890 GTK_DIALOG_DESTROY_WITH_PARENT,
891 GTK_MESSAGE_QUESTION,
893 _("You are about to remove your %s account!\n"
894 "Are you sure you want to proceed?"),
895 mc_account_get_display_name (account));
897 gtk_message_dialog_format_secondary_text
898 (GTK_MESSAGE_DIALOG (message_dialog),
899 _("Any associated conversations and chat rooms will NOT be "
900 "removed if you decide to proceed.\n"
902 "Should you decide to add the account back at a later time, "
903 "they will still be available."));
905 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
908 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
912 g_signal_connect (message_dialog, "response",
913 G_CALLBACK (accounts_dialog_remove_response_cb),
916 gtk_widget_show (message_dialog);
920 accounts_dialog_response_cb (GtkWidget *widget,
922 EmpathyAccountsDialog *dialog)
924 gtk_widget_destroy (widget);
928 accounts_dialog_destroy_cb (GtkWidget *widget,
929 EmpathyAccountsDialog *dialog)
933 /* Disconnect signals */
934 g_signal_handlers_disconnect_by_func (dialog->monitor,
935 accounts_dialog_account_added_cb,
937 g_signal_handlers_disconnect_by_func (dialog->monitor,
938 accounts_dialog_account_removed_cb,
940 g_signal_handlers_disconnect_by_func (dialog->monitor,
941 accounts_dialog_account_enabled_cb,
943 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog->mc),
944 "AccountStatusChanged",
945 G_CALLBACK (accounts_dialog_status_changed_cb),
948 /* Delete incomplete accounts */
949 accounts = mc_accounts_list ();
950 for (l = accounts; l; l = l->next) {
954 if (!mc_account_is_complete (account)) {
955 /* FIXME: Warn the user the account is not complete
956 * and is going to be removed. */
957 mc_account_delete (account);
960 g_object_unref (account);
962 g_list_free (accounts);
964 if (dialog->connecting_id) {
965 g_source_remove (dialog->connecting_id);
968 g_object_unref (dialog->mc);
969 g_object_unref (dialog->monitor);
975 empathy_accounts_dialog_show (GtkWindow *parent)
977 static EmpathyAccountsDialog *dialog = NULL;
980 GtkWidget *button_close;
983 gtk_window_present (GTK_WINDOW (dialog->window));
984 return dialog->window;
987 dialog = g_new0 (EmpathyAccountsDialog, 1);
989 glade = empathy_glade_get_file ("empathy-accounts-dialog.glade",
992 "accounts_dialog", &dialog->window,
993 "vbox_details", &dialog->vbox_details,
994 "frame_no_account", &dialog->frame_no_account,
995 "label_no_account", &dialog->label_no_account,
996 "label_no_account_blurb", &dialog->label_no_account_blurb,
997 "alignment_settings", &dialog->alignment_settings,
998 "dialog-action_area", &bbox,
999 "treeview", &dialog->treeview,
1000 "frame_new_account", &dialog->frame_new_account,
1001 "hbox_type", &dialog->hbox_type,
1002 "button_create", &dialog->button_create,
1003 "button_back", &dialog->button_back,
1004 "image_type", &dialog->image_type,
1005 "label_name", &dialog->label_name,
1006 "button_add", &dialog->button_add,
1007 "button_remove", &dialog->button_remove,
1008 "button_close", &button_close,
1011 empathy_glade_connect (glade,
1013 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1014 "accounts_dialog", "response", accounts_dialog_response_cb,
1015 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1016 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1017 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1018 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1021 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1023 g_object_unref (glade);
1025 /* Create profile chooser */
1026 dialog->combobox_profile = empathy_profile_chooser_new ();
1027 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1028 dialog->combobox_profile,
1030 gtk_widget_show (dialog->combobox_profile);
1031 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) <= 0) {
1032 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1035 /* Set up signalling */
1036 dialog->mc = empathy_mission_control_new ();
1037 dialog->monitor = mc_account_monitor_new ();
1039 g_signal_connect (dialog->monitor, "account-created",
1040 G_CALLBACK (accounts_dialog_account_added_cb),
1042 g_signal_connect (dialog->monitor, "account-deleted",
1043 G_CALLBACK (accounts_dialog_account_removed_cb),
1045 g_signal_connect (dialog->monitor, "account-enabled",
1046 G_CALLBACK (accounts_dialog_account_enabled_cb),
1048 g_signal_connect (dialog->monitor, "account-disabled",
1049 G_CALLBACK (accounts_dialog_account_enabled_cb),
1051 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog->mc), "AccountStatusChanged",
1052 G_CALLBACK (accounts_dialog_status_changed_cb),
1055 accounts_dialog_model_setup (dialog);
1056 accounts_dialog_setup (dialog);
1057 accounts_dialog_model_select_first (dialog);
1060 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1061 GTK_WINDOW (parent));
1064 gtk_widget_show (dialog->window);
1066 return dialog->window;