2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
32 #include <glib/gi18n.h>
33 #include <dbus/dbus-glib.h>
35 #include <telepathy-glib/account-manager.h>
36 #include <telepathy-glib/util.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-connection-managers.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
42 #include <libempathy-gtk/empathy-protocol-chooser.h>
43 #include <libempathy-gtk/empathy-account-widget.h>
44 #include <libempathy-gtk/empathy-account-widget-irc.h>
45 #include <libempathy-gtk/empathy-account-widget-sip.h>
46 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
47 #include <libempathy-gtk/empathy-conf.h>
48 #include <libempathy-gtk/empathy-images.h>
50 #include "empathy-accounts-dialog.h"
51 #include "empathy-import-dialog.h"
52 #include "empathy-import-utils.h"
54 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
55 #include <libempathy/empathy-debug.h>
57 /* Flashing delay for icons (milliseconds). */
58 #define FLASH_TIMEOUT 500
60 /* The primary text of the dialog shown to the user when he is about to lose
62 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
63 _("There are unsaved modification regarding your %s account.")
64 /* The primary text of the dialog shown to the user when he is about to lose
65 * an unsaved new account */
66 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
67 _("Your new account has not been saved yet.")
69 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
70 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
72 static EmpathyAccountsDialog *dialog_singleton = NULL;
77 GtkWidget *alignment_settings;
79 GtkWidget *vbox_details;
80 GtkWidget *frame_no_protocol;
84 GtkWidget *button_add;
85 GtkWidget *button_import;
87 GtkWidget *frame_new_account;
88 GtkWidget *combobox_protocol;
90 GtkWidget *button_create;
91 GtkWidget *button_back;
92 GtkWidget *radiobutton_reuse;
93 GtkWidget *radiobutton_register;
95 GtkWidget *image_type;
96 GtkWidget *label_name;
97 GtkWidget *label_type;
98 GtkWidget *settings_widget;
100 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
101 * his GtkWidget. It is the only reliable source we can query to know if
102 * there are any unsaved changes to the currently selected account. We can't
103 * look at the account settings because it does not contain everything that
104 * can be changed using the EmpathyAccountWidget. For instance, it does not
105 * contain the state of the "Enabled" checkbox. */
106 EmpathyAccountWidget *setting_widget_object;
108 gboolean connecting_show;
111 gulong settings_ready_id;
112 EmpathyAccountSettings *settings_ready;
114 TpAccountManager *account_manager;
115 EmpathyConnectionManagers *cms;
117 GtkWindow *parent_window;
118 TpAccount *initial_selection;
120 /* Those are needed when changing the selected row. When a user selects
121 * another account and there are unsaved changes on the currently selected
122 * one, a confirmation message box is presented to him. Since his answer
123 * is retrieved asynchronously, we keep some information as member of the
124 * EmpathyAccountsDialog object. */
125 gboolean force_change_row;
126 GtkTreeRowReference *destination_row;
129 } EmpathyAccountsDialogPriv;
135 COL_ACCOUNT_SETTINGS_POINTER,
143 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
144 EmpathyAccountsDialog *dialog);
146 static gboolean accounts_dialog_get_settings_iter (
147 EmpathyAccountsDialog *dialog,
148 EmpathyAccountSettings *settings,
151 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
157 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
158 const gchar *display_name)
161 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
163 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
164 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
170 empathy_account_dialog_widget_cancelled_cb (
171 EmpathyAccountWidget *widget_object,
172 EmpathyAccountsDialog *dialog)
176 GtkTreeSelection *selection;
178 EmpathyAccountSettings *settings;
180 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
182 view = GTK_TREE_VIEW (priv->treeview);
183 selection = gtk_tree_view_get_selection (view);
185 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
188 gtk_tree_model_get (model, &iter,
189 COL_ACCOUNT_SETTINGS_POINTER, &settings,
190 COL_ACCOUNT_POINTER, &account, -1);
192 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
196 /* We were creating an account. We remove the selected row */
197 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
201 /* We were modifying an account. We discard the changes by reloading the
202 * settings and the UI. */
203 accounts_dialog_update_settings (dialog, settings);
204 g_object_unref (account);
207 if (settings != NULL)
208 g_object_unref (settings);
212 get_default_display_name (EmpathyAccountSettings *settings)
214 const gchar *login_id;
215 const gchar *protocol, *p;
216 gchar *default_display_name;
218 login_id = empathy_account_settings_get_string (settings, "account");
219 protocol = empathy_account_settings_get_protocol (settings);
221 if (login_id != NULL)
223 if (!tp_strdiff (protocol, "irc"))
226 server = empathy_account_settings_get_string (settings, "server");
228 /* To translators: The first parameter is the login id and the
229 * second one is the server. The resulting string will be something
230 * like: "MyUserName on chat.freenode.net".
231 * You should reverse the order of these arguments if the
232 * server should come before the login id in your locale.*/
233 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
238 default_display_name = g_strdup (login_id);
241 return default_display_name;
244 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
247 if (protocol != NULL)
249 /* To translators: The parameter is the protocol name. The resulting
250 * string will be something like: "Jabber Account" */
251 default_display_name = g_strdup_printf (_("%s Account"), protocol);
255 default_display_name = g_strdup (_("New account"));
258 return default_display_name;
262 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
263 EmpathyAccountsDialog *dialog)
266 EmpathyAccountSettings *settings =
267 accounts_dialog_model_get_selected_settings (dialog);
269 display_name = get_default_display_name (settings);
271 empathy_account_settings_set_display_name_async (settings,
272 display_name, NULL, NULL);
274 g_free (display_name);
276 accounts_dialog_update_settings (dialog, settings);
279 g_object_unref (settings);
283 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
284 EmpathyAccountSettings *settings)
286 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
289 priv->setting_widget_object =
290 empathy_account_widget_new_for_protocol (settings, FALSE);
292 priv->settings_widget =
293 empathy_account_widget_get_widget (priv->setting_widget_object);
295 priv->settings_widget =
296 empathy_account_widget_get_widget (priv->setting_widget_object);
297 g_signal_connect (priv->setting_widget_object, "account-created",
298 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
299 g_signal_connect (priv->setting_widget_object, "cancelled",
300 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
302 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
303 priv->settings_widget);
304 gtk_widget_show (priv->settings_widget);
306 icon_name = empathy_account_settings_get_icon_name (settings);
308 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
310 /* show the default icon; keep this in sync with the default
311 * one in empathy-accounts-dialog.ui.
313 icon_name = GTK_STOCK_CUT;
315 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
316 icon_name, GTK_ICON_SIZE_DIALOG);
317 gtk_widget_set_tooltip_text (priv->image_type,
318 empathy_protocol_name_to_display_name
319 (empathy_account_settings_get_protocol (settings)));
320 gtk_widget_show (priv->image_type);
322 accounts_dialog_update_name_label (dialog,
323 empathy_account_settings_get_display_name (settings));
327 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
329 EmpathyAccountsDialog *dialog)
331 if (empathy_account_settings_is_ready (settings))
332 account_dialog_create_settings_widget (dialog, settings);
336 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
340 GtkTreeSelection *selection;
342 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
345 view = GTK_TREE_VIEW (priv->treeview);
346 model = gtk_tree_view_get_model (view);
348 if (gtk_tree_model_get_iter_first (model, &iter))
350 selection = gtk_tree_view_get_selection (view);
351 gtk_tree_selection_select_iter (selection, &iter);
355 accounts_dialog_update_settings (dialog, NULL);
360 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
365 GtkTreeSelection *selection;
366 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
368 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
370 if (gtk_tree_selection_get_selected (selection, &model, &iter))
371 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
373 return priv->setting_widget_object != NULL
374 && empathy_account_widget_contains_pending_changes (
375 priv->setting_widget_object);
379 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
380 EmpathyAccountsDialog *dialog)
382 TpConnectionManager *cm;
383 TpConnectionManagerProtocol *proto;
385 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
387 cm = empathy_protocol_chooser_dup_selected (
388 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
400 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
402 gtk_widget_show (priv->radiobutton_register);
403 gtk_widget_show (priv->radiobutton_reuse);
407 gtk_widget_hide (priv->radiobutton_register);
408 gtk_widget_hide (priv->radiobutton_reuse);
411 gtk_widget_hide (priv->radiobutton_register);
412 gtk_widget_hide (priv->radiobutton_reuse);
419 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
423 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
425 view = GTK_TREE_VIEW (priv->treeview);
426 model = gtk_tree_view_get_model (view);
428 gtk_widget_set_sensitive (priv->button_add, FALSE);
429 gtk_widget_hide (priv->vbox_details);
430 gtk_widget_hide (priv->frame_no_protocol);
431 gtk_widget_show (priv->frame_new_account);
433 /* If we have no account, no need of a back button */
434 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
435 gtk_widget_show (priv->button_back);
437 gtk_widget_hide (priv->button_back);
439 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
440 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
442 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
443 gtk_widget_grab_focus (priv->combobox_protocol);
447 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
448 const gchar *primary_text,
449 const gchar *secondary_text,
450 GCallback response_callback,
452 const gchar *first_button_text,
456 GtkWidget *message_dialog;
457 const gchar *button_text;
458 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
460 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
461 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
462 GTK_MESSAGE_QUESTION,
466 gtk_message_dialog_format_secondary_text (
467 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
469 va_start (button_args, first_button_text);
470 for (button_text = first_button_text;
472 button_text = va_arg (button_args, const gchar *))
475 response_id = va_arg (button_args, gint);
477 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
480 va_end (button_args);
482 g_signal_connect (message_dialog, "response", response_callback, user_data);
484 gtk_widget_show (message_dialog);
488 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
492 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
493 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
495 gtk_widget_destroy (GTK_WIDGET (message_dialog));
497 if (response_id == GTK_RESPONSE_YES)
499 empathy_account_widget_discard_pending_changes (
500 priv->setting_widget_object);
501 accounts_dialog_setup_ui_to_add_account (dialog);
506 get_dialog_primary_text (TpAccount *account)
510 /* Existing account */
511 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
512 tp_account_get_display_name (account));
516 /* Newly created account */
517 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
522 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
523 EmpathyAccountsDialog *dialog)
525 TpAccount *account = NULL;
527 if (accounts_dialog_has_pending_change (dialog, &account))
529 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
531 accounts_dialog_show_question_dialog (dialog,
532 question_dialog_primary_text,
533 _("You are about to create a new account, which will discard\n"
534 "your changes. Are you sure you want to proceed?"),
535 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
537 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
538 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
540 g_free (question_dialog_primary_text);
544 accounts_dialog_setup_ui_to_add_account (dialog);
549 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
550 EmpathyAccountSettings *settings)
552 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
554 if (priv->settings_ready != NULL)
556 g_signal_handler_disconnect (priv->settings_ready,
557 priv->settings_ready_id);
558 priv->settings_ready = NULL;
559 priv->settings_ready_id = 0;
566 GtkTreeSelection *selection;
568 view = GTK_TREE_VIEW (priv->treeview);
569 model = gtk_tree_view_get_model (view);
570 selection = gtk_tree_view_get_selection (view);
572 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
574 /* We have configured accounts, select the first one if there
575 * is no other account selected already. */
576 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
577 accounts_dialog_model_select_first (dialog);
581 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
583 /* We have no account configured but we have some
584 * profiles installed. The user obviously wants to add
585 * an account. Click on the Add button for him. */
586 accounts_dialog_button_add_clicked_cb (priv->button_add,
591 /* No account and no profile, warn the user */
592 gtk_widget_hide (priv->vbox_details);
593 gtk_widget_hide (priv->frame_new_account);
594 gtk_widget_show (priv->frame_no_protocol);
595 gtk_widget_set_sensitive (priv->button_add, FALSE);
599 /* We have an account selected, destroy old settings and create a new
600 * one for the account selected */
601 gtk_widget_hide (priv->frame_new_account);
602 gtk_widget_hide (priv->frame_no_protocol);
603 gtk_widget_show (priv->vbox_details);
604 gtk_widget_set_sensitive (priv->button_add, TRUE);
606 if (priv->settings_widget)
608 gtk_widget_destroy (priv->settings_widget);
609 priv->settings_widget = NULL;
612 if (empathy_account_settings_is_ready (settings))
614 account_dialog_create_settings_widget (dialog, settings);
618 priv->settings_ready = settings;
619 priv->settings_ready_id =
620 g_signal_connect (settings, "notify::ready",
621 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
627 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
628 GtkCellEditable *editable,
630 EmpathyAccountsDialog *dialog)
632 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
634 if (priv->connecting_id)
635 g_source_remove (priv->connecting_id);
637 DEBUG ("Editing account name started; stopping flashing");
641 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
642 GtkCellRenderer *cell,
645 EmpathyAccountsDialog *dialog)
647 EmpathyAccountSettings *settings;
650 TpConnectionStatus status;
651 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
653 gtk_tree_model_get (model, iter,
655 COL_ACCOUNT_SETTINGS_POINTER, &settings,
658 icon_name = empathy_account_settings_get_icon_name (settings);
659 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
663 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
664 (status == TP_CONNECTION_STATUS_CONNECTING &&
665 !priv->connecting_show))
667 GdkPixbuf *modded_pixbuf;
669 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
672 gdk_pixbuf_get_width (pixbuf),
673 gdk_pixbuf_get_height (pixbuf));
675 gdk_pixbuf_saturate_and_pixelate (pixbuf,
679 g_object_unref (pixbuf);
680 pixbuf = modded_pixbuf;
689 g_object_unref (settings);
692 g_object_unref (pixbuf);
696 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
701 gtk_tree_model_row_changed (model, path, iter);
707 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
711 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
713 priv->connecting_show = !priv->connecting_show;
715 view = GTK_TREE_VIEW (priv->treeview);
716 model = gtk_tree_view_get_model (view);
718 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
724 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
727 EmpathyAccountsDialog *dialog)
729 EmpathyAccountSettings *settings;
731 GtkTreePath *treepath;
733 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
736 empathy_account_manager_get_accounts_connected (&connecting);
740 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
741 (GSourceFunc) accounts_dialog_flash_connecting_cb,
745 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
746 treepath = gtk_tree_path_new_from_string (path);
747 gtk_tree_model_get_iter (model, &iter, treepath);
748 gtk_tree_model_get (model, &iter,
749 COL_ACCOUNT_SETTINGS_POINTER, &settings,
751 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
754 gtk_tree_path_free (treepath);
756 empathy_account_settings_set_display_name_async (settings, new_text,
758 g_object_set (settings, "display-name-overridden", TRUE, NULL);
759 g_object_unref (settings);
763 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
770 GtkTreeSelection *selection;
771 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
772 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
774 if (response_id == GTK_RESPONSE_YES)
776 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
778 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
781 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
785 tp_account_remove_async (account, NULL, NULL);
786 g_object_unref (account);
790 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
791 accounts_dialog_model_select_first (account_dialog);
794 gtk_widget_destroy (GTK_WIDGET (message_dialog));
798 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
799 const gchar *path_string,
800 EmpathyAccountsDialog *dialog)
805 gchar *question_dialog_primary_text;
806 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
808 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
810 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
813 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
815 if (account == NULL || !tp_account_is_valid (account))
817 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
818 accounts_dialog_model_select_first (dialog);
822 question_dialog_primary_text = g_strdup_printf (
824 _("You are about to remove your %s account!\n"
825 "Are you sure you want to proceed?"),
827 /* Translators: this is used only when built on a moblin platform */
828 _("Do you want to remove %s from your computer?"),
829 #endif /* HAVE_MOBLIN */
830 tp_account_get_display_name (account));
832 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
834 _("Any associated conversations and chat rooms will NOT be "
835 "removed if you decide to proceed.\n"
837 "Should you decide to add the account back at a later time, "
838 "they will still be available."),
840 /* Translators: this is used only when built on a moblin platform */
841 _("This will not remove your account on the server."),
842 #endif /* HAVE_MOBLIN */
843 G_CALLBACK (accounts_dialog_delete_account_response_cb),
845 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
846 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
848 g_free (question_dialog_primary_text);
852 g_object_unref (account);
858 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
861 GtkTreeViewColumn *column;
862 GtkCellRenderer *cell;
863 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
865 view = GTK_TREE_VIEW (priv->treeview);
866 gtk_tree_view_set_headers_visible (view, FALSE);
869 column = gtk_tree_view_column_new ();
870 gtk_tree_view_column_set_expand (column, TRUE);
871 gtk_tree_view_append_column (view, column);
874 cell = gtk_cell_renderer_pixbuf_new ();
875 gtk_tree_view_column_pack_start (column, cell, FALSE);
876 gtk_tree_view_column_set_cell_data_func (column, cell,
877 (GtkTreeCellDataFunc)
878 accounts_dialog_model_pixbuf_data_func,
882 g_object_set (cell, "ypad", 4, NULL);
886 cell = gtk_cell_renderer_text_new ();
888 "ellipsize", PANGO_ELLIPSIZE_END,
892 gtk_tree_view_column_pack_start (column, cell, TRUE);
893 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
894 g_signal_connect (cell, "edited",
895 G_CALLBACK (accounts_dialog_name_edited_cb),
897 g_signal_connect (cell, "editing-started",
898 G_CALLBACK (accounts_dialog_name_editing_started_cb),
902 cell = empathy_cell_renderer_activatable_new ();
903 gtk_tree_view_column_pack_start (column, cell, FALSE);
905 "icon-name", GTK_STOCK_DELETE,
907 "show-on-select", TRUE,
911 g_signal_connect (cell, "path-activated",
912 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
916 static EmpathyAccountSettings *
917 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
921 GtkTreeSelection *selection;
923 EmpathyAccountSettings *settings;
924 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
926 view = GTK_TREE_VIEW (priv->treeview);
927 selection = gtk_tree_view_get_selection (view);
929 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
932 gtk_tree_model_get (model, &iter,
933 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
939 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
940 EmpathyAccountsDialog *dialog)
942 EmpathyAccountSettings *settings;
945 gboolean is_selection;
947 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
949 settings = accounts_dialog_model_get_selected_settings (dialog);
950 accounts_dialog_update_settings (dialog, settings);
952 if (settings != NULL)
953 g_object_unref (settings);
957 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
961 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
962 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
964 gtk_widget_destroy (GTK_WIDGET (message_dialog));
966 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
968 /* The user wants to lose unsaved changes to the currently selected
969 * account and select another account. We discard the changes and
970 * select the other account. */
972 GtkTreeSelection *selection;
974 priv->force_change_row = TRUE;
975 empathy_account_widget_discard_pending_changes (
976 priv->setting_widget_object);
978 path = gtk_tree_row_reference_get_path (priv->destination_row);
979 selection = gtk_tree_view_get_selection (
980 GTK_TREE_VIEW (priv->treeview));
984 /* This will trigger a call to
985 * accounts_dialog_account_selection_change() */
986 gtk_tree_selection_select_path (selection, path);
987 gtk_tree_path_free (path);
990 gtk_tree_row_reference_free (priv->destination_row);
994 priv->force_change_row = FALSE;
999 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1000 GtkTreeModel *model,
1002 gboolean path_currently_selected,
1005 TpAccount *account = NULL;
1006 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1007 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1009 if (priv->force_change_row)
1011 /* We came back here because the user wants to discard changes to his
1012 * modified account. The changes have already been discarded so we
1013 * just change the selected row. */
1014 priv->force_change_row = FALSE;
1018 if (accounts_dialog_has_pending_change (dialog, &account))
1020 /* The currently selected account has some unsaved changes. We ask
1021 * the user if he really wants to lose his changes and select another
1023 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1024 priv->destination_row = gtk_tree_row_reference_new (model, path);
1026 accounts_dialog_show_question_dialog (dialog,
1027 question_dialog_primary_text,
1028 _("You are about to select another account, which will discard\n"
1029 "your changes. Are you sure you want to proceed?"),
1030 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1032 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1033 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1035 g_free (question_dialog_primary_text);
1046 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1048 GtkListStore *store;
1049 GtkTreeSelection *selection;
1050 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1052 store = gtk_list_store_new (COL_COUNT,
1053 G_TYPE_STRING, /* name */
1054 G_TYPE_UINT, /* status */
1055 TP_TYPE_ACCOUNT, /* account */
1056 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1058 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1059 GTK_TREE_MODEL (store));
1061 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1062 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1063 gtk_tree_selection_set_select_function (selection,
1064 accounts_dialog_account_selection_change, dialog, NULL);
1066 g_signal_connect (selection, "changed",
1067 G_CALLBACK (accounts_dialog_model_selection_changed),
1070 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1071 COL_NAME, GTK_SORT_ASCENDING);
1073 accounts_dialog_model_add_columns (dialog);
1075 g_object_unref (store);
1079 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1080 EmpathyAccountSettings *settings,
1084 GtkTreeSelection *selection;
1085 GtkTreeModel *model;
1087 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1089 /* Update the status in the model */
1090 view = GTK_TREE_VIEW (priv->treeview);
1091 selection = gtk_tree_view_get_selection (view);
1092 model = gtk_tree_view_get_model (view);
1094 for (ok = gtk_tree_model_get_iter_first (model, iter);
1096 ok = gtk_tree_model_iter_next (model, iter))
1098 EmpathyAccountSettings *this_settings;
1101 gtk_tree_model_get (model, iter,
1102 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1105 equal = (this_settings == settings);
1106 g_object_unref (this_settings);
1116 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1121 GtkTreeSelection *selection;
1122 GtkTreeModel *model;
1124 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1126 /* Update the status in the model */
1127 view = GTK_TREE_VIEW (priv->treeview);
1128 selection = gtk_tree_view_get_selection (view);
1129 model = gtk_tree_view_get_model (view);
1131 for (ok = gtk_tree_model_get_iter_first (model, iter);
1133 ok = gtk_tree_model_iter_next (model, iter))
1135 EmpathyAccountSettings *settings;
1138 gtk_tree_model_get (model, iter,
1139 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1142 equal = empathy_account_settings_has_account (settings, account);
1143 g_object_unref (settings);
1153 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1154 EmpathyAccountSettings *settings)
1156 GtkTreeSelection *selection;
1158 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1160 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1161 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1162 gtk_tree_selection_select_iter (selection, &iter);
1165 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1166 EmpathyAccountSettings *settings)
1168 GtkTreeModel *model;
1171 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1173 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1174 name = empathy_account_settings_get_display_name (settings);
1176 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1178 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1180 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1181 COL_ACCOUNT_SETTINGS_POINTER, settings,
1186 accounts_dialog_connection_changed_cb (TpAccount *account,
1190 gchar *dbus_error_name,
1191 GHashTable *details,
1192 EmpathyAccountsDialog *dialog)
1194 GtkTreeModel *model;
1197 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1199 /* Update the status in the model */
1200 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1202 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1206 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1207 COL_STATUS, current,
1210 path = gtk_tree_model_get_path (model, &iter);
1211 gtk_tree_model_row_changed (model, path, &iter);
1212 gtk_tree_path_free (path);
1215 empathy_account_manager_get_accounts_connected (&found);
1217 if (!found && priv->connecting_id)
1219 g_source_remove (priv->connecting_id);
1220 priv->connecting_id = 0;
1223 if (found && !priv->connecting_id)
1224 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1225 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1230 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1234 const gchar *display_name;
1236 GtkTreeModel *model;
1237 EmpathyAccountSettings *settings;
1238 TpAccount *selected_account;
1239 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1240 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1242 display_name = tp_account_get_display_name (account);
1243 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1244 settings = accounts_dialog_model_get_selected_settings (dialog);
1245 if (settings == NULL)
1248 selected_account = empathy_account_settings_get_account (settings);
1250 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1252 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1253 COL_NAME, display_name,
1257 if (selected_account == account)
1258 accounts_dialog_update_name_label (dialog, display_name);
1260 g_object_unref (settings);
1264 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1267 EmpathyAccountSettings *settings;
1268 GtkTreeModel *model;
1270 TpConnectionStatus status;
1273 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1275 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1276 status = tp_account_get_connection_status (account, NULL);
1277 name = tp_account_get_display_name (account);
1278 enabled = tp_account_is_enabled (account);
1280 settings = empathy_account_settings_new_for_account (account);
1282 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1283 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1285 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1288 COL_ACCOUNT_POINTER, account,
1289 COL_ACCOUNT_SETTINGS_POINTER, settings,
1292 accounts_dialog_connection_changed_cb (account,
1295 TP_CONNECTION_STATUS_DISCONNECTED,
1300 empathy_signal_connect_weak (account, "notify::display-name",
1301 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1304 g_object_unref (settings);
1308 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1311 EmpathyAccountsDialog *dialog)
1313 accounts_dialog_add_account (dialog, account);
1317 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1319 EmpathyAccountsDialog *dialog)
1322 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1324 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1326 gtk_list_store_remove (GTK_LIST_STORE (
1327 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1332 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1336 GtkTreeModel *model;
1337 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1339 /* Update the status in the model */
1340 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1342 DEBUG ("Account %s is now %s",
1343 tp_account_get_display_name (account),
1344 enabled ? "enabled" : "disabled");
1348 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1350 EmpathyAccountsDialog *dialog)
1352 enable_or_disable_account (dialog, account, FALSE);
1356 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1358 EmpathyAccountsDialog *dialog)
1360 enable_or_disable_account (dialog, account, TRUE);
1364 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1365 EmpathyAccountsDialog *dialog)
1367 EmpathyAccountSettings *settings;
1369 const gchar *display_name;
1370 TpConnectionManager *cm;
1371 TpConnectionManagerProtocol *proto;
1372 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1375 cm = empathy_protocol_chooser_dup_selected (
1376 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1378 display_name = empathy_protocol_name_to_display_name (
1379 is_gtalk ? "gtalk" : proto->name);
1381 if (display_name == NULL)
1382 display_name = proto->name;
1384 /* Create account */
1385 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1388 str = g_strdup_printf (_("New %s account"), display_name);
1389 settings = empathy_account_settings_new (cm->name, proto->name, str);
1394 if (tp_connection_manager_protocol_can_register (proto))
1398 active = gtk_toggle_button_get_active
1399 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1401 empathy_account_settings_set_boolean (settings, "register", TRUE);
1406 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1409 accounts_dialog_add (dialog, settings);
1410 accounts_dialog_model_set_selected (dialog, settings);
1412 g_object_unref (settings);
1413 g_object_unref (cm);
1417 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1418 EmpathyAccountsDialog *dialog)
1420 EmpathyAccountSettings *settings;
1422 settings = accounts_dialog_model_get_selected_settings (dialog);
1423 accounts_dialog_update_settings (dialog, settings);
1426 g_object_unref (settings);
1430 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1431 EmpathyAccountsDialog *dialog)
1433 empathy_url_show (button, "ghelp:empathy?accounts-window");
1437 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1438 EmpathyAccountsDialog *dialog)
1440 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1441 GtkWidget *import_dialog;
1443 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1445 gtk_widget_show (import_dialog);
1449 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1453 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1455 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1457 if (response_id == GTK_RESPONSE_YES)
1458 gtk_widget_destroy (account_dialog);
1462 accounts_dialog_response_cb (GtkWidget *widget,
1464 EmpathyAccountsDialog *dialog)
1466 TpAccount *account = NULL;
1468 if (accounts_dialog_has_pending_change (dialog, &account))
1470 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1472 accounts_dialog_show_question_dialog (dialog,
1473 question_dialog_primary_text,
1474 _("You are about to close the window, which will discard\n"
1475 "your changes. Are you sure you want to proceed?"),
1476 G_CALLBACK (accounts_dialog_close_response_cb),
1478 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1479 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1481 g_free (question_dialog_primary_text);
1483 else if (response == GTK_RESPONSE_CLOSE ||
1484 response == GTK_RESPONSE_DELETE_EVENT)
1485 gtk_widget_destroy (widget);
1489 accounts_dialog_delete_event_cb (GtkWidget *widget,
1491 EmpathyAccountsDialog *dialog)
1493 /* we maunally handle responses to delete events */
1498 accounts_dialog_destroy_cb (GtkObject *obj,
1499 EmpathyAccountsDialog *dialog)
1503 g_object_unref (dialog);
1507 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1510 GtkTreeSelection *selection;
1512 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1514 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1515 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1516 gtk_tree_selection_select_iter (selection, &iter);
1520 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1522 EmpathyAccountsDialog *dialog)
1524 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1526 if (empathy_connection_managers_is_ready (cms))
1528 accounts_dialog_update_settings (dialog, NULL);
1530 if (priv->initial_selection != NULL)
1532 accounts_dialog_set_selected_account
1533 (dialog, priv->initial_selection);
1534 g_object_unref (priv->initial_selection);
1535 priv->initial_selection = NULL;
1541 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1543 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1544 GList *accounts, *l;
1546 g_signal_connect (priv->account_manager, "account-validity-changed",
1547 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1549 g_signal_connect (priv->account_manager, "account-removed",
1550 G_CALLBACK (accounts_dialog_account_removed_cb),
1552 g_signal_connect (priv->account_manager, "account-enabled",
1553 G_CALLBACK (accounts_dialog_account_enabled_cb),
1555 g_signal_connect (priv->account_manager, "account-disabled",
1556 G_CALLBACK (accounts_dialog_account_disabled_cb),
1559 /* Add existing accounts */
1560 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1561 for (l = accounts; l; l = l->next)
1563 accounts_dialog_add_account (dialog, l->data);
1565 empathy_signal_connect_weak (l->data, "status-changed",
1566 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1568 g_list_free (accounts);
1570 priv->cms = empathy_connection_managers_dup_singleton ();
1571 if (!empathy_connection_managers_is_ready (priv->cms))
1572 g_signal_connect (priv->cms, "notify::ready",
1573 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1575 accounts_dialog_model_select_first (dialog);
1579 accounts_dialog_manager_ready_cb (GObject *source_object,
1580 GAsyncResult *result,
1583 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1584 GError *error = NULL;
1586 if (!tp_account_manager_prepare_finish (manager, result, &error))
1588 DEBUG ("Failed to prepare account manager: %s", error->message);
1589 g_error_free (error);
1593 accounts_dialog_accounts_setup (user_data);
1597 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1601 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
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 "treeview", &priv->treeview,
1614 "frame_new_account", &priv->frame_new_account,
1615 "hbox_type", &priv->hbox_type,
1616 "button_create", &priv->button_create,
1617 "button_back", &priv->button_back,
1618 "radiobutton_reuse", &priv->radiobutton_reuse,
1619 "radiobutton_register", &priv->radiobutton_register,
1620 "image_type", &priv->image_type,
1621 "label_name", &priv->label_name,
1622 "button_add", &priv->button_add,
1623 "button_import", &priv->button_import,
1627 empathy_builder_connect (gui, dialog,
1628 "accounts_dialog", "response", accounts_dialog_response_cb,
1629 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1630 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1631 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1632 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1633 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1634 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1635 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1638 g_object_unref (gui);
1641 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1642 gtk_widget_hide (action_area);
1644 /* Translators: this is used only when built on a moblin platform */
1645 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1646 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1649 priv->combobox_protocol = empathy_protocol_chooser_new ();
1650 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1651 priv->combobox_protocol,
1653 gtk_widget_show (priv->combobox_protocol);
1654 g_signal_connect (priv->combobox_protocol, "changed",
1655 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1658 if (priv->parent_window)
1659 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1660 priv->parent_window);
1664 do_dispose (GObject *obj)
1666 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1667 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1669 /* Disconnect signals */
1670 g_signal_handlers_disconnect_by_func (priv->account_manager,
1671 accounts_dialog_account_validity_changed_cb,
1673 g_signal_handlers_disconnect_by_func (priv->account_manager,
1674 accounts_dialog_account_removed_cb,
1676 g_signal_handlers_disconnect_by_func (priv->account_manager,
1677 accounts_dialog_account_enabled_cb,
1679 g_signal_handlers_disconnect_by_func (priv->account_manager,
1680 accounts_dialog_account_disabled_cb,
1682 g_signal_handlers_disconnect_by_func (priv->account_manager,
1683 accounts_dialog_manager_ready_cb,
1686 if (priv->connecting_id)
1687 g_source_remove (priv->connecting_id);
1689 if (priv->account_manager != NULL)
1691 g_object_unref (priv->account_manager);
1692 priv->account_manager = NULL;
1695 if (priv->cms != NULL)
1697 g_object_unref (priv->cms);
1701 if (priv->initial_selection != NULL)
1702 g_object_unref (priv->initial_selection);
1703 priv->initial_selection = NULL;
1705 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1709 do_constructor (GType type,
1711 GObjectConstructParam *props)
1715 if (dialog_singleton)
1717 retval = G_OBJECT (dialog_singleton);
1718 g_object_ref (retval);
1723 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1724 (type, n_props, props);
1726 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1727 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1728 /* We add an extra reference that we'll release when the dialog is
1729 * destroyed (accounts_dialog_destroy_cb) */
1730 g_object_ref (retval);
1737 do_get_property (GObject *object,
1742 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1744 switch (property_id)
1747 g_value_set_object (value, priv->parent_window);
1750 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1755 do_set_property (GObject *object,
1757 const GValue *value,
1760 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1762 switch (property_id)
1765 priv->parent_window = g_value_get_object (value);
1768 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1773 do_constructed (GObject *object)
1775 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1776 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1777 gboolean import_asked;
1779 accounts_dialog_build_ui (dialog);
1780 accounts_dialog_model_setup (dialog);
1782 /* Set up signalling */
1783 priv->account_manager = tp_account_manager_dup ();
1785 tp_account_manager_prepare_async (priv->account_manager, NULL,
1786 accounts_dialog_manager_ready_cb, dialog);
1788 empathy_conf_get_bool (empathy_conf_get (),
1789 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1791 if (empathy_import_accounts_to_import ())
1793 gtk_widget_show (priv->button_import);
1797 GtkWidget *import_dialog;
1799 empathy_conf_set_bool (empathy_conf_get (),
1800 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1801 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1803 gtk_widget_show (import_dialog);
1809 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1811 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1812 GParamSpec *param_spec;
1814 oclass->constructor = do_constructor;
1815 oclass->dispose = do_dispose;
1816 oclass->constructed = do_constructed;
1817 oclass->set_property = do_set_property;
1818 oclass->get_property = do_get_property;
1820 param_spec = g_param_spec_object ("parent",
1821 "parent", "The parent window",
1823 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1824 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1826 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1830 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1832 EmpathyAccountsDialogPriv *priv;
1834 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1835 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1836 EmpathyAccountsDialogPriv);
1837 dialog->priv = priv;
1840 /* public methods */
1843 empathy_accounts_dialog_show (GtkWindow *parent,
1844 TpAccount *selected_account)
1846 EmpathyAccountsDialog *dialog;
1847 EmpathyAccountsDialogPriv *priv;
1849 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1850 "parent", parent, NULL);
1852 priv = GET_PRIV (dialog);
1854 if (selected_account)
1856 if (empathy_connection_managers_is_ready (priv->cms))
1857 accounts_dialog_set_selected_account (dialog, selected_account);
1859 /* save the selection to set it later when the cms
1862 priv->initial_selection = g_object_ref (selected_account);
1865 gtk_window_present (GTK_WINDOW (priv->window));
1866 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1867 * destroyed so we can release the ref returned by the constructor now. */
1868 g_object_unref (dialog);
1870 return priv->window;