1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
31 #include <glade/glade.h>
32 #include <glib/gi18n.h>
33 #include <dbus/dbus-glib.h>
35 #include <libmissioncontrol/mc-account.h>
36 #include <libmissioncontrol/mc-profile.h>
37 #include <libmissioncontrol/mission-control.h>
38 #include <libmissioncontrol/mc-account-monitor.h>
39 #include <libtelepathy/tp-constants.h>
41 #include <libempathy/empathy-debug.h>
42 #include <libempathy/empathy-utils.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include "empathy-accounts-dialog.h"
46 #include "empathy-profile-chooser.h"
47 #include "empathy-account-widget-generic.h"
48 #include "empathy-account-widget-jabber.h"
49 #include "empathy-account-widget-msn.h"
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 } EmpathyAccountsDialog;
98 static void accounts_dialog_setup (EmpathyAccountsDialog *dialog);
99 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
101 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
102 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
103 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
104 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
105 GtkCellRenderer *cell,
108 EmpathyAccountsDialog *dialog);
109 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
110 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
112 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
113 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
114 EmpathyAccountsDialog *dialog);
115 static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
117 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
119 EmpathyAccountsDialog *dialog);
120 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
122 EmpathyAccountsDialog *dialog);
123 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
127 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
128 static void accounts_dialog_status_changed_cb (MissionControl *mc,
129 TelepathyConnectionStatus status,
131 TelepathyConnectionStatusReason reason,
132 const gchar *unique_name,
133 EmpathyAccountsDialog *dialog);
134 static void accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
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 TelepathyConnectionStatus 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_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 (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;
245 gtk_widget_show (dialog->frame_no_account);
246 gtk_widget_hide (dialog->vbox_details);
248 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
249 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
251 view = GTK_TREE_VIEW (dialog->treeview);
252 model = gtk_tree_view_get_model (view);
254 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
255 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
256 _("<b>No Account Selected</b>"));
257 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
258 _("To add a new account, you can click on the "
259 "'Add' button and a new entry will be created "
260 "for you to start configuring.\n"
262 "If you do not want to add an account, simply "
263 "click on the account you want to configure in "
264 "the list on the left."));
266 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
267 _("<b>No Accounts Configured</b>"));
268 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
269 _("To add a new account, you can click on the "
270 "'Add' button and a new entry will be created "
271 "for you to start configuring."));
275 const gchar *config_ui;
277 gtk_widget_hide (dialog->frame_no_account);
278 gtk_widget_show (dialog->vbox_details);
280 profile = mc_account_get_profile (account);
281 config_ui = mc_profile_get_configuration_ui (profile);
282 g_object_unref (profile);
284 if (!empathy_strdiff (config_ui, "jabber")) {
285 dialog->settings_widget =
286 empathy_account_widget_jabber_new (account);
288 else if (!empathy_strdiff (config_ui, "msn")) {
289 dialog ->settings_widget =
290 empathy_account_widget_msn_new (account);
293 dialog->settings_widget =
294 empathy_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 profile = mc_account_get_profile (account);
310 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
311 mc_profile_get_icon_name (profile),
312 GTK_ICON_SIZE_DIALOG);
313 /* FIXME: Uncomment once we depend on GTK+ 2.12
314 gtk_widget_set_tooltip_text (dialog->image_type,
315 mc_profile_get_display_name (profile));
318 text = g_strdup_printf ("<big><b>%s</b></big>", mc_account_get_display_name (account));
319 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
325 accounts_dialog_model_setup (EmpathyAccountsDialog *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 (EmpathyAccountsDialog *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 (EmpathyAccountsDialog *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 EmpathyAccountsDialog *dialog)
414 const gchar *icon_name;
416 TelepathyConnectionStatus status;
418 gtk_tree_model_get (model, iter,
420 COL_ACCOUNT_POINTER, &account,
423 icon_name = empathy_icon_name_from_account (account);
424 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
427 if (status == TP_CONN_STATUS_DISCONNECTED ||
428 (status == TP_CONN_STATUS_CONNECTING &&
429 !dialog->connecting_show)) {
430 GdkPixbuf *modded_pixbuf;
432 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
435 gdk_pixbuf_get_width (pixbuf),
436 gdk_pixbuf_get_height (pixbuf));
438 gdk_pixbuf_saturate_and_pixelate (pixbuf,
442 g_object_unref (pixbuf);
443 pixbuf = modded_pixbuf;
452 g_object_unref (account);
454 g_object_unref (pixbuf);
459 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
463 GtkTreeSelection *selection;
467 view = GTK_TREE_VIEW (dialog->treeview);
468 selection = gtk_tree_view_get_selection (view);
470 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
474 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
480 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
484 GtkTreeSelection *selection;
489 view = GTK_TREE_VIEW (dialog->treeview);
490 model = gtk_tree_view_get_model (view);
491 selection = gtk_tree_view_get_selection (view);
493 for (ok = gtk_tree_model_get_iter_first (model, &iter);
495 ok = gtk_tree_model_iter_next (model, &iter)) {
496 McAccount *this_account;
499 gtk_tree_model_get (model, &iter,
500 COL_ACCOUNT_POINTER, &this_account,
503 equal = empathy_account_equal (this_account, account);
504 g_object_unref (this_account);
507 gtk_tree_selection_select_iter (selection, &iter);
514 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
518 GtkTreeSelection *selection;
521 view = GTK_TREE_VIEW (dialog->treeview);
522 selection = gtk_tree_view_get_selection (view);
524 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
528 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
532 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
533 EmpathyAccountsDialog *dialog)
538 gboolean is_selection;
540 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
542 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
543 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
545 accounts_dialog_update_connect_button (dialog);
547 account = accounts_dialog_model_get_selected (dialog);
548 accounts_dialog_update_account (dialog, account);
551 g_object_unref (account);
554 /* insure new account frame is hidden when a row is selected*/
555 gtk_widget_hide (dialog->frame_new_account);
559 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
562 TelepathyConnectionStatus status;
570 view = GTK_TREE_VIEW (dialog->treeview);
571 model = gtk_tree_view_get_model (view);
572 store = GTK_LIST_STORE (model);
574 for (ok = gtk_tree_model_get_iter_first (model, &iter);
576 ok = gtk_tree_model_iter_next (model, &iter)) {
577 McAccount *this_account;
580 gtk_tree_model_get (model, &iter,
581 COL_ACCOUNT_POINTER, &this_account,
584 equal = empathy_account_equal (this_account, account);
585 g_object_unref (this_account);
592 status = mission_control_get_connection_status (dialog->mc, account, NULL);
593 name = mc_account_get_display_name (account);
595 g_return_if_fail (name != NULL);
597 empathy_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
599 gtk_list_store_insert_with_values (store, &iter,
603 COL_ACCOUNT_POINTER, account,
608 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
610 EmpathyAccountsDialog *dialog)
614 account = mc_account_lookup (unique_name);
615 accounts_dialog_add_account (dialog, account);
616 g_object_unref (account);
620 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
622 EmpathyAccountsDialog *dialog)
626 account = mc_account_lookup (unique_name);
628 accounts_dialog_model_set_selected (dialog, account);
629 accounts_dialog_model_remove_selected (dialog);
631 g_object_unref (account);
635 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
640 gtk_tree_model_row_changed (model, path, iter);
646 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
651 dialog->connecting_show = !dialog->connecting_show;
653 view = GTK_TREE_VIEW (dialog->treeview);
654 model = gtk_tree_view_get_model (view);
656 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
662 accounts_dialog_status_changed_cb (MissionControl *mc,
663 TelepathyConnectionStatus status,
665 TelepathyConnectionStatusReason reason,
666 const gchar *unique_name,
667 EmpathyAccountsDialog *dialog)
670 GtkTreeSelection *selection;
676 gboolean found = FALSE;
678 /* Update the status in the model */
679 view = GTK_TREE_VIEW (dialog->treeview);
680 selection = gtk_tree_view_get_selection (view);
681 model = gtk_tree_view_get_model (view);
682 account = mc_account_lookup (unique_name);
684 empathy_debug (DEBUG_DOMAIN, "Status changed for account %s: "
685 "status=%d presence=%d",
686 unique_name, status, presence);
688 for (ok = gtk_tree_model_get_iter_first (model, &iter);
690 ok = gtk_tree_model_iter_next (model, &iter)) {
691 McAccount *this_account;
694 gtk_tree_model_get (model, &iter,
695 COL_ACCOUNT_POINTER, &this_account,
698 equal = empathy_account_equal (this_account, account);
699 g_object_unref (this_account);
704 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
708 path = gtk_tree_model_get_path (model, &iter);
709 gtk_tree_model_row_changed (model, path, &iter);
710 gtk_tree_path_free (path);
716 g_object_unref (account);
718 /* Start to flash account if status is connecting */
719 if (status == TP_CONN_STATUS_CONNECTING) {
720 if (!dialog->connecting_id) {
721 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
722 (GSourceFunc) accounts_dialog_flash_connecting_cb,
729 /* Stop to flash if no account is connecting */
730 accounts = mc_accounts_list ();
731 for (l = accounts; l; l = l->next) {
732 McAccount *this_account;
734 this_account = l->data;
736 if (mission_control_get_connection_status (mc, this_account, NULL) == TP_CONN_STATUS_CONNECTING) {
741 g_object_unref (this_account);
743 g_list_free (accounts);
745 if (!found && dialog->connecting_id) {
746 g_source_remove (dialog->connecting_id);
747 dialog->connecting_id = 0;
750 gtk_widget_show (dialog->window);
754 accounts_dialog_entry_name_changed_cb (GtkWidget *widget,
755 EmpathyAccountsDialog *dialog)
759 str = gtk_entry_get_text (GTK_ENTRY (widget));
760 gtk_widget_set_sensitive (dialog->button_create, !G_STR_EMPTY (str));
764 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
765 EmpathyAccountsDialog *dialog)
772 gtk_widget_show (dialog->vbox_details);
773 gtk_widget_hide (dialog->frame_no_account);
774 gtk_widget_hide (dialog->frame_new_account);
776 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
779 account = mc_account_create (profile);
781 str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_name));
782 mc_account_set_display_name (account, str);
784 accounts_dialog_add_account (dialog, account);
785 accounts_dialog_model_set_selected (dialog, account);
787 g_object_unref (account);
788 g_object_unref (profile);
792 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
793 EmpathyAccountsDialog *dialog)
797 gtk_widget_hide (dialog->vbox_details);
798 gtk_widget_hide (dialog->frame_no_account);
799 gtk_widget_hide (dialog->frame_new_account);
801 account = accounts_dialog_model_get_selected (dialog);
802 accounts_dialog_update_account (dialog, account);
806 accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
807 EmpathyAccountsDialog *dialog)
812 account = accounts_dialog_model_get_selected (dialog);
813 enable = (!mc_account_is_enabled (account));
814 mc_account_set_enabled (account, enable);
815 accounts_dialog_update_connect_button (dialog);
817 g_object_unref (account);
821 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
822 EmpathyAccountsDialog *dialog)
824 gtk_widget_hide (dialog->vbox_details);
825 gtk_widget_hide (dialog->frame_no_account);
826 gtk_widget_show (dialog->frame_new_account);
828 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
829 gtk_entry_set_text (GTK_ENTRY (dialog->entry_name), "");
830 gtk_widget_grab_focus (dialog->entry_name);
834 accounts_dialog_remove_response_cb (GtkWidget *dialog,
838 if (response == GTK_RESPONSE_YES) {
839 mc_account_delete (account);
842 gtk_widget_destroy (dialog);
846 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
847 EmpathyAccountsDialog *dialog)
850 GtkWidget *message_dialog;
852 account = accounts_dialog_model_get_selected (dialog);
854 if (!mc_account_is_complete (account)) {
855 accounts_dialog_model_remove_selected (dialog);
858 message_dialog = gtk_message_dialog_new
859 (GTK_WINDOW (dialog->window),
860 GTK_DIALOG_DESTROY_WITH_PARENT,
861 GTK_MESSAGE_QUESTION,
863 _("You are about to remove your %s account!\n"
864 "Are you sure you want to proceed?"),
865 mc_account_get_display_name (account));
867 gtk_message_dialog_format_secondary_text
868 (GTK_MESSAGE_DIALOG (message_dialog),
869 _("Any associated conversations and chat rooms will NOT be "
870 "removed if you decide to proceed.\n"
872 "Should you decide to add the account back at a later time, "
873 "they will still be available."));
875 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
878 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
882 g_signal_connect (message_dialog, "response",
883 G_CALLBACK (accounts_dialog_remove_response_cb),
886 gtk_widget_show (message_dialog);
890 accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
892 GtkTreeViewColumn *column,
893 EmpathyAccountsDialog *dialog)
896 accounts_dialog_button_connect_clicked_cb (dialog->button_connect,
901 accounts_dialog_response_cb (GtkWidget *widget,
903 EmpathyAccountsDialog *dialog)
905 gtk_widget_destroy (widget);
909 accounts_dialog_destroy_cb (GtkWidget *widget,
910 EmpathyAccountsDialog *dialog)
914 /* Disconnect signals */
915 g_signal_handlers_disconnect_by_func (dialog->monitor,
916 accounts_dialog_account_added_cb,
918 g_signal_handlers_disconnect_by_func (dialog->monitor,
919 accounts_dialog_account_removed_cb,
921 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog->mc),
922 "AccountStatusChanged",
923 G_CALLBACK (accounts_dialog_status_changed_cb),
926 /* Delete incomplete accounts */
927 accounts = mc_accounts_list ();
928 for (l = accounts; l; l = l->next) {
932 if (!mc_account_is_complete (account)) {
933 /* FIXME: Warn the user the account is not complete
934 * and is going to be removed. */
935 mc_account_delete (account);
938 g_object_unref (account);
940 g_list_free (accounts);
942 if (dialog->connecting_id) {
943 g_source_remove (dialog->connecting_id);
946 g_object_unref (dialog->mc);
947 g_object_unref (dialog->monitor);
953 empathy_accounts_dialog_show (GtkWindow *parent)
955 static EmpathyAccountsDialog *dialog = NULL;
958 GtkWidget *button_close;
961 gtk_window_present (GTK_WINDOW (dialog->window));
962 return dialog->window;
965 dialog = g_new0 (EmpathyAccountsDialog, 1);
967 glade = empathy_glade_get_file ("empathy-accounts-dialog.glade",
970 "accounts_dialog", &dialog->window,
971 "vbox_details", &dialog->vbox_details,
972 "frame_no_account", &dialog->frame_no_account,
973 "label_no_account", &dialog->label_no_account,
974 "label_no_account_blurb", &dialog->label_no_account_blurb,
975 "alignment_settings", &dialog->alignment_settings,
976 "dialog-action_area", &bbox,
977 "treeview", &dialog->treeview,
978 "frame_new_account", &dialog->frame_new_account,
979 "entry_name", &dialog->entry_name,
980 "table_new_account", &dialog->table_new_account,
981 "button_create", &dialog->button_create,
982 "button_back", &dialog->button_back,
983 "image_type", &dialog->image_type,
984 "label_name", &dialog->label_name,
985 "button_remove", &dialog->button_remove,
986 "button_connect", &dialog->button_connect,
987 "button_close", &button_close,
990 empathy_glade_connect (glade,
992 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
993 "accounts_dialog", "response", accounts_dialog_response_cb,
994 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
995 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
996 "entry_name", "changed", accounts_dialog_entry_name_changed_cb,
997 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
998 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
999 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1000 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1003 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1005 g_object_unref (glade);
1007 /* Create profile chooser */
1008 dialog->combobox_profile = empathy_profile_chooser_new ();
1009 gtk_table_attach_defaults (GTK_TABLE (dialog->table_new_account),
1010 dialog->combobox_profile,
1013 gtk_widget_show (dialog->combobox_profile);
1015 /* Set up signalling */
1016 dialog->mc = empathy_mission_control_new ();
1017 dialog->monitor = mc_account_monitor_new ();
1019 /* FIXME: connect account-enabled/disabled too */
1020 g_signal_connect (dialog->monitor, "account-created",
1021 G_CALLBACK (accounts_dialog_account_added_cb),
1023 g_signal_connect (dialog->monitor, "account-deleted",
1024 G_CALLBACK (accounts_dialog_account_removed_cb),
1026 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog->mc), "AccountStatusChanged",
1027 G_CALLBACK (accounts_dialog_status_changed_cb),
1030 accounts_dialog_model_setup (dialog);
1031 accounts_dialog_setup (dialog);
1032 accounts_dialog_model_select_first (dialog);
1035 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1036 GTK_WINDOW (parent));
1039 gtk_widget_show (dialog->window);
1041 return dialog->window;