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;
244 gtk_widget_show (dialog->frame_no_account);
245 gtk_widget_hide (dialog->vbox_details);
247 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
248 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
250 view = GTK_TREE_VIEW (dialog->treeview);
251 model = gtk_tree_view_get_model (view);
253 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
254 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
255 _("<b>No Account Selected</b>"));
256 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
257 _("To add a new account, you can click on the "
258 "'Add' button and a new entry will be created "
259 "for you to start configuring.\n"
261 "If you do not want to add an account, simply "
262 "click on the account you want to configure in "
263 "the list on the left."));
265 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
266 _("<b>No Accounts Configured</b>"));
267 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
268 _("To add a new account, you can click on the "
269 "'Add' button and a new entry will be created "
270 "for you to start configuring."));
274 const gchar *config_ui;
276 gtk_widget_hide (dialog->frame_no_account);
277 gtk_widget_show (dialog->vbox_details);
279 profile = mc_account_get_profile (account);
280 config_ui = mc_profile_get_configuration_ui (profile);
281 g_object_unref (profile);
283 if (!empathy_strdiff (config_ui, "jabber")) {
284 dialog->settings_widget =
285 empathy_account_widget_jabber_new (account);
287 else if (!empathy_strdiff (config_ui, "msn")) {
288 dialog ->settings_widget =
289 empathy_account_widget_msn_new (account);
291 else if (!empathy_strdiff (config_ui, "salut")) {
292 dialog->settings_widget =
293 empathy_account_widget_salut_new (account);
296 dialog->settings_widget =
297 empathy_account_widget_generic_new (account);
300 gtk_widget_grab_focus (dialog->settings_widget);
303 if (dialog->settings_widget) {
304 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
305 dialog->settings_widget);
312 profile = mc_account_get_profile (account);
313 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
314 mc_profile_get_icon_name (profile),
315 GTK_ICON_SIZE_DIALOG);
316 /* FIXME: Uncomment once we depend on GTK+ 2.12
317 gtk_widget_set_tooltip_text (dialog->image_type,
318 mc_profile_get_display_name (profile));
321 text = g_strdup_printf ("<big><b>%s</b></big>", 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_STRING, /* name */
335 G_TYPE_UINT, /* status */
336 MC_TYPE_ACCOUNT); /* account */
338 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
339 GTK_TREE_MODEL (store));
341 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
342 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
344 g_signal_connect (selection, "changed",
345 G_CALLBACK (accounts_dialog_model_selection_changed),
348 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
349 COL_NAME, GTK_SORT_ASCENDING);
351 accounts_dialog_model_add_columns (dialog);
353 g_object_unref (store);
357 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
360 EmpathyAccountsDialog *dialog)
364 GtkTreePath *treepath;
367 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
368 treepath = gtk_tree_path_new_from_string (path);
369 gtk_tree_model_get_iter (model, &iter, treepath);
370 gtk_tree_model_get (model, &iter,
371 COL_ACCOUNT_POINTER, &account,
373 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
376 gtk_tree_path_free (treepath);
378 mc_account_set_display_name (account, new_text);
379 g_object_unref (account);
383 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
386 GtkTreeViewColumn *column;
387 GtkCellRenderer *cell;
389 view = GTK_TREE_VIEW (dialog->treeview);
390 gtk_tree_view_set_headers_visible (view, TRUE);
392 /* account name/status */
393 column = gtk_tree_view_column_new ();
394 gtk_tree_view_column_set_title (column, _("Accounts"));
396 cell = gtk_cell_renderer_pixbuf_new ();
397 gtk_tree_view_column_pack_start (column, cell, FALSE);
398 gtk_tree_view_column_set_cell_data_func (column, cell,
399 (GtkTreeCellDataFunc)
400 accounts_dialog_model_pixbuf_data_func,
404 cell = gtk_cell_renderer_text_new ();
406 "ellipsize", PANGO_ELLIPSIZE_END,
409 gtk_tree_view_column_pack_start (column, cell, TRUE);
410 gtk_tree_view_column_add_attribute (column,
413 g_signal_connect (cell, "edited",
414 G_CALLBACK (accounts_dialog_name_edited_cb),
417 gtk_tree_view_column_set_expand (column, TRUE);
418 gtk_tree_view_append_column (view, column);
422 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
426 GtkTreeSelection *selection;
430 view = GTK_TREE_VIEW (dialog->treeview);
431 model = gtk_tree_view_get_model (view);
433 if (gtk_tree_model_get_iter_first (model, &iter)) {
434 selection = gtk_tree_view_get_selection (view);
435 gtk_tree_selection_select_iter (selection, &iter);
437 accounts_dialog_update_account (dialog, NULL);
442 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
443 GtkCellRenderer *cell,
446 EmpathyAccountsDialog *dialog)
449 const gchar *icon_name;
451 TelepathyConnectionStatus status;
453 gtk_tree_model_get (model, iter,
455 COL_ACCOUNT_POINTER, &account,
458 icon_name = empathy_icon_name_from_account (account);
459 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
462 if (status == TP_CONN_STATUS_DISCONNECTED ||
463 (status == TP_CONN_STATUS_CONNECTING &&
464 !dialog->connecting_show)) {
465 GdkPixbuf *modded_pixbuf;
467 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
470 gdk_pixbuf_get_width (pixbuf),
471 gdk_pixbuf_get_height (pixbuf));
473 gdk_pixbuf_saturate_and_pixelate (pixbuf,
477 g_object_unref (pixbuf);
478 pixbuf = modded_pixbuf;
487 g_object_unref (account);
489 g_object_unref (pixbuf);
494 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
498 GtkTreeSelection *selection;
502 view = GTK_TREE_VIEW (dialog->treeview);
503 selection = gtk_tree_view_get_selection (view);
505 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
509 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
515 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
519 GtkTreeSelection *selection;
524 view = GTK_TREE_VIEW (dialog->treeview);
525 model = gtk_tree_view_get_model (view);
526 selection = gtk_tree_view_get_selection (view);
528 for (ok = gtk_tree_model_get_iter_first (model, &iter);
530 ok = gtk_tree_model_iter_next (model, &iter)) {
531 McAccount *this_account;
534 gtk_tree_model_get (model, &iter,
535 COL_ACCOUNT_POINTER, &this_account,
538 equal = empathy_account_equal (this_account, account);
539 g_object_unref (this_account);
542 gtk_tree_selection_select_iter (selection, &iter);
549 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
553 GtkTreeSelection *selection;
556 view = GTK_TREE_VIEW (dialog->treeview);
557 selection = gtk_tree_view_get_selection (view);
559 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
563 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
567 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
568 EmpathyAccountsDialog *dialog)
573 gboolean is_selection;
575 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
577 gtk_widget_set_sensitive (dialog->button_add, TRUE);
578 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
579 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
581 accounts_dialog_update_connect_button (dialog);
583 account = accounts_dialog_model_get_selected (dialog);
584 accounts_dialog_update_account (dialog, account);
587 g_object_unref (account);
590 /* insure new account frame is hidden when a row is selected*/
591 gtk_widget_hide (dialog->frame_new_account);
595 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
598 TelepathyConnectionStatus status;
606 view = GTK_TREE_VIEW (dialog->treeview);
607 model = gtk_tree_view_get_model (view);
608 store = GTK_LIST_STORE (model);
610 for (ok = gtk_tree_model_get_iter_first (model, &iter);
612 ok = gtk_tree_model_iter_next (model, &iter)) {
613 McAccount *this_account;
616 gtk_tree_model_get (model, &iter,
617 COL_ACCOUNT_POINTER, &this_account,
620 equal = empathy_account_equal (this_account, account);
621 g_object_unref (this_account);
628 status = mission_control_get_connection_status (dialog->mc, account, NULL);
629 name = mc_account_get_display_name (account);
631 g_return_if_fail (name != NULL);
633 empathy_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
635 gtk_list_store_insert_with_values (store, &iter,
639 COL_ACCOUNT_POINTER, account,
644 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
646 EmpathyAccountsDialog *dialog)
650 account = mc_account_lookup (unique_name);
651 accounts_dialog_add_account (dialog, account);
652 g_object_unref (account);
656 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
658 EmpathyAccountsDialog *dialog)
662 account = mc_account_lookup (unique_name);
664 accounts_dialog_model_set_selected (dialog, account);
665 accounts_dialog_model_remove_selected (dialog);
667 g_object_unref (account);
671 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
676 gtk_tree_model_row_changed (model, path, iter);
682 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
687 dialog->connecting_show = !dialog->connecting_show;
689 view = GTK_TREE_VIEW (dialog->treeview);
690 model = gtk_tree_view_get_model (view);
692 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
698 accounts_dialog_status_changed_cb (MissionControl *mc,
699 TelepathyConnectionStatus status,
701 TelepathyConnectionStatusReason reason,
702 const gchar *unique_name,
703 EmpathyAccountsDialog *dialog)
706 GtkTreeSelection *selection;
712 gboolean found = FALSE;
714 /* Update the status in the model */
715 view = GTK_TREE_VIEW (dialog->treeview);
716 selection = gtk_tree_view_get_selection (view);
717 model = gtk_tree_view_get_model (view);
718 account = mc_account_lookup (unique_name);
720 empathy_debug (DEBUG_DOMAIN, "Status changed for account %s: "
721 "status=%d presence=%d",
722 unique_name, status, presence);
724 for (ok = gtk_tree_model_get_iter_first (model, &iter);
726 ok = gtk_tree_model_iter_next (model, &iter)) {
727 McAccount *this_account;
730 gtk_tree_model_get (model, &iter,
731 COL_ACCOUNT_POINTER, &this_account,
734 equal = empathy_account_equal (this_account, account);
735 g_object_unref (this_account);
740 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
744 path = gtk_tree_model_get_path (model, &iter);
745 gtk_tree_model_row_changed (model, path, &iter);
746 gtk_tree_path_free (path);
752 g_object_unref (account);
754 /* Start to flash account if status is connecting */
755 if (status == TP_CONN_STATUS_CONNECTING) {
756 if (!dialog->connecting_id) {
757 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
758 (GSourceFunc) accounts_dialog_flash_connecting_cb,
765 /* Stop to flash if no account is connecting */
766 accounts = mc_accounts_list ();
767 for (l = accounts; l; l = l->next) {
768 McAccount *this_account;
770 this_account = l->data;
772 if (mission_control_get_connection_status (mc, this_account, NULL) == TP_CONN_STATUS_CONNECTING) {
777 g_object_unref (this_account);
779 g_list_free (accounts);
781 if (!found && dialog->connecting_id) {
782 g_source_remove (dialog->connecting_id);
783 dialog->connecting_id = 0;
786 gtk_widget_show (dialog->window);
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 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog->mc),
957 "AccountStatusChanged",
958 G_CALLBACK (accounts_dialog_status_changed_cb),
961 /* Delete incomplete accounts */
962 accounts = mc_accounts_list ();
963 for (l = accounts; l; l = l->next) {
967 if (!mc_account_is_complete (account)) {
968 /* FIXME: Warn the user the account is not complete
969 * and is going to be removed. */
970 mc_account_delete (account);
973 g_object_unref (account);
975 g_list_free (accounts);
977 if (dialog->connecting_id) {
978 g_source_remove (dialog->connecting_id);
981 g_object_unref (dialog->mc);
982 g_object_unref (dialog->monitor);
988 empathy_accounts_dialog_show (GtkWindow *parent)
990 static EmpathyAccountsDialog *dialog = NULL;
993 GtkWidget *button_close;
996 gtk_window_present (GTK_WINDOW (dialog->window));
997 return dialog->window;
1000 dialog = g_new0 (EmpathyAccountsDialog, 1);
1002 glade = empathy_glade_get_file ("empathy-accounts-dialog.glade",
1005 "accounts_dialog", &dialog->window,
1006 "vbox_details", &dialog->vbox_details,
1007 "frame_no_account", &dialog->frame_no_account,
1008 "label_no_account", &dialog->label_no_account,
1009 "label_no_account_blurb", &dialog->label_no_account_blurb,
1010 "alignment_settings", &dialog->alignment_settings,
1011 "dialog-action_area", &bbox,
1012 "treeview", &dialog->treeview,
1013 "frame_new_account", &dialog->frame_new_account,
1014 "hbox_type", &dialog->hbox_type,
1015 "button_create", &dialog->button_create,
1016 "button_back", &dialog->button_back,
1017 "image_type", &dialog->image_type,
1018 "label_name", &dialog->label_name,
1019 "button_add", &dialog->button_add,
1020 "button_remove", &dialog->button_remove,
1021 "button_connect", &dialog->button_connect,
1022 "button_close", &button_close,
1025 empathy_glade_connect (glade,
1027 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1028 "accounts_dialog", "response", accounts_dialog_response_cb,
1029 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1030 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1031 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
1032 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
1033 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1034 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1037 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1039 g_object_unref (glade);
1041 /* Create profile chooser */
1042 dialog->combobox_profile = empathy_profile_chooser_new ();
1043 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1044 dialog->combobox_profile,
1046 gtk_widget_show (dialog->combobox_profile);
1048 /* Set up signalling */
1049 dialog->mc = empathy_mission_control_new ();
1050 dialog->monitor = mc_account_monitor_new ();
1052 /* FIXME: connect account-enabled/disabled too */
1053 g_signal_connect (dialog->monitor, "account-created",
1054 G_CALLBACK (accounts_dialog_account_added_cb),
1056 g_signal_connect (dialog->monitor, "account-deleted",
1057 G_CALLBACK (accounts_dialog_account_removed_cb),
1059 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog->mc), "AccountStatusChanged",
1060 G_CALLBACK (accounts_dialog_status_changed_cb),
1063 accounts_dialog_model_setup (dialog);
1064 accounts_dialog_setup (dialog);
1065 accounts_dialog_model_select_first (dialog);
1068 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1069 GTK_WINDOW (parent));
1072 gtk_widget_show (dialog->window);
1074 return dialog->window;