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;
672 EmpathyAccount *account;
674 view = GTK_TREE_VIEW (dialog->treeview);
675 selection = gtk_tree_view_get_selection (view);
677 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
681 gtk_tree_model_get (model, &iter,
682 COL_ACCOUNT_POINTER, &account,
686 empathy_account_remove_async (account, NULL, NULL);
688 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
692 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
693 EmpathyAccountsDialog *dialog)
695 EmpathyAccountSettings *settings;
698 gboolean is_selection;
700 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
702 settings = accounts_dialog_model_get_selected_settings (dialog);
703 accounts_dialog_update_settings (dialog, settings);
706 g_object_unref (settings);
711 accounts_dialog_add (EmpathyAccountsDialog *dialog,
712 EmpathyAccountSettings *settings)
718 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
719 name = empathy_account_settings_get_display_name (settings);
721 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
723 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
726 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
727 COL_ACCOUNT_SETTINGS_POINTER, settings,
733 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
734 EmpathyAccount *account)
736 EmpathyAccountSettings *settings;
739 TpConnectionStatus status;
743 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
744 g_object_get (account, "status", &status, NULL);
745 name = empathy_account_get_display_name (account);
746 enabled = empathy_account_is_enabled (account);
748 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
750 settings = empathy_account_settings_new_for_account (account);
752 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
753 COL_ENABLED, enabled,
756 COL_ACCOUNT_POINTER, account,
757 COL_ACCOUNT_SETTINGS_POINTER, settings,
760 accounts_dialog_connection_changed_cb (dialog->account_manager,
762 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
764 TP_CONNECTION_STATUS_DISCONNECTED,
767 g_object_unref (settings);
771 accounts_dialog_update (EmpathyAccountsDialog *dialog,
772 EmpathyAccountSettings *settings)
776 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
778 gboolean enabled = FALSE;
779 EmpathyAccount *account;
781 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
782 name = empathy_account_settings_get_display_name (settings);
784 account = empathy_account_settings_get_account (settings);
787 enabled = empathy_account_is_enabled (account);
788 g_object_get (account, "connection-status", &status, NULL);
791 accounts_dialog_get_settings_iter (dialog, settings, &iter);
792 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
793 COL_ENABLED, enabled,
796 COL_ACCOUNT_POINTER, account,
797 COL_ACCOUNT_SETTINGS_POINTER, settings,
802 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
803 EmpathyAccount *account,
804 EmpathyAccountsDialog *dialog)
806 accounts_dialog_add_account (dialog, account);
811 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
812 EmpathyAccount *account,
813 EmpathyAccountsDialog *dialog)
817 if (accounts_dialog_get_account_iter (dialog, account, &iter))
818 gtk_list_store_remove (GTK_LIST_STORE (
819 gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview))), &iter);
823 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
828 gtk_tree_model_row_changed (model, path, iter);
834 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
839 dialog->connecting_show = !dialog->connecting_show;
841 view = GTK_TREE_VIEW (dialog->treeview);
842 model = gtk_tree_view_get_model (view);
844 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
850 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
851 EmpathyAccount *account,
852 TpConnectionStatusReason reason,
853 TpConnectionStatus current,
854 TpConnectionStatus previous,
855 EmpathyAccountsDialog *dialog)
861 /* Update the status in the model */
862 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
864 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
867 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
871 path = gtk_tree_model_get_path (model, &iter);
872 gtk_tree_model_row_changed (model, path, &iter);
873 gtk_tree_path_free (path);
876 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
878 if (!found && dialog->connecting_id) {
879 g_source_remove (dialog->connecting_id);
880 dialog->connecting_id = 0;
883 if (found && !dialog->connecting_id) {
884 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
885 (GSourceFunc) accounts_dialog_flash_connecting_cb,
891 enable_or_disable_account (EmpathyAccountsDialog *dialog,
892 EmpathyAccount *account,
898 /* Update the status in the model */
899 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
901 DEBUG ("Account %s is now %s",
902 empathy_account_get_display_name (account),
903 enabled ? "enabled" : "disabled");
905 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
906 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
907 COL_ENABLED, enabled,
913 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
914 EmpathyAccount *account,
915 EmpathyAccountsDialog *dialog)
917 enable_or_disable_account (dialog, account, FALSE);
921 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
922 EmpathyAccount *account,
923 EmpathyAccountsDialog *dialog)
925 enable_or_disable_account (dialog, account, TRUE);
929 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
930 EmpathyAccount *account,
931 EmpathyAccountsDialog *dialog)
933 EmpathyAccountSettings *settings, *selected_settings;
937 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
939 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
942 gtk_tree_model_get (model, &iter,
943 COL_ACCOUNT_SETTINGS_POINTER, &settings,
946 accounts_dialog_update (dialog, settings);
947 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
949 if (settings == selected_settings)
950 accounts_dialog_update_name_label (dialog, settings);
954 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
955 EmpathyAccountsDialog *dialog)
957 EmpathyAccountSettings *settings;
959 TpConnectionManager *cm;
960 TpConnectionManagerProtocol *proto;
962 cm = empathy_protocol_chooser_dup_selected (
963 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
966 /* To translator: %s is the protocol name */
967 str = g_strdup_printf (_("New %s account"), proto->name);
969 settings = empathy_account_settings_new (cm->name, proto->name, str);
973 if (tp_connection_manager_protocol_can_register (proto)) {
976 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_register));
978 empathy_account_settings_set_boolean (settings, "register", TRUE);
982 accounts_dialog_add (dialog, settings);
983 accounts_dialog_model_set_selected (dialog, settings);
985 g_object_unref (settings);
990 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
991 EmpathyAccountsDialog *dialog)
993 EmpathyAccountSettings *settings;
995 settings = accounts_dialog_model_get_selected_settings (dialog);
996 accounts_dialog_update (dialog, settings);
1000 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
1001 EmpathyAccountsDialog *dialog)
1003 TpConnectionManager *cm;
1004 TpConnectionManagerProtocol *proto;
1006 cm = empathy_protocol_chooser_dup_selected (
1007 EMPATHY_PROTOCOL_CHOOSER (dialog->combobox_protocol), &proto);
1009 if (tp_connection_manager_protocol_can_register (proto)) {
1010 gtk_widget_show (dialog->radiobutton_register);
1011 gtk_widget_show (dialog->radiobutton_reuse);
1013 gtk_widget_hide (dialog->radiobutton_register);
1014 gtk_widget_hide (dialog->radiobutton_reuse);
1016 g_object_unref (cm);
1020 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
1021 EmpathyAccountsDialog *dialog)
1024 GtkTreeSelection *selection;
1025 GtkTreeModel *model;
1027 view = GTK_TREE_VIEW (dialog->treeview);
1028 model = gtk_tree_view_get_model (view);
1029 selection = gtk_tree_view_get_selection (view);
1030 gtk_tree_selection_unselect_all (selection);
1032 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1033 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
1034 gtk_widget_hide (dialog->vbox_details);
1035 gtk_widget_hide (dialog->frame_no_protocol);
1036 gtk_widget_show (dialog->frame_new_account);
1038 /* If we have no account, no need of a back button */
1039 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
1040 gtk_widget_show (dialog->button_back);
1042 gtk_widget_hide (dialog->button_back);
1045 accounts_dialog_protocol_changed_cb (dialog->radiobutton_register, dialog);
1046 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radiobutton_reuse),
1048 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_protocol), 0);
1049 gtk_widget_grab_focus (dialog->combobox_protocol);
1053 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1054 EmpathyAccountsDialog *dialog)
1056 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
1060 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1061 EmpathyAccountsDialog *dialog)
1063 EmpathyAccount *account;
1064 GtkWidget *message_dialog;
1067 account = accounts_dialog_model_get_selected_account (dialog);
1069 if (account == NULL || !empathy_account_is_valid (account)) {
1070 accounts_dialog_model_remove_selected (dialog);
1071 accounts_dialog_model_select_first (dialog);
1074 message_dialog = gtk_message_dialog_new
1075 (GTK_WINDOW (dialog->window),
1076 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1077 GTK_MESSAGE_QUESTION,
1079 _("You are about to remove your %s account!\n"
1080 "Are you sure you want to proceed?"),
1081 empathy_account_get_display_name (account));
1083 gtk_message_dialog_format_secondary_text
1084 (GTK_MESSAGE_DIALOG (message_dialog),
1085 _("Any associated conversations and chat rooms will NOT be "
1086 "removed if you decide to proceed.\n"
1088 "Should you decide to add the account back at a later time, "
1089 "they will still be available."));
1091 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1094 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1098 gtk_widget_show (message_dialog);
1099 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
1101 if (res == GTK_RESPONSE_YES) {
1102 empathy_account_manager_remove (dialog->account_manager, account);
1103 accounts_dialog_model_select_first (dialog);
1105 gtk_widget_destroy (message_dialog);
1111 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1112 EmpathyAccountsDialog *dialog)
1114 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
1119 accounts_dialog_response_cb (GtkWidget *widget,
1121 EmpathyAccountsDialog *dialog)
1123 if (response == GTK_RESPONSE_CLOSE) {
1124 gtk_widget_destroy (widget);
1129 accounts_dialog_destroy_cb (GtkWidget *widget,
1130 EmpathyAccountsDialog *dialog)
1132 GList *accounts, *l;
1134 /* Disconnect signals */
1135 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1136 accounts_dialog_account_added_cb,
1138 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1139 accounts_dialog_account_removed_cb,
1141 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1142 accounts_dialog_account_enabled_cb,
1144 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1145 accounts_dialog_account_disabled_cb,
1147 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1148 accounts_dialog_account_changed_cb,
1150 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1151 accounts_dialog_connection_changed_cb,
1154 /* Delete incomplete accounts */
1155 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1156 for (l = accounts; l; l = l->next) {
1157 EmpathyAccount *account;
1160 if (!empathy_account_is_valid (account)) {
1161 /* FIXME: Warn the user the account is not complete
1162 * and is going to be removed. */
1163 empathy_account_manager_remove (dialog->account_manager, account);
1166 g_object_unref (account);
1168 g_list_free (accounts);
1170 if (dialog->connecting_id) {
1171 g_source_remove (dialog->connecting_id);
1174 g_object_unref (dialog->account_manager);
1180 empathy_accounts_dialog_show (GtkWindow *parent,
1181 EmpathyAccount *selected_account)
1183 static EmpathyAccountsDialog *dialog = NULL;
1186 GList *accounts, *l;
1187 gboolean import_asked;
1190 gtk_window_present (GTK_WINDOW (dialog->window));
1191 return dialog->window;
1194 dialog = g_new0 (EmpathyAccountsDialog, 1);
1196 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1198 gui = empathy_builder_get_file (filename,
1199 "accounts_dialog", &dialog->window,
1200 "vbox_details", &dialog->vbox_details,
1201 "frame_no_protocol", &dialog->frame_no_protocol,
1202 "alignment_settings", &dialog->alignment_settings,
1203 "treeview", &dialog->treeview,
1204 "frame_new_account", &dialog->frame_new_account,
1205 "hbox_type", &dialog->hbox_type,
1206 "button_create", &dialog->button_create,
1207 "button_back", &dialog->button_back,
1208 "radiobutton_reuse", &dialog->radiobutton_reuse,
1209 "radiobutton_register", &dialog->radiobutton_register,
1210 "image_type", &dialog->image_type,
1211 "label_name", &dialog->label_name,
1212 "button_add", &dialog->button_add,
1213 "button_remove", &dialog->button_remove,
1214 "button_import", &dialog->button_import,
1218 empathy_builder_connect (gui, dialog,
1219 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1220 "accounts_dialog", "response", accounts_dialog_response_cb,
1221 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1222 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1223 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1224 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1227 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1229 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1232 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1234 g_object_unref (gui);
1236 /* Create protocol chooser */
1237 dialog->combobox_protocol = empathy_protocol_chooser_new ();
1238 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1239 dialog->combobox_protocol,
1241 gtk_widget_show (dialog->combobox_protocol);
1242 g_signal_connect (dialog->combobox_protocol, "changed",
1243 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1246 /* Set up signalling */
1247 dialog->account_manager = empathy_account_manager_dup_singleton ();
1249 g_signal_connect (dialog->account_manager, "account-created",
1250 G_CALLBACK (accounts_dialog_account_added_cb),
1252 g_signal_connect (dialog->account_manager, "account-deleted",
1253 G_CALLBACK (accounts_dialog_account_removed_cb),
1255 g_signal_connect (dialog->account_manager, "account-enabled",
1256 G_CALLBACK (accounts_dialog_account_enabled_cb),
1258 g_signal_connect (dialog->account_manager, "account-disabled",
1259 G_CALLBACK (accounts_dialog_account_disabled_cb),
1261 g_signal_connect (dialog->account_manager, "account-changed",
1262 G_CALLBACK (accounts_dialog_account_changed_cb),
1264 g_signal_connect (dialog->account_manager, "account-connection-changed",
1265 G_CALLBACK (accounts_dialog_connection_changed_cb),
1268 accounts_dialog_model_setup (dialog);
1270 /* Add existing accounts */
1271 accounts = empathy_account_manager_dup_accounts (dialog->account_manager);
1272 for (l = accounts; l; l = l->next) {
1273 accounts_dialog_add_account (dialog, l->data);
1274 g_object_unref (l->data);
1276 g_list_free (accounts);
1278 if (selected_account) {
1279 GtkTreeSelection *selection;
1282 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
1283 if (accounts_dialog_get_account_iter (dialog, selected_account, &iter)) {
1284 gtk_tree_selection_select_iter (selection, &iter);
1287 accounts_dialog_model_select_first (dialog);
1291 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1292 GTK_WINDOW (parent));
1295 gtk_widget_show (dialog->window);
1297 empathy_conf_get_bool (empathy_conf_get (),
1298 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1303 if (empathy_import_dialog_accounts_to_import ()) {
1305 if (!import_asked) {
1306 empathy_conf_set_bool (empathy_conf_get (),
1307 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1308 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1312 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1316 return dialog->window;