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;
78 GtkWidget *alignment_infobar;
80 GtkWidget *vbox_details;
82 GtkWidget *label_status;
83 GtkWidget *frame_no_protocol;
87 GtkWidget *button_add;
88 GtkWidget *button_import;
90 GtkWidget *frame_new_account;
91 GtkWidget *combobox_protocol;
93 GtkWidget *button_create;
94 GtkWidget *button_back;
95 GtkWidget *radiobutton_reuse;
96 GtkWidget *radiobutton_register;
98 GtkWidget *image_type;
99 GtkWidget *label_name;
100 GtkWidget *label_type;
101 GtkWidget *settings_widget;
103 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
104 * his GtkWidget. It is the only reliable source we can query to know if
105 * there are any unsaved changes to the currently selected account. We can't
106 * look at the account settings because it does not contain everything that
107 * can be changed using the EmpathyAccountWidget. For instance, it does not
108 * contain the state of the "Enabled" checkbox. */
109 EmpathyAccountWidget *setting_widget_object;
111 gboolean connecting_show;
114 gulong settings_ready_id;
115 EmpathyAccountSettings *settings_ready;
117 TpAccountManager *account_manager;
118 EmpathyConnectionManagers *cms;
120 GtkWindow *parent_window;
121 TpAccount *initial_selection;
123 /* Those are needed when changing the selected row. When a user selects
124 * another account and there are unsaved changes on the currently selected
125 * one, a confirmation message box is presented to him. Since his answer
126 * is retrieved asynchronously, we keep some information as member of the
127 * EmpathyAccountsDialog object. */
128 gboolean force_change_row;
129 GtkTreeRowReference *destination_row;
132 } EmpathyAccountsDialogPriv;
138 COL_ACCOUNT_SETTINGS_POINTER,
146 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
147 EmpathyAccountsDialog *dialog);
149 static gboolean accounts_dialog_get_settings_iter (
150 EmpathyAccountsDialog *dialog,
151 EmpathyAccountSettings *settings,
154 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
156 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
157 EmpathyAccountSettings *settings);
160 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
161 const gchar *display_name)
164 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
166 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
167 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
173 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
176 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
178 /* don't show the infobar if account is connected */
179 if (status == TP_CONNECTION_STATUS_CONNECTED)
181 gtk_widget_hide (priv->infobar);
187 case TP_CONNECTION_STATUS_CONNECTING:
188 gtk_label_set_text (GTK_LABEL (priv->label_status),
190 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
193 case TP_CONNECTION_STATUS_DISCONNECTED:
194 gtk_label_set_text (GTK_LABEL (priv->label_status),
195 _("Disconnected - REASON"));
196 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
197 GTK_MESSAGE_WARNING);
200 gtk_label_set_text (GTK_LABEL (priv->label_status),
201 _("Unknown Status"));
202 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
203 GTK_MESSAGE_WARNING);
206 gtk_widget_show (priv->label_status);
207 gtk_widget_show (priv->infobar);
211 empathy_account_dialog_widget_cancelled_cb (
212 EmpathyAccountWidget *widget_object,
213 EmpathyAccountsDialog *dialog)
217 GtkTreeSelection *selection;
219 EmpathyAccountSettings *settings;
221 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
223 view = GTK_TREE_VIEW (priv->treeview);
224 selection = gtk_tree_view_get_selection (view);
226 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
229 gtk_tree_model_get (model, &iter,
230 COL_ACCOUNT_SETTINGS_POINTER, &settings,
231 COL_ACCOUNT_POINTER, &account, -1);
233 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
237 /* We were creating an account. We remove the selected row */
238 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
242 /* We were modifying an account. We discard the changes by reloading the
243 * settings and the UI. */
244 accounts_dialog_update_settings (dialog, settings);
245 g_object_unref (account);
248 if (settings != NULL)
249 g_object_unref (settings);
253 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
254 EmpathyAccountsDialog *dialog)
257 EmpathyAccountSettings *settings =
258 accounts_dialog_model_get_selected_settings (dialog);
260 display_name = empathy_account_widget_get_default_display_name (
263 empathy_account_settings_set_display_name_async (settings,
264 display_name, NULL, NULL);
266 g_free (display_name);
268 accounts_dialog_update_settings (dialog, settings);
271 g_object_unref (settings);
275 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
276 EmpathyAccountSettings *settings)
278 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
281 priv->setting_widget_object =
282 empathy_account_widget_new_for_protocol (settings, FALSE);
284 priv->settings_widget =
285 empathy_account_widget_get_widget (priv->setting_widget_object);
287 priv->settings_widget =
288 empathy_account_widget_get_widget (priv->setting_widget_object);
289 g_signal_connect (priv->setting_widget_object, "account-created",
290 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
291 g_signal_connect (priv->setting_widget_object, "cancelled",
292 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
294 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
295 priv->settings_widget);
296 gtk_widget_show (priv->settings_widget);
298 icon_name = empathy_account_settings_get_icon_name (settings);
300 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
302 /* show the default icon; keep this in sync with the default
303 * one in empathy-accounts-dialog.ui.
305 icon_name = GTK_STOCK_CUT;
307 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
308 icon_name, GTK_ICON_SIZE_DIALOG);
309 gtk_widget_set_tooltip_text (priv->image_type,
310 empathy_protocol_name_to_display_name
311 (empathy_account_settings_get_protocol (settings)));
312 gtk_widget_show (priv->image_type);
314 accounts_dialog_update_name_label (dialog,
315 empathy_account_settings_get_display_name (settings));
317 accounts_dialog_update_status_infobar (dialog,
318 tp_account_get_connection_status (
319 empathy_account_settings_get_account (settings), NULL));
323 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
325 EmpathyAccountsDialog *dialog)
327 if (empathy_account_settings_is_ready (settings))
328 account_dialog_create_settings_widget (dialog, settings);
332 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
336 GtkTreeSelection *selection;
338 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
341 view = GTK_TREE_VIEW (priv->treeview);
342 model = gtk_tree_view_get_model (view);
344 if (gtk_tree_model_get_iter_first (model, &iter))
346 selection = gtk_tree_view_get_selection (view);
347 gtk_tree_selection_select_iter (selection, &iter);
351 accounts_dialog_update_settings (dialog, NULL);
356 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
361 GtkTreeSelection *selection;
362 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
364 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
366 if (gtk_tree_selection_get_selected (selection, &model, &iter))
367 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
369 return priv->setting_widget_object != NULL
370 && empathy_account_widget_contains_pending_changes (
371 priv->setting_widget_object);
375 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
376 EmpathyAccountsDialog *dialog)
378 TpConnectionManager *cm;
379 TpConnectionManagerProtocol *proto;
381 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
383 cm = empathy_protocol_chooser_dup_selected (
384 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
396 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
398 gtk_widget_show (priv->radiobutton_register);
399 gtk_widget_show (priv->radiobutton_reuse);
403 gtk_widget_hide (priv->radiobutton_register);
404 gtk_widget_hide (priv->radiobutton_reuse);
407 gtk_widget_hide (priv->radiobutton_register);
408 gtk_widget_hide (priv->radiobutton_reuse);
415 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
419 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
421 view = GTK_TREE_VIEW (priv->treeview);
422 model = gtk_tree_view_get_model (view);
424 gtk_widget_set_sensitive (priv->button_add, FALSE);
425 gtk_widget_hide (priv->vbox_details);
426 gtk_widget_hide (priv->frame_no_protocol);
427 gtk_widget_show (priv->frame_new_account);
429 /* If we have no account, no need of a back button */
430 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
431 gtk_widget_show (priv->button_back);
433 gtk_widget_hide (priv->button_back);
435 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
436 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
438 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
439 gtk_widget_grab_focus (priv->combobox_protocol);
443 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
444 const gchar *primary_text,
445 const gchar *secondary_text,
446 GCallback response_callback,
448 const gchar *first_button_text,
452 GtkWidget *message_dialog;
453 const gchar *button_text;
454 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
456 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
457 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
458 GTK_MESSAGE_QUESTION,
462 gtk_message_dialog_format_secondary_text (
463 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
465 va_start (button_args, first_button_text);
466 for (button_text = first_button_text;
468 button_text = va_arg (button_args, const gchar *))
471 response_id = va_arg (button_args, gint);
473 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
476 va_end (button_args);
478 g_signal_connect (message_dialog, "response", response_callback, user_data);
480 gtk_widget_show (message_dialog);
484 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
488 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
489 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
491 gtk_widget_destroy (GTK_WIDGET (message_dialog));
493 if (response_id == GTK_RESPONSE_YES)
495 empathy_account_widget_discard_pending_changes (
496 priv->setting_widget_object);
497 accounts_dialog_setup_ui_to_add_account (dialog);
502 get_dialog_primary_text (TpAccount *account)
506 /* Existing account */
507 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
508 tp_account_get_display_name (account));
512 /* Newly created account */
513 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
518 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
519 EmpathyAccountsDialog *dialog)
521 TpAccount *account = NULL;
523 if (accounts_dialog_has_pending_change (dialog, &account))
525 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
527 accounts_dialog_show_question_dialog (dialog,
528 question_dialog_primary_text,
529 _("You are about to create a new account, which will discard\n"
530 "your changes. Are you sure you want to proceed?"),
531 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
533 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
534 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
536 g_free (question_dialog_primary_text);
540 accounts_dialog_setup_ui_to_add_account (dialog);
545 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
546 EmpathyAccountSettings *settings)
548 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
550 if (priv->settings_ready != NULL)
552 g_signal_handler_disconnect (priv->settings_ready,
553 priv->settings_ready_id);
554 priv->settings_ready = NULL;
555 priv->settings_ready_id = 0;
562 GtkTreeSelection *selection;
564 view = GTK_TREE_VIEW (priv->treeview);
565 model = gtk_tree_view_get_model (view);
566 selection = gtk_tree_view_get_selection (view);
568 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
570 /* We have configured accounts, select the first one if there
571 * is no other account selected already. */
572 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
573 accounts_dialog_model_select_first (dialog);
577 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
579 /* We have no account configured but we have some
580 * profiles installed. The user obviously wants to add
581 * an account. Click on the Add button for him. */
582 accounts_dialog_button_add_clicked_cb (priv->button_add,
587 /* No account and no profile, warn the user */
588 gtk_widget_hide (priv->vbox_details);
589 gtk_widget_hide (priv->frame_new_account);
590 gtk_widget_show (priv->frame_no_protocol);
591 gtk_widget_set_sensitive (priv->button_add, FALSE);
595 /* We have an account selected, destroy old settings and create a new
596 * one for the account selected */
597 gtk_widget_hide (priv->frame_new_account);
598 gtk_widget_hide (priv->frame_no_protocol);
599 gtk_widget_show (priv->vbox_details);
600 gtk_widget_set_sensitive (priv->button_add, TRUE);
602 if (priv->settings_widget)
604 gtk_widget_destroy (priv->settings_widget);
605 priv->settings_widget = NULL;
608 if (empathy_account_settings_is_ready (settings))
610 account_dialog_create_settings_widget (dialog, settings);
614 priv->settings_ready = settings;
615 priv->settings_ready_id =
616 g_signal_connect (settings, "notify::ready",
617 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
623 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
624 GtkCellEditable *editable,
626 EmpathyAccountsDialog *dialog)
628 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
630 if (priv->connecting_id)
631 g_source_remove (priv->connecting_id);
633 DEBUG ("Editing account name started; stopping flashing");
637 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
638 GtkCellRenderer *cell,
641 EmpathyAccountsDialog *dialog)
643 EmpathyAccountSettings *settings;
646 TpConnectionStatus status;
647 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
649 gtk_tree_model_get (model, iter,
651 COL_ACCOUNT_SETTINGS_POINTER, &settings,
654 icon_name = empathy_account_settings_get_icon_name (settings);
655 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
659 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
660 (status == TP_CONNECTION_STATUS_CONNECTING &&
661 !priv->connecting_show))
663 GdkPixbuf *modded_pixbuf;
665 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
668 gdk_pixbuf_get_width (pixbuf),
669 gdk_pixbuf_get_height (pixbuf));
671 gdk_pixbuf_saturate_and_pixelate (pixbuf,
675 g_object_unref (pixbuf);
676 pixbuf = modded_pixbuf;
685 g_object_unref (settings);
688 g_object_unref (pixbuf);
692 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
697 gtk_tree_model_row_changed (model, path, iter);
703 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
707 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
709 priv->connecting_show = !priv->connecting_show;
711 view = GTK_TREE_VIEW (priv->treeview);
712 model = gtk_tree_view_get_model (view);
714 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
720 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
723 EmpathyAccountsDialog *dialog)
725 EmpathyAccountSettings *settings;
727 GtkTreePath *treepath;
729 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
732 empathy_account_manager_get_accounts_connected (&connecting);
736 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
737 (GSourceFunc) accounts_dialog_flash_connecting_cb,
741 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
742 treepath = gtk_tree_path_new_from_string (path);
743 gtk_tree_model_get_iter (model, &iter, treepath);
744 gtk_tree_model_get (model, &iter,
745 COL_ACCOUNT_SETTINGS_POINTER, &settings,
747 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
750 gtk_tree_path_free (treepath);
752 empathy_account_settings_set_display_name_async (settings, new_text,
754 g_object_set (settings, "display-name-overridden", TRUE, NULL);
755 g_object_unref (settings);
759 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
766 GtkTreeSelection *selection;
767 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
768 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
770 if (response_id == GTK_RESPONSE_YES)
772 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
774 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
777 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
781 tp_account_remove_async (account, NULL, NULL);
782 g_object_unref (account);
786 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
787 accounts_dialog_model_select_first (account_dialog);
790 gtk_widget_destroy (GTK_WIDGET (message_dialog));
794 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
795 const gchar *path_string,
796 EmpathyAccountsDialog *dialog)
801 gchar *question_dialog_primary_text;
802 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
804 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
806 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
809 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
811 if (account == NULL || !tp_account_is_valid (account))
813 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
814 accounts_dialog_model_select_first (dialog);
818 question_dialog_primary_text = g_strdup_printf (
819 _("Do you want to remove %s from your computer?"),
820 tp_account_get_display_name (account));
822 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
823 _("This will not remove your account on the server."),
824 G_CALLBACK (accounts_dialog_delete_account_response_cb),
826 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
827 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
829 g_free (question_dialog_primary_text);
833 g_object_unref (account);
839 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
842 GtkTreeViewColumn *column;
843 GtkCellRenderer *cell;
844 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
846 view = GTK_TREE_VIEW (priv->treeview);
847 gtk_tree_view_set_headers_visible (view, FALSE);
850 column = gtk_tree_view_column_new ();
851 gtk_tree_view_column_set_expand (column, TRUE);
852 gtk_tree_view_append_column (view, column);
855 cell = gtk_cell_renderer_pixbuf_new ();
856 gtk_tree_view_column_pack_start (column, cell, FALSE);
857 gtk_tree_view_column_set_cell_data_func (column, cell,
858 (GtkTreeCellDataFunc)
859 accounts_dialog_model_pixbuf_data_func,
864 cell = gtk_cell_renderer_text_new ();
866 "ellipsize", PANGO_ELLIPSIZE_END,
870 gtk_tree_view_column_pack_start (column, cell, TRUE);
871 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
872 g_signal_connect (cell, "edited",
873 G_CALLBACK (accounts_dialog_name_edited_cb),
875 g_signal_connect (cell, "editing-started",
876 G_CALLBACK (accounts_dialog_name_editing_started_cb),
878 g_object_set (cell, "ypad", 4, NULL);
881 cell = empathy_cell_renderer_activatable_new ();
882 gtk_tree_view_column_pack_start (column, cell, FALSE);
884 "icon-name", GTK_STOCK_DELETE,
885 "show-on-select", TRUE,
888 g_signal_connect (cell, "path-activated",
889 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
893 static EmpathyAccountSettings *
894 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
898 GtkTreeSelection *selection;
900 EmpathyAccountSettings *settings;
901 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
903 view = GTK_TREE_VIEW (priv->treeview);
904 selection = gtk_tree_view_get_selection (view);
906 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
909 gtk_tree_model_get (model, &iter,
910 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
916 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
917 EmpathyAccountsDialog *dialog)
919 EmpathyAccountSettings *settings;
922 gboolean is_selection;
924 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
926 settings = accounts_dialog_model_get_selected_settings (dialog);
927 accounts_dialog_update_settings (dialog, settings);
929 if (settings != NULL)
930 g_object_unref (settings);
934 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
938 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
939 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
941 gtk_widget_destroy (GTK_WIDGET (message_dialog));
943 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
945 /* The user wants to lose unsaved changes to the currently selected
946 * account and select another account. We discard the changes and
947 * select the other account. */
949 GtkTreeSelection *selection;
951 priv->force_change_row = TRUE;
952 empathy_account_widget_discard_pending_changes (
953 priv->setting_widget_object);
955 path = gtk_tree_row_reference_get_path (priv->destination_row);
956 selection = gtk_tree_view_get_selection (
957 GTK_TREE_VIEW (priv->treeview));
961 /* This will trigger a call to
962 * accounts_dialog_account_selection_change() */
963 gtk_tree_selection_select_path (selection, path);
964 gtk_tree_path_free (path);
967 gtk_tree_row_reference_free (priv->destination_row);
971 priv->force_change_row = FALSE;
976 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
979 gboolean path_currently_selected,
982 TpAccount *account = NULL;
983 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
984 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
986 if (priv->force_change_row)
988 /* We came back here because the user wants to discard changes to his
989 * modified account. The changes have already been discarded so we
990 * just change the selected row. */
991 priv->force_change_row = FALSE;
995 if (accounts_dialog_has_pending_change (dialog, &account))
997 /* The currently selected account has some unsaved changes. We ask
998 * the user if he really wants to lose his changes and select another
1000 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1001 priv->destination_row = gtk_tree_row_reference_new (model, path);
1003 accounts_dialog_show_question_dialog (dialog,
1004 question_dialog_primary_text,
1005 _("You are about to select another account, which will discard\n"
1006 "your changes. Are you sure you want to proceed?"),
1007 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1009 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1010 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1012 g_free (question_dialog_primary_text);
1023 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1025 GtkListStore *store;
1026 GtkTreeSelection *selection;
1027 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1029 store = gtk_list_store_new (COL_COUNT,
1030 G_TYPE_STRING, /* name */
1031 G_TYPE_UINT, /* status */
1032 TP_TYPE_ACCOUNT, /* account */
1033 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1035 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1036 GTK_TREE_MODEL (store));
1038 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1039 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1040 gtk_tree_selection_set_select_function (selection,
1041 accounts_dialog_account_selection_change, dialog, NULL);
1043 g_signal_connect (selection, "changed",
1044 G_CALLBACK (accounts_dialog_model_selection_changed),
1047 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1048 COL_NAME, GTK_SORT_ASCENDING);
1050 accounts_dialog_model_add_columns (dialog);
1052 g_object_unref (store);
1056 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1057 EmpathyAccountSettings *settings,
1061 GtkTreeSelection *selection;
1062 GtkTreeModel *model;
1064 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1066 /* Update the status in the model */
1067 view = GTK_TREE_VIEW (priv->treeview);
1068 selection = gtk_tree_view_get_selection (view);
1069 model = gtk_tree_view_get_model (view);
1071 for (ok = gtk_tree_model_get_iter_first (model, iter);
1073 ok = gtk_tree_model_iter_next (model, iter))
1075 EmpathyAccountSettings *this_settings;
1078 gtk_tree_model_get (model, iter,
1079 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1082 equal = (this_settings == settings);
1083 g_object_unref (this_settings);
1093 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1098 GtkTreeSelection *selection;
1099 GtkTreeModel *model;
1101 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1103 /* Update the status in the model */
1104 view = GTK_TREE_VIEW (priv->treeview);
1105 selection = gtk_tree_view_get_selection (view);
1106 model = gtk_tree_view_get_model (view);
1108 for (ok = gtk_tree_model_get_iter_first (model, iter);
1110 ok = gtk_tree_model_iter_next (model, iter))
1112 EmpathyAccountSettings *settings;
1115 gtk_tree_model_get (model, iter,
1116 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1119 equal = empathy_account_settings_has_account (settings, account);
1120 g_object_unref (settings);
1130 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1131 EmpathyAccountSettings *settings)
1133 GtkTreeSelection *selection;
1135 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1137 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1138 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1139 gtk_tree_selection_select_iter (selection, &iter);
1142 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1143 EmpathyAccountSettings *settings)
1145 GtkTreeModel *model;
1148 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1150 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1151 name = empathy_account_settings_get_display_name (settings);
1153 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1155 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1157 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1158 COL_ACCOUNT_SETTINGS_POINTER, settings,
1163 accounts_dialog_connection_changed_cb (TpAccount *account,
1167 gchar *dbus_error_name,
1168 GHashTable *details,
1169 EmpathyAccountsDialog *dialog)
1171 GtkTreeModel *model;
1174 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1176 /* Update the status-infobar in the details view*/
1177 accounts_dialog_update_status_infobar (dialog, current);
1179 /* Update the status in the model */
1180 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1182 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1186 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1187 COL_STATUS, current,
1190 path = gtk_tree_model_get_path (model, &iter);
1191 gtk_tree_model_row_changed (model, path, &iter);
1192 gtk_tree_path_free (path);
1195 empathy_account_manager_get_accounts_connected (&found);
1197 if (!found && priv->connecting_id)
1199 g_source_remove (priv->connecting_id);
1200 priv->connecting_id = 0;
1203 if (found && !priv->connecting_id)
1204 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1205 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1210 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1214 const gchar *display_name;
1216 GtkTreeModel *model;
1217 EmpathyAccountSettings *settings;
1218 TpAccount *selected_account;
1219 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1220 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1222 display_name = tp_account_get_display_name (account);
1223 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1224 settings = accounts_dialog_model_get_selected_settings (dialog);
1225 if (settings == NULL)
1228 selected_account = empathy_account_settings_get_account (settings);
1230 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1232 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1233 COL_NAME, display_name,
1237 if (selected_account == account)
1238 accounts_dialog_update_name_label (dialog, display_name);
1240 g_object_unref (settings);
1244 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1247 EmpathyAccountSettings *settings;
1248 GtkTreeModel *model;
1250 TpConnectionStatus status;
1253 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1255 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1256 status = tp_account_get_connection_status (account, NULL);
1257 name = tp_account_get_display_name (account);
1258 enabled = tp_account_is_enabled (account);
1260 settings = empathy_account_settings_new_for_account (account);
1262 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1263 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1265 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1268 COL_ACCOUNT_POINTER, account,
1269 COL_ACCOUNT_SETTINGS_POINTER, settings,
1272 accounts_dialog_connection_changed_cb (account,
1275 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1280 empathy_signal_connect_weak (account, "notify::display-name",
1281 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1284 g_object_unref (settings);
1288 account_prepare_cb (GObject *source_object,
1289 GAsyncResult *result,
1292 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1293 TpAccount *account = TP_ACCOUNT (source_object);
1294 GError *error = NULL;
1296 if (!tp_account_prepare_finish (account, result, &error))
1298 DEBUG ("Failed to prepare account: %s", error->message);
1299 g_error_free (error);
1303 accounts_dialog_add_account (dialog, account);
1307 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1310 EmpathyAccountsDialog *dialog)
1312 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1316 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1318 EmpathyAccountsDialog *dialog)
1321 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1323 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1325 gtk_list_store_remove (GTK_LIST_STORE (
1326 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1331 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1335 GtkTreeModel *model;
1336 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1338 /* Update the status in the model */
1339 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1341 DEBUG ("Account %s is now %s",
1342 tp_account_get_display_name (account),
1343 enabled ? "enabled" : "disabled");
1347 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1349 EmpathyAccountsDialog *dialog)
1351 enable_or_disable_account (dialog, account, FALSE);
1355 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1357 EmpathyAccountsDialog *dialog)
1359 enable_or_disable_account (dialog, account, TRUE);
1363 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1364 EmpathyAccountsDialog *dialog)
1366 EmpathyAccountSettings *settings;
1368 const gchar *display_name;
1369 TpConnectionManager *cm;
1370 TpConnectionManagerProtocol *proto;
1371 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1374 cm = empathy_protocol_chooser_dup_selected (
1375 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1377 display_name = empathy_protocol_name_to_display_name (
1378 is_gtalk ? "gtalk" : proto->name);
1380 if (display_name == NULL)
1381 display_name = proto->name;
1383 /* Create account */
1384 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1387 str = g_strdup_printf (_("New %s account"), display_name);
1388 settings = empathy_account_settings_new (cm->name, proto->name, str);
1393 if (tp_connection_manager_protocol_can_register (proto))
1397 active = gtk_toggle_button_get_active
1398 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1400 empathy_account_settings_set_boolean (settings, "register", TRUE);
1405 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1408 accounts_dialog_add (dialog, settings);
1409 accounts_dialog_model_set_selected (dialog, settings);
1411 g_object_unref (settings);
1412 g_object_unref (cm);
1416 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1417 EmpathyAccountsDialog *dialog)
1419 EmpathyAccountSettings *settings;
1421 settings = accounts_dialog_model_get_selected_settings (dialog);
1422 accounts_dialog_update_settings (dialog, settings);
1425 g_object_unref (settings);
1429 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1430 EmpathyAccountsDialog *dialog)
1432 empathy_url_show (button, "ghelp:empathy?accounts-window");
1436 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1437 EmpathyAccountsDialog *dialog)
1439 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1440 GtkWidget *import_dialog;
1442 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1444 gtk_widget_show (import_dialog);
1448 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1452 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1454 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1456 if (response_id == GTK_RESPONSE_YES)
1457 gtk_widget_destroy (account_dialog);
1461 accounts_dialog_response_cb (GtkWidget *widget,
1463 EmpathyAccountsDialog *dialog)
1465 TpAccount *account = NULL;
1467 if (accounts_dialog_has_pending_change (dialog, &account))
1469 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1471 accounts_dialog_show_question_dialog (dialog,
1472 question_dialog_primary_text,
1473 _("You are about to close the window, which will discard\n"
1474 "your changes. Are you sure you want to proceed?"),
1475 G_CALLBACK (accounts_dialog_close_response_cb),
1477 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1478 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1480 g_free (question_dialog_primary_text);
1482 else if (response == GTK_RESPONSE_CLOSE ||
1483 response == GTK_RESPONSE_DELETE_EVENT)
1484 gtk_widget_destroy (widget);
1488 accounts_dialog_delete_event_cb (GtkWidget *widget,
1490 EmpathyAccountsDialog *dialog)
1492 /* we maunally handle responses to delete events */
1497 accounts_dialog_destroy_cb (GtkObject *obj,
1498 EmpathyAccountsDialog *dialog)
1502 g_object_unref (dialog);
1506 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1509 GtkTreeSelection *selection;
1511 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1513 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1514 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1515 gtk_tree_selection_select_iter (selection, &iter);
1519 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1521 EmpathyAccountsDialog *dialog)
1523 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1525 if (empathy_connection_managers_is_ready (cms))
1527 accounts_dialog_update_settings (dialog, NULL);
1529 if (priv->initial_selection != NULL)
1531 accounts_dialog_set_selected_account
1532 (dialog, priv->initial_selection);
1533 g_object_unref (priv->initial_selection);
1534 priv->initial_selection = NULL;
1540 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1542 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1543 GList *accounts, *l;
1545 g_signal_connect (priv->account_manager, "account-validity-changed",
1546 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1548 g_signal_connect (priv->account_manager, "account-removed",
1549 G_CALLBACK (accounts_dialog_account_removed_cb),
1551 g_signal_connect (priv->account_manager, "account-enabled",
1552 G_CALLBACK (accounts_dialog_account_enabled_cb),
1554 g_signal_connect (priv->account_manager, "account-disabled",
1555 G_CALLBACK (accounts_dialog_account_disabled_cb),
1558 /* Add existing accounts */
1559 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1560 for (l = accounts; l; l = l->next)
1562 accounts_dialog_add_account (dialog, l->data);
1564 empathy_signal_connect_weak (l->data, "status-changed",
1565 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1567 g_list_free (accounts);
1569 priv->cms = empathy_connection_managers_dup_singleton ();
1570 if (!empathy_connection_managers_is_ready (priv->cms))
1571 g_signal_connect (priv->cms, "notify::ready",
1572 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1574 accounts_dialog_model_select_first (dialog);
1578 accounts_dialog_manager_ready_cb (GObject *source_object,
1579 GAsyncResult *result,
1582 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1583 GError *error = NULL;
1585 if (!tp_account_manager_prepare_finish (manager, result, &error))
1587 DEBUG ("Failed to prepare account manager: %s", error->message);
1588 g_error_free (error);
1592 accounts_dialog_accounts_setup (user_data);
1596 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1600 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1601 GtkWidget *content_area;
1603 GtkWidget *action_area;
1606 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1608 gui = empathy_builder_get_file (filename,
1609 "accounts_dialog", &priv->window,
1610 "vbox_details", &priv->vbox_details,
1611 "frame_no_protocol", &priv->frame_no_protocol,
1612 "alignment_settings", &priv->alignment_settings,
1613 "alignment_infobar", &priv->alignment_infobar,
1614 "treeview", &priv->treeview,
1615 "frame_new_account", &priv->frame_new_account,
1616 "hbox_type", &priv->hbox_type,
1617 "button_create", &priv->button_create,
1618 "button_back", &priv->button_back,
1619 "radiobutton_reuse", &priv->radiobutton_reuse,
1620 "radiobutton_register", &priv->radiobutton_register,
1621 "image_type", &priv->image_type,
1622 "label_name", &priv->label_name,
1623 "button_add", &priv->button_add,
1624 "button_import", &priv->button_import,
1628 empathy_builder_connect (gui, dialog,
1629 "accounts_dialog", "response", accounts_dialog_response_cb,
1630 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1631 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1632 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1633 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1634 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1635 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1636 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1639 g_object_unref (gui);
1642 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1643 gtk_widget_hide (action_area);
1645 /* Translators: this is used only when built on a moblin platform */
1646 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1647 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1650 priv->combobox_protocol = empathy_protocol_chooser_new ();
1651 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1652 priv->combobox_protocol,
1654 gtk_widget_show (priv->combobox_protocol);
1655 g_signal_connect (priv->combobox_protocol, "changed",
1656 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1659 if (priv->parent_window)
1660 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1661 priv->parent_window);
1663 priv->infobar = gtk_info_bar_new ();
1664 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1667 priv->label_status = gtk_label_new (NULL);
1668 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1669 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1673 do_dispose (GObject *obj)
1675 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1676 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1678 /* Disconnect signals */
1679 g_signal_handlers_disconnect_by_func (priv->account_manager,
1680 accounts_dialog_account_validity_changed_cb,
1682 g_signal_handlers_disconnect_by_func (priv->account_manager,
1683 accounts_dialog_account_removed_cb,
1685 g_signal_handlers_disconnect_by_func (priv->account_manager,
1686 accounts_dialog_account_enabled_cb,
1688 g_signal_handlers_disconnect_by_func (priv->account_manager,
1689 accounts_dialog_account_disabled_cb,
1691 g_signal_handlers_disconnect_by_func (priv->account_manager,
1692 accounts_dialog_manager_ready_cb,
1695 if (priv->connecting_id)
1696 g_source_remove (priv->connecting_id);
1698 if (priv->account_manager != NULL)
1700 g_object_unref (priv->account_manager);
1701 priv->account_manager = NULL;
1704 if (priv->cms != NULL)
1706 g_object_unref (priv->cms);
1710 if (priv->initial_selection != NULL)
1711 g_object_unref (priv->initial_selection);
1712 priv->initial_selection = NULL;
1714 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1718 do_constructor (GType type,
1720 GObjectConstructParam *props)
1724 if (dialog_singleton)
1726 retval = G_OBJECT (dialog_singleton);
1727 g_object_ref (retval);
1732 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1733 (type, n_props, props);
1735 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1736 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1737 /* We add an extra reference that we'll release when the dialog is
1738 * destroyed (accounts_dialog_destroy_cb) */
1739 g_object_ref (retval);
1746 do_get_property (GObject *object,
1751 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1753 switch (property_id)
1756 g_value_set_object (value, priv->parent_window);
1759 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1764 do_set_property (GObject *object,
1766 const GValue *value,
1769 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1771 switch (property_id)
1774 priv->parent_window = g_value_get_object (value);
1777 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1782 do_constructed (GObject *object)
1784 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1785 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1786 gboolean import_asked;
1788 accounts_dialog_build_ui (dialog);
1789 accounts_dialog_model_setup (dialog);
1791 /* Set up signalling */
1792 priv->account_manager = tp_account_manager_dup ();
1794 tp_account_manager_prepare_async (priv->account_manager, NULL,
1795 accounts_dialog_manager_ready_cb, dialog);
1797 empathy_conf_get_bool (empathy_conf_get (),
1798 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1800 if (empathy_import_accounts_to_import ())
1802 gtk_widget_show (priv->button_import);
1806 GtkWidget *import_dialog;
1808 empathy_conf_set_bool (empathy_conf_get (),
1809 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1810 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1812 gtk_widget_show (import_dialog);
1818 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1820 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1821 GParamSpec *param_spec;
1823 oclass->constructor = do_constructor;
1824 oclass->dispose = do_dispose;
1825 oclass->constructed = do_constructed;
1826 oclass->set_property = do_set_property;
1827 oclass->get_property = do_get_property;
1829 param_spec = g_param_spec_object ("parent",
1830 "parent", "The parent window",
1832 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1833 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1835 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1839 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1841 EmpathyAccountsDialogPriv *priv;
1843 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1844 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1845 EmpathyAccountsDialogPriv);
1846 dialog->priv = priv;
1849 /* public methods */
1852 empathy_accounts_dialog_show (GtkWindow *parent,
1853 TpAccount *selected_account)
1855 EmpathyAccountsDialog *dialog;
1856 EmpathyAccountsDialogPriv *priv;
1858 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1859 "parent", parent, NULL);
1861 priv = GET_PRIV (dialog);
1863 if (selected_account)
1865 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1866 accounts_dialog_set_selected_account (dialog, selected_account);
1868 /* save the selection to set it later when the cms
1871 priv->initial_selection = g_object_ref (selected_account);
1874 gtk_window_present (GTK_WINDOW (priv->window));
1875 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1876 * destroyed so we can release the ref returned by the constructor now. */
1877 g_object_unref (dialog);
1879 return priv->window;