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;
80 GtkWidget *frame_no_protocol;
84 GtkWidget *button_add;
85 GtkWidget *button_import;
87 GtkWidget *frame_new_account;
88 GtkWidget *combobox_protocol;
90 GtkWidget *button_create;
91 GtkWidget *button_back;
92 GtkWidget *radiobutton_reuse;
93 GtkWidget *radiobutton_register;
95 GtkWidget *image_type;
96 GtkWidget *label_name;
97 GtkWidget *label_type;
98 GtkWidget *settings_widget;
100 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
101 * his GtkWidget. It is the only reliable source we can query to know if
102 * there are any unsaved changes to the currently selected account. We can't
103 * look at the account settings because it does not contain everything that
104 * can be changed using the EmpathyAccountWidget. For instance, it does not
105 * contain the state of the "Enabled" checkbox. */
106 EmpathyAccountWidget *setting_widget_object;
108 gboolean connecting_show;
111 gulong settings_ready_id;
112 EmpathyAccountSettings *settings_ready;
114 TpAccountManager *account_manager;
115 EmpathyConnectionManagers *cms;
117 GtkWindow *parent_window;
118 TpAccount *initial_selection;
120 /* Those are needed when changing the selected row. When a user selects
121 * another account and there are unsaved changes on the currently selected
122 * one, a confirmation message box is presented to him. Since his answer
123 * is retrieved asynchronously, we keep some information as member of the
124 * EmpathyAccountsDialog object. */
125 gboolean force_change_row;
126 GtkTreeRowReference *destination_row;
129 } EmpathyAccountsDialogPriv;
135 COL_ACCOUNT_SETTINGS_POINTER,
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_settings (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
157 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
158 const gchar *display_name)
161 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
163 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
164 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
170 empathy_account_dialog_widget_cancelled_cb (
171 EmpathyAccountWidget *widget_object,
172 EmpathyAccountsDialog *dialog)
176 GtkTreeSelection *selection;
178 EmpathyAccountSettings *settings;
180 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
182 view = GTK_TREE_VIEW (priv->treeview);
183 selection = gtk_tree_view_get_selection (view);
185 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
188 gtk_tree_model_get (model, &iter,
189 COL_ACCOUNT_SETTINGS_POINTER, &settings,
190 COL_ACCOUNT_POINTER, &account, -1);
192 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
196 /* We were creating an account. We remove the selected row */
197 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
201 /* We were modifying an account. We discard the changes by reloading the
202 * settings and the UI. */
203 accounts_dialog_update_settings (dialog, settings);
204 g_object_unref (account);
207 if (settings != NULL)
208 g_object_unref (settings);
212 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
213 EmpathyAccountsDialog *dialog)
216 EmpathyAccountSettings *settings =
217 accounts_dialog_model_get_selected_settings (dialog);
219 display_name = empathy_account_widget_get_default_display_name (
222 empathy_account_settings_set_display_name_async (settings,
223 display_name, NULL, NULL);
225 g_free (display_name);
227 accounts_dialog_update_settings (dialog, settings);
230 g_object_unref (settings);
234 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
235 EmpathyAccountSettings *settings)
237 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
240 priv->setting_widget_object =
241 empathy_account_widget_new_for_protocol (settings, FALSE);
243 priv->settings_widget =
244 empathy_account_widget_get_widget (priv->setting_widget_object);
246 priv->settings_widget =
247 empathy_account_widget_get_widget (priv->setting_widget_object);
248 g_signal_connect (priv->setting_widget_object, "account-created",
249 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
250 g_signal_connect (priv->setting_widget_object, "cancelled",
251 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
253 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
254 priv->settings_widget);
255 gtk_widget_show (priv->settings_widget);
257 icon_name = empathy_account_settings_get_icon_name (settings);
259 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
261 /* show the default icon; keep this in sync with the default
262 * one in empathy-accounts-dialog.ui.
264 icon_name = GTK_STOCK_CUT;
266 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
267 icon_name, GTK_ICON_SIZE_DIALOG);
268 gtk_widget_set_tooltip_text (priv->image_type,
269 empathy_protocol_name_to_display_name
270 (empathy_account_settings_get_protocol (settings)));
271 gtk_widget_show (priv->image_type);
273 accounts_dialog_update_name_label (dialog,
274 empathy_account_settings_get_display_name (settings));
278 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
280 EmpathyAccountsDialog *dialog)
282 if (empathy_account_settings_is_ready (settings))
283 account_dialog_create_settings_widget (dialog, settings);
287 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
291 GtkTreeSelection *selection;
293 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
296 view = GTK_TREE_VIEW (priv->treeview);
297 model = gtk_tree_view_get_model (view);
299 if (gtk_tree_model_get_iter_first (model, &iter))
301 selection = gtk_tree_view_get_selection (view);
302 gtk_tree_selection_select_iter (selection, &iter);
306 accounts_dialog_update_settings (dialog, NULL);
311 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
316 GtkTreeSelection *selection;
317 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
319 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
321 if (gtk_tree_selection_get_selected (selection, &model, &iter))
322 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
324 return priv->setting_widget_object != NULL
325 && empathy_account_widget_contains_pending_changes (
326 priv->setting_widget_object);
330 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
331 EmpathyAccountsDialog *dialog)
333 TpConnectionManager *cm;
334 TpConnectionManagerProtocol *proto;
336 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
338 cm = empathy_protocol_chooser_dup_selected (
339 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
351 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
353 gtk_widget_show (priv->radiobutton_register);
354 gtk_widget_show (priv->radiobutton_reuse);
358 gtk_widget_hide (priv->radiobutton_register);
359 gtk_widget_hide (priv->radiobutton_reuse);
362 gtk_widget_hide (priv->radiobutton_register);
363 gtk_widget_hide (priv->radiobutton_reuse);
370 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
374 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
376 view = GTK_TREE_VIEW (priv->treeview);
377 model = gtk_tree_view_get_model (view);
379 gtk_widget_set_sensitive (priv->button_add, FALSE);
380 gtk_widget_hide (priv->vbox_details);
381 gtk_widget_hide (priv->frame_no_protocol);
382 gtk_widget_show (priv->frame_new_account);
384 /* If we have no account, no need of a back button */
385 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
386 gtk_widget_show (priv->button_back);
388 gtk_widget_hide (priv->button_back);
390 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
391 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
393 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
394 gtk_widget_grab_focus (priv->combobox_protocol);
398 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
399 const gchar *primary_text,
400 const gchar *secondary_text,
401 GCallback response_callback,
403 const gchar *first_button_text,
407 GtkWidget *message_dialog;
408 const gchar *button_text;
409 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
411 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
412 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
413 GTK_MESSAGE_QUESTION,
417 gtk_message_dialog_format_secondary_text (
418 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
420 va_start (button_args, first_button_text);
421 for (button_text = first_button_text;
423 button_text = va_arg (button_args, const gchar *))
426 response_id = va_arg (button_args, gint);
428 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
431 va_end (button_args);
433 g_signal_connect (message_dialog, "response", response_callback, user_data);
435 gtk_widget_show (message_dialog);
439 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
443 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
444 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
446 gtk_widget_destroy (GTK_WIDGET (message_dialog));
448 if (response_id == GTK_RESPONSE_YES)
450 empathy_account_widget_discard_pending_changes (
451 priv->setting_widget_object);
452 accounts_dialog_setup_ui_to_add_account (dialog);
457 get_dialog_primary_text (TpAccount *account)
461 /* Existing account */
462 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
463 tp_account_get_display_name (account));
467 /* Newly created account */
468 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
473 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
474 EmpathyAccountsDialog *dialog)
476 TpAccount *account = NULL;
478 if (accounts_dialog_has_pending_change (dialog, &account))
480 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
482 accounts_dialog_show_question_dialog (dialog,
483 question_dialog_primary_text,
484 _("You are about to create a new account, which will discard\n"
485 "your changes. Are you sure you want to proceed?"),
486 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
488 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
489 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
491 g_free (question_dialog_primary_text);
495 accounts_dialog_setup_ui_to_add_account (dialog);
500 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
501 EmpathyAccountSettings *settings)
503 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
505 if (priv->settings_ready != NULL)
507 g_signal_handler_disconnect (priv->settings_ready,
508 priv->settings_ready_id);
509 priv->settings_ready = NULL;
510 priv->settings_ready_id = 0;
517 GtkTreeSelection *selection;
519 view = GTK_TREE_VIEW (priv->treeview);
520 model = gtk_tree_view_get_model (view);
521 selection = gtk_tree_view_get_selection (view);
523 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
525 /* We have configured accounts, select the first one if there
526 * is no other account selected already. */
527 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
528 accounts_dialog_model_select_first (dialog);
532 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
534 /* We have no account configured but we have some
535 * profiles installed. The user obviously wants to add
536 * an account. Click on the Add button for him. */
537 accounts_dialog_button_add_clicked_cb (priv->button_add,
542 /* No account and no profile, warn the user */
543 gtk_widget_hide (priv->vbox_details);
544 gtk_widget_hide (priv->frame_new_account);
545 gtk_widget_show (priv->frame_no_protocol);
546 gtk_widget_set_sensitive (priv->button_add, FALSE);
550 /* We have an account selected, destroy old settings and create a new
551 * one for the account selected */
552 gtk_widget_hide (priv->frame_new_account);
553 gtk_widget_hide (priv->frame_no_protocol);
554 gtk_widget_show (priv->vbox_details);
555 gtk_widget_set_sensitive (priv->button_add, TRUE);
557 if (priv->settings_widget)
559 gtk_widget_destroy (priv->settings_widget);
560 priv->settings_widget = NULL;
563 if (empathy_account_settings_is_ready (settings))
565 account_dialog_create_settings_widget (dialog, settings);
569 priv->settings_ready = settings;
570 priv->settings_ready_id =
571 g_signal_connect (settings, "notify::ready",
572 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
578 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
579 GtkCellEditable *editable,
581 EmpathyAccountsDialog *dialog)
583 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
585 if (priv->connecting_id)
586 g_source_remove (priv->connecting_id);
588 DEBUG ("Editing account name started; stopping flashing");
592 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
593 GtkCellRenderer *cell,
596 EmpathyAccountsDialog *dialog)
598 EmpathyAccountSettings *settings;
601 TpConnectionStatus status;
602 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
604 gtk_tree_model_get (model, iter,
606 COL_ACCOUNT_SETTINGS_POINTER, &settings,
609 icon_name = empathy_account_settings_get_icon_name (settings);
610 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
614 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
615 (status == TP_CONNECTION_STATUS_CONNECTING &&
616 !priv->connecting_show))
618 GdkPixbuf *modded_pixbuf;
620 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
623 gdk_pixbuf_get_width (pixbuf),
624 gdk_pixbuf_get_height (pixbuf));
626 gdk_pixbuf_saturate_and_pixelate (pixbuf,
630 g_object_unref (pixbuf);
631 pixbuf = modded_pixbuf;
640 g_object_unref (settings);
643 g_object_unref (pixbuf);
647 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
652 gtk_tree_model_row_changed (model, path, iter);
658 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
662 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
664 priv->connecting_show = !priv->connecting_show;
666 view = GTK_TREE_VIEW (priv->treeview);
667 model = gtk_tree_view_get_model (view);
669 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
675 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
678 EmpathyAccountsDialog *dialog)
680 EmpathyAccountSettings *settings;
682 GtkTreePath *treepath;
684 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
687 empathy_account_manager_get_accounts_connected (&connecting);
691 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
692 (GSourceFunc) accounts_dialog_flash_connecting_cb,
696 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
697 treepath = gtk_tree_path_new_from_string (path);
698 gtk_tree_model_get_iter (model, &iter, treepath);
699 gtk_tree_model_get (model, &iter,
700 COL_ACCOUNT_SETTINGS_POINTER, &settings,
702 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
705 gtk_tree_path_free (treepath);
707 empathy_account_settings_set_display_name_async (settings, new_text,
709 g_object_set (settings, "display-name-overridden", TRUE, NULL);
710 g_object_unref (settings);
714 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
721 GtkTreeSelection *selection;
722 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
723 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
725 if (response_id == GTK_RESPONSE_YES)
727 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
729 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
732 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
736 tp_account_remove_async (account, NULL, NULL);
737 g_object_unref (account);
741 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
742 accounts_dialog_model_select_first (account_dialog);
745 gtk_widget_destroy (GTK_WIDGET (message_dialog));
749 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
750 const gchar *path_string,
751 EmpathyAccountsDialog *dialog)
756 gchar *question_dialog_primary_text;
757 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
759 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
761 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
764 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
766 if (account == NULL || !tp_account_is_valid (account))
768 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
769 accounts_dialog_model_select_first (dialog);
773 question_dialog_primary_text = g_strdup_printf (
774 _("Do you want to remove %s from your computer?"),
775 tp_account_get_display_name (account));
777 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
778 _("This will not remove your account on the server."),
779 G_CALLBACK (accounts_dialog_delete_account_response_cb),
781 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
782 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
784 g_free (question_dialog_primary_text);
788 g_object_unref (account);
794 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
797 GtkTreeViewColumn *column;
798 GtkCellRenderer *cell;
799 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
801 view = GTK_TREE_VIEW (priv->treeview);
802 gtk_tree_view_set_headers_visible (view, FALSE);
805 column = gtk_tree_view_column_new ();
806 gtk_tree_view_column_set_expand (column, TRUE);
807 gtk_tree_view_append_column (view, column);
810 cell = gtk_cell_renderer_pixbuf_new ();
811 gtk_tree_view_column_pack_start (column, cell, FALSE);
812 gtk_tree_view_column_set_cell_data_func (column, cell,
813 (GtkTreeCellDataFunc)
814 accounts_dialog_model_pixbuf_data_func,
819 cell = gtk_cell_renderer_text_new ();
821 "ellipsize", PANGO_ELLIPSIZE_END,
825 gtk_tree_view_column_pack_start (column, cell, TRUE);
826 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
827 g_signal_connect (cell, "edited",
828 G_CALLBACK (accounts_dialog_name_edited_cb),
830 g_signal_connect (cell, "editing-started",
831 G_CALLBACK (accounts_dialog_name_editing_started_cb),
833 g_object_set (cell, "ypad", 4, NULL);
836 cell = empathy_cell_renderer_activatable_new ();
837 gtk_tree_view_column_pack_start (column, cell, FALSE);
839 "icon-name", GTK_STOCK_DELETE,
840 "show-on-select", TRUE,
843 g_signal_connect (cell, "path-activated",
844 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
848 static EmpathyAccountSettings *
849 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
853 GtkTreeSelection *selection;
855 EmpathyAccountSettings *settings;
856 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
858 view = GTK_TREE_VIEW (priv->treeview);
859 selection = gtk_tree_view_get_selection (view);
861 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
864 gtk_tree_model_get (model, &iter,
865 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
871 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
872 EmpathyAccountsDialog *dialog)
874 EmpathyAccountSettings *settings;
877 gboolean is_selection;
879 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
881 settings = accounts_dialog_model_get_selected_settings (dialog);
882 accounts_dialog_update_settings (dialog, settings);
884 if (settings != NULL)
885 g_object_unref (settings);
889 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
893 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
894 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
896 gtk_widget_destroy (GTK_WIDGET (message_dialog));
898 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
900 /* The user wants to lose unsaved changes to the currently selected
901 * account and select another account. We discard the changes and
902 * select the other account. */
904 GtkTreeSelection *selection;
906 priv->force_change_row = TRUE;
907 empathy_account_widget_discard_pending_changes (
908 priv->setting_widget_object);
910 path = gtk_tree_row_reference_get_path (priv->destination_row);
911 selection = gtk_tree_view_get_selection (
912 GTK_TREE_VIEW (priv->treeview));
916 /* This will trigger a call to
917 * accounts_dialog_account_selection_change() */
918 gtk_tree_selection_select_path (selection, path);
919 gtk_tree_path_free (path);
922 gtk_tree_row_reference_free (priv->destination_row);
926 priv->force_change_row = FALSE;
931 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
934 gboolean path_currently_selected,
937 TpAccount *account = NULL;
938 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
939 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
941 if (priv->force_change_row)
943 /* We came back here because the user wants to discard changes to his
944 * modified account. The changes have already been discarded so we
945 * just change the selected row. */
946 priv->force_change_row = FALSE;
950 if (accounts_dialog_has_pending_change (dialog, &account))
952 /* The currently selected account has some unsaved changes. We ask
953 * the user if he really wants to lose his changes and select another
955 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
956 priv->destination_row = gtk_tree_row_reference_new (model, path);
958 accounts_dialog_show_question_dialog (dialog,
959 question_dialog_primary_text,
960 _("You are about to select another account, which will discard\n"
961 "your changes. Are you sure you want to proceed?"),
962 G_CALLBACK (accounts_dialog_selection_change_response_cb),
964 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
965 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
967 g_free (question_dialog_primary_text);
978 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
981 GtkTreeSelection *selection;
982 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
984 store = gtk_list_store_new (COL_COUNT,
985 G_TYPE_STRING, /* name */
986 G_TYPE_UINT, /* status */
987 TP_TYPE_ACCOUNT, /* account */
988 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
990 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
991 GTK_TREE_MODEL (store));
993 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
994 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
995 gtk_tree_selection_set_select_function (selection,
996 accounts_dialog_account_selection_change, dialog, NULL);
998 g_signal_connect (selection, "changed",
999 G_CALLBACK (accounts_dialog_model_selection_changed),
1002 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1003 COL_NAME, GTK_SORT_ASCENDING);
1005 accounts_dialog_model_add_columns (dialog);
1007 g_object_unref (store);
1011 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1012 EmpathyAccountSettings *settings,
1016 GtkTreeSelection *selection;
1017 GtkTreeModel *model;
1019 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1021 /* Update the status in the model */
1022 view = GTK_TREE_VIEW (priv->treeview);
1023 selection = gtk_tree_view_get_selection (view);
1024 model = gtk_tree_view_get_model (view);
1026 for (ok = gtk_tree_model_get_iter_first (model, iter);
1028 ok = gtk_tree_model_iter_next (model, iter))
1030 EmpathyAccountSettings *this_settings;
1033 gtk_tree_model_get (model, iter,
1034 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1037 equal = (this_settings == settings);
1038 g_object_unref (this_settings);
1048 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1053 GtkTreeSelection *selection;
1054 GtkTreeModel *model;
1056 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1058 /* Update the status in the model */
1059 view = GTK_TREE_VIEW (priv->treeview);
1060 selection = gtk_tree_view_get_selection (view);
1061 model = gtk_tree_view_get_model (view);
1063 for (ok = gtk_tree_model_get_iter_first (model, iter);
1065 ok = gtk_tree_model_iter_next (model, iter))
1067 EmpathyAccountSettings *settings;
1070 gtk_tree_model_get (model, iter,
1071 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1074 equal = empathy_account_settings_has_account (settings, account);
1075 g_object_unref (settings);
1085 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1086 EmpathyAccountSettings *settings)
1088 GtkTreeSelection *selection;
1090 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1092 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1093 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1094 gtk_tree_selection_select_iter (selection, &iter);
1097 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1098 EmpathyAccountSettings *settings)
1100 GtkTreeModel *model;
1103 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1105 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1106 name = empathy_account_settings_get_display_name (settings);
1108 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1110 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1112 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1113 COL_ACCOUNT_SETTINGS_POINTER, settings,
1118 accounts_dialog_connection_changed_cb (TpAccount *account,
1122 gchar *dbus_error_name,
1123 GHashTable *details,
1124 EmpathyAccountsDialog *dialog)
1126 GtkTreeModel *model;
1129 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1131 /* Update the status in the model */
1132 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1134 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1138 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1139 COL_STATUS, current,
1142 path = gtk_tree_model_get_path (model, &iter);
1143 gtk_tree_model_row_changed (model, path, &iter);
1144 gtk_tree_path_free (path);
1147 empathy_account_manager_get_accounts_connected (&found);
1149 if (!found && priv->connecting_id)
1151 g_source_remove (priv->connecting_id);
1152 priv->connecting_id = 0;
1155 if (found && !priv->connecting_id)
1156 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1157 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1162 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1166 const gchar *display_name;
1168 GtkTreeModel *model;
1169 EmpathyAccountSettings *settings;
1170 TpAccount *selected_account;
1171 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1172 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1174 display_name = tp_account_get_display_name (account);
1175 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1176 settings = accounts_dialog_model_get_selected_settings (dialog);
1177 if (settings == NULL)
1180 selected_account = empathy_account_settings_get_account (settings);
1182 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1184 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1185 COL_NAME, display_name,
1189 if (selected_account == account)
1190 accounts_dialog_update_name_label (dialog, display_name);
1192 g_object_unref (settings);
1196 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1199 EmpathyAccountSettings *settings;
1200 GtkTreeModel *model;
1202 TpConnectionStatus status;
1205 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1207 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1208 status = tp_account_get_connection_status (account, NULL);
1209 name = tp_account_get_display_name (account);
1210 enabled = tp_account_is_enabled (account);
1212 settings = empathy_account_settings_new_for_account (account);
1214 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1215 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1217 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1220 COL_ACCOUNT_POINTER, account,
1221 COL_ACCOUNT_SETTINGS_POINTER, settings,
1224 accounts_dialog_connection_changed_cb (account,
1227 TP_CONNECTION_STATUS_DISCONNECTED,
1232 empathy_signal_connect_weak (account, "notify::display-name",
1233 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1236 g_object_unref (settings);
1240 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1243 EmpathyAccountsDialog *dialog)
1245 accounts_dialog_add_account (dialog, account);
1249 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1251 EmpathyAccountsDialog *dialog)
1254 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1256 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1258 gtk_list_store_remove (GTK_LIST_STORE (
1259 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1264 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1268 GtkTreeModel *model;
1269 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1271 /* Update the status in the model */
1272 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1274 DEBUG ("Account %s is now %s",
1275 tp_account_get_display_name (account),
1276 enabled ? "enabled" : "disabled");
1280 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1282 EmpathyAccountsDialog *dialog)
1284 enable_or_disable_account (dialog, account, FALSE);
1288 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1290 EmpathyAccountsDialog *dialog)
1292 enable_or_disable_account (dialog, account, TRUE);
1296 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1297 EmpathyAccountsDialog *dialog)
1299 EmpathyAccountSettings *settings;
1301 const gchar *display_name;
1302 TpConnectionManager *cm;
1303 TpConnectionManagerProtocol *proto;
1304 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1307 cm = empathy_protocol_chooser_dup_selected (
1308 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1310 display_name = empathy_protocol_name_to_display_name (
1311 is_gtalk ? "gtalk" : proto->name);
1313 if (display_name == NULL)
1314 display_name = proto->name;
1316 /* Create account */
1317 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1320 str = g_strdup_printf (_("New %s account"), display_name);
1321 settings = empathy_account_settings_new (cm->name, proto->name, str);
1326 if (tp_connection_manager_protocol_can_register (proto))
1330 active = gtk_toggle_button_get_active
1331 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1333 empathy_account_settings_set_boolean (settings, "register", TRUE);
1338 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1341 accounts_dialog_add (dialog, settings);
1342 accounts_dialog_model_set_selected (dialog, settings);
1344 g_object_unref (settings);
1345 g_object_unref (cm);
1349 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1350 EmpathyAccountsDialog *dialog)
1352 EmpathyAccountSettings *settings;
1354 settings = accounts_dialog_model_get_selected_settings (dialog);
1355 accounts_dialog_update_settings (dialog, settings);
1358 g_object_unref (settings);
1362 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1363 EmpathyAccountsDialog *dialog)
1365 empathy_url_show (button, "ghelp:empathy?accounts-window");
1369 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1370 EmpathyAccountsDialog *dialog)
1372 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1373 GtkWidget *import_dialog;
1375 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1377 gtk_widget_show (import_dialog);
1381 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1385 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1387 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1389 if (response_id == GTK_RESPONSE_YES)
1390 gtk_widget_destroy (account_dialog);
1394 accounts_dialog_response_cb (GtkWidget *widget,
1396 EmpathyAccountsDialog *dialog)
1398 TpAccount *account = NULL;
1400 if (accounts_dialog_has_pending_change (dialog, &account))
1402 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1404 accounts_dialog_show_question_dialog (dialog,
1405 question_dialog_primary_text,
1406 _("You are about to close the window, which will discard\n"
1407 "your changes. Are you sure you want to proceed?"),
1408 G_CALLBACK (accounts_dialog_close_response_cb),
1410 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1411 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1413 g_free (question_dialog_primary_text);
1415 else if (response == GTK_RESPONSE_CLOSE ||
1416 response == GTK_RESPONSE_DELETE_EVENT)
1417 gtk_widget_destroy (widget);
1421 accounts_dialog_delete_event_cb (GtkWidget *widget,
1423 EmpathyAccountsDialog *dialog)
1425 /* we maunally handle responses to delete events */
1430 accounts_dialog_destroy_cb (GtkObject *obj,
1431 EmpathyAccountsDialog *dialog)
1435 g_object_unref (dialog);
1439 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1442 GtkTreeSelection *selection;
1444 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1446 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1447 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1448 gtk_tree_selection_select_iter (selection, &iter);
1452 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1454 EmpathyAccountsDialog *dialog)
1456 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1458 if (empathy_connection_managers_is_ready (cms))
1460 accounts_dialog_update_settings (dialog, NULL);
1462 if (priv->initial_selection != NULL)
1464 accounts_dialog_set_selected_account
1465 (dialog, priv->initial_selection);
1466 g_object_unref (priv->initial_selection);
1467 priv->initial_selection = NULL;
1473 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1475 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1476 GList *accounts, *l;
1478 g_signal_connect (priv->account_manager, "account-validity-changed",
1479 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1481 g_signal_connect (priv->account_manager, "account-removed",
1482 G_CALLBACK (accounts_dialog_account_removed_cb),
1484 g_signal_connect (priv->account_manager, "account-enabled",
1485 G_CALLBACK (accounts_dialog_account_enabled_cb),
1487 g_signal_connect (priv->account_manager, "account-disabled",
1488 G_CALLBACK (accounts_dialog_account_disabled_cb),
1491 /* Add existing accounts */
1492 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1493 for (l = accounts; l; l = l->next)
1495 accounts_dialog_add_account (dialog, l->data);
1497 empathy_signal_connect_weak (l->data, "status-changed",
1498 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1500 g_list_free (accounts);
1502 priv->cms = empathy_connection_managers_dup_singleton ();
1503 if (!empathy_connection_managers_is_ready (priv->cms))
1504 g_signal_connect (priv->cms, "notify::ready",
1505 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1507 accounts_dialog_model_select_first (dialog);
1511 accounts_dialog_manager_ready_cb (GObject *source_object,
1512 GAsyncResult *result,
1515 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1516 GError *error = NULL;
1518 if (!tp_account_manager_prepare_finish (manager, result, &error))
1520 DEBUG ("Failed to prepare account manager: %s", error->message);
1521 g_error_free (error);
1525 accounts_dialog_accounts_setup (user_data);
1529 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1533 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1535 GtkWidget *action_area;
1538 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1540 gui = empathy_builder_get_file (filename,
1541 "accounts_dialog", &priv->window,
1542 "vbox_details", &priv->vbox_details,
1543 "frame_no_protocol", &priv->frame_no_protocol,
1544 "alignment_settings", &priv->alignment_settings,
1545 "treeview", &priv->treeview,
1546 "frame_new_account", &priv->frame_new_account,
1547 "hbox_type", &priv->hbox_type,
1548 "button_create", &priv->button_create,
1549 "button_back", &priv->button_back,
1550 "radiobutton_reuse", &priv->radiobutton_reuse,
1551 "radiobutton_register", &priv->radiobutton_register,
1552 "image_type", &priv->image_type,
1553 "label_name", &priv->label_name,
1554 "button_add", &priv->button_add,
1555 "button_import", &priv->button_import,
1559 empathy_builder_connect (gui, dialog,
1560 "accounts_dialog", "response", accounts_dialog_response_cb,
1561 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1562 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1563 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1564 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1565 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1566 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1567 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1570 g_object_unref (gui);
1573 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1574 gtk_widget_hide (action_area);
1576 /* Translators: this is used only when built on a moblin platform */
1577 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1578 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1581 priv->combobox_protocol = empathy_protocol_chooser_new ();
1582 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1583 priv->combobox_protocol,
1585 gtk_widget_show (priv->combobox_protocol);
1586 g_signal_connect (priv->combobox_protocol, "changed",
1587 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1590 if (priv->parent_window)
1591 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1592 priv->parent_window);
1596 do_dispose (GObject *obj)
1598 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1599 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1601 /* Disconnect signals */
1602 g_signal_handlers_disconnect_by_func (priv->account_manager,
1603 accounts_dialog_account_validity_changed_cb,
1605 g_signal_handlers_disconnect_by_func (priv->account_manager,
1606 accounts_dialog_account_removed_cb,
1608 g_signal_handlers_disconnect_by_func (priv->account_manager,
1609 accounts_dialog_account_enabled_cb,
1611 g_signal_handlers_disconnect_by_func (priv->account_manager,
1612 accounts_dialog_account_disabled_cb,
1614 g_signal_handlers_disconnect_by_func (priv->account_manager,
1615 accounts_dialog_manager_ready_cb,
1618 if (priv->connecting_id)
1619 g_source_remove (priv->connecting_id);
1621 if (priv->account_manager != NULL)
1623 g_object_unref (priv->account_manager);
1624 priv->account_manager = NULL;
1627 if (priv->cms != NULL)
1629 g_object_unref (priv->cms);
1633 if (priv->initial_selection != NULL)
1634 g_object_unref (priv->initial_selection);
1635 priv->initial_selection = NULL;
1637 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1641 do_constructor (GType type,
1643 GObjectConstructParam *props)
1647 if (dialog_singleton)
1649 retval = G_OBJECT (dialog_singleton);
1650 g_object_ref (retval);
1655 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1656 (type, n_props, props);
1658 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1659 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1660 /* We add an extra reference that we'll release when the dialog is
1661 * destroyed (accounts_dialog_destroy_cb) */
1662 g_object_ref (retval);
1669 do_get_property (GObject *object,
1674 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1676 switch (property_id)
1679 g_value_set_object (value, priv->parent_window);
1682 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1687 do_set_property (GObject *object,
1689 const GValue *value,
1692 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1694 switch (property_id)
1697 priv->parent_window = g_value_get_object (value);
1700 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1705 do_constructed (GObject *object)
1707 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1708 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1709 gboolean import_asked;
1711 accounts_dialog_build_ui (dialog);
1712 accounts_dialog_model_setup (dialog);
1714 /* Set up signalling */
1715 priv->account_manager = tp_account_manager_dup ();
1717 tp_account_manager_prepare_async (priv->account_manager, NULL,
1718 accounts_dialog_manager_ready_cb, dialog);
1720 empathy_conf_get_bool (empathy_conf_get (),
1721 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1723 if (empathy_import_accounts_to_import ())
1725 gtk_widget_show (priv->button_import);
1729 GtkWidget *import_dialog;
1731 empathy_conf_set_bool (empathy_conf_get (),
1732 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1733 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1735 gtk_widget_show (import_dialog);
1741 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1743 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1744 GParamSpec *param_spec;
1746 oclass->constructor = do_constructor;
1747 oclass->dispose = do_dispose;
1748 oclass->constructed = do_constructed;
1749 oclass->set_property = do_set_property;
1750 oclass->get_property = do_get_property;
1752 param_spec = g_param_spec_object ("parent",
1753 "parent", "The parent window",
1755 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1756 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1758 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1762 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1764 EmpathyAccountsDialogPriv *priv;
1766 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1767 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1768 EmpathyAccountsDialogPriv);
1769 dialog->priv = priv;
1772 /* public methods */
1775 empathy_accounts_dialog_show (GtkWindow *parent,
1776 TpAccount *selected_account)
1778 EmpathyAccountsDialog *dialog;
1779 EmpathyAccountsDialogPriv *priv;
1781 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1782 "parent", parent, NULL);
1784 priv = GET_PRIV (dialog);
1786 if (selected_account)
1788 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1789 accounts_dialog_set_selected_account (dialog, selected_account);
1791 /* save the selection to set it later when the cms
1794 priv->initial_selection = g_object_ref (selected_account);
1797 gtk_window_present (GTK_WINDOW (priv->window));
1798 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1799 * destroyed so we can release the ref returned by the constructor now. */
1800 g_object_unref (dialog);
1802 return priv->window;