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"
46 #include "empathy-import-dialog.h"
48 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
49 #include <libempathy/empathy-debug.h>
51 /* Flashing delay for icons (milliseconds). */
52 #define FLASH_TIMEOUT 500
57 GtkWidget *alignment_settings;
59 GtkWidget *vbox_details;
60 GtkWidget *frame_no_protocol;
64 GtkWidget *button_add;
65 GtkWidget *button_remove;
66 GtkWidget *button_import;
68 GtkWidget *frame_new_account;
69 GtkWidget *combobox_protocol;
71 GtkWidget *button_create;
72 GtkWidget *button_back;
73 GtkWidget *radiobutton_reuse;
74 GtkWidget *radiobutton_register;
76 GtkWidget *image_type;
77 GtkWidget *label_name;
78 GtkWidget *label_type;
79 GtkWidget *settings_widget;
81 gboolean connecting_show;
84 EmpathyAccountManager *account_manager;
86 } EmpathyAccountsDialog;
96 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
97 EmpathyAccount *account);
98 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
99 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
100 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
101 GtkCellEditable *editable,
103 EmpathyAccountsDialog *dialog);
104 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
105 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
106 GtkCellRenderer *cell,
109 EmpathyAccountsDialog *dialog);
110 static EmpathyAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
111 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
112 EmpathyAccount *account);
113 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
114 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
115 EmpathyAccountsDialog *dialog);
116 static void accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
117 EmpathyAccount *account);
118 static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
119 EmpathyAccount *account,
120 EmpathyAccountsDialog *dialog);
121 static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
122 EmpathyAccount *account,
123 EmpathyAccountsDialog *dialog);
124 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
128 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
129 static void accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
130 EmpathyAccount *account,
131 TpConnectionStatusReason reason,
132 TpConnectionStatus current,
133 TpConnectionStatus previous,
134 EmpathyAccountsDialog *dialog);
135 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
136 EmpathyAccountsDialog *dialog);
137 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
138 EmpathyAccountsDialog *dialog);
139 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
140 EmpathyAccountsDialog *dialog);
141 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
142 EmpathyAccountsDialog *dialog);
143 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
144 EmpathyAccountsDialog *dialog);
145 static void accounts_dialog_button_import_clicked_cb (GtkWidget *button,
146 EmpathyAccountsDialog *dialog);
147 static void accounts_dialog_response_cb (GtkWidget *widget,
149 EmpathyAccountsDialog *dialog);
150 static void accounts_dialog_destroy_cb (GtkWidget *widget,
151 EmpathyAccountsDialog *dialog);
154 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
155 EmpathyAccount *account)
159 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
160 empathy_account_get_display_name (account));
161 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
166 typedef GtkWidget *CreateWidget (EmpathyAccount *);
169 get_account_setup_widget (EmpathyAccount *account)
171 const gchar *cm = empathy_account_get_connection_manager (account);
172 const gchar *proto = empathy_account_get_protocol (account);
178 { "gabble", "jabber", empathy_account_widget_jabber_new},
179 { "butterfly", "msn", empathy_account_widget_msn_new},
180 { "salut", "local-xmpp", empathy_account_widget_salut_new},
181 { "idle", "irc", empathy_account_widget_irc_new},
182 { "haze", "icq", empathy_account_widget_icq_new},
183 { "haze", "aim", empathy_account_widget_aim_new},
184 { "haze", "yahoo", empathy_account_widget_yahoo_new},
185 { "haze", "groupwise", empathy_account_widget_groupwise_new},
186 { "sofiasip", "sip", empathy_account_widget_sip_new},
191 for (i = 0; dialogs[i].cm != NULL; i++) {
192 if (!tp_strdiff (cm, dialogs[i].cm)
193 && !tp_strdiff (proto, dialogs[i].proto))
194 return dialogs[i].cb(account);
197 return empathy_account_widget_generic_new (account);
202 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
203 EmpathyAccount *account)
209 view = GTK_TREE_VIEW (dialog->treeview);
210 model = gtk_tree_view_get_model (view);
212 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
213 /* We have configured accounts, select the first one */
214 accounts_dialog_model_select_first (dialog);
217 if (empathy_protocol_chooser_n_protocols (
218 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) {
219 /* We have no account configured but we have some
220 * profiles instsalled. The user obviously wants to add
221 * an account. Click on the Add button for him. */
222 accounts_dialog_button_add_clicked_cb (dialog->button_add,
227 /* No account and no profile, warn the user */
228 gtk_widget_hide (dialog->vbox_details);
229 gtk_widget_hide (dialog->frame_new_account);
230 gtk_widget_show (dialog->frame_no_protocol);
231 gtk_widget_set_sensitive (dialog->button_add, FALSE);
232 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
236 /* We have an account selected, destroy old settings and create a new
237 * one for the account selected */
238 gtk_widget_hide (dialog->frame_new_account);
239 gtk_widget_hide (dialog->frame_no_protocol);
240 gtk_widget_show (dialog->vbox_details);
241 gtk_widget_set_sensitive (dialog->button_add, TRUE);
242 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
244 if (dialog->settings_widget) {
245 gtk_widget_destroy (dialog->settings_widget);
246 dialog->settings_widget = NULL;
249 dialog->settings_widget = get_account_setup_widget (account);
251 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
252 dialog->settings_widget);
253 gtk_widget_show (dialog->settings_widget);
256 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
257 empathy_account_get_icon_name (account),
258 GTK_ICON_SIZE_DIALOG);
259 gtk_widget_set_tooltip_text (dialog->image_type,
260 empathy_account_get_protocol (account));
262 accounts_dialog_update_name_label (dialog, account);
266 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
269 GtkTreeSelection *selection;
271 store = gtk_list_store_new (COL_COUNT,
272 G_TYPE_BOOLEAN, /* enabled */
273 G_TYPE_STRING, /* name */
274 G_TYPE_UINT, /* status */
275 EMPATHY_TYPE_ACCOUNT); /* account */
277 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
278 GTK_TREE_MODEL (store));
280 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
281 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
283 g_signal_connect (selection, "changed",
284 G_CALLBACK (accounts_dialog_model_selection_changed),
287 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
288 COL_NAME, GTK_SORT_ASCENDING);
290 accounts_dialog_model_add_columns (dialog);
292 g_object_unref (store);
296 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
299 EmpathyAccountsDialog *dialog)
301 EmpathyAccount *account;
303 GtkTreePath *treepath;
306 if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
307 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
308 (GSourceFunc) accounts_dialog_flash_connecting_cb,
312 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
313 treepath = gtk_tree_path_new_from_string (path);
314 gtk_tree_model_get_iter (model, &iter, treepath);
315 gtk_tree_model_get (model, &iter,
316 COL_ACCOUNT_POINTER, &account,
318 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
321 gtk_tree_path_free (treepath);
323 empathy_account_set_display_name (account, new_text);
324 g_object_unref (account);
328 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
330 EmpathyAccountsDialog *dialog)
332 EmpathyAccount *account;
334 GtkTreePath *treepath;
338 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
339 treepath = gtk_tree_path_new_from_string (path);
340 gtk_tree_model_get_iter (model, &iter, treepath);
341 gtk_tree_model_get (model, &iter,
342 COL_ACCOUNT_POINTER, &account,
344 gtk_tree_path_free (treepath);
346 enabled = empathy_account_is_enabled (account);
347 empathy_account_set_enabled (account, !enabled);
349 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
350 empathy_account_get_display_name (account));
352 g_object_unref (account);
356 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
357 GtkCellEditable *editable,
359 EmpathyAccountsDialog *dialog)
361 if (dialog->connecting_id) {
362 g_source_remove (dialog->connecting_id);
364 DEBUG ("Editing account name started; stopping flashing");
368 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
371 GtkTreeViewColumn *column;
372 GtkCellRenderer *cell;
374 view = GTK_TREE_VIEW (dialog->treeview);
375 gtk_tree_view_set_headers_visible (view, TRUE);
378 cell = gtk_cell_renderer_toggle_new ();
379 gtk_tree_view_insert_column_with_attributes (view, -1,
382 "active", COL_ENABLED,
384 g_signal_connect (cell, "toggled",
385 G_CALLBACK (accounts_dialog_enable_toggled_cb),
389 column = gtk_tree_view_column_new ();
390 gtk_tree_view_column_set_title (column, _("Accounts"));
391 gtk_tree_view_column_set_expand (column, TRUE);
392 gtk_tree_view_append_column (view, column);
395 cell = gtk_cell_renderer_pixbuf_new ();
396 gtk_tree_view_column_pack_start (column, cell, FALSE);
397 gtk_tree_view_column_set_cell_data_func (column, cell,
398 (GtkTreeCellDataFunc)
399 accounts_dialog_model_pixbuf_data_func,
404 cell = gtk_cell_renderer_text_new ();
406 "ellipsize", PANGO_ELLIPSIZE_END,
410 gtk_tree_view_column_pack_start (column, cell, TRUE);
411 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
412 g_signal_connect (cell, "edited",
413 G_CALLBACK (accounts_dialog_name_edited_cb),
415 g_signal_connect (cell, "editing-started",
416 G_CALLBACK (accounts_dialog_name_editing_started_cb),
421 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
425 GtkTreeSelection *selection;
429 view = GTK_TREE_VIEW (dialog->treeview);
430 model = gtk_tree_view_get_model (view);
432 if (gtk_tree_model_get_iter_first (model, &iter)) {
433 selection = gtk_tree_view_get_selection (view);
434 gtk_tree_selection_select_iter (selection, &iter);
436 accounts_dialog_update_account (dialog, NULL);
441 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
442 GtkCellRenderer *cell,
445 EmpathyAccountsDialog *dialog)
447 EmpathyAccount *account;
448 const gchar *icon_name;
450 TpConnectionStatus status;
452 gtk_tree_model_get (model, iter,
454 COL_ACCOUNT_POINTER, &account,
457 icon_name = empathy_account_get_icon_name (account);
458 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
461 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
462 (status == TP_CONNECTION_STATUS_CONNECTING &&
463 !dialog->connecting_show)) {
464 GdkPixbuf *modded_pixbuf;
466 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
469 gdk_pixbuf_get_width (pixbuf),
470 gdk_pixbuf_get_height (pixbuf));
472 gdk_pixbuf_saturate_and_pixelate (pixbuf,
476 g_object_unref (pixbuf);
477 pixbuf = modded_pixbuf;
486 g_object_unref (account);
488 g_object_unref (pixbuf);
493 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
494 EmpathyAccount *account,
498 GtkTreeSelection *selection;
502 /* Update the status in the model */
503 view = GTK_TREE_VIEW (dialog->treeview);
504 selection = gtk_tree_view_get_selection (view);
505 model = gtk_tree_view_get_model (view);
507 for (ok = gtk_tree_model_get_iter_first (model, iter);
509 ok = gtk_tree_model_iter_next (model, iter)) {
510 EmpathyAccount *this_account;
513 gtk_tree_model_get (model, iter,
514 COL_ACCOUNT_POINTER, &this_account,
517 equal = empathy_account_equal (this_account, account);
518 g_object_unref (this_account);
528 static EmpathyAccount *
529 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
533 GtkTreeSelection *selection;
535 EmpathyAccount *account;
537 view = GTK_TREE_VIEW (dialog->treeview);
538 selection = gtk_tree_view_get_selection (view);
540 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
544 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
550 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
551 EmpathyAccount *account)
553 GtkTreeSelection *selection;
556 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
557 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
558 gtk_tree_selection_select_iter (selection, &iter);
563 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
567 GtkTreeSelection *selection;
570 view = GTK_TREE_VIEW (dialog->treeview);
571 selection = gtk_tree_view_get_selection (view);
573 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
577 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
581 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
582 EmpathyAccountsDialog *dialog)
584 EmpathyAccount *account;
587 gboolean is_selection;
589 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
591 account = accounts_dialog_model_get_selected (dialog);
592 accounts_dialog_update_account (dialog, account);
595 g_object_unref (account);
600 accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
601 EmpathyAccount *account)
605 TpConnectionStatus status;
609 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
610 g_object_get (account, "status", &status, NULL);
611 name = empathy_account_get_display_name (account);
612 enabled = empathy_account_is_enabled (account);
614 if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
615 DEBUG ("Adding new account");
616 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
619 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
620 COL_ENABLED, enabled,
623 COL_ACCOUNT_POINTER, account,
626 accounts_dialog_connection_changed_cb (dialog->account_manager,
628 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
630 TP_CONNECTION_STATUS_DISCONNECTED,
635 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
636 EmpathyAccount *account,
637 EmpathyAccountsDialog *dialog)
639 const gchar *current_name;
640 gchar *account_param = NULL;
642 accounts_dialog_add_or_update_account (dialog, account);
644 /* Change the display name to "%s (%s)" % (protocol, account).
645 * - The protocol is the display name of the profile.
646 * - The account should be the normalized name of the EmpathyAccount but
647 * it's not set until first connection, so we get the "account"
648 * parameter for CM that have it. */
649 current_name = empathy_account_get_display_name (account);
650 account_param = empathy_account_get_param_string (account, "account");
651 if (!EMP_STR_EMPTY (account_param)) {
654 new_name = g_strdup_printf ("%s (%s)",
655 empathy_account_get_protocol (account),
658 DEBUG ("Setting new display name for account %s: '%s'",
659 empathy_account_get_unique_name (account), new_name);
661 empathy_account_set_display_name (account, new_name);
664 /* FIXME: This CM has no account parameter, what can be done? */
666 g_free (account_param);
670 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
671 EmpathyAccount *account,
672 EmpathyAccountsDialog *dialog)
675 accounts_dialog_model_set_selected (dialog, account);
676 accounts_dialog_model_remove_selected (dialog);
680 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
685 gtk_tree_model_row_changed (model, path, iter);
691 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
696 dialog->connecting_show = !dialog->connecting_show;
698 view = GTK_TREE_VIEW (dialog->treeview);
699 model = gtk_tree_view_get_model (view);
701 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
707 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
708 EmpathyAccount *account,
709 TpConnectionStatusReason reason,
710 TpConnectionStatus current,
711 TpConnectionStatus previous,
712 EmpathyAccountsDialog *dialog)
718 /* Update the status in the model */
719 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
721 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
724 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
728 path = gtk_tree_model_get_path (model, &iter);
729 gtk_tree_model_row_changed (model, path, &iter);
730 gtk_tree_path_free (path);
733 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
735 if (!found && dialog->connecting_id) {
736 g_source_remove (dialog->connecting_id);
737 dialog->connecting_id = 0;
740 if (found && !dialog->connecting_id) {
741 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
742 (GSourceFunc) accounts_dialog_flash_connecting_cb,
748 enable_or_disable_account (EmpathyAccountsDialog *dialog,
749 EmpathyAccount *account,
755 /* Update the status in the model */
756 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
758 DEBUG ("Account %s is now %s",
759 empathy_account_get_display_name (account),
760 enabled ? "enabled" : "disabled");
762 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
763 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
764 COL_ENABLED, enabled,
770 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
771 EmpathyAccount *account,
772 EmpathyAccountsDialog *dialog)
774 enable_or_disable_account (dialog, account, FALSE);
778 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
779 EmpathyAccount *account,
780 EmpathyAccountsDialog *dialog)
782 enable_or_disable_account (dialog, account, TRUE);
786 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
787 EmpathyAccount *account,
788 EmpathyAccountsDialog *dialog)
790 EmpathyAccount *selected_account;
792 accounts_dialog_add_or_update_account (dialog, account);
793 selected_account = accounts_dialog_model_get_selected (dialog);
794 if (empathy_account_equal (account, selected_account)) {
795 accounts_dialog_update_name_label (dialog, account);
800 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
801 EmpathyAccountsDialog *dialog)
803 EmpathyAccount *account;
805 TpConnectionManager *cm;
806 TpConnectionManagerProtocol *proto;
808 cm = empathy_protocol_chooser_dup_selected (
809 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
812 /* To translator: %s is the protocol name */
813 str = g_strdup_printf (_("New %s account"), proto->name);
815 account = empathy_account_manager_create (dialog->account_manager,
816 cm->name, proto->name, str);
820 if (account == NULL) {
821 /* We can't display an error to the user as MC doesn't give us
822 * any clue about the reason of the failure... */
826 if (tp_connection_manager_protocol_can_register (proto)) {
829 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
831 empathy_account_set_param_boolean (account, "register", TRUE);
835 accounts_dialog_add_or_update_account (dialog, account);
836 accounts_dialog_model_set_selected (dialog, account);
838 g_object_unref (account);
843 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
844 EmpathyAccountsDialog *dialog)
846 EmpathyAccount *account;
848 account = accounts_dialog_model_get_selected (dialog);
849 accounts_dialog_update_account (dialog, account);
853 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
854 EmpathyAccountsDialog *dialog)
856 TpConnectionManager *cm;
857 TpConnectionManagerProtocol *proto;
859 cm = empathy_protocol_chooser_dup_selected (
860 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
862 if (tp_connection_manager_protocol_can_register (proto)) {
863 gtk_widget_show (dialog->radiobutton_register);
864 gtk_widget_show (dialog->radiobutton_reuse);
866 gtk_widget_hide (dialog->radiobutton_register);
867 gtk_widget_hide (dialog->radiobutton_reuse);
873 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
874 EmpathyAccountsDialog *dialog)
877 GtkTreeSelection *selection;
880 view = GTK_TREE_VIEW (dialog->treeview);
881 model = gtk_tree_view_get_model (view);
882 selection = gtk_tree_view_get_selection (view);
883 gtk_tree_selection_unselect_all (selection);
885 gtk_widget_set_sensitive (dialog->button_add, FALSE);
886 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
887 gtk_widget_hide (dialog->vbox_details);
888 gtk_widget_hide (dialog->frame_no_protocol);
889 gtk_widget_show (dialog->frame_new_account);
891 /* If we have no account, no need of a back button */
892 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
893 gtk_widget_show (dialog->button_back);
895 gtk_widget_hide (dialog->button_back);
898 accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
899 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
901 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
902 gtk_widget_grab_focus (dialog->combobox_protocol);
906 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
907 EmpathyAccountsDialog *dialog)
909 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
913 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
914 EmpathyAccountsDialog *dialog)
916 EmpathyAccount *account;
917 GtkWidget *message_dialog;
920 account = accounts_dialog_model_get_selected (dialog);
922 if (!empathy_account_is_valid (account)) {
923 accounts_dialog_model_remove_selected (dialog);
924 accounts_dialog_model_select_first (dialog);
927 message_dialog = gtk_message_dialog_new
928 (GTK_WINDOW (dialog->window),
929 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
930 GTK_MESSAGE_QUESTION,
932 _("You are about to remove your %s account!\n"
933 "Are you sure you want to proceed?"),
934 empathy_account_get_display_name (account));
936 gtk_message_dialog_format_secondary_text
937 (GTK_MESSAGE_DIALOG (message_dialog),
938 _("Any associated conversations and chat rooms will NOT be "
939 "removed if you decide to proceed.\n"
941 "Should you decide to add the account back at a later time, "
942 "they will still be available."));
944 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
947 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
951 gtk_widget_show (message_dialog);
952 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
954 if (res == GTK_RESPONSE_YES) {
955 empathy_account_manager_remove (dialog->account_manager, account);
956 accounts_dialog_model_select_first (dialog);
958 gtk_widget_destroy (message_dialog);
962 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
963 EmpathyAccountsDialog *dialog)
965 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
969 accounts_dialog_response_cb (GtkWidget *widget,
971 EmpathyAccountsDialog *dialog)
973 if (response == GTK_RESPONSE_CLOSE) {
974 gtk_widget_destroy (widget);
979 accounts_dialog_destroy_cb (GtkWidget *widget,
980 EmpathyAccountsDialog *dialog)
984 /* Disconnect signals */
985 g_signal_handlers_disconnect_by_func (dialog->account_manager,
986 accounts_dialog_account_added_cb,
988 g_signal_handlers_disconnect_by_func (dialog->account_manager,
989 accounts_dialog_account_removed_cb,
991 g_signal_handlers_disconnect_by_func (dialog->account_manager,
992 accounts_dialog_account_enabled_cb,
994 g_signal_handlers_disconnect_by_func (dialog->account_manager,
995 accounts_dialog_account_disabled_cb,
997 g_signal_handlers_disconnect_by_func (dialog->account_manager,
998 accounts_dialog_account_changed_cb,
1000 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1001 accounts_dialog_connection_changed_cb,
1004 /* Delete incomplete accounts */
1005 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1006 for (l = accounts; l; l = l->next) {
1007 EmpathyAccount *account;
1010 if (!empathy_account_is_valid (account)) {
1011 /* FIXME: Warn the user the account is not complete
1012 * and is going to be removed. */
1013 empathy_account_manager_remove (dialog->account_manager, account);
1016 g_object_unref (account);
1018 g_list_free (accounts);
1020 if (dialog->connecting_id) {
1021 g_source_remove (dialog->connecting_id);
1024 g_object_unref (dialog->account_manager);
1025 g_object_unref (dialog->mc);
1031 empathy_accounts_dialog_show (GtkWindow *parent,
1032 EmpathyAccount *selected_account)
1034 static EmpathyAccountsDialog *dialog = NULL;
1037 GList *accounts, *l;
1038 gboolean import_asked;
1041 gtk_window_present (GTK_WINDOW (dialog->window));
1042 return dialog->window;
1045 dialog = g_new0 (EmpathyAccountsDialog, 1);
1047 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1049 gui = empathy_builder_get_file (filename,
1050 "accounts_dialog", &dialog->window,
1051 "vbox_details", &dialog->vbox_details,
1052 "frame_no_protocol", &dialog->frame_no_protocol,
1053 "alignment_settings", &dialog->alignment_settings,
1054 "treeview", &dialog->treeview,
1055 "frame_new_account", &dialog->frame_new_account,
1056 "hbox_type", &dialog->hbox_type,
1057 "button_create", &dialog->button_create,
1058 "button_back", &dialog->button_back,
1059 "radiobutton_reuse", &dialog->radiobutton_reuse,
1060 "radiobutton_register", &dialog->radiobutton_register,
1061 "image_type", &dialog->image_type,
1062 "label_name", &dialog->label_name,
1063 "button_add", &dialog->button_add,
1064 "button_remove", &dialog->button_remove,
1065 "button_import", &dialog->button_import,
1069 empathy_builder_connect (gui, dialog,
1070 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1071 "accounts_dialog", "response", accounts_dialog_response_cb,
1072 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1073 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1074 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1075 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1076 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1077 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1080 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1082 g_object_unref (gui);
1084 /* Create protocol chooser */
1085 dialog->combobox_protocol = empathy_protocol_chooser_new ();
1086 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1087 dialog->combobox_protocol,
1089 gtk_widget_show (dialog->combobox_protocol);
1090 g_signal_connect (dialog->combobox_protocol, "changed",
1091 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1094 /* Set up signalling */
1095 dialog->account_manager = empathy_account_manager_dup_singleton ();
1096 dialog->mc = empathy_mission_control_dup_singleton ();
1098 g_signal_connect (dialog->account_manager, "account-created",
1099 G_CALLBACK (accounts_dialog_account_added_cb),
1101 g_signal_connect (dialog->account_manager, "account-deleted",
1102 G_CALLBACK (accounts_dialog_account_removed_cb),
1104 g_signal_connect (dialog->account_manager, "account-enabled",
1105 G_CALLBACK (accounts_dialog_account_enabled_cb),
1107 g_signal_connect (dialog->account_manager, "account-disabled",
1108 G_CALLBACK (accounts_dialog_account_disabled_cb),
1110 g_signal_connect (dialog->account_manager, "account-changed",
1111 G_CALLBACK (accounts_dialog_account_changed_cb),
1113 g_signal_connect (dialog->account_manager, "account-connection-changed",
1114 G_CALLBACK (accounts_dialog_connection_changed_cb),
1117 accounts_dialog_model_setup (dialog);
1119 /* Add existing accounts */
1120 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1121 for (l = accounts; l; l = l->next) {
1122 accounts_dialog_add_or_update_account (dialog, l->data);
1123 g_object_unref (l->data);
1125 g_list_free (accounts);
1127 if (selected_account) {
1128 accounts_dialog_model_set_selected (dialog, selected_account);
1130 accounts_dialog_model_select_first (dialog);
1134 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1135 GTK_WINDOW (parent));
1138 gtk_widget_show (dialog->window);
1140 empathy_conf_get_bool (empathy_conf_get (),
1141 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1144 if (empathy_import_dialog_accounts_to_import ()) {
1146 if (!import_asked) {
1147 empathy_conf_set_bool (empathy_conf_get (),
1148 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1149 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1153 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1156 return dialog->window;