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 g_object_unref (settings);
355 return has_pending_changes;
359 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
360 EmpathyAccountsDialog *dialog)
362 TpConnectionManager *cm;
363 TpConnectionManagerProtocol *proto;
364 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
366 cm = empathy_protocol_chooser_dup_selected (
367 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
378 if (tp_connection_manager_protocol_can_register (proto))
380 gtk_widget_show (priv->radiobutton_register);
381 gtk_widget_show (priv->radiobutton_reuse);
385 gtk_widget_hide (priv->radiobutton_register);
386 gtk_widget_hide (priv->radiobutton_reuse);
392 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
396 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
398 view = GTK_TREE_VIEW (priv->treeview);
399 model = gtk_tree_view_get_model (view);
401 gtk_widget_set_sensitive (priv->button_add, FALSE);
402 gtk_widget_hide (priv->vbox_details);
403 gtk_widget_hide (priv->frame_no_protocol);
404 gtk_widget_show (priv->frame_new_account);
406 /* If we have no account, no need of a back button */
407 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
408 gtk_widget_show (priv->button_back);
410 gtk_widget_hide (priv->button_back);
412 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
413 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
415 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
416 gtk_widget_grab_focus (priv->combobox_protocol);
420 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
424 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
425 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
427 gtk_widget_destroy (GTK_WIDGET (message_dialog));
429 if (response_id == GTK_RESPONSE_YES)
431 empathy_account_widget_discard_pending_changes (
432 priv->setting_widget_object);
433 accounts_dialog_setup_ui_to_add_account (dialog);
438 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
439 EmpathyAccountsDialog *dialog)
441 EmpathyAccount *account;
442 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
444 if (accounts_dialog_has_pending_change (dialog, &account))
448 message = g_strdup_printf (
449 _("There are unsaved modification regarding your %s account.\n"
450 "You are about to create a new account, which will discard\n"
451 "your changes. Are you sure you want to proceed?"),
452 empathy_account_get_display_name (account));
454 empathy_show_yes_no_question_dialog (GTK_WINDOW (priv->window),
456 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
463 accounts_dialog_setup_ui_to_add_account (dialog);
468 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
469 EmpathyAccountSettings *settings)
471 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
473 if (priv->settings_ready != NULL)
475 g_signal_handler_disconnect (priv->settings_ready,
476 priv->settings_ready_id);
477 priv->settings_ready = NULL;
478 priv->settings_ready_id = 0;
486 view = GTK_TREE_VIEW (priv->treeview);
487 model = gtk_tree_view_get_model (view);
489 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
491 /* We have configured accounts, select the first one */
492 accounts_dialog_model_select_first (dialog);
495 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
497 /* We have no account configured but we have some
498 * profiles installed. The user obviously wants to add
499 * an account. Click on the Add button for him. */
500 accounts_dialog_button_add_clicked_cb (priv->button_add,
505 /* No account and no profile, warn the user */
506 gtk_widget_hide (priv->vbox_details);
507 gtk_widget_hide (priv->frame_new_account);
508 gtk_widget_show (priv->frame_no_protocol);
509 gtk_widget_set_sensitive (priv->button_add, FALSE);
513 /* We have an account selected, destroy old settings and create a new
514 * one for the account selected */
515 gtk_widget_hide (priv->frame_new_account);
516 gtk_widget_hide (priv->frame_no_protocol);
517 gtk_widget_show (priv->vbox_details);
518 gtk_widget_set_sensitive (priv->button_add, TRUE);
520 if (priv->settings_widget)
522 gtk_widget_destroy (priv->settings_widget);
523 priv->settings_widget = NULL;
526 if (empathy_account_settings_is_ready (settings))
528 account_dialog_create_settings_widget (dialog, settings);
532 priv->settings_ready = settings;
533 priv->settings_ready_id =
534 g_signal_connect (settings, "notify::ready",
535 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
541 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
542 GtkCellEditable *editable,
544 EmpathyAccountsDialog *dialog)
546 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
548 if (priv->connecting_id)
549 g_source_remove (priv->connecting_id);
551 DEBUG ("Editing account name started; stopping flashing");
555 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
556 GtkCellRenderer *cell,
559 EmpathyAccountsDialog *dialog)
561 EmpathyAccountSettings *settings;
564 TpConnectionStatus status;
565 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
567 gtk_tree_model_get (model, iter,
569 COL_ACCOUNT_SETTINGS_POINTER, &settings,
572 icon_name = empathy_account_settings_get_icon_name (settings);
573 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
577 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
578 (status == TP_CONNECTION_STATUS_CONNECTING &&
579 !priv->connecting_show))
581 GdkPixbuf *modded_pixbuf;
583 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
586 gdk_pixbuf_get_width (pixbuf),
587 gdk_pixbuf_get_height (pixbuf));
589 gdk_pixbuf_saturate_and_pixelate (pixbuf,
593 g_object_unref (pixbuf);
594 pixbuf = modded_pixbuf;
603 g_object_unref (settings);
606 g_object_unref (pixbuf);
610 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
615 gtk_tree_model_row_changed (model, path, iter);
621 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
625 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
627 priv->connecting_show = !priv->connecting_show;
629 view = GTK_TREE_VIEW (priv->treeview);
630 model = gtk_tree_view_get_model (view);
632 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
638 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
641 EmpathyAccountsDialog *dialog)
643 EmpathyAccountSettings *settings;
645 GtkTreePath *treepath;
647 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
649 if (empathy_account_manager_get_connecting_accounts
650 (priv->account_manager) > 0)
652 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
653 (GSourceFunc) accounts_dialog_flash_connecting_cb,
657 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
658 treepath = gtk_tree_path_new_from_string (path);
659 gtk_tree_model_get_iter (model, &iter, treepath);
660 gtk_tree_model_get (model, &iter,
661 COL_ACCOUNT_SETTINGS_POINTER, &settings,
663 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
666 gtk_tree_path_free (treepath);
668 empathy_account_settings_set_display_name_async (settings, new_text,
670 g_object_set (settings, "display-name-overridden", TRUE, NULL);
671 g_object_unref (settings);
675 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
679 EmpathyAccount *account;
682 GtkTreeSelection *selection;
683 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
684 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
686 if (response_id == GTK_RESPONSE_YES)
688 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
690 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
693 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
697 g_signal_handlers_disconnect_by_func (account,
698 accounts_dialog_account_display_name_changed_cb, account_dialog);
699 empathy_account_remove_async (account, NULL, NULL);
700 g_object_unref (account);
703 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
704 accounts_dialog_model_select_first (account_dialog);
707 gtk_widget_destroy (GTK_WIDGET (message_dialog));
711 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
712 const gchar *path_string,
713 EmpathyAccountsDialog *dialog)
715 EmpathyAccount *account;
718 GtkWidget *message_dialog;
719 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
721 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
723 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
726 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
728 if (account == NULL || !empathy_account_is_valid (account))
730 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
731 accounts_dialog_model_select_first (dialog);
735 message_dialog = gtk_message_dialog_new
736 (GTK_WINDOW (priv->window),
737 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
738 GTK_MESSAGE_QUESTION,
740 _("You are about to remove your %s account!\n"
741 "Are you sure you want to proceed?"),
742 empathy_account_get_display_name (account));
744 gtk_message_dialog_format_secondary_text
745 (GTK_MESSAGE_DIALOG (message_dialog),
746 _("Any associated conversations and chat rooms will NOT be "
747 "removed if you decide to proceed.\n"
749 "Should you decide to add the account back at a later time, "
750 "they will still be available."));
752 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
755 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
759 g_signal_connect (message_dialog, "response",
760 G_CALLBACK (accounts_dialog_delete_account_response_cb), dialog);
762 gtk_widget_show (message_dialog);
765 g_object_unref (account);
769 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
772 GtkTreeViewColumn *column;
773 GtkCellRenderer *cell;
774 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
776 view = GTK_TREE_VIEW (priv->treeview);
777 gtk_tree_view_set_headers_visible (view, FALSE);
780 column = gtk_tree_view_column_new ();
781 gtk_tree_view_column_set_expand (column, TRUE);
782 gtk_tree_view_append_column (view, column);
785 cell = gtk_cell_renderer_pixbuf_new ();
786 gtk_tree_view_column_pack_start (column, cell, FALSE);
787 gtk_tree_view_column_set_cell_data_func (column, cell,
788 (GtkTreeCellDataFunc)
789 accounts_dialog_model_pixbuf_data_func,
794 cell = gtk_cell_renderer_text_new ();
796 "ellipsize", PANGO_ELLIPSIZE_END,
800 gtk_tree_view_column_pack_start (column, cell, TRUE);
801 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
802 g_signal_connect (cell, "edited",
803 G_CALLBACK (accounts_dialog_name_edited_cb),
805 g_signal_connect (cell, "editing-started",
806 G_CALLBACK (accounts_dialog_name_editing_started_cb),
810 cell = empathy_cell_renderer_activatable_new ();
811 gtk_tree_view_column_pack_start (column, cell, FALSE);
813 "icon-name", GTK_STOCK_DELETE,
816 g_signal_connect (cell, "path-activated",
817 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
821 static EmpathyAccountSettings *
822 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
826 GtkTreeSelection *selection;
828 EmpathyAccountSettings *settings;
829 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
831 view = GTK_TREE_VIEW (priv->treeview);
832 selection = gtk_tree_view_get_selection (view);
834 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
837 gtk_tree_model_get (model, &iter,
838 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
844 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
845 EmpathyAccountsDialog *dialog)
847 EmpathyAccountSettings *settings;
850 gboolean is_selection;
852 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
854 settings = accounts_dialog_model_get_selected_settings (dialog);
855 accounts_dialog_update_settings (dialog, settings);
857 if (settings != NULL)
858 g_object_unref (settings);
862 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
866 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
867 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
869 gtk_widget_destroy (GTK_WIDGET (message_dialog));
871 if (response_id == GTK_RESPONSE_YES)
873 /* The user wants to lose unsaved changes to the currently selected
874 * account and select another account. We discard the changes and
875 * select the other account. */
877 GtkTreeSelection *selection;
880 priv->force_change_row = TRUE;
881 empathy_account_widget_discard_pending_changes (
882 priv->setting_widget_object);
884 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
885 selection = gtk_tree_view_get_selection (
886 GTK_TREE_VIEW (priv->treeview));
888 if (gtk_tree_model_get_iter_from_string (model,
889 &iter, priv->destination_path))
891 /* This will trigger a call to
892 * accounts_dialog_account_selection_change() */
893 gtk_tree_selection_select_iter (selection, &iter);
898 priv->force_change_row = FALSE;
903 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
906 gboolean path_currently_selected,
909 g_message ("path_currently_selected: %d - path: %s", path_currently_selected, gtk_tree_path_to_string (path));
911 EmpathyAccount *account;
912 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
913 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
915 if (priv->force_change_row)
917 /* We came back here because the user wants to discard changes to his
918 * modified account. The changes have already been discarded so we
919 * just change the selected row. */
920 priv->force_change_row = FALSE;
924 if (accounts_dialog_has_pending_change (dialog, &account))
926 /* The currently selected account has some unsaved changes. We ask
927 * the user if he really wants to lose his changes and select another
929 priv->destination_path = gtk_tree_path_to_string (path);
932 message = g_strdup_printf (
933 _("There are unsaved modification regarding your %s account.\n"
934 "You are about to select another account, which will discard\n"
935 "your changes. Are you sure you want to proceed?"),
936 empathy_account_get_display_name (account));
938 empathy_show_yes_no_question_dialog (GTK_WINDOW (priv->window),
939 message, G_CALLBACK (accounts_dialog_selection_change_response_cb),
953 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
956 GtkTreeSelection *selection;
957 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
959 store = gtk_list_store_new (COL_COUNT,
960 G_TYPE_STRING, /* name */
961 G_TYPE_UINT, /* status */
962 EMPATHY_TYPE_ACCOUNT, /* account */
963 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
965 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
966 GTK_TREE_MODEL (store));
968 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
969 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
970 gtk_tree_selection_set_select_function (selection,
971 accounts_dialog_account_selection_change, dialog, NULL);
973 g_signal_connect (selection, "changed",
974 G_CALLBACK (accounts_dialog_model_selection_changed),
977 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
978 COL_NAME, GTK_SORT_ASCENDING);
980 accounts_dialog_model_add_columns (dialog);
982 g_object_unref (store);
986 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
987 EmpathyAccountSettings *settings,
991 GtkTreeSelection *selection;
994 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
996 /* Update the status in the model */
997 view = GTK_TREE_VIEW (priv->treeview);
998 selection = gtk_tree_view_get_selection (view);
999 model = gtk_tree_view_get_model (view);
1001 for (ok = gtk_tree_model_get_iter_first (model, iter);
1003 ok = gtk_tree_model_iter_next (model, iter))
1005 EmpathyAccountSettings *this_settings;
1008 gtk_tree_model_get (model, iter,
1009 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1012 equal = (this_settings == settings);
1013 g_object_unref (this_settings);
1023 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1024 EmpathyAccount *account,
1028 GtkTreeSelection *selection;
1029 GtkTreeModel *model;
1031 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1033 /* Update the status in the model */
1034 view = GTK_TREE_VIEW (priv->treeview);
1035 selection = gtk_tree_view_get_selection (view);
1036 model = gtk_tree_view_get_model (view);
1038 for (ok = gtk_tree_model_get_iter_first (model, iter);
1040 ok = gtk_tree_model_iter_next (model, iter))
1042 EmpathyAccountSettings *settings;
1045 gtk_tree_model_get (model, iter,
1046 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1049 equal = empathy_account_settings_has_account (settings, account);
1050 g_object_unref (settings);
1060 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1061 EmpathyAccountSettings *settings)
1063 GtkTreeSelection *selection;
1065 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1067 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1068 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1069 gtk_tree_selection_select_iter (selection, &iter);
1072 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1073 EmpathyAccountSettings *settings)
1075 GtkTreeModel *model;
1078 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1080 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1081 name = empathy_account_settings_get_display_name (settings);
1083 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1085 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1087 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1088 COL_ACCOUNT_SETTINGS_POINTER, settings,
1093 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1094 EmpathyAccount *account,
1095 TpConnectionStatusReason reason,
1096 TpConnectionStatus current,
1097 TpConnectionStatus previous,
1098 EmpathyAccountsDialog *dialog)
1100 GtkTreeModel *model;
1103 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1105 /* Update the status in the model */
1106 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1108 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1112 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1113 COL_STATUS, current,
1116 path = gtk_tree_model_get_path (model, &iter);
1117 gtk_tree_model_row_changed (model, path, &iter);
1118 gtk_tree_path_free (path);
1121 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1123 if (!found && priv->connecting_id)
1125 g_source_remove (priv->connecting_id);
1126 priv->connecting_id = 0;
1129 if (found && !priv->connecting_id)
1130 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1131 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1136 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1140 const gchar *display_name;
1142 GtkTreeModel *model;
1143 EmpathyAccountSettings *settings;
1144 EmpathyAccount *selected_account;
1145 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1146 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1148 display_name = empathy_account_get_display_name (account);
1149 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1150 settings = accounts_dialog_model_get_selected_settings (dialog);
1151 selected_account = empathy_account_settings_get_account (settings);
1153 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1155 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1156 COL_NAME, display_name,
1160 if (selected_account == account)
1161 accounts_dialog_update_name_label (dialog, display_name);
1163 g_object_unref (settings);
1167 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1168 EmpathyAccount *account)
1170 EmpathyAccountSettings *settings;
1171 GtkTreeModel *model;
1173 TpConnectionStatus status;
1176 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1178 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1179 g_object_get (account, "connection-status", &status, NULL);
1180 name = empathy_account_get_display_name (account);
1181 enabled = empathy_account_is_enabled (account);
1183 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1184 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1186 settings = empathy_account_settings_new_for_account (account);
1188 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1191 COL_ACCOUNT_POINTER, account,
1192 COL_ACCOUNT_SETTINGS_POINTER, settings,
1195 accounts_dialog_connection_changed_cb (priv->account_manager,
1197 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1199 TP_CONNECTION_STATUS_DISCONNECTED,
1202 g_signal_connect (account, "notify::display-name",
1203 G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
1205 g_object_unref (settings);
1209 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1210 EmpathyAccountSettings *settings)
1212 GtkTreeModel *model;
1214 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1216 gboolean enabled = FALSE;
1217 EmpathyAccount *account;
1218 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1220 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1221 name = empathy_account_settings_get_display_name (settings);
1223 account = empathy_account_settings_get_account (settings);
1224 if (account != NULL)
1226 enabled = empathy_account_is_enabled (account);
1227 g_object_get (account, "connection-status", &status, NULL);
1230 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1231 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1234 COL_ACCOUNT_POINTER, account,
1235 COL_ACCOUNT_SETTINGS_POINTER, settings,
1240 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1241 EmpathyAccount *account,
1242 EmpathyAccountsDialog *dialog)
1244 accounts_dialog_add_account (dialog, account);
1249 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1250 EmpathyAccount *account,
1251 EmpathyAccountsDialog *dialog)
1254 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1256 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1258 g_signal_handlers_disconnect_by_func (account,
1259 accounts_dialog_account_display_name_changed_cb, dialog);
1260 gtk_list_store_remove (GTK_LIST_STORE (
1261 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1266 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1267 EmpathyAccount *account,
1270 GtkTreeModel *model;
1271 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1273 /* Update the status in the model */
1274 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1276 DEBUG ("Account %s is now %s",
1277 empathy_account_get_display_name (account),
1278 enabled ? "enabled" : "disabled");
1282 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1283 EmpathyAccount *account,
1284 EmpathyAccountsDialog *dialog)
1286 enable_or_disable_account (dialog, account, FALSE);
1290 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1291 EmpathyAccount *account,
1292 EmpathyAccountsDialog *dialog)
1294 enable_or_disable_account (dialog, account, TRUE);
1298 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1299 EmpathyAccount *account,
1300 EmpathyAccountsDialog *dialog)
1302 EmpathyAccountSettings *settings, *selected_settings;
1303 GtkTreeModel *model;
1305 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1307 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1309 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1312 gtk_tree_model_get (model, &iter,
1313 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1316 accounts_dialog_update (dialog, settings);
1317 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1319 if (settings == selected_settings)
1320 accounts_dialog_update_name_label (dialog,
1321 empathy_account_settings_get_display_name (settings));
1324 g_object_unref (settings);
1326 if (selected_settings)
1327 g_object_unref (selected_settings);
1331 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1332 EmpathyAccountsDialog *dialog)
1334 EmpathyAccountSettings *settings;
1336 const gchar *display_name;
1337 TpConnectionManager *cm;
1338 TpConnectionManagerProtocol *proto;
1339 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1341 cm = empathy_protocol_chooser_dup_selected (
1342 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
1343 display_name = empathy_protocol_name_to_display_name (proto->name);
1345 if (display_name == NULL)
1346 display_name = proto->name;
1348 /* Create account */
1349 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1352 str = g_strdup_printf (_("New %s account"), display_name);
1353 settings = empathy_account_settings_new (cm->name, proto->name, str);
1357 if (tp_connection_manager_protocol_can_register (proto))
1361 active = gtk_toggle_button_get_active
1362 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1364 empathy_account_settings_set_boolean (settings, "register", TRUE);
1367 accounts_dialog_add (dialog, settings);
1368 accounts_dialog_model_set_selected (dialog, settings);
1370 g_object_unref (settings);
1371 g_object_unref (cm);
1375 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1376 EmpathyAccountsDialog *dialog)
1378 EmpathyAccountSettings *settings;
1380 settings = accounts_dialog_model_get_selected_settings (dialog);
1381 accounts_dialog_update_settings (dialog, settings);
1384 g_object_unref (settings);
1388 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1389 EmpathyAccountsDialog *dialog)
1391 empathy_url_show (button, "ghelp:empathy?accounts-window");
1395 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1399 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1401 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1403 if (response_id == GTK_RESPONSE_YES)
1404 gtk_widget_destroy (account_dialog);
1408 accounts_dialog_response_cb (GtkWidget *widget,
1410 EmpathyAccountsDialog *dialog)
1412 EmpathyAccount *account;
1413 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1415 if (accounts_dialog_has_pending_change (dialog, &account))
1419 message = g_strdup_printf (
1420 _("There are unsaved modifications regarding your %s account.\n"
1421 "Are you sure you want to close the window? "),
1422 empathy_account_get_display_name (account));
1424 empathy_show_yes_no_question_dialog (GTK_WINDOW (priv->window),
1425 message, G_CALLBACK (accounts_dialog_close_response_cb),
1430 else if (response == GTK_RESPONSE_CLOSE)
1431 gtk_widget_destroy (widget);
1435 accounts_dialog_destroy_cb (GtkObject *obj,
1436 EmpathyAccountsDialog *dialog)
1440 g_object_unref (dialog);
1444 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1445 EmpathyAccount *account)
1447 GtkTreeSelection *selection;
1449 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1451 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1452 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1453 gtk_tree_selection_select_iter (selection, &iter);
1457 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1459 EmpathyAccountsDialog *dialog)
1461 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1463 if (empathy_connection_managers_is_ready (cms))
1465 accounts_dialog_update_settings (dialog, NULL);
1467 if (priv->initial_selection != NULL)
1469 accounts_dialog_set_selected_account
1470 (dialog, priv->initial_selection);
1471 g_object_unref (priv->initial_selection);
1472 priv->initial_selection = NULL;
1478 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1482 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1484 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1486 gui = empathy_builder_get_file (filename,
1487 "accounts_dialog", &priv->window,
1488 "vbox_details", &priv->vbox_details,
1489 "frame_no_protocol", &priv->frame_no_protocol,
1490 "alignment_settings", &priv->alignment_settings,
1491 "treeview", &priv->treeview,
1492 "frame_new_account", &priv->frame_new_account,
1493 "hbox_type", &priv->hbox_type,
1494 "button_create", &priv->button_create,
1495 "button_back", &priv->button_back,
1496 "radiobutton_reuse", &priv->radiobutton_reuse,
1497 "radiobutton_register", &priv->radiobutton_register,
1498 "image_type", &priv->image_type,
1499 "label_name", &priv->label_name,
1500 "button_add", &priv->button_add,
1504 empathy_builder_connect (gui, dialog,
1505 "accounts_dialog", "response", accounts_dialog_response_cb,
1506 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1507 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1508 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1509 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1510 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1513 g_object_unref (gui);
1515 priv->combobox_protocol = empathy_protocol_chooser_new ();
1516 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1517 priv->combobox_protocol,
1519 gtk_widget_show (priv->combobox_protocol);
1520 g_signal_connect (priv->combobox_protocol, "changed",
1521 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1524 if (priv->parent_window)
1525 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1526 priv->parent_window);
1530 do_dispose (GObject *obj)
1532 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1533 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1535 /* Disconnect signals */
1536 g_signal_handlers_disconnect_by_func (priv->account_manager,
1537 accounts_dialog_account_added_cb,
1539 g_signal_handlers_disconnect_by_func (priv->account_manager,
1540 accounts_dialog_account_removed_cb,
1542 g_signal_handlers_disconnect_by_func (priv->account_manager,
1543 accounts_dialog_account_enabled_cb,
1545 g_signal_handlers_disconnect_by_func (priv->account_manager,
1546 accounts_dialog_account_disabled_cb,
1548 g_signal_handlers_disconnect_by_func (priv->account_manager,
1549 accounts_dialog_account_changed_cb,
1551 g_signal_handlers_disconnect_by_func (priv->account_manager,
1552 accounts_dialog_connection_changed_cb,
1555 if (priv->connecting_id)
1556 g_source_remove (priv->connecting_id);
1558 if (priv->account_manager != NULL)
1560 g_object_unref (priv->account_manager);
1561 priv->account_manager = NULL;
1564 if (priv->cms != NULL)
1566 g_object_unref (priv->cms);
1570 if (priv->initial_selection != NULL)
1571 g_object_unref (priv->initial_selection);
1572 priv->initial_selection = NULL;
1574 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1578 do_constructor (GType type,
1580 GObjectConstructParam *props)
1584 if (dialog_singleton)
1586 retval = G_OBJECT (dialog_singleton);
1587 g_object_ref (retval);
1592 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1593 (type, n_props, props);
1595 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1596 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1603 do_get_property (GObject *object,
1608 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1610 switch (property_id)
1613 g_value_set_object (value, priv->parent_window);
1616 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1621 do_set_property (GObject *object,
1623 const GValue *value,
1626 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1628 switch (property_id)
1631 priv->parent_window = g_value_get_object (value);
1634 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1639 do_constructed (GObject *object)
1641 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1642 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1643 GList *accounts, *l;
1644 gboolean import_asked;
1646 accounts_dialog_build_ui (dialog);
1648 /* Set up signalling */
1649 priv->account_manager = empathy_account_manager_dup_singleton ();
1651 g_signal_connect (priv->account_manager, "account-created",
1652 G_CALLBACK (accounts_dialog_account_added_cb),
1654 g_signal_connect (priv->account_manager, "account-deleted",
1655 G_CALLBACK (accounts_dialog_account_removed_cb),
1657 g_signal_connect (priv->account_manager, "account-enabled",
1658 G_CALLBACK (accounts_dialog_account_enabled_cb),
1660 g_signal_connect (priv->account_manager, "account-disabled",
1661 G_CALLBACK (accounts_dialog_account_disabled_cb),
1663 g_signal_connect (priv->account_manager, "account-changed",
1664 G_CALLBACK (accounts_dialog_account_changed_cb),
1666 g_signal_connect (priv->account_manager, "account-connection-changed",
1667 G_CALLBACK (accounts_dialog_connection_changed_cb),
1670 accounts_dialog_model_setup (dialog);
1672 /* Add existing accounts */
1673 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1674 for (l = accounts; l; l = l->next)
1676 accounts_dialog_add_account (dialog, l->data);
1677 g_object_unref (l->data);
1679 g_list_free (accounts);
1681 priv->cms = empathy_connection_managers_dup_singleton ();
1682 if (!empathy_connection_managers_is_ready (priv->cms))
1683 g_signal_connect (priv->cms, "notify::ready",
1684 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1686 accounts_dialog_model_select_first (dialog);
1688 empathy_conf_get_bool (empathy_conf_get (),
1689 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1692 if (empathy_import_accounts_to_import ())
1697 GtkWidget *import_dialog;
1699 empathy_conf_set_bool (empathy_conf_get (),
1700 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1701 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1703 gtk_widget_show (import_dialog);
1709 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1711 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1712 GParamSpec *param_spec;
1714 oclass->constructor = do_constructor;
1715 oclass->dispose = do_dispose;
1716 oclass->constructed = do_constructed;
1717 oclass->set_property = do_set_property;
1718 oclass->get_property = do_get_property;
1720 param_spec = g_param_spec_object ("parent",
1721 "parent", "The parent window",
1723 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1724 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1726 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1730 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1732 EmpathyAccountsDialogPriv *priv;
1734 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1735 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1736 EmpathyAccountsDialogPriv);
1737 dialog->priv = priv;
1740 /* public methods */
1743 empathy_accounts_dialog_show (GtkWindow *parent,
1744 EmpathyAccount *selected_account)
1746 EmpathyAccountsDialog *dialog;
1747 EmpathyAccountsDialogPriv *priv;
1749 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1750 "parent", parent, NULL);
1752 priv = GET_PRIV (dialog);
1754 if (selected_account)
1756 if (empathy_connection_managers_is_ready (priv->cms))
1757 accounts_dialog_set_selected_account (dialog, selected_account);
1759 /* save the selection to set it later when the cms
1762 priv->initial_selection = g_object_ref (selected_account);
1765 gtk_window_present (GTK_WINDOW (priv->window));
1767 return priv->window;