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/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"
49 #include "gossip-account-widget-jabber.h"
51 #define DEBUG_DOMAIN "AccountDialog"
53 /* Flashing delay for icons (milliseconds). */
54 #define FLASH_TIMEOUT 500
59 GtkWidget *alignment_settings;
61 GtkWidget *vbox_details;
62 GtkWidget *frame_no_account;
63 GtkWidget *label_no_account;
64 GtkWidget *label_no_account_blurb;
68 GtkWidget *button_remove;
69 GtkWidget *button_connect;
71 GtkWidget *frame_new_account;
72 GtkWidget *combobox_profile;
73 GtkWidget *entry_name;
74 GtkWidget *table_new_account;
75 GtkWidget *button_create;
76 GtkWidget *button_back;
78 GtkWidget *image_type;
79 GtkWidget *label_name;
80 GtkWidget *label_type;
81 GtkWidget *settings_widget;
83 gboolean connecting_show;
85 gboolean account_changed;
88 McAccountMonitor *monitor;
89 } GossipAccountsDialog;
98 static void accounts_dialog_setup (GossipAccountsDialog *dialog);
99 static void accounts_dialog_update_account (GossipAccountsDialog *dialog,
101 static void accounts_dialog_model_setup (GossipAccountsDialog *dialog);
102 static void accounts_dialog_model_add_columns (GossipAccountsDialog *dialog);
103 static void accounts_dialog_model_select_first (GossipAccountsDialog *dialog);
104 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
105 GtkCellRenderer *cell,
108 GossipAccountsDialog *dialog);
109 static McAccount *accounts_dialog_model_get_selected (GossipAccountsDialog *dialog);
110 static void accounts_dialog_model_set_selected (GossipAccountsDialog *dialog,
112 static gboolean accounts_dialog_model_remove_selected (GossipAccountsDialog *dialog);
113 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
114 GossipAccountsDialog *dialog);
115 static void accounts_dialog_add_account (GossipAccountsDialog *dialog,
117 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
119 GossipAccountsDialog *dialog);
120 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
122 GossipAccountsDialog *dialog);
123 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
127 static gboolean accounts_dialog_flash_connecting_cb (GossipAccountsDialog *dialog);
128 static void accounts_dialog_status_changed_cb (MissionControl *mc,
129 TelepathyConnectionStatus status,
131 TelepathyConnectionStatusReason reason,
132 const gchar *unique_name,
133 GossipAccountsDialog *dialog);
134 static void accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
135 GossipAccountsDialog *dialog);
136 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
137 GossipAccountsDialog *dialog);
138 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
139 GossipAccountsDialog *dialog);
140 static void accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
141 GossipAccountsDialog *dialog);
142 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
143 GossipAccountsDialog *dialog);
144 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
147 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
148 GossipAccountsDialog *dialog);
149 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
151 GtkTreeViewColumn *column,
152 GossipAccountsDialog *dialog);
153 static void accounts_dialog_response_cb (GtkWidget *widget,
155 GossipAccountsDialog *dialog);
156 static void accounts_dialog_destroy_cb (GtkWidget *widget,
157 GossipAccountsDialog *dialog);
160 accounts_dialog_setup (GossipAccountsDialog *dialog)
164 GtkTreeSelection *selection;
168 view = GTK_TREE_VIEW (dialog->treeview);
169 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
170 selection = gtk_tree_view_get_selection (view);
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 (dialog->mc, account, NULL);
188 gtk_list_store_insert_with_values (store, &iter,
192 COL_ACCOUNT_POINTER, account,
195 accounts_dialog_status_changed_cb (dialog->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);
308 profile = mc_account_get_profile (account);
309 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
310 mc_profile_get_icon_name (profile),
311 GTK_ICON_SIZE_DIALOG);
314 gtk_label_set_text (GTK_LABEL (dialog->label_type),
315 mc_profile_get_display_name (profile));
316 gtk_label_set_text (GTK_LABEL (dialog->label_name),
317 mc_account_get_display_name (account));
322 accounts_dialog_model_setup (GossipAccountsDialog *dialog)
325 GtkTreeSelection *selection;
327 store = gtk_list_store_new (COL_COUNT,
328 G_TYPE_STRING, /* name */
329 G_TYPE_UINT, /* status */
330 MC_TYPE_ACCOUNT); /* account */
332 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
333 GTK_TREE_MODEL (store));
335 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
336 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
338 g_signal_connect (selection, "changed",
339 G_CALLBACK (accounts_dialog_model_selection_changed),
342 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
343 COL_NAME, GTK_SORT_ASCENDING);
345 accounts_dialog_model_add_columns (dialog);
347 g_object_unref (store);
351 accounts_dialog_model_add_columns (GossipAccountsDialog *dialog)
354 GtkTreeViewColumn *column;
355 GtkCellRenderer *cell;
357 view = GTK_TREE_VIEW (dialog->treeview);
358 gtk_tree_view_set_headers_visible (view, TRUE);
360 /* account name/status */
361 column = gtk_tree_view_column_new ();
362 gtk_tree_view_column_set_title (column, _("Accounts"));
364 cell = gtk_cell_renderer_pixbuf_new ();
365 gtk_tree_view_column_pack_start (column, cell, FALSE);
366 gtk_tree_view_column_set_cell_data_func (column, cell,
367 (GtkTreeCellDataFunc)
368 accounts_dialog_model_pixbuf_data_func,
372 cell = gtk_cell_renderer_text_new ();
373 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
374 gtk_tree_view_column_pack_start (column, cell, TRUE);
375 gtk_tree_view_column_add_attribute (column,
379 gtk_tree_view_column_set_expand (column, TRUE);
380 gtk_tree_view_append_column (view, column);
384 accounts_dialog_model_select_first (GossipAccountsDialog *dialog)
388 GtkTreeSelection *selection;
392 view = GTK_TREE_VIEW (dialog->treeview);
393 model = gtk_tree_view_get_model (view);
395 if (gtk_tree_model_get_iter_first (model, &iter)) {
396 selection = gtk_tree_view_get_selection (view);
397 gtk_tree_selection_select_iter (selection, &iter);
399 accounts_dialog_update_account (dialog, NULL);
404 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
405 GtkCellRenderer *cell,
408 GossipAccountsDialog *dialog)
411 const gchar *icon_name;
413 TelepathyConnectionStatus status;
415 gtk_tree_model_get (model, iter,
417 COL_ACCOUNT_POINTER, &account,
420 icon_name = gossip_icon_name_from_account (account);
421 pixbuf = gossip_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
424 if (status == TP_CONN_STATUS_DISCONNECTED ||
425 (status == TP_CONN_STATUS_CONNECTING &&
426 !dialog->connecting_show)) {
427 GdkPixbuf *modded_pixbuf;
429 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
432 gdk_pixbuf_get_width (pixbuf),
433 gdk_pixbuf_get_height (pixbuf));
435 gdk_pixbuf_saturate_and_pixelate (pixbuf,
439 g_object_unref (pixbuf);
440 pixbuf = modded_pixbuf;
449 g_object_unref (account);
451 g_object_unref (pixbuf);
456 accounts_dialog_model_get_selected (GossipAccountsDialog *dialog)
460 GtkTreeSelection *selection;
464 view = GTK_TREE_VIEW (dialog->treeview);
465 selection = gtk_tree_view_get_selection (view);
467 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
471 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
477 accounts_dialog_model_set_selected (GossipAccountsDialog *dialog,
481 GtkTreeSelection *selection;
486 view = GTK_TREE_VIEW (dialog->treeview);
487 model = gtk_tree_view_get_model (view);
488 selection = gtk_tree_view_get_selection (view);
490 for (ok = gtk_tree_model_get_iter_first (model, &iter);
492 ok = gtk_tree_model_iter_next (model, &iter)) {
493 McAccount *this_account;
496 gtk_tree_model_get (model, &iter,
497 COL_ACCOUNT_POINTER, &this_account,
500 equal = gossip_account_equal (this_account, account);
501 g_object_unref (this_account);
504 gtk_tree_selection_select_iter (selection, &iter);
511 accounts_dialog_model_remove_selected (GossipAccountsDialog *dialog)
515 GtkTreeSelection *selection;
518 view = GTK_TREE_VIEW (dialog->treeview);
519 selection = gtk_tree_view_get_selection (view);
521 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
525 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
529 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
530 GossipAccountsDialog *dialog)
535 gboolean is_selection;
537 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
539 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
540 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
542 accounts_dialog_update_connect_button (dialog);
544 account = accounts_dialog_model_get_selected (dialog);
545 accounts_dialog_update_account (dialog, account);
548 g_object_unref (account);
553 accounts_dialog_add_account (GossipAccountsDialog *dialog,
556 TelepathyConnectionStatus status;
564 view = GTK_TREE_VIEW (dialog->treeview);
565 model = gtk_tree_view_get_model (view);
566 store = GTK_LIST_STORE (model);
568 for (ok = gtk_tree_model_get_iter_first (model, &iter);
570 ok = gtk_tree_model_iter_next (model, &iter)) {
571 McAccount *this_account;
574 gtk_tree_model_get (model, &iter,
575 COL_ACCOUNT_POINTER, &this_account,
578 equal = gossip_account_equal (this_account, account);
579 g_object_unref (this_account);
586 status = mission_control_get_connection_status (dialog->mc, account, NULL);
587 name = mc_account_get_display_name (account);
589 g_return_if_fail (name != NULL);
591 gossip_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
593 gtk_list_store_insert_with_values (store, &iter,
597 COL_ACCOUNT_POINTER, account,
602 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
604 GossipAccountsDialog *dialog)
608 account = mc_account_lookup (unique_name);
609 accounts_dialog_add_account (dialog, account);
610 g_object_unref (account);
614 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
616 GossipAccountsDialog *dialog)
620 account = mc_account_lookup (unique_name);
622 accounts_dialog_model_set_selected (dialog, account);
623 accounts_dialog_model_remove_selected (dialog);
625 g_object_unref (account);
629 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
634 gtk_tree_model_row_changed (model, path, iter);
640 accounts_dialog_flash_connecting_cb (GossipAccountsDialog *dialog)
645 dialog->connecting_show = !dialog->connecting_show;
647 view = GTK_TREE_VIEW (dialog->treeview);
648 model = gtk_tree_view_get_model (view);
650 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
656 accounts_dialog_status_changed_cb (MissionControl *mc,
657 TelepathyConnectionStatus status,
659 TelepathyConnectionStatusReason reason,
660 const gchar *unique_name,
661 GossipAccountsDialog *dialog)
664 GtkTreeSelection *selection;
670 gboolean found = FALSE;
672 /* Update the status in the model */
673 view = GTK_TREE_VIEW (dialog->treeview);
674 selection = gtk_tree_view_get_selection (view);
675 model = gtk_tree_view_get_model (view);
676 account = mc_account_lookup (unique_name);
678 gossip_debug (DEBUG_DOMAIN, "Status changed for account %s: "
679 "status=%d presence=%d",
680 unique_name, status, presence);
682 for (ok = gtk_tree_model_get_iter_first (model, &iter);
684 ok = gtk_tree_model_iter_next (model, &iter)) {
685 McAccount *this_account;
688 gtk_tree_model_get (model, &iter,
689 COL_ACCOUNT_POINTER, &this_account,
692 equal = gossip_account_equal (this_account, account);
693 g_object_unref (this_account);
698 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
702 path = gtk_tree_model_get_path (model, &iter);
703 gtk_tree_model_row_changed (model, path, &iter);
704 gtk_tree_path_free (path);
710 g_object_unref (account);
712 /* Start to flash account if status is connecting */
713 if (status == TP_CONN_STATUS_CONNECTING) {
714 if (!dialog->connecting_id) {
715 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
716 (GSourceFunc) accounts_dialog_flash_connecting_cb,
723 /* Stop to flash if no account is connecting */
724 accounts = mc_accounts_list ();
725 for (l = accounts; l; l = l->next) {
726 McAccount *this_account;
728 this_account = l->data;
730 if (mission_control_get_connection_status (mc, this_account, NULL) == TP_CONN_STATUS_CONNECTING) {
735 g_object_unref (this_account);
737 g_list_free (accounts);
739 if (!found && dialog->connecting_id) {
740 g_source_remove (dialog->connecting_id);
741 dialog->connecting_id = 0;
744 gtk_widget_show (dialog->window);
748 accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
749 GossipAccountsDialog *dialog)
753 str = gtk_entry_get_text (GTK_ENTRY (widget));
754 gtk_widget_set_sensitive (dialog->button_create, !G_STR_EMPTY (str));
758 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
759 GossipAccountsDialog *dialog)
766 gtk_widget_show (dialog->vbox_details);
767 gtk_widget_hide (dialog->frame_no_account);
768 gtk_widget_hide (dialog->frame_new_account);
770 profile = gossip_profile_chooser_get_selected (dialog->combobox_profile);
773 account = mc_account_create (profile);
775 str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_name));
776 mc_account_set_display_name (account, str);
778 accounts_dialog_add_account (dialog, account);
779 accounts_dialog_model_set_selected (dialog, account);
781 g_object_unref (account);
782 g_object_unref (profile);
786 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
787 GossipAccountsDialog *dialog)
791 gtk_widget_hide (dialog->vbox_details);
792 gtk_widget_hide (dialog->frame_no_account);
793 gtk_widget_hide (dialog->frame_new_account);
795 account = accounts_dialog_model_get_selected (dialog);
796 accounts_dialog_update_account (dialog, account);
800 accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
801 GossipAccountsDialog *dialog)
806 account = accounts_dialog_model_get_selected (dialog);
807 enable = (!mc_account_is_enabled (account));
808 mc_account_set_enabled (account, enable);
809 accounts_dialog_update_connect_button (dialog);
811 g_object_unref (account);
815 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
816 GossipAccountsDialog *dialog)
818 gtk_widget_hide (dialog->vbox_details);
819 gtk_widget_hide (dialog->frame_no_account);
820 gtk_widget_show (dialog->frame_new_account);
822 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
823 gtk_entry_set_text (GTK_ENTRY (dialog->entry_name), "");
824 gtk_widget_grab_focus (dialog->entry_name);
828 accounts_dialog_remove_response_cb (GtkWidget *dialog,
832 if (response == GTK_RESPONSE_YES) {
833 mc_account_delete (account);
836 gtk_widget_destroy (dialog);
840 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
841 GossipAccountsDialog *dialog)
844 GtkWidget *message_dialog;
846 account = accounts_dialog_model_get_selected (dialog);
848 if (!mc_account_is_complete (account)) {
849 accounts_dialog_model_remove_selected (dialog);
852 message_dialog = gtk_message_dialog_new
853 (GTK_WINDOW (dialog->window),
854 GTK_DIALOG_DESTROY_WITH_PARENT,
855 GTK_MESSAGE_QUESTION,
857 _("You are about to remove your %s account!\n"
858 "Are you sure you want to proceed?"),
859 mc_account_get_display_name (account));
861 gtk_message_dialog_format_secondary_text
862 (GTK_MESSAGE_DIALOG (message_dialog),
863 _("Any associated conversations and chat rooms will NOT be "
864 "removed if you decide to proceed.\n"
866 "Should you decide to add the account back at a later time, "
867 "they will still be available."));
869 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
872 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
876 g_signal_connect (message_dialog, "response",
877 G_CALLBACK (accounts_dialog_remove_response_cb),
880 gtk_widget_show (message_dialog);
884 accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
886 GtkTreeViewColumn *column,
887 GossipAccountsDialog *dialog)
890 accounts_dialog_button_connect_clicked_cb (dialog->button_connect,
895 accounts_dialog_response_cb (GtkWidget *widget,
897 GossipAccountsDialog *dialog)
899 gtk_widget_destroy (widget);
903 accounts_dialog_destroy_cb (GtkWidget *widget,
904 GossipAccountsDialog *dialog)
908 /* Disconnect signals */
909 g_signal_handlers_disconnect_by_func (dialog->monitor,
910 accounts_dialog_account_added_cb,
912 g_signal_handlers_disconnect_by_func (dialog->monitor,
913 accounts_dialog_account_removed_cb,
915 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog->mc),
916 "AccountStatusChanged",
917 G_CALLBACK (accounts_dialog_status_changed_cb),
920 /* Delete incomplete accounts */
921 accounts = mc_accounts_list ();
922 for (l = accounts; l; l = l->next) {
926 if (!mc_account_is_complete (account)) {
927 /* FIXME: Warn the user the account is not complete
928 * and is going to be removed. */
929 mc_account_delete (account);
932 g_object_unref (account);
934 g_list_free (accounts);
936 if (dialog->connecting_id) {
937 g_source_remove (dialog->connecting_id);
940 g_object_unref (dialog->mc);
941 g_object_unref (dialog->monitor);
947 gossip_accounts_dialog_show (GtkWindow *parent)
949 static GossipAccountsDialog *dialog = NULL;
952 GtkWidget *button_close;
955 gtk_window_present (GTK_WINDOW (dialog->window));
956 return dialog->window;
959 dialog = g_new0 (GossipAccountsDialog, 1);
961 glade = gossip_glade_get_file ("gossip-accounts-dialog.glade",
964 "accounts_dialog", &dialog->window,
965 "vbox_details", &dialog->vbox_details,
966 "frame_no_account", &dialog->frame_no_account,
967 "label_no_account", &dialog->label_no_account,
968 "label_no_account_blurb", &dialog->label_no_account_blurb,
969 "alignment_settings", &dialog->alignment_settings,
970 "dialog-action_area", &bbox,
971 "treeview", &dialog->treeview,
972 "frame_new_account", &dialog->frame_new_account,
973 "entry_name", &dialog->entry_name,
974 "table_new_account", &dialog->table_new_account,
975 "button_create", &dialog->button_create,
976 "button_back", &dialog->button_back,
977 "image_type", &dialog->image_type,
978 "label_type", &dialog->label_type,
979 "label_name", &dialog->label_name,
980 "button_remove", &dialog->button_remove,
981 "button_connect", &dialog->button_connect,
982 "button_close", &button_close,
985 gossip_glade_connect (glade,
987 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
988 "accounts_dialog", "response", accounts_dialog_response_cb,
989 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
990 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
991 "entry_name", "changed", accounts_dialog_entry_name_changed_cb,
992 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
993 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
994 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
995 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
998 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1000 g_object_unref (glade);
1002 /* Create profile chooser */
1003 dialog->combobox_profile = gossip_profile_chooser_new ();
1004 gtk_table_attach_defaults (GTK_TABLE (dialog->table_new_account),
1005 dialog->combobox_profile,
1008 gtk_widget_show (dialog->combobox_profile);
1010 /* Set up signalling */
1011 dialog->mc = gossip_mission_control_new ();
1012 dialog->monitor = mc_account_monitor_new ();
1014 /* FIXME: connect account-enabled/disabled too */
1015 g_signal_connect (dialog->monitor, "account-created",
1016 G_CALLBACK (accounts_dialog_account_added_cb),
1018 g_signal_connect (dialog->monitor, "account-deleted",
1019 G_CALLBACK (accounts_dialog_account_removed_cb),
1021 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog->mc), "AccountStatusChanged",
1022 G_CALLBACK (accounts_dialog_status_changed_cb),
1025 accounts_dialog_model_setup (dialog);
1026 accounts_dialog_setup (dialog);
1027 accounts_dialog_model_select_first (dialog);
1030 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1031 GTK_WINDOW (parent));
1034 gtk_widget_show (dialog->window);
1036 return dialog->window;