2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
32 #include <glib/gi18n.h>
33 #include <dbus/dbus-glib.h>
35 #include <telepathy-glib/util.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy/empathy-account-manager.h>
39 #include <libempathy/empathy-connection-managers.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
42 #include <libempathy-gtk/empathy-protocol-chooser.h>
43 #include <libempathy-gtk/empathy-account-widget.h>
44 #include <libempathy-gtk/empathy-account-widget-irc.h>
45 #include <libempathy-gtk/empathy-account-widget-sip.h>
46 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
47 #include <libempathy-gtk/empathy-conf.h>
48 #include <libempathy-gtk/empathy-images.h>
50 #include "empathy-accounts-dialog.h"
51 #include "empathy-import-dialog.h"
52 #include "empathy-import-utils.h"
54 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
55 #include <libempathy/empathy-debug.h>
57 /* Flashing delay for icons (milliseconds). */
58 #define FLASH_TIMEOUT 500
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
61 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
63 static EmpathyAccountsDialog *dialog_singleton = NULL;
68 GtkWidget *alignment_settings;
70 GtkWidget *vbox_details;
71 GtkWidget *frame_no_protocol;
75 GtkWidget *button_add;
77 GtkWidget *frame_new_account;
78 GtkWidget *combobox_protocol;
80 GtkWidget *button_create;
81 GtkWidget *button_back;
82 GtkWidget *radiobutton_reuse;
83 GtkWidget *radiobutton_register;
85 GtkWidget *image_type;
86 GtkWidget *label_name;
87 GtkWidget *label_type;
88 GtkWidget *settings_widget;
90 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
91 * his GtkWidget. It is the only reliable source we can query to know if
92 * there are any unsaved changes to the currently selected account. We can't
93 * look at the account settings because it does not contain everything that
94 * can be changed using the EmpathyAccountWidget. For instance, it does not
95 * contain the state of the "Enabled" checkbox. */
96 EmpathyAccountWidget *setting_widget_object;
98 gboolean connecting_show;
101 gulong settings_ready_id;
102 EmpathyAccountSettings *settings_ready;
104 EmpathyAccountManager *account_manager;
105 EmpathyConnectionManagers *cms;
107 GtkWindow *parent_window;
108 EmpathyAccount *initial_selection;
110 /* Those are needed when changing the selected row. When a user selects
111 * another account and there are unsaved changes on the currently selected
112 * one, a confirmation message box is presented to him. Since his answer
113 * is retrieved asynchronously, we keep some information as member of the
114 * EmpathyAccountsDialog object. */
115 gboolean force_change_row;
116 gchar *destination_path;
119 } EmpathyAccountsDialogPriv;
125 COL_ACCOUNT_SETTINGS_POINTER,
133 static void accounts_dialog_account_display_name_changed_cb (
134 EmpathyAccount *account,
138 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
139 EmpathyAccountsDialog *dialog);
141 static gboolean accounts_dialog_get_settings_iter (
142 EmpathyAccountsDialog *dialog,
143 EmpathyAccountSettings *settings,
146 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
148 static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
149 EmpathyAccountSettings *settings);
151 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
152 EmpathyAccountSettings *settings);
155 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
156 const gchar *display_name)
159 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
161 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
162 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
168 empathy_account_dialog_widget_cancelled_cb (EmpathyAccountWidget *widget_object,
169 EmpathyAccountsDialog *dialog)
173 GtkTreeSelection *selection;
175 EmpathyAccountSettings *settings;
176 EmpathyAccount *account;
177 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
179 view = GTK_TREE_VIEW (priv->treeview);
180 selection = gtk_tree_view_get_selection (view);
182 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
185 gtk_tree_model_get (model, &iter,
186 COL_ACCOUNT_SETTINGS_POINTER, &settings,
187 COL_ACCOUNT_POINTER, &account, -1);
189 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
193 /* We were creating an account. We remove the selected row */
194 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
198 /* We were modifying an account. We discard the changes by reloading the
199 * settings and the UI. */
200 accounts_dialog_update_settings (dialog, settings);
201 g_object_unref (account);
204 if (settings != NULL)
205 g_object_unref (settings);
209 get_default_display_name (EmpathyAccountSettings *settings)
211 const gchar *login_id;
212 const gchar *protocol;
213 gchar *default_display_name;
215 login_id = empathy_account_settings_get_string (settings, "account");
216 protocol = empathy_account_settings_get_protocol (settings);
218 if (login_id != NULL)
220 if (!tp_strdiff(protocol, "irc"))
223 server = empathy_account_settings_get_string (settings, "server");
225 /* To translators: The first parameter is the login id and the
226 * second one is the server. The resulting string will be something
227 * like: "MyUserName on chat.freenode.net" */
228 default_display_name =
229 g_strdup_printf (_("%s on %s"), login_id, server);
233 default_display_name = g_strdup (login_id);
236 else if (protocol != NULL)
238 /* To translators: The parameter is the protocol name. The resulting
239 * string will be something like: "Jabber Account" */
240 default_display_name = g_strdup_printf (_("%s Account"), protocol);
244 default_display_name = g_strdup (_("New account"));
247 return default_display_name;
251 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
252 EmpathyAccountsDialog *dialog)
255 EmpathyAccountSettings *settings =
256 accounts_dialog_model_get_selected_settings (dialog);
258 display_name = get_default_display_name (settings);
260 empathy_account_settings_set_display_name_async (settings,
261 display_name, NULL, NULL);
263 g_free (display_name);
265 accounts_dialog_update_settings (dialog, settings);
268 g_object_unref (settings);
272 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
273 EmpathyAccountSettings *settings)
275 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
278 priv->settings_widget = empathy_account_widget_get_widget (widget_object);
279 g_signal_connect (priv->setting_widget_object, "account-created",
280 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
281 g_signal_connect (priv->setting_widget_object, "cancelled",
282 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
284 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
285 priv->settings_widget);
286 gtk_widget_show (priv->settings_widget);
288 icon_name = empathy_account_settings_get_icon_name (settings);
290 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
291 icon_name, GTK_ICON_SIZE_DIALOG);
292 gtk_widget_set_tooltip_text (priv->image_type,
293 empathy_protocol_name_to_display_name
294 (empathy_account_settings_get_protocol (settings)));
296 accounts_dialog_update_name_label (dialog,
297 empathy_account_settings_get_display_name (settings));
301 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
303 EmpathyAccountsDialog *dialog)
305 if (empathy_account_settings_is_ready (settings))
306 account_dialog_create_settings_widget (dialog, settings);
310 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
314 GtkTreeSelection *selection;
316 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
319 view = GTK_TREE_VIEW (priv->treeview);
320 model = gtk_tree_view_get_model (view);
322 if (gtk_tree_model_get_iter_first (model, &iter))
324 selection = gtk_tree_view_get_selection (view);
325 gtk_tree_selection_select_iter (selection, &iter);
329 accounts_dialog_update_settings (dialog, NULL);
334 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
335 EmpathyAccount **account)
337 gboolean has_pending_changes;
340 EmpathyAccountSettings *settings;
341 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
343 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
344 settings = accounts_dialog_model_get_selected_settings (dialog);
346 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
347 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
349 has_pending_changes = account != NULL && priv->setting_widget_object != NULL
350 && empathy_account_widget_contains_pending_changes (
351 priv->setting_widget_object);
353 if (settings != NULL)
354 g_object_unref (settings);
356 return has_pending_changes;
360 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
361 EmpathyAccountsDialog *dialog)
363 TpConnectionManager *cm;
364 TpConnectionManagerProtocol *proto;
365 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
367 cm = empathy_protocol_chooser_dup_selected (
368 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
379 if (tp_connection_manager_protocol_can_register (proto))
381 gtk_widget_show (priv->radiobutton_register);
382 gtk_widget_show (priv->radiobutton_reuse);
386 gtk_widget_hide (priv->radiobutton_register);
387 gtk_widget_hide (priv->radiobutton_reuse);
393 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
397 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
399 view = GTK_TREE_VIEW (priv->treeview);
400 model = gtk_tree_view_get_model (view);
402 gtk_widget_set_sensitive (priv->button_add, FALSE);
403 gtk_widget_hide (priv->vbox_details);
404 gtk_widget_hide (priv->frame_no_protocol);
405 gtk_widget_show (priv->frame_new_account);
407 /* If we have no account, no need of a back button */
408 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
409 gtk_widget_show (priv->button_back);
411 gtk_widget_hide (priv->button_back);
413 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
414 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
416 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
417 gtk_widget_grab_focus (priv->combobox_protocol);
421 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
425 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
426 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
428 gtk_widget_destroy (GTK_WIDGET (message_dialog));
430 if (response_id == GTK_RESPONSE_YES)
432 empathy_account_widget_discard_pending_changes (
433 priv->setting_widget_object);
434 accounts_dialog_setup_ui_to_add_account (dialog);
439 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
440 EmpathyAccountsDialog *dialog)
442 EmpathyAccount *account;
443 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
445 if (accounts_dialog_has_pending_change (dialog, &account))
449 message = g_strdup_printf (
450 _("There are unsaved modification regarding your %s account.\n"
451 "You are about to create a new account, which will discard\n"
452 "your changes. Are you sure you want to proceed?"),
453 empathy_account_get_display_name (account));
455 empathy_show_yes_no_question_dialog (GTK_WINDOW (priv->window),
457 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
464 accounts_dialog_setup_ui_to_add_account (dialog);
469 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
470 EmpathyAccountSettings *settings)
472 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
474 if (priv->settings_ready != NULL)
476 g_signal_handler_disconnect (priv->settings_ready,
477 priv->settings_ready_id);
478 priv->settings_ready = NULL;
479 priv->settings_ready_id = 0;
487 view = GTK_TREE_VIEW (priv->treeview);
488 model = gtk_tree_view_get_model (view);
490 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
492 /* We have configured accounts, select the first one */
493 accounts_dialog_model_select_first (dialog);
496 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
498 /* We have no account configured but we have some
499 * profiles installed. The user obviously wants to add
500 * an account. Click on the Add button for him. */
501 accounts_dialog_button_add_clicked_cb (priv->button_add,
506 /* No account and no profile, warn the user */
507 gtk_widget_hide (priv->vbox_details);
508 gtk_widget_hide (priv->frame_new_account);
509 gtk_widget_show (priv->frame_no_protocol);
510 gtk_widget_set_sensitive (priv->button_add, FALSE);
514 /* We have an account selected, destroy old settings and create a new
515 * one for the account selected */
516 gtk_widget_hide (priv->frame_new_account);
517 gtk_widget_hide (priv->frame_no_protocol);
518 gtk_widget_show (priv->vbox_details);
519 gtk_widget_set_sensitive (priv->button_add, TRUE);
521 if (priv->settings_widget)
523 gtk_widget_destroy (priv->settings_widget);
524 priv->settings_widget = NULL;
527 if (empathy_account_settings_is_ready (settings))
529 account_dialog_create_settings_widget (dialog, settings);
533 priv->settings_ready = settings;
534 priv->settings_ready_id =
535 g_signal_connect (settings, "notify::ready",
536 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
542 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
543 GtkCellEditable *editable,
545 EmpathyAccountsDialog *dialog)
547 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
549 if (priv->connecting_id)
550 g_source_remove (priv->connecting_id);
552 DEBUG ("Editing account name started; stopping flashing");
556 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
557 GtkCellRenderer *cell,
560 EmpathyAccountsDialog *dialog)
562 EmpathyAccountSettings *settings;
565 TpConnectionStatus status;
566 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
568 gtk_tree_model_get (model, iter,
570 COL_ACCOUNT_SETTINGS_POINTER, &settings,
573 icon_name = empathy_account_settings_get_icon_name (settings);
574 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
578 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
579 (status == TP_CONNECTION_STATUS_CONNECTING &&
580 !priv->connecting_show))
582 GdkPixbuf *modded_pixbuf;
584 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
587 gdk_pixbuf_get_width (pixbuf),
588 gdk_pixbuf_get_height (pixbuf));
590 gdk_pixbuf_saturate_and_pixelate (pixbuf,
594 g_object_unref (pixbuf);
595 pixbuf = modded_pixbuf;
604 g_object_unref (settings);
607 g_object_unref (pixbuf);
611 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
616 gtk_tree_model_row_changed (model, path, iter);
622 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
626 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
628 priv->connecting_show = !priv->connecting_show;
630 view = GTK_TREE_VIEW (priv->treeview);
631 model = gtk_tree_view_get_model (view);
633 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
639 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
642 EmpathyAccountsDialog *dialog)
644 EmpathyAccountSettings *settings;
646 GtkTreePath *treepath;
648 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
650 if (empathy_account_manager_get_connecting_accounts
651 (priv->account_manager) > 0)
653 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
654 (GSourceFunc) accounts_dialog_flash_connecting_cb,
658 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
659 treepath = gtk_tree_path_new_from_string (path);
660 gtk_tree_model_get_iter (model, &iter, treepath);
661 gtk_tree_model_get (model, &iter,
662 COL_ACCOUNT_SETTINGS_POINTER, &settings,
664 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
667 gtk_tree_path_free (treepath);
669 empathy_account_settings_set_display_name_async (settings, new_text,
671 g_object_set (settings, "display-name-overridden", TRUE, NULL);
672 g_object_unref (settings);
676 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
680 EmpathyAccount *account;
683 GtkTreeSelection *selection;
684 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
685 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
687 if (response_id == GTK_RESPONSE_YES)
689 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
691 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
694 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
698 g_signal_handlers_disconnect_by_func (account,
699 accounts_dialog_account_display_name_changed_cb, account_dialog);
700 empathy_account_remove_async (account, NULL, NULL);
701 g_object_unref (account);
704 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
705 accounts_dialog_model_select_first (account_dialog);
708 gtk_widget_destroy (GTK_WIDGET (message_dialog));
712 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
713 const gchar *path_string,
714 EmpathyAccountsDialog *dialog)
716 EmpathyAccount *account;
719 GtkWidget *message_dialog;
720 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
722 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
724 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
727 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
729 if (account == NULL || !empathy_account_is_valid (account))
731 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
732 accounts_dialog_model_select_first (dialog);
736 message_dialog = gtk_message_dialog_new
737 (GTK_WINDOW (priv->window),
738 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
739 GTK_MESSAGE_QUESTION,
741 _("You are about to remove your %s account!\n"
742 "Are you sure you want to proceed?"),
743 empathy_account_get_display_name (account));
745 gtk_message_dialog_format_secondary_text
746 (GTK_MESSAGE_DIALOG (message_dialog),
747 _("Any associated conversations and chat rooms will NOT be "
748 "removed if you decide to proceed.\n"
750 "Should you decide to add the account back at a later time, "
751 "they will still be available."));
753 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
756 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
760 g_signal_connect (message_dialog, "response",
761 G_CALLBACK (accounts_dialog_delete_account_response_cb), dialog);
763 gtk_widget_show (message_dialog);
766 g_object_unref (account);
770 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
773 GtkTreeViewColumn *column;
774 GtkCellRenderer *cell;
775 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
777 view = GTK_TREE_VIEW (priv->treeview);
778 gtk_tree_view_set_headers_visible (view, FALSE);
781 column = gtk_tree_view_column_new ();
782 gtk_tree_view_column_set_expand (column, TRUE);
783 gtk_tree_view_append_column (view, column);
786 cell = gtk_cell_renderer_pixbuf_new ();
787 gtk_tree_view_column_pack_start (column, cell, FALSE);
788 gtk_tree_view_column_set_cell_data_func (column, cell,
789 (GtkTreeCellDataFunc)
790 accounts_dialog_model_pixbuf_data_func,
795 cell = gtk_cell_renderer_text_new ();
797 "ellipsize", PANGO_ELLIPSIZE_END,
801 gtk_tree_view_column_pack_start (column, cell, TRUE);
802 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
803 g_signal_connect (cell, "edited",
804 G_CALLBACK (accounts_dialog_name_edited_cb),
806 g_signal_connect (cell, "editing-started",
807 G_CALLBACK (accounts_dialog_name_editing_started_cb),
811 cell = empathy_cell_renderer_activatable_new ();
812 gtk_tree_view_column_pack_start (column, cell, FALSE);
814 "icon-name", GTK_STOCK_DELETE,
817 g_signal_connect (cell, "path-activated",
818 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
822 static EmpathyAccountSettings *
823 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
827 GtkTreeSelection *selection;
829 EmpathyAccountSettings *settings;
830 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
832 view = GTK_TREE_VIEW (priv->treeview);
833 selection = gtk_tree_view_get_selection (view);
835 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
838 gtk_tree_model_get (model, &iter,
839 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
845 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
846 EmpathyAccountsDialog *dialog)
848 EmpathyAccountSettings *settings;
851 gboolean is_selection;
853 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
855 settings = accounts_dialog_model_get_selected_settings (dialog);
856 accounts_dialog_update_settings (dialog, settings);
858 if (settings != NULL)
859 g_object_unref (settings);
863 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
867 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
868 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
870 gtk_widget_destroy (GTK_WIDGET (message_dialog));
872 if (response_id == GTK_RESPONSE_YES)
874 /* The user wants to lose unsaved changes to the currently selected
875 * account and select another account. We discard the changes and
876 * select the other account. */
878 GtkTreeSelection *selection;
881 priv->force_change_row = TRUE;
882 empathy_account_widget_discard_pending_changes (
883 priv->setting_widget_object);
885 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
886 selection = gtk_tree_view_get_selection (
887 GTK_TREE_VIEW (priv->treeview));
889 if (gtk_tree_model_get_iter_from_string (model,
890 &iter, priv->destination_path))
892 /* This will trigger a call to
893 * accounts_dialog_account_selection_change() */
894 gtk_tree_selection_select_iter (selection, &iter);
899 priv->force_change_row = FALSE;
904 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
907 gboolean path_currently_selected,
910 EmpathyAccount *account;
911 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
912 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
914 if (priv->force_change_row)
916 /* We came back here because the user wants to discard changes to his
917 * modified account. The changes have already been discarded so we
918 * just change the selected row. */
919 priv->force_change_row = FALSE;
923 if (accounts_dialog_has_pending_change (dialog, &account))
925 /* The currently selected account has some unsaved changes. We ask
926 * the user if he really wants to lose his changes and select another
928 priv->destination_path = gtk_tree_path_to_string (path);
931 message = g_strdup_printf (
932 _("There are unsaved modification regarding your %s account.\n"
933 "You are about to select another account, which will discard\n"
934 "your changes. Are you sure you want to proceed?"),
935 empathy_account_get_display_name (account));
937 empathy_show_yes_no_question_dialog (GTK_WINDOW (priv->window),
938 message, G_CALLBACK (accounts_dialog_selection_change_response_cb),
952 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
955 GtkTreeSelection *selection;
956 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
958 store = gtk_list_store_new (COL_COUNT,
959 G_TYPE_STRING, /* name */
960 G_TYPE_UINT, /* status */
961 EMPATHY_TYPE_ACCOUNT, /* account */
962 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
964 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
965 GTK_TREE_MODEL (store));
967 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
968 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
969 gtk_tree_selection_set_select_function (selection,
970 accounts_dialog_account_selection_change, dialog, NULL);
972 g_signal_connect (selection, "changed",
973 G_CALLBACK (accounts_dialog_model_selection_changed),
976 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
977 COL_NAME, GTK_SORT_ASCENDING);
979 accounts_dialog_model_add_columns (dialog);
981 g_object_unref (store);
985 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
986 EmpathyAccountSettings *settings,
990 GtkTreeSelection *selection;
993 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
995 /* Update the status in the model */
996 view = GTK_TREE_VIEW (priv->treeview);
997 selection = gtk_tree_view_get_selection (view);
998 model = gtk_tree_view_get_model (view);
1000 for (ok = gtk_tree_model_get_iter_first (model, iter);
1002 ok = gtk_tree_model_iter_next (model, iter))
1004 EmpathyAccountSettings *this_settings;
1007 gtk_tree_model_get (model, iter,
1008 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1011 equal = (this_settings == settings);
1012 g_object_unref (this_settings);
1022 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1023 EmpathyAccount *account,
1027 GtkTreeSelection *selection;
1028 GtkTreeModel *model;
1030 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1032 /* Update the status in the model */
1033 view = GTK_TREE_VIEW (priv->treeview);
1034 selection = gtk_tree_view_get_selection (view);
1035 model = gtk_tree_view_get_model (view);
1037 for (ok = gtk_tree_model_get_iter_first (model, iter);
1039 ok = gtk_tree_model_iter_next (model, iter))
1041 EmpathyAccountSettings *settings;
1044 gtk_tree_model_get (model, iter,
1045 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1048 equal = empathy_account_settings_has_account (settings, account);
1049 g_object_unref (settings);
1059 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1060 EmpathyAccountSettings *settings)
1062 GtkTreeSelection *selection;
1064 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1066 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1067 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1068 gtk_tree_selection_select_iter (selection, &iter);
1071 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1072 EmpathyAccountSettings *settings)
1074 GtkTreeModel *model;
1077 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1079 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1080 name = empathy_account_settings_get_display_name (settings);
1082 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1084 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1086 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1087 COL_ACCOUNT_SETTINGS_POINTER, settings,
1092 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1093 EmpathyAccount *account,
1094 TpConnectionStatusReason reason,
1095 TpConnectionStatus current,
1096 TpConnectionStatus previous,
1097 EmpathyAccountsDialog *dialog)
1099 GtkTreeModel *model;
1102 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1104 /* Update the status in the model */
1105 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1107 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1111 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1112 COL_STATUS, current,
1115 path = gtk_tree_model_get_path (model, &iter);
1116 gtk_tree_model_row_changed (model, path, &iter);
1117 gtk_tree_path_free (path);
1120 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1122 if (!found && priv->connecting_id)
1124 g_source_remove (priv->connecting_id);
1125 priv->connecting_id = 0;
1128 if (found && !priv->connecting_id)
1129 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1130 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1135 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1139 const gchar *display_name;
1141 GtkTreeModel *model;
1142 EmpathyAccountSettings *settings;
1143 EmpathyAccount *selected_account;
1144 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1145 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1147 display_name = empathy_account_get_display_name (account);
1148 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1149 settings = accounts_dialog_model_get_selected_settings (dialog);
1150 selected_account = empathy_account_settings_get_account (settings);
1152 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1154 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1155 COL_NAME, display_name,
1159 if (selected_account == account)
1160 accounts_dialog_update_name_label (dialog, display_name);
1162 g_object_unref (settings);
1166 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1167 EmpathyAccount *account)
1169 EmpathyAccountSettings *settings;
1170 GtkTreeModel *model;
1172 TpConnectionStatus status;
1175 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1177 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1178 g_object_get (account, "connection-status", &status, NULL);
1179 name = empathy_account_get_display_name (account);
1180 enabled = empathy_account_is_enabled (account);
1182 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1183 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1185 settings = empathy_account_settings_new_for_account (account);
1187 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1190 COL_ACCOUNT_POINTER, account,
1191 COL_ACCOUNT_SETTINGS_POINTER, settings,
1194 accounts_dialog_connection_changed_cb (priv->account_manager,
1196 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1198 TP_CONNECTION_STATUS_DISCONNECTED,
1201 g_signal_connect (account, "notify::display-name",
1202 G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
1204 g_object_unref (settings);
1208 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1209 EmpathyAccountSettings *settings)
1211 GtkTreeModel *model;
1213 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1215 gboolean enabled = FALSE;
1216 EmpathyAccount *account;
1217 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1219 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1220 name = empathy_account_settings_get_display_name (settings);
1222 account = empathy_account_settings_get_account (settings);
1223 if (account != NULL)
1225 enabled = empathy_account_is_enabled (account);
1226 g_object_get (account, "connection-status", &status, NULL);
1229 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1230 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1233 COL_ACCOUNT_POINTER, account,
1234 COL_ACCOUNT_SETTINGS_POINTER, settings,
1239 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1240 EmpathyAccount *account,
1241 EmpathyAccountsDialog *dialog)
1243 accounts_dialog_add_account (dialog, account);
1248 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1249 EmpathyAccount *account,
1250 EmpathyAccountsDialog *dialog)
1253 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1255 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1257 g_signal_handlers_disconnect_by_func (account,
1258 accounts_dialog_account_display_name_changed_cb, dialog);
1259 gtk_list_store_remove (GTK_LIST_STORE (
1260 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1265 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1266 EmpathyAccount *account,
1269 GtkTreeModel *model;
1270 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1272 /* Update the status in the model */
1273 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1275 DEBUG ("Account %s is now %s",
1276 empathy_account_get_display_name (account),
1277 enabled ? "enabled" : "disabled");
1281 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1282 EmpathyAccount *account,
1283 EmpathyAccountsDialog *dialog)
1285 enable_or_disable_account (dialog, account, FALSE);
1289 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1290 EmpathyAccount *account,
1291 EmpathyAccountsDialog *dialog)
1293 enable_or_disable_account (dialog, account, TRUE);
1297 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1298 EmpathyAccount *account,
1299 EmpathyAccountsDialog *dialog)
1301 EmpathyAccountSettings *settings, *selected_settings;
1302 GtkTreeModel *model;
1304 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1306 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1308 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1311 gtk_tree_model_get (model, &iter,
1312 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1315 accounts_dialog_update (dialog, settings);
1316 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1318 if (settings == selected_settings)
1319 accounts_dialog_update_name_label (dialog,
1320 empathy_account_settings_get_display_name (settings));
1323 g_object_unref (settings);
1325 if (selected_settings)
1326 g_object_unref (selected_settings);
1330 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1331 EmpathyAccountsDialog *dialog)
1333 EmpathyAccountSettings *settings;
1335 const gchar *display_name;
1336 TpConnectionManager *cm;
1337 TpConnectionManagerProtocol *proto;
1338 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1340 cm = empathy_protocol_chooser_dup_selected (
1341 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
1342 display_name = empathy_protocol_name_to_display_name (proto->name);
1344 if (display_name == NULL)
1345 display_name = proto->name;
1347 /* Create account */
1348 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1351 str = g_strdup_printf (_("New %s account"), display_name);
1352 settings = empathy_account_settings_new (cm->name, proto->name, str);
1356 if (tp_connection_manager_protocol_can_register (proto))
1360 active = gtk_toggle_button_get_active
1361 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1363 empathy_account_settings_set_boolean (settings, "register", TRUE);
1366 accounts_dialog_add (dialog, settings);
1367 accounts_dialog_model_set_selected (dialog, settings);
1369 g_object_unref (settings);
1370 g_object_unref (cm);
1374 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1375 EmpathyAccountsDialog *dialog)
1377 EmpathyAccountSettings *settings;
1379 settings = accounts_dialog_model_get_selected_settings (dialog);
1380 accounts_dialog_update_settings (dialog, settings);
1383 g_object_unref (settings);
1387 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1388 EmpathyAccountsDialog *dialog)
1390 empathy_url_show (button, "ghelp:empathy?accounts-window");
1394 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1398 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1400 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1402 if (response_id == GTK_RESPONSE_YES)
1403 gtk_widget_destroy (account_dialog);
1407 accounts_dialog_response_cb (GtkWidget *widget,
1409 EmpathyAccountsDialog *dialog)
1411 EmpathyAccount *account;
1412 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1414 if (accounts_dialog_has_pending_change (dialog, &account))
1418 message = g_strdup_printf (
1419 _("There are unsaved modifications regarding your %s account.\n"
1420 "Are you sure you want to close the window? "),
1421 empathy_account_get_display_name (account));
1423 empathy_show_yes_no_question_dialog (GTK_WINDOW (priv->window),
1424 message, G_CALLBACK (accounts_dialog_close_response_cb),
1429 else if (response == GTK_RESPONSE_CLOSE)
1430 gtk_widget_destroy (widget);
1434 accounts_dialog_destroy_cb (GtkObject *obj,
1435 EmpathyAccountsDialog *dialog)
1439 g_object_unref (dialog);
1443 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1444 EmpathyAccount *account)
1446 GtkTreeSelection *selection;
1448 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1450 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1451 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1452 gtk_tree_selection_select_iter (selection, &iter);
1456 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1458 EmpathyAccountsDialog *dialog)
1460 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1462 if (empathy_connection_managers_is_ready (cms))
1464 accounts_dialog_update_settings (dialog, NULL);
1466 if (priv->initial_selection != NULL)
1468 accounts_dialog_set_selected_account
1469 (dialog, priv->initial_selection);
1470 g_object_unref (priv->initial_selection);
1471 priv->initial_selection = NULL;
1477 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1481 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1483 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1485 gui = empathy_builder_get_file (filename,
1486 "accounts_dialog", &priv->window,
1487 "vbox_details", &priv->vbox_details,
1488 "frame_no_protocol", &priv->frame_no_protocol,
1489 "alignment_settings", &priv->alignment_settings,
1490 "treeview", &priv->treeview,
1491 "frame_new_account", &priv->frame_new_account,
1492 "hbox_type", &priv->hbox_type,
1493 "button_create", &priv->button_create,
1494 "button_back", &priv->button_back,
1495 "radiobutton_reuse", &priv->radiobutton_reuse,
1496 "radiobutton_register", &priv->radiobutton_register,
1497 "image_type", &priv->image_type,
1498 "label_name", &priv->label_name,
1499 "button_add", &priv->button_add,
1503 empathy_builder_connect (gui, dialog,
1504 "accounts_dialog", "response", accounts_dialog_response_cb,
1505 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1506 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1507 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1508 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1509 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1512 g_object_unref (gui);
1514 priv->combobox_protocol = empathy_protocol_chooser_new ();
1515 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1516 priv->combobox_protocol,
1518 gtk_widget_show (priv->combobox_protocol);
1519 g_signal_connect (priv->combobox_protocol, "changed",
1520 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1523 if (priv->parent_window)
1524 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1525 priv->parent_window);
1529 do_dispose (GObject *obj)
1531 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1532 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1534 /* Disconnect signals */
1535 g_signal_handlers_disconnect_by_func (priv->account_manager,
1536 accounts_dialog_account_added_cb,
1538 g_signal_handlers_disconnect_by_func (priv->account_manager,
1539 accounts_dialog_account_removed_cb,
1541 g_signal_handlers_disconnect_by_func (priv->account_manager,
1542 accounts_dialog_account_enabled_cb,
1544 g_signal_handlers_disconnect_by_func (priv->account_manager,
1545 accounts_dialog_account_disabled_cb,
1547 g_signal_handlers_disconnect_by_func (priv->account_manager,
1548 accounts_dialog_account_changed_cb,
1550 g_signal_handlers_disconnect_by_func (priv->account_manager,
1551 accounts_dialog_connection_changed_cb,
1554 if (priv->connecting_id)
1555 g_source_remove (priv->connecting_id);
1557 if (priv->account_manager != NULL)
1559 g_object_unref (priv->account_manager);
1560 priv->account_manager = NULL;
1563 if (priv->cms != NULL)
1565 g_object_unref (priv->cms);
1569 if (priv->initial_selection != NULL)
1570 g_object_unref (priv->initial_selection);
1571 priv->initial_selection = NULL;
1573 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1577 do_constructor (GType type,
1579 GObjectConstructParam *props)
1583 if (dialog_singleton)
1585 retval = G_OBJECT (dialog_singleton);
1586 g_object_ref (retval);
1591 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1592 (type, n_props, props);
1594 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1595 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1602 do_get_property (GObject *object,
1607 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1609 switch (property_id)
1612 g_value_set_object (value, priv->parent_window);
1615 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1620 do_set_property (GObject *object,
1622 const GValue *value,
1625 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1627 switch (property_id)
1630 priv->parent_window = g_value_get_object (value);
1633 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1638 do_constructed (GObject *object)
1640 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1641 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1642 GList *accounts, *l;
1643 gboolean import_asked;
1645 accounts_dialog_build_ui (dialog);
1647 /* Set up signalling */
1648 priv->account_manager = empathy_account_manager_dup_singleton ();
1650 g_signal_connect (priv->account_manager, "account-created",
1651 G_CALLBACK (accounts_dialog_account_added_cb),
1653 g_signal_connect (priv->account_manager, "account-deleted",
1654 G_CALLBACK (accounts_dialog_account_removed_cb),
1656 g_signal_connect (priv->account_manager, "account-enabled",
1657 G_CALLBACK (accounts_dialog_account_enabled_cb),
1659 g_signal_connect (priv->account_manager, "account-disabled",
1660 G_CALLBACK (accounts_dialog_account_disabled_cb),
1662 g_signal_connect (priv->account_manager, "account-changed",
1663 G_CALLBACK (accounts_dialog_account_changed_cb),
1665 g_signal_connect (priv->account_manager, "account-connection-changed",
1666 G_CALLBACK (accounts_dialog_connection_changed_cb),
1669 accounts_dialog_model_setup (dialog);
1671 /* Add existing accounts */
1672 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1673 for (l = accounts; l; l = l->next)
1675 accounts_dialog_add_account (dialog, l->data);
1676 g_object_unref (l->data);
1678 g_list_free (accounts);
1680 priv->cms = empathy_connection_managers_dup_singleton ();
1681 if (!empathy_connection_managers_is_ready (priv->cms))
1682 g_signal_connect (priv->cms, "notify::ready",
1683 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1685 accounts_dialog_model_select_first (dialog);
1687 empathy_conf_get_bool (empathy_conf_get (),
1688 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1691 if (empathy_import_accounts_to_import ())
1696 GtkWidget *import_dialog;
1698 empathy_conf_set_bool (empathy_conf_get (),
1699 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1700 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1702 gtk_widget_show (import_dialog);
1708 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1710 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1711 GParamSpec *param_spec;
1713 oclass->constructor = do_constructor;
1714 oclass->dispose = do_dispose;
1715 oclass->constructed = do_constructed;
1716 oclass->set_property = do_set_property;
1717 oclass->get_property = do_get_property;
1719 param_spec = g_param_spec_object ("parent",
1720 "parent", "The parent window",
1722 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1723 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1725 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1729 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1731 EmpathyAccountsDialogPriv *priv;
1733 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1734 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1735 EmpathyAccountsDialogPriv);
1736 dialog->priv = priv;
1739 /* public methods */
1742 empathy_accounts_dialog_show (GtkWindow *parent,
1743 EmpathyAccount *selected_account)
1745 EmpathyAccountsDialog *dialog;
1746 EmpathyAccountsDialogPriv *priv;
1748 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1749 "parent", parent, NULL);
1751 priv = GET_PRIV (dialog);
1753 if (selected_account)
1755 if (empathy_connection_managers_is_ready (priv->cms))
1756 accounts_dialog_set_selected_account (dialog, selected_account);
1758 /* save the selection to set it later when the cms
1761 priv->initial_selection = g_object_ref (selected_account);
1764 gtk_window_present (GTK_WINDOW (priv->window));
1766 return priv->window;