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 <telepathy-glib/util.h>
36 #include <libempathy/empathy-utils.h>
37 #include <libempathy/empathy-account-manager.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
39 #include <libempathy-gtk/empathy-protocol-chooser.h>
40 #include <libempathy-gtk/empathy-account-widget.h>
41 #include <libempathy-gtk/empathy-account-widget-irc.h>
42 #include <libempathy-gtk/empathy-account-widget-sip.h>
43 #include <libempathy-gtk/empathy-conf.h>
45 #include "empathy-accounts-dialog.h"
48 #include "empathy-import-dialog.h"
51 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
52 #include <libempathy/empathy-debug.h>
54 /* Flashing delay for icons (milliseconds). */
55 #define FLASH_TIMEOUT 500
60 GtkWidget *alignment_settings;
62 GtkWidget *vbox_details;
63 GtkWidget *frame_no_protocol;
67 GtkWidget *button_add;
68 GtkWidget *button_remove;
69 GtkWidget *button_import;
71 GtkWidget *frame_new_account;
72 GtkWidget *combobox_protocol;
74 GtkWidget *button_create;
75 GtkWidget *button_back;
76 GtkWidget *radiobutton_reuse;
77 GtkWidget *radiobutton_register;
79 GtkWidget *image_type;
80 GtkWidget *label_name;
81 GtkWidget *label_type;
82 GtkWidget *settings_widget;
84 gboolean connecting_show;
87 EmpathyAccountManager *account_manager;
88 } EmpathyAccountsDialog;
98 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
99 EmpathyAccount *account);
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 EmpathyAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
113 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
114 EmpathyAccount *account);
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,
119 EmpathyAccount *account);
120 static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
121 EmpathyAccount *account,
122 EmpathyAccountsDialog *dialog);
123 static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
124 EmpathyAccount *account,
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,
132 EmpathyAccount *account,
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);
149 static void accounts_dialog_button_import_clicked_cb (GtkWidget *button,
150 EmpathyAccountsDialog *dialog);
152 static void accounts_dialog_response_cb (GtkWidget *widget,
154 EmpathyAccountsDialog *dialog);
155 static void accounts_dialog_destroy_cb (GtkWidget *widget,
156 EmpathyAccountsDialog *dialog);
159 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
160 EmpathyAccount *account)
164 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
165 empathy_account_get_display_name (account));
166 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
171 typedef GtkWidget *CreateWidget (EmpathyAccount *);
174 get_account_setup_widget (EmpathyAccount *account)
176 const gchar *cm = empathy_account_get_connection_manager (account);
177 const gchar *proto = empathy_account_get_protocol (account);
183 { "gabble", "jabber", empathy_account_widget_jabber_new},
184 { "butterfly", "msn", empathy_account_widget_msn_new},
185 { "salut", "local-xmpp", empathy_account_widget_salut_new},
186 { "idle", "irc", empathy_account_widget_irc_new},
187 { "haze", "icq", empathy_account_widget_icq_new},
188 { "haze", "aim", empathy_account_widget_aim_new},
189 { "haze", "yahoo", empathy_account_widget_yahoo_new},
190 { "haze", "groupwise", empathy_account_widget_groupwise_new},
191 { "sofiasip", "sip", empathy_account_widget_sip_new},
196 for (i = 0; dialogs[i].cm != NULL; i++) {
197 if (!tp_strdiff (cm, dialogs[i].cm)
198 && !tp_strdiff (proto, dialogs[i].proto))
199 return dialogs[i].cb(account);
202 return empathy_account_widget_generic_new (account);
207 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
208 EmpathyAccount *account)
214 view = GTK_TREE_VIEW (dialog->treeview);
215 model = gtk_tree_view_get_model (view);
217 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
218 /* We have configured accounts, select the first one */
219 accounts_dialog_model_select_first (dialog);
222 if (empathy_protocol_chooser_n_protocols (
223 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) {
224 /* We have no account configured but we have some
225 * profiles instsalled. The user obviously wants to add
226 * an account. Click on the Add button for him. */
227 accounts_dialog_button_add_clicked_cb (dialog->button_add,
232 /* No account and no profile, warn the user */
233 gtk_widget_hide (dialog->vbox_details);
234 gtk_widget_hide (dialog->frame_new_account);
235 gtk_widget_show (dialog->frame_no_protocol);
236 gtk_widget_set_sensitive (dialog->button_add, FALSE);
237 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
241 /* We have an account selected, destroy old settings and create a new
242 * one for the account selected */
243 gtk_widget_hide (dialog->frame_new_account);
244 gtk_widget_hide (dialog->frame_no_protocol);
245 gtk_widget_show (dialog->vbox_details);
246 gtk_widget_set_sensitive (dialog->button_add, TRUE);
247 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
249 if (dialog->settings_widget) {
250 gtk_widget_destroy (dialog->settings_widget);
251 dialog->settings_widget = NULL;
254 dialog->settings_widget = get_account_setup_widget (account);
256 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
257 dialog->settings_widget);
258 gtk_widget_show (dialog->settings_widget);
261 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
262 empathy_account_get_icon_name (account),
263 GTK_ICON_SIZE_DIALOG);
264 gtk_widget_set_tooltip_text (dialog->image_type,
265 empathy_account_get_protocol (account));
267 accounts_dialog_update_name_label (dialog, account);
271 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
274 GtkTreeSelection *selection;
276 store = gtk_list_store_new (COL_COUNT,
277 G_TYPE_BOOLEAN, /* enabled */
278 G_TYPE_STRING, /* name */
279 G_TYPE_UINT, /* status */
280 EMPATHY_TYPE_ACCOUNT); /* account */
282 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
283 GTK_TREE_MODEL (store));
285 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
286 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
288 g_signal_connect (selection, "changed",
289 G_CALLBACK (accounts_dialog_model_selection_changed),
292 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
293 COL_NAME, GTK_SORT_ASCENDING);
295 accounts_dialog_model_add_columns (dialog);
297 g_object_unref (store);
301 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
304 EmpathyAccountsDialog *dialog)
306 EmpathyAccount *account;
308 GtkTreePath *treepath;
311 if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
312 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
313 (GSourceFunc) accounts_dialog_flash_connecting_cb,
317 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
318 treepath = gtk_tree_path_new_from_string (path);
319 gtk_tree_model_get_iter (model, &iter, treepath);
320 gtk_tree_model_get (model, &iter,
321 COL_ACCOUNT_POINTER, &account,
323 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
326 gtk_tree_path_free (treepath);
328 empathy_account_set_display_name (account, new_text);
329 g_object_unref (account);
333 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
335 EmpathyAccountsDialog *dialog)
337 EmpathyAccount *account;
339 GtkTreePath *treepath;
343 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
344 treepath = gtk_tree_path_new_from_string (path);
345 gtk_tree_model_get_iter (model, &iter, treepath);
346 gtk_tree_model_get (model, &iter,
347 COL_ACCOUNT_POINTER, &account,
349 gtk_tree_path_free (treepath);
351 enabled = empathy_account_is_enabled (account);
352 empathy_account_set_enabled (account, !enabled);
354 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
355 empathy_account_get_display_name (account));
357 g_object_unref (account);
361 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
362 GtkCellEditable *editable,
364 EmpathyAccountsDialog *dialog)
366 if (dialog->connecting_id) {
367 g_source_remove (dialog->connecting_id);
369 DEBUG ("Editing account name started; stopping flashing");
373 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
376 GtkTreeViewColumn *column;
377 GtkCellRenderer *cell;
379 view = GTK_TREE_VIEW (dialog->treeview);
380 gtk_tree_view_set_headers_visible (view, TRUE);
383 cell = gtk_cell_renderer_toggle_new ();
384 gtk_tree_view_insert_column_with_attributes (view, -1,
387 "active", COL_ENABLED,
389 g_signal_connect (cell, "toggled",
390 G_CALLBACK (accounts_dialog_enable_toggled_cb),
394 column = gtk_tree_view_column_new ();
395 gtk_tree_view_column_set_title (column, _("Accounts"));
396 gtk_tree_view_column_set_expand (column, TRUE);
397 gtk_tree_view_append_column (view, column);
400 cell = gtk_cell_renderer_pixbuf_new ();
401 gtk_tree_view_column_pack_start (column, cell, FALSE);
402 gtk_tree_view_column_set_cell_data_func (column, cell,
403 (GtkTreeCellDataFunc)
404 accounts_dialog_model_pixbuf_data_func,
409 cell = gtk_cell_renderer_text_new ();
411 "ellipsize", PANGO_ELLIPSIZE_END,
415 gtk_tree_view_column_pack_start (column, cell, TRUE);
416 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
417 g_signal_connect (cell, "edited",
418 G_CALLBACK (accounts_dialog_name_edited_cb),
420 g_signal_connect (cell, "editing-started",
421 G_CALLBACK (accounts_dialog_name_editing_started_cb),
426 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
430 GtkTreeSelection *selection;
434 view = GTK_TREE_VIEW (dialog->treeview);
435 model = gtk_tree_view_get_model (view);
437 if (gtk_tree_model_get_iter_first (model, &iter)) {
438 selection = gtk_tree_view_get_selection (view);
439 gtk_tree_selection_select_iter (selection, &iter);
441 accounts_dialog_update_account (dialog, NULL);
446 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
447 GtkCellRenderer *cell,
450 EmpathyAccountsDialog *dialog)
452 EmpathyAccount *account;
453 const gchar *icon_name;
455 TpConnectionStatus status;
457 gtk_tree_model_get (model, iter,
459 COL_ACCOUNT_POINTER, &account,
462 icon_name = empathy_account_get_icon_name (account);
463 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
466 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
467 (status == TP_CONNECTION_STATUS_CONNECTING &&
468 !dialog->connecting_show)) {
469 GdkPixbuf *modded_pixbuf;
471 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
474 gdk_pixbuf_get_width (pixbuf),
475 gdk_pixbuf_get_height (pixbuf));
477 gdk_pixbuf_saturate_and_pixelate (pixbuf,
481 g_object_unref (pixbuf);
482 pixbuf = modded_pixbuf;
491 g_object_unref (account);
493 g_object_unref (pixbuf);
498 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
499 EmpathyAccount *account,
503 GtkTreeSelection *selection;
507 /* Update the status in the model */
508 view = GTK_TREE_VIEW (dialog->treeview);
509 selection = gtk_tree_view_get_selection (view);
510 model = gtk_tree_view_get_model (view);
512 for (ok = gtk_tree_model_get_iter_first (model, iter);
514 ok = gtk_tree_model_iter_next (model, iter)) {
515 EmpathyAccount *this_account;
518 gtk_tree_model_get (model, iter,
519 COL_ACCOUNT_POINTER, &this_account,
522 equal = empathy_account_equal (this_account, account);
523 g_object_unref (this_account);
533 static EmpathyAccount *
534 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
538 GtkTreeSelection *selection;
540 EmpathyAccount *account;
542 view = GTK_TREE_VIEW (dialog->treeview);
543 selection = gtk_tree_view_get_selection (view);
545 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
549 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
555 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
556 EmpathyAccount *account)
558 GtkTreeSelection *selection;
561 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
562 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
563 gtk_tree_selection_select_iter (selection, &iter);
568 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
572 GtkTreeSelection *selection;
575 view = GTK_TREE_VIEW (dialog->treeview);
576 selection = gtk_tree_view_get_selection (view);
578 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
582 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
586 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
587 EmpathyAccountsDialog *dialog)
589 EmpathyAccount *account;
592 gboolean is_selection;
594 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
596 account = accounts_dialog_model_get_selected (dialog);
597 accounts_dialog_update_account (dialog, account);
600 g_object_unref (account);
605 accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
606 EmpathyAccount *account)
610 TpConnectionStatus status;
614 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
615 g_object_get (account, "status", &status, NULL);
616 name = empathy_account_get_display_name (account);
617 enabled = empathy_account_is_enabled (account);
619 if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
620 DEBUG ("Adding new account");
621 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
624 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
625 COL_ENABLED, enabled,
628 COL_ACCOUNT_POINTER, account,
631 accounts_dialog_connection_changed_cb (dialog->account_manager,
633 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
635 TP_CONNECTION_STATUS_DISCONNECTED,
640 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
641 EmpathyAccount *account,
642 EmpathyAccountsDialog *dialog)
644 const gchar *current_name;
645 const gchar *account_param = NULL;
647 accounts_dialog_add_or_update_account (dialog, account);
649 /* Change the display name to "%s (%s)" % (protocol, account).
650 * - The protocol is the display name of the profile.
651 * - The account should be the normalized name of the EmpathyAccount but
652 * it's not set until first connection, so we get the "account"
653 * parameter for CM that have it. */
654 current_name = empathy_account_get_display_name (account);
655 account_param = empathy_account_get_param_string (account, "account");
656 if (!EMP_STR_EMPTY (account_param)) {
659 new_name = g_strdup_printf ("%s (%s)",
660 empathy_account_get_protocol (account),
663 DEBUG ("Setting new display name for account %s: '%s'",
664 empathy_account_get_unique_name (account), new_name);
666 empathy_account_set_display_name (account, new_name);
669 /* FIXME: This CM has no account parameter, what can be done? */
674 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
675 EmpathyAccount *account,
676 EmpathyAccountsDialog *dialog)
679 accounts_dialog_model_set_selected (dialog, account);
680 accounts_dialog_model_remove_selected (dialog);
684 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
689 gtk_tree_model_row_changed (model, path, iter);
695 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
700 dialog->connecting_show = !dialog->connecting_show;
702 view = GTK_TREE_VIEW (dialog->treeview);
703 model = gtk_tree_view_get_model (view);
705 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
711 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
712 EmpathyAccount *account,
713 TpConnectionStatusReason reason,
714 TpConnectionStatus current,
715 TpConnectionStatus previous,
716 EmpathyAccountsDialog *dialog)
722 /* Update the status in the model */
723 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
725 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
728 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
732 path = gtk_tree_model_get_path (model, &iter);
733 gtk_tree_model_row_changed (model, path, &iter);
734 gtk_tree_path_free (path);
737 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
739 if (!found && dialog->connecting_id) {
740 g_source_remove (dialog->connecting_id);
741 dialog->connecting_id = 0;
744 if (found && !dialog->connecting_id) {
745 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
746 (GSourceFunc) accounts_dialog_flash_connecting_cb,
752 enable_or_disable_account (EmpathyAccountsDialog *dialog,
753 EmpathyAccount *account,
759 /* Update the status in the model */
760 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
762 DEBUG ("Account %s is now %s",
763 empathy_account_get_display_name (account),
764 enabled ? "enabled" : "disabled");
766 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
767 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
768 COL_ENABLED, enabled,
774 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
775 EmpathyAccount *account,
776 EmpathyAccountsDialog *dialog)
778 enable_or_disable_account (dialog, account, FALSE);
782 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
783 EmpathyAccount *account,
784 EmpathyAccountsDialog *dialog)
786 enable_or_disable_account (dialog, account, TRUE);
790 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
791 EmpathyAccount *account,
792 EmpathyAccountsDialog *dialog)
794 EmpathyAccount *selected_account;
796 accounts_dialog_add_or_update_account (dialog, account);
797 selected_account = accounts_dialog_model_get_selected (dialog);
798 if (empathy_account_equal (account, selected_account)) {
799 accounts_dialog_update_name_label (dialog, account);
804 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
805 EmpathyAccountsDialog *dialog)
807 EmpathyAccount *account;
809 TpConnectionManager *cm;
810 TpConnectionManagerProtocol *proto;
812 cm = empathy_protocol_chooser_dup_selected (
813 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
816 /* To translator: %s is the protocol name */
817 str = g_strdup_printf (_("New %s account"), proto->name);
819 account = empathy_account_manager_create (dialog->account_manager,
820 cm->name, proto->name, str);
824 if (account == NULL) {
825 /* We can't display an error to the user as MC doesn't give us
826 * any clue about the reason of the failure... */
830 if (tp_connection_manager_protocol_can_register (proto)) {
833 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
835 empathy_account_set_param_boolean (account, "register", TRUE);
839 accounts_dialog_add_or_update_account (dialog, account);
840 accounts_dialog_model_set_selected (dialog, account);
842 g_object_unref (account);
847 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
848 EmpathyAccountsDialog *dialog)
850 EmpathyAccount *account;
852 account = accounts_dialog_model_get_selected (dialog);
853 accounts_dialog_update_account (dialog, account);
857 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
858 EmpathyAccountsDialog *dialog)
860 TpConnectionManager *cm;
861 TpConnectionManagerProtocol *proto;
863 cm = empathy_protocol_chooser_dup_selected (
864 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
866 if (tp_connection_manager_protocol_can_register (proto)) {
867 gtk_widget_show (dialog->radiobutton_register);
868 gtk_widget_show (dialog->radiobutton_reuse);
870 gtk_widget_hide (dialog->radiobutton_register);
871 gtk_widget_hide (dialog->radiobutton_reuse);
877 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
878 EmpathyAccountsDialog *dialog)
881 GtkTreeSelection *selection;
884 view = GTK_TREE_VIEW (dialog->treeview);
885 model = gtk_tree_view_get_model (view);
886 selection = gtk_tree_view_get_selection (view);
887 gtk_tree_selection_unselect_all (selection);
889 gtk_widget_set_sensitive (dialog->button_add, FALSE);
890 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
891 gtk_widget_hide (dialog->vbox_details);
892 gtk_widget_hide (dialog->frame_no_protocol);
893 gtk_widget_show (dialog->frame_new_account);
895 /* If we have no account, no need of a back button */
896 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
897 gtk_widget_show (dialog->button_back);
899 gtk_widget_hide (dialog->button_back);
902 accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
903 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
905 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
906 gtk_widget_grab_focus (dialog->combobox_protocol);
910 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
911 EmpathyAccountsDialog *dialog)
913 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
917 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
918 EmpathyAccountsDialog *dialog)
920 EmpathyAccount *account;
921 GtkWidget *message_dialog;
924 account = accounts_dialog_model_get_selected (dialog);
926 if (!empathy_account_is_valid (account)) {
927 accounts_dialog_model_remove_selected (dialog);
928 accounts_dialog_model_select_first (dialog);
931 message_dialog = gtk_message_dialog_new
932 (GTK_WINDOW (dialog->window),
933 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
934 GTK_MESSAGE_QUESTION,
936 _("You are about to remove your %s account!\n"
937 "Are you sure you want to proceed?"),
938 empathy_account_get_display_name (account));
940 gtk_message_dialog_format_secondary_text
941 (GTK_MESSAGE_DIALOG (message_dialog),
942 _("Any associated conversations and chat rooms will NOT be "
943 "removed if you decide to proceed.\n"
945 "Should you decide to add the account back at a later time, "
946 "they will still be available."));
948 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
951 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
955 gtk_widget_show (message_dialog);
956 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
958 if (res == GTK_RESPONSE_YES) {
959 empathy_account_manager_remove (dialog->account_manager, account);
960 accounts_dialog_model_select_first (dialog);
962 gtk_widget_destroy (message_dialog);
968 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
969 EmpathyAccountsDialog *dialog)
971 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
976 accounts_dialog_response_cb (GtkWidget *widget,
978 EmpathyAccountsDialog *dialog)
980 if (response == GTK_RESPONSE_CLOSE) {
981 gtk_widget_destroy (widget);
986 accounts_dialog_destroy_cb (GtkWidget *widget,
987 EmpathyAccountsDialog *dialog)
991 /* Disconnect signals */
992 g_signal_handlers_disconnect_by_func (dialog->account_manager,
993 accounts_dialog_account_added_cb,
995 g_signal_handlers_disconnect_by_func (dialog->account_manager,
996 accounts_dialog_account_removed_cb,
998 g_signal_handlers_disconnect_by_func (dialog->account_manager,
999 accounts_dialog_account_enabled_cb,
1001 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1002 accounts_dialog_account_disabled_cb,
1004 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1005 accounts_dialog_account_changed_cb,
1007 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1008 accounts_dialog_connection_changed_cb,
1011 /* Delete incomplete accounts */
1012 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1013 for (l = accounts; l; l = l->next) {
1014 EmpathyAccount *account;
1017 if (!empathy_account_is_valid (account)) {
1018 /* FIXME: Warn the user the account is not complete
1019 * and is going to be removed. */
1020 empathy_account_manager_remove (dialog->account_manager, account);
1023 g_object_unref (account);
1025 g_list_free (accounts);
1027 if (dialog->connecting_id) {
1028 g_source_remove (dialog->connecting_id);
1031 g_object_unref (dialog->account_manager);
1037 empathy_accounts_dialog_show (GtkWindow *parent,
1038 EmpathyAccount *selected_account)
1040 static EmpathyAccountsDialog *dialog = NULL;
1043 GList *accounts, *l;
1044 gboolean import_asked;
1047 gtk_window_present (GTK_WINDOW (dialog->window));
1048 return dialog->window;
1051 dialog = g_new0 (EmpathyAccountsDialog, 1);
1053 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1055 gui = empathy_builder_get_file (filename,
1056 "accounts_dialog", &dialog->window,
1057 "vbox_details", &dialog->vbox_details,
1058 "frame_no_protocol", &dialog->frame_no_protocol,
1059 "alignment_settings", &dialog->alignment_settings,
1060 "treeview", &dialog->treeview,
1061 "frame_new_account", &dialog->frame_new_account,
1062 "hbox_type", &dialog->hbox_type,
1063 "button_create", &dialog->button_create,
1064 "button_back", &dialog->button_back,
1065 "radiobutton_reuse", &dialog->radiobutton_reuse,
1066 "radiobutton_register", &dialog->radiobutton_register,
1067 "image_type", &dialog->image_type,
1068 "label_name", &dialog->label_name,
1069 "button_add", &dialog->button_add,
1070 "button_remove", &dialog->button_remove,
1071 "button_import", &dialog->button_import,
1075 empathy_builder_connect (gui, dialog,
1076 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1077 "accounts_dialog", "response", accounts_dialog_response_cb,
1078 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1079 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1080 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1081 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1084 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1086 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1089 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1091 g_object_unref (gui);
1093 /* Create protocol chooser */
1094 dialog->combobox_protocol = empathy_protocol_chooser_new ();
1095 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1096 dialog->combobox_protocol,
1098 gtk_widget_show (dialog->combobox_protocol);
1099 g_signal_connect (dialog->combobox_protocol, "changed",
1100 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1103 /* Set up signalling */
1104 dialog->account_manager = empathy_account_manager_dup_singleton ();
1106 g_signal_connect (dialog->account_manager, "account-created",
1107 G_CALLBACK (accounts_dialog_account_added_cb),
1109 g_signal_connect (dialog->account_manager, "account-deleted",
1110 G_CALLBACK (accounts_dialog_account_removed_cb),
1112 g_signal_connect (dialog->account_manager, "account-enabled",
1113 G_CALLBACK (accounts_dialog_account_enabled_cb),
1115 g_signal_connect (dialog->account_manager, "account-disabled",
1116 G_CALLBACK (accounts_dialog_account_disabled_cb),
1118 g_signal_connect (dialog->account_manager, "account-changed",
1119 G_CALLBACK (accounts_dialog_account_changed_cb),
1121 g_signal_connect (dialog->account_manager, "account-connection-changed",
1122 G_CALLBACK (accounts_dialog_connection_changed_cb),
1125 accounts_dialog_model_setup (dialog);
1127 /* Add existing accounts */
1128 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1129 for (l = accounts; l; l = l->next) {
1130 accounts_dialog_add_or_update_account (dialog, l->data);
1131 g_object_unref (l->data);
1133 g_list_free (accounts);
1135 if (selected_account) {
1136 accounts_dialog_model_set_selected (dialog, selected_account);
1138 accounts_dialog_model_select_first (dialog);
1142 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1143 GTK_WINDOW (parent));
1146 gtk_widget_show (dialog->window);
1148 empathy_conf_get_bool (empathy_conf_get (),
1149 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1154 if (empathy_import_dialog_accounts_to_import ()) {
1156 if (!import_asked) {
1157 empathy_conf_set_bool (empathy_conf_get (),
1158 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1159 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1163 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1167 return dialog->window;