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;
81 GtkWidget *button_import;
83 GtkWidget *frame_new_account;
84 GtkWidget *combobox_protocol;
86 GtkWidget *button_create;
87 GtkWidget *button_back;
88 GtkWidget *radiobutton_reuse;
89 GtkWidget *radiobutton_register;
91 GtkWidget *image_type;
92 GtkWidget *label_name;
93 GtkWidget *label_type;
94 GtkWidget *settings_widget;
96 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
97 * his GtkWidget. It is the only reliable source we can query to know if
98 * there are any unsaved changes to the currently selected account. We can't
99 * look at the account settings because it does not contain everything that
100 * can be changed using the EmpathyAccountWidget. For instance, it does not
101 * contain the state of the "Enabled" checkbox. */
102 EmpathyAccountWidget *setting_widget_object;
104 gboolean connecting_show;
107 gulong settings_ready_id;
108 EmpathyAccountSettings *settings_ready;
110 EmpathyAccountManager *account_manager;
111 EmpathyConnectionManagers *cms;
113 GtkWindow *parent_window;
114 EmpathyAccount *initial_selection;
116 /* Those are needed when changing the selected row. When a user selects
117 * another account and there are unsaved changes on the currently selected
118 * one, a confirmation message box is presented to him. Since his answer
119 * is retrieved asynchronously, we keep some information as member of the
120 * EmpathyAccountsDialog object. */
121 gboolean force_change_row;
122 GtkTreeRowReference *destination_row;
125 } EmpathyAccountsDialogPriv;
131 COL_ACCOUNT_SETTINGS_POINTER,
139 static void accounts_dialog_account_display_name_changed_cb (
140 EmpathyAccount *account,
144 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
145 EmpathyAccountsDialog *dialog);
147 static gboolean accounts_dialog_get_settings_iter (
148 EmpathyAccountsDialog *dialog,
149 EmpathyAccountSettings *settings,
152 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
154 static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
155 EmpathyAccountSettings *settings);
157 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
158 EmpathyAccountSettings *settings);
161 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
162 const gchar *display_name)
165 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
167 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
168 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
174 empathy_account_dialog_widget_cancelled_cb (
175 EmpathyAccountWidget *widget_object,
176 EmpathyAccountsDialog *dialog)
180 GtkTreeSelection *selection;
182 EmpathyAccountSettings *settings;
183 EmpathyAccount *account;
184 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
186 view = GTK_TREE_VIEW (priv->treeview);
187 selection = gtk_tree_view_get_selection (view);
189 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
192 gtk_tree_model_get (model, &iter,
193 COL_ACCOUNT_SETTINGS_POINTER, &settings,
194 COL_ACCOUNT_POINTER, &account, -1);
196 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
200 /* We were creating an account. We remove the selected row */
201 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
205 /* We were modifying an account. We discard the changes by reloading the
206 * settings and the UI. */
207 accounts_dialog_update_settings (dialog, settings);
208 g_object_unref (account);
211 if (settings != NULL)
212 g_object_unref (settings);
216 get_default_display_name (EmpathyAccountSettings *settings)
218 const gchar *login_id;
219 const gchar *protocol, *p;
220 gchar *default_display_name;
222 login_id = empathy_account_settings_get_string (settings, "account");
223 protocol = empathy_account_settings_get_protocol (settings);
225 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
228 if (login_id != NULL)
230 if (!tp_strdiff (protocol, "irc"))
233 server = empathy_account_settings_get_string (settings, "server");
235 /* To translators: The first parameter is the login id and the
236 * second one is the server. The resulting string will be something
237 * like: "MyUserName on chat.freenode.net".
238 * You should reverse the order of these arguments if the
239 * server should come before the login id in your locale.*/
240 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
245 default_display_name = g_strdup (login_id);
248 else if (protocol != NULL)
250 /* To translators: The parameter is the protocol name. The resulting
251 * string will be something like: "Jabber Account" */
252 default_display_name = g_strdup_printf (_("%s Account"), protocol);
256 default_display_name = g_strdup (_("New account"));
259 return default_display_name;
263 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
264 EmpathyAccountsDialog *dialog)
267 EmpathyAccountSettings *settings =
268 accounts_dialog_model_get_selected_settings (dialog);
270 display_name = get_default_display_name (settings);
272 empathy_account_settings_set_display_name_async (settings,
273 display_name, NULL, NULL);
275 g_free (display_name);
277 accounts_dialog_update_settings (dialog, settings);
280 g_object_unref (settings);
284 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
285 EmpathyAccountSettings *settings)
287 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
290 priv->setting_widget_object =
291 empathy_account_widget_new_for_protocol (settings, FALSE);
293 priv->settings_widget =
294 empathy_account_widget_get_widget (priv->setting_widget_object);
296 priv->settings_widget =
297 empathy_account_widget_get_widget (priv->setting_widget_object);
298 g_signal_connect (priv->setting_widget_object, "account-created",
299 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
300 g_signal_connect (priv->setting_widget_object, "cancelled",
301 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
303 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
304 priv->settings_widget);
305 gtk_widget_show (priv->settings_widget);
307 icon_name = empathy_account_settings_get_icon_name (settings);
309 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
311 /* show the default icon; keep this in sync with the default
312 * one in empathy-accounts-dialog.ui.
314 icon_name = GTK_STOCK_CUT;
316 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
317 icon_name, GTK_ICON_SIZE_DIALOG);
318 gtk_widget_set_tooltip_text (priv->image_type,
319 empathy_protocol_name_to_display_name
320 (empathy_account_settings_get_protocol (settings)));
321 gtk_widget_show (priv->image_type);
323 accounts_dialog_update_name_label (dialog,
324 empathy_account_settings_get_display_name (settings));
328 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
330 EmpathyAccountsDialog *dialog)
332 if (empathy_account_settings_is_ready (settings))
333 account_dialog_create_settings_widget (dialog, settings);
337 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
341 GtkTreeSelection *selection;
343 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
346 view = GTK_TREE_VIEW (priv->treeview);
347 model = gtk_tree_view_get_model (view);
349 if (gtk_tree_model_get_iter_first (model, &iter))
351 selection = gtk_tree_view_get_selection (view);
352 gtk_tree_selection_select_iter (selection, &iter);
356 accounts_dialog_update_settings (dialog, NULL);
361 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
362 EmpathyAccount **account)
366 GtkTreeSelection *selection;
367 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
369 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
371 if (gtk_tree_selection_get_selected (selection, &model, &iter))
372 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
374 return *account != NULL && priv->setting_widget_object != NULL
375 && empathy_account_widget_contains_pending_changes (
376 priv->setting_widget_object);
380 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
381 EmpathyAccountsDialog *dialog)
383 TpConnectionManager *cm;
384 TpConnectionManagerProtocol *proto;
386 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
388 cm = empathy_protocol_chooser_dup_selected (
389 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
401 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
403 gtk_widget_show (priv->radiobutton_register);
404 gtk_widget_show (priv->radiobutton_reuse);
408 gtk_widget_hide (priv->radiobutton_register);
409 gtk_widget_hide (priv->radiobutton_reuse);
412 gtk_widget_hide (priv->radiobutton_register);
413 gtk_widget_hide (priv->radiobutton_reuse);
420 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
424 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
426 view = GTK_TREE_VIEW (priv->treeview);
427 model = gtk_tree_view_get_model (view);
429 gtk_widget_set_sensitive (priv->button_add, FALSE);
430 gtk_widget_hide (priv->vbox_details);
431 gtk_widget_hide (priv->frame_no_protocol);
432 gtk_widget_show (priv->frame_new_account);
434 /* If we have no account, no need of a back button */
435 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
436 gtk_widget_show (priv->button_back);
438 gtk_widget_hide (priv->button_back);
440 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
441 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
443 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
444 gtk_widget_grab_focus (priv->combobox_protocol);
448 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
449 const gchar *primary_text,
450 const gchar *secondary_text,
451 GCallback response_callback,
453 const gchar *first_button_text,
457 GtkWidget *message_dialog;
458 const gchar *button_text;
459 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
461 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
462 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
463 GTK_MESSAGE_QUESTION,
467 gtk_message_dialog_format_secondary_text (
468 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
470 va_start (button_args, first_button_text);
471 for (button_text = first_button_text;
473 button_text = va_arg (button_args, const gchar *))
476 response_id = va_arg (button_args, gint);
478 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
481 va_end (button_args);
483 g_signal_connect (message_dialog, "response", response_callback, user_data);
485 gtk_widget_show (message_dialog);
489 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
493 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
494 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
496 gtk_widget_destroy (GTK_WIDGET (message_dialog));
498 if (response_id == GTK_RESPONSE_YES)
500 empathy_account_widget_discard_pending_changes (
501 priv->setting_widget_object);
502 accounts_dialog_setup_ui_to_add_account (dialog);
507 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
508 EmpathyAccountsDialog *dialog)
510 EmpathyAccount *account = NULL;
512 if (accounts_dialog_has_pending_change (dialog, &account))
514 gchar *question_dialog_primary_text = g_strdup_printf (
515 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
516 empathy_account_get_display_name (account));
518 accounts_dialog_show_question_dialog (dialog,
519 question_dialog_primary_text,
520 _("You are about to create a new account, which will discard\n"
521 "your changes. Are you sure you want to proceed?"),
522 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
524 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
525 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
527 g_free (question_dialog_primary_text);
531 accounts_dialog_setup_ui_to_add_account (dialog);
536 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
537 EmpathyAccountSettings *settings)
539 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
541 if (priv->settings_ready != NULL)
543 g_signal_handler_disconnect (priv->settings_ready,
544 priv->settings_ready_id);
545 priv->settings_ready = NULL;
546 priv->settings_ready_id = 0;
554 view = GTK_TREE_VIEW (priv->treeview);
555 model = gtk_tree_view_get_model (view);
557 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
559 /* We have configured accounts, select the first one */
560 accounts_dialog_model_select_first (dialog);
563 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
565 /* We have no account configured but we have some
566 * profiles installed. The user obviously wants to add
567 * an account. Click on the Add button for him. */
568 accounts_dialog_button_add_clicked_cb (priv->button_add,
573 /* No account and no profile, warn the user */
574 gtk_widget_hide (priv->vbox_details);
575 gtk_widget_hide (priv->frame_new_account);
576 gtk_widget_show (priv->frame_no_protocol);
577 gtk_widget_set_sensitive (priv->button_add, FALSE);
581 /* We have an account selected, destroy old settings and create a new
582 * one for the account selected */
583 gtk_widget_hide (priv->frame_new_account);
584 gtk_widget_hide (priv->frame_no_protocol);
585 gtk_widget_show (priv->vbox_details);
586 gtk_widget_set_sensitive (priv->button_add, TRUE);
588 if (priv->settings_widget)
590 gtk_widget_destroy (priv->settings_widget);
591 priv->settings_widget = NULL;
594 if (empathy_account_settings_is_ready (settings))
596 account_dialog_create_settings_widget (dialog, settings);
600 priv->settings_ready = settings;
601 priv->settings_ready_id =
602 g_signal_connect (settings, "notify::ready",
603 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
609 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
610 GtkCellEditable *editable,
612 EmpathyAccountsDialog *dialog)
614 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
616 if (priv->connecting_id)
617 g_source_remove (priv->connecting_id);
619 DEBUG ("Editing account name started; stopping flashing");
623 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
624 GtkCellRenderer *cell,
627 EmpathyAccountsDialog *dialog)
629 EmpathyAccountSettings *settings;
632 TpConnectionStatus status;
633 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
635 gtk_tree_model_get (model, iter,
637 COL_ACCOUNT_SETTINGS_POINTER, &settings,
640 icon_name = empathy_account_settings_get_icon_name (settings);
641 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
645 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
646 (status == TP_CONNECTION_STATUS_CONNECTING &&
647 !priv->connecting_show))
649 GdkPixbuf *modded_pixbuf;
651 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
654 gdk_pixbuf_get_width (pixbuf),
655 gdk_pixbuf_get_height (pixbuf));
657 gdk_pixbuf_saturate_and_pixelate (pixbuf,
661 g_object_unref (pixbuf);
662 pixbuf = modded_pixbuf;
671 g_object_unref (settings);
674 g_object_unref (pixbuf);
678 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
683 gtk_tree_model_row_changed (model, path, iter);
689 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
693 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
695 priv->connecting_show = !priv->connecting_show;
697 view = GTK_TREE_VIEW (priv->treeview);
698 model = gtk_tree_view_get_model (view);
700 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
706 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
709 EmpathyAccountsDialog *dialog)
711 EmpathyAccountSettings *settings;
713 GtkTreePath *treepath;
715 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
717 if (empathy_account_manager_get_connecting_accounts
718 (priv->account_manager) > 0)
720 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
721 (GSourceFunc) accounts_dialog_flash_connecting_cb,
725 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
726 treepath = gtk_tree_path_new_from_string (path);
727 gtk_tree_model_get_iter (model, &iter, treepath);
728 gtk_tree_model_get (model, &iter,
729 COL_ACCOUNT_SETTINGS_POINTER, &settings,
731 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
734 gtk_tree_path_free (treepath);
736 empathy_account_settings_set_display_name_async (settings, new_text,
738 g_object_set (settings, "display-name-overridden", TRUE, NULL);
739 g_object_unref (settings);
743 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
747 EmpathyAccount *account;
750 GtkTreeSelection *selection;
751 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
752 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
754 if (response_id == GTK_RESPONSE_YES)
756 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
758 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
761 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
765 g_signal_handlers_disconnect_by_func (account,
766 accounts_dialog_account_display_name_changed_cb, account_dialog);
767 empathy_account_remove_async (account, NULL, NULL);
768 g_object_unref (account);
772 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
773 accounts_dialog_model_select_first (account_dialog);
776 gtk_widget_destroy (GTK_WIDGET (message_dialog));
780 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
781 const gchar *path_string,
782 EmpathyAccountsDialog *dialog)
784 EmpathyAccount *account;
787 gchar *question_dialog_primary_text;
788 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
790 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
792 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
795 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
797 if (account == NULL || !empathy_account_is_valid (account))
799 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
800 accounts_dialog_model_select_first (dialog);
804 question_dialog_primary_text = g_strdup_printf (
806 _("You are about to remove your %s account!\n"
807 "Are you sure you want to proceed?"),
809 /* Translators: this is used only when built on a moblin platform */
810 _("Do you want to remove %s from your computer?"),
811 #endif /* HAVE_MOBLIN */
812 empathy_account_get_display_name (account));
814 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
816 _("Any associated conversations and chat rooms will NOT be "
817 "removed if you decide to proceed.\n"
819 "Should you decide to add the account back at a later time, "
820 "they will still be available."),
822 /* Translators: this is used only when built on a moblin platform */
823 _("This will not remove your account on the server."),
824 #endif /* HAVE_MOBLIN */
825 G_CALLBACK (accounts_dialog_delete_account_response_cb),
827 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
828 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
830 g_free (question_dialog_primary_text);
834 g_object_unref (account);
840 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
843 GtkTreeViewColumn *column;
844 GtkCellRenderer *cell;
845 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
847 view = GTK_TREE_VIEW (priv->treeview);
848 gtk_tree_view_set_headers_visible (view, FALSE);
851 column = gtk_tree_view_column_new ();
852 gtk_tree_view_column_set_expand (column, TRUE);
853 gtk_tree_view_append_column (view, column);
856 cell = gtk_cell_renderer_pixbuf_new ();
857 gtk_tree_view_column_pack_start (column, cell, FALSE);
858 gtk_tree_view_column_set_cell_data_func (column, cell,
859 (GtkTreeCellDataFunc)
860 accounts_dialog_model_pixbuf_data_func,
864 g_object_set (cell, "ypad", 4, NULL);
868 cell = gtk_cell_renderer_text_new ();
870 "ellipsize", PANGO_ELLIPSIZE_END,
874 gtk_tree_view_column_pack_start (column, cell, TRUE);
875 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
876 g_signal_connect (cell, "edited",
877 G_CALLBACK (accounts_dialog_name_edited_cb),
879 g_signal_connect (cell, "editing-started",
880 G_CALLBACK (accounts_dialog_name_editing_started_cb),
884 cell = empathy_cell_renderer_activatable_new ();
885 gtk_tree_view_column_pack_start (column, cell, FALSE);
887 "icon-name", GTK_STOCK_DELETE,
889 "show-on-select", TRUE,
893 g_signal_connect (cell, "path-activated",
894 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
898 static EmpathyAccountSettings *
899 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
903 GtkTreeSelection *selection;
905 EmpathyAccountSettings *settings;
906 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
908 view = GTK_TREE_VIEW (priv->treeview);
909 selection = gtk_tree_view_get_selection (view);
911 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
914 gtk_tree_model_get (model, &iter,
915 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
921 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
922 EmpathyAccountsDialog *dialog)
924 EmpathyAccountSettings *settings;
927 gboolean is_selection;
929 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
931 settings = accounts_dialog_model_get_selected_settings (dialog);
932 accounts_dialog_update_settings (dialog, settings);
934 if (settings != NULL)
935 g_object_unref (settings);
939 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
943 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
944 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
946 gtk_widget_destroy (GTK_WIDGET (message_dialog));
948 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
950 /* The user wants to lose unsaved changes to the currently selected
951 * account and select another account. We discard the changes and
952 * select the other account. */
954 GtkTreeSelection *selection;
956 priv->force_change_row = TRUE;
957 empathy_account_widget_discard_pending_changes (
958 priv->setting_widget_object);
960 path = gtk_tree_row_reference_get_path (priv->destination_row);
961 selection = gtk_tree_view_get_selection (
962 GTK_TREE_VIEW (priv->treeview));
966 /* This will trigger a call to
967 * accounts_dialog_account_selection_change() */
968 gtk_tree_selection_select_path (selection, path);
969 gtk_tree_path_free (path);
972 gtk_tree_row_reference_free (priv->destination_row);
976 priv->force_change_row = FALSE;
981 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
984 gboolean path_currently_selected,
987 EmpathyAccount *account = NULL;
988 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
989 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
991 if (priv->force_change_row)
993 /* We came back here because the user wants to discard changes to his
994 * modified account. The changes have already been discarded so we
995 * just change the selected row. */
996 priv->force_change_row = FALSE;
1000 if (accounts_dialog_has_pending_change (dialog, &account))
1002 /* The currently selected account has some unsaved changes. We ask
1003 * the user if he really wants to lose his changes and select another
1005 gchar *question_dialog_primary_text;
1006 priv->destination_row = gtk_tree_row_reference_new (model, path);
1008 question_dialog_primary_text = g_strdup_printf (
1009 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1010 empathy_account_get_display_name (account));
1012 accounts_dialog_show_question_dialog (dialog,
1013 question_dialog_primary_text,
1014 _("You are about to select another account, which will discard\n"
1015 "your changes. Are you sure you want to proceed?"),
1016 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1018 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1019 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1021 g_free (question_dialog_primary_text);
1032 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1034 GtkListStore *store;
1035 GtkTreeSelection *selection;
1036 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1038 store = gtk_list_store_new (COL_COUNT,
1039 G_TYPE_STRING, /* name */
1040 G_TYPE_UINT, /* status */
1041 EMPATHY_TYPE_ACCOUNT, /* account */
1042 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1044 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1045 GTK_TREE_MODEL (store));
1047 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1048 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1049 gtk_tree_selection_set_select_function (selection,
1050 accounts_dialog_account_selection_change, dialog, NULL);
1052 g_signal_connect (selection, "changed",
1053 G_CALLBACK (accounts_dialog_model_selection_changed),
1056 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1057 COL_NAME, GTK_SORT_ASCENDING);
1059 accounts_dialog_model_add_columns (dialog);
1061 g_object_unref (store);
1065 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1066 EmpathyAccountSettings *settings,
1070 GtkTreeSelection *selection;
1071 GtkTreeModel *model;
1073 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1075 /* Update the status in the model */
1076 view = GTK_TREE_VIEW (priv->treeview);
1077 selection = gtk_tree_view_get_selection (view);
1078 model = gtk_tree_view_get_model (view);
1080 for (ok = gtk_tree_model_get_iter_first (model, iter);
1082 ok = gtk_tree_model_iter_next (model, iter))
1084 EmpathyAccountSettings *this_settings;
1087 gtk_tree_model_get (model, iter,
1088 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1091 equal = (this_settings == settings);
1092 g_object_unref (this_settings);
1102 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1103 EmpathyAccount *account,
1107 GtkTreeSelection *selection;
1108 GtkTreeModel *model;
1110 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1112 /* Update the status in the model */
1113 view = GTK_TREE_VIEW (priv->treeview);
1114 selection = gtk_tree_view_get_selection (view);
1115 model = gtk_tree_view_get_model (view);
1117 for (ok = gtk_tree_model_get_iter_first (model, iter);
1119 ok = gtk_tree_model_iter_next (model, iter))
1121 EmpathyAccountSettings *settings;
1124 gtk_tree_model_get (model, iter,
1125 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1128 equal = empathy_account_settings_has_account (settings, account);
1129 g_object_unref (settings);
1139 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1140 EmpathyAccountSettings *settings)
1142 GtkTreeSelection *selection;
1144 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1146 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1147 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1148 gtk_tree_selection_select_iter (selection, &iter);
1151 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1152 EmpathyAccountSettings *settings)
1154 GtkTreeModel *model;
1157 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1159 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1160 name = empathy_account_settings_get_display_name (settings);
1162 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1164 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1166 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1167 COL_ACCOUNT_SETTINGS_POINTER, settings,
1172 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1173 EmpathyAccount *account,
1174 TpConnectionStatusReason reason,
1175 TpConnectionStatus current,
1176 TpConnectionStatus previous,
1177 EmpathyAccountsDialog *dialog)
1179 GtkTreeModel *model;
1182 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1184 /* Update the status in the model */
1185 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1187 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1191 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1192 COL_STATUS, current,
1195 path = gtk_tree_model_get_path (model, &iter);
1196 gtk_tree_model_row_changed (model, path, &iter);
1197 gtk_tree_path_free (path);
1200 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1202 if (!found && priv->connecting_id)
1204 g_source_remove (priv->connecting_id);
1205 priv->connecting_id = 0;
1208 if (found && !priv->connecting_id)
1209 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1210 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1215 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1219 const gchar *display_name;
1221 GtkTreeModel *model;
1222 EmpathyAccountSettings *settings;
1223 EmpathyAccount *selected_account;
1224 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1225 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1227 display_name = empathy_account_get_display_name (account);
1228 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1229 settings = accounts_dialog_model_get_selected_settings (dialog);
1230 if (settings == NULL)
1233 selected_account = empathy_account_settings_get_account (settings);
1235 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1237 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1238 COL_NAME, display_name,
1242 if (selected_account == account)
1243 accounts_dialog_update_name_label (dialog, display_name);
1245 g_object_unref (settings);
1249 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1250 EmpathyAccount *account)
1252 EmpathyAccountSettings *settings;
1253 GtkTreeModel *model;
1255 TpConnectionStatus status;
1258 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1260 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1261 g_object_get (account, "connection-status", &status, NULL);
1262 name = empathy_account_get_display_name (account);
1263 enabled = empathy_account_is_enabled (account);
1265 settings = empathy_account_settings_new_for_account (account);
1267 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1268 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1270 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1273 COL_ACCOUNT_POINTER, account,
1274 COL_ACCOUNT_SETTINGS_POINTER, settings,
1277 accounts_dialog_connection_changed_cb (priv->account_manager,
1279 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1281 TP_CONNECTION_STATUS_DISCONNECTED,
1284 g_signal_connect (account, "notify::display-name",
1285 G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
1287 g_object_unref (settings);
1291 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1292 EmpathyAccountSettings *settings)
1294 GtkTreeModel *model;
1296 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1298 gboolean enabled = FALSE;
1299 EmpathyAccount *account;
1300 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1302 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1303 name = empathy_account_settings_get_display_name (settings);
1305 account = empathy_account_settings_get_account (settings);
1306 if (account != NULL)
1308 enabled = empathy_account_is_enabled (account);
1309 g_object_get (account, "connection-status", &status, NULL);
1312 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1313 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1316 COL_ACCOUNT_POINTER, account,
1317 COL_ACCOUNT_SETTINGS_POINTER, settings,
1322 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1323 EmpathyAccount *account,
1324 EmpathyAccountsDialog *dialog)
1326 accounts_dialog_add_account (dialog, account);
1331 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1332 EmpathyAccount *account,
1333 EmpathyAccountsDialog *dialog)
1336 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1338 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1340 g_signal_handlers_disconnect_by_func (account,
1341 accounts_dialog_account_display_name_changed_cb, dialog);
1342 gtk_list_store_remove (GTK_LIST_STORE (
1343 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1348 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1349 EmpathyAccount *account,
1352 GtkTreeModel *model;
1353 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1355 /* Update the status in the model */
1356 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1358 DEBUG ("Account %s is now %s",
1359 empathy_account_get_display_name (account),
1360 enabled ? "enabled" : "disabled");
1364 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1365 EmpathyAccount *account,
1366 EmpathyAccountsDialog *dialog)
1368 enable_or_disable_account (dialog, account, FALSE);
1372 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1373 EmpathyAccount *account,
1374 EmpathyAccountsDialog *dialog)
1376 enable_or_disable_account (dialog, account, TRUE);
1380 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1381 EmpathyAccount *account,
1382 EmpathyAccountsDialog *dialog)
1384 EmpathyAccountSettings *settings, *selected_settings;
1385 GtkTreeModel *model;
1387 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1389 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1391 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1394 gtk_tree_model_get (model, &iter,
1395 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1398 accounts_dialog_update (dialog, settings);
1399 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1401 if (settings == selected_settings)
1402 accounts_dialog_update_name_label (dialog,
1403 empathy_account_settings_get_display_name (settings));
1406 g_object_unref (settings);
1408 if (selected_settings)
1409 g_object_unref (selected_settings);
1413 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1414 EmpathyAccountsDialog *dialog)
1416 EmpathyAccountSettings *settings;
1418 const gchar *display_name;
1419 TpConnectionManager *cm;
1420 TpConnectionManagerProtocol *proto;
1421 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1424 cm = empathy_protocol_chooser_dup_selected (
1425 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1427 display_name = empathy_protocol_name_to_display_name (
1428 is_gtalk ? "gtalk" : proto->name);
1430 if (display_name == NULL)
1431 display_name = proto->name;
1433 /* Create account */
1434 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1437 str = g_strdup_printf (_("New %s account"), display_name);
1438 settings = empathy_account_settings_new (cm->name, proto->name, str);
1443 if (tp_connection_manager_protocol_can_register (proto))
1447 active = gtk_toggle_button_get_active
1448 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1450 empathy_account_settings_set_boolean (settings, "register", TRUE);
1455 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1458 accounts_dialog_add (dialog, settings);
1459 accounts_dialog_model_set_selected (dialog, settings);
1461 g_object_unref (settings);
1462 g_object_unref (cm);
1466 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1467 EmpathyAccountsDialog *dialog)
1469 EmpathyAccountSettings *settings;
1471 settings = accounts_dialog_model_get_selected_settings (dialog);
1472 accounts_dialog_update_settings (dialog, settings);
1475 g_object_unref (settings);
1479 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1480 EmpathyAccountsDialog *dialog)
1482 empathy_url_show (button, "ghelp:empathy?accounts-window");
1486 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1487 EmpathyAccountsDialog *dialog)
1489 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1490 GtkWidget *import_dialog;
1492 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1494 gtk_widget_show (import_dialog);
1498 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1502 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1504 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1506 if (response_id == GTK_RESPONSE_YES)
1507 gtk_widget_destroy (account_dialog);
1511 accounts_dialog_response_cb (GtkWidget *widget,
1513 EmpathyAccountsDialog *dialog)
1515 EmpathyAccount *account = NULL;
1517 if (accounts_dialog_has_pending_change (dialog, &account))
1519 gchar *question_dialog_primary_text;
1520 question_dialog_primary_text = g_strdup_printf (
1521 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1522 empathy_account_get_display_name (account));
1524 accounts_dialog_show_question_dialog (dialog,
1525 question_dialog_primary_text,
1526 _("You are about to close the window, which will discard\n"
1527 "your changes. Are you sure you want to proceed?"),
1528 G_CALLBACK (accounts_dialog_close_response_cb),
1530 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1531 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1533 g_free (question_dialog_primary_text);
1535 else if (response == GTK_RESPONSE_CLOSE ||
1536 response == GTK_RESPONSE_DELETE_EVENT)
1537 gtk_widget_destroy (widget);
1541 accounts_dialog_delete_event_cb (GtkWidget *widget,
1543 EmpathyAccountsDialog *dialog)
1545 /* we maunally handle responses to delete events */
1550 accounts_dialog_destroy_cb (GtkObject *obj,
1551 EmpathyAccountsDialog *dialog)
1555 g_object_unref (dialog);
1559 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1560 EmpathyAccount *account)
1562 GtkTreeSelection *selection;
1564 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1566 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1567 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1568 gtk_tree_selection_select_iter (selection, &iter);
1572 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1574 EmpathyAccountsDialog *dialog)
1576 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1578 if (empathy_connection_managers_is_ready (cms))
1580 accounts_dialog_update_settings (dialog, NULL);
1582 if (priv->initial_selection != NULL)
1584 accounts_dialog_set_selected_account
1585 (dialog, priv->initial_selection);
1586 g_object_unref (priv->initial_selection);
1587 priv->initial_selection = NULL;
1593 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1595 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1596 GList *accounts, *l;
1598 g_signal_connect (priv->account_manager, "account-created",
1599 G_CALLBACK (accounts_dialog_account_added_cb),
1601 g_signal_connect (priv->account_manager, "account-deleted",
1602 G_CALLBACK (accounts_dialog_account_removed_cb),
1604 g_signal_connect (priv->account_manager, "account-enabled",
1605 G_CALLBACK (accounts_dialog_account_enabled_cb),
1607 g_signal_connect (priv->account_manager, "account-disabled",
1608 G_CALLBACK (accounts_dialog_account_disabled_cb),
1610 g_signal_connect (priv->account_manager, "account-changed",
1611 G_CALLBACK (accounts_dialog_account_changed_cb),
1613 g_signal_connect (priv->account_manager, "account-connection-changed",
1614 G_CALLBACK (accounts_dialog_connection_changed_cb),
1617 /* Add existing accounts */
1618 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1619 for (l = accounts; l; l = l->next)
1621 accounts_dialog_add_account (dialog, l->data);
1622 g_object_unref (l->data);
1624 g_list_free (accounts);
1626 priv->cms = empathy_connection_managers_dup_singleton ();
1627 if (!empathy_connection_managers_is_ready (priv->cms))
1628 g_signal_connect (priv->cms, "notify::ready",
1629 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1631 accounts_dialog_model_select_first (dialog);
1635 accounts_dialog_manager_ready_cb (EmpathyAccountManager *manager,
1639 if (!empathy_account_manager_is_ready (manager))
1642 accounts_dialog_accounts_setup (user_data);
1646 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1650 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1652 GtkWidget *action_area;
1655 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1657 gui = empathy_builder_get_file (filename,
1658 "accounts_dialog", &priv->window,
1659 "vbox_details", &priv->vbox_details,
1660 "frame_no_protocol", &priv->frame_no_protocol,
1661 "alignment_settings", &priv->alignment_settings,
1662 "treeview", &priv->treeview,
1663 "frame_new_account", &priv->frame_new_account,
1664 "hbox_type", &priv->hbox_type,
1665 "button_create", &priv->button_create,
1666 "button_back", &priv->button_back,
1667 "radiobutton_reuse", &priv->radiobutton_reuse,
1668 "radiobutton_register", &priv->radiobutton_register,
1669 "image_type", &priv->image_type,
1670 "label_name", &priv->label_name,
1671 "button_add", &priv->button_add,
1672 "button_import", &priv->button_import,
1676 empathy_builder_connect (gui, dialog,
1677 "accounts_dialog", "response", accounts_dialog_response_cb,
1678 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1679 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1680 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1681 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1682 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1683 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1684 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1687 g_object_unref (gui);
1690 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1691 gtk_widget_hide (action_area);
1693 /* Translators: this is used only when built on a moblin platform */
1694 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1695 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1698 priv->combobox_protocol = empathy_protocol_chooser_new ();
1699 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1700 priv->combobox_protocol,
1702 gtk_widget_show (priv->combobox_protocol);
1703 g_signal_connect (priv->combobox_protocol, "changed",
1704 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1707 if (priv->parent_window)
1708 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1709 priv->parent_window);
1713 do_dispose (GObject *obj)
1715 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1716 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1718 /* Disconnect signals */
1719 g_signal_handlers_disconnect_by_func (priv->account_manager,
1720 accounts_dialog_account_added_cb,
1722 g_signal_handlers_disconnect_by_func (priv->account_manager,
1723 accounts_dialog_account_removed_cb,
1725 g_signal_handlers_disconnect_by_func (priv->account_manager,
1726 accounts_dialog_account_enabled_cb,
1728 g_signal_handlers_disconnect_by_func (priv->account_manager,
1729 accounts_dialog_account_disabled_cb,
1731 g_signal_handlers_disconnect_by_func (priv->account_manager,
1732 accounts_dialog_account_changed_cb,
1734 g_signal_handlers_disconnect_by_func (priv->account_manager,
1735 accounts_dialog_connection_changed_cb,
1737 g_signal_handlers_disconnect_by_func (priv->account_manager,
1738 accounts_dialog_manager_ready_cb,
1741 if (priv->connecting_id)
1742 g_source_remove (priv->connecting_id);
1744 if (priv->account_manager != NULL)
1746 g_object_unref (priv->account_manager);
1747 priv->account_manager = NULL;
1750 if (priv->cms != NULL)
1752 g_object_unref (priv->cms);
1756 if (priv->initial_selection != NULL)
1757 g_object_unref (priv->initial_selection);
1758 priv->initial_selection = NULL;
1760 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1764 do_constructor (GType type,
1766 GObjectConstructParam *props)
1770 if (dialog_singleton)
1772 retval = G_OBJECT (dialog_singleton);
1773 g_object_ref (retval);
1778 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1779 (type, n_props, props);
1781 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1782 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1789 do_get_property (GObject *object,
1794 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1796 switch (property_id)
1799 g_value_set_object (value, priv->parent_window);
1802 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1807 do_set_property (GObject *object,
1809 const GValue *value,
1812 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1814 switch (property_id)
1817 priv->parent_window = g_value_get_object (value);
1820 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1825 do_constructed (GObject *object)
1827 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1828 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1829 gboolean import_asked;
1831 accounts_dialog_build_ui (dialog);
1832 accounts_dialog_model_setup (dialog);
1834 /* Set up signalling */
1835 priv->account_manager = empathy_account_manager_dup_singleton ();
1837 if (!empathy_account_manager_is_ready (priv->account_manager))
1838 g_signal_connect (priv->account_manager, "notify::ready",
1839 G_CALLBACK (accounts_dialog_manager_ready_cb), dialog);
1841 accounts_dialog_accounts_setup (dialog);
1843 empathy_conf_get_bool (empathy_conf_get (),
1844 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1846 if (empathy_import_accounts_to_import ())
1848 gtk_widget_show (priv->button_import);
1852 GtkWidget *import_dialog;
1854 empathy_conf_set_bool (empathy_conf_get (),
1855 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1856 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1858 gtk_widget_show (import_dialog);
1864 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1866 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1867 GParamSpec *param_spec;
1869 oclass->constructor = do_constructor;
1870 oclass->dispose = do_dispose;
1871 oclass->constructed = do_constructed;
1872 oclass->set_property = do_set_property;
1873 oclass->get_property = do_get_property;
1875 param_spec = g_param_spec_object ("parent",
1876 "parent", "The parent window",
1878 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1879 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1881 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1885 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1887 EmpathyAccountsDialogPriv *priv;
1889 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1890 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1891 EmpathyAccountsDialogPriv);
1892 dialog->priv = priv;
1895 /* public methods */
1898 empathy_accounts_dialog_show (GtkWindow *parent,
1899 EmpathyAccount *selected_account)
1901 EmpathyAccountsDialog *dialog;
1902 EmpathyAccountsDialogPriv *priv;
1904 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1905 "parent", parent, NULL);
1907 priv = GET_PRIV (dialog);
1909 if (selected_account)
1911 if (empathy_connection_managers_is_ready (priv->cms))
1912 accounts_dialog_set_selected_account (dialog, selected_account);
1914 /* save the selection to set it later when the cms
1917 priv->initial_selection = g_object_ref (selected_account);
1920 gtk_window_present (GTK_WINDOW (priv->window));
1922 return priv->window;