2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
32 #include <glib/gi18n.h>
33 #include <dbus/dbus-glib.h>
35 #include <telepathy-glib/util.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy/empathy-account-manager.h>
39 #include <libempathy/empathy-connection-managers.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
42 #include <libempathy-gtk/empathy-protocol-chooser.h>
43 #include <libempathy-gtk/empathy-account-widget.h>
44 #include <libempathy-gtk/empathy-account-widget-irc.h>
45 #include <libempathy-gtk/empathy-account-widget-sip.h>
46 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
47 #include <libempathy-gtk/empathy-conf.h>
48 #include <libempathy-gtk/empathy-images.h>
50 #include "empathy-accounts-dialog.h"
51 #include "empathy-import-dialog.h"
52 #include "empathy-import-utils.h"
54 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
55 #include <libempathy/empathy-debug.h>
57 /* Flashing delay for icons (milliseconds). */
58 #define FLASH_TIMEOUT 500
60 /* The primary text of the dialog shown to the user when he is about to lose
62 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
63 _("There are unsaved modification regarding your %s account.")
65 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
66 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
68 static EmpathyAccountsDialog *dialog_singleton = NULL;
73 GtkWidget *alignment_settings;
75 GtkWidget *vbox_details;
76 GtkWidget *frame_no_protocol;
80 GtkWidget *button_add;
82 GtkWidget *frame_new_account;
83 GtkWidget *combobox_protocol;
85 GtkWidget *button_create;
86 GtkWidget *button_back;
87 GtkWidget *radiobutton_reuse;
88 GtkWidget *radiobutton_register;
90 GtkWidget *image_type;
91 GtkWidget *label_name;
92 GtkWidget *label_type;
93 GtkWidget *settings_widget;
95 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
96 * his GtkWidget. It is the only reliable source we can query to know if
97 * there are any unsaved changes to the currently selected account. We can't
98 * look at the account settings because it does not contain everything that
99 * can be changed using the EmpathyAccountWidget. For instance, it does not
100 * contain the state of the "Enabled" checkbox. */
101 EmpathyAccountWidget *setting_widget_object;
103 gboolean connecting_show;
106 gulong settings_ready_id;
107 EmpathyAccountSettings *settings_ready;
109 EmpathyAccountManager *account_manager;
110 EmpathyConnectionManagers *cms;
112 GtkWindow *parent_window;
113 EmpathyAccount *initial_selection;
115 /* Those are needed when changing the selected row. When a user selects
116 * another account and there are unsaved changes on the currently selected
117 * one, a confirmation message box is presented to him. Since his answer
118 * is retrieved asynchronously, we keep some information as member of the
119 * EmpathyAccountsDialog object. */
120 gboolean force_change_row;
121 GtkTreeRowReference *destination_row;
124 } EmpathyAccountsDialogPriv;
130 COL_ACCOUNT_SETTINGS_POINTER,
138 static void accounts_dialog_account_display_name_changed_cb (
139 EmpathyAccount *account,
143 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
144 EmpathyAccountsDialog *dialog);
146 static gboolean accounts_dialog_get_settings_iter (
147 EmpathyAccountsDialog *dialog,
148 EmpathyAccountSettings *settings,
151 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
156 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
157 EmpathyAccountSettings *settings);
160 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
161 const gchar *display_name)
164 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
166 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
167 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
173 empathy_account_dialog_widget_cancelled_cb (
174 EmpathyAccountWidget *widget_object,
175 EmpathyAccountsDialog *dialog)
179 GtkTreeSelection *selection;
181 EmpathyAccountSettings *settings;
182 EmpathyAccount *account;
183 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
185 view = GTK_TREE_VIEW (priv->treeview);
186 selection = gtk_tree_view_get_selection (view);
188 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
191 gtk_tree_model_get (model, &iter,
192 COL_ACCOUNT_SETTINGS_POINTER, &settings,
193 COL_ACCOUNT_POINTER, &account, -1);
195 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
199 /* We were creating an account. We remove the selected row */
200 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
204 /* We were modifying an account. We discard the changes by reloading the
205 * settings and the UI. */
206 accounts_dialog_update_settings (dialog, settings);
207 g_object_unref (account);
210 if (settings != NULL)
211 g_object_unref (settings);
215 get_default_display_name (EmpathyAccountSettings *settings)
217 const gchar *login_id;
218 const gchar *protocol;
219 gchar *default_display_name;
221 login_id = empathy_account_settings_get_string (settings, "account");
222 protocol = empathy_account_settings_get_protocol (settings);
224 if (login_id != NULL)
226 if (!tp_strdiff (protocol, "irc"))
229 server = empathy_account_settings_get_string (settings, "server");
231 /* To translators: The first parameter is the login id and the
232 * second one is the server. The resulting string will be something
233 * like: "MyUserName on chat.freenode.net".
234 * You should reverse the order of these arguments if the
235 * server should come before the login id in your locale.*/
236 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
241 default_display_name = g_strdup (login_id);
244 else if (protocol != NULL)
246 /* To translators: The parameter is the protocol name. The resulting
247 * string will be something like: "Jabber Account" */
248 default_display_name = g_strdup_printf (_("%s Account"), protocol);
252 default_display_name = g_strdup (_("New account"));
255 return default_display_name;
259 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
260 EmpathyAccountsDialog *dialog)
263 EmpathyAccountSettings *settings =
264 accounts_dialog_model_get_selected_settings (dialog);
266 display_name = get_default_display_name (settings);
268 empathy_account_settings_set_display_name_async (settings,
269 display_name, NULL, NULL);
271 g_free (display_name);
273 accounts_dialog_update_settings (dialog, settings);
276 g_object_unref (settings);
280 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
281 EmpathyAccountSettings *settings)
283 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
286 priv->setting_widget_object =
287 empathy_account_widget_new_for_protocol (settings, FALSE);
289 priv->settings_widget =
290 empathy_account_widget_get_widget (priv->setting_widget_object);
292 priv->settings_widget =
293 empathy_account_widget_get_widget (priv->setting_widget_object);
294 g_signal_connect (priv->setting_widget_object, "account-created",
295 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
296 g_signal_connect (priv->setting_widget_object, "cancelled",
297 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
299 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
300 priv->settings_widget);
301 gtk_widget_show (priv->settings_widget);
303 icon_name = empathy_account_settings_get_icon_name (settings);
305 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
307 /* show the default icon; keep this in sync with the default
308 * one in empathy-accounts-dialog.ui.
310 icon_name = GTK_STOCK_CUT;
312 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
313 icon_name, GTK_ICON_SIZE_DIALOG);
314 gtk_widget_set_tooltip_text (priv->image_type,
315 empathy_protocol_name_to_display_name
316 (empathy_account_settings_get_protocol (settings)));
317 gtk_widget_show (priv->image_type);
319 accounts_dialog_update_name_label (dialog,
320 empathy_account_settings_get_display_name (settings));
324 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
326 EmpathyAccountsDialog *dialog)
328 if (empathy_account_settings_is_ready (settings))
329 account_dialog_create_settings_widget (dialog, settings);
333 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
337 GtkTreeSelection *selection;
339 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
342 view = GTK_TREE_VIEW (priv->treeview);
343 model = gtk_tree_view_get_model (view);
345 if (gtk_tree_model_get_iter_first (model, &iter))
347 selection = gtk_tree_view_get_selection (view);
348 gtk_tree_selection_select_iter (selection, &iter);
352 accounts_dialog_update_settings (dialog, NULL);
357 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
358 EmpathyAccount **account)
362 GtkTreeSelection *selection;
363 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
365 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
367 if (gtk_tree_selection_get_selected (selection, &model, &iter))
368 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
370 return *account != NULL && priv->setting_widget_object != NULL
371 && empathy_account_widget_contains_pending_changes (
372 priv->setting_widget_object);
376 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
377 EmpathyAccountsDialog *dialog)
379 TpConnectionManager *cm;
380 TpConnectionManagerProtocol *proto;
382 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
384 cm = empathy_protocol_chooser_dup_selected (
385 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);
410 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
414 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
416 view = GTK_TREE_VIEW (priv->treeview);
417 model = gtk_tree_view_get_model (view);
419 gtk_widget_set_sensitive (priv->button_add, FALSE);
420 gtk_widget_hide (priv->vbox_details);
421 gtk_widget_hide (priv->frame_no_protocol);
422 gtk_widget_show (priv->frame_new_account);
424 /* If we have no account, no need of a back button */
425 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
426 gtk_widget_show (priv->button_back);
428 gtk_widget_hide (priv->button_back);
430 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
431 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
433 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
434 gtk_widget_grab_focus (priv->combobox_protocol);
438 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
439 const gchar *primary_text,
440 const gchar *secondary_text,
441 GCallback response_callback,
443 const gchar *first_button_text,
447 GtkWidget *message_dialog;
448 const gchar *button_text;
449 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
451 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
452 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
453 GTK_MESSAGE_QUESTION,
457 gtk_message_dialog_format_secondary_text (
458 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
460 va_start (button_args, first_button_text);
461 for (button_text = first_button_text;
463 button_text = va_arg (button_args, const gchar *))
466 response_id = va_arg (button_args, gint);
468 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
471 va_end (button_args);
473 g_signal_connect (message_dialog, "response", response_callback, user_data);
475 gtk_widget_show (message_dialog);
479 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
483 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
484 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
486 gtk_widget_destroy (GTK_WIDGET (message_dialog));
488 if (response_id == GTK_RESPONSE_YES)
490 empathy_account_widget_discard_pending_changes (
491 priv->setting_widget_object);
492 accounts_dialog_setup_ui_to_add_account (dialog);
497 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
498 EmpathyAccountsDialog *dialog)
500 EmpathyAccount *account = NULL;
502 if (accounts_dialog_has_pending_change (dialog, &account))
504 gchar *question_dialog_primary_text = g_strdup_printf (
505 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
506 empathy_account_get_display_name (account));
508 accounts_dialog_show_question_dialog (dialog,
509 question_dialog_primary_text,
510 _("You are about to create a new account, which will discard\n"
511 "your changes. Are you sure you want to proceed?"),
512 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
514 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
515 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
517 g_free (question_dialog_primary_text);
521 accounts_dialog_setup_ui_to_add_account (dialog);
526 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
527 EmpathyAccountSettings *settings)
529 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
531 if (priv->settings_ready != NULL)
533 g_signal_handler_disconnect (priv->settings_ready,
534 priv->settings_ready_id);
535 priv->settings_ready = NULL;
536 priv->settings_ready_id = 0;
544 view = GTK_TREE_VIEW (priv->treeview);
545 model = gtk_tree_view_get_model (view);
547 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
549 /* We have configured accounts, select the first one */
550 accounts_dialog_model_select_first (dialog);
553 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
555 /* We have no account configured but we have some
556 * profiles installed. The user obviously wants to add
557 * an account. Click on the Add button for him. */
558 accounts_dialog_button_add_clicked_cb (priv->button_add,
563 /* No account and no profile, warn the user */
564 gtk_widget_hide (priv->vbox_details);
565 gtk_widget_hide (priv->frame_new_account);
566 gtk_widget_show (priv->frame_no_protocol);
567 gtk_widget_set_sensitive (priv->button_add, FALSE);
571 /* We have an account selected, destroy old settings and create a new
572 * one for the account selected */
573 gtk_widget_hide (priv->frame_new_account);
574 gtk_widget_hide (priv->frame_no_protocol);
575 gtk_widget_show (priv->vbox_details);
576 gtk_widget_set_sensitive (priv->button_add, TRUE);
578 if (priv->settings_widget)
580 gtk_widget_destroy (priv->settings_widget);
581 priv->settings_widget = NULL;
584 if (empathy_account_settings_is_ready (settings))
586 account_dialog_create_settings_widget (dialog, settings);
590 priv->settings_ready = settings;
591 priv->settings_ready_id =
592 g_signal_connect (settings, "notify::ready",
593 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
599 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
600 GtkCellEditable *editable,
602 EmpathyAccountsDialog *dialog)
604 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
606 if (priv->connecting_id)
607 g_source_remove (priv->connecting_id);
609 DEBUG ("Editing account name started; stopping flashing");
613 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
614 GtkCellRenderer *cell,
617 EmpathyAccountsDialog *dialog)
619 EmpathyAccountSettings *settings;
622 TpConnectionStatus status;
623 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
625 gtk_tree_model_get (model, iter,
627 COL_ACCOUNT_SETTINGS_POINTER, &settings,
630 icon_name = empathy_account_settings_get_icon_name (settings);
631 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
635 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
636 (status == TP_CONNECTION_STATUS_CONNECTING &&
637 !priv->connecting_show))
639 GdkPixbuf *modded_pixbuf;
641 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
644 gdk_pixbuf_get_width (pixbuf),
645 gdk_pixbuf_get_height (pixbuf));
647 gdk_pixbuf_saturate_and_pixelate (pixbuf,
651 g_object_unref (pixbuf);
652 pixbuf = modded_pixbuf;
661 g_object_unref (settings);
664 g_object_unref (pixbuf);
668 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
673 gtk_tree_model_row_changed (model, path, iter);
679 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
683 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
685 priv->connecting_show = !priv->connecting_show;
687 view = GTK_TREE_VIEW (priv->treeview);
688 model = gtk_tree_view_get_model (view);
690 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
696 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
699 EmpathyAccountsDialog *dialog)
701 EmpathyAccountSettings *settings;
703 GtkTreePath *treepath;
705 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
707 if (empathy_account_manager_get_connecting_accounts
708 (priv->account_manager) > 0)
710 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
711 (GSourceFunc) accounts_dialog_flash_connecting_cb,
715 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
716 treepath = gtk_tree_path_new_from_string (path);
717 gtk_tree_model_get_iter (model, &iter, treepath);
718 gtk_tree_model_get (model, &iter,
719 COL_ACCOUNT_SETTINGS_POINTER, &settings,
721 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
724 gtk_tree_path_free (treepath);
726 empathy_account_settings_set_display_name_async (settings, new_text,
728 g_object_set (settings, "display-name-overridden", TRUE, NULL);
729 g_object_unref (settings);
733 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
737 EmpathyAccount *account;
740 GtkTreeSelection *selection;
741 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
742 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
744 if (response_id == GTK_RESPONSE_YES)
746 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
748 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
751 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
755 g_signal_handlers_disconnect_by_func (account,
756 accounts_dialog_account_display_name_changed_cb, account_dialog);
757 empathy_account_remove_async (account, NULL, NULL);
758 g_object_unref (account);
762 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
763 accounts_dialog_model_select_first (account_dialog);
766 gtk_widget_destroy (GTK_WIDGET (message_dialog));
770 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
771 const gchar *path_string,
772 EmpathyAccountsDialog *dialog)
774 EmpathyAccount *account;
777 gchar *question_dialog_primary_text;
778 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
780 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
782 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
785 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
787 if (account == NULL || !empathy_account_is_valid (account))
789 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
790 accounts_dialog_model_select_first (dialog);
794 question_dialog_primary_text = g_strdup_printf (
795 _("You are about to remove your %s account!\n"
796 "Are you sure you want to proceed?"),
797 empathy_account_get_display_name (account));
799 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
800 _("Any associated conversations and chat rooms will NOT be "
801 "removed if you decide to proceed.\n"
803 "Should you decide to add the account back at a later time, "
804 "they will still be available."),
805 G_CALLBACK (accounts_dialog_delete_account_response_cb),
807 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
808 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
810 g_free (question_dialog_primary_text);
814 g_object_unref (account);
820 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
823 GtkTreeViewColumn *column;
824 GtkCellRenderer *cell;
825 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
827 view = GTK_TREE_VIEW (priv->treeview);
828 gtk_tree_view_set_headers_visible (view, FALSE);
831 column = gtk_tree_view_column_new ();
832 gtk_tree_view_column_set_expand (column, TRUE);
833 gtk_tree_view_append_column (view, column);
836 cell = gtk_cell_renderer_pixbuf_new ();
837 gtk_tree_view_column_pack_start (column, cell, FALSE);
838 gtk_tree_view_column_set_cell_data_func (column, cell,
839 (GtkTreeCellDataFunc)
840 accounts_dialog_model_pixbuf_data_func,
845 cell = gtk_cell_renderer_text_new ();
847 "ellipsize", PANGO_ELLIPSIZE_END,
851 gtk_tree_view_column_pack_start (column, cell, TRUE);
852 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
853 g_signal_connect (cell, "edited",
854 G_CALLBACK (accounts_dialog_name_edited_cb),
856 g_signal_connect (cell, "editing-started",
857 G_CALLBACK (accounts_dialog_name_editing_started_cb),
861 cell = empathy_cell_renderer_activatable_new ();
862 gtk_tree_view_column_pack_start (column, cell, FALSE);
864 "icon-name", GTK_STOCK_DELETE,
867 g_signal_connect (cell, "path-activated",
868 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
872 static EmpathyAccountSettings *
873 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
877 GtkTreeSelection *selection;
879 EmpathyAccountSettings *settings;
880 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
882 view = GTK_TREE_VIEW (priv->treeview);
883 selection = gtk_tree_view_get_selection (view);
885 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
888 gtk_tree_model_get (model, &iter,
889 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
895 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
896 EmpathyAccountsDialog *dialog)
898 EmpathyAccountSettings *settings;
901 gboolean is_selection;
903 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
905 settings = accounts_dialog_model_get_selected_settings (dialog);
906 accounts_dialog_update_settings (dialog, settings);
908 if (settings != NULL)
909 g_object_unref (settings);
913 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
917 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
918 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
920 gtk_widget_destroy (GTK_WIDGET (message_dialog));
922 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
924 /* The user wants to lose unsaved changes to the currently selected
925 * account and select another account. We discard the changes and
926 * select the other account. */
928 GtkTreeSelection *selection;
930 priv->force_change_row = TRUE;
931 empathy_account_widget_discard_pending_changes (
932 priv->setting_widget_object);
934 path = gtk_tree_row_reference_get_path (priv->destination_row);
935 selection = gtk_tree_view_get_selection (
936 GTK_TREE_VIEW (priv->treeview));
940 /* This will trigger a call to
941 * accounts_dialog_account_selection_change() */
942 gtk_tree_selection_select_path (selection, path);
943 gtk_tree_path_free (path);
946 gtk_tree_row_reference_free (priv->destination_row);
950 priv->force_change_row = FALSE;
955 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
958 gboolean path_currently_selected,
961 EmpathyAccount *account = NULL;
962 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
963 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
965 if (priv->force_change_row)
967 /* We came back here because the user wants to discard changes to his
968 * modified account. The changes have already been discarded so we
969 * just change the selected row. */
970 priv->force_change_row = FALSE;
974 if (accounts_dialog_has_pending_change (dialog, &account))
976 /* The currently selected account has some unsaved changes. We ask
977 * the user if he really wants to lose his changes and select another
979 gchar *question_dialog_primary_text;
980 priv->destination_row = gtk_tree_row_reference_new (model, path);
982 question_dialog_primary_text = g_strdup_printf (
983 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
984 empathy_account_get_display_name (account));
986 accounts_dialog_show_question_dialog (dialog,
987 question_dialog_primary_text,
988 _("You are about to select another account, which will discard\n"
989 "your changes. Are you sure you want to proceed?"),
990 G_CALLBACK (accounts_dialog_selection_change_response_cb),
992 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
993 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
995 g_free (question_dialog_primary_text);
1006 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1008 GtkListStore *store;
1009 GtkTreeSelection *selection;
1010 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1012 store = gtk_list_store_new (COL_COUNT,
1013 G_TYPE_STRING, /* name */
1014 G_TYPE_UINT, /* status */
1015 EMPATHY_TYPE_ACCOUNT, /* account */
1016 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1018 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1019 GTK_TREE_MODEL (store));
1021 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1022 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1023 gtk_tree_selection_set_select_function (selection,
1024 accounts_dialog_account_selection_change, dialog, NULL);
1026 g_signal_connect (selection, "changed",
1027 G_CALLBACK (accounts_dialog_model_selection_changed),
1030 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1031 COL_NAME, GTK_SORT_ASCENDING);
1033 accounts_dialog_model_add_columns (dialog);
1035 g_object_unref (store);
1039 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1040 EmpathyAccountSettings *settings,
1044 GtkTreeSelection *selection;
1045 GtkTreeModel *model;
1047 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1049 /* Update the status in the model */
1050 view = GTK_TREE_VIEW (priv->treeview);
1051 selection = gtk_tree_view_get_selection (view);
1052 model = gtk_tree_view_get_model (view);
1054 for (ok = gtk_tree_model_get_iter_first (model, iter);
1056 ok = gtk_tree_model_iter_next (model, iter))
1058 EmpathyAccountSettings *this_settings;
1061 gtk_tree_model_get (model, iter,
1062 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1065 equal = (this_settings == settings);
1066 g_object_unref (this_settings);
1076 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1077 EmpathyAccount *account,
1081 GtkTreeSelection *selection;
1082 GtkTreeModel *model;
1084 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1086 /* Update the status in the model */
1087 view = GTK_TREE_VIEW (priv->treeview);
1088 selection = gtk_tree_view_get_selection (view);
1089 model = gtk_tree_view_get_model (view);
1091 for (ok = gtk_tree_model_get_iter_first (model, iter);
1093 ok = gtk_tree_model_iter_next (model, iter))
1095 EmpathyAccountSettings *settings;
1098 gtk_tree_model_get (model, iter,
1099 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1102 equal = empathy_account_settings_has_account (settings, account);
1103 g_object_unref (settings);
1113 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1114 EmpathyAccountSettings *settings)
1116 GtkTreeSelection *selection;
1118 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1120 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1121 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1122 gtk_tree_selection_select_iter (selection, &iter);
1125 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1126 EmpathyAccountSettings *settings)
1128 GtkTreeModel *model;
1131 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1133 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1134 name = empathy_account_settings_get_display_name (settings);
1136 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1138 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1140 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1141 COL_ACCOUNT_SETTINGS_POINTER, settings,
1146 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1147 EmpathyAccount *account,
1148 TpConnectionStatusReason reason,
1149 TpConnectionStatus current,
1150 TpConnectionStatus previous,
1151 EmpathyAccountsDialog *dialog)
1153 GtkTreeModel *model;
1156 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1158 /* Update the status in the model */
1159 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1161 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1165 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1166 COL_STATUS, current,
1169 path = gtk_tree_model_get_path (model, &iter);
1170 gtk_tree_model_row_changed (model, path, &iter);
1171 gtk_tree_path_free (path);
1174 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1176 if (!found && priv->connecting_id)
1178 g_source_remove (priv->connecting_id);
1179 priv->connecting_id = 0;
1182 if (found && !priv->connecting_id)
1183 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1184 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1189 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1193 const gchar *display_name;
1195 GtkTreeModel *model;
1196 EmpathyAccountSettings *settings;
1197 EmpathyAccount *selected_account;
1198 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1199 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1201 display_name = empathy_account_get_display_name (account);
1202 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1203 settings = accounts_dialog_model_get_selected_settings (dialog);
1204 selected_account = empathy_account_settings_get_account (settings);
1206 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1208 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1209 COL_NAME, display_name,
1213 if (selected_account == account)
1214 accounts_dialog_update_name_label (dialog, display_name);
1216 g_object_unref (settings);
1220 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1221 EmpathyAccount *account)
1223 EmpathyAccountSettings *settings;
1224 GtkTreeModel *model;
1226 TpConnectionStatus status;
1229 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1231 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1232 g_object_get (account, "connection-status", &status, NULL);
1233 name = empathy_account_get_display_name (account);
1234 enabled = empathy_account_is_enabled (account);
1236 settings = empathy_account_settings_new_for_account (account);
1238 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1239 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1241 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1244 COL_ACCOUNT_POINTER, account,
1245 COL_ACCOUNT_SETTINGS_POINTER, settings,
1248 accounts_dialog_connection_changed_cb (priv->account_manager,
1250 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1252 TP_CONNECTION_STATUS_DISCONNECTED,
1255 g_signal_connect (account, "notify::display-name",
1256 G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
1258 g_object_unref (settings);
1262 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1263 EmpathyAccountSettings *settings)
1265 GtkTreeModel *model;
1267 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1269 gboolean enabled = FALSE;
1270 EmpathyAccount *account;
1271 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1273 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1274 name = empathy_account_settings_get_display_name (settings);
1276 account = empathy_account_settings_get_account (settings);
1277 if (account != NULL)
1279 enabled = empathy_account_is_enabled (account);
1280 g_object_get (account, "connection-status", &status, NULL);
1283 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1284 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1287 COL_ACCOUNT_POINTER, account,
1288 COL_ACCOUNT_SETTINGS_POINTER, settings,
1293 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1294 EmpathyAccount *account,
1295 EmpathyAccountsDialog *dialog)
1297 accounts_dialog_add_account (dialog, account);
1302 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1303 EmpathyAccount *account,
1304 EmpathyAccountsDialog *dialog)
1307 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1309 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1311 g_signal_handlers_disconnect_by_func (account,
1312 accounts_dialog_account_display_name_changed_cb, dialog);
1313 gtk_list_store_remove (GTK_LIST_STORE (
1314 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1319 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1320 EmpathyAccount *account,
1323 GtkTreeModel *model;
1324 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1326 /* Update the status in the model */
1327 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1329 DEBUG ("Account %s is now %s",
1330 empathy_account_get_display_name (account),
1331 enabled ? "enabled" : "disabled");
1335 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1336 EmpathyAccount *account,
1337 EmpathyAccountsDialog *dialog)
1339 enable_or_disable_account (dialog, account, FALSE);
1343 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1344 EmpathyAccount *account,
1345 EmpathyAccountsDialog *dialog)
1347 enable_or_disable_account (dialog, account, TRUE);
1351 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1352 EmpathyAccount *account,
1353 EmpathyAccountsDialog *dialog)
1355 EmpathyAccountSettings *settings, *selected_settings;
1356 GtkTreeModel *model;
1358 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1360 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1362 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1365 gtk_tree_model_get (model, &iter,
1366 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1369 accounts_dialog_update (dialog, settings);
1370 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1372 if (settings == selected_settings)
1373 accounts_dialog_update_name_label (dialog,
1374 empathy_account_settings_get_display_name (settings));
1377 g_object_unref (settings);
1379 if (selected_settings)
1380 g_object_unref (selected_settings);
1384 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1385 EmpathyAccountsDialog *dialog)
1387 EmpathyAccountSettings *settings;
1389 const gchar *display_name;
1390 TpConnectionManager *cm;
1391 TpConnectionManagerProtocol *proto;
1392 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1395 cm = empathy_protocol_chooser_dup_selected (
1396 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1398 display_name = empathy_protocol_name_to_display_name (
1399 is_gtalk ? "gtalk" : proto->name);
1401 if (display_name == NULL)
1402 display_name = proto->name;
1404 /* Create account */
1405 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1408 str = g_strdup_printf (_("New %s account"), display_name);
1409 settings = empathy_account_settings_new (cm->name, proto->name, str);
1413 if (tp_connection_manager_protocol_can_register (proto))
1417 active = gtk_toggle_button_get_active
1418 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1420 empathy_account_settings_set_boolean (settings, "register", TRUE);
1424 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1427 accounts_dialog_add (dialog, settings);
1428 accounts_dialog_model_set_selected (dialog, settings);
1430 g_object_unref (settings);
1431 g_object_unref (cm);
1435 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1436 EmpathyAccountsDialog *dialog)
1438 EmpathyAccountSettings *settings;
1440 settings = accounts_dialog_model_get_selected_settings (dialog);
1441 accounts_dialog_update_settings (dialog, settings);
1444 g_object_unref (settings);
1448 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1449 EmpathyAccountsDialog *dialog)
1451 empathy_url_show (button, "ghelp:empathy?accounts-window");
1455 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1459 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1461 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1463 if (response_id == GTK_RESPONSE_YES)
1464 gtk_widget_destroy (account_dialog);
1468 accounts_dialog_response_cb (GtkWidget *widget,
1470 EmpathyAccountsDialog *dialog)
1472 EmpathyAccount *account = NULL;
1474 if (accounts_dialog_has_pending_change (dialog, &account))
1476 gchar *question_dialog_primary_text;
1477 question_dialog_primary_text = g_strdup_printf (
1478 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1479 empathy_account_get_display_name (account));
1481 accounts_dialog_show_question_dialog (dialog,
1482 question_dialog_primary_text,
1483 _("You are about to close the window, which will discard\n"
1484 "your changes. Are you sure you want to proceed?"),
1485 G_CALLBACK (accounts_dialog_close_response_cb),
1487 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1488 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1490 g_free (question_dialog_primary_text);
1492 else if (response == GTK_RESPONSE_CLOSE ||
1493 response == GTK_RESPONSE_DELETE_EVENT)
1494 gtk_widget_destroy (widget);
1498 accounts_dialog_delete_event_cb (GtkWidget *widget,
1500 EmpathyAccountsDialog *dialog)
1502 /* we maunally handle responses to delete events */
1507 accounts_dialog_destroy_cb (GtkObject *obj,
1508 EmpathyAccountsDialog *dialog)
1512 g_object_unref (dialog);
1516 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1517 EmpathyAccount *account)
1519 GtkTreeSelection *selection;
1521 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1523 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1524 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1525 gtk_tree_selection_select_iter (selection, &iter);
1529 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1531 EmpathyAccountsDialog *dialog)
1533 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1535 if (empathy_connection_managers_is_ready (cms))
1537 accounts_dialog_update_settings (dialog, NULL);
1539 if (priv->initial_selection != NULL)
1541 accounts_dialog_set_selected_account
1542 (dialog, priv->initial_selection);
1543 g_object_unref (priv->initial_selection);
1544 priv->initial_selection = NULL;
1550 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1554 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1556 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1558 gui = empathy_builder_get_file (filename,
1559 "accounts_dialog", &priv->window,
1560 "vbox_details", &priv->vbox_details,
1561 "frame_no_protocol", &priv->frame_no_protocol,
1562 "alignment_settings", &priv->alignment_settings,
1563 "treeview", &priv->treeview,
1564 "frame_new_account", &priv->frame_new_account,
1565 "hbox_type", &priv->hbox_type,
1566 "button_create", &priv->button_create,
1567 "button_back", &priv->button_back,
1568 "radiobutton_reuse", &priv->radiobutton_reuse,
1569 "radiobutton_register", &priv->radiobutton_register,
1570 "image_type", &priv->image_type,
1571 "label_name", &priv->label_name,
1572 "button_add", &priv->button_add,
1576 empathy_builder_connect (gui, dialog,
1577 "accounts_dialog", "response", accounts_dialog_response_cb,
1578 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1579 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1580 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1581 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1582 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1583 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1586 g_object_unref (gui);
1588 priv->combobox_protocol = empathy_protocol_chooser_new ();
1589 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1590 priv->combobox_protocol,
1592 gtk_widget_show (priv->combobox_protocol);
1593 g_signal_connect (priv->combobox_protocol, "changed",
1594 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1597 if (priv->parent_window)
1598 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1599 priv->parent_window);
1603 do_dispose (GObject *obj)
1605 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1606 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1608 /* Disconnect signals */
1609 g_signal_handlers_disconnect_by_func (priv->account_manager,
1610 accounts_dialog_account_added_cb,
1612 g_signal_handlers_disconnect_by_func (priv->account_manager,
1613 accounts_dialog_account_removed_cb,
1615 g_signal_handlers_disconnect_by_func (priv->account_manager,
1616 accounts_dialog_account_enabled_cb,
1618 g_signal_handlers_disconnect_by_func (priv->account_manager,
1619 accounts_dialog_account_disabled_cb,
1621 g_signal_handlers_disconnect_by_func (priv->account_manager,
1622 accounts_dialog_account_changed_cb,
1624 g_signal_handlers_disconnect_by_func (priv->account_manager,
1625 accounts_dialog_connection_changed_cb,
1628 if (priv->connecting_id)
1629 g_source_remove (priv->connecting_id);
1631 if (priv->account_manager != NULL)
1633 g_object_unref (priv->account_manager);
1634 priv->account_manager = NULL;
1637 if (priv->cms != NULL)
1639 g_object_unref (priv->cms);
1643 if (priv->initial_selection != NULL)
1644 g_object_unref (priv->initial_selection);
1645 priv->initial_selection = NULL;
1647 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1651 do_constructor (GType type,
1653 GObjectConstructParam *props)
1657 if (dialog_singleton)
1659 retval = G_OBJECT (dialog_singleton);
1660 g_object_ref (retval);
1665 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1666 (type, n_props, props);
1668 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1669 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1676 do_get_property (GObject *object,
1681 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1683 switch (property_id)
1686 g_value_set_object (value, priv->parent_window);
1689 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1694 do_set_property (GObject *object,
1696 const GValue *value,
1699 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1701 switch (property_id)
1704 priv->parent_window = g_value_get_object (value);
1707 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1712 do_constructed (GObject *object)
1714 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1715 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1716 GList *accounts, *l;
1717 gboolean import_asked;
1719 accounts_dialog_build_ui (dialog);
1721 /* Set up signalling */
1722 priv->account_manager = empathy_account_manager_dup_singleton ();
1724 g_signal_connect (priv->account_manager, "account-created",
1725 G_CALLBACK (accounts_dialog_account_added_cb),
1727 g_signal_connect (priv->account_manager, "account-deleted",
1728 G_CALLBACK (accounts_dialog_account_removed_cb),
1730 g_signal_connect (priv->account_manager, "account-enabled",
1731 G_CALLBACK (accounts_dialog_account_enabled_cb),
1733 g_signal_connect (priv->account_manager, "account-disabled",
1734 G_CALLBACK (accounts_dialog_account_disabled_cb),
1736 g_signal_connect (priv->account_manager, "account-changed",
1737 G_CALLBACK (accounts_dialog_account_changed_cb),
1739 g_signal_connect (priv->account_manager, "account-connection-changed",
1740 G_CALLBACK (accounts_dialog_connection_changed_cb),
1743 accounts_dialog_model_setup (dialog);
1745 /* Add existing accounts */
1746 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1747 for (l = accounts; l; l = l->next)
1749 accounts_dialog_add_account (dialog, l->data);
1750 g_object_unref (l->data);
1752 g_list_free (accounts);
1754 priv->cms = empathy_connection_managers_dup_singleton ();
1755 if (!empathy_connection_managers_is_ready (priv->cms))
1756 g_signal_connect (priv->cms, "notify::ready",
1757 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1759 accounts_dialog_model_select_first (dialog);
1761 empathy_conf_get_bool (empathy_conf_get (),
1762 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1765 if (empathy_import_accounts_to_import ())
1770 GtkWidget *import_dialog;
1772 empathy_conf_set_bool (empathy_conf_get (),
1773 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1774 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1776 gtk_widget_show (import_dialog);
1782 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1784 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1785 GParamSpec *param_spec;
1787 oclass->constructor = do_constructor;
1788 oclass->dispose = do_dispose;
1789 oclass->constructed = do_constructed;
1790 oclass->set_property = do_set_property;
1791 oclass->get_property = do_get_property;
1793 param_spec = g_param_spec_object ("parent",
1794 "parent", "The parent window",
1796 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1797 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1799 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1803 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1805 EmpathyAccountsDialogPriv *priv;
1807 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1808 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1809 EmpathyAccountsDialogPriv);
1810 dialog->priv = priv;
1813 /* public methods */
1816 empathy_accounts_dialog_show (GtkWindow *parent,
1817 EmpathyAccount *selected_account)
1819 EmpathyAccountsDialog *dialog;
1820 EmpathyAccountsDialogPriv *priv;
1822 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1823 "parent", parent, NULL);
1825 priv = GET_PRIV (dialog);
1827 if (selected_account)
1829 if (empathy_connection_managers_is_ready (priv->cms))
1830 accounts_dialog_set_selected_account (dialog, selected_account);
1832 /* save the selection to set it later when the cms
1835 priv->initial_selection = g_object_ref (selected_account);
1838 gtk_window_present (GTK_WINDOW (priv->window));
1840 return priv->window;