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->settings_widget = empathy_account_widget_get_widget (widget_object);
284 g_signal_connect (priv->setting_widget_object, "account-created",
285 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
286 g_signal_connect (priv->setting_widget_object, "cancelled",
287 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
289 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
290 priv->settings_widget);
291 gtk_widget_show (priv->settings_widget);
293 icon_name = empathy_account_settings_get_icon_name (settings);
295 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
296 icon_name, GTK_ICON_SIZE_DIALOG);
297 gtk_widget_set_tooltip_text (priv->image_type,
298 empathy_protocol_name_to_display_name
299 (empathy_account_settings_get_protocol (settings)));
301 accounts_dialog_update_name_label (dialog,
302 empathy_account_settings_get_display_name (settings));
306 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
308 EmpathyAccountsDialog *dialog)
310 if (empathy_account_settings_is_ready (settings))
311 account_dialog_create_settings_widget (dialog, settings);
315 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
319 GtkTreeSelection *selection;
321 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
324 view = GTK_TREE_VIEW (priv->treeview);
325 model = gtk_tree_view_get_model (view);
327 if (gtk_tree_model_get_iter_first (model, &iter))
329 selection = gtk_tree_view_get_selection (view);
330 gtk_tree_selection_select_iter (selection, &iter);
334 accounts_dialog_update_settings (dialog, NULL);
339 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
340 EmpathyAccount **account)
342 gboolean has_pending_changes;
345 GtkTreeSelection *selection;
346 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
348 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
350 if (gtk_tree_selection_get_selected (selection, &model, &iter))
351 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
353 has_pending_changes = account != NULL && priv->setting_widget_object != NULL
354 && empathy_account_widget_contains_pending_changes (
355 priv->setting_widget_object);
357 return has_pending_changes;
361 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
362 EmpathyAccountsDialog *dialog)
364 TpConnectionManager *cm;
365 TpConnectionManagerProtocol *proto;
366 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
368 cm = empathy_protocol_chooser_dup_selected (
369 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
380 if (tp_connection_manager_protocol_can_register (proto))
382 gtk_widget_show (priv->radiobutton_register);
383 gtk_widget_show (priv->radiobutton_reuse);
387 gtk_widget_hide (priv->radiobutton_register);
388 gtk_widget_hide (priv->radiobutton_reuse);
394 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
398 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
400 view = GTK_TREE_VIEW (priv->treeview);
401 model = gtk_tree_view_get_model (view);
403 gtk_widget_set_sensitive (priv->button_add, FALSE);
404 gtk_widget_hide (priv->vbox_details);
405 gtk_widget_hide (priv->frame_no_protocol);
406 gtk_widget_show (priv->frame_new_account);
408 /* If we have no account, no need of a back button */
409 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
410 gtk_widget_show (priv->button_back);
412 gtk_widget_hide (priv->button_back);
414 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
415 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
417 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
418 gtk_widget_grab_focus (priv->combobox_protocol);
422 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
424 gchar *secondary_text,
425 GCallback response_callback,
427 const gchar *first_button_text,
431 GtkWidget *message_dialog;
432 const gchar *button_text;
433 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
435 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
436 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
437 GTK_MESSAGE_QUESTION,
441 gtk_message_dialog_format_secondary_text (
442 GTK_MESSAGE_DIALOG (message_dialog), secondary_text);
444 va_start (button_args, first_button_text);
445 for (button_text = first_button_text;
447 button_text = va_arg (button_args, const gchar *))
450 response_id = va_arg (button_args, gint);
452 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text, response_id);
454 va_end (button_args);
456 g_signal_connect (message_dialog, "response", response_callback, user_data);
458 gtk_widget_show (message_dialog);
462 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
466 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
467 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
469 gtk_widget_destroy (GTK_WIDGET (message_dialog));
471 if (response_id == GTK_RESPONSE_YES)
473 empathy_account_widget_discard_pending_changes (
474 priv->setting_widget_object);
475 accounts_dialog_setup_ui_to_add_account (dialog);
480 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
481 EmpathyAccountsDialog *dialog)
483 EmpathyAccount *account;
485 if (accounts_dialog_has_pending_change (dialog, &account))
487 gchar *question_dialog_primary_text = g_strdup_printf (
488 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
489 empathy_account_get_display_name (account));
491 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
492 "You are about to create a new account, which will discard\n"
493 "your changes. Are you sure you want to proceed?",
494 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
496 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
497 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
499 g_free (question_dialog_primary_text);
503 accounts_dialog_setup_ui_to_add_account (dialog);
508 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
509 EmpathyAccountSettings *settings)
511 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
513 if (priv->settings_ready != NULL)
515 g_signal_handler_disconnect (priv->settings_ready,
516 priv->settings_ready_id);
517 priv->settings_ready = NULL;
518 priv->settings_ready_id = 0;
526 view = GTK_TREE_VIEW (priv->treeview);
527 model = gtk_tree_view_get_model (view);
529 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
531 /* We have configured accounts, select the first one */
532 accounts_dialog_model_select_first (dialog);
535 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
537 /* We have no account configured but we have some
538 * profiles installed. The user obviously wants to add
539 * an account. Click on the Add button for him. */
540 accounts_dialog_button_add_clicked_cb (priv->button_add,
545 /* No account and no profile, warn the user */
546 gtk_widget_hide (priv->vbox_details);
547 gtk_widget_hide (priv->frame_new_account);
548 gtk_widget_show (priv->frame_no_protocol);
549 gtk_widget_set_sensitive (priv->button_add, FALSE);
553 /* We have an account selected, destroy old settings and create a new
554 * one for the account selected */
555 gtk_widget_hide (priv->frame_new_account);
556 gtk_widget_hide (priv->frame_no_protocol);
557 gtk_widget_show (priv->vbox_details);
558 gtk_widget_set_sensitive (priv->button_add, TRUE);
560 if (priv->settings_widget)
562 gtk_widget_destroy (priv->settings_widget);
563 priv->settings_widget = NULL;
566 if (empathy_account_settings_is_ready (settings))
568 account_dialog_create_settings_widget (dialog, settings);
572 priv->settings_ready = settings;
573 priv->settings_ready_id =
574 g_signal_connect (settings, "notify::ready",
575 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
581 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
582 GtkCellEditable *editable,
584 EmpathyAccountsDialog *dialog)
586 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
588 if (priv->connecting_id)
589 g_source_remove (priv->connecting_id);
591 DEBUG ("Editing account name started; stopping flashing");
595 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
596 GtkCellRenderer *cell,
599 EmpathyAccountsDialog *dialog)
601 EmpathyAccountSettings *settings;
604 TpConnectionStatus status;
605 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
607 gtk_tree_model_get (model, iter,
609 COL_ACCOUNT_SETTINGS_POINTER, &settings,
612 icon_name = empathy_account_settings_get_icon_name (settings);
613 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
617 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
618 (status == TP_CONNECTION_STATUS_CONNECTING &&
619 !priv->connecting_show))
621 GdkPixbuf *modded_pixbuf;
623 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
626 gdk_pixbuf_get_width (pixbuf),
627 gdk_pixbuf_get_height (pixbuf));
629 gdk_pixbuf_saturate_and_pixelate (pixbuf,
633 g_object_unref (pixbuf);
634 pixbuf = modded_pixbuf;
643 g_object_unref (settings);
646 g_object_unref (pixbuf);
650 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
655 gtk_tree_model_row_changed (model, path, iter);
661 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
665 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
667 priv->connecting_show = !priv->connecting_show;
669 view = GTK_TREE_VIEW (priv->treeview);
670 model = gtk_tree_view_get_model (view);
672 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
678 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
681 EmpathyAccountsDialog *dialog)
683 EmpathyAccountSettings *settings;
685 GtkTreePath *treepath;
687 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
689 if (empathy_account_manager_get_connecting_accounts
690 (priv->account_manager) > 0)
692 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
693 (GSourceFunc) accounts_dialog_flash_connecting_cb,
697 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
698 treepath = gtk_tree_path_new_from_string (path);
699 gtk_tree_model_get_iter (model, &iter, treepath);
700 gtk_tree_model_get (model, &iter,
701 COL_ACCOUNT_SETTINGS_POINTER, &settings,
703 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
706 gtk_tree_path_free (treepath);
708 empathy_account_settings_set_display_name_async (settings, new_text,
710 g_object_set (settings, "display-name-overridden", TRUE, NULL);
711 g_object_unref (settings);
715 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
719 EmpathyAccount *account;
722 GtkTreeSelection *selection;
723 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
724 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
726 if (response_id == GTK_RESPONSE_YES)
728 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
730 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
733 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
737 g_signal_handlers_disconnect_by_func (account,
738 accounts_dialog_account_display_name_changed_cb, account_dialog);
739 empathy_account_remove_async (account, NULL, NULL);
740 g_object_unref (account);
743 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
744 accounts_dialog_model_select_first (account_dialog);
747 gtk_widget_destroy (GTK_WIDGET (message_dialog));
751 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
752 const gchar *path_string,
753 EmpathyAccountsDialog *dialog)
755 EmpathyAccount *account;
758 gchar *question_dialog_primary_text;
759 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
761 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
763 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
766 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
768 if (account == NULL || !empathy_account_is_valid (account))
770 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
771 accounts_dialog_model_select_first (dialog);
775 question_dialog_primary_text = g_strdup_printf (
776 _("You are about to remove your %s account!\n"
777 "Are you sure you want to proceed?"),
778 empathy_account_get_display_name (account));
780 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
781 _("Any associated conversations and chat rooms will NOT be "
782 "removed if you decide to proceed.\n"
784 "Should you decide to add the account back at a later time, "
785 "they will still be available."),
786 G_CALLBACK (accounts_dialog_delete_account_response_cb),
788 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
789 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
791 g_free (question_dialog_primary_text);
794 g_object_unref (account);
798 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
801 GtkTreeViewColumn *column;
802 GtkCellRenderer *cell;
803 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
805 view = GTK_TREE_VIEW (priv->treeview);
806 gtk_tree_view_set_headers_visible (view, FALSE);
809 column = gtk_tree_view_column_new ();
810 gtk_tree_view_column_set_expand (column, TRUE);
811 gtk_tree_view_append_column (view, column);
814 cell = gtk_cell_renderer_pixbuf_new ();
815 gtk_tree_view_column_pack_start (column, cell, FALSE);
816 gtk_tree_view_column_set_cell_data_func (column, cell,
817 (GtkTreeCellDataFunc)
818 accounts_dialog_model_pixbuf_data_func,
823 cell = gtk_cell_renderer_text_new ();
825 "ellipsize", PANGO_ELLIPSIZE_END,
829 gtk_tree_view_column_pack_start (column, cell, TRUE);
830 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
831 g_signal_connect (cell, "edited",
832 G_CALLBACK (accounts_dialog_name_edited_cb),
834 g_signal_connect (cell, "editing-started",
835 G_CALLBACK (accounts_dialog_name_editing_started_cb),
839 cell = empathy_cell_renderer_activatable_new ();
840 gtk_tree_view_column_pack_start (column, cell, FALSE);
842 "icon-name", GTK_STOCK_DELETE,
845 g_signal_connect (cell, "path-activated",
846 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
850 static EmpathyAccountSettings *
851 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
855 GtkTreeSelection *selection;
857 EmpathyAccountSettings *settings;
858 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
860 view = GTK_TREE_VIEW (priv->treeview);
861 selection = gtk_tree_view_get_selection (view);
863 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
866 gtk_tree_model_get (model, &iter,
867 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
873 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
874 EmpathyAccountsDialog *dialog)
876 EmpathyAccountSettings *settings;
879 gboolean is_selection;
881 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
883 settings = accounts_dialog_model_get_selected_settings (dialog);
884 accounts_dialog_update_settings (dialog, settings);
886 if (settings != NULL)
887 g_object_unref (settings);
891 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
895 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
896 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
898 gtk_widget_destroy (GTK_WIDGET (message_dialog));
900 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
902 /* The user wants to lose unsaved changes to the currently selected
903 * account and select another account. We discard the changes and
904 * select the other account. */
906 GtkTreeSelection *selection;
908 priv->force_change_row = TRUE;
909 empathy_account_widget_discard_pending_changes (
910 priv->setting_widget_object);
912 path = gtk_tree_row_reference_get_path (priv->destination_row);
913 selection = gtk_tree_view_get_selection (
914 GTK_TREE_VIEW (priv->treeview));
918 /* This will trigger a call to
919 * accounts_dialog_account_selection_change() */
920 gtk_tree_selection_select_path (selection, path);
921 gtk_tree_path_free (path);
924 gtk_tree_row_reference_free (priv->destination_row);
928 priv->force_change_row = FALSE;
933 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
936 gboolean path_currently_selected,
939 EmpathyAccount *account;
940 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
941 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
943 if (priv->force_change_row)
945 /* We came back here because the user wants to discard changes to his
946 * modified account. The changes have already been discarded so we
947 * just change the selected row. */
948 priv->force_change_row = FALSE;
952 if (accounts_dialog_has_pending_change (dialog, &account))
954 /* The currently selected account has some unsaved changes. We ask
955 * the user if he really wants to lose his changes and select another
957 gchar *question_dialog_primary_text;
958 priv->destination_row = gtk_tree_row_reference_new (model, path);
960 question_dialog_primary_text = g_strdup_printf (
961 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
962 empathy_account_get_display_name (account));
964 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
965 "You are about to select another account, which will discard\n"
966 "your changes. Are you sure you want to proceed?",
967 G_CALLBACK (accounts_dialog_selection_change_response_cb),
969 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
970 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
972 g_free (question_dialog_primary_text);
983 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
986 GtkTreeSelection *selection;
987 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
989 store = gtk_list_store_new (COL_COUNT,
990 G_TYPE_STRING, /* name */
991 G_TYPE_UINT, /* status */
992 EMPATHY_TYPE_ACCOUNT, /* account */
993 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
995 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
996 GTK_TREE_MODEL (store));
998 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
999 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1000 gtk_tree_selection_set_select_function (selection,
1001 accounts_dialog_account_selection_change, dialog, NULL);
1003 g_signal_connect (selection, "changed",
1004 G_CALLBACK (accounts_dialog_model_selection_changed),
1007 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1008 COL_NAME, GTK_SORT_ASCENDING);
1010 accounts_dialog_model_add_columns (dialog);
1012 g_object_unref (store);
1016 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1017 EmpathyAccountSettings *settings,
1021 GtkTreeSelection *selection;
1022 GtkTreeModel *model;
1024 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1026 /* Update the status in the model */
1027 view = GTK_TREE_VIEW (priv->treeview);
1028 selection = gtk_tree_view_get_selection (view);
1029 model = gtk_tree_view_get_model (view);
1031 for (ok = gtk_tree_model_get_iter_first (model, iter);
1033 ok = gtk_tree_model_iter_next (model, iter))
1035 EmpathyAccountSettings *this_settings;
1038 gtk_tree_model_get (model, iter,
1039 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1042 equal = (this_settings == settings);
1043 g_object_unref (this_settings);
1053 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1054 EmpathyAccount *account,
1058 GtkTreeSelection *selection;
1059 GtkTreeModel *model;
1061 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1063 /* Update the status in the model */
1064 view = GTK_TREE_VIEW (priv->treeview);
1065 selection = gtk_tree_view_get_selection (view);
1066 model = gtk_tree_view_get_model (view);
1068 for (ok = gtk_tree_model_get_iter_first (model, iter);
1070 ok = gtk_tree_model_iter_next (model, iter))
1072 EmpathyAccountSettings *settings;
1075 gtk_tree_model_get (model, iter,
1076 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1079 equal = empathy_account_settings_has_account (settings, account);
1080 g_object_unref (settings);
1090 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1091 EmpathyAccountSettings *settings)
1093 GtkTreeSelection *selection;
1095 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1097 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1098 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1099 gtk_tree_selection_select_iter (selection, &iter);
1102 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1103 EmpathyAccountSettings *settings)
1105 GtkTreeModel *model;
1108 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1110 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1111 name = empathy_account_settings_get_display_name (settings);
1113 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1115 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1117 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1118 COL_ACCOUNT_SETTINGS_POINTER, settings,
1123 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1124 EmpathyAccount *account,
1125 TpConnectionStatusReason reason,
1126 TpConnectionStatus current,
1127 TpConnectionStatus previous,
1128 EmpathyAccountsDialog *dialog)
1130 GtkTreeModel *model;
1133 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1135 /* Update the status in the model */
1136 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1138 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1142 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1143 COL_STATUS, current,
1146 path = gtk_tree_model_get_path (model, &iter);
1147 gtk_tree_model_row_changed (model, path, &iter);
1148 gtk_tree_path_free (path);
1151 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1153 if (!found && priv->connecting_id)
1155 g_source_remove (priv->connecting_id);
1156 priv->connecting_id = 0;
1159 if (found && !priv->connecting_id)
1160 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1161 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1166 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1170 const gchar *display_name;
1172 GtkTreeModel *model;
1173 EmpathyAccountSettings *settings;
1174 EmpathyAccount *selected_account;
1175 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1176 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1178 display_name = empathy_account_get_display_name (account);
1179 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1180 settings = accounts_dialog_model_get_selected_settings (dialog);
1181 selected_account = empathy_account_settings_get_account (settings);
1183 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1185 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1186 COL_NAME, display_name,
1190 if (selected_account == account)
1191 accounts_dialog_update_name_label (dialog, display_name);
1193 g_object_unref (settings);
1197 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1198 EmpathyAccount *account)
1200 EmpathyAccountSettings *settings;
1201 GtkTreeModel *model;
1203 TpConnectionStatus status;
1206 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1208 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1209 g_object_get (account, "connection-status", &status, NULL);
1210 name = empathy_account_get_display_name (account);
1211 enabled = empathy_account_is_enabled (account);
1213 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1214 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1216 settings = empathy_account_settings_new_for_account (account);
1218 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1221 COL_ACCOUNT_POINTER, account,
1222 COL_ACCOUNT_SETTINGS_POINTER, settings,
1225 accounts_dialog_connection_changed_cb (priv->account_manager,
1227 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1229 TP_CONNECTION_STATUS_DISCONNECTED,
1232 g_signal_connect (account, "notify::display-name",
1233 G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
1235 g_object_unref (settings);
1239 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1240 EmpathyAccountSettings *settings)
1242 GtkTreeModel *model;
1244 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1246 gboolean enabled = FALSE;
1247 EmpathyAccount *account;
1248 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1250 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1251 name = empathy_account_settings_get_display_name (settings);
1253 account = empathy_account_settings_get_account (settings);
1254 if (account != NULL)
1256 enabled = empathy_account_is_enabled (account);
1257 g_object_get (account, "connection-status", &status, NULL);
1260 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1261 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1264 COL_ACCOUNT_POINTER, account,
1265 COL_ACCOUNT_SETTINGS_POINTER, settings,
1270 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1271 EmpathyAccount *account,
1272 EmpathyAccountsDialog *dialog)
1274 accounts_dialog_add_account (dialog, account);
1279 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1280 EmpathyAccount *account,
1281 EmpathyAccountsDialog *dialog)
1284 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1286 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1288 g_signal_handlers_disconnect_by_func (account,
1289 accounts_dialog_account_display_name_changed_cb, dialog);
1290 gtk_list_store_remove (GTK_LIST_STORE (
1291 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1296 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1297 EmpathyAccount *account,
1300 GtkTreeModel *model;
1301 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1303 /* Update the status in the model */
1304 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1306 DEBUG ("Account %s is now %s",
1307 empathy_account_get_display_name (account),
1308 enabled ? "enabled" : "disabled");
1312 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1313 EmpathyAccount *account,
1314 EmpathyAccountsDialog *dialog)
1316 enable_or_disable_account (dialog, account, FALSE);
1320 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1321 EmpathyAccount *account,
1322 EmpathyAccountsDialog *dialog)
1324 enable_or_disable_account (dialog, account, TRUE);
1328 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1329 EmpathyAccount *account,
1330 EmpathyAccountsDialog *dialog)
1332 EmpathyAccountSettings *settings, *selected_settings;
1333 GtkTreeModel *model;
1335 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1337 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1339 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1342 gtk_tree_model_get (model, &iter,
1343 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1346 accounts_dialog_update (dialog, settings);
1347 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1349 if (settings == selected_settings)
1350 accounts_dialog_update_name_label (dialog,
1351 empathy_account_settings_get_display_name (settings));
1354 g_object_unref (settings);
1356 if (selected_settings)
1357 g_object_unref (selected_settings);
1361 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1362 EmpathyAccountsDialog *dialog)
1364 EmpathyAccountSettings *settings;
1366 const gchar *display_name;
1367 TpConnectionManager *cm;
1368 TpConnectionManagerProtocol *proto;
1369 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1371 cm = empathy_protocol_chooser_dup_selected (
1372 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
1373 display_name = empathy_protocol_name_to_display_name (proto->name);
1375 if (display_name == NULL)
1376 display_name = proto->name;
1378 /* Create account */
1379 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1382 str = g_strdup_printf (_("New %s account"), display_name);
1383 settings = empathy_account_settings_new (cm->name, proto->name, str);
1387 if (tp_connection_manager_protocol_can_register (proto))
1391 active = gtk_toggle_button_get_active
1392 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1394 empathy_account_settings_set_boolean (settings, "register", TRUE);
1397 accounts_dialog_add (dialog, settings);
1398 accounts_dialog_model_set_selected (dialog, settings);
1400 g_object_unref (settings);
1401 g_object_unref (cm);
1405 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1406 EmpathyAccountsDialog *dialog)
1408 EmpathyAccountSettings *settings;
1410 settings = accounts_dialog_model_get_selected_settings (dialog);
1411 accounts_dialog_update_settings (dialog, settings);
1414 g_object_unref (settings);
1418 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1419 EmpathyAccountsDialog *dialog)
1421 empathy_url_show (button, "ghelp:empathy?accounts-window");
1425 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1429 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1431 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1433 if (response_id == GTK_RESPONSE_YES)
1434 gtk_widget_destroy (account_dialog);
1438 accounts_dialog_response_cb (GtkWidget *widget,
1440 EmpathyAccountsDialog *dialog)
1442 EmpathyAccount *account;
1444 if (accounts_dialog_has_pending_change (dialog, &account))
1446 gchar *question_dialog_primary_text;
1447 question_dialog_primary_text = g_strdup_printf (
1448 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1449 empathy_account_get_display_name (account));
1451 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1452 "You are about to close the window, which will discard\n"
1453 "your changes. Are you sure you want to proceed?",
1454 G_CALLBACK (accounts_dialog_close_response_cb),
1456 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1457 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1459 g_free (question_dialog_primary_text);
1461 else if (response == GTK_RESPONSE_CLOSE)
1462 gtk_widget_destroy (widget);
1466 accounts_dialog_destroy_cb (GtkObject *obj,
1467 EmpathyAccountsDialog *dialog)
1471 g_object_unref (dialog);
1475 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1476 EmpathyAccount *account)
1478 GtkTreeSelection *selection;
1480 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1482 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1483 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1484 gtk_tree_selection_select_iter (selection, &iter);
1488 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1490 EmpathyAccountsDialog *dialog)
1492 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1494 if (empathy_connection_managers_is_ready (cms))
1496 accounts_dialog_update_settings (dialog, NULL);
1498 if (priv->initial_selection != NULL)
1500 accounts_dialog_set_selected_account
1501 (dialog, priv->initial_selection);
1502 g_object_unref (priv->initial_selection);
1503 priv->initial_selection = NULL;
1509 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1513 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1515 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1517 gui = empathy_builder_get_file (filename,
1518 "accounts_dialog", &priv->window,
1519 "vbox_details", &priv->vbox_details,
1520 "frame_no_protocol", &priv->frame_no_protocol,
1521 "alignment_settings", &priv->alignment_settings,
1522 "treeview", &priv->treeview,
1523 "frame_new_account", &priv->frame_new_account,
1524 "hbox_type", &priv->hbox_type,
1525 "button_create", &priv->button_create,
1526 "button_back", &priv->button_back,
1527 "radiobutton_reuse", &priv->radiobutton_reuse,
1528 "radiobutton_register", &priv->radiobutton_register,
1529 "image_type", &priv->image_type,
1530 "label_name", &priv->label_name,
1531 "button_add", &priv->button_add,
1535 empathy_builder_connect (gui, dialog,
1536 "accounts_dialog", "response", accounts_dialog_response_cb,
1537 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1538 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1539 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1540 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1541 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1544 g_object_unref (gui);
1546 priv->combobox_protocol = empathy_protocol_chooser_new ();
1547 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1548 priv->combobox_protocol,
1550 gtk_widget_show (priv->combobox_protocol);
1551 g_signal_connect (priv->combobox_protocol, "changed",
1552 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1555 if (priv->parent_window)
1556 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1557 priv->parent_window);
1561 do_dispose (GObject *obj)
1563 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1564 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1566 /* Disconnect signals */
1567 g_signal_handlers_disconnect_by_func (priv->account_manager,
1568 accounts_dialog_account_added_cb,
1570 g_signal_handlers_disconnect_by_func (priv->account_manager,
1571 accounts_dialog_account_removed_cb,
1573 g_signal_handlers_disconnect_by_func (priv->account_manager,
1574 accounts_dialog_account_enabled_cb,
1576 g_signal_handlers_disconnect_by_func (priv->account_manager,
1577 accounts_dialog_account_disabled_cb,
1579 g_signal_handlers_disconnect_by_func (priv->account_manager,
1580 accounts_dialog_account_changed_cb,
1582 g_signal_handlers_disconnect_by_func (priv->account_manager,
1583 accounts_dialog_connection_changed_cb,
1586 if (priv->connecting_id)
1587 g_source_remove (priv->connecting_id);
1589 if (priv->account_manager != NULL)
1591 g_object_unref (priv->account_manager);
1592 priv->account_manager = NULL;
1595 if (priv->cms != NULL)
1597 g_object_unref (priv->cms);
1601 if (priv->initial_selection != NULL)
1602 g_object_unref (priv->initial_selection);
1603 priv->initial_selection = NULL;
1605 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1609 do_constructor (GType type,
1611 GObjectConstructParam *props)
1615 if (dialog_singleton)
1617 retval = G_OBJECT (dialog_singleton);
1618 g_object_ref (retval);
1623 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1624 (type, n_props, props);
1626 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1627 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1634 do_get_property (GObject *object,
1639 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1641 switch (property_id)
1644 g_value_set_object (value, priv->parent_window);
1647 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1652 do_set_property (GObject *object,
1654 const GValue *value,
1657 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1659 switch (property_id)
1662 priv->parent_window = g_value_get_object (value);
1665 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1670 do_constructed (GObject *object)
1672 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1673 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1674 GList *accounts, *l;
1675 gboolean import_asked;
1677 accounts_dialog_build_ui (dialog);
1679 /* Set up signalling */
1680 priv->account_manager = empathy_account_manager_dup_singleton ();
1682 g_signal_connect (priv->account_manager, "account-created",
1683 G_CALLBACK (accounts_dialog_account_added_cb),
1685 g_signal_connect (priv->account_manager, "account-deleted",
1686 G_CALLBACK (accounts_dialog_account_removed_cb),
1688 g_signal_connect (priv->account_manager, "account-enabled",
1689 G_CALLBACK (accounts_dialog_account_enabled_cb),
1691 g_signal_connect (priv->account_manager, "account-disabled",
1692 G_CALLBACK (accounts_dialog_account_disabled_cb),
1694 g_signal_connect (priv->account_manager, "account-changed",
1695 G_CALLBACK (accounts_dialog_account_changed_cb),
1697 g_signal_connect (priv->account_manager, "account-connection-changed",
1698 G_CALLBACK (accounts_dialog_connection_changed_cb),
1701 accounts_dialog_model_setup (dialog);
1703 /* Add existing accounts */
1704 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1705 for (l = accounts; l; l = l->next)
1707 accounts_dialog_add_account (dialog, l->data);
1708 g_object_unref (l->data);
1710 g_list_free (accounts);
1712 priv->cms = empathy_connection_managers_dup_singleton ();
1713 if (!empathy_connection_managers_is_ready (priv->cms))
1714 g_signal_connect (priv->cms, "notify::ready",
1715 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1717 accounts_dialog_model_select_first (dialog);
1719 empathy_conf_get_bool (empathy_conf_get (),
1720 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1723 if (empathy_import_accounts_to_import ())
1728 GtkWidget *import_dialog;
1730 empathy_conf_set_bool (empathy_conf_get (),
1731 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1732 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1734 gtk_widget_show (import_dialog);
1740 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1742 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1743 GParamSpec *param_spec;
1745 oclass->constructor = do_constructor;
1746 oclass->dispose = do_dispose;
1747 oclass->constructed = do_constructed;
1748 oclass->set_property = do_set_property;
1749 oclass->get_property = do_get_property;
1751 param_spec = g_param_spec_object ("parent",
1752 "parent", "The parent window",
1754 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1755 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1757 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1761 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1763 EmpathyAccountsDialogPriv *priv;
1765 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1766 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1767 EmpathyAccountsDialogPriv);
1768 dialog->priv = priv;
1771 /* public methods */
1774 empathy_accounts_dialog_show (GtkWindow *parent,
1775 EmpathyAccount *selected_account)
1777 EmpathyAccountsDialog *dialog;
1778 EmpathyAccountsDialogPriv *priv;
1780 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1781 "parent", parent, NULL);
1783 priv = GET_PRIV (dialog);
1785 if (selected_account)
1787 if (empathy_connection_managers_is_ready (priv->cms))
1788 accounts_dialog_set_selected_account (dialog, selected_account);
1790 /* save the selection to set it later when the cms
1793 priv->initial_selection = g_object_ref (selected_account);
1796 gtk_window_present (GTK_WINDOW (priv->window));
1798 return priv->window;