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.")
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;
81 GtkWidget *button_import;
83 GtkWidget *frame_new_account;
84 GtkWidget *combobox_protocol;
86 GtkWidget *button_create;
87 GtkWidget *button_back;
88 GtkWidget *radiobutton_reuse;
89 GtkWidget *radiobutton_register;
91 GtkWidget *image_type;
92 GtkWidget *label_name;
93 GtkWidget *label_type;
94 GtkWidget *settings_widget;
96 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
97 * his GtkWidget. It is the only reliable source we can query to know if
98 * there are any unsaved changes to the currently selected account. We can't
99 * look at the account settings because it does not contain everything that
100 * can be changed using the EmpathyAccountWidget. For instance, it does not
101 * contain the state of the "Enabled" checkbox. */
102 EmpathyAccountWidget *setting_widget_object;
104 gboolean connecting_show;
107 gulong settings_ready_id;
108 EmpathyAccountSettings *settings_ready;
110 TpAccountManager *account_manager;
111 EmpathyConnectionManagers *cms;
113 GtkWindow *parent_window;
114 TpAccount *initial_selection;
116 /* Those are needed when changing the selected row. When a user selects
117 * another account and there are unsaved changes on the currently selected
118 * one, a confirmation message box is presented to him. Since his answer
119 * is retrieved asynchronously, we keep some information as member of the
120 * EmpathyAccountsDialog object. */
121 gboolean force_change_row;
122 GtkTreeRowReference *destination_row;
125 } EmpathyAccountsDialogPriv;
131 COL_ACCOUNT_SETTINGS_POINTER,
139 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
140 EmpathyAccountsDialog *dialog);
142 static gboolean accounts_dialog_get_settings_iter (
143 EmpathyAccountsDialog *dialog,
144 EmpathyAccountSettings *settings,
147 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
150 EmpathyAccountSettings *settings);
153 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
154 const gchar *display_name)
157 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
159 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
160 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
166 empathy_account_dialog_widget_cancelled_cb (
167 EmpathyAccountWidget *widget_object,
168 EmpathyAccountsDialog *dialog)
172 GtkTreeSelection *selection;
174 EmpathyAccountSettings *settings;
176 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
178 view = GTK_TREE_VIEW (priv->treeview);
179 selection = gtk_tree_view_get_selection (view);
181 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
184 gtk_tree_model_get (model, &iter,
185 COL_ACCOUNT_SETTINGS_POINTER, &settings,
186 COL_ACCOUNT_POINTER, &account, -1);
188 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
192 /* We were creating an account. We remove the selected row */
193 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
197 /* We were modifying an account. We discard the changes by reloading the
198 * settings and the UI. */
199 accounts_dialog_update_settings (dialog, settings);
200 g_object_unref (account);
203 if (settings != NULL)
204 g_object_unref (settings);
208 get_default_display_name (EmpathyAccountSettings *settings)
210 const gchar *login_id;
211 const gchar *protocol, *p;
212 gchar *default_display_name;
214 login_id = empathy_account_settings_get_string (settings, "account");
215 protocol = empathy_account_settings_get_protocol (settings);
217 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
220 if (login_id != NULL)
222 if (!tp_strdiff (protocol, "irc"))
225 server = empathy_account_settings_get_string (settings, "server");
227 /* To translators: The first parameter is the login id and the
228 * second one is the server. The resulting string will be something
229 * like: "MyUserName on chat.freenode.net".
230 * You should reverse the order of these arguments if the
231 * server should come before the login id in your locale.*/
232 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
237 default_display_name = g_strdup (login_id);
240 else if (protocol != NULL)
242 /* To translators: The parameter is the protocol name. The resulting
243 * string will be something like: "Jabber Account" */
244 default_display_name = g_strdup_printf (_("%s Account"), protocol);
248 default_display_name = g_strdup (_("New account"));
251 return default_display_name;
255 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
256 EmpathyAccountsDialog *dialog)
259 EmpathyAccountSettings *settings =
260 accounts_dialog_model_get_selected_settings (dialog);
262 display_name = get_default_display_name (settings);
264 empathy_account_settings_set_display_name_async (settings,
265 display_name, NULL, NULL);
267 g_free (display_name);
269 accounts_dialog_update_settings (dialog, settings);
272 g_object_unref (settings);
276 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
277 EmpathyAccountSettings *settings)
279 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
282 priv->setting_widget_object =
283 empathy_account_widget_new_for_protocol (settings, FALSE);
285 priv->settings_widget =
286 empathy_account_widget_get_widget (priv->setting_widget_object);
288 priv->settings_widget =
289 empathy_account_widget_get_widget (priv->setting_widget_object);
290 g_signal_connect (priv->setting_widget_object, "account-created",
291 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
292 g_signal_connect (priv->setting_widget_object, "cancelled",
293 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
295 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
296 priv->settings_widget);
297 gtk_widget_show (priv->settings_widget);
299 icon_name = empathy_account_settings_get_icon_name (settings);
301 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
303 /* show the default icon; keep this in sync with the default
304 * one in empathy-accounts-dialog.ui.
306 icon_name = GTK_STOCK_CUT;
308 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
309 icon_name, GTK_ICON_SIZE_DIALOG);
310 gtk_widget_set_tooltip_text (priv->image_type,
311 empathy_protocol_name_to_display_name
312 (empathy_account_settings_get_protocol (settings)));
313 gtk_widget_show (priv->image_type);
315 accounts_dialog_update_name_label (dialog,
316 empathy_account_settings_get_display_name (settings));
320 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
322 EmpathyAccountsDialog *dialog)
324 if (empathy_account_settings_is_ready (settings))
325 account_dialog_create_settings_widget (dialog, settings);
329 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
333 GtkTreeSelection *selection;
335 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
338 view = GTK_TREE_VIEW (priv->treeview);
339 model = gtk_tree_view_get_model (view);
341 if (gtk_tree_model_get_iter_first (model, &iter))
343 selection = gtk_tree_view_get_selection (view);
344 gtk_tree_selection_select_iter (selection, &iter);
348 accounts_dialog_update_settings (dialog, NULL);
353 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
358 GtkTreeSelection *selection;
359 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
361 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
363 if (gtk_tree_selection_get_selected (selection, &model, &iter))
364 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
366 return *account != NULL && priv->setting_widget_object != NULL
367 && empathy_account_widget_contains_pending_changes (
368 priv->setting_widget_object);
372 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
373 EmpathyAccountsDialog *dialog)
375 TpConnectionManager *cm;
376 TpConnectionManagerProtocol *proto;
378 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
380 cm = empathy_protocol_chooser_dup_selected (
381 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
393 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
395 gtk_widget_show (priv->radiobutton_register);
396 gtk_widget_show (priv->radiobutton_reuse);
400 gtk_widget_hide (priv->radiobutton_register);
401 gtk_widget_hide (priv->radiobutton_reuse);
404 gtk_widget_hide (priv->radiobutton_register);
405 gtk_widget_hide (priv->radiobutton_reuse);
412 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
416 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
418 view = GTK_TREE_VIEW (priv->treeview);
419 model = gtk_tree_view_get_model (view);
421 gtk_widget_set_sensitive (priv->button_add, FALSE);
422 gtk_widget_hide (priv->vbox_details);
423 gtk_widget_hide (priv->frame_no_protocol);
424 gtk_widget_show (priv->frame_new_account);
426 /* If we have no account, no need of a back button */
427 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
428 gtk_widget_show (priv->button_back);
430 gtk_widget_hide (priv->button_back);
432 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
433 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
435 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
436 gtk_widget_grab_focus (priv->combobox_protocol);
440 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
441 const gchar *primary_text,
442 const gchar *secondary_text,
443 GCallback response_callback,
445 const gchar *first_button_text,
449 GtkWidget *message_dialog;
450 const gchar *button_text;
451 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
453 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
454 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
455 GTK_MESSAGE_QUESTION,
459 gtk_message_dialog_format_secondary_text (
460 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
462 va_start (button_args, first_button_text);
463 for (button_text = first_button_text;
465 button_text = va_arg (button_args, const gchar *))
468 response_id = va_arg (button_args, gint);
470 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
473 va_end (button_args);
475 g_signal_connect (message_dialog, "response", response_callback, user_data);
477 gtk_widget_show (message_dialog);
481 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
485 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
486 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
488 gtk_widget_destroy (GTK_WIDGET (message_dialog));
490 if (response_id == GTK_RESPONSE_YES)
492 empathy_account_widget_discard_pending_changes (
493 priv->setting_widget_object);
494 accounts_dialog_setup_ui_to_add_account (dialog);
499 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
500 EmpathyAccountsDialog *dialog)
502 TpAccount *account = NULL;
504 if (accounts_dialog_has_pending_change (dialog, &account))
506 gchar *question_dialog_primary_text = g_strdup_printf (
507 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
508 tp_account_get_display_name (account));
510 accounts_dialog_show_question_dialog (dialog,
511 question_dialog_primary_text,
512 _("You are about to create a new account, which will discard\n"
513 "your changes. Are you sure you want to proceed?"),
514 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
516 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
517 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
519 g_free (question_dialog_primary_text);
523 accounts_dialog_setup_ui_to_add_account (dialog);
528 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
529 EmpathyAccountSettings *settings)
531 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
533 if (priv->settings_ready != NULL)
535 g_signal_handler_disconnect (priv->settings_ready,
536 priv->settings_ready_id);
537 priv->settings_ready = NULL;
538 priv->settings_ready_id = 0;
545 GtkTreeSelection *selection;
547 view = GTK_TREE_VIEW (priv->treeview);
548 model = gtk_tree_view_get_model (view);
549 selection = gtk_tree_view_get_selection (view);
551 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
553 /* We have configured accounts, select the first one if there
554 * is no other account selected already. */
555 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
556 accounts_dialog_model_select_first (dialog);
560 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
562 /* We have no account configured but we have some
563 * profiles installed. The user obviously wants to add
564 * an account. Click on the Add button for him. */
565 accounts_dialog_button_add_clicked_cb (priv->button_add,
570 /* No account and no profile, warn the user */
571 gtk_widget_hide (priv->vbox_details);
572 gtk_widget_hide (priv->frame_new_account);
573 gtk_widget_show (priv->frame_no_protocol);
574 gtk_widget_set_sensitive (priv->button_add, FALSE);
578 /* We have an account selected, destroy old settings and create a new
579 * one for the account selected */
580 gtk_widget_hide (priv->frame_new_account);
581 gtk_widget_hide (priv->frame_no_protocol);
582 gtk_widget_show (priv->vbox_details);
583 gtk_widget_set_sensitive (priv->button_add, TRUE);
585 if (priv->settings_widget)
587 gtk_widget_destroy (priv->settings_widget);
588 priv->settings_widget = NULL;
591 if (empathy_account_settings_is_ready (settings))
593 account_dialog_create_settings_widget (dialog, settings);
597 priv->settings_ready = settings;
598 priv->settings_ready_id =
599 g_signal_connect (settings, "notify::ready",
600 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
606 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
607 GtkCellEditable *editable,
609 EmpathyAccountsDialog *dialog)
611 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
613 if (priv->connecting_id)
614 g_source_remove (priv->connecting_id);
616 DEBUG ("Editing account name started; stopping flashing");
620 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
621 GtkCellRenderer *cell,
624 EmpathyAccountsDialog *dialog)
626 EmpathyAccountSettings *settings;
629 TpConnectionStatus status;
630 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
632 gtk_tree_model_get (model, iter,
634 COL_ACCOUNT_SETTINGS_POINTER, &settings,
637 icon_name = empathy_account_settings_get_icon_name (settings);
638 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
642 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
643 (status == TP_CONNECTION_STATUS_CONNECTING &&
644 !priv->connecting_show))
646 GdkPixbuf *modded_pixbuf;
648 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
651 gdk_pixbuf_get_width (pixbuf),
652 gdk_pixbuf_get_height (pixbuf));
654 gdk_pixbuf_saturate_and_pixelate (pixbuf,
658 g_object_unref (pixbuf);
659 pixbuf = modded_pixbuf;
668 g_object_unref (settings);
671 g_object_unref (pixbuf);
675 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
680 gtk_tree_model_row_changed (model, path, iter);
686 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
690 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
692 priv->connecting_show = !priv->connecting_show;
694 view = GTK_TREE_VIEW (priv->treeview);
695 model = gtk_tree_view_get_model (view);
697 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
703 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
706 EmpathyAccountsDialog *dialog)
708 EmpathyAccountSettings *settings;
710 GtkTreePath *treepath;
712 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
715 empathy_account_manager_get_accounts_connected (&connecting);
719 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
720 (GSourceFunc) accounts_dialog_flash_connecting_cb,
724 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
725 treepath = gtk_tree_path_new_from_string (path);
726 gtk_tree_model_get_iter (model, &iter, treepath);
727 gtk_tree_model_get (model, &iter,
728 COL_ACCOUNT_SETTINGS_POINTER, &settings,
730 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
733 gtk_tree_path_free (treepath);
735 empathy_account_settings_set_display_name_async (settings, new_text,
737 g_object_set (settings, "display-name-overridden", TRUE, NULL);
738 g_object_unref (settings);
742 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
749 GtkTreeSelection *selection;
750 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
751 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
753 if (response_id == GTK_RESPONSE_YES)
755 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
757 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
760 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
764 tp_account_remove_async (account, NULL, NULL);
765 g_object_unref (account);
769 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
770 accounts_dialog_model_select_first (account_dialog);
773 gtk_widget_destroy (GTK_WIDGET (message_dialog));
777 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
778 const gchar *path_string,
779 EmpathyAccountsDialog *dialog)
784 gchar *question_dialog_primary_text;
785 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
787 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
789 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
792 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
794 if (account == NULL || !tp_account_is_valid (account))
796 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
797 accounts_dialog_model_select_first (dialog);
801 question_dialog_primary_text = g_strdup_printf (
803 _("You are about to remove your %s account!\n"
804 "Are you sure you want to proceed?"),
806 /* Translators: this is used only when built on a moblin platform */
807 _("Do you want to remove %s from your computer?"),
808 #endif /* HAVE_MOBLIN */
809 tp_account_get_display_name (account));
811 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
813 _("Any associated conversations and chat rooms will NOT be "
814 "removed if you decide to proceed.\n"
816 "Should you decide to add the account back at a later time, "
817 "they will still be available."),
819 /* Translators: this is used only when built on a moblin platform */
820 _("This will not remove your account on the server."),
821 #endif /* HAVE_MOBLIN */
822 G_CALLBACK (accounts_dialog_delete_account_response_cb),
824 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
825 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
827 g_free (question_dialog_primary_text);
831 g_object_unref (account);
837 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
840 GtkTreeViewColumn *column;
841 GtkCellRenderer *cell;
842 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
844 view = GTK_TREE_VIEW (priv->treeview);
845 gtk_tree_view_set_headers_visible (view, FALSE);
848 column = gtk_tree_view_column_new ();
849 gtk_tree_view_column_set_expand (column, TRUE);
850 gtk_tree_view_append_column (view, column);
853 cell = gtk_cell_renderer_pixbuf_new ();
854 gtk_tree_view_column_pack_start (column, cell, FALSE);
855 gtk_tree_view_column_set_cell_data_func (column, cell,
856 (GtkTreeCellDataFunc)
857 accounts_dialog_model_pixbuf_data_func,
861 g_object_set (cell, "ypad", 4, NULL);
865 cell = gtk_cell_renderer_text_new ();
867 "ellipsize", PANGO_ELLIPSIZE_END,
871 gtk_tree_view_column_pack_start (column, cell, TRUE);
872 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
873 g_signal_connect (cell, "edited",
874 G_CALLBACK (accounts_dialog_name_edited_cb),
876 g_signal_connect (cell, "editing-started",
877 G_CALLBACK (accounts_dialog_name_editing_started_cb),
881 cell = empathy_cell_renderer_activatable_new ();
882 gtk_tree_view_column_pack_start (column, cell, FALSE);
884 "icon-name", GTK_STOCK_DELETE,
886 "show-on-select", TRUE,
890 g_signal_connect (cell, "path-activated",
891 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
895 static EmpathyAccountSettings *
896 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
900 GtkTreeSelection *selection;
902 EmpathyAccountSettings *settings;
903 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
905 view = GTK_TREE_VIEW (priv->treeview);
906 selection = gtk_tree_view_get_selection (view);
908 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
911 gtk_tree_model_get (model, &iter,
912 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
918 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
919 EmpathyAccountsDialog *dialog)
921 EmpathyAccountSettings *settings;
924 gboolean is_selection;
926 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
928 settings = accounts_dialog_model_get_selected_settings (dialog);
929 accounts_dialog_update_settings (dialog, settings);
931 if (settings != NULL)
932 g_object_unref (settings);
936 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
940 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
941 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
943 gtk_widget_destroy (GTK_WIDGET (message_dialog));
945 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
947 /* The user wants to lose unsaved changes to the currently selected
948 * account and select another account. We discard the changes and
949 * select the other account. */
951 GtkTreeSelection *selection;
953 priv->force_change_row = TRUE;
954 empathy_account_widget_discard_pending_changes (
955 priv->setting_widget_object);
957 path = gtk_tree_row_reference_get_path (priv->destination_row);
958 selection = gtk_tree_view_get_selection (
959 GTK_TREE_VIEW (priv->treeview));
963 /* This will trigger a call to
964 * accounts_dialog_account_selection_change() */
965 gtk_tree_selection_select_path (selection, path);
966 gtk_tree_path_free (path);
969 gtk_tree_row_reference_free (priv->destination_row);
973 priv->force_change_row = FALSE;
978 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
981 gboolean path_currently_selected,
984 TpAccount *account = NULL;
985 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
986 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
988 if (priv->force_change_row)
990 /* We came back here because the user wants to discard changes to his
991 * modified account. The changes have already been discarded so we
992 * just change the selected row. */
993 priv->force_change_row = FALSE;
997 if (accounts_dialog_has_pending_change (dialog, &account))
999 /* The currently selected account has some unsaved changes. We ask
1000 * the user if he really wants to lose his changes and select another
1002 gchar *question_dialog_primary_text;
1003 priv->destination_row = gtk_tree_row_reference_new (model, path);
1005 question_dialog_primary_text = g_strdup_printf (
1006 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1007 tp_account_get_display_name (account));
1009 accounts_dialog_show_question_dialog (dialog,
1010 question_dialog_primary_text,
1011 _("You are about to select another account, which will discard\n"
1012 "your changes. Are you sure you want to proceed?"),
1013 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1015 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1016 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1018 g_free (question_dialog_primary_text);
1029 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1031 GtkListStore *store;
1032 GtkTreeSelection *selection;
1033 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1035 store = gtk_list_store_new (COL_COUNT,
1036 G_TYPE_STRING, /* name */
1037 G_TYPE_UINT, /* status */
1038 TP_TYPE_ACCOUNT, /* account */
1039 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1041 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1042 GTK_TREE_MODEL (store));
1044 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1045 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1046 gtk_tree_selection_set_select_function (selection,
1047 accounts_dialog_account_selection_change, dialog, NULL);
1049 g_signal_connect (selection, "changed",
1050 G_CALLBACK (accounts_dialog_model_selection_changed),
1053 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1054 COL_NAME, GTK_SORT_ASCENDING);
1056 accounts_dialog_model_add_columns (dialog);
1058 g_object_unref (store);
1062 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1063 EmpathyAccountSettings *settings,
1067 GtkTreeSelection *selection;
1068 GtkTreeModel *model;
1070 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1072 /* Update the status in the model */
1073 view = GTK_TREE_VIEW (priv->treeview);
1074 selection = gtk_tree_view_get_selection (view);
1075 model = gtk_tree_view_get_model (view);
1077 for (ok = gtk_tree_model_get_iter_first (model, iter);
1079 ok = gtk_tree_model_iter_next (model, iter))
1081 EmpathyAccountSettings *this_settings;
1084 gtk_tree_model_get (model, iter,
1085 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1088 equal = (this_settings == settings);
1089 g_object_unref (this_settings);
1099 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1104 GtkTreeSelection *selection;
1105 GtkTreeModel *model;
1107 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1109 /* Update the status in the model */
1110 view = GTK_TREE_VIEW (priv->treeview);
1111 selection = gtk_tree_view_get_selection (view);
1112 model = gtk_tree_view_get_model (view);
1114 for (ok = gtk_tree_model_get_iter_first (model, iter);
1116 ok = gtk_tree_model_iter_next (model, iter))
1118 EmpathyAccountSettings *settings;
1121 gtk_tree_model_get (model, iter,
1122 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1125 equal = empathy_account_settings_has_account (settings, account);
1126 g_object_unref (settings);
1136 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1137 EmpathyAccountSettings *settings)
1139 GtkTreeSelection *selection;
1141 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1143 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1144 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1145 gtk_tree_selection_select_iter (selection, &iter);
1148 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1149 EmpathyAccountSettings *settings)
1151 GtkTreeModel *model;
1154 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1156 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1157 name = empathy_account_settings_get_display_name (settings);
1159 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1161 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1163 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1164 COL_ACCOUNT_SETTINGS_POINTER, settings,
1169 accounts_dialog_connection_changed_cb (TpAccount *account,
1173 gchar *dbus_error_name,
1174 GHashTable *details,
1175 EmpathyAccountsDialog *dialog)
1177 GtkTreeModel *model;
1180 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1182 /* Update the status in the model */
1183 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1185 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1189 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1190 COL_STATUS, current,
1193 path = gtk_tree_model_get_path (model, &iter);
1194 gtk_tree_model_row_changed (model, path, &iter);
1195 gtk_tree_path_free (path);
1198 empathy_account_manager_get_accounts_connected (&found);
1200 if (!found && priv->connecting_id)
1202 g_source_remove (priv->connecting_id);
1203 priv->connecting_id = 0;
1206 if (found && !priv->connecting_id)
1207 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1208 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1213 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1217 const gchar *display_name;
1219 GtkTreeModel *model;
1220 EmpathyAccountSettings *settings;
1221 TpAccount *selected_account;
1222 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1223 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1225 display_name = tp_account_get_display_name (account);
1226 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1227 settings = accounts_dialog_model_get_selected_settings (dialog);
1228 if (settings == NULL)
1231 selected_account = empathy_account_settings_get_account (settings);
1233 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1235 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1236 COL_NAME, display_name,
1240 if (selected_account == account)
1241 accounts_dialog_update_name_label (dialog, display_name);
1243 g_object_unref (settings);
1247 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1250 EmpathyAccountSettings *settings;
1251 GtkTreeModel *model;
1253 TpConnectionStatus status;
1256 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1258 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1259 status = tp_account_get_connection_status (account, NULL);
1260 name = tp_account_get_display_name (account);
1261 enabled = tp_account_is_enabled (account);
1263 settings = empathy_account_settings_new_for_account (account);
1265 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1266 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1268 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1271 COL_ACCOUNT_POINTER, account,
1272 COL_ACCOUNT_SETTINGS_POINTER, settings,
1275 accounts_dialog_connection_changed_cb (account,
1278 TP_CONNECTION_STATUS_DISCONNECTED,
1283 empathy_signal_connect_weak (account, "notify::display-name",
1284 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1287 g_object_unref (settings);
1291 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1294 EmpathyAccountsDialog *dialog)
1296 accounts_dialog_add_account (dialog, account);
1300 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1302 EmpathyAccountsDialog *dialog)
1305 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1307 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1309 gtk_list_store_remove (GTK_LIST_STORE (
1310 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1315 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1319 GtkTreeModel *model;
1320 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1322 /* Update the status in the model */
1323 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1325 DEBUG ("Account %s is now %s",
1326 tp_account_get_display_name (account),
1327 enabled ? "enabled" : "disabled");
1331 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1333 EmpathyAccountsDialog *dialog)
1335 enable_or_disable_account (dialog, account, FALSE);
1339 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1341 EmpathyAccountsDialog *dialog)
1343 enable_or_disable_account (dialog, account, TRUE);
1347 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1348 EmpathyAccountsDialog *dialog)
1350 EmpathyAccountSettings *settings;
1352 const gchar *display_name;
1353 TpConnectionManager *cm;
1354 TpConnectionManagerProtocol *proto;
1355 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1358 cm = empathy_protocol_chooser_dup_selected (
1359 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1361 display_name = empathy_protocol_name_to_display_name (
1362 is_gtalk ? "gtalk" : proto->name);
1364 if (display_name == NULL)
1365 display_name = proto->name;
1367 /* Create account */
1368 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1371 str = g_strdup_printf (_("New %s account"), display_name);
1372 settings = empathy_account_settings_new (cm->name, proto->name, str);
1377 if (tp_connection_manager_protocol_can_register (proto))
1381 active = gtk_toggle_button_get_active
1382 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1384 empathy_account_settings_set_boolean (settings, "register", TRUE);
1389 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1392 accounts_dialog_add (dialog, settings);
1393 accounts_dialog_model_set_selected (dialog, settings);
1395 g_object_unref (settings);
1396 g_object_unref (cm);
1400 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1401 EmpathyAccountsDialog *dialog)
1403 EmpathyAccountSettings *settings;
1405 settings = accounts_dialog_model_get_selected_settings (dialog);
1406 accounts_dialog_update_settings (dialog, settings);
1409 g_object_unref (settings);
1413 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1414 EmpathyAccountsDialog *dialog)
1416 empathy_url_show (button, "ghelp:empathy?accounts-window");
1420 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1421 EmpathyAccountsDialog *dialog)
1423 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1424 GtkWidget *import_dialog;
1426 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1428 gtk_widget_show (import_dialog);
1432 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1436 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1438 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1440 if (response_id == GTK_RESPONSE_YES)
1441 gtk_widget_destroy (account_dialog);
1445 accounts_dialog_response_cb (GtkWidget *widget,
1447 EmpathyAccountsDialog *dialog)
1449 TpAccount *account = NULL;
1451 if (accounts_dialog_has_pending_change (dialog, &account))
1453 gchar *question_dialog_primary_text;
1454 question_dialog_primary_text = g_strdup_printf (
1455 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1456 tp_account_get_display_name (account));
1458 accounts_dialog_show_question_dialog (dialog,
1459 question_dialog_primary_text,
1460 _("You are about to close the window, which will discard\n"
1461 "your changes. Are you sure you want to proceed?"),
1462 G_CALLBACK (accounts_dialog_close_response_cb),
1464 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1465 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1467 g_free (question_dialog_primary_text);
1469 else if (response == GTK_RESPONSE_CLOSE ||
1470 response == GTK_RESPONSE_DELETE_EVENT)
1471 gtk_widget_destroy (widget);
1475 accounts_dialog_delete_event_cb (GtkWidget *widget,
1477 EmpathyAccountsDialog *dialog)
1479 /* we maunally handle responses to delete events */
1484 accounts_dialog_destroy_cb (GtkObject *obj,
1485 EmpathyAccountsDialog *dialog)
1489 g_object_unref (dialog);
1493 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1496 GtkTreeSelection *selection;
1498 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1500 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1501 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1502 gtk_tree_selection_select_iter (selection, &iter);
1506 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1508 EmpathyAccountsDialog *dialog)
1510 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1512 if (empathy_connection_managers_is_ready (cms))
1514 accounts_dialog_update_settings (dialog, NULL);
1516 if (priv->initial_selection != NULL)
1518 accounts_dialog_set_selected_account
1519 (dialog, priv->initial_selection);
1520 g_object_unref (priv->initial_selection);
1521 priv->initial_selection = NULL;
1527 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1529 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1530 GList *accounts, *l;
1532 g_signal_connect (priv->account_manager, "account-validity-changed",
1533 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1535 g_signal_connect (priv->account_manager, "account-removed",
1536 G_CALLBACK (accounts_dialog_account_removed_cb),
1538 g_signal_connect (priv->account_manager, "account-enabled",
1539 G_CALLBACK (accounts_dialog_account_enabled_cb),
1541 g_signal_connect (priv->account_manager, "account-disabled",
1542 G_CALLBACK (accounts_dialog_account_disabled_cb),
1545 /* Add existing accounts */
1546 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1547 for (l = accounts; l; l = l->next)
1549 accounts_dialog_add_account (dialog, l->data);
1551 empathy_signal_connect_weak (l->data, "status-changed",
1552 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1554 g_list_free (accounts);
1556 priv->cms = empathy_connection_managers_dup_singleton ();
1557 if (!empathy_connection_managers_is_ready (priv->cms))
1558 g_signal_connect (priv->cms, "notify::ready",
1559 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1561 accounts_dialog_model_select_first (dialog);
1565 accounts_dialog_manager_ready_cb (GObject *source_object,
1566 GAsyncResult *result,
1569 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1570 GError *error = NULL;
1572 if (!tp_account_manager_prepare_finish (manager, result, &error))
1574 DEBUG ("Failed to prepare account manager: %s", error->message);
1575 g_error_free (error);
1579 accounts_dialog_accounts_setup (user_data);
1583 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1587 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1589 GtkWidget *action_area;
1592 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1594 gui = empathy_builder_get_file (filename,
1595 "accounts_dialog", &priv->window,
1596 "vbox_details", &priv->vbox_details,
1597 "frame_no_protocol", &priv->frame_no_protocol,
1598 "alignment_settings", &priv->alignment_settings,
1599 "treeview", &priv->treeview,
1600 "frame_new_account", &priv->frame_new_account,
1601 "hbox_type", &priv->hbox_type,
1602 "button_create", &priv->button_create,
1603 "button_back", &priv->button_back,
1604 "radiobutton_reuse", &priv->radiobutton_reuse,
1605 "radiobutton_register", &priv->radiobutton_register,
1606 "image_type", &priv->image_type,
1607 "label_name", &priv->label_name,
1608 "button_add", &priv->button_add,
1609 "button_import", &priv->button_import,
1613 empathy_builder_connect (gui, dialog,
1614 "accounts_dialog", "response", accounts_dialog_response_cb,
1615 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1616 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1617 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1618 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1619 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1620 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1621 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1624 g_object_unref (gui);
1627 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1628 gtk_widget_hide (action_area);
1630 /* Translators: this is used only when built on a moblin platform */
1631 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1632 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1635 priv->combobox_protocol = empathy_protocol_chooser_new ();
1636 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1637 priv->combobox_protocol,
1639 gtk_widget_show (priv->combobox_protocol);
1640 g_signal_connect (priv->combobox_protocol, "changed",
1641 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1644 if (priv->parent_window)
1645 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1646 priv->parent_window);
1650 do_dispose (GObject *obj)
1652 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1653 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1655 /* Disconnect signals */
1656 g_signal_handlers_disconnect_by_func (priv->account_manager,
1657 accounts_dialog_account_validity_changed_cb,
1659 g_signal_handlers_disconnect_by_func (priv->account_manager,
1660 accounts_dialog_account_removed_cb,
1662 g_signal_handlers_disconnect_by_func (priv->account_manager,
1663 accounts_dialog_account_enabled_cb,
1665 g_signal_handlers_disconnect_by_func (priv->account_manager,
1666 accounts_dialog_account_disabled_cb,
1668 g_signal_handlers_disconnect_by_func (priv->account_manager,
1669 accounts_dialog_manager_ready_cb,
1672 if (priv->connecting_id)
1673 g_source_remove (priv->connecting_id);
1675 if (priv->account_manager != NULL)
1677 g_object_unref (priv->account_manager);
1678 priv->account_manager = NULL;
1681 if (priv->cms != NULL)
1683 g_object_unref (priv->cms);
1687 if (priv->initial_selection != NULL)
1688 g_object_unref (priv->initial_selection);
1689 priv->initial_selection = NULL;
1691 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1695 do_constructor (GType type,
1697 GObjectConstructParam *props)
1701 if (dialog_singleton)
1703 retval = G_OBJECT (dialog_singleton);
1704 g_object_ref (retval);
1709 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1710 (type, n_props, props);
1712 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1713 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1714 /* We add an extra reference that we'll release when the dialog is
1715 * destroyed (accounts_dialog_destroy_cb) */
1716 g_object_ref (retval);
1723 do_get_property (GObject *object,
1728 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1730 switch (property_id)
1733 g_value_set_object (value, priv->parent_window);
1736 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1741 do_set_property (GObject *object,
1743 const GValue *value,
1746 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1748 switch (property_id)
1751 priv->parent_window = g_value_get_object (value);
1754 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1759 do_constructed (GObject *object)
1761 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1762 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1763 gboolean import_asked;
1765 accounts_dialog_build_ui (dialog);
1766 accounts_dialog_model_setup (dialog);
1768 /* Set up signalling */
1769 priv->account_manager = tp_account_manager_dup ();
1771 tp_account_manager_prepare_async (priv->account_manager, NULL,
1772 accounts_dialog_manager_ready_cb, dialog);
1774 empathy_conf_get_bool (empathy_conf_get (),
1775 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1777 if (empathy_import_accounts_to_import ())
1779 gtk_widget_show (priv->button_import);
1783 GtkWidget *import_dialog;
1785 empathy_conf_set_bool (empathy_conf_get (),
1786 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1787 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1789 gtk_widget_show (import_dialog);
1795 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1797 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1798 GParamSpec *param_spec;
1800 oclass->constructor = do_constructor;
1801 oclass->dispose = do_dispose;
1802 oclass->constructed = do_constructed;
1803 oclass->set_property = do_set_property;
1804 oclass->get_property = do_get_property;
1806 param_spec = g_param_spec_object ("parent",
1807 "parent", "The parent window",
1809 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1810 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1812 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1816 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1818 EmpathyAccountsDialogPriv *priv;
1820 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1821 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1822 EmpathyAccountsDialogPriv);
1823 dialog->priv = priv;
1826 /* public methods */
1829 empathy_accounts_dialog_show (GtkWindow *parent,
1830 TpAccount *selected_account)
1832 EmpathyAccountsDialog *dialog;
1833 EmpathyAccountsDialogPriv *priv;
1835 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1836 "parent", parent, NULL);
1838 priv = GET_PRIV (dialog);
1840 if (selected_account)
1842 if (empathy_connection_managers_is_ready (priv->cms))
1843 accounts_dialog_set_selected_account (dialog, selected_account);
1845 /* save the selection to set it later when the cms
1848 priv->initial_selection = g_object_ref (selected_account);
1851 gtk_window_present (GTK_WINDOW (priv->window));
1852 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1853 * destroyed so we can release the ref returned by the constructor now. */
1854 g_object_unref (dialog);
1856 return priv->window;