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;
89 } EmpathyAccountsDialog;
99 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
100 EmpathyAccount *account);
101 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
102 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
103 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
104 GtkCellEditable *editable,
106 EmpathyAccountsDialog *dialog);
107 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
108 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
109 GtkCellRenderer *cell,
112 EmpathyAccountsDialog *dialog);
113 static EmpathyAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
114 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
115 EmpathyAccount *account);
116 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
117 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
118 EmpathyAccountsDialog *dialog);
119 static void accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
120 EmpathyAccount *account);
121 static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
122 EmpathyAccount *account,
123 EmpathyAccountsDialog *dialog);
124 static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
125 EmpathyAccount *account,
126 EmpathyAccountsDialog *dialog);
127 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
131 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
132 static void accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
133 EmpathyAccount *account,
134 TpConnectionStatusReason reason,
135 TpConnectionStatus current,
136 TpConnectionStatus previous,
137 EmpathyAccountsDialog *dialog);
138 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
139 EmpathyAccountsDialog *dialog);
140 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
143 EmpathyAccountsDialog *dialog);
144 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
145 EmpathyAccountsDialog *dialog);
146 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
147 EmpathyAccountsDialog *dialog);
150 static void accounts_dialog_button_import_clicked_cb (GtkWidget *button,
151 EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_response_cb (GtkWidget *widget,
155 EmpathyAccountsDialog *dialog);
156 static void accounts_dialog_destroy_cb (GtkWidget *widget,
157 EmpathyAccountsDialog *dialog);
160 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
161 EmpathyAccount *account)
165 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
166 empathy_account_get_display_name (account));
167 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
172 typedef GtkWidget *CreateWidget (EmpathyAccount *);
175 get_account_setup_widget (EmpathyAccount *account)
177 const gchar *cm = empathy_account_get_connection_manager (account);
178 const gchar *proto = empathy_account_get_protocol (account);
184 { "gabble", "jabber", empathy_account_widget_jabber_new},
185 { "butterfly", "msn", empathy_account_widget_msn_new},
186 { "salut", "local-xmpp", empathy_account_widget_salut_new},
187 { "idle", "irc", empathy_account_widget_irc_new},
188 { "haze", "icq", empathy_account_widget_icq_new},
189 { "haze", "aim", empathy_account_widget_aim_new},
190 { "haze", "yahoo", empathy_account_widget_yahoo_new},
191 { "haze", "groupwise", empathy_account_widget_groupwise_new},
192 { "sofiasip", "sip", empathy_account_widget_sip_new},
197 for (i = 0; dialogs[i].cm != NULL; i++) {
198 if (!tp_strdiff (cm, dialogs[i].cm)
199 && !tp_strdiff (proto, dialogs[i].proto))
200 return dialogs[i].cb(account);
203 return empathy_account_widget_generic_new (account);
208 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
209 EmpathyAccount *account)
215 view = GTK_TREE_VIEW (dialog->treeview);
216 model = gtk_tree_view_get_model (view);
218 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
219 /* We have configured accounts, select the first one */
220 accounts_dialog_model_select_first (dialog);
223 if (empathy_protocol_chooser_n_protocols (
224 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) {
225 /* We have no account configured but we have some
226 * profiles instsalled. The user obviously wants to add
227 * an account. Click on the Add button for him. */
228 accounts_dialog_button_add_clicked_cb (dialog->button_add,
233 /* No account and no profile, warn the user */
234 gtk_widget_hide (dialog->vbox_details);
235 gtk_widget_hide (dialog->frame_new_account);
236 gtk_widget_show (dialog->frame_no_protocol);
237 gtk_widget_set_sensitive (dialog->button_add, FALSE);
238 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
242 /* We have an account selected, destroy old settings and create a new
243 * one for the account selected */
244 gtk_widget_hide (dialog->frame_new_account);
245 gtk_widget_hide (dialog->frame_no_protocol);
246 gtk_widget_show (dialog->vbox_details);
247 gtk_widget_set_sensitive (dialog->button_add, TRUE);
248 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
250 if (dialog->settings_widget) {
251 gtk_widget_destroy (dialog->settings_widget);
252 dialog->settings_widget = NULL;
255 dialog->settings_widget = get_account_setup_widget (account);
257 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
258 dialog->settings_widget);
259 gtk_widget_show (dialog->settings_widget);
262 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
263 empathy_account_get_icon_name (account),
264 GTK_ICON_SIZE_DIALOG);
265 gtk_widget_set_tooltip_text (dialog->image_type,
266 empathy_account_get_protocol (account));
268 accounts_dialog_update_name_label (dialog, account);
272 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
275 GtkTreeSelection *selection;
277 store = gtk_list_store_new (COL_COUNT,
278 G_TYPE_BOOLEAN, /* enabled */
279 G_TYPE_STRING, /* name */
280 G_TYPE_UINT, /* status */
281 EMPATHY_TYPE_ACCOUNT); /* account */
283 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
284 GTK_TREE_MODEL (store));
286 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
287 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
289 g_signal_connect (selection, "changed",
290 G_CALLBACK (accounts_dialog_model_selection_changed),
293 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
294 COL_NAME, GTK_SORT_ASCENDING);
296 accounts_dialog_model_add_columns (dialog);
298 g_object_unref (store);
302 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
305 EmpathyAccountsDialog *dialog)
307 EmpathyAccount *account;
309 GtkTreePath *treepath;
312 if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
313 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
314 (GSourceFunc) accounts_dialog_flash_connecting_cb,
318 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
319 treepath = gtk_tree_path_new_from_string (path);
320 gtk_tree_model_get_iter (model, &iter, treepath);
321 gtk_tree_model_get (model, &iter,
322 COL_ACCOUNT_POINTER, &account,
324 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
327 gtk_tree_path_free (treepath);
329 empathy_account_set_display_name (account, new_text);
330 g_object_unref (account);
334 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
336 EmpathyAccountsDialog *dialog)
338 EmpathyAccount *account;
340 GtkTreePath *treepath;
344 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
345 treepath = gtk_tree_path_new_from_string (path);
346 gtk_tree_model_get_iter (model, &iter, treepath);
347 gtk_tree_model_get (model, &iter,
348 COL_ACCOUNT_POINTER, &account,
350 gtk_tree_path_free (treepath);
352 enabled = empathy_account_is_enabled (account);
353 empathy_account_set_enabled (account, !enabled);
355 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
356 empathy_account_get_display_name (account));
358 g_object_unref (account);
362 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
363 GtkCellEditable *editable,
365 EmpathyAccountsDialog *dialog)
367 if (dialog->connecting_id) {
368 g_source_remove (dialog->connecting_id);
370 DEBUG ("Editing account name started; stopping flashing");
374 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
377 GtkTreeViewColumn *column;
378 GtkCellRenderer *cell;
380 view = GTK_TREE_VIEW (dialog->treeview);
381 gtk_tree_view_set_headers_visible (view, TRUE);
384 cell = gtk_cell_renderer_toggle_new ();
385 gtk_tree_view_insert_column_with_attributes (view, -1,
388 "active", COL_ENABLED,
390 g_signal_connect (cell, "toggled",
391 G_CALLBACK (accounts_dialog_enable_toggled_cb),
395 column = gtk_tree_view_column_new ();
396 gtk_tree_view_column_set_title (column, _("Accounts"));
397 gtk_tree_view_column_set_expand (column, TRUE);
398 gtk_tree_view_append_column (view, column);
401 cell = gtk_cell_renderer_pixbuf_new ();
402 gtk_tree_view_column_pack_start (column, cell, FALSE);
403 gtk_tree_view_column_set_cell_data_func (column, cell,
404 (GtkTreeCellDataFunc)
405 accounts_dialog_model_pixbuf_data_func,
410 cell = gtk_cell_renderer_text_new ();
412 "ellipsize", PANGO_ELLIPSIZE_END,
416 gtk_tree_view_column_pack_start (column, cell, TRUE);
417 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
418 g_signal_connect (cell, "edited",
419 G_CALLBACK (accounts_dialog_name_edited_cb),
421 g_signal_connect (cell, "editing-started",
422 G_CALLBACK (accounts_dialog_name_editing_started_cb),
427 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
431 GtkTreeSelection *selection;
435 view = GTK_TREE_VIEW (dialog->treeview);
436 model = gtk_tree_view_get_model (view);
438 if (gtk_tree_model_get_iter_first (model, &iter)) {
439 selection = gtk_tree_view_get_selection (view);
440 gtk_tree_selection_select_iter (selection, &iter);
442 accounts_dialog_update_account (dialog, NULL);
447 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
448 GtkCellRenderer *cell,
451 EmpathyAccountsDialog *dialog)
453 EmpathyAccount *account;
454 const gchar *icon_name;
456 TpConnectionStatus status;
458 gtk_tree_model_get (model, iter,
460 COL_ACCOUNT_POINTER, &account,
463 icon_name = empathy_account_get_icon_name (account);
464 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
467 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
468 (status == TP_CONNECTION_STATUS_CONNECTING &&
469 !dialog->connecting_show)) {
470 GdkPixbuf *modded_pixbuf;
472 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
475 gdk_pixbuf_get_width (pixbuf),
476 gdk_pixbuf_get_height (pixbuf));
478 gdk_pixbuf_saturate_and_pixelate (pixbuf,
482 g_object_unref (pixbuf);
483 pixbuf = modded_pixbuf;
492 g_object_unref (account);
494 g_object_unref (pixbuf);
499 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
500 EmpathyAccount *account,
504 GtkTreeSelection *selection;
508 /* Update the status in the model */
509 view = GTK_TREE_VIEW (dialog->treeview);
510 selection = gtk_tree_view_get_selection (view);
511 model = gtk_tree_view_get_model (view);
513 for (ok = gtk_tree_model_get_iter_first (model, iter);
515 ok = gtk_tree_model_iter_next (model, iter)) {
516 EmpathyAccount *this_account;
519 gtk_tree_model_get (model, iter,
520 COL_ACCOUNT_POINTER, &this_account,
523 equal = empathy_account_equal (this_account, account);
524 g_object_unref (this_account);
534 static EmpathyAccount *
535 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
539 GtkTreeSelection *selection;
541 EmpathyAccount *account;
543 view = GTK_TREE_VIEW (dialog->treeview);
544 selection = gtk_tree_view_get_selection (view);
546 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
550 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
556 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
557 EmpathyAccount *account)
559 GtkTreeSelection *selection;
562 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
563 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
564 gtk_tree_selection_select_iter (selection, &iter);
569 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
573 GtkTreeSelection *selection;
576 view = GTK_TREE_VIEW (dialog->treeview);
577 selection = gtk_tree_view_get_selection (view);
579 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
583 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
587 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
588 EmpathyAccountsDialog *dialog)
590 EmpathyAccount *account;
593 gboolean is_selection;
595 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
597 account = accounts_dialog_model_get_selected (dialog);
598 accounts_dialog_update_account (dialog, account);
601 g_object_unref (account);
606 accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
607 EmpathyAccount *account)
611 TpConnectionStatus status;
615 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
616 g_object_get (account, "status", &status, NULL);
617 name = empathy_account_get_display_name (account);
618 enabled = empathy_account_is_enabled (account);
620 if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
621 DEBUG ("Adding new account");
622 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
625 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
626 COL_ENABLED, enabled,
629 COL_ACCOUNT_POINTER, account,
632 accounts_dialog_connection_changed_cb (dialog->account_manager,
634 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
636 TP_CONNECTION_STATUS_DISCONNECTED,
641 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
642 EmpathyAccount *account,
643 EmpathyAccountsDialog *dialog)
645 const gchar *current_name;
646 const gchar *account_param = NULL;
648 accounts_dialog_add_or_update_account (dialog, account);
650 /* Change the display name to "%s (%s)" % (protocol, account).
651 * - The protocol is the display name of the profile.
652 * - The account should be the normalized name of the EmpathyAccount but
653 * it's not set until first connection, so we get the "account"
654 * parameter for CM that have it. */
655 current_name = empathy_account_get_display_name (account);
656 account_param = empathy_account_get_param_string (account, "account");
657 if (!EMP_STR_EMPTY (account_param)) {
660 new_name = g_strdup_printf ("%s (%s)",
661 empathy_account_get_protocol (account),
664 DEBUG ("Setting new display name for account %s: '%s'",
665 empathy_account_get_unique_name (account), new_name);
667 empathy_account_set_display_name (account, new_name);
670 /* FIXME: This CM has no account parameter, what can be done? */
675 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
676 EmpathyAccount *account,
677 EmpathyAccountsDialog *dialog)
680 accounts_dialog_model_set_selected (dialog, account);
681 accounts_dialog_model_remove_selected (dialog);
685 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
690 gtk_tree_model_row_changed (model, path, iter);
696 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
701 dialog->connecting_show = !dialog->connecting_show;
703 view = GTK_TREE_VIEW (dialog->treeview);
704 model = gtk_tree_view_get_model (view);
706 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
712 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
713 EmpathyAccount *account,
714 TpConnectionStatusReason reason,
715 TpConnectionStatus current,
716 TpConnectionStatus previous,
717 EmpathyAccountsDialog *dialog)
723 /* Update the status in the model */
724 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
726 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
729 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
733 path = gtk_tree_model_get_path (model, &iter);
734 gtk_tree_model_row_changed (model, path, &iter);
735 gtk_tree_path_free (path);
738 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
740 if (!found && dialog->connecting_id) {
741 g_source_remove (dialog->connecting_id);
742 dialog->connecting_id = 0;
745 if (found && !dialog->connecting_id) {
746 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
747 (GSourceFunc) accounts_dialog_flash_connecting_cb,
753 enable_or_disable_account (EmpathyAccountsDialog *dialog,
754 EmpathyAccount *account,
760 /* Update the status in the model */
761 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
763 DEBUG ("Account %s is now %s",
764 empathy_account_get_display_name (account),
765 enabled ? "enabled" : "disabled");
767 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
768 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
769 COL_ENABLED, enabled,
775 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
776 EmpathyAccount *account,
777 EmpathyAccountsDialog *dialog)
779 enable_or_disable_account (dialog, account, FALSE);
783 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
784 EmpathyAccount *account,
785 EmpathyAccountsDialog *dialog)
787 enable_or_disable_account (dialog, account, TRUE);
791 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
792 EmpathyAccount *account,
793 EmpathyAccountsDialog *dialog)
795 EmpathyAccount *selected_account;
797 accounts_dialog_add_or_update_account (dialog, account);
798 selected_account = accounts_dialog_model_get_selected (dialog);
799 if (empathy_account_equal (account, selected_account)) {
800 accounts_dialog_update_name_label (dialog, account);
805 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
806 EmpathyAccountsDialog *dialog)
808 EmpathyAccount *account;
810 TpConnectionManager *cm;
811 TpConnectionManagerProtocol *proto;
813 cm = empathy_protocol_chooser_dup_selected (
814 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
817 /* To translator: %s is the protocol name */
818 str = g_strdup_printf (_("New %s account"), proto->name);
820 account = empathy_account_manager_create (dialog->account_manager,
821 cm->name, proto->name, str);
825 if (account == NULL) {
826 /* We can't display an error to the user as MC doesn't give us
827 * any clue about the reason of the failure... */
831 if (tp_connection_manager_protocol_can_register (proto)) {
834 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
836 empathy_account_set_param_boolean (account, "register", TRUE);
840 accounts_dialog_add_or_update_account (dialog, account);
841 accounts_dialog_model_set_selected (dialog, account);
843 g_object_unref (account);
848 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
849 EmpathyAccountsDialog *dialog)
851 EmpathyAccount *account;
853 account = accounts_dialog_model_get_selected (dialog);
854 accounts_dialog_update_account (dialog, account);
858 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
859 EmpathyAccountsDialog *dialog)
861 TpConnectionManager *cm;
862 TpConnectionManagerProtocol *proto;
864 cm = empathy_protocol_chooser_dup_selected (
865 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
867 if (tp_connection_manager_protocol_can_register (proto)) {
868 gtk_widget_show (dialog->radiobutton_register);
869 gtk_widget_show (dialog->radiobutton_reuse);
871 gtk_widget_hide (dialog->radiobutton_register);
872 gtk_widget_hide (dialog->radiobutton_reuse);
878 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
879 EmpathyAccountsDialog *dialog)
882 GtkTreeSelection *selection;
885 view = GTK_TREE_VIEW (dialog->treeview);
886 model = gtk_tree_view_get_model (view);
887 selection = gtk_tree_view_get_selection (view);
888 gtk_tree_selection_unselect_all (selection);
890 gtk_widget_set_sensitive (dialog->button_add, FALSE);
891 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
892 gtk_widget_hide (dialog->vbox_details);
893 gtk_widget_hide (dialog->frame_no_protocol);
894 gtk_widget_show (dialog->frame_new_account);
896 /* If we have no account, no need of a back button */
897 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
898 gtk_widget_show (dialog->button_back);
900 gtk_widget_hide (dialog->button_back);
903 accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
904 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
906 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
907 gtk_widget_grab_focus (dialog->combobox_protocol);
911 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
912 EmpathyAccountsDialog *dialog)
914 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
918 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
919 EmpathyAccountsDialog *dialog)
921 EmpathyAccount *account;
922 GtkWidget *message_dialog;
925 account = accounts_dialog_model_get_selected (dialog);
927 if (!empathy_account_is_valid (account)) {
928 accounts_dialog_model_remove_selected (dialog);
929 accounts_dialog_model_select_first (dialog);
932 message_dialog = gtk_message_dialog_new
933 (GTK_WINDOW (dialog->window),
934 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
935 GTK_MESSAGE_QUESTION,
937 _("You are about to remove your %s account!\n"
938 "Are you sure you want to proceed?"),
939 empathy_account_get_display_name (account));
941 gtk_message_dialog_format_secondary_text
942 (GTK_MESSAGE_DIALOG (message_dialog),
943 _("Any associated conversations and chat rooms will NOT be "
944 "removed if you decide to proceed.\n"
946 "Should you decide to add the account back at a later time, "
947 "they will still be available."));
949 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
952 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
956 gtk_widget_show (message_dialog);
957 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
959 if (res == GTK_RESPONSE_YES) {
960 empathy_account_manager_remove (dialog->account_manager, account);
961 accounts_dialog_model_select_first (dialog);
963 gtk_widget_destroy (message_dialog);
969 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
970 EmpathyAccountsDialog *dialog)
972 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
977 accounts_dialog_response_cb (GtkWidget *widget,
979 EmpathyAccountsDialog *dialog)
981 if (response == GTK_RESPONSE_CLOSE) {
982 gtk_widget_destroy (widget);
987 accounts_dialog_destroy_cb (GtkWidget *widget,
988 EmpathyAccountsDialog *dialog)
992 /* Disconnect signals */
993 g_signal_handlers_disconnect_by_func (dialog->account_manager,
994 accounts_dialog_account_added_cb,
996 g_signal_handlers_disconnect_by_func (dialog->account_manager,
997 accounts_dialog_account_removed_cb,
999 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1000 accounts_dialog_account_enabled_cb,
1002 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1003 accounts_dialog_account_disabled_cb,
1005 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1006 accounts_dialog_account_changed_cb,
1008 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1009 accounts_dialog_connection_changed_cb,
1012 /* Delete incomplete accounts */
1013 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1014 for (l = accounts; l; l = l->next) {
1015 EmpathyAccount *account;
1018 if (!empathy_account_is_valid (account)) {
1019 /* FIXME: Warn the user the account is not complete
1020 * and is going to be removed. */
1021 empathy_account_manager_remove (dialog->account_manager, account);
1024 g_object_unref (account);
1026 g_list_free (accounts);
1028 if (dialog->connecting_id) {
1029 g_source_remove (dialog->connecting_id);
1032 g_object_unref (dialog->account_manager);
1033 g_object_unref (dialog->mc);
1039 empathy_accounts_dialog_show (GtkWindow *parent,
1040 EmpathyAccount *selected_account)
1042 static EmpathyAccountsDialog *dialog = NULL;
1045 GList *accounts, *l;
1046 gboolean import_asked;
1049 gtk_window_present (GTK_WINDOW (dialog->window));
1050 return dialog->window;
1053 dialog = g_new0 (EmpathyAccountsDialog, 1);
1055 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1057 gui = empathy_builder_get_file (filename,
1058 "accounts_dialog", &dialog->window,
1059 "vbox_details", &dialog->vbox_details,
1060 "frame_no_protocol", &dialog->frame_no_protocol,
1061 "alignment_settings", &dialog->alignment_settings,
1062 "treeview", &dialog->treeview,
1063 "frame_new_account", &dialog->frame_new_account,
1064 "hbox_type", &dialog->hbox_type,
1065 "button_create", &dialog->button_create,
1066 "button_back", &dialog->button_back,
1067 "radiobutton_reuse", &dialog->radiobutton_reuse,
1068 "radiobutton_register", &dialog->radiobutton_register,
1069 "image_type", &dialog->image_type,
1070 "label_name", &dialog->label_name,
1071 "button_add", &dialog->button_add,
1072 "button_remove", &dialog->button_remove,
1073 "button_import", &dialog->button_import,
1077 empathy_builder_connect (gui, dialog,
1078 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1079 "accounts_dialog", "response", accounts_dialog_response_cb,
1080 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1081 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1082 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1083 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1086 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1088 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1091 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1093 g_object_unref (gui);
1095 /* Create protocol chooser */
1096 dialog->combobox_protocol = empathy_protocol_chooser_new ();
1097 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1098 dialog->combobox_protocol,
1100 gtk_widget_show (dialog->combobox_protocol);
1101 g_signal_connect (dialog->combobox_protocol, "changed",
1102 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1105 /* Set up signalling */
1106 dialog->account_manager = empathy_account_manager_dup_singleton ();
1107 dialog->mc = empathy_mission_control_dup_singleton ();
1109 g_signal_connect (dialog->account_manager, "account-created",
1110 G_CALLBACK (accounts_dialog_account_added_cb),
1112 g_signal_connect (dialog->account_manager, "account-deleted",
1113 G_CALLBACK (accounts_dialog_account_removed_cb),
1115 g_signal_connect (dialog->account_manager, "account-enabled",
1116 G_CALLBACK (accounts_dialog_account_enabled_cb),
1118 g_signal_connect (dialog->account_manager, "account-disabled",
1119 G_CALLBACK (accounts_dialog_account_disabled_cb),
1121 g_signal_connect (dialog->account_manager, "account-changed",
1122 G_CALLBACK (accounts_dialog_account_changed_cb),
1124 g_signal_connect (dialog->account_manager, "account-connection-changed",
1125 G_CALLBACK (accounts_dialog_connection_changed_cb),
1128 accounts_dialog_model_setup (dialog);
1130 /* Add existing accounts */
1131 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1132 for (l = accounts; l; l = l->next) {
1133 accounts_dialog_add_or_update_account (dialog, l->data);
1134 g_object_unref (l->data);
1136 g_list_free (accounts);
1138 if (selected_account) {
1139 accounts_dialog_model_set_selected (dialog, selected_account);
1141 accounts_dialog_model_select_first (dialog);
1145 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1146 GTK_WINDOW (parent));
1149 gtk_widget_show (dialog->window);
1151 empathy_conf_get_bool (empathy_conf_get (),
1152 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1157 if (empathy_import_dialog_accounts_to_import ()) {
1159 if (!import_asked) {
1160 empathy_conf_set_bool (empathy_conf_get (),
1161 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1162 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1166 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1170 return dialog->window;