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;
72 GtkWidget *button_connect;
74 GtkWidget *frame_new_account;
75 GtkWidget *combobox_profile;
77 GtkWidget *button_create;
78 GtkWidget *button_back;
80 GtkWidget *image_type;
81 GtkWidget *label_name;
82 GtkWidget *label_type;
83 GtkWidget *settings_widget;
85 gboolean connecting_show;
87 gboolean account_changed;
90 McAccountMonitor *monitor;
91 } 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_connect_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
143 EmpathyAccountsDialog *dialog);
144 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
147 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
148 EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
151 GtkTreeViewColumn *column,
152 EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_response_cb (GtkWidget *widget,
155 EmpathyAccountsDialog *dialog);
156 static void accounts_dialog_destroy_cb (GtkWidget *widget,
157 EmpathyAccountsDialog *dialog);
160 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
167 view = GTK_TREE_VIEW (dialog->treeview);
168 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
170 accounts = mc_accounts_list ();
172 for (l = accounts; l; l = l->next) {
175 TpConnectionStatus status;
179 name = mc_account_get_display_name (account);
184 status = mission_control_get_connection_status (dialog->mc, account, NULL);
186 gtk_list_store_insert_with_values (store, &iter,
190 COL_ACCOUNT_POINTER, account,
193 accounts_dialog_status_changed_cb (dialog->mc,
196 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
197 mc_account_get_unique_name (account),
200 g_object_unref (account);
203 g_list_free (accounts);
207 accounts_dialog_update_connect_button (EmpathyAccountsDialog *dialog)
211 const gchar *stock_id;
214 account = accounts_dialog_model_get_selected (dialog);
216 gtk_widget_set_sensitive (dialog->button_connect, account != NULL);
218 if (account && mc_account_is_enabled (account)) {
219 label = _("Disable");
220 stock_id = GTK_STOCK_DISCONNECT;
223 stock_id = GTK_STOCK_CONNECT;
226 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
228 gtk_button_set_label (GTK_BUTTON (dialog->button_connect), label);
229 gtk_button_set_image (GTK_BUTTON (dialog->button_connect), image);
233 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
236 if (dialog->settings_widget) {
237 gtk_widget_destroy (dialog->settings_widget);
238 dialog->settings_widget = NULL;
247 gtk_widget_show (dialog->frame_no_account);
248 gtk_widget_hide (dialog->vbox_details);
250 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
251 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
253 view = GTK_TREE_VIEW (dialog->treeview);
254 model = gtk_tree_view_get_model (view);
256 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
257 string = g_string_new (_("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."));
261 string = g_string_new (_("To add a new account, you first have to "
262 "install a backend for each protocol "
263 "you want to use."));
266 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
267 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
268 _("<b>No Account Selected</b>"));
269 g_string_append (string, _("\n\n"
270 "If you do not want to add an account, simply "
271 "click on the account you want to configure in "
272 "the list on the left."));
274 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
275 _("<b>No Accounts Configured</b>"));
278 str = g_string_free (string, FALSE);
279 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
284 const gchar *config_ui;
286 gtk_widget_hide (dialog->frame_no_account);
287 gtk_widget_show (dialog->vbox_details);
289 profile = mc_account_get_profile (account);
290 config_ui = mc_profile_get_configuration_ui (profile);
291 g_object_unref (profile);
293 if (!tp_strdiff (config_ui, "jabber")) {
294 dialog->settings_widget =
295 empathy_account_widget_jabber_new (account);
297 else if (!tp_strdiff (config_ui, "msn")) {
298 dialog ->settings_widget =
299 empathy_account_widget_msn_new (account);
301 else if (!tp_strdiff (config_ui, "local-xmpp")) {
302 dialog->settings_widget =
303 empathy_account_widget_salut_new (account);
306 dialog->settings_widget =
307 empathy_account_widget_generic_new (account);
310 gtk_widget_grab_focus (dialog->settings_widget);
313 if (dialog->settings_widget) {
314 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
315 dialog->settings_widget);
322 profile = mc_account_get_profile (account);
323 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
324 mc_profile_get_icon_name (profile),
325 GTK_ICON_SIZE_DIALOG);
326 gtk_widget_set_tooltip_text (dialog->image_type,
327 mc_profile_get_display_name (profile));
329 text = g_strdup_printf ("<big><b>%s</b></big>", mc_account_get_display_name (account));
330 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
336 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
339 GtkTreeSelection *selection;
341 store = gtk_list_store_new (COL_COUNT,
342 G_TYPE_STRING, /* name */
343 G_TYPE_UINT, /* status */
344 MC_TYPE_ACCOUNT); /* account */
346 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
347 GTK_TREE_MODEL (store));
349 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
350 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
352 g_signal_connect (selection, "changed",
353 G_CALLBACK (accounts_dialog_model_selection_changed),
356 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
357 COL_NAME, GTK_SORT_ASCENDING);
359 accounts_dialog_model_add_columns (dialog);
361 g_object_unref (store);
365 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
368 EmpathyAccountsDialog *dialog)
372 GtkTreePath *treepath;
375 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
376 treepath = gtk_tree_path_new_from_string (path);
377 gtk_tree_model_get_iter (model, &iter, treepath);
378 gtk_tree_model_get (model, &iter,
379 COL_ACCOUNT_POINTER, &account,
381 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
384 gtk_tree_path_free (treepath);
386 mc_account_set_display_name (account, new_text);
387 g_object_unref (account);
391 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
394 GtkTreeViewColumn *column;
395 GtkCellRenderer *cell;
397 view = GTK_TREE_VIEW (dialog->treeview);
398 gtk_tree_view_set_headers_visible (view, TRUE);
400 /* account name/status */
401 column = gtk_tree_view_column_new ();
402 gtk_tree_view_column_set_title (column, _("Accounts"));
404 cell = gtk_cell_renderer_pixbuf_new ();
405 gtk_tree_view_column_pack_start (column, cell, FALSE);
406 gtk_tree_view_column_set_cell_data_func (column, cell,
407 (GtkTreeCellDataFunc)
408 accounts_dialog_model_pixbuf_data_func,
412 cell = gtk_cell_renderer_text_new ();
414 "ellipsize", PANGO_ELLIPSIZE_END,
417 gtk_tree_view_column_pack_start (column, cell, TRUE);
418 gtk_tree_view_column_add_attribute (column,
421 g_signal_connect (cell, "edited",
422 G_CALLBACK (accounts_dialog_name_edited_cb),
425 gtk_tree_view_column_set_expand (column, TRUE);
426 gtk_tree_view_append_column (view, column);
430 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
434 GtkTreeSelection *selection;
438 view = GTK_TREE_VIEW (dialog->treeview);
439 model = gtk_tree_view_get_model (view);
441 if (gtk_tree_model_get_iter_first (model, &iter)) {
442 selection = gtk_tree_view_get_selection (view);
443 gtk_tree_selection_select_iter (selection, &iter);
445 accounts_dialog_update_account (dialog, NULL);
450 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
451 GtkCellRenderer *cell,
454 EmpathyAccountsDialog *dialog)
457 const gchar *icon_name;
459 TpConnectionStatus status;
461 gtk_tree_model_get (model, iter,
463 COL_ACCOUNT_POINTER, &account,
466 icon_name = empathy_icon_name_from_account (account);
467 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
470 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
471 (status == TP_CONNECTION_STATUS_CONNECTING &&
472 !dialog->connecting_show)) {
473 GdkPixbuf *modded_pixbuf;
475 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
478 gdk_pixbuf_get_width (pixbuf),
479 gdk_pixbuf_get_height (pixbuf));
481 gdk_pixbuf_saturate_and_pixelate (pixbuf,
485 g_object_unref (pixbuf);
486 pixbuf = modded_pixbuf;
495 g_object_unref (account);
497 g_object_unref (pixbuf);
502 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
506 GtkTreeSelection *selection;
510 view = GTK_TREE_VIEW (dialog->treeview);
511 selection = gtk_tree_view_get_selection (view);
513 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
517 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
523 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
527 GtkTreeSelection *selection;
532 view = GTK_TREE_VIEW (dialog->treeview);
533 model = gtk_tree_view_get_model (view);
534 selection = gtk_tree_view_get_selection (view);
536 for (ok = gtk_tree_model_get_iter_first (model, &iter);
538 ok = gtk_tree_model_iter_next (model, &iter)) {
539 McAccount *this_account;
542 gtk_tree_model_get (model, &iter,
543 COL_ACCOUNT_POINTER, &this_account,
546 equal = empathy_account_equal (this_account, account);
547 g_object_unref (this_account);
550 gtk_tree_selection_select_iter (selection, &iter);
557 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
561 GtkTreeSelection *selection;
564 view = GTK_TREE_VIEW (dialog->treeview);
565 selection = gtk_tree_view_get_selection (view);
567 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
571 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
575 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
576 EmpathyAccountsDialog *dialog)
581 gboolean is_selection;
583 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
585 gtk_widget_set_sensitive (dialog->button_add, TRUE);
586 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
587 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
589 accounts_dialog_update_connect_button (dialog);
591 account = accounts_dialog_model_get_selected (dialog);
592 accounts_dialog_update_account (dialog, account);
595 g_object_unref (account);
598 /* insure new account frame is hidden when a row is selected*/
599 gtk_widget_hide (dialog->frame_new_account);
603 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
606 TpConnectionStatus status;
614 view = GTK_TREE_VIEW (dialog->treeview);
615 model = gtk_tree_view_get_model (view);
616 store = GTK_LIST_STORE (model);
618 for (ok = gtk_tree_model_get_iter_first (model, &iter);
620 ok = gtk_tree_model_iter_next (model, &iter)) {
621 McAccount *this_account;
624 gtk_tree_model_get (model, &iter,
625 COL_ACCOUNT_POINTER, &this_account,
628 equal = empathy_account_equal (this_account, account);
629 g_object_unref (this_account);
636 status = mission_control_get_connection_status (dialog->mc, account, NULL);
637 name = mc_account_get_display_name (account);
639 g_return_if_fail (name != NULL);
641 empathy_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
643 gtk_list_store_insert_with_values (store, &iter,
647 COL_ACCOUNT_POINTER, account,
652 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
654 EmpathyAccountsDialog *dialog)
658 account = mc_account_lookup (unique_name);
659 accounts_dialog_add_account (dialog, account);
660 g_object_unref (account);
664 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
666 EmpathyAccountsDialog *dialog)
670 account = mc_account_lookup (unique_name);
672 accounts_dialog_model_set_selected (dialog, account);
673 accounts_dialog_model_remove_selected (dialog);
675 g_object_unref (account);
679 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
684 gtk_tree_model_row_changed (model, path, iter);
690 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
695 dialog->connecting_show = !dialog->connecting_show;
697 view = GTK_TREE_VIEW (dialog->treeview);
698 model = gtk_tree_view_get_model (view);
700 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
706 accounts_dialog_status_changed_cb (MissionControl *mc,
707 TpConnectionStatus status,
709 TpConnectionStatusReason reason,
710 const gchar *unique_name,
711 EmpathyAccountsDialog *dialog)
714 GtkTreeSelection *selection;
720 gboolean found = FALSE;
722 /* Update the status in the model */
723 view = GTK_TREE_VIEW (dialog->treeview);
724 selection = gtk_tree_view_get_selection (view);
725 model = gtk_tree_view_get_model (view);
726 account = mc_account_lookup (unique_name);
728 empathy_debug (DEBUG_DOMAIN, "Status changed for account %s: "
729 "status=%d presence=%d",
730 unique_name, status, presence);
732 for (ok = gtk_tree_model_get_iter_first (model, &iter);
734 ok = gtk_tree_model_iter_next (model, &iter)) {
735 McAccount *this_account;
738 gtk_tree_model_get (model, &iter,
739 COL_ACCOUNT_POINTER, &this_account,
742 equal = empathy_account_equal (this_account, account);
743 g_object_unref (this_account);
748 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
752 path = gtk_tree_model_get_path (model, &iter);
753 gtk_tree_model_row_changed (model, path, &iter);
754 gtk_tree_path_free (path);
759 g_object_unref (account);
761 /* Check if there is still accounts in CONNECTING state */
762 accounts = mc_accounts_list ();
763 for (l = accounts; l; l = l->next) {
764 McAccount *this_account;
765 TpConnectionStatus status;
767 this_account = l->data;
769 status = mission_control_get_connection_status (mc, this_account, NULL);
770 if (status == TP_CONNECTION_STATUS_CONNECTING) {
775 g_object_unref (this_account);
777 g_list_free (accounts);
779 if (!found && dialog->connecting_id) {
780 g_source_remove (dialog->connecting_id);
781 dialog->connecting_id = 0;
783 if (found && !dialog->connecting_id) {
784 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
785 (GSourceFunc) accounts_dialog_flash_connecting_cb,
791 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
792 EmpathyAccountsDialog *dialog)
799 gtk_widget_show (dialog->vbox_details);
800 gtk_widget_hide (dialog->frame_no_account);
801 gtk_widget_hide (dialog->frame_new_account);
803 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
806 account = mc_account_create (profile);
808 str = mc_account_get_unique_name (account);
809 mc_account_set_display_name (account, str);
811 accounts_dialog_add_account (dialog, account);
812 accounts_dialog_model_set_selected (dialog, account);
814 g_object_unref (account);
815 g_object_unref (profile);
819 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
820 EmpathyAccountsDialog *dialog)
824 gtk_widget_hide (dialog->vbox_details);
825 gtk_widget_hide (dialog->frame_no_account);
826 gtk_widget_hide (dialog->frame_new_account);
828 gtk_widget_set_sensitive (dialog->button_add, TRUE);
830 account = accounts_dialog_model_get_selected (dialog);
831 accounts_dialog_update_account (dialog, account);
835 accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
836 EmpathyAccountsDialog *dialog)
841 account = accounts_dialog_model_get_selected (dialog);
842 enable = (!mc_account_is_enabled (account));
843 mc_account_set_enabled (account, enable);
844 accounts_dialog_update_connect_button (dialog);
846 g_object_unref (account);
850 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
851 EmpathyAccountsDialog *dialog)
854 GtkTreeSelection *selection;
856 view = GTK_TREE_VIEW (dialog->treeview);
857 selection = gtk_tree_view_get_selection (view);
858 gtk_tree_selection_unselect_all (selection);
860 gtk_widget_set_sensitive (dialog->button_add, FALSE);
861 gtk_widget_hide (dialog->vbox_details);
862 gtk_widget_hide (dialog->frame_no_account);
863 gtk_widget_show (dialog->frame_new_account);
865 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
866 gtk_widget_grab_focus (dialog->combobox_profile);
870 accounts_dialog_remove_response_cb (GtkWidget *dialog,
874 if (response == GTK_RESPONSE_YES) {
875 mc_account_delete (account);
878 gtk_widget_destroy (dialog);
882 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
883 EmpathyAccountsDialog *dialog)
886 GtkWidget *message_dialog;
888 account = accounts_dialog_model_get_selected (dialog);
890 if (!mc_account_is_complete (account)) {
891 accounts_dialog_model_remove_selected (dialog);
894 message_dialog = gtk_message_dialog_new
895 (GTK_WINDOW (dialog->window),
896 GTK_DIALOG_DESTROY_WITH_PARENT,
897 GTK_MESSAGE_QUESTION,
899 _("You are about to remove your %s account!\n"
900 "Are you sure you want to proceed?"),
901 mc_account_get_display_name (account));
903 gtk_message_dialog_format_secondary_text
904 (GTK_MESSAGE_DIALOG (message_dialog),
905 _("Any associated conversations and chat rooms will NOT be "
906 "removed if you decide to proceed.\n"
908 "Should you decide to add the account back at a later time, "
909 "they will still be available."));
911 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
914 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
918 g_signal_connect (message_dialog, "response",
919 G_CALLBACK (accounts_dialog_remove_response_cb),
922 gtk_widget_show (message_dialog);
926 accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
928 GtkTreeViewColumn *column,
929 EmpathyAccountsDialog *dialog)
932 accounts_dialog_button_connect_clicked_cb (dialog->button_connect,
937 accounts_dialog_response_cb (GtkWidget *widget,
939 EmpathyAccountsDialog *dialog)
941 gtk_widget_destroy (widget);
945 accounts_dialog_destroy_cb (GtkWidget *widget,
946 EmpathyAccountsDialog *dialog)
950 /* Disconnect signals */
951 g_signal_handlers_disconnect_by_func (dialog->monitor,
952 accounts_dialog_account_added_cb,
954 g_signal_handlers_disconnect_by_func (dialog->monitor,
955 accounts_dialog_account_removed_cb,
957 g_signal_handlers_disconnect_by_func (dialog->monitor,
958 accounts_dialog_update_connect_button,
960 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog->mc),
961 "AccountStatusChanged",
962 G_CALLBACK (accounts_dialog_status_changed_cb),
965 /* Delete incomplete accounts */
966 accounts = mc_accounts_list ();
967 for (l = accounts; l; l = l->next) {
971 if (!mc_account_is_complete (account)) {
972 /* FIXME: Warn the user the account is not complete
973 * and is going to be removed. */
974 mc_account_delete (account);
977 g_object_unref (account);
979 g_list_free (accounts);
981 if (dialog->connecting_id) {
982 g_source_remove (dialog->connecting_id);
985 g_object_unref (dialog->mc);
986 g_object_unref (dialog->monitor);
992 empathy_accounts_dialog_show (GtkWindow *parent)
994 static EmpathyAccountsDialog *dialog = NULL;
997 GtkWidget *button_close;
1000 gtk_window_present (GTK_WINDOW (dialog->window));
1001 return dialog->window;
1004 dialog = g_new0 (EmpathyAccountsDialog, 1);
1006 glade = empathy_glade_get_file ("empathy-accounts-dialog.glade",
1009 "accounts_dialog", &dialog->window,
1010 "vbox_details", &dialog->vbox_details,
1011 "frame_no_account", &dialog->frame_no_account,
1012 "label_no_account", &dialog->label_no_account,
1013 "label_no_account_blurb", &dialog->label_no_account_blurb,
1014 "alignment_settings", &dialog->alignment_settings,
1015 "dialog-action_area", &bbox,
1016 "treeview", &dialog->treeview,
1017 "frame_new_account", &dialog->frame_new_account,
1018 "hbox_type", &dialog->hbox_type,
1019 "button_create", &dialog->button_create,
1020 "button_back", &dialog->button_back,
1021 "image_type", &dialog->image_type,
1022 "label_name", &dialog->label_name,
1023 "button_add", &dialog->button_add,
1024 "button_remove", &dialog->button_remove,
1025 "button_connect", &dialog->button_connect,
1026 "button_close", &button_close,
1029 empathy_glade_connect (glade,
1031 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1032 "accounts_dialog", "response", accounts_dialog_response_cb,
1033 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1034 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1035 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
1036 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
1037 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1038 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1041 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1043 g_object_unref (glade);
1045 /* Create profile chooser */
1046 dialog->combobox_profile = empathy_profile_chooser_new ();
1047 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1048 dialog->combobox_profile,
1050 gtk_widget_show (dialog->combobox_profile);
1051 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) <= 0) {
1052 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1055 /* Set up signalling */
1056 dialog->mc = empathy_mission_control_new ();
1057 dialog->monitor = mc_account_monitor_new ();
1059 g_signal_connect (dialog->monitor, "account-created",
1060 G_CALLBACK (accounts_dialog_account_added_cb),
1062 g_signal_connect (dialog->monitor, "account-deleted",
1063 G_CALLBACK (accounts_dialog_account_removed_cb),
1065 g_signal_connect_swapped (dialog->monitor, "account-enabled",
1066 G_CALLBACK (accounts_dialog_update_connect_button),
1068 g_signal_connect_swapped (dialog->monitor, "account-disabled",
1069 G_CALLBACK (accounts_dialog_update_connect_button),
1071 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog->mc), "AccountStatusChanged",
1072 G_CALLBACK (accounts_dialog_status_changed_cb),
1075 accounts_dialog_model_setup (dialog);
1076 accounts_dialog_setup (dialog);
1077 accounts_dialog_model_select_first (dialog);
1080 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1081 GTK_WINDOW (parent));
1084 gtk_widget_show (dialog->window);
1086 return dialog->window;