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/account-manager.h>
36 #include <telepathy-glib/util.h>
38 #include <libempathy/empathy-utils.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.")
64 /* The primary text of the dialog shown to the user when he is about to lose
65 * an unsaved new account */
66 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
67 _("Your new account has not been saved yet.")
69 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
70 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
72 static EmpathyAccountsDialog *dialog_singleton = NULL;
77 GtkWidget *alignment_settings;
79 GtkWidget *vbox_details;
81 GtkWidget *frame_no_protocol;
85 GtkWidget *button_add;
86 GtkWidget *button_import;
88 GtkWidget *frame_new_account;
89 GtkWidget *combobox_protocol;
91 GtkWidget *button_create;
92 GtkWidget *button_back;
93 GtkWidget *radiobutton_reuse;
94 GtkWidget *radiobutton_register;
96 GtkWidget *image_type;
97 GtkWidget *label_name;
98 GtkWidget *label_type;
99 GtkWidget *settings_widget;
101 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
102 * his GtkWidget. It is the only reliable source we can query to know if
103 * there are any unsaved changes to the currently selected account. We can't
104 * look at the account settings because it does not contain everything that
105 * can be changed using the EmpathyAccountWidget. For instance, it does not
106 * contain the state of the "Enabled" checkbox. */
107 EmpathyAccountWidget *setting_widget_object;
109 gboolean connecting_show;
112 gulong settings_ready_id;
113 EmpathyAccountSettings *settings_ready;
115 TpAccountManager *account_manager;
116 EmpathyConnectionManagers *cms;
118 GtkWindow *parent_window;
119 TpAccount *initial_selection;
121 /* Those are needed when changing the selected row. When a user selects
122 * another account and there are unsaved changes on the currently selected
123 * one, a confirmation message box is presented to him. Since his answer
124 * is retrieved asynchronously, we keep some information as member of the
125 * EmpathyAccountsDialog object. */
126 gboolean force_change_row;
127 GtkTreeRowReference *destination_row;
130 } EmpathyAccountsDialogPriv;
136 COL_ACCOUNT_SETTINGS_POINTER,
144 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
145 EmpathyAccountsDialog *dialog);
147 static gboolean accounts_dialog_get_settings_iter (
148 EmpathyAccountsDialog *dialog,
149 EmpathyAccountSettings *settings,
152 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
154 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
155 EmpathyAccountSettings *settings);
158 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
159 const gchar *display_name)
162 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
164 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
165 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
171 empathy_account_dialog_widget_cancelled_cb (
172 EmpathyAccountWidget *widget_object,
173 EmpathyAccountsDialog *dialog)
177 GtkTreeSelection *selection;
179 EmpathyAccountSettings *settings;
181 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
183 view = GTK_TREE_VIEW (priv->treeview);
184 selection = gtk_tree_view_get_selection (view);
186 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
189 gtk_tree_model_get (model, &iter,
190 COL_ACCOUNT_SETTINGS_POINTER, &settings,
191 COL_ACCOUNT_POINTER, &account, -1);
193 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
197 /* We were creating an account. We remove the selected row */
198 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
202 /* We were modifying an account. We discard the changes by reloading the
203 * settings and the UI. */
204 accounts_dialog_update_settings (dialog, settings);
205 g_object_unref (account);
208 if (settings != NULL)
209 g_object_unref (settings);
213 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
214 EmpathyAccountsDialog *dialog)
217 EmpathyAccountSettings *settings =
218 accounts_dialog_model_get_selected_settings (dialog);
220 display_name = empathy_account_widget_get_default_display_name (
223 empathy_account_settings_set_display_name_async (settings,
224 display_name, NULL, NULL);
226 g_free (display_name);
228 accounts_dialog_update_settings (dialog, settings);
231 g_object_unref (settings);
235 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
236 EmpathyAccountSettings *settings)
238 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
241 priv->setting_widget_object =
242 empathy_account_widget_new_for_protocol (settings, FALSE);
244 priv->settings_widget =
245 empathy_account_widget_get_widget (priv->setting_widget_object);
247 priv->settings_widget =
248 empathy_account_widget_get_widget (priv->setting_widget_object);
249 g_signal_connect (priv->setting_widget_object, "account-created",
250 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
251 g_signal_connect (priv->setting_widget_object, "cancelled",
252 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
254 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
255 priv->settings_widget);
256 gtk_widget_show (priv->settings_widget);
258 icon_name = empathy_account_settings_get_icon_name (settings);
260 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
262 /* show the default icon; keep this in sync with the default
263 * one in empathy-accounts-dialog.ui.
265 icon_name = GTK_STOCK_CUT;
267 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
268 icon_name, GTK_ICON_SIZE_DIALOG);
269 gtk_widget_set_tooltip_text (priv->image_type,
270 empathy_protocol_name_to_display_name
271 (empathy_account_settings_get_protocol (settings)));
272 gtk_widget_show (priv->image_type);
274 accounts_dialog_update_name_label (dialog,
275 empathy_account_settings_get_display_name (settings));
279 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
281 EmpathyAccountsDialog *dialog)
283 if (empathy_account_settings_is_ready (settings))
284 account_dialog_create_settings_widget (dialog, settings);
288 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
292 GtkTreeSelection *selection;
294 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
297 view = GTK_TREE_VIEW (priv->treeview);
298 model = gtk_tree_view_get_model (view);
300 if (gtk_tree_model_get_iter_first (model, &iter))
302 selection = gtk_tree_view_get_selection (view);
303 gtk_tree_selection_select_iter (selection, &iter);
307 accounts_dialog_update_settings (dialog, NULL);
312 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
317 GtkTreeSelection *selection;
318 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
320 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
322 if (gtk_tree_selection_get_selected (selection, &model, &iter))
323 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
325 return priv->setting_widget_object != NULL
326 && empathy_account_widget_contains_pending_changes (
327 priv->setting_widget_object);
331 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
332 EmpathyAccountsDialog *dialog)
334 TpConnectionManager *cm;
335 TpConnectionManagerProtocol *proto;
337 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
339 cm = empathy_protocol_chooser_dup_selected (
340 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
352 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
354 gtk_widget_show (priv->radiobutton_register);
355 gtk_widget_show (priv->radiobutton_reuse);
359 gtk_widget_hide (priv->radiobutton_register);
360 gtk_widget_hide (priv->radiobutton_reuse);
363 gtk_widget_hide (priv->radiobutton_register);
364 gtk_widget_hide (priv->radiobutton_reuse);
371 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
375 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
377 view = GTK_TREE_VIEW (priv->treeview);
378 model = gtk_tree_view_get_model (view);
380 gtk_widget_set_sensitive (priv->button_add, FALSE);
381 gtk_widget_hide (priv->vbox_details);
382 gtk_widget_hide (priv->frame_no_protocol);
383 gtk_widget_show (priv->frame_new_account);
385 /* If we have no account, no need of a back button */
386 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
387 gtk_widget_show (priv->button_back);
389 gtk_widget_hide (priv->button_back);
391 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
392 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
394 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
395 gtk_widget_grab_focus (priv->combobox_protocol);
399 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
400 const gchar *primary_text,
401 const gchar *secondary_text,
402 GCallback response_callback,
404 const gchar *first_button_text,
408 GtkWidget *message_dialog;
409 const gchar *button_text;
410 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
412 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
413 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
414 GTK_MESSAGE_QUESTION,
418 gtk_message_dialog_format_secondary_text (
419 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
421 va_start (button_args, first_button_text);
422 for (button_text = first_button_text;
424 button_text = va_arg (button_args, const gchar *))
427 response_id = va_arg (button_args, gint);
429 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
432 va_end (button_args);
434 g_signal_connect (message_dialog, "response", response_callback, user_data);
436 gtk_widget_show (message_dialog);
440 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
444 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
445 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
447 gtk_widget_destroy (GTK_WIDGET (message_dialog));
449 if (response_id == GTK_RESPONSE_YES)
451 empathy_account_widget_discard_pending_changes (
452 priv->setting_widget_object);
453 accounts_dialog_setup_ui_to_add_account (dialog);
458 get_dialog_primary_text (TpAccount *account)
462 /* Existing account */
463 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
464 tp_account_get_display_name (account));
468 /* Newly created account */
469 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
474 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
475 EmpathyAccountsDialog *dialog)
477 TpAccount *account = NULL;
479 if (accounts_dialog_has_pending_change (dialog, &account))
481 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
483 accounts_dialog_show_question_dialog (dialog,
484 question_dialog_primary_text,
485 _("You are about to create a new account, which will discard\n"
486 "your changes. Are you sure you want to proceed?"),
487 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
489 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
490 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
492 g_free (question_dialog_primary_text);
496 accounts_dialog_setup_ui_to_add_account (dialog);
501 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
502 EmpathyAccountSettings *settings)
504 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
506 if (priv->settings_ready != NULL)
508 g_signal_handler_disconnect (priv->settings_ready,
509 priv->settings_ready_id);
510 priv->settings_ready = NULL;
511 priv->settings_ready_id = 0;
518 GtkTreeSelection *selection;
520 view = GTK_TREE_VIEW (priv->treeview);
521 model = gtk_tree_view_get_model (view);
522 selection = gtk_tree_view_get_selection (view);
524 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
526 /* We have configured accounts, select the first one if there
527 * is no other account selected already. */
528 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
529 accounts_dialog_model_select_first (dialog);
533 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
535 /* We have no account configured but we have some
536 * profiles installed. The user obviously wants to add
537 * an account. Click on the Add button for him. */
538 accounts_dialog_button_add_clicked_cb (priv->button_add,
543 /* No account and no profile, warn the user */
544 gtk_widget_hide (priv->vbox_details);
545 gtk_widget_hide (priv->frame_new_account);
546 gtk_widget_show (priv->frame_no_protocol);
547 gtk_widget_set_sensitive (priv->button_add, FALSE);
551 /* We have an account selected, destroy old settings and create a new
552 * one for the account selected */
553 gtk_widget_hide (priv->frame_new_account);
554 gtk_widget_hide (priv->frame_no_protocol);
555 gtk_widget_show (priv->vbox_details);
556 gtk_widget_set_sensitive (priv->button_add, TRUE);
558 if (priv->settings_widget)
560 gtk_widget_destroy (priv->settings_widget);
561 priv->settings_widget = NULL;
564 if (empathy_account_settings_is_ready (settings))
566 account_dialog_create_settings_widget (dialog, settings);
570 priv->settings_ready = settings;
571 priv->settings_ready_id =
572 g_signal_connect (settings, "notify::ready",
573 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
579 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
580 GtkCellEditable *editable,
582 EmpathyAccountsDialog *dialog)
584 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
586 if (priv->connecting_id)
587 g_source_remove (priv->connecting_id);
589 DEBUG ("Editing account name started; stopping flashing");
593 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
594 GtkCellRenderer *cell,
597 EmpathyAccountsDialog *dialog)
599 EmpathyAccountSettings *settings;
602 TpConnectionStatus status;
603 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
605 gtk_tree_model_get (model, iter,
607 COL_ACCOUNT_SETTINGS_POINTER, &settings,
610 icon_name = empathy_account_settings_get_icon_name (settings);
611 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
615 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
616 (status == TP_CONNECTION_STATUS_CONNECTING &&
617 !priv->connecting_show))
619 GdkPixbuf *modded_pixbuf;
621 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
624 gdk_pixbuf_get_width (pixbuf),
625 gdk_pixbuf_get_height (pixbuf));
627 gdk_pixbuf_saturate_and_pixelate (pixbuf,
631 g_object_unref (pixbuf);
632 pixbuf = modded_pixbuf;
641 g_object_unref (settings);
644 g_object_unref (pixbuf);
648 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
653 gtk_tree_model_row_changed (model, path, iter);
659 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
663 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
665 priv->connecting_show = !priv->connecting_show;
667 view = GTK_TREE_VIEW (priv->treeview);
668 model = gtk_tree_view_get_model (view);
670 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
676 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
679 EmpathyAccountsDialog *dialog)
681 EmpathyAccountSettings *settings;
683 GtkTreePath *treepath;
685 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
688 empathy_account_manager_get_accounts_connected (&connecting);
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,
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 tp_account_remove_async (account, NULL, NULL);
738 g_object_unref (account);
742 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
743 accounts_dialog_model_select_first (account_dialog);
746 gtk_widget_destroy (GTK_WIDGET (message_dialog));
750 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
751 const gchar *path_string,
752 EmpathyAccountsDialog *dialog)
757 gchar *question_dialog_primary_text;
758 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
760 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
762 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
765 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
767 if (account == NULL || !tp_account_is_valid (account))
769 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
770 accounts_dialog_model_select_first (dialog);
774 question_dialog_primary_text = g_strdup_printf (
775 _("Do you want to remove %s from your computer?"),
776 tp_account_get_display_name (account));
778 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
779 _("This will not remove your account on the server."),
780 G_CALLBACK (accounts_dialog_delete_account_response_cb),
782 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
783 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
785 g_free (question_dialog_primary_text);
789 g_object_unref (account);
795 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
798 GtkTreeViewColumn *column;
799 GtkCellRenderer *cell;
800 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
802 view = GTK_TREE_VIEW (priv->treeview);
803 gtk_tree_view_set_headers_visible (view, FALSE);
806 column = gtk_tree_view_column_new ();
807 gtk_tree_view_column_set_expand (column, TRUE);
808 gtk_tree_view_append_column (view, column);
811 cell = gtk_cell_renderer_pixbuf_new ();
812 gtk_tree_view_column_pack_start (column, cell, FALSE);
813 gtk_tree_view_column_set_cell_data_func (column, cell,
814 (GtkTreeCellDataFunc)
815 accounts_dialog_model_pixbuf_data_func,
820 cell = gtk_cell_renderer_text_new ();
822 "ellipsize", PANGO_ELLIPSIZE_END,
826 gtk_tree_view_column_pack_start (column, cell, TRUE);
827 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
828 g_signal_connect (cell, "edited",
829 G_CALLBACK (accounts_dialog_name_edited_cb),
831 g_signal_connect (cell, "editing-started",
832 G_CALLBACK (accounts_dialog_name_editing_started_cb),
834 g_object_set (cell, "ypad", 4, NULL);
837 cell = empathy_cell_renderer_activatable_new ();
838 gtk_tree_view_column_pack_start (column, cell, FALSE);
840 "icon-name", GTK_STOCK_DELETE,
841 "show-on-select", TRUE,
844 g_signal_connect (cell, "path-activated",
845 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
849 static EmpathyAccountSettings *
850 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
854 GtkTreeSelection *selection;
856 EmpathyAccountSettings *settings;
857 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
859 view = GTK_TREE_VIEW (priv->treeview);
860 selection = gtk_tree_view_get_selection (view);
862 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
865 gtk_tree_model_get (model, &iter,
866 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
872 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
873 EmpathyAccountsDialog *dialog)
875 EmpathyAccountSettings *settings;
878 gboolean is_selection;
880 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
882 settings = accounts_dialog_model_get_selected_settings (dialog);
883 accounts_dialog_update_settings (dialog, settings);
885 if (settings != NULL)
886 g_object_unref (settings);
890 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
894 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
895 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
897 gtk_widget_destroy (GTK_WIDGET (message_dialog));
899 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
901 /* The user wants to lose unsaved changes to the currently selected
902 * account and select another account. We discard the changes and
903 * select the other account. */
905 GtkTreeSelection *selection;
907 priv->force_change_row = TRUE;
908 empathy_account_widget_discard_pending_changes (
909 priv->setting_widget_object);
911 path = gtk_tree_row_reference_get_path (priv->destination_row);
912 selection = gtk_tree_view_get_selection (
913 GTK_TREE_VIEW (priv->treeview));
917 /* This will trigger a call to
918 * accounts_dialog_account_selection_change() */
919 gtk_tree_selection_select_path (selection, path);
920 gtk_tree_path_free (path);
923 gtk_tree_row_reference_free (priv->destination_row);
927 priv->force_change_row = FALSE;
932 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
935 gboolean path_currently_selected,
938 TpAccount *account = NULL;
939 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
940 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
942 if (priv->force_change_row)
944 /* We came back here because the user wants to discard changes to his
945 * modified account. The changes have already been discarded so we
946 * just change the selected row. */
947 priv->force_change_row = FALSE;
951 if (accounts_dialog_has_pending_change (dialog, &account))
953 /* The currently selected account has some unsaved changes. We ask
954 * the user if he really wants to lose his changes and select another
956 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
957 priv->destination_row = gtk_tree_row_reference_new (model, path);
959 accounts_dialog_show_question_dialog (dialog,
960 question_dialog_primary_text,
961 _("You are about to select another account, which will discard\n"
962 "your changes. Are you sure you want to proceed?"),
963 G_CALLBACK (accounts_dialog_selection_change_response_cb),
965 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
966 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
968 g_free (question_dialog_primary_text);
979 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
982 GtkTreeSelection *selection;
983 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
985 store = gtk_list_store_new (COL_COUNT,
986 G_TYPE_STRING, /* name */
987 G_TYPE_UINT, /* status */
988 TP_TYPE_ACCOUNT, /* account */
989 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
991 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
992 GTK_TREE_MODEL (store));
994 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
995 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
996 gtk_tree_selection_set_select_function (selection,
997 accounts_dialog_account_selection_change, dialog, NULL);
999 g_signal_connect (selection, "changed",
1000 G_CALLBACK (accounts_dialog_model_selection_changed),
1003 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1004 COL_NAME, GTK_SORT_ASCENDING);
1006 accounts_dialog_model_add_columns (dialog);
1008 g_object_unref (store);
1012 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1013 EmpathyAccountSettings *settings,
1017 GtkTreeSelection *selection;
1018 GtkTreeModel *model;
1020 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1022 /* Update the status in the model */
1023 view = GTK_TREE_VIEW (priv->treeview);
1024 selection = gtk_tree_view_get_selection (view);
1025 model = gtk_tree_view_get_model (view);
1027 for (ok = gtk_tree_model_get_iter_first (model, iter);
1029 ok = gtk_tree_model_iter_next (model, iter))
1031 EmpathyAccountSettings *this_settings;
1034 gtk_tree_model_get (model, iter,
1035 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1038 equal = (this_settings == settings);
1039 g_object_unref (this_settings);
1049 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1054 GtkTreeSelection *selection;
1055 GtkTreeModel *model;
1057 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1059 /* Update the status in the model */
1060 view = GTK_TREE_VIEW (priv->treeview);
1061 selection = gtk_tree_view_get_selection (view);
1062 model = gtk_tree_view_get_model (view);
1064 for (ok = gtk_tree_model_get_iter_first (model, iter);
1066 ok = gtk_tree_model_iter_next (model, iter))
1068 EmpathyAccountSettings *settings;
1071 gtk_tree_model_get (model, iter,
1072 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1075 equal = empathy_account_settings_has_account (settings, account);
1076 g_object_unref (settings);
1086 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1087 EmpathyAccountSettings *settings)
1089 GtkTreeSelection *selection;
1091 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1093 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1094 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1095 gtk_tree_selection_select_iter (selection, &iter);
1098 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1099 EmpathyAccountSettings *settings)
1101 GtkTreeModel *model;
1104 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1106 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1107 name = empathy_account_settings_get_display_name (settings);
1109 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1111 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1113 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1114 COL_ACCOUNT_SETTINGS_POINTER, settings,
1119 accounts_dialog_connection_changed_cb (TpAccount *account,
1123 gchar *dbus_error_name,
1124 GHashTable *details,
1125 EmpathyAccountsDialog *dialog)
1127 GtkTreeModel *model;
1130 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1132 /* Update the status in the model */
1133 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1135 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1139 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1140 COL_STATUS, current,
1143 path = gtk_tree_model_get_path (model, &iter);
1144 gtk_tree_model_row_changed (model, path, &iter);
1145 gtk_tree_path_free (path);
1148 empathy_account_manager_get_accounts_connected (&found);
1150 if (!found && priv->connecting_id)
1152 g_source_remove (priv->connecting_id);
1153 priv->connecting_id = 0;
1156 if (found && !priv->connecting_id)
1157 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1158 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1163 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1167 const gchar *display_name;
1169 GtkTreeModel *model;
1170 EmpathyAccountSettings *settings;
1171 TpAccount *selected_account;
1172 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1173 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1175 display_name = tp_account_get_display_name (account);
1176 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1177 settings = accounts_dialog_model_get_selected_settings (dialog);
1178 if (settings == NULL)
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,
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 status = tp_account_get_connection_status (account, NULL);
1210 name = tp_account_get_display_name (account);
1211 enabled = tp_account_is_enabled (account);
1213 settings = empathy_account_settings_new_for_account (account);
1215 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1216 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
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 (account,
1228 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1233 empathy_signal_connect_weak (account, "notify::display-name",
1234 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1237 g_object_unref (settings);
1241 account_prepare_cb (GObject *source_object,
1242 GAsyncResult *result,
1245 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1246 TpAccount *account = TP_ACCOUNT (source_object);
1247 GError *error = NULL;
1249 if (!tp_account_prepare_finish (account, result, &error))
1251 DEBUG ("Failed to prepare account: %s", error->message);
1252 g_error_free (error);
1256 accounts_dialog_add_account (dialog, account);
1260 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1263 EmpathyAccountsDialog *dialog)
1265 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1269 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1271 EmpathyAccountsDialog *dialog)
1274 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1276 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1278 gtk_list_store_remove (GTK_LIST_STORE (
1279 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1284 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1288 GtkTreeModel *model;
1289 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1291 /* Update the status in the model */
1292 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1294 DEBUG ("Account %s is now %s",
1295 tp_account_get_display_name (account),
1296 enabled ? "enabled" : "disabled");
1300 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1302 EmpathyAccountsDialog *dialog)
1304 enable_or_disable_account (dialog, account, FALSE);
1308 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1310 EmpathyAccountsDialog *dialog)
1312 enable_or_disable_account (dialog, account, TRUE);
1316 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1317 EmpathyAccountsDialog *dialog)
1319 EmpathyAccountSettings *settings;
1321 const gchar *display_name;
1322 TpConnectionManager *cm;
1323 TpConnectionManagerProtocol *proto;
1324 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1327 cm = empathy_protocol_chooser_dup_selected (
1328 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1330 display_name = empathy_protocol_name_to_display_name (
1331 is_gtalk ? "gtalk" : proto->name);
1333 if (display_name == NULL)
1334 display_name = proto->name;
1336 /* Create account */
1337 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1340 str = g_strdup_printf (_("New %s account"), display_name);
1341 settings = empathy_account_settings_new (cm->name, proto->name, str);
1346 if (tp_connection_manager_protocol_can_register (proto))
1350 active = gtk_toggle_button_get_active
1351 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1353 empathy_account_settings_set_boolean (settings, "register", TRUE);
1358 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1361 accounts_dialog_add (dialog, settings);
1362 accounts_dialog_model_set_selected (dialog, settings);
1364 g_object_unref (settings);
1365 g_object_unref (cm);
1369 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1370 EmpathyAccountsDialog *dialog)
1372 EmpathyAccountSettings *settings;
1374 settings = accounts_dialog_model_get_selected_settings (dialog);
1375 accounts_dialog_update_settings (dialog, settings);
1378 g_object_unref (settings);
1382 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1383 EmpathyAccountsDialog *dialog)
1385 empathy_url_show (button, "ghelp:empathy?accounts-window");
1389 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1390 EmpathyAccountsDialog *dialog)
1392 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1393 GtkWidget *import_dialog;
1395 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1397 gtk_widget_show (import_dialog);
1401 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1405 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1407 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1409 if (response_id == GTK_RESPONSE_YES)
1410 gtk_widget_destroy (account_dialog);
1414 accounts_dialog_response_cb (GtkWidget *widget,
1416 EmpathyAccountsDialog *dialog)
1418 TpAccount *account = NULL;
1420 if (accounts_dialog_has_pending_change (dialog, &account))
1422 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1424 accounts_dialog_show_question_dialog (dialog,
1425 question_dialog_primary_text,
1426 _("You are about to close the window, which will discard\n"
1427 "your changes. Are you sure you want to proceed?"),
1428 G_CALLBACK (accounts_dialog_close_response_cb),
1430 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1431 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1433 g_free (question_dialog_primary_text);
1435 else if (response == GTK_RESPONSE_CLOSE ||
1436 response == GTK_RESPONSE_DELETE_EVENT)
1437 gtk_widget_destroy (widget);
1441 accounts_dialog_delete_event_cb (GtkWidget *widget,
1443 EmpathyAccountsDialog *dialog)
1445 /* we maunally handle responses to delete events */
1450 accounts_dialog_destroy_cb (GtkObject *obj,
1451 EmpathyAccountsDialog *dialog)
1455 g_object_unref (dialog);
1459 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1462 GtkTreeSelection *selection;
1464 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1466 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1467 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1468 gtk_tree_selection_select_iter (selection, &iter);
1472 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1474 EmpathyAccountsDialog *dialog)
1476 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1478 if (empathy_connection_managers_is_ready (cms))
1480 accounts_dialog_update_settings (dialog, NULL);
1482 if (priv->initial_selection != NULL)
1484 accounts_dialog_set_selected_account
1485 (dialog, priv->initial_selection);
1486 g_object_unref (priv->initial_selection);
1487 priv->initial_selection = NULL;
1493 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1495 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1496 GList *accounts, *l;
1498 g_signal_connect (priv->account_manager, "account-validity-changed",
1499 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1501 g_signal_connect (priv->account_manager, "account-removed",
1502 G_CALLBACK (accounts_dialog_account_removed_cb),
1504 g_signal_connect (priv->account_manager, "account-enabled",
1505 G_CALLBACK (accounts_dialog_account_enabled_cb),
1507 g_signal_connect (priv->account_manager, "account-disabled",
1508 G_CALLBACK (accounts_dialog_account_disabled_cb),
1511 /* Add existing accounts */
1512 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1513 for (l = accounts; l; l = l->next)
1515 accounts_dialog_add_account (dialog, l->data);
1517 empathy_signal_connect_weak (l->data, "status-changed",
1518 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1520 g_list_free (accounts);
1522 priv->cms = empathy_connection_managers_dup_singleton ();
1523 if (!empathy_connection_managers_is_ready (priv->cms))
1524 g_signal_connect (priv->cms, "notify::ready",
1525 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1527 accounts_dialog_model_select_first (dialog);
1531 accounts_dialog_manager_ready_cb (GObject *source_object,
1532 GAsyncResult *result,
1535 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1536 GError *error = NULL;
1538 if (!tp_account_manager_prepare_finish (manager, result, &error))
1540 DEBUG ("Failed to prepare account manager: %s", error->message);
1541 g_error_free (error);
1545 accounts_dialog_accounts_setup (user_data);
1549 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1553 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1555 GtkWidget *action_area;
1558 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1560 gui = empathy_builder_get_file (filename,
1561 "accounts_dialog", &priv->window,
1562 "vbox_details", &priv->vbox_details,
1563 "vbox_name", &priv->vbox_name,
1564 "frame_no_protocol", &priv->frame_no_protocol,
1565 "alignment_settings", &priv->alignment_settings,
1566 "treeview", &priv->treeview,
1567 "frame_new_account", &priv->frame_new_account,
1568 "hbox_type", &priv->hbox_type,
1569 "button_create", &priv->button_create,
1570 "button_back", &priv->button_back,
1571 "radiobutton_reuse", &priv->radiobutton_reuse,
1572 "radiobutton_register", &priv->radiobutton_register,
1573 "image_type", &priv->image_type,
1574 "label_name", &priv->label_name,
1575 "button_add", &priv->button_add,
1576 "button_import", &priv->button_import,
1580 empathy_builder_connect (gui, dialog,
1581 "accounts_dialog", "response", accounts_dialog_response_cb,
1582 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1583 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1584 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1585 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1586 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1587 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1588 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1591 g_object_unref (gui);
1594 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1595 gtk_widget_hide (action_area);
1597 /* Translators: this is used only when built on a moblin platform */
1598 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1599 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1602 priv->combobox_protocol = empathy_protocol_chooser_new ();
1603 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1604 priv->combobox_protocol,
1606 gtk_widget_show (priv->combobox_protocol);
1607 g_signal_connect (priv->combobox_protocol, "changed",
1608 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1611 if (priv->parent_window)
1612 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1613 priv->parent_window);
1617 do_dispose (GObject *obj)
1619 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1620 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1622 /* Disconnect signals */
1623 g_signal_handlers_disconnect_by_func (priv->account_manager,
1624 accounts_dialog_account_validity_changed_cb,
1626 g_signal_handlers_disconnect_by_func (priv->account_manager,
1627 accounts_dialog_account_removed_cb,
1629 g_signal_handlers_disconnect_by_func (priv->account_manager,
1630 accounts_dialog_account_enabled_cb,
1632 g_signal_handlers_disconnect_by_func (priv->account_manager,
1633 accounts_dialog_account_disabled_cb,
1635 g_signal_handlers_disconnect_by_func (priv->account_manager,
1636 accounts_dialog_manager_ready_cb,
1639 if (priv->connecting_id)
1640 g_source_remove (priv->connecting_id);
1642 if (priv->account_manager != NULL)
1644 g_object_unref (priv->account_manager);
1645 priv->account_manager = NULL;
1648 if (priv->cms != NULL)
1650 g_object_unref (priv->cms);
1654 if (priv->initial_selection != NULL)
1655 g_object_unref (priv->initial_selection);
1656 priv->initial_selection = NULL;
1658 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1662 do_constructor (GType type,
1664 GObjectConstructParam *props)
1668 if (dialog_singleton)
1670 retval = G_OBJECT (dialog_singleton);
1671 g_object_ref (retval);
1676 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1677 (type, n_props, props);
1679 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1680 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1681 /* We add an extra reference that we'll release when the dialog is
1682 * destroyed (accounts_dialog_destroy_cb) */
1683 g_object_ref (retval);
1690 do_get_property (GObject *object,
1695 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1697 switch (property_id)
1700 g_value_set_object (value, priv->parent_window);
1703 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1708 do_set_property (GObject *object,
1710 const GValue *value,
1713 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1715 switch (property_id)
1718 priv->parent_window = g_value_get_object (value);
1721 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1726 do_constructed (GObject *object)
1728 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1729 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1730 gboolean import_asked;
1732 accounts_dialog_build_ui (dialog);
1733 accounts_dialog_model_setup (dialog);
1735 /* Set up signalling */
1736 priv->account_manager = tp_account_manager_dup ();
1738 tp_account_manager_prepare_async (priv->account_manager, NULL,
1739 accounts_dialog_manager_ready_cb, dialog);
1741 empathy_conf_get_bool (empathy_conf_get (),
1742 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1744 if (empathy_import_accounts_to_import ())
1746 gtk_widget_show (priv->button_import);
1750 GtkWidget *import_dialog;
1752 empathy_conf_set_bool (empathy_conf_get (),
1753 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1754 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1756 gtk_widget_show (import_dialog);
1762 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1764 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1765 GParamSpec *param_spec;
1767 oclass->constructor = do_constructor;
1768 oclass->dispose = do_dispose;
1769 oclass->constructed = do_constructed;
1770 oclass->set_property = do_set_property;
1771 oclass->get_property = do_get_property;
1773 param_spec = g_param_spec_object ("parent",
1774 "parent", "The parent window",
1776 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1777 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1779 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1783 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1785 EmpathyAccountsDialogPriv *priv;
1787 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1788 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1789 EmpathyAccountsDialogPriv);
1790 dialog->priv = priv;
1793 /* public methods */
1796 empathy_accounts_dialog_show (GtkWindow *parent,
1797 TpAccount *selected_account)
1799 EmpathyAccountsDialog *dialog;
1800 EmpathyAccountsDialogPriv *priv;
1802 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1803 "parent", parent, NULL);
1805 priv = GET_PRIV (dialog);
1807 if (selected_account)
1809 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1810 accounts_dialog_set_selected_account (dialog, selected_account);
1812 /* save the selection to set it later when the cms
1815 priv->initial_selection = g_object_ref (selected_account);
1818 gtk_window_present (GTK_WINDOW (priv->window));
1819 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1820 * destroyed so we can release the ref returned by the constructor now. */
1821 g_object_unref (dialog);
1823 return priv->window;