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 /* The primary text of the dialog shown to the user when he is about to lose
62 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
63 "There are unsaved modification regarding your %s account."
65 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
66 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
68 static EmpathyAccountsDialog *dialog_singleton = NULL;
73 GtkWidget *alignment_settings;
75 GtkWidget *vbox_details;
76 GtkWidget *frame_no_protocol;
80 GtkWidget *button_add;
82 GtkWidget *frame_new_account;
83 GtkWidget *combobox_protocol;
85 GtkWidget *button_create;
86 GtkWidget *button_back;
87 GtkWidget *radiobutton_reuse;
88 GtkWidget *radiobutton_register;
90 GtkWidget *image_type;
91 GtkWidget *label_name;
92 GtkWidget *label_type;
93 GtkWidget *settings_widget;
95 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
96 * his GtkWidget. It is the only reliable source we can query to know if
97 * there are any unsaved changes to the currently selected account. We can't
98 * look at the account settings because it does not contain everything that
99 * can be changed using the EmpathyAccountWidget. For instance, it does not
100 * contain the state of the "Enabled" checkbox. */
101 EmpathyAccountWidget *setting_widget_object;
103 gboolean connecting_show;
106 gulong settings_ready_id;
107 EmpathyAccountSettings *settings_ready;
109 EmpathyAccountManager *account_manager;
110 EmpathyConnectionManagers *cms;
112 GtkWindow *parent_window;
113 EmpathyAccount *initial_selection;
115 /* Those are needed when changing the selected row. When a user selects
116 * another account and there are unsaved changes on the currently selected
117 * one, a confirmation message box is presented to him. Since his answer
118 * is retrieved asynchronously, we keep some information as member of the
119 * EmpathyAccountsDialog object. */
120 gboolean force_change_row;
121 GtkTreeRowReference *destination_row;
124 } EmpathyAccountsDialogPriv;
130 COL_ACCOUNT_SETTINGS_POINTER,
138 static void accounts_dialog_account_display_name_changed_cb (
139 EmpathyAccount *account,
143 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
144 EmpathyAccountsDialog *dialog);
146 static gboolean accounts_dialog_get_settings_iter (
147 EmpathyAccountsDialog *dialog,
148 EmpathyAccountSettings *settings,
151 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
156 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
157 EmpathyAccountSettings *settings);
160 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
161 const gchar *display_name)
164 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
166 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
167 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
173 empathy_account_dialog_widget_cancelled_cb (EmpathyAccountWidget *widget_object,
174 EmpathyAccountsDialog *dialog)
178 GtkTreeSelection *selection;
180 EmpathyAccountSettings *settings;
181 EmpathyAccount *account;
182 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
184 view = GTK_TREE_VIEW (priv->treeview);
185 selection = gtk_tree_view_get_selection (view);
187 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
190 gtk_tree_model_get (model, &iter,
191 COL_ACCOUNT_SETTINGS_POINTER, &settings,
192 COL_ACCOUNT_POINTER, &account, -1);
194 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
198 /* We were creating an account. We remove the selected row */
199 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
203 /* We were modifying an account. We discard the changes by reloading the
204 * settings and the UI. */
205 accounts_dialog_update_settings (dialog, settings);
206 g_object_unref (account);
209 if (settings != NULL)
210 g_object_unref (settings);
214 get_default_display_name (EmpathyAccountSettings *settings)
216 const gchar *login_id;
217 const gchar *protocol;
218 gchar *default_display_name;
220 login_id = empathy_account_settings_get_string (settings, "account");
221 protocol = empathy_account_settings_get_protocol (settings);
223 if (login_id != NULL)
225 if (!tp_strdiff (protocol, "irc"))
228 server = empathy_account_settings_get_string (settings, "server");
230 /* To translators: The first parameter is the login id and the
231 * second one is the server. The resulting string will be something
232 * like: "MyUserName on chat.freenode.net" */
233 default_display_name =
234 g_strdup_printf (_("%s on %s"), login_id, server);
238 default_display_name = g_strdup (login_id);
241 else if (protocol != NULL)
243 /* To translators: The parameter is the protocol name. The resulting
244 * string will be something like: "Jabber Account" */
245 default_display_name = g_strdup_printf (_("%s Account"), protocol);
249 default_display_name = g_strdup (_("New account"));
252 return default_display_name;
256 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
257 EmpathyAccountsDialog *dialog)
260 EmpathyAccountSettings *settings =
261 accounts_dialog_model_get_selected_settings (dialog);
263 display_name = get_default_display_name (settings);
265 empathy_account_settings_set_display_name_async (settings,
266 display_name, NULL, NULL);
268 g_free (display_name);
270 accounts_dialog_update_settings (dialog, settings);
273 g_object_unref (settings);
277 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
278 EmpathyAccountSettings *settings)
280 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
283 priv->setting_widget_object =
284 empathy_account_widget_new_for_protocol (settings, FALSE);
286 priv->settings_widget =
287 empathy_account_widget_get_widget (priv->setting_widget_object);
289 priv->settings_widget =
290 empathy_account_widget_get_widget (priv->setting_widget_object);
291 g_signal_connect (priv->setting_widget_object, "account-created",
292 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
293 g_signal_connect (priv->setting_widget_object, "cancelled",
294 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
296 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
297 priv->settings_widget);
298 gtk_widget_show (priv->settings_widget);
300 icon_name = empathy_account_settings_get_icon_name (settings);
302 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
303 icon_name, GTK_ICON_SIZE_DIALOG);
304 gtk_widget_set_tooltip_text (priv->image_type,
305 empathy_protocol_name_to_display_name
306 (empathy_account_settings_get_protocol (settings)));
308 accounts_dialog_update_name_label (dialog,
309 empathy_account_settings_get_display_name (settings));
313 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
315 EmpathyAccountsDialog *dialog)
317 if (empathy_account_settings_is_ready (settings))
318 account_dialog_create_settings_widget (dialog, settings);
322 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
326 GtkTreeSelection *selection;
328 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
331 view = GTK_TREE_VIEW (priv->treeview);
332 model = gtk_tree_view_get_model (view);
334 if (gtk_tree_model_get_iter_first (model, &iter))
336 selection = gtk_tree_view_get_selection (view);
337 gtk_tree_selection_select_iter (selection, &iter);
341 accounts_dialog_update_settings (dialog, NULL);
346 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
347 EmpathyAccount **account)
351 GtkTreeSelection *selection;
352 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
354 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
356 if (gtk_tree_selection_get_selected (selection, &model, &iter))
357 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
359 return *account != NULL && priv->setting_widget_object != NULL
360 && empathy_account_widget_contains_pending_changes (
361 priv->setting_widget_object);
365 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
366 EmpathyAccountsDialog *dialog)
368 TpConnectionManager *cm;
369 TpConnectionManagerProtocol *proto;
370 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
372 cm = empathy_protocol_chooser_dup_selected (
373 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
384 if (tp_connection_manager_protocol_can_register (proto))
386 gtk_widget_show (priv->radiobutton_register);
387 gtk_widget_show (priv->radiobutton_reuse);
391 gtk_widget_hide (priv->radiobutton_register);
392 gtk_widget_hide (priv->radiobutton_reuse);
398 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
402 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
404 view = GTK_TREE_VIEW (priv->treeview);
405 model = gtk_tree_view_get_model (view);
407 gtk_widget_set_sensitive (priv->button_add, FALSE);
408 gtk_widget_hide (priv->vbox_details);
409 gtk_widget_hide (priv->frame_no_protocol);
410 gtk_widget_show (priv->frame_new_account);
412 /* If we have no account, no need of a back button */
413 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
414 gtk_widget_show (priv->button_back);
416 gtk_widget_hide (priv->button_back);
418 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
419 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
421 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
422 gtk_widget_grab_focus (priv->combobox_protocol);
426 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
428 gchar *secondary_text,
429 GCallback response_callback,
431 const gchar *first_button_text,
435 GtkWidget *message_dialog;
436 const gchar *button_text;
437 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
439 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
440 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
441 GTK_MESSAGE_QUESTION,
445 gtk_message_dialog_format_secondary_text (
446 GTK_MESSAGE_DIALOG (message_dialog), secondary_text);
448 va_start (button_args, first_button_text);
449 for (button_text = first_button_text;
451 button_text = va_arg (button_args, const gchar *))
454 response_id = va_arg (button_args, gint);
456 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text, response_id);
458 va_end (button_args);
460 g_signal_connect (message_dialog, "response", response_callback, user_data);
462 gtk_widget_show (message_dialog);
466 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
470 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
471 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
473 gtk_widget_destroy (GTK_WIDGET (message_dialog));
475 if (response_id == GTK_RESPONSE_YES)
477 empathy_account_widget_discard_pending_changes (
478 priv->setting_widget_object);
479 accounts_dialog_setup_ui_to_add_account (dialog);
484 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
485 EmpathyAccountsDialog *dialog)
487 EmpathyAccount *account = NULL;
489 if (accounts_dialog_has_pending_change (dialog, &account))
491 gchar *question_dialog_primary_text = g_strdup_printf (
492 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
493 empathy_account_get_display_name (account));
495 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
496 "You are about to create a new account, which will discard\n"
497 "your changes. Are you sure you want to proceed?",
498 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
500 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
501 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
503 g_free (question_dialog_primary_text);
507 accounts_dialog_setup_ui_to_add_account (dialog);
512 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
513 EmpathyAccountSettings *settings)
515 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
517 if (priv->settings_ready != NULL)
519 g_signal_handler_disconnect (priv->settings_ready,
520 priv->settings_ready_id);
521 priv->settings_ready = NULL;
522 priv->settings_ready_id = 0;
530 view = GTK_TREE_VIEW (priv->treeview);
531 model = gtk_tree_view_get_model (view);
533 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
535 /* We have configured accounts, select the first one */
536 accounts_dialog_model_select_first (dialog);
539 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
541 /* We have no account configured but we have some
542 * profiles installed. The user obviously wants to add
543 * an account. Click on the Add button for him. */
544 accounts_dialog_button_add_clicked_cb (priv->button_add,
549 /* No account and no profile, warn the user */
550 gtk_widget_hide (priv->vbox_details);
551 gtk_widget_hide (priv->frame_new_account);
552 gtk_widget_show (priv->frame_no_protocol);
553 gtk_widget_set_sensitive (priv->button_add, FALSE);
557 /* We have an account selected, destroy old settings and create a new
558 * one for the account selected */
559 gtk_widget_hide (priv->frame_new_account);
560 gtk_widget_hide (priv->frame_no_protocol);
561 gtk_widget_show (priv->vbox_details);
562 gtk_widget_set_sensitive (priv->button_add, TRUE);
564 if (priv->settings_widget)
566 gtk_widget_destroy (priv->settings_widget);
567 priv->settings_widget = NULL;
570 if (empathy_account_settings_is_ready (settings))
572 account_dialog_create_settings_widget (dialog, settings);
576 priv->settings_ready = settings;
577 priv->settings_ready_id =
578 g_signal_connect (settings, "notify::ready",
579 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
585 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
586 GtkCellEditable *editable,
588 EmpathyAccountsDialog *dialog)
590 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
592 if (priv->connecting_id)
593 g_source_remove (priv->connecting_id);
595 DEBUG ("Editing account name started; stopping flashing");
599 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
600 GtkCellRenderer *cell,
603 EmpathyAccountsDialog *dialog)
605 EmpathyAccountSettings *settings;
608 TpConnectionStatus status;
609 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
611 gtk_tree_model_get (model, iter,
613 COL_ACCOUNT_SETTINGS_POINTER, &settings,
616 icon_name = empathy_account_settings_get_icon_name (settings);
617 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
621 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
622 (status == TP_CONNECTION_STATUS_CONNECTING &&
623 !priv->connecting_show))
625 GdkPixbuf *modded_pixbuf;
627 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
630 gdk_pixbuf_get_width (pixbuf),
631 gdk_pixbuf_get_height (pixbuf));
633 gdk_pixbuf_saturate_and_pixelate (pixbuf,
637 g_object_unref (pixbuf);
638 pixbuf = modded_pixbuf;
647 g_object_unref (settings);
650 g_object_unref (pixbuf);
654 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
659 gtk_tree_model_row_changed (model, path, iter);
665 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
669 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
671 priv->connecting_show = !priv->connecting_show;
673 view = GTK_TREE_VIEW (priv->treeview);
674 model = gtk_tree_view_get_model (view);
676 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
682 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
685 EmpathyAccountsDialog *dialog)
687 EmpathyAccountSettings *settings;
689 GtkTreePath *treepath;
691 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
693 if (empathy_account_manager_get_connecting_accounts
694 (priv->account_manager) > 0)
696 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
697 (GSourceFunc) accounts_dialog_flash_connecting_cb,
701 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
702 treepath = gtk_tree_path_new_from_string (path);
703 gtk_tree_model_get_iter (model, &iter, treepath);
704 gtk_tree_model_get (model, &iter,
705 COL_ACCOUNT_SETTINGS_POINTER, &settings,
707 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
710 gtk_tree_path_free (treepath);
712 empathy_account_settings_set_display_name_async (settings, new_text,
714 g_object_set (settings, "display-name-overridden", TRUE, NULL);
715 g_object_unref (settings);
719 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
723 EmpathyAccount *account;
726 GtkTreeSelection *selection;
727 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
728 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
730 if (response_id == GTK_RESPONSE_YES)
732 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
734 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
737 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
741 g_signal_handlers_disconnect_by_func (account,
742 accounts_dialog_account_display_name_changed_cb, account_dialog);
743 empathy_account_remove_async (account, NULL, NULL);
744 g_object_unref (account);
748 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
749 accounts_dialog_model_select_first (account_dialog);
752 gtk_widget_destroy (GTK_WIDGET (message_dialog));
756 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
757 const gchar *path_string,
758 EmpathyAccountsDialog *dialog)
760 EmpathyAccount *account;
763 gchar *question_dialog_primary_text;
764 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
766 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
768 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
771 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
773 if (account == NULL || !empathy_account_is_valid (account))
775 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
776 accounts_dialog_model_select_first (dialog);
780 question_dialog_primary_text = g_strdup_printf (
781 _("You are about to remove your %s account!\n"
782 "Are you sure you want to proceed?"),
783 empathy_account_get_display_name (account));
785 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
786 _("Any associated conversations and chat rooms will NOT be "
787 "removed if you decide to proceed.\n"
789 "Should you decide to add the account back at a later time, "
790 "they will still be available."),
791 G_CALLBACK (accounts_dialog_delete_account_response_cb),
793 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
794 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
796 g_free (question_dialog_primary_text);
800 g_object_unref (account);
806 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
809 GtkTreeViewColumn *column;
810 GtkCellRenderer *cell;
811 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
813 view = GTK_TREE_VIEW (priv->treeview);
814 gtk_tree_view_set_headers_visible (view, FALSE);
817 column = gtk_tree_view_column_new ();
818 gtk_tree_view_column_set_expand (column, TRUE);
819 gtk_tree_view_append_column (view, column);
822 cell = gtk_cell_renderer_pixbuf_new ();
823 gtk_tree_view_column_pack_start (column, cell, FALSE);
824 gtk_tree_view_column_set_cell_data_func (column, cell,
825 (GtkTreeCellDataFunc)
826 accounts_dialog_model_pixbuf_data_func,
831 cell = gtk_cell_renderer_text_new ();
833 "ellipsize", PANGO_ELLIPSIZE_END,
837 gtk_tree_view_column_pack_start (column, cell, TRUE);
838 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
839 g_signal_connect (cell, "edited",
840 G_CALLBACK (accounts_dialog_name_edited_cb),
842 g_signal_connect (cell, "editing-started",
843 G_CALLBACK (accounts_dialog_name_editing_started_cb),
847 cell = empathy_cell_renderer_activatable_new ();
848 gtk_tree_view_column_pack_start (column, cell, FALSE);
850 "icon-name", GTK_STOCK_DELETE,
853 g_signal_connect (cell, "path-activated",
854 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
858 static EmpathyAccountSettings *
859 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
863 GtkTreeSelection *selection;
865 EmpathyAccountSettings *settings;
866 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
868 view = GTK_TREE_VIEW (priv->treeview);
869 selection = gtk_tree_view_get_selection (view);
871 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
874 gtk_tree_model_get (model, &iter,
875 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
881 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
882 EmpathyAccountsDialog *dialog)
884 EmpathyAccountSettings *settings;
887 gboolean is_selection;
889 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
891 settings = accounts_dialog_model_get_selected_settings (dialog);
892 accounts_dialog_update_settings (dialog, settings);
894 if (settings != NULL)
895 g_object_unref (settings);
899 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
903 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
904 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
906 gtk_widget_destroy (GTK_WIDGET (message_dialog));
908 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
910 /* The user wants to lose unsaved changes to the currently selected
911 * account and select another account. We discard the changes and
912 * select the other account. */
914 GtkTreeSelection *selection;
916 priv->force_change_row = TRUE;
917 empathy_account_widget_discard_pending_changes (
918 priv->setting_widget_object);
920 path = gtk_tree_row_reference_get_path (priv->destination_row);
921 selection = gtk_tree_view_get_selection (
922 GTK_TREE_VIEW (priv->treeview));
926 /* This will trigger a call to
927 * accounts_dialog_account_selection_change() */
928 gtk_tree_selection_select_path (selection, path);
929 gtk_tree_path_free (path);
932 gtk_tree_row_reference_free (priv->destination_row);
936 priv->force_change_row = FALSE;
941 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
944 gboolean path_currently_selected,
947 EmpathyAccount *account = NULL;
948 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
949 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
951 if (priv->force_change_row)
953 /* We came back here because the user wants to discard changes to his
954 * modified account. The changes have already been discarded so we
955 * just change the selected row. */
956 priv->force_change_row = FALSE;
960 if (accounts_dialog_has_pending_change (dialog, &account))
962 /* The currently selected account has some unsaved changes. We ask
963 * the user if he really wants to lose his changes and select another
965 gchar *question_dialog_primary_text;
966 priv->destination_row = gtk_tree_row_reference_new (model, path);
968 question_dialog_primary_text = g_strdup_printf (
969 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
970 empathy_account_get_display_name (account));
972 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
973 "You are about to select another account, which will discard\n"
974 "your changes. Are you sure you want to proceed?",
975 G_CALLBACK (accounts_dialog_selection_change_response_cb),
977 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
978 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
980 g_free (question_dialog_primary_text);
991 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
994 GtkTreeSelection *selection;
995 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
997 store = gtk_list_store_new (COL_COUNT,
998 G_TYPE_STRING, /* name */
999 G_TYPE_UINT, /* status */
1000 EMPATHY_TYPE_ACCOUNT, /* account */
1001 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1003 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1004 GTK_TREE_MODEL (store));
1006 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1007 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1008 gtk_tree_selection_set_select_function (selection,
1009 accounts_dialog_account_selection_change, dialog, NULL);
1011 g_signal_connect (selection, "changed",
1012 G_CALLBACK (accounts_dialog_model_selection_changed),
1015 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1016 COL_NAME, GTK_SORT_ASCENDING);
1018 accounts_dialog_model_add_columns (dialog);
1020 g_object_unref (store);
1024 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1025 EmpathyAccountSettings *settings,
1029 GtkTreeSelection *selection;
1030 GtkTreeModel *model;
1032 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1034 /* Update the status in the model */
1035 view = GTK_TREE_VIEW (priv->treeview);
1036 selection = gtk_tree_view_get_selection (view);
1037 model = gtk_tree_view_get_model (view);
1039 for (ok = gtk_tree_model_get_iter_first (model, iter);
1041 ok = gtk_tree_model_iter_next (model, iter))
1043 EmpathyAccountSettings *this_settings;
1046 gtk_tree_model_get (model, iter,
1047 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1050 equal = (this_settings == settings);
1051 g_object_unref (this_settings);
1061 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1062 EmpathyAccount *account,
1066 GtkTreeSelection *selection;
1067 GtkTreeModel *model;
1069 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1071 /* Update the status in the model */
1072 view = GTK_TREE_VIEW (priv->treeview);
1073 selection = gtk_tree_view_get_selection (view);
1074 model = gtk_tree_view_get_model (view);
1076 for (ok = gtk_tree_model_get_iter_first (model, iter);
1078 ok = gtk_tree_model_iter_next (model, iter))
1080 EmpathyAccountSettings *settings;
1083 gtk_tree_model_get (model, iter,
1084 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1087 equal = empathy_account_settings_has_account (settings, account);
1088 g_object_unref (settings);
1098 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1099 EmpathyAccountSettings *settings)
1101 GtkTreeSelection *selection;
1103 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1105 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1106 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1107 gtk_tree_selection_select_iter (selection, &iter);
1110 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1111 EmpathyAccountSettings *settings)
1113 GtkTreeModel *model;
1116 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1118 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1119 name = empathy_account_settings_get_display_name (settings);
1121 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1123 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1125 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1126 COL_ACCOUNT_SETTINGS_POINTER, settings,
1131 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1132 EmpathyAccount *account,
1133 TpConnectionStatusReason reason,
1134 TpConnectionStatus current,
1135 TpConnectionStatus previous,
1136 EmpathyAccountsDialog *dialog)
1138 GtkTreeModel *model;
1141 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1143 /* Update the status in the model */
1144 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1146 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1150 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1151 COL_STATUS, current,
1154 path = gtk_tree_model_get_path (model, &iter);
1155 gtk_tree_model_row_changed (model, path, &iter);
1156 gtk_tree_path_free (path);
1159 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1161 if (!found && priv->connecting_id)
1163 g_source_remove (priv->connecting_id);
1164 priv->connecting_id = 0;
1167 if (found && !priv->connecting_id)
1168 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1169 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1174 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1178 const gchar *display_name;
1180 GtkTreeModel *model;
1181 EmpathyAccountSettings *settings;
1182 EmpathyAccount *selected_account;
1183 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1184 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1186 display_name = empathy_account_get_display_name (account);
1187 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1188 settings = accounts_dialog_model_get_selected_settings (dialog);
1189 selected_account = empathy_account_settings_get_account (settings);
1191 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1193 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1194 COL_NAME, display_name,
1198 if (selected_account == account)
1199 accounts_dialog_update_name_label (dialog, display_name);
1201 g_object_unref (settings);
1205 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1206 EmpathyAccount *account)
1208 EmpathyAccountSettings *settings;
1209 GtkTreeModel *model;
1211 TpConnectionStatus status;
1214 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1216 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1217 g_object_get (account, "connection-status", &status, NULL);
1218 name = empathy_account_get_display_name (account);
1219 enabled = empathy_account_is_enabled (account);
1221 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1222 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1224 settings = empathy_account_settings_new_for_account (account);
1226 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1229 COL_ACCOUNT_POINTER, account,
1230 COL_ACCOUNT_SETTINGS_POINTER, settings,
1233 accounts_dialog_connection_changed_cb (priv->account_manager,
1235 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1237 TP_CONNECTION_STATUS_DISCONNECTED,
1240 g_signal_connect (account, "notify::display-name",
1241 G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
1243 g_object_unref (settings);
1247 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1248 EmpathyAccountSettings *settings)
1250 GtkTreeModel *model;
1252 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1254 gboolean enabled = FALSE;
1255 EmpathyAccount *account;
1256 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1258 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1259 name = empathy_account_settings_get_display_name (settings);
1261 account = empathy_account_settings_get_account (settings);
1262 if (account != NULL)
1264 enabled = empathy_account_is_enabled (account);
1265 g_object_get (account, "connection-status", &status, NULL);
1268 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1269 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1272 COL_ACCOUNT_POINTER, account,
1273 COL_ACCOUNT_SETTINGS_POINTER, settings,
1278 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1279 EmpathyAccount *account,
1280 EmpathyAccountsDialog *dialog)
1282 accounts_dialog_add_account (dialog, account);
1287 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1288 EmpathyAccount *account,
1289 EmpathyAccountsDialog *dialog)
1292 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1294 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1296 g_signal_handlers_disconnect_by_func (account,
1297 accounts_dialog_account_display_name_changed_cb, dialog);
1298 gtk_list_store_remove (GTK_LIST_STORE (
1299 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1304 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1305 EmpathyAccount *account,
1308 GtkTreeModel *model;
1309 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1311 /* Update the status in the model */
1312 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1314 DEBUG ("Account %s is now %s",
1315 empathy_account_get_display_name (account),
1316 enabled ? "enabled" : "disabled");
1320 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1321 EmpathyAccount *account,
1322 EmpathyAccountsDialog *dialog)
1324 enable_or_disable_account (dialog, account, FALSE);
1328 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1329 EmpathyAccount *account,
1330 EmpathyAccountsDialog *dialog)
1332 enable_or_disable_account (dialog, account, TRUE);
1336 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1337 EmpathyAccount *account,
1338 EmpathyAccountsDialog *dialog)
1340 EmpathyAccountSettings *settings, *selected_settings;
1341 GtkTreeModel *model;
1343 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1345 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1347 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1350 gtk_tree_model_get (model, &iter,
1351 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1354 accounts_dialog_update (dialog, settings);
1355 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1357 if (settings == selected_settings)
1358 accounts_dialog_update_name_label (dialog,
1359 empathy_account_settings_get_display_name (settings));
1362 g_object_unref (settings);
1364 if (selected_settings)
1365 g_object_unref (selected_settings);
1369 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1370 EmpathyAccountsDialog *dialog)
1372 EmpathyAccountSettings *settings;
1374 const gchar *display_name;
1375 TpConnectionManager *cm;
1376 TpConnectionManagerProtocol *proto;
1377 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1379 cm = empathy_protocol_chooser_dup_selected (
1380 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
1381 display_name = empathy_protocol_name_to_display_name (proto->name);
1383 if (display_name == NULL)
1384 display_name = proto->name;
1386 /* Create account */
1387 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1390 str = g_strdup_printf (_("New %s account"), display_name);
1391 settings = empathy_account_settings_new (cm->name, proto->name, str);
1395 if (tp_connection_manager_protocol_can_register (proto))
1399 active = gtk_toggle_button_get_active
1400 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1402 empathy_account_settings_set_boolean (settings, "register", TRUE);
1405 accounts_dialog_add (dialog, settings);
1406 accounts_dialog_model_set_selected (dialog, settings);
1408 g_object_unref (settings);
1409 g_object_unref (cm);
1413 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1414 EmpathyAccountsDialog *dialog)
1416 EmpathyAccountSettings *settings;
1418 settings = accounts_dialog_model_get_selected_settings (dialog);
1419 accounts_dialog_update_settings (dialog, settings);
1422 g_object_unref (settings);
1426 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1427 EmpathyAccountsDialog *dialog)
1429 empathy_url_show (button, "ghelp:empathy?accounts-window");
1433 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1437 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1439 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1441 if (response_id == GTK_RESPONSE_YES)
1442 gtk_widget_destroy (account_dialog);
1446 accounts_dialog_response_cb (GtkWidget *widget,
1448 EmpathyAccountsDialog *dialog)
1450 EmpathyAccount *account = NULL;
1452 if (accounts_dialog_has_pending_change (dialog, &account))
1454 gchar *question_dialog_primary_text;
1455 question_dialog_primary_text = g_strdup_printf (
1456 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1457 empathy_account_get_display_name (account));
1459 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1460 "You are about to close the window, which will discard\n"
1461 "your changes. Are you sure you want to proceed?",
1462 G_CALLBACK (accounts_dialog_close_response_cb),
1464 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1465 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1467 g_free (question_dialog_primary_text);
1469 else if (response == GTK_RESPONSE_CLOSE)
1470 gtk_widget_destroy (widget);
1474 accounts_dialog_destroy_cb (GtkObject *obj,
1475 EmpathyAccountsDialog *dialog)
1479 g_object_unref (dialog);
1483 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1484 EmpathyAccount *account)
1486 GtkTreeSelection *selection;
1488 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1490 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1491 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1492 gtk_tree_selection_select_iter (selection, &iter);
1496 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1498 EmpathyAccountsDialog *dialog)
1500 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1502 if (empathy_connection_managers_is_ready (cms))
1504 accounts_dialog_update_settings (dialog, NULL);
1506 if (priv->initial_selection != NULL)
1508 accounts_dialog_set_selected_account
1509 (dialog, priv->initial_selection);
1510 g_object_unref (priv->initial_selection);
1511 priv->initial_selection = NULL;
1517 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1521 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1523 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1525 gui = empathy_builder_get_file (filename,
1526 "accounts_dialog", &priv->window,
1527 "vbox_details", &priv->vbox_details,
1528 "frame_no_protocol", &priv->frame_no_protocol,
1529 "alignment_settings", &priv->alignment_settings,
1530 "treeview", &priv->treeview,
1531 "frame_new_account", &priv->frame_new_account,
1532 "hbox_type", &priv->hbox_type,
1533 "button_create", &priv->button_create,
1534 "button_back", &priv->button_back,
1535 "radiobutton_reuse", &priv->radiobutton_reuse,
1536 "radiobutton_register", &priv->radiobutton_register,
1537 "image_type", &priv->image_type,
1538 "label_name", &priv->label_name,
1539 "button_add", &priv->button_add,
1543 empathy_builder_connect (gui, dialog,
1544 "accounts_dialog", "response", accounts_dialog_response_cb,
1545 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1546 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1547 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1548 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1549 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1552 g_object_unref (gui);
1554 priv->combobox_protocol = empathy_protocol_chooser_new ();
1555 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1556 priv->combobox_protocol,
1558 gtk_widget_show (priv->combobox_protocol);
1559 g_signal_connect (priv->combobox_protocol, "changed",
1560 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1563 if (priv->parent_window)
1564 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1565 priv->parent_window);
1569 do_dispose (GObject *obj)
1571 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1572 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1574 /* Disconnect signals */
1575 g_signal_handlers_disconnect_by_func (priv->account_manager,
1576 accounts_dialog_account_added_cb,
1578 g_signal_handlers_disconnect_by_func (priv->account_manager,
1579 accounts_dialog_account_removed_cb,
1581 g_signal_handlers_disconnect_by_func (priv->account_manager,
1582 accounts_dialog_account_enabled_cb,
1584 g_signal_handlers_disconnect_by_func (priv->account_manager,
1585 accounts_dialog_account_disabled_cb,
1587 g_signal_handlers_disconnect_by_func (priv->account_manager,
1588 accounts_dialog_account_changed_cb,
1590 g_signal_handlers_disconnect_by_func (priv->account_manager,
1591 accounts_dialog_connection_changed_cb,
1594 if (priv->connecting_id)
1595 g_source_remove (priv->connecting_id);
1597 if (priv->account_manager != NULL)
1599 g_object_unref (priv->account_manager);
1600 priv->account_manager = NULL;
1603 if (priv->cms != NULL)
1605 g_object_unref (priv->cms);
1609 if (priv->initial_selection != NULL)
1610 g_object_unref (priv->initial_selection);
1611 priv->initial_selection = NULL;
1613 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1617 do_constructor (GType type,
1619 GObjectConstructParam *props)
1623 if (dialog_singleton)
1625 retval = G_OBJECT (dialog_singleton);
1626 g_object_ref (retval);
1631 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1632 (type, n_props, props);
1634 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1635 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1642 do_get_property (GObject *object,
1647 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1649 switch (property_id)
1652 g_value_set_object (value, priv->parent_window);
1655 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1660 do_set_property (GObject *object,
1662 const GValue *value,
1665 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1667 switch (property_id)
1670 priv->parent_window = g_value_get_object (value);
1673 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1678 do_constructed (GObject *object)
1680 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1681 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1682 GList *accounts, *l;
1683 gboolean import_asked;
1685 accounts_dialog_build_ui (dialog);
1687 /* Set up signalling */
1688 priv->account_manager = empathy_account_manager_dup_singleton ();
1690 g_signal_connect (priv->account_manager, "account-created",
1691 G_CALLBACK (accounts_dialog_account_added_cb),
1693 g_signal_connect (priv->account_manager, "account-deleted",
1694 G_CALLBACK (accounts_dialog_account_removed_cb),
1696 g_signal_connect (priv->account_manager, "account-enabled",
1697 G_CALLBACK (accounts_dialog_account_enabled_cb),
1699 g_signal_connect (priv->account_manager, "account-disabled",
1700 G_CALLBACK (accounts_dialog_account_disabled_cb),
1702 g_signal_connect (priv->account_manager, "account-changed",
1703 G_CALLBACK (accounts_dialog_account_changed_cb),
1705 g_signal_connect (priv->account_manager, "account-connection-changed",
1706 G_CALLBACK (accounts_dialog_connection_changed_cb),
1709 accounts_dialog_model_setup (dialog);
1711 /* Add existing accounts */
1712 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1713 for (l = accounts; l; l = l->next)
1715 accounts_dialog_add_account (dialog, l->data);
1716 g_object_unref (l->data);
1718 g_list_free (accounts);
1720 priv->cms = empathy_connection_managers_dup_singleton ();
1721 if (!empathy_connection_managers_is_ready (priv->cms))
1722 g_signal_connect (priv->cms, "notify::ready",
1723 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1725 accounts_dialog_model_select_first (dialog);
1727 empathy_conf_get_bool (empathy_conf_get (),
1728 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1731 if (empathy_import_accounts_to_import ())
1736 GtkWidget *import_dialog;
1738 empathy_conf_set_bool (empathy_conf_get (),
1739 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1740 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1742 gtk_widget_show (import_dialog);
1748 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1750 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1751 GParamSpec *param_spec;
1753 oclass->constructor = do_constructor;
1754 oclass->dispose = do_dispose;
1755 oclass->constructed = do_constructed;
1756 oclass->set_property = do_set_property;
1757 oclass->get_property = do_get_property;
1759 param_spec = g_param_spec_object ("parent",
1760 "parent", "The parent window",
1762 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1763 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1765 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1769 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1771 EmpathyAccountsDialogPriv *priv;
1773 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1774 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1775 EmpathyAccountsDialogPriv);
1776 dialog->priv = priv;
1779 /* public methods */
1782 empathy_accounts_dialog_show (GtkWindow *parent,
1783 EmpathyAccount *selected_account)
1785 EmpathyAccountsDialog *dialog;
1786 EmpathyAccountsDialogPriv *priv;
1788 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1789 "parent", parent, NULL);
1791 priv = GET_PRIV (dialog);
1793 if (selected_account)
1795 if (empathy_connection_managers_is_ready (priv->cms))
1796 accounts_dialog_set_selected_account (dialog, selected_account);
1798 /* save the selection to set it later when the cms
1801 priv->initial_selection = g_object_ref (selected_account);
1804 gtk_window_present (GTK_WINDOW (priv->window));
1806 return priv->window;