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-session.h>
42 #include <libempathy/gossip-debug.h>
43 #include <libempathy/gossip-paths.h>
44 #include <libempathy/gossip-utils.h>
45 #include <libempathy-gtk/gossip-ui-utils.h>
47 #include "gossip-accounts-dialog.h"
48 #include "gossip-profile-chooser.h"
49 #include "gossip-account-widget-generic.h"
50 #include "gossip-account-widget-jabber.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_remove;
70 GtkWidget *button_connect;
72 GtkWidget *frame_new_account;
73 GtkWidget *combobox_profile;
74 GtkWidget *entry_name;
75 GtkWidget *table_new_account;
76 GtkWidget *button_create;
77 GtkWidget *button_cancel;
79 GtkWidget *image_type;
80 GtkWidget *label_name;
81 GtkWidget *label_type;
82 GtkWidget *settings_widget;
84 gboolean connecting_show;
86 gboolean account_changed;
87 } GossipAccountsDialog;
96 static void accounts_dialog_setup (GossipAccountsDialog *dialog);
97 static void accounts_dialog_update_account (GossipAccountsDialog *dialog,
99 static void accounts_dialog_model_setup (GossipAccountsDialog *dialog);
100 static void accounts_dialog_model_add_columns (GossipAccountsDialog *dialog);
101 static void accounts_dialog_model_select_first (GossipAccountsDialog *dialog);
102 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
103 GtkCellRenderer *cell,
106 GossipAccountsDialog *dialog);
107 static McAccount *accounts_dialog_model_get_selected (GossipAccountsDialog *dialog);
108 static void accounts_dialog_model_set_selected (GossipAccountsDialog *dialog,
110 static gboolean accounts_dialog_model_remove_selected (GossipAccountsDialog *dialog);
111 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
112 GossipAccountsDialog *dialog);
113 static void accounts_dialog_add_account (GossipAccountsDialog *dialog,
115 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
117 GossipAccountsDialog *dialog);
118 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
120 GossipAccountsDialog *dialog);
121 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
125 static gboolean accounts_dialog_flash_connecting_cb (GossipAccountsDialog *dialog);
126 static void accounts_dialog_status_changed_cb (MissionControl *mc,
127 TelepathyConnectionStatus status,
129 TelepathyConnectionStatusReason reason,
130 const gchar *unique_name,
131 GossipAccountsDialog *dialog);
132 static void accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
133 GossipAccountsDialog *dialog);
134 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
135 GossipAccountsDialog *dialog);
136 static void accounts_dialog_button_cancel_clicked_cb (GtkWidget *button,
137 GossipAccountsDialog *dialog);
138 static void accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
139 GossipAccountsDialog *dialog);
140 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
141 GossipAccountsDialog *dialog);
142 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
145 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
146 GossipAccountsDialog *dialog);
147 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
149 GtkTreeViewColumn *column,
150 GossipAccountsDialog *dialog);
151 static void accounts_dialog_response_cb (GtkWidget *widget,
153 GossipAccountsDialog *dialog);
154 static void accounts_dialog_destroy_cb (GtkWidget *widget,
155 GossipAccountsDialog *dialog);
158 accounts_dialog_setup (GossipAccountsDialog *dialog)
162 GtkTreeSelection *selection;
167 view = GTK_TREE_VIEW (dialog->treeview);
168 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
169 selection = gtk_tree_view_get_selection (view);
171 mc = empathy_session_get_mission_control ();
172 accounts = mc_accounts_list ();
174 for (l = accounts; l; l = l->next) {
177 TelepathyConnectionStatus status;
181 name = mc_account_get_display_name (account);
186 status = mission_control_get_connection_status (mc, account, NULL);
188 gtk_list_store_append (store, &iter);
189 gtk_list_store_set (store, &iter,
192 COL_ACCOUNT_POINTER, account,
195 accounts_dialog_status_changed_cb (mc,
198 TP_CONN_STATUS_REASON_NONE_SPECIFIED,
199 mc_account_get_unique_name (account),
202 g_object_unref (account);
205 g_list_free (accounts);
209 accounts_dialog_update_connect_button (GossipAccountsDialog *dialog)
213 const gchar *stock_id;
216 account = accounts_dialog_model_get_selected (dialog);
219 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
223 if (mc_account_is_enabled (account)) {
224 label = _("Disable");
225 stock_id = GTK_STOCK_DISCONNECT;
228 stock_id = GTK_STOCK_CONNECT;
231 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
233 gtk_button_set_label (GTK_BUTTON (dialog->button_connect), label);
234 gtk_button_set_image (GTK_BUTTON (dialog->button_connect), image);
238 accounts_dialog_update_account (GossipAccountsDialog *dialog,
241 if (dialog->settings_widget) {
242 gtk_widget_destroy (dialog->settings_widget);
243 dialog->settings_widget = NULL;
250 gtk_widget_show (dialog->frame_no_account);
251 gtk_widget_hide (dialog->vbox_details);
253 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
254 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
256 view = GTK_TREE_VIEW (dialog->treeview);
257 model = gtk_tree_view_get_model (view);
259 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
260 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
261 _("<b>No Account Selected</b>"));
262 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
263 _("To add a new account, you can click on the "
264 "'Add' button and a new entry will be created "
265 "for you to start configuring.\n"
267 "If you do not want to add an account, simply "
268 "click on the account you want to configure in "
269 "the list on the left."));
271 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
272 _("<b>No Accounts Configured</b>"));
273 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
274 _("To add a new account, you can click on the "
275 "'Add' button and a new entry will be created "
276 "for you to start configuring."));
280 const gchar *config_ui;
282 gtk_widget_hide (dialog->frame_no_account);
283 gtk_widget_show (dialog->vbox_details);
285 profile = mc_account_get_profile (account);
286 config_ui = mc_profile_get_configuration_ui (profile);
288 if (strcmp (config_ui, "jabber") == 0) {
289 dialog->settings_widget =
290 gossip_account_widget_jabber_new (account);
292 dialog->settings_widget =
293 gossip_account_widget_generic_new (account,
297 gtk_widget_grab_focus (dialog->settings_widget);
300 if (dialog->settings_widget) {
301 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
302 dialog->settings_widget);
309 pixbuf = gossip_pixbuf_from_account (account, GTK_ICON_SIZE_DIALOG);
310 gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->image_type), pixbuf);
312 g_object_unref (pixbuf);
315 profile = mc_account_get_profile (account);
317 gtk_label_set_text (GTK_LABEL (dialog->label_type),
318 mc_profile_get_display_name (profile));
319 gtk_label_set_text (GTK_LABEL (dialog->label_name),
320 mc_account_get_display_name (account));
325 accounts_dialog_model_setup (GossipAccountsDialog *dialog)
328 GtkTreeSelection *selection;
330 store = gtk_list_store_new (COL_COUNT,
331 G_TYPE_STRING, /* name */
332 G_TYPE_UINT, /* status */
333 MC_TYPE_ACCOUNT); /* account */
335 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
336 GTK_TREE_MODEL (store));
338 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
339 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
341 g_signal_connect (selection, "changed",
342 G_CALLBACK (accounts_dialog_model_selection_changed),
345 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
346 COL_NAME, GTK_SORT_ASCENDING);
348 accounts_dialog_model_add_columns (dialog);
350 g_object_unref (store);
354 accounts_dialog_model_add_columns (GossipAccountsDialog *dialog)
357 GtkTreeViewColumn *column;
358 GtkCellRenderer *cell;
360 view = GTK_TREE_VIEW (dialog->treeview);
361 gtk_tree_view_set_headers_visible (view, TRUE);
363 /* account name/status */
364 column = gtk_tree_view_column_new ();
365 gtk_tree_view_column_set_title (column, _("Accounts"));
367 cell = gtk_cell_renderer_pixbuf_new ();
368 gtk_tree_view_column_pack_start (column, cell, FALSE);
369 gtk_tree_view_column_set_cell_data_func (column, cell,
370 (GtkTreeCellDataFunc)
371 accounts_dialog_model_pixbuf_data_func,
375 cell = gtk_cell_renderer_text_new ();
376 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
377 gtk_tree_view_column_pack_start (column, cell, TRUE);
378 gtk_tree_view_column_add_attribute (column,
382 gtk_tree_view_column_set_expand (column, TRUE);
383 gtk_tree_view_append_column (view, column);
387 accounts_dialog_model_select_first (GossipAccountsDialog *dialog)
391 GtkTreeSelection *selection;
395 view = GTK_TREE_VIEW (dialog->treeview);
396 model = gtk_tree_view_get_model (view);
398 if (gtk_tree_model_get_iter_first (model, &iter)) {
399 selection = gtk_tree_view_get_selection (view);
400 gtk_tree_selection_select_iter (selection, &iter);
402 accounts_dialog_update_account (dialog, NULL);
407 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
408 GtkCellRenderer *cell,
411 GossipAccountsDialog *dialog)
415 TelepathyConnectionStatus status;
417 gtk_tree_model_get (model, iter,
419 COL_ACCOUNT_POINTER, &account,
422 pixbuf = gossip_pixbuf_from_account (account, GTK_ICON_SIZE_BUTTON);
425 if (status == TP_CONN_STATUS_DISCONNECTED ||
426 (status == TP_CONN_STATUS_CONNECTING &&
427 !dialog->connecting_show)) {
428 GdkPixbuf *modded_pixbuf;
430 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
433 gdk_pixbuf_get_width (pixbuf),
434 gdk_pixbuf_get_height (pixbuf));
436 gdk_pixbuf_saturate_and_pixelate (pixbuf,
440 g_object_unref (pixbuf);
441 pixbuf = modded_pixbuf;
450 g_object_unref (account);
452 g_object_unref (pixbuf);
457 accounts_dialog_model_get_selected (GossipAccountsDialog *dialog)
461 GtkTreeSelection *selection;
465 view = GTK_TREE_VIEW (dialog->treeview);
466 selection = gtk_tree_view_get_selection (view);
468 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
472 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
478 accounts_dialog_model_set_selected (GossipAccountsDialog *dialog,
482 GtkTreeSelection *selection;
487 view = GTK_TREE_VIEW (dialog->treeview);
488 model = gtk_tree_view_get_model (view);
489 selection = gtk_tree_view_get_selection (view);
491 for (ok = gtk_tree_model_get_iter_first (model, &iter);
493 ok = gtk_tree_model_iter_next (model, &iter)) {
494 McAccount *this_account;
497 gtk_tree_model_get (model, &iter,
498 COL_ACCOUNT_POINTER, &this_account,
501 equal = gossip_account_equal (this_account, account);
502 g_object_unref (this_account);
505 gtk_tree_selection_select_iter (selection, &iter);
512 accounts_dialog_model_remove_selected (GossipAccountsDialog *dialog)
516 GtkTreeSelection *selection;
519 view = GTK_TREE_VIEW (dialog->treeview);
520 selection = gtk_tree_view_get_selection (view);
522 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
526 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
530 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
531 GossipAccountsDialog *dialog)
536 gboolean is_selection;
538 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
540 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
541 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
543 accounts_dialog_update_connect_button (dialog);
545 account = accounts_dialog_model_get_selected (dialog);
546 accounts_dialog_update_account (dialog, account);
549 g_object_unref (account);
554 accounts_dialog_add_account (GossipAccountsDialog *dialog,
558 TelepathyConnectionStatus status;
566 view = GTK_TREE_VIEW (dialog->treeview);
567 model = gtk_tree_view_get_model (view);
568 store = GTK_LIST_STORE (model);
570 for (ok = gtk_tree_model_get_iter_first (model, &iter);
572 ok = gtk_tree_model_iter_next (model, &iter)) {
573 McAccount *this_account;
576 gtk_tree_model_get (model, &iter,
577 COL_ACCOUNT_POINTER, &this_account,
580 equal = gossip_account_equal (this_account, account);
581 g_object_unref (this_account);
588 mc = empathy_session_get_mission_control ();
589 status = mission_control_get_connection_status (mc, account, NULL);
590 name = mc_account_get_display_name (account);
592 g_return_if_fail (name != NULL);
594 gossip_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
596 gtk_list_store_append (store, &iter);
597 gtk_list_store_set (store, &iter,
600 COL_ACCOUNT_POINTER, account,
605 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
607 GossipAccountsDialog *dialog)
611 account = mc_account_lookup (unique_name);
612 accounts_dialog_add_account (dialog, account);
613 g_object_unref (account);
617 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
619 GossipAccountsDialog *dialog)
624 mc = empathy_session_get_mission_control ();
625 account = mc_account_lookup (unique_name);
627 accounts_dialog_model_set_selected (dialog, account);
628 accounts_dialog_model_remove_selected (dialog);
630 g_object_unref (account);
634 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
639 gtk_tree_model_row_changed (model, path, iter);
645 accounts_dialog_flash_connecting_cb (GossipAccountsDialog *dialog)
650 dialog->connecting_show = !dialog->connecting_show;
652 view = GTK_TREE_VIEW (dialog->treeview);
653 model = gtk_tree_view_get_model (view);
655 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
661 accounts_dialog_status_changed_cb (MissionControl *mc,
662 TelepathyConnectionStatus status,
664 TelepathyConnectionStatusReason reason,
665 const gchar *unique_name,
666 GossipAccountsDialog *dialog)
669 GtkTreeSelection *selection;
675 gboolean found = FALSE;
677 /* Update the status in the model */
678 view = GTK_TREE_VIEW (dialog->treeview);
679 selection = gtk_tree_view_get_selection (view);
680 model = gtk_tree_view_get_model (view);
681 account = mc_account_lookup (unique_name);
683 for (ok = gtk_tree_model_get_iter_first (model, &iter);
685 ok = gtk_tree_model_iter_next (model, &iter)) {
686 McAccount *this_account;
689 gtk_tree_model_get (model, &iter,
690 COL_ACCOUNT_POINTER, &this_account,
693 equal = gossip_account_equal (this_account, account);
694 g_object_unref (this_account);
699 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
703 path = gtk_tree_model_get_path (model, &iter);
704 gtk_tree_model_row_changed (model, path, &iter);
705 gtk_tree_path_free (path);
711 g_object_unref (account);
713 /* Start to flash account if status is connecting */
714 if (status == TP_CONN_STATUS_CONNECTING) {
715 if (!dialog->connecting_id) {
716 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
717 (GSourceFunc) accounts_dialog_flash_connecting_cb,
724 /* Stop to flash if no account is connecting */
725 accounts = mc_accounts_list ();
726 for (l = accounts; l; l = l->next) {
727 McAccount *this_account;
729 this_account = l->data;
731 if (mission_control_get_connection_status (mc, this_account, NULL) == TP_CONN_STATUS_CONNECTING) {
736 g_object_unref (this_account);
738 g_list_free (accounts);
740 if (!found && dialog->connecting_id) {
741 g_source_remove (dialog->connecting_id);
742 dialog->connecting_id = 0;
747 accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
748 GossipAccountsDialog *dialog)
752 str = gtk_entry_get_text (GTK_ENTRY (widget));
753 gtk_widget_set_sensitive (dialog->button_create, !G_STR_EMPTY (str));
757 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
758 GossipAccountsDialog *dialog)
765 gtk_widget_show (dialog->vbox_details);
766 gtk_widget_hide (dialog->frame_no_account);
767 gtk_widget_hide (dialog->frame_new_account);
769 profile = gossip_profile_chooser_get_selected (dialog->combobox_profile);
772 account = mc_account_create (profile);
774 str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_name));
775 mc_account_set_display_name (account, str);
777 accounts_dialog_add_account (dialog, account);
778 accounts_dialog_model_set_selected (dialog, account);
780 g_object_unref (account);
781 g_object_unref (profile);
785 accounts_dialog_button_cancel_clicked_cb (GtkWidget *button,
786 GossipAccountsDialog *dialog)
790 gtk_widget_hide (dialog->vbox_details);
791 gtk_widget_hide (dialog->frame_no_account);
792 gtk_widget_hide (dialog->frame_new_account);
794 account = accounts_dialog_model_get_selected (dialog);
795 accounts_dialog_update_account (dialog, account);
799 accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
800 GossipAccountsDialog *dialog)
805 account = accounts_dialog_model_get_selected (dialog);
806 enable = (!mc_account_is_enabled (account));
807 mc_account_set_enabled (account, enable);
808 accounts_dialog_update_connect_button (dialog);
810 g_object_unref (account);
814 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
815 GossipAccountsDialog *dialog)
817 gtk_widget_hide (dialog->vbox_details);
818 gtk_widget_hide (dialog->frame_no_account);
819 gtk_widget_show (dialog->frame_new_account);
821 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
822 gtk_entry_set_text (GTK_ENTRY (dialog->entry_name), "");
823 gtk_widget_grab_focus (dialog->entry_name);
827 accounts_dialog_remove_response_cb (GtkWidget *dialog,
831 if (response == GTK_RESPONSE_YES) {
832 mc_account_delete (account);
835 gtk_widget_destroy (dialog);
839 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
840 GossipAccountsDialog *dialog)
843 GtkWidget *message_dialog;
845 account = accounts_dialog_model_get_selected (dialog);
847 if (!mc_account_is_complete (account)) {
848 accounts_dialog_model_remove_selected (dialog);
851 message_dialog = gtk_message_dialog_new
852 (GTK_WINDOW (dialog->window),
853 GTK_DIALOG_DESTROY_WITH_PARENT,
854 GTK_MESSAGE_QUESTION,
856 _("You are about to remove your %s account!\n"
857 "Are you sure you want to proceed?"),
858 mc_account_get_display_name (account));
860 gtk_message_dialog_format_secondary_text
861 (GTK_MESSAGE_DIALOG (message_dialog),
862 _("Any associated conversations and chat rooms will NOT be "
863 "removed if you decide to proceed.\n"
865 "Should you decide to add the account back at a later time, "
866 "they will still be available."));
868 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
871 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
875 g_signal_connect (message_dialog, "response",
876 G_CALLBACK (accounts_dialog_remove_response_cb),
879 gtk_widget_show (message_dialog);
883 accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
885 GtkTreeViewColumn *column,
886 GossipAccountsDialog *dialog)
889 accounts_dialog_button_connect_clicked_cb (dialog->button_connect,
894 accounts_dialog_response_cb (GtkWidget *widget,
896 GossipAccountsDialog *dialog)
898 gtk_widget_destroy (widget);
902 accounts_dialog_destroy_cb (GtkWidget *widget,
903 GossipAccountsDialog *dialog)
906 McAccountMonitor *monitor;
909 mc = empathy_session_get_mission_control ();
910 monitor = mc_account_monitor_new ();
912 /* Disconnect signals */
913 g_signal_handlers_disconnect_by_func (monitor,
914 accounts_dialog_account_added_cb,
916 g_signal_handlers_disconnect_by_func (monitor,
917 accounts_dialog_account_removed_cb,
919 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (mc), "AccountStatusChanged",
920 G_CALLBACK (accounts_dialog_status_changed_cb),
923 /* Delete incomplete accounts */
924 accounts = mc_accounts_list ();
925 for (l = accounts; l; l = l->next) {
929 if (!mc_account_is_complete (account)) {
930 /* FIXME: Warn the user the account is not complete
931 * and is going to be removed. */
932 mc_account_delete (account);
935 g_object_unref (account);
937 g_list_free (accounts);
939 if (dialog->connecting_id) {
940 g_source_remove (dialog->connecting_id);
947 gossip_accounts_dialog_show (void)
949 static GossipAccountsDialog *dialog = NULL;
951 McAccountMonitor *monitor;
954 GtkWidget *button_close;
957 gtk_window_present (GTK_WINDOW (dialog->window));
958 return dialog->window;
961 dialog = g_new0 (GossipAccountsDialog, 1);
963 glade = gossip_glade_get_file ("gossip-accounts-dialog.glade",
966 "accounts_dialog", &dialog->window,
967 "vbox_details", &dialog->vbox_details,
968 "frame_no_account", &dialog->frame_no_account,
969 "label_no_account", &dialog->label_no_account,
970 "label_no_account_blurb", &dialog->label_no_account_blurb,
971 "alignment_settings", &dialog->alignment_settings,
972 "dialog-action_area", &bbox,
973 "treeview", &dialog->treeview,
974 "frame_new_account", &dialog->frame_new_account,
975 "entry_name", &dialog->entry_name,
976 "table_new_account", &dialog->table_new_account,
977 "button_create", &dialog->button_create,
978 "button_cancel", &dialog->button_cancel,
979 "image_type", &dialog->image_type,
980 "label_type", &dialog->label_type,
981 "label_name", &dialog->label_name,
982 "button_remove", &dialog->button_remove,
983 "button_connect", &dialog->button_connect,
984 "button_close", &button_close,
987 gossip_glade_connect (glade,
989 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
990 "accounts_dialog", "response", accounts_dialog_response_cb,
991 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
992 "button_cancel", "clicked", accounts_dialog_button_cancel_clicked_cb,
993 "entry_name", "changed", accounts_dialog_entry_name_changed_cb,
994 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
995 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
996 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
997 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1000 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1002 g_object_unref (glade);
1004 /* Create profile chooser */
1005 dialog->combobox_profile = gossip_profile_chooser_new ();
1006 gtk_table_attach_defaults (GTK_TABLE (dialog->table_new_account),
1007 dialog->combobox_profile,
1010 gtk_widget_show (dialog->combobox_profile);
1012 /* Set up signalling */
1013 mc = empathy_session_get_mission_control ();
1014 monitor = mc_account_monitor_new ();
1016 /* FIXME: connect account-enabled/disabled too */
1017 g_signal_connect (monitor, "account-created",
1018 G_CALLBACK (accounts_dialog_account_added_cb),
1020 g_signal_connect (monitor, "account-deleted",
1021 G_CALLBACK (accounts_dialog_account_removed_cb),
1023 dbus_g_proxy_connect_signal (DBUS_G_PROXY (mc), "AccountStatusChanged",
1024 G_CALLBACK (accounts_dialog_status_changed_cb),
1027 accounts_dialog_model_setup (dialog);
1028 accounts_dialog_setup (dialog);
1030 gtk_widget_show (dialog->window);
1032 accounts_dialog_model_select_first (dialog);
1034 return dialog->window;