1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
30 #include <glade/glade.h>
31 #include <glib/gi18n.h>
32 #include <dbus/dbus-glib.h>
34 #include <libmissioncontrol/mc-account.h>
35 #include <libmissioncontrol/mc-profile.h>
36 #include <libmissioncontrol/mission-control.h>
37 #include <libmissioncontrol/mc-account-monitor.h>
38 #include <libtelepathy/tp-constants.h>
40 #include <libempathy/empathy-session.h>
41 #include <libempathy/gossip-debug.h>
42 #include <libempathy/gossip-paths.h>
43 #include <libempathy/gossip-utils.h>
44 #include <libempathy-gtk/gossip-ui-utils.h>
46 #include "gossip-accounts-dialog.h"
47 #include "gossip-profile-chooser.h"
48 #include "gossip-account-widget-generic.h"
50 #define DEBUG_DOMAIN "AccountDialog"
52 /* Flashing delay for icons (milliseconds). */
53 #define FLASH_TIMEOUT 500
58 GtkWidget *alignment_settings;
60 GtkWidget *vbox_details;
61 GtkWidget *frame_no_account;
62 GtkWidget *label_no_account;
63 GtkWidget *label_no_account_blurb;
67 GtkWidget *button_remove;
68 GtkWidget *button_connect;
70 GtkWidget *frame_new_account;
71 GtkWidget *combobox_profile;
72 GtkWidget *entry_name;
73 GtkWidget *table_new_account;
74 GtkWidget *button_create;
75 GtkWidget *button_cancel;
77 GtkWidget *image_type;
78 GtkWidget *label_name;
79 GtkWidget *label_type;
80 GtkWidget *settings_widget;
82 gboolean connecting_show;
84 gboolean account_changed;
85 } GossipAccountsDialog;
94 static void accounts_dialog_setup (GossipAccountsDialog *dialog);
95 static void accounts_dialog_update_account (GossipAccountsDialog *dialog,
97 static void accounts_dialog_model_setup (GossipAccountsDialog *dialog);
98 static void accounts_dialog_model_add_columns (GossipAccountsDialog *dialog);
99 static void accounts_dialog_model_select_first (GossipAccountsDialog *dialog);
100 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
101 GtkCellRenderer *cell,
104 GossipAccountsDialog *dialog);
105 static McAccount *accounts_dialog_model_get_selected (GossipAccountsDialog *dialog);
106 static void accounts_dialog_model_set_selected (GossipAccountsDialog *dialog,
108 static gboolean accounts_dialog_model_remove_selected (GossipAccountsDialog *dialog);
109 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
110 GossipAccountsDialog *dialog);
111 static void accounts_dialog_add_account (GossipAccountsDialog *dialog,
113 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
115 GossipAccountsDialog *dialog);
116 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
118 GossipAccountsDialog *dialog);
119 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
123 static gboolean accounts_dialog_flash_connecting_cb (GossipAccountsDialog *dialog);
124 static void accounts_dialog_status_changed_cb (MissionControl *mc,
125 TelepathyConnectionStatus status,
127 TelepathyConnectionStatusReason reason,
128 const gchar *unique_name,
129 GossipAccountsDialog *dialog);
130 static void accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
131 GossipAccountsDialog *dialog);
132 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
133 GossipAccountsDialog *dialog);
134 static void accounts_dialog_button_cancel_clicked_cb (GtkWidget *button,
135 GossipAccountsDialog *dialog);
136 static void accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
137 GossipAccountsDialog *dialog);
138 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
139 GossipAccountsDialog *dialog);
140 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
143 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
144 GossipAccountsDialog *dialog);
145 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
147 GtkTreeViewColumn *column,
148 GossipAccountsDialog *dialog);
149 static void accounts_dialog_response_cb (GtkWidget *widget,
151 GossipAccountsDialog *dialog);
152 static void accounts_dialog_destroy_cb (GtkWidget *widget,
153 GossipAccountsDialog *dialog);
156 accounts_dialog_setup (GossipAccountsDialog *dialog)
160 GtkTreeSelection *selection;
165 view = GTK_TREE_VIEW (dialog->treeview);
166 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
167 selection = gtk_tree_view_get_selection (view);
169 mc = empathy_session_get_mission_control ();
170 accounts = mc_accounts_list ();
172 for (l = accounts; l; l = l->next) {
175 TelepathyConnectionStatus status;
179 name = mc_account_get_display_name (account);
184 status = mission_control_get_connection_status (mc, account, NULL);
186 gtk_list_store_append (store, &iter);
187 gtk_list_store_set (store, &iter,
190 COL_ACCOUNT_POINTER, account,
193 accounts_dialog_status_changed_cb (mc,
196 TP_CONN_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 (GossipAccountsDialog *dialog)
211 const gchar *stock_id;
214 account = accounts_dialog_model_get_selected (dialog);
217 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
221 if (mc_account_is_enabled (account)) {
222 label = _("Disable");
223 stock_id = GTK_STOCK_DISCONNECT;
226 stock_id = GTK_STOCK_CONNECT;
229 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
231 gtk_button_set_label (GTK_BUTTON (dialog->button_connect), label);
232 gtk_button_set_image (GTK_BUTTON (dialog->button_connect), image);
236 accounts_dialog_update_account (GossipAccountsDialog *dialog,
239 if (dialog->settings_widget) {
240 gtk_widget_destroy (dialog->settings_widget);
241 dialog->settings_widget = NULL;
248 gtk_widget_show (dialog->frame_no_account);
249 gtk_widget_hide (dialog->vbox_details);
251 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
252 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
254 view = GTK_TREE_VIEW (dialog->treeview);
255 model = gtk_tree_view_get_model (view);
257 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
258 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
259 _("<b>No Account Selected</b>"));
260 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
261 _("To add a new account, you can click on the "
262 "'Add' button and a new entry will be created "
263 "for you to start configuring.\n"
265 "If you do not want to add an account, simply "
266 "click on the account you want to configure in "
267 "the list on the left."));
269 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
270 _("<b>No Accounts Configured</b>"));
271 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
272 _("To add a new account, you can click on the "
273 "'Add' button and a new entry will be created "
274 "for you to start configuring."));
278 const gchar *config_ui;
280 gtk_widget_hide (dialog->frame_no_account);
281 gtk_widget_show (dialog->vbox_details);
283 profile = mc_account_get_profile (account);
284 config_ui = mc_profile_get_configuration_ui (profile);
286 if (strcmp (config_ui, "blah") == 0) {
288 dialog->settings_widget =
289 gossip_account_widget_generic_new (account,
293 gtk_widget_grab_focus (dialog->settings_widget);
296 if (dialog->settings_widget) {
297 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
298 dialog->settings_widget);
305 pixbuf = gossip_pixbuf_from_account (account, GTK_ICON_SIZE_DIALOG);
306 gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->image_type), pixbuf);
308 g_object_unref (pixbuf);
311 profile = mc_account_get_profile (account);
313 gtk_label_set_text (GTK_LABEL (dialog->label_type),
314 mc_profile_get_display_name (profile));
315 gtk_label_set_text (GTK_LABEL (dialog->label_name),
316 mc_account_get_display_name (account));
321 accounts_dialog_model_setup (GossipAccountsDialog *dialog)
324 GtkTreeSelection *selection;
326 store = gtk_list_store_new (COL_COUNT,
327 G_TYPE_STRING, /* name */
328 G_TYPE_UINT, /* status */
329 MC_TYPE_ACCOUNT); /* account */
331 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
332 GTK_TREE_MODEL (store));
334 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
335 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
337 g_signal_connect (selection, "changed",
338 G_CALLBACK (accounts_dialog_model_selection_changed),
341 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
342 COL_NAME, GTK_SORT_ASCENDING);
344 accounts_dialog_model_add_columns (dialog);
346 g_object_unref (store);
350 accounts_dialog_model_add_columns (GossipAccountsDialog *dialog)
353 GtkTreeViewColumn *column;
354 GtkCellRenderer *cell;
356 view = GTK_TREE_VIEW (dialog->treeview);
357 gtk_tree_view_set_headers_visible (view, TRUE);
359 /* account name/status */
360 column = gtk_tree_view_column_new ();
361 gtk_tree_view_column_set_title (column, _("Accounts"));
363 cell = gtk_cell_renderer_pixbuf_new ();
364 gtk_tree_view_column_pack_start (column, cell, FALSE);
365 gtk_tree_view_column_set_cell_data_func (column, cell,
366 (GtkTreeCellDataFunc)
367 accounts_dialog_model_pixbuf_data_func,
371 cell = gtk_cell_renderer_text_new ();
372 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
373 gtk_tree_view_column_pack_start (column, cell, TRUE);
374 gtk_tree_view_column_add_attribute (column,
378 gtk_tree_view_column_set_expand (column, TRUE);
379 gtk_tree_view_append_column (view, column);
383 accounts_dialog_model_select_first (GossipAccountsDialog *dialog)
387 GtkTreeSelection *selection;
391 view = GTK_TREE_VIEW (dialog->treeview);
392 model = gtk_tree_view_get_model (view);
394 if (gtk_tree_model_get_iter_first (model, &iter)) {
395 selection = gtk_tree_view_get_selection (view);
396 gtk_tree_selection_select_iter (selection, &iter);
398 accounts_dialog_update_account (dialog, NULL);
403 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
404 GtkCellRenderer *cell,
407 GossipAccountsDialog *dialog)
411 TelepathyConnectionStatus status;
413 gtk_tree_model_get (model, iter,
415 COL_ACCOUNT_POINTER, &account,
418 pixbuf = gossip_pixbuf_from_account (account, GTK_ICON_SIZE_BUTTON);
421 if (status == TP_CONN_STATUS_DISCONNECTED ||
422 (status == TP_CONN_STATUS_CONNECTING &&
423 !dialog->connecting_show)) {
424 GdkPixbuf *modded_pixbuf;
426 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
429 gdk_pixbuf_get_width (pixbuf),
430 gdk_pixbuf_get_height (pixbuf));
432 gdk_pixbuf_saturate_and_pixelate (pixbuf,
436 g_object_unref (pixbuf);
437 pixbuf = modded_pixbuf;
446 g_object_unref (account);
448 g_object_unref (pixbuf);
453 accounts_dialog_model_get_selected (GossipAccountsDialog *dialog)
457 GtkTreeSelection *selection;
461 view = GTK_TREE_VIEW (dialog->treeview);
462 selection = gtk_tree_view_get_selection (view);
464 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
468 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
474 accounts_dialog_model_set_selected (GossipAccountsDialog *dialog,
478 GtkTreeSelection *selection;
483 view = GTK_TREE_VIEW (dialog->treeview);
484 model = gtk_tree_view_get_model (view);
485 selection = gtk_tree_view_get_selection (view);
487 for (ok = gtk_tree_model_get_iter_first (model, &iter);
489 ok = gtk_tree_model_iter_next (model, &iter)) {
490 McAccount *this_account;
493 gtk_tree_model_get (model, &iter,
494 COL_ACCOUNT_POINTER, &this_account,
497 equal = gossip_account_equal (this_account, account);
498 g_object_unref (this_account);
501 gtk_tree_selection_select_iter (selection, &iter);
508 accounts_dialog_model_remove_selected (GossipAccountsDialog *dialog)
512 GtkTreeSelection *selection;
515 view = GTK_TREE_VIEW (dialog->treeview);
516 selection = gtk_tree_view_get_selection (view);
518 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
522 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
526 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
527 GossipAccountsDialog *dialog)
532 gboolean is_selection;
534 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
536 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
537 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
539 accounts_dialog_update_connect_button (dialog);
541 account = accounts_dialog_model_get_selected (dialog);
542 accounts_dialog_update_account (dialog, account);
545 g_object_unref (account);
550 accounts_dialog_add_account (GossipAccountsDialog *dialog,
554 TelepathyConnectionStatus status;
562 view = GTK_TREE_VIEW (dialog->treeview);
563 model = gtk_tree_view_get_model (view);
564 store = GTK_LIST_STORE (model);
566 for (ok = gtk_tree_model_get_iter_first (model, &iter);
568 ok = gtk_tree_model_iter_next (model, &iter)) {
569 McAccount *this_account;
572 gtk_tree_model_get (model, &iter,
573 COL_ACCOUNT_POINTER, &this_account,
576 equal = gossip_account_equal (this_account, account);
577 g_object_unref (this_account);
584 mc = empathy_session_get_mission_control ();
585 status = mission_control_get_connection_status (mc, account, NULL);
586 name = mc_account_get_display_name (account);
588 g_return_if_fail (name != NULL);
590 gossip_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
592 gtk_list_store_append (store, &iter);
593 gtk_list_store_set (store, &iter,
596 COL_ACCOUNT_POINTER, account,
601 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
603 GossipAccountsDialog *dialog)
607 account = mc_account_lookup (unique_name);
608 accounts_dialog_add_account (dialog, account);
609 g_object_unref (account);
613 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
615 GossipAccountsDialog *dialog)
620 mc = empathy_session_get_mission_control ();
621 account = mc_account_lookup (unique_name);
623 accounts_dialog_model_set_selected (dialog, account);
624 accounts_dialog_model_remove_selected (dialog);
626 g_object_unref (account);
630 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
635 gtk_tree_model_row_changed (model, path, iter);
641 accounts_dialog_flash_connecting_cb (GossipAccountsDialog *dialog)
646 dialog->connecting_show = !dialog->connecting_show;
648 view = GTK_TREE_VIEW (dialog->treeview);
649 model = gtk_tree_view_get_model (view);
651 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
657 accounts_dialog_status_changed_cb (MissionControl *mc,
658 TelepathyConnectionStatus status,
660 TelepathyConnectionStatusReason reason,
661 const gchar *unique_name,
662 GossipAccountsDialog *dialog)
665 GtkTreeSelection *selection;
671 gboolean found = FALSE;
673 /* Update the status in the model */
674 view = GTK_TREE_VIEW (dialog->treeview);
675 selection = gtk_tree_view_get_selection (view);
676 model = gtk_tree_view_get_model (view);
677 account = mc_account_lookup (unique_name);
679 for (ok = gtk_tree_model_get_iter_first (model, &iter);
681 ok = gtk_tree_model_iter_next (model, &iter)) {
682 McAccount *this_account;
685 gtk_tree_model_get (model, &iter,
686 COL_ACCOUNT_POINTER, &this_account,
689 equal = gossip_account_equal (this_account, account);
690 g_object_unref (this_account);
695 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
699 path = gtk_tree_model_get_path (model, &iter);
700 gtk_tree_model_row_changed (model, path, &iter);
701 gtk_tree_path_free (path);
707 g_object_unref (account);
709 /* Start to flash account if status is connecting */
710 if (status == TP_CONN_STATUS_CONNECTING) {
711 if (!dialog->connecting_id) {
712 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
713 (GSourceFunc) accounts_dialog_flash_connecting_cb,
720 /* Stop to flash if no account is connecting */
721 accounts = mc_accounts_list ();
722 for (l = accounts; l; l = l->next) {
723 McAccount *this_account;
725 this_account = l->data;
727 if (mission_control_get_connection_status (mc, this_account, NULL) == TP_CONN_STATUS_CONNECTING) {
732 g_object_unref (this_account);
734 g_list_free (accounts);
736 if (!found && dialog->connecting_id) {
737 g_source_remove (dialog->connecting_id);
738 dialog->connecting_id = 0;
743 accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
744 GossipAccountsDialog *dialog)
748 str = gtk_entry_get_text (GTK_ENTRY (widget));
749 gtk_widget_set_sensitive (dialog->button_create, !G_STR_EMPTY (str));
753 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
754 GossipAccountsDialog *dialog)
761 gtk_widget_show (dialog->vbox_details);
762 gtk_widget_hide (dialog->frame_no_account);
763 gtk_widget_hide (dialog->frame_new_account);
765 profile = gossip_profile_chooser_get_selected (dialog->combobox_profile);
768 account = mc_account_create (profile);
770 str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_name));
771 mc_account_set_display_name (account, str);
773 accounts_dialog_add_account (dialog, account);
774 accounts_dialog_model_set_selected (dialog, account);
776 g_object_unref (account);
777 g_object_unref (profile);
781 accounts_dialog_button_cancel_clicked_cb (GtkWidget *button,
782 GossipAccountsDialog *dialog)
786 gtk_widget_hide (dialog->vbox_details);
787 gtk_widget_hide (dialog->frame_no_account);
788 gtk_widget_hide (dialog->frame_new_account);
790 account = accounts_dialog_model_get_selected (dialog);
791 accounts_dialog_update_account (dialog, account);
795 accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
796 GossipAccountsDialog *dialog)
801 account = accounts_dialog_model_get_selected (dialog);
802 enable = (!mc_account_is_enabled (account));
803 mc_account_set_enabled (account, enable);
804 accounts_dialog_update_connect_button (dialog);
806 g_object_unref (account);
810 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
811 GossipAccountsDialog *dialog)
813 gtk_widget_hide (dialog->vbox_details);
814 gtk_widget_hide (dialog->frame_no_account);
815 gtk_widget_show (dialog->frame_new_account);
817 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
818 gtk_entry_set_text (GTK_ENTRY (dialog->entry_name), "");
819 gtk_widget_grab_focus (dialog->entry_name);
823 accounts_dialog_remove_response_cb (GtkWidget *dialog,
827 if (response == GTK_RESPONSE_YES) {
828 mc_account_delete (account);
831 gtk_widget_destroy (dialog);
835 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
836 GossipAccountsDialog *dialog)
839 GtkWidget *message_dialog;
841 account = accounts_dialog_model_get_selected (dialog);
843 if (!mc_account_is_complete (account)) {
844 accounts_dialog_model_remove_selected (dialog);
847 message_dialog = gtk_message_dialog_new
848 (GTK_WINDOW (dialog->window),
849 GTK_DIALOG_DESTROY_WITH_PARENT,
850 GTK_MESSAGE_QUESTION,
852 _("You are about to remove your %s account!\n"
853 "Are you sure you want to proceed?"),
854 mc_account_get_display_name (account));
856 gtk_message_dialog_format_secondary_text
857 (GTK_MESSAGE_DIALOG (message_dialog),
858 _("Any associated conversations and chat rooms will NOT be "
859 "removed if you decide to proceed.\n"
861 "Should you decide to add the account back at a later time, "
862 "they will still be available."));
864 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
867 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
871 g_signal_connect (message_dialog, "response",
872 G_CALLBACK (accounts_dialog_remove_response_cb),
875 gtk_widget_show (message_dialog);
879 accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
881 GtkTreeViewColumn *column,
882 GossipAccountsDialog *dialog)
885 accounts_dialog_button_connect_clicked_cb (dialog->button_connect,
890 accounts_dialog_response_cb (GtkWidget *widget,
892 GossipAccountsDialog *dialog)
894 gtk_widget_destroy (widget);
898 accounts_dialog_destroy_cb (GtkWidget *widget,
899 GossipAccountsDialog *dialog)
902 McAccountMonitor *monitor;
905 mc = empathy_session_get_mission_control ();
906 monitor = mc_account_monitor_new ();
908 /* Disconnect signals */
909 g_signal_handlers_disconnect_by_func (monitor,
910 accounts_dialog_account_added_cb,
912 g_signal_handlers_disconnect_by_func (monitor,
913 accounts_dialog_account_removed_cb,
915 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (mc), "AccountStatusChanged",
916 G_CALLBACK (accounts_dialog_status_changed_cb),
919 /* Delete incomplete accounts */
920 accounts = mc_accounts_list ();
921 for (l = accounts; l; l = l->next) {
925 if (!mc_account_is_complete (account)) {
926 /* FIXME: Warn the user the account is not complete
927 * and is going to be removed. */
928 mc_account_delete (account);
931 g_object_unref (account);
933 g_list_free (accounts);
935 if (dialog->connecting_id) {
936 g_source_remove (dialog->connecting_id);
943 gossip_accounts_dialog_show (void)
945 static GossipAccountsDialog *dialog = NULL;
947 McAccountMonitor *monitor;
950 GtkWidget *button_close;
953 gtk_window_present (GTK_WINDOW (dialog->window));
954 return dialog->window;
957 dialog = g_new0 (GossipAccountsDialog, 1);
959 glade = gossip_glade_get_file ("empathy-accounts.glade",
962 "accounts_dialog", &dialog->window,
963 "vbox_details", &dialog->vbox_details,
964 "frame_no_account", &dialog->frame_no_account,
965 "label_no_account", &dialog->label_no_account,
966 "label_no_account_blurb", &dialog->label_no_account_blurb,
967 "alignment_settings", &dialog->alignment_settings,
968 "dialog-action_area", &bbox,
969 "treeview", &dialog->treeview,
970 "frame_new_account", &dialog->frame_new_account,
971 "entry_name", &dialog->entry_name,
972 "table_new_account", &dialog->table_new_account,
973 "button_create", &dialog->button_create,
974 "button_cancel", &dialog->button_cancel,
975 "image_type", &dialog->image_type,
976 "label_type", &dialog->label_type,
977 "label_name", &dialog->label_name,
978 "button_remove", &dialog->button_remove,
979 "button_connect", &dialog->button_connect,
980 "button_close", &button_close,
983 gossip_glade_connect (glade,
985 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
986 "accounts_dialog", "response", accounts_dialog_response_cb,
987 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
988 "button_cancel", "clicked", accounts_dialog_button_cancel_clicked_cb,
989 "entry_name", "changed", accounts_dialog_entry_name_changed_cb,
990 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
991 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
992 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
993 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
996 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
998 g_object_unref (glade);
1000 /* Create profile chooser */
1001 dialog->combobox_profile = gossip_profile_chooser_new ();
1002 gtk_table_attach_defaults (GTK_TABLE (dialog->table_new_account),
1003 dialog->combobox_profile,
1006 gtk_widget_show (dialog->combobox_profile);
1008 /* Set up signalling */
1009 mc = empathy_session_get_mission_control ();
1010 monitor = mc_account_monitor_new ();
1012 /* FIXME: connect account-enabled/disabled too */
1013 g_signal_connect (monitor, "account-created",
1014 G_CALLBACK (accounts_dialog_account_added_cb),
1016 g_signal_connect (monitor, "account-deleted",
1017 G_CALLBACK (accounts_dialog_account_removed_cb),
1019 dbus_g_proxy_connect_signal (DBUS_G_PROXY (mc), "AccountStatusChanged",
1020 G_CALLBACK (accounts_dialog_status_changed_cb),
1023 accounts_dialog_model_setup (dialog);
1024 accounts_dialog_setup (dialog);
1026 gtk_widget_show (dialog->window);
1028 accounts_dialog_model_select_first (dialog);
1030 return dialog->window;