1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
31 #include <glib/gi18n.h>
32 #include <dbus/dbus-glib.h>
34 #include <libmissioncontrol/mc-account.h>
35 #include <libmissioncontrol/mc-profile.h>
36 #include <telepathy-glib/util.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-account-manager.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
41 #include <libempathy-gtk/empathy-profile-chooser.h>
42 #include <libempathy-gtk/empathy-account-widget.h>
43 #include <libempathy-gtk/empathy-account-widget-irc.h>
44 #include <libempathy-gtk/empathy-account-widget-sip.h>
45 #include <libempathy-gtk/empathy-conf.h>
47 #include "empathy-accounts-dialog.h"
48 #include "empathy-import-dialog.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
51 #include <libempathy/empathy-debug.h>
53 /* Flashing delay for icons (milliseconds). */
54 #define FLASH_TIMEOUT 500
59 GtkWidget *alignment_settings;
61 GtkWidget *vbox_details;
62 GtkWidget *frame_no_profile;
66 GtkWidget *button_add;
67 GtkWidget *button_remove;
68 GtkWidget *button_import;
70 GtkWidget *frame_new_account;
71 GtkWidget *combobox_profile;
73 GtkWidget *button_create;
74 GtkWidget *button_back;
75 GtkWidget *radiobutton_reuse;
76 GtkWidget *radiobutton_register;
78 GtkWidget *image_type;
79 GtkWidget *label_name;
80 GtkWidget *label_type;
81 GtkWidget *settings_widget;
83 gboolean connecting_show;
86 EmpathyAccountManager *account_manager;
88 } EmpathyAccountsDialog;
98 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
100 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
101 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
102 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
103 GtkCellEditable *editable,
105 EmpathyAccountsDialog *dialog);
106 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
107 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
108 GtkCellRenderer *cell,
111 EmpathyAccountsDialog *dialog);
112 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
113 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
115 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
116 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
117 EmpathyAccountsDialog *dialog);
118 static void accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
120 static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
122 EmpathyAccountsDialog *dialog);
123 static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
125 EmpathyAccountsDialog *dialog);
126 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
130 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
131 static void accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
133 TpConnectionStatusReason reason,
134 TpConnectionStatus current,
135 TpConnectionStatus previous,
136 EmpathyAccountsDialog *dialog);
137 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
138 EmpathyAccountsDialog *dialog);
139 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
140 EmpathyAccountsDialog *dialog);
141 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
142 EmpathyAccountsDialog *dialog);
143 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
144 EmpathyAccountsDialog *dialog);
145 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
146 EmpathyAccountsDialog *dialog);
147 static void accounts_dialog_button_import_clicked_cb (GtkWidget *button,
148 EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_response_cb (GtkWidget *widget,
151 EmpathyAccountsDialog *dialog);
152 static void accounts_dialog_destroy_cb (GtkWidget *widget,
153 EmpathyAccountsDialog *dialog);
156 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
161 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
162 mc_account_get_display_name (account));
163 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
169 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
173 const gchar *config_ui;
179 view = GTK_TREE_VIEW (dialog->treeview);
180 model = gtk_tree_view_get_model (view);
182 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
183 /* We have configured accounts, select the first one */
184 accounts_dialog_model_select_first (dialog);
187 if (empathy_profile_chooser_n_profiles (
188 EMPATHY_PROFILE_CHOOSER (dialog->combobox_profile)) > 0) {
189 /* We have no account configured but we have some
190 * profiles instsalled. The user obviously wants to add
191 * an account. Click on the Add button for him. */
192 accounts_dialog_button_add_clicked_cb (dialog->button_add,
197 /* No account and no profile, warn the user */
198 gtk_widget_hide (dialog->vbox_details);
199 gtk_widget_hide (dialog->frame_new_account);
200 gtk_widget_show (dialog->frame_no_profile);
201 gtk_widget_set_sensitive (dialog->button_add, FALSE);
202 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
206 /* We have an account selected, destroy old settings and create a new
207 * one for the account selected */
208 gtk_widget_hide (dialog->frame_new_account);
209 gtk_widget_hide (dialog->frame_no_profile);
210 gtk_widget_show (dialog->vbox_details);
211 gtk_widget_set_sensitive (dialog->button_add, TRUE);
212 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
214 if (dialog->settings_widget) {
215 gtk_widget_destroy (dialog->settings_widget);
216 dialog->settings_widget = NULL;
219 profile = mc_account_get_profile (account);
220 config_ui = mc_profile_get_configuration_ui (profile);
221 if (!tp_strdiff (config_ui, "jabber")) {
222 dialog->settings_widget =
223 empathy_account_widget_jabber_new (account);
225 else if (!tp_strdiff (config_ui, "msn")) {
226 dialog ->settings_widget =
227 empathy_account_widget_msn_new (account);
229 else if (!tp_strdiff (config_ui, "local-xmpp")) {
230 dialog->settings_widget =
231 empathy_account_widget_salut_new (account);
233 else if (!tp_strdiff (config_ui, "irc")) {
234 dialog->settings_widget =
235 empathy_account_widget_irc_new (account);
237 else if (!tp_strdiff (config_ui, "icq")) {
238 dialog->settings_widget =
239 empathy_account_widget_icq_new (account);
241 else if (!tp_strdiff (config_ui, "aim")) {
242 dialog->settings_widget =
243 empathy_account_widget_aim_new (account);
245 else if (!tp_strdiff (config_ui, "yahoo")) {
246 dialog->settings_widget =
247 empathy_account_widget_yahoo_new (account);
249 else if (!tp_strdiff (config_ui, "sofiasip")) {
250 dialog->settings_widget =
251 empathy_account_widget_sip_new (account);
253 else if (!tp_strdiff (config_ui, "groupwise")) {
254 dialog->settings_widget =
255 empathy_account_widget_groupwise_new (account);
258 dialog->settings_widget =
259 empathy_account_widget_generic_new (account);
262 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
263 dialog->settings_widget);
264 gtk_widget_show (dialog->settings_widget);
267 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
268 mc_profile_get_icon_name (profile),
269 GTK_ICON_SIZE_DIALOG);
270 gtk_widget_set_tooltip_text (dialog->image_type,
271 mc_profile_get_display_name (profile));
273 accounts_dialog_update_name_label (dialog, account);
275 g_object_unref (profile);
279 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
282 GtkTreeSelection *selection;
284 store = gtk_list_store_new (COL_COUNT,
285 G_TYPE_BOOLEAN, /* enabled */
286 G_TYPE_STRING, /* name */
287 G_TYPE_UINT, /* status */
288 MC_TYPE_ACCOUNT); /* account */
290 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
291 GTK_TREE_MODEL (store));
293 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
294 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
296 g_signal_connect (selection, "changed",
297 G_CALLBACK (accounts_dialog_model_selection_changed),
300 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
301 COL_NAME, GTK_SORT_ASCENDING);
303 accounts_dialog_model_add_columns (dialog);
305 g_object_unref (store);
309 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
312 EmpathyAccountsDialog *dialog)
316 GtkTreePath *treepath;
319 if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
320 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
321 (GSourceFunc) accounts_dialog_flash_connecting_cb,
325 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
326 treepath = gtk_tree_path_new_from_string (path);
327 gtk_tree_model_get_iter (model, &iter, treepath);
328 gtk_tree_model_get (model, &iter,
329 COL_ACCOUNT_POINTER, &account,
331 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
334 gtk_tree_path_free (treepath);
336 mc_account_set_display_name (account, new_text);
337 g_object_unref (account);
341 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
343 EmpathyAccountsDialog *dialog)
347 GtkTreePath *treepath;
351 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
352 treepath = gtk_tree_path_new_from_string (path);
353 gtk_tree_model_get_iter (model, &iter, treepath);
354 gtk_tree_model_get (model, &iter,
355 COL_ACCOUNT_POINTER, &account,
357 gtk_tree_path_free (treepath);
359 enabled = mc_account_is_enabled (account);
360 mc_account_set_enabled (account, !enabled);
362 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
363 mc_account_get_display_name (account));
365 g_object_unref (account);
369 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
370 GtkCellEditable *editable,
372 EmpathyAccountsDialog *dialog)
374 if (dialog->connecting_id) {
375 g_source_remove (dialog->connecting_id);
377 DEBUG ("Editing account name started; stopping flashing");
381 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
384 GtkTreeViewColumn *column;
385 GtkCellRenderer *cell;
387 view = GTK_TREE_VIEW (dialog->treeview);
388 gtk_tree_view_set_headers_visible (view, TRUE);
391 cell = gtk_cell_renderer_toggle_new ();
392 gtk_tree_view_insert_column_with_attributes (view, -1,
395 "active", COL_ENABLED,
397 g_signal_connect (cell, "toggled",
398 G_CALLBACK (accounts_dialog_enable_toggled_cb),
402 column = gtk_tree_view_column_new ();
403 gtk_tree_view_column_set_title (column, _("Accounts"));
404 gtk_tree_view_column_set_expand (column, TRUE);
405 gtk_tree_view_append_column (view, column);
408 cell = gtk_cell_renderer_pixbuf_new ();
409 gtk_tree_view_column_pack_start (column, cell, FALSE);
410 gtk_tree_view_column_set_cell_data_func (column, cell,
411 (GtkTreeCellDataFunc)
412 accounts_dialog_model_pixbuf_data_func,
417 cell = gtk_cell_renderer_text_new ();
419 "ellipsize", PANGO_ELLIPSIZE_END,
422 gtk_tree_view_column_pack_start (column, cell, TRUE);
423 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
424 g_signal_connect (cell, "edited",
425 G_CALLBACK (accounts_dialog_name_edited_cb),
427 g_signal_connect (cell, "editing-started",
428 G_CALLBACK (accounts_dialog_name_editing_started_cb),
433 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
437 GtkTreeSelection *selection;
441 view = GTK_TREE_VIEW (dialog->treeview);
442 model = gtk_tree_view_get_model (view);
444 if (gtk_tree_model_get_iter_first (model, &iter)) {
445 selection = gtk_tree_view_get_selection (view);
446 gtk_tree_selection_select_iter (selection, &iter);
448 accounts_dialog_update_account (dialog, NULL);
453 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
454 GtkCellRenderer *cell,
457 EmpathyAccountsDialog *dialog)
460 const gchar *icon_name;
462 TpConnectionStatus status;
464 gtk_tree_model_get (model, iter,
466 COL_ACCOUNT_POINTER, &account,
469 icon_name = empathy_icon_name_from_account (account);
470 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
473 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
474 (status == TP_CONNECTION_STATUS_CONNECTING &&
475 !dialog->connecting_show)) {
476 GdkPixbuf *modded_pixbuf;
478 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
481 gdk_pixbuf_get_width (pixbuf),
482 gdk_pixbuf_get_height (pixbuf));
484 gdk_pixbuf_saturate_and_pixelate (pixbuf,
488 g_object_unref (pixbuf);
489 pixbuf = modded_pixbuf;
498 g_object_unref (account);
500 g_object_unref (pixbuf);
505 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
510 GtkTreeSelection *selection;
514 /* Update the status in the model */
515 view = GTK_TREE_VIEW (dialog->treeview);
516 selection = gtk_tree_view_get_selection (view);
517 model = gtk_tree_view_get_model (view);
519 for (ok = gtk_tree_model_get_iter_first (model, iter);
521 ok = gtk_tree_model_iter_next (model, iter)) {
522 McAccount *this_account;
525 gtk_tree_model_get (model, iter,
526 COL_ACCOUNT_POINTER, &this_account,
529 equal = empathy_account_equal (this_account, account);
530 g_object_unref (this_account);
541 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
545 GtkTreeSelection *selection;
549 view = GTK_TREE_VIEW (dialog->treeview);
550 selection = gtk_tree_view_get_selection (view);
552 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
556 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
562 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
565 GtkTreeSelection *selection;
568 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
569 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
570 gtk_tree_selection_select_iter (selection, &iter);
575 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
579 GtkTreeSelection *selection;
582 view = GTK_TREE_VIEW (dialog->treeview);
583 selection = gtk_tree_view_get_selection (view);
585 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
589 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
593 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
594 EmpathyAccountsDialog *dialog)
599 gboolean is_selection;
601 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
603 account = accounts_dialog_model_get_selected (dialog);
604 accounts_dialog_update_account (dialog, account);
607 g_object_unref (account);
612 accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
617 TpConnectionStatus status;
621 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
622 status = mission_control_get_connection_status (dialog->mc, account, NULL);
623 name = mc_account_get_display_name (account);
624 enabled = mc_account_is_enabled (account);
626 if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
627 DEBUG ("Adding new account");
628 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
631 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
632 COL_ENABLED, enabled,
635 COL_ACCOUNT_POINTER, account,
638 accounts_dialog_connection_changed_cb (dialog->account_manager,
640 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
642 TP_CONNECTION_STATUS_DISCONNECTED,
647 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
649 EmpathyAccountsDialog *dialog)
651 const gchar *current_name;
652 gchar *account_param = NULL;
654 accounts_dialog_add_or_update_account (dialog, account);
656 /* Change the display name to "%s (%s)" % (protocol, account).
657 * - The protocol is the display name of the profile.
658 * - The account should be the normalized name of the McAccount but
659 * it's not set until first connection, so we get the "account"
660 * parameter for CM that have it. */
661 current_name = mc_account_get_display_name (account);
662 mc_account_get_param_string (account, "account", &account_param);
663 if (!EMP_STR_EMPTY (account_param)) {
665 const gchar *profile_name;
668 profile = mc_account_get_profile (account);
669 profile_name = mc_profile_get_display_name (profile);
670 new_name = g_strdup_printf ("%s (%s)", profile_name,
673 DEBUG ("Setting new display name for account %s: '%s'",
674 mc_account_get_unique_name (account), new_name);
676 mc_account_set_display_name (account, new_name);
678 g_object_unref (profile);
680 /* FIXME: This CM has no account parameter, what can be done? */
682 g_free (account_param);
686 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
688 EmpathyAccountsDialog *dialog)
691 accounts_dialog_model_set_selected (dialog, account);
692 accounts_dialog_model_remove_selected (dialog);
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)
712 dialog->connecting_show = !dialog->connecting_show;
714 view = GTK_TREE_VIEW (dialog->treeview);
715 model = gtk_tree_view_get_model (view);
717 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
723 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
725 TpConnectionStatusReason reason,
726 TpConnectionStatus current,
727 TpConnectionStatus previous,
728 EmpathyAccountsDialog *dialog)
734 /* Update the status in the model */
735 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
737 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
740 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
744 path = gtk_tree_model_get_path (model, &iter);
745 gtk_tree_model_row_changed (model, path, &iter);
746 gtk_tree_path_free (path);
749 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
751 if (!found && dialog->connecting_id) {
752 g_source_remove (dialog->connecting_id);
753 dialog->connecting_id = 0;
756 if (found && !dialog->connecting_id) {
757 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
758 (GSourceFunc) accounts_dialog_flash_connecting_cb,
764 enable_or_disable_account (EmpathyAccountsDialog *dialog,
771 /* Update the status in the model */
772 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
774 DEBUG ("Account %s is now %s",
775 mc_account_get_display_name (account),
776 enabled ? "enabled" : "disabled");
778 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
779 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
780 COL_ENABLED, enabled,
786 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
788 EmpathyAccountsDialog *dialog)
790 enable_or_disable_account (dialog, account, FALSE);
794 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
796 EmpathyAccountsDialog *dialog)
798 enable_or_disable_account (dialog, account, TRUE);
802 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
804 EmpathyAccountsDialog *dialog)
806 McAccount *selected_account;
808 accounts_dialog_add_or_update_account (dialog, account);
809 selected_account = accounts_dialog_model_get_selected (dialog);
810 if (empathy_account_equal (account, selected_account)) {
811 accounts_dialog_update_name_label (dialog, account);
816 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
817 EmpathyAccountsDialog *dialog)
822 McProfileCapabilityFlags cap;
824 profile = empathy_profile_chooser_dup_selected (
825 EMPATHY_PROFILE_CHOOSER (dialog->combobox_profile));
828 account = mc_account_create (profile);
829 if (account == NULL) {
830 /* We can't display an error to the user as MC doesn't give us
831 * any clue about the reason of the failure... */
832 g_object_unref (profile);
836 /* To translator: %s is the protocol name */
837 str = g_strdup_printf (_("New %s account"),
838 mc_profile_get_display_name (profile));
839 mc_account_set_display_name (account, str);
842 cap = mc_profile_get_capabilities (profile);
843 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
846 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
848 mc_account_set_param_boolean (account, "register", TRUE);
852 accounts_dialog_add_or_update_account (dialog, account);
853 accounts_dialog_model_set_selected (dialog, account);
855 g_object_unref (account);
856 g_object_unref (profile);
860 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
861 EmpathyAccountsDialog *dialog)
865 account = accounts_dialog_model_get_selected (dialog);
866 accounts_dialog_update_account (dialog, account);
870 accounts_dialog_profile_changed_cb (GtkWidget *widget,
871 EmpathyAccountsDialog *dialog)
874 McProfileCapabilityFlags cap;
876 profile = empathy_profile_chooser_dup_selected (
877 EMPATHY_PROFILE_CHOOSER (dialog->combobox_profile));
878 cap = mc_profile_get_capabilities (profile);
880 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
881 gtk_widget_show (dialog->radiobutton_register);
882 gtk_widget_show (dialog->radiobutton_reuse);
884 gtk_widget_hide (dialog->radiobutton_register);
885 gtk_widget_hide (dialog->radiobutton_reuse);
887 g_object_unref (profile);
891 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
892 EmpathyAccountsDialog *dialog)
895 GtkTreeSelection *selection;
898 view = GTK_TREE_VIEW (dialog->treeview);
899 model = gtk_tree_view_get_model (view);
900 selection = gtk_tree_view_get_selection (view);
901 gtk_tree_selection_unselect_all (selection);
903 gtk_widget_set_sensitive (dialog->button_add, FALSE);
904 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
905 gtk_widget_hide (dialog->vbox_details);
906 gtk_widget_hide (dialog->frame_no_profile);
907 gtk_widget_show (dialog->frame_new_account);
909 /* If we have no account, no need of a back button */
910 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
911 gtk_widget_show (dialog->button_back);
913 gtk_widget_hide (dialog->button_back);
916 accounts_dialog_profile_changed_cb (dialog->radiobutton_register, dialog);
917 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
919 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
920 gtk_widget_grab_focus (dialog->combobox_profile);
924 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
925 EmpathyAccountsDialog *dialog)
927 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
931 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
932 EmpathyAccountsDialog *dialog)
935 GtkWidget *message_dialog;
938 account = accounts_dialog_model_get_selected (dialog);
940 if (!mc_account_is_complete (account)) {
941 accounts_dialog_model_remove_selected (dialog);
942 accounts_dialog_model_select_first (dialog);
945 message_dialog = gtk_message_dialog_new
946 (GTK_WINDOW (dialog->window),
947 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
948 GTK_MESSAGE_QUESTION,
950 _("You are about to remove your %s account!\n"
951 "Are you sure you want to proceed?"),
952 mc_account_get_display_name (account));
954 gtk_message_dialog_format_secondary_text
955 (GTK_MESSAGE_DIALOG (message_dialog),
956 _("Any associated conversations and chat rooms will NOT be "
957 "removed if you decide to proceed.\n"
959 "Should you decide to add the account back at a later time, "
960 "they will still be available."));
962 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
965 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
969 gtk_widget_show (message_dialog);
970 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
972 if (res == GTK_RESPONSE_YES) {
973 mc_account_delete (account);
974 accounts_dialog_model_select_first (dialog);
976 gtk_widget_destroy (message_dialog);
980 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
981 EmpathyAccountsDialog *dialog)
983 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
987 accounts_dialog_response_cb (GtkWidget *widget,
989 EmpathyAccountsDialog *dialog)
991 if (response == GTK_RESPONSE_CLOSE) {
992 gtk_widget_destroy (widget);
997 accounts_dialog_destroy_cb (GtkWidget *widget,
998 EmpathyAccountsDialog *dialog)
1000 GList *accounts, *l;
1002 /* Disconnect signals */
1003 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1004 accounts_dialog_account_added_cb,
1006 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1007 accounts_dialog_account_removed_cb,
1009 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1010 accounts_dialog_account_enabled_cb,
1012 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1013 accounts_dialog_account_disabled_cb,
1015 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1016 accounts_dialog_account_changed_cb,
1018 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1019 accounts_dialog_connection_changed_cb,
1022 /* Delete incomplete accounts */
1023 accounts = mc_accounts_list ();
1024 for (l = accounts; l; l = l->next) {
1028 if (!mc_account_is_complete (account)) {
1029 /* FIXME: Warn the user the account is not complete
1030 * and is going to be removed. */
1031 mc_account_delete (account);
1034 g_object_unref (account);
1036 g_list_free (accounts);
1038 if (dialog->connecting_id) {
1039 g_source_remove (dialog->connecting_id);
1042 g_object_unref (dialog->account_manager);
1043 g_object_unref (dialog->mc);
1049 empathy_accounts_dialog_show (GtkWindow *parent,
1050 McAccount *selected_account)
1052 static EmpathyAccountsDialog *dialog = NULL;
1055 GList *accounts, *l;
1056 gboolean import_asked;
1059 gtk_window_present (GTK_WINDOW (dialog->window));
1060 return dialog->window;
1063 dialog = g_new0 (EmpathyAccountsDialog, 1);
1065 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1067 gui = empathy_builder_get_file (filename,
1068 "accounts_dialog", &dialog->window,
1069 "vbox_details", &dialog->vbox_details,
1070 "frame_no_profile", &dialog->frame_no_profile,
1071 "alignment_settings", &dialog->alignment_settings,
1072 "treeview", &dialog->treeview,
1073 "frame_new_account", &dialog->frame_new_account,
1074 "hbox_type", &dialog->hbox_type,
1075 "button_create", &dialog->button_create,
1076 "button_back", &dialog->button_back,
1077 "radiobutton_reuse", &dialog->radiobutton_reuse,
1078 "radiobutton_register", &dialog->radiobutton_register,
1079 "image_type", &dialog->image_type,
1080 "label_name", &dialog->label_name,
1081 "button_add", &dialog->button_add,
1082 "button_remove", &dialog->button_remove,
1083 "button_import", &dialog->button_import,
1087 empathy_builder_connect (gui, dialog,
1088 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1089 "accounts_dialog", "response", accounts_dialog_response_cb,
1090 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1091 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1092 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1093 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1094 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1095 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1098 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1100 g_object_unref (gui);
1102 /* Create profile chooser */
1103 dialog->combobox_profile = empathy_profile_chooser_new ();
1104 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1105 dialog->combobox_profile,
1107 gtk_widget_show (dialog->combobox_profile);
1108 g_signal_connect (dialog->combobox_profile, "changed",
1109 G_CALLBACK (accounts_dialog_profile_changed_cb),
1112 /* Set up signalling */
1113 dialog->account_manager = empathy_account_manager_dup_singleton ();
1114 dialog->mc = empathy_mission_control_dup_singleton ();
1116 g_signal_connect (dialog->account_manager, "account-created",
1117 G_CALLBACK (accounts_dialog_account_added_cb),
1119 g_signal_connect (dialog->account_manager, "account-deleted",
1120 G_CALLBACK (accounts_dialog_account_removed_cb),
1122 g_signal_connect (dialog->account_manager, "account-enabled",
1123 G_CALLBACK (accounts_dialog_account_enabled_cb),
1125 g_signal_connect (dialog->account_manager, "account-disabled",
1126 G_CALLBACK (accounts_dialog_account_disabled_cb),
1128 g_signal_connect (dialog->account_manager, "account-changed",
1129 G_CALLBACK (accounts_dialog_account_changed_cb),
1131 g_signal_connect (dialog->account_manager, "account-connection-changed",
1132 G_CALLBACK (accounts_dialog_connection_changed_cb),
1135 accounts_dialog_model_setup (dialog);
1137 /* Add existing accounts */
1138 accounts = mc_accounts_list ();
1139 for (l = accounts; l; l = l->next) {
1140 accounts_dialog_add_or_update_account (dialog, l->data);
1141 g_object_unref (l->data);
1143 g_list_free (accounts);
1145 if (selected_account) {
1146 accounts_dialog_model_set_selected (dialog, selected_account);
1148 accounts_dialog_model_select_first (dialog);
1152 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1153 GTK_WINDOW (parent));
1156 gtk_widget_show (dialog->window);
1158 empathy_conf_get_bool (empathy_conf_get (),
1159 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1162 if (empathy_import_dialog_accounts_to_import ()) {
1164 if (!import_asked) {
1165 empathy_conf_set_bool (empathy_conf_get (),
1166 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1167 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1171 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1174 return dialog->window;