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 gulong settings_ready_id;
88 EmpathyAccountSettings *settings_ready;
90 EmpathyAccountManager *account_manager;
91 } EmpathyAccountsDialog;
98 COL_ACCOUNT_SETTINGS_POINTER,
102 static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
103 EmpathyAccountSettings *settings);
104 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
105 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
106 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
107 GtkCellEditable *editable,
109 EmpathyAccountsDialog *dialog);
110 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
111 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
112 GtkCellRenderer *cell,
115 EmpathyAccountsDialog *dialog);
116 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
117 EmpathyAccountSettings *settings);
118 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
119 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
120 EmpathyAccountsDialog *dialog);
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 EmpathyAccountSettings *settings)
165 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
166 empathy_account_settings_get_display_name (settings));
167 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
172 typedef GtkWidget *CreateWidget (EmpathyAccountSettings *);
175 get_account_setup_widget (EmpathyAccountSettings *settings)
177 const gchar *cm = empathy_account_settings_get_cm (settings);
178 const gchar *proto = empathy_account_settings_get_protocol (settings);
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 (settings);
203 return empathy_account_widget_generic_new (settings);
208 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
209 EmpathyAccountSettings *settings)
211 dialog->settings_widget = get_account_setup_widget (settings);
213 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
214 dialog->settings_widget);
215 gtk_widget_show (dialog->settings_widget);
218 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
219 empathy_account_settings_get_icon_name (settings),
220 GTK_ICON_SIZE_DIALOG);
221 gtk_widget_set_tooltip_text (dialog->image_type,
222 empathy_account_settings_get_protocol (settings));
224 accounts_dialog_update_name_label (dialog, settings);
228 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
229 GParamSpec *spec, EmpathyAccountsDialog *dialog)
231 if (empathy_account_settings_is_ready (settings))
232 account_dialog_create_settings_widget (dialog, settings);
236 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
237 EmpathyAccountSettings *settings)
239 if (dialog->settings_ready != NULL) {
240 g_signal_handler_disconnect (dialog->settings_ready,
241 dialog->settings_ready_id);
242 dialog->settings_ready = NULL;
243 dialog->settings_ready_id = 0;
250 view = GTK_TREE_VIEW (dialog->treeview);
251 model = gtk_tree_view_get_model (view);
253 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
254 /* We have configured accounts, select the first one */
255 accounts_dialog_model_select_first (dialog);
258 if (empathy_protocol_chooser_n_protocols (
259 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol)) > 0) {
260 /* We have no account configured but we have some
261 * profiles instsalled. The user obviously wants to add
262 * an account. Click on the Add button for him. */
263 accounts_dialog_button_add_clicked_cb (dialog->button_add,
268 /* No account and no profile, warn the user */
269 gtk_widget_hide (dialog->vbox_details);
270 gtk_widget_hide (dialog->frame_new_account);
271 gtk_widget_show (dialog->frame_no_protocol);
272 gtk_widget_set_sensitive (dialog->button_add, FALSE);
273 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
277 /* We have an account selected, destroy old settings and create a new
278 * one for the account selected */
279 gtk_widget_hide (dialog->frame_new_account);
280 gtk_widget_hide (dialog->frame_no_protocol);
281 gtk_widget_show (dialog->vbox_details);
282 gtk_widget_set_sensitive (dialog->button_add, TRUE);
283 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
285 if (dialog->settings_widget) {
286 gtk_widget_destroy (dialog->settings_widget);
287 dialog->settings_widget = NULL;
290 if (empathy_account_settings_is_ready (settings))
292 account_dialog_create_settings_widget (dialog, settings);
296 dialog->settings_ready = settings;
297 dialog->settings_ready_id =
298 g_signal_connect (settings, "notify::ready",
299 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
305 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
308 GtkTreeSelection *selection;
310 store = gtk_list_store_new (COL_COUNT,
311 G_TYPE_BOOLEAN, /* enabled */
312 G_TYPE_STRING, /* name */
313 G_TYPE_UINT, /* status */
314 EMPATHY_TYPE_ACCOUNT, /* account */
315 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
317 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
318 GTK_TREE_MODEL (store));
320 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
321 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
323 g_signal_connect (selection, "changed",
324 G_CALLBACK (accounts_dialog_model_selection_changed),
327 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
328 COL_NAME, GTK_SORT_ASCENDING);
330 accounts_dialog_model_add_columns (dialog);
332 g_object_unref (store);
336 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
339 EmpathyAccountsDialog *dialog)
341 EmpathyAccountSettings *settings;
343 GtkTreePath *treepath;
346 if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
347 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
348 (GSourceFunc) accounts_dialog_flash_connecting_cb,
352 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
353 treepath = gtk_tree_path_new_from_string (path);
354 gtk_tree_model_get_iter (model, &iter, treepath);
355 gtk_tree_model_get (model, &iter,
356 COL_ACCOUNT_SETTINGS_POINTER, &settings,
358 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
361 gtk_tree_path_free (treepath);
363 empathy_account_settings_set_display_name_async (settings, new_text,
365 g_object_unref (settings);
369 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
371 EmpathyAccountsDialog *dialog)
373 EmpathyAccount *account;
375 GtkTreePath *treepath;
379 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
380 treepath = gtk_tree_path_new_from_string (path);
381 gtk_tree_model_get_iter (model, &iter, treepath);
382 gtk_tree_model_get (model, &iter,
383 COL_ACCOUNT_POINTER, &account,
385 gtk_tree_path_free (treepath);
390 enabled = empathy_account_is_enabled (account);
391 empathy_account_set_enabled (account, !enabled);
393 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
394 empathy_account_get_display_name (account));
396 g_object_unref (account);
400 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
401 GtkCellEditable *editable,
403 EmpathyAccountsDialog *dialog)
405 if (dialog->connecting_id) {
406 g_source_remove (dialog->connecting_id);
408 DEBUG ("Editing account name started; stopping flashing");
412 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
415 GtkTreeViewColumn *column;
416 GtkCellRenderer *cell;
418 view = GTK_TREE_VIEW (dialog->treeview);
419 gtk_tree_view_set_headers_visible (view, TRUE);
422 cell = gtk_cell_renderer_toggle_new ();
423 gtk_tree_view_insert_column_with_attributes (view, -1,
426 "active", COL_ENABLED,
428 g_signal_connect (cell, "toggled",
429 G_CALLBACK (accounts_dialog_enable_toggled_cb),
433 column = gtk_tree_view_column_new ();
434 gtk_tree_view_column_set_title (column, _("Accounts"));
435 gtk_tree_view_column_set_expand (column, TRUE);
436 gtk_tree_view_append_column (view, column);
439 cell = gtk_cell_renderer_pixbuf_new ();
440 gtk_tree_view_column_pack_start (column, cell, FALSE);
441 gtk_tree_view_column_set_cell_data_func (column, cell,
442 (GtkTreeCellDataFunc)
443 accounts_dialog_model_pixbuf_data_func,
448 cell = gtk_cell_renderer_text_new ();
450 "ellipsize", PANGO_ELLIPSIZE_END,
454 gtk_tree_view_column_pack_start (column, cell, TRUE);
455 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
456 g_signal_connect (cell, "edited",
457 G_CALLBACK (accounts_dialog_name_edited_cb),
459 g_signal_connect (cell, "editing-started",
460 G_CALLBACK (accounts_dialog_name_editing_started_cb),
465 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
469 GtkTreeSelection *selection;
473 view = GTK_TREE_VIEW (dialog->treeview);
474 model = gtk_tree_view_get_model (view);
476 if (gtk_tree_model_get_iter_first (model, &iter)) {
477 selection = gtk_tree_view_get_selection (view);
478 gtk_tree_selection_select_iter (selection, &iter);
480 accounts_dialog_update_settings (dialog, NULL);
485 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
486 GtkCellRenderer *cell,
489 EmpathyAccountsDialog *dialog)
491 EmpathyAccountSettings *settings;
492 const gchar *icon_name;
494 TpConnectionStatus status;
496 gtk_tree_model_get (model, iter,
498 COL_ACCOUNT_SETTINGS_POINTER, &settings,
501 icon_name = empathy_account_settings_get_icon_name (settings);
502 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
505 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
506 (status == TP_CONNECTION_STATUS_CONNECTING &&
507 !dialog->connecting_show)) {
508 GdkPixbuf *modded_pixbuf;
510 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
513 gdk_pixbuf_get_width (pixbuf),
514 gdk_pixbuf_get_height (pixbuf));
516 gdk_pixbuf_saturate_and_pixelate (pixbuf,
520 g_object_unref (pixbuf);
521 pixbuf = modded_pixbuf;
530 g_object_unref (settings);
532 g_object_unref (pixbuf);
537 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
538 EmpathyAccountSettings *settings,
542 GtkTreeSelection *selection;
546 /* Update the status in the model */
547 view = GTK_TREE_VIEW (dialog->treeview);
548 selection = gtk_tree_view_get_selection (view);
549 model = gtk_tree_view_get_model (view);
551 for (ok = gtk_tree_model_get_iter_first (model, iter);
553 ok = gtk_tree_model_iter_next (model, iter)) {
554 EmpathyAccountSettings *this_settings;
557 gtk_tree_model_get (model, iter,
558 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
561 equal = (this_settings == settings);
562 g_object_unref (this_settings);
573 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
574 EmpathyAccount *account,
578 GtkTreeSelection *selection;
582 /* Update the status in the model */
583 view = GTK_TREE_VIEW (dialog->treeview);
584 selection = gtk_tree_view_get_selection (view);
585 model = gtk_tree_view_get_model (view);
587 for (ok = gtk_tree_model_get_iter_first (model, iter);
589 ok = gtk_tree_model_iter_next (model, iter)) {
590 EmpathyAccount *this_account;
593 gtk_tree_model_get (model, iter,
594 COL_ACCOUNT_POINTER, &this_account,
597 equal = (this_account == account);
598 g_object_unref (this_account);
608 static EmpathyAccountSettings *
609 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
613 GtkTreeSelection *selection;
615 EmpathyAccountSettings *settings;
617 view = GTK_TREE_VIEW (dialog->treeview);
618 selection = gtk_tree_view_get_selection (view);
620 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
624 gtk_tree_model_get (model, &iter,
625 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
631 static EmpathyAccount *
632 accounts_dialog_model_get_selected_account (EmpathyAccountsDialog *dialog)
636 GtkTreeSelection *selection;
638 EmpathyAccount *account;
640 view = GTK_TREE_VIEW (dialog->treeview);
641 selection = gtk_tree_view_get_selection (view);
643 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
647 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
653 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
654 EmpathyAccountSettings *settings)
656 GtkTreeSelection *selection;
659 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
660 if (accounts_dialog_get_settings_iter (dialog, settings, &iter)) {
661 gtk_tree_selection_select_iter (selection, &iter);
666 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
670 GtkTreeSelection *selection;
673 view = GTK_TREE_VIEW (dialog->treeview);
674 selection = gtk_tree_view_get_selection (view);
676 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
680 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
684 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
685 EmpathyAccountsDialog *dialog)
687 EmpathyAccountSettings *settings;
690 gboolean is_selection;
692 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
694 settings = accounts_dialog_model_get_selected_settings (dialog);
695 accounts_dialog_update_settings (dialog, settings);
698 g_object_unref (settings);
703 accounts_dialog_add (EmpathyAccountsDialog *dialog,
704 EmpathyAccountSettings *settings)
710 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
711 name = empathy_account_settings_get_display_name (settings);
713 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
715 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
718 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
719 COL_ACCOUNT_SETTINGS_POINTER, settings,
725 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
726 EmpathyAccount *account)
728 EmpathyAccountSettings *settings;
731 TpConnectionStatus status;
735 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
736 g_object_get (account, "status", &status, NULL);
737 name = empathy_account_get_display_name (account);
738 enabled = empathy_account_is_enabled (account);
740 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
742 settings = empathy_account_settings_new_for_account (account);
744 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
745 COL_ENABLED, enabled,
748 COL_ACCOUNT_POINTER, account,
749 COL_ACCOUNT_SETTINGS_POINTER, settings,
752 accounts_dialog_connection_changed_cb (dialog->account_manager,
754 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
756 TP_CONNECTION_STATUS_DISCONNECTED,
759 g_object_unref (settings);
763 accounts_dialog_update (EmpathyAccountsDialog *dialog,
764 EmpathyAccountSettings *settings)
768 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
770 gboolean enabled = FALSE;
771 EmpathyAccount *account;
773 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
774 name = empathy_account_settings_get_display_name (settings);
776 account = empathy_account_settings_get_account (settings);
779 enabled = empathy_account_is_enabled (account);
780 g_object_get (account, "connection-status", &status, NULL);
783 accounts_dialog_get_settings_iter (dialog, settings, &iter);
784 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
785 COL_ENABLED, enabled,
788 COL_ACCOUNT_POINTER, account,
789 COL_ACCOUNT_SETTINGS_POINTER, settings,
794 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
795 EmpathyAccount *account,
796 EmpathyAccountsDialog *dialog)
798 accounts_dialog_add_account (dialog, account);
803 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
804 EmpathyAccount *account,
805 EmpathyAccountsDialog *dialog)
809 if (accounts_dialog_get_account_iter (dialog, account, &iter))
810 gtk_list_store_remove (GTK_LIST_STORE (
811 gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview))), &iter);
815 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
820 gtk_tree_model_row_changed (model, path, iter);
826 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
831 dialog->connecting_show = !dialog->connecting_show;
833 view = GTK_TREE_VIEW (dialog->treeview);
834 model = gtk_tree_view_get_model (view);
836 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
842 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
843 EmpathyAccount *account,
844 TpConnectionStatusReason reason,
845 TpConnectionStatus current,
846 TpConnectionStatus previous,
847 EmpathyAccountsDialog *dialog)
853 /* Update the status in the model */
854 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
856 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
859 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
863 path = gtk_tree_model_get_path (model, &iter);
864 gtk_tree_model_row_changed (model, path, &iter);
865 gtk_tree_path_free (path);
868 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
870 if (!found && dialog->connecting_id) {
871 g_source_remove (dialog->connecting_id);
872 dialog->connecting_id = 0;
875 if (found && !dialog->connecting_id) {
876 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
877 (GSourceFunc) accounts_dialog_flash_connecting_cb,
883 enable_or_disable_account (EmpathyAccountsDialog *dialog,
884 EmpathyAccount *account,
890 /* Update the status in the model */
891 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
893 DEBUG ("Account %s is now %s",
894 empathy_account_get_display_name (account),
895 enabled ? "enabled" : "disabled");
897 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
898 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
899 COL_ENABLED, enabled,
905 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
906 EmpathyAccount *account,
907 EmpathyAccountsDialog *dialog)
909 enable_or_disable_account (dialog, account, FALSE);
913 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
914 EmpathyAccount *account,
915 EmpathyAccountsDialog *dialog)
917 enable_or_disable_account (dialog, account, TRUE);
921 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
922 EmpathyAccount *account,
923 EmpathyAccountsDialog *dialog)
925 EmpathyAccountSettings *settings, *selected_settings;
929 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
931 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
934 gtk_tree_model_get (model, &iter,
935 COL_ACCOUNT_SETTINGS_POINTER, &settings,
938 accounts_dialog_update (dialog, settings);
939 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
941 if (settings == selected_settings)
942 accounts_dialog_update_name_label (dialog, settings);
946 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
947 EmpathyAccountsDialog *dialog)
949 EmpathyAccountSettings *settings;
951 TpConnectionManager *cm;
952 TpConnectionManagerProtocol *proto;
954 cm = empathy_protocol_chooser_dup_selected (
955 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
958 /* To translator: %s is the protocol name */
959 str = g_strdup_printf (_("New %s account"), proto->name);
961 settings = empathy_account_settings_new (cm->name, proto->name, str);
965 if (tp_connection_manager_protocol_can_register (proto)) {
968 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
970 empathy_account_settings_set_boolean (settings, "register", TRUE);
974 accounts_dialog_add (dialog, settings);
975 accounts_dialog_model_set_selected (dialog, settings);
977 g_object_unref (settings);
982 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
983 EmpathyAccountsDialog *dialog)
985 EmpathyAccountSettings *settings;
987 settings = accounts_dialog_model_get_selected_settings (dialog);
988 accounts_dialog_update (dialog, settings);
992 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
993 EmpathyAccountsDialog *dialog)
995 TpConnectionManager *cm;
996 TpConnectionManagerProtocol *proto;
998 cm = empathy_protocol_chooser_dup_selected (
999 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
1001 if (tp_connection_manager_protocol_can_register (proto)) {
1002 gtk_widget_show (dialog->radiobutton_register);
1003 gtk_widget_show (dialog->radiobutton_reuse);
1005 gtk_widget_hide (dialog->radiobutton_register);
1006 gtk_widget_hide (dialog->radiobutton_reuse);
1008 g_object_unref (cm);
1012 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
1013 EmpathyAccountsDialog *dialog)
1016 GtkTreeSelection *selection;
1017 GtkTreeModel *model;
1019 view = GTK_TREE_VIEW (dialog->treeview);
1020 model = gtk_tree_view_get_model (view);
1021 selection = gtk_tree_view_get_selection (view);
1022 gtk_tree_selection_unselect_all (selection);
1024 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1025 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
1026 gtk_widget_hide (dialog->vbox_details);
1027 gtk_widget_hide (dialog->frame_no_protocol);
1028 gtk_widget_show (dialog->frame_new_account);
1030 /* If we have no account, no need of a back button */
1031 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
1032 gtk_widget_show (dialog->button_back);
1034 gtk_widget_hide (dialog->button_back);
1037 accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
1038 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
1040 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
1041 gtk_widget_grab_focus (dialog->combobox_protocol);
1045 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1046 EmpathyAccountsDialog *dialog)
1048 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
1052 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1053 EmpathyAccountsDialog *dialog)
1055 EmpathyAccount *account;
1056 GtkWidget *message_dialog;
1059 account = accounts_dialog_model_get_selected_account (dialog);
1061 if (account == NULL || !empathy_account_is_valid (account)) {
1062 accounts_dialog_model_remove_selected (dialog);
1063 accounts_dialog_model_select_first (dialog);
1066 message_dialog = gtk_message_dialog_new
1067 (GTK_WINDOW (dialog->window),
1068 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1069 GTK_MESSAGE_QUESTION,
1071 _("You are about to remove your %s account!\n"
1072 "Are you sure you want to proceed?"),
1073 empathy_account_get_display_name (account));
1075 gtk_message_dialog_format_secondary_text
1076 (GTK_MESSAGE_DIALOG (message_dialog),
1077 _("Any associated conversations and chat rooms will NOT be "
1078 "removed if you decide to proceed.\n"
1080 "Should you decide to add the account back at a later time, "
1081 "they will still be available."));
1083 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1086 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1090 gtk_widget_show (message_dialog);
1091 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
1093 if (res == GTK_RESPONSE_YES) {
1094 empathy_account_manager_remove (dialog->account_manager, account);
1095 accounts_dialog_model_select_first (dialog);
1097 gtk_widget_destroy (message_dialog);
1103 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1104 EmpathyAccountsDialog *dialog)
1106 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
1111 accounts_dialog_response_cb (GtkWidget *widget,
1113 EmpathyAccountsDialog *dialog)
1115 if (response == GTK_RESPONSE_CLOSE) {
1116 gtk_widget_destroy (widget);
1121 accounts_dialog_destroy_cb (GtkWidget *widget,
1122 EmpathyAccountsDialog *dialog)
1124 GList *accounts, *l;
1126 /* Disconnect signals */
1127 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1128 accounts_dialog_account_added_cb,
1130 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1131 accounts_dialog_account_removed_cb,
1133 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1134 accounts_dialog_account_enabled_cb,
1136 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1137 accounts_dialog_account_disabled_cb,
1139 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1140 accounts_dialog_account_changed_cb,
1142 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1143 accounts_dialog_connection_changed_cb,
1146 /* Delete incomplete accounts */
1147 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1148 for (l = accounts; l; l = l->next) {
1149 EmpathyAccount *account;
1152 if (!empathy_account_is_valid (account)) {
1153 /* FIXME: Warn the user the account is not complete
1154 * and is going to be removed. */
1155 empathy_account_manager_remove (dialog->account_manager, account);
1158 g_object_unref (account);
1160 g_list_free (accounts);
1162 if (dialog->connecting_id) {
1163 g_source_remove (dialog->connecting_id);
1166 g_object_unref (dialog->account_manager);
1172 empathy_accounts_dialog_show (GtkWindow *parent,
1173 EmpathyAccount *selected_account)
1175 static EmpathyAccountsDialog *dialog = NULL;
1178 GList *accounts, *l;
1179 gboolean import_asked;
1182 gtk_window_present (GTK_WINDOW (dialog->window));
1183 return dialog->window;
1186 dialog = g_new0 (EmpathyAccountsDialog, 1);
1188 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1190 gui = empathy_builder_get_file (filename,
1191 "accounts_dialog", &dialog->window,
1192 "vbox_details", &dialog->vbox_details,
1193 "frame_no_protocol", &dialog->frame_no_protocol,
1194 "alignment_settings", &dialog->alignment_settings,
1195 "treeview", &dialog->treeview,
1196 "frame_new_account", &dialog->frame_new_account,
1197 "hbox_type", &dialog->hbox_type,
1198 "button_create", &dialog->button_create,
1199 "button_back", &dialog->button_back,
1200 "radiobutton_reuse", &dialog->radiobutton_reuse,
1201 "radiobutton_register", &dialog->radiobutton_register,
1202 "image_type", &dialog->image_type,
1203 "label_name", &dialog->label_name,
1204 "button_add", &dialog->button_add,
1205 "button_remove", &dialog->button_remove,
1206 "button_import", &dialog->button_import,
1210 empathy_builder_connect (gui, dialog,
1211 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1212 "accounts_dialog", "response", accounts_dialog_response_cb,
1213 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1214 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1215 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1216 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1219 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1221 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1224 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1226 g_object_unref (gui);
1228 /* Create protocol chooser */
1229 dialog->combobox_protocol = empathy_protocol_chooser_new ();
1230 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1231 dialog->combobox_protocol,
1233 gtk_widget_show (dialog->combobox_protocol);
1234 g_signal_connect (dialog->combobox_protocol, "changed",
1235 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1238 /* Set up signalling */
1239 dialog->account_manager = empathy_account_manager_dup_singleton ();
1241 g_signal_connect (dialog->account_manager, "account-created",
1242 G_CALLBACK (accounts_dialog_account_added_cb),
1244 g_signal_connect (dialog->account_manager, "account-deleted",
1245 G_CALLBACK (accounts_dialog_account_removed_cb),
1247 g_signal_connect (dialog->account_manager, "account-enabled",
1248 G_CALLBACK (accounts_dialog_account_enabled_cb),
1250 g_signal_connect (dialog->account_manager, "account-disabled",
1251 G_CALLBACK (accounts_dialog_account_disabled_cb),
1253 g_signal_connect (dialog->account_manager, "account-changed",
1254 G_CALLBACK (accounts_dialog_account_changed_cb),
1256 g_signal_connect (dialog->account_manager, "account-connection-changed",
1257 G_CALLBACK (accounts_dialog_connection_changed_cb),
1260 accounts_dialog_model_setup (dialog);
1262 /* Add existing accounts */
1263 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1264 for (l = accounts; l; l = l->next) {
1265 accounts_dialog_add_account (dialog, l->data);
1266 g_object_unref (l->data);
1268 g_list_free (accounts);
1270 if (selected_account) {
1271 GtkTreeSelection *selection;
1274 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
1275 if (accounts_dialog_get_account_iter (dialog, selected_account, &iter)) {
1276 gtk_tree_selection_select_iter (selection, &iter);
1279 accounts_dialog_model_select_first (dialog);
1283 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1284 GTK_WINDOW (parent));
1287 gtk_widget_show (dialog->window);
1289 empathy_conf_get_bool (empathy_conf_get (),
1290 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1295 if (empathy_import_dialog_accounts_to_import ()) {
1297 if (!import_asked) {
1298 empathy_conf_set_bool (empathy_conf_get (),
1299 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1300 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1304 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1308 return dialog->window;