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 const 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? */
669 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
670 EmpathyAccount *account,
671 EmpathyAccountsDialog *dialog)
674 accounts_dialog_model_set_selected (dialog, account);
675 accounts_dialog_model_remove_selected (dialog);
679 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
684 gtk_tree_model_row_changed (model, path, iter);
690 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
695 dialog->connecting_show = !dialog->connecting_show;
697 view = GTK_TREE_VIEW (dialog->treeview);
698 model = gtk_tree_view_get_model (view);
700 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
706 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
707 EmpathyAccount *account,
708 TpConnectionStatusReason reason,
709 TpConnectionStatus current,
710 TpConnectionStatus previous,
711 EmpathyAccountsDialog *dialog)
717 /* Update the status in the model */
718 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
720 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
723 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
727 path = gtk_tree_model_get_path (model, &iter);
728 gtk_tree_model_row_changed (model, path, &iter);
729 gtk_tree_path_free (path);
732 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
734 if (!found && dialog->connecting_id) {
735 g_source_remove (dialog->connecting_id);
736 dialog->connecting_id = 0;
739 if (found && !dialog->connecting_id) {
740 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
741 (GSourceFunc) accounts_dialog_flash_connecting_cb,
747 enable_or_disable_account (EmpathyAccountsDialog *dialog,
748 EmpathyAccount *account,
754 /* Update the status in the model */
755 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
757 DEBUG ("Account %s is now %s",
758 empathy_account_get_display_name (account),
759 enabled ? "enabled" : "disabled");
761 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
762 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
763 COL_ENABLED, enabled,
769 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
770 EmpathyAccount *account,
771 EmpathyAccountsDialog *dialog)
773 enable_or_disable_account (dialog, account, FALSE);
777 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
778 EmpathyAccount *account,
779 EmpathyAccountsDialog *dialog)
781 enable_or_disable_account (dialog, account, TRUE);
785 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
786 EmpathyAccount *account,
787 EmpathyAccountsDialog *dialog)
789 EmpathyAccount *selected_account;
791 accounts_dialog_add_or_update_account (dialog, account);
792 selected_account = accounts_dialog_model_get_selected (dialog);
793 if (empathy_account_equal (account, selected_account)) {
794 accounts_dialog_update_name_label (dialog, account);
799 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
800 EmpathyAccountsDialog *dialog)
802 EmpathyAccount *account;
804 TpConnectionManager *cm;
805 TpConnectionManagerProtocol *proto;
807 cm = empathy_protocol_chooser_dup_selected (
808 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
811 /* To translator: %s is the protocol name */
812 str = g_strdup_printf (_("New %s account"), proto->name);
814 account = empathy_account_manager_create (dialog->account_manager,
815 cm->name, proto->name, str);
819 if (account == NULL) {
820 /* We can't display an error to the user as MC doesn't give us
821 * any clue about the reason of the failure... */
825 if (tp_connection_manager_protocol_can_register (proto)) {
828 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
830 empathy_account_set_param_boolean (account, "register", TRUE);
834 accounts_dialog_add_or_update_account (dialog, account);
835 accounts_dialog_model_set_selected (dialog, account);
837 g_object_unref (account);
842 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
843 EmpathyAccountsDialog *dialog)
845 EmpathyAccount *account;
847 account = accounts_dialog_model_get_selected (dialog);
848 accounts_dialog_update_account (dialog, account);
852 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
853 EmpathyAccountsDialog *dialog)
855 TpConnectionManager *cm;
856 TpConnectionManagerProtocol *proto;
858 cm = empathy_protocol_chooser_dup_selected (
859 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
861 if (tp_connection_manager_protocol_can_register (proto)) {
862 gtk_widget_show (dialog->radiobutton_register);
863 gtk_widget_show (dialog->radiobutton_reuse);
865 gtk_widget_hide (dialog->radiobutton_register);
866 gtk_widget_hide (dialog->radiobutton_reuse);
872 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
873 EmpathyAccountsDialog *dialog)
876 GtkTreeSelection *selection;
879 view = GTK_TREE_VIEW (dialog->treeview);
880 model = gtk_tree_view_get_model (view);
881 selection = gtk_tree_view_get_selection (view);
882 gtk_tree_selection_unselect_all (selection);
884 gtk_widget_set_sensitive (dialog->button_add, FALSE);
885 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
886 gtk_widget_hide (dialog->vbox_details);
887 gtk_widget_hide (dialog->frame_no_protocol);
888 gtk_widget_show (dialog->frame_new_account);
890 /* If we have no account, no need of a back button */
891 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
892 gtk_widget_show (dialog->button_back);
894 gtk_widget_hide (dialog->button_back);
897 accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
898 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
900 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
901 gtk_widget_grab_focus (dialog->combobox_protocol);
905 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
906 EmpathyAccountsDialog *dialog)
908 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
912 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
913 EmpathyAccountsDialog *dialog)
915 EmpathyAccount *account;
916 GtkWidget *message_dialog;
919 account = accounts_dialog_model_get_selected (dialog);
921 if (!empathy_account_is_valid (account)) {
922 accounts_dialog_model_remove_selected (dialog);
923 accounts_dialog_model_select_first (dialog);
926 message_dialog = gtk_message_dialog_new
927 (GTK_WINDOW (dialog->window),
928 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
929 GTK_MESSAGE_QUESTION,
931 _("You are about to remove your %s account!\n"
932 "Are you sure you want to proceed?"),
933 empathy_account_get_display_name (account));
935 gtk_message_dialog_format_secondary_text
936 (GTK_MESSAGE_DIALOG (message_dialog),
937 _("Any associated conversations and chat rooms will NOT be "
938 "removed if you decide to proceed.\n"
940 "Should you decide to add the account back at a later time, "
941 "they will still be available."));
943 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
946 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
950 gtk_widget_show (message_dialog);
951 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
953 if (res == GTK_RESPONSE_YES) {
954 empathy_account_manager_remove (dialog->account_manager, account);
955 accounts_dialog_model_select_first (dialog);
957 gtk_widget_destroy (message_dialog);
961 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
962 EmpathyAccountsDialog *dialog)
964 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
968 accounts_dialog_response_cb (GtkWidget *widget,
970 EmpathyAccountsDialog *dialog)
972 if (response == GTK_RESPONSE_CLOSE) {
973 gtk_widget_destroy (widget);
978 accounts_dialog_destroy_cb (GtkWidget *widget,
979 EmpathyAccountsDialog *dialog)
983 /* Disconnect signals */
984 g_signal_handlers_disconnect_by_func (dialog->account_manager,
985 accounts_dialog_account_added_cb,
987 g_signal_handlers_disconnect_by_func (dialog->account_manager,
988 accounts_dialog_account_removed_cb,
990 g_signal_handlers_disconnect_by_func (dialog->account_manager,
991 accounts_dialog_account_enabled_cb,
993 g_signal_handlers_disconnect_by_func (dialog->account_manager,
994 accounts_dialog_account_disabled_cb,
996 g_signal_handlers_disconnect_by_func (dialog->account_manager,
997 accounts_dialog_account_changed_cb,
999 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1000 accounts_dialog_connection_changed_cb,
1003 /* Delete incomplete accounts */
1004 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1005 for (l = accounts; l; l = l->next) {
1006 EmpathyAccount *account;
1009 if (!empathy_account_is_valid (account)) {
1010 /* FIXME: Warn the user the account is not complete
1011 * and is going to be removed. */
1012 empathy_account_manager_remove (dialog->account_manager, account);
1015 g_object_unref (account);
1017 g_list_free (accounts);
1019 if (dialog->connecting_id) {
1020 g_source_remove (dialog->connecting_id);
1023 g_object_unref (dialog->account_manager);
1024 g_object_unref (dialog->mc);
1030 empathy_accounts_dialog_show (GtkWindow *parent,
1031 EmpathyAccount *selected_account)
1033 static EmpathyAccountsDialog *dialog = NULL;
1036 GList *accounts, *l;
1037 gboolean import_asked;
1040 gtk_window_present (GTK_WINDOW (dialog->window));
1041 return dialog->window;
1044 dialog = g_new0 (EmpathyAccountsDialog, 1);
1046 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1048 gui = empathy_builder_get_file (filename,
1049 "accounts_dialog", &dialog->window,
1050 "vbox_details", &dialog->vbox_details,
1051 "frame_no_protocol", &dialog->frame_no_protocol,
1052 "alignment_settings", &dialog->alignment_settings,
1053 "treeview", &dialog->treeview,
1054 "frame_new_account", &dialog->frame_new_account,
1055 "hbox_type", &dialog->hbox_type,
1056 "button_create", &dialog->button_create,
1057 "button_back", &dialog->button_back,
1058 "radiobutton_reuse", &dialog->radiobutton_reuse,
1059 "radiobutton_register", &dialog->radiobutton_register,
1060 "image_type", &dialog->image_type,
1061 "label_name", &dialog->label_name,
1062 "button_add", &dialog->button_add,
1063 "button_remove", &dialog->button_remove,
1064 "button_import", &dialog->button_import,
1068 empathy_builder_connect (gui, dialog,
1069 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1070 "accounts_dialog", "response", accounts_dialog_response_cb,
1071 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1072 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1073 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1074 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1075 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1076 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1079 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1081 g_object_unref (gui);
1083 /* Create protocol chooser */
1084 dialog->combobox_protocol = empathy_protocol_chooser_new ();
1085 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1086 dialog->combobox_protocol,
1088 gtk_widget_show (dialog->combobox_protocol);
1089 g_signal_connect (dialog->combobox_protocol, "changed",
1090 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1093 /* Set up signalling */
1094 dialog->account_manager = empathy_account_manager_dup_singleton ();
1095 dialog->mc = empathy_mission_control_dup_singleton ();
1097 g_signal_connect (dialog->account_manager, "account-created",
1098 G_CALLBACK (accounts_dialog_account_added_cb),
1100 g_signal_connect (dialog->account_manager, "account-deleted",
1101 G_CALLBACK (accounts_dialog_account_removed_cb),
1103 g_signal_connect (dialog->account_manager, "account-enabled",
1104 G_CALLBACK (accounts_dialog_account_enabled_cb),
1106 g_signal_connect (dialog->account_manager, "account-disabled",
1107 G_CALLBACK (accounts_dialog_account_disabled_cb),
1109 g_signal_connect (dialog->account_manager, "account-changed",
1110 G_CALLBACK (accounts_dialog_account_changed_cb),
1112 g_signal_connect (dialog->account_manager, "account-connection-changed",
1113 G_CALLBACK (accounts_dialog_connection_changed_cb),
1116 accounts_dialog_model_setup (dialog);
1118 /* Add existing accounts */
1119 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1120 for (l = accounts; l; l = l->next) {
1121 accounts_dialog_add_or_update_account (dialog, l->data);
1122 g_object_unref (l->data);
1124 g_list_free (accounts);
1126 if (selected_account) {
1127 accounts_dialog_model_set_selected (dialog, selected_account);
1129 accounts_dialog_model_select_first (dialog);
1133 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1134 GTK_WINDOW (parent));
1137 gtk_widget_show (dialog->window);
1139 empathy_conf_get_bool (empathy_conf_get (),
1140 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1143 if (empathy_import_dialog_accounts_to_import ()) {
1145 if (!import_asked) {
1146 empathy_conf_set_bool (empathy_conf_get (),
1147 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1148 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1152 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1155 return dialog->window;