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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, 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 <libmissioncontrol/mc-account.h>
35 #include <libmissioncontrol/mc-profile.h>
36 #include <telepathy-glib/util.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-account-manager.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
41 #include <libempathy-gtk/empathy-profile-chooser.h>
42 #include <libempathy-gtk/empathy-account-widget.h>
43 #include <libempathy-gtk/empathy-account-widget-irc.h>
44 #include <libempathy-gtk/empathy-account-widget-sip.h>
45 #include <libempathy-gtk/empathy-conf.h>
47 #include "empathy-accounts-dialog.h"
48 #include "empathy-import-dialog.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
51 #include <libempathy/empathy-debug.h>
53 /* Flashing delay for icons (milliseconds). */
54 #define FLASH_TIMEOUT 500
59 GtkWidget *alignment_settings;
61 GtkWidget *vbox_details;
62 GtkWidget *frame_no_profile;
66 GtkWidget *button_add;
67 GtkWidget *button_remove;
68 GtkWidget *button_import;
70 GtkWidget *frame_new_account;
71 GtkWidget *combobox_profile;
73 GtkWidget *button_create;
74 GtkWidget *button_back;
75 GtkWidget *checkbutton_register;
77 GtkWidget *image_type;
78 GtkWidget *label_name;
79 GtkWidget *label_type;
80 GtkWidget *settings_widget;
82 gboolean connecting_show;
85 EmpathyAccountManager *account_manager;
87 } EmpathyAccountsDialog;
97 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
99 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
100 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
101 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
102 GtkCellEditable *editable,
104 EmpathyAccountsDialog *dialog);
105 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
106 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
107 GtkCellRenderer *cell,
110 EmpathyAccountsDialog *dialog);
111 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
112 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
114 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
115 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
116 EmpathyAccountsDialog *dialog);
117 static void accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
119 static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
121 EmpathyAccountsDialog *dialog);
122 static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
124 EmpathyAccountsDialog *dialog);
125 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
129 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
130 static void accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
132 TpConnectionStatusReason reason,
133 TpConnectionStatus current,
134 TpConnectionStatus previous,
135 EmpathyAccountsDialog *dialog);
136 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
137 EmpathyAccountsDialog *dialog);
138 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
139 EmpathyAccountsDialog *dialog);
140 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
143 EmpathyAccountsDialog *dialog);
144 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
145 EmpathyAccountsDialog *dialog);
146 static void accounts_dialog_button_import_clicked_cb (GtkWidget *button,
147 EmpathyAccountsDialog *dialog);
148 static void accounts_dialog_response_cb (GtkWidget *widget,
150 EmpathyAccountsDialog *dialog);
151 static void accounts_dialog_destroy_cb (GtkWidget *widget,
152 EmpathyAccountsDialog *dialog);
155 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
160 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
161 mc_account_get_display_name (account));
162 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
168 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
172 const gchar *config_ui;
178 view = GTK_TREE_VIEW (dialog->treeview);
179 model = gtk_tree_view_get_model (view);
181 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
182 /* We have configured accounts, select the first one */
183 accounts_dialog_model_select_first (dialog);
186 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
187 /* We have no account configured but we have some
188 * profiles instsalled. The user obviously wants to add
189 * an account. Click on the Add button for him. */
190 accounts_dialog_button_add_clicked_cb (dialog->button_add,
195 /* No account and no profile, warn the user */
196 gtk_widget_hide (dialog->vbox_details);
197 gtk_widget_hide (dialog->frame_new_account);
198 gtk_widget_show (dialog->frame_no_profile);
199 gtk_widget_set_sensitive (dialog->button_add, FALSE);
200 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
204 /* We have an account selected, destroy old settings and create a new
205 * one for the account selected */
206 gtk_widget_hide (dialog->frame_new_account);
207 gtk_widget_hide (dialog->frame_no_profile);
208 gtk_widget_show (dialog->vbox_details);
209 gtk_widget_set_sensitive (dialog->button_add, TRUE);
210 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
212 if (dialog->settings_widget) {
213 gtk_widget_destroy (dialog->settings_widget);
214 dialog->settings_widget = NULL;
217 profile = mc_account_get_profile (account);
218 config_ui = mc_profile_get_configuration_ui (profile);
219 if (!tp_strdiff (config_ui, "jabber")) {
220 dialog->settings_widget =
221 empathy_account_widget_jabber_new (account);
223 else if (!tp_strdiff (config_ui, "msn")) {
224 dialog ->settings_widget =
225 empathy_account_widget_msn_new (account);
227 else if (!tp_strdiff (config_ui, "local-xmpp")) {
228 dialog->settings_widget =
229 empathy_account_widget_salut_new (account);
231 else if (!tp_strdiff (config_ui, "irc")) {
232 dialog->settings_widget =
233 empathy_account_widget_irc_new (account);
235 else if (!tp_strdiff(config_ui, "icq")) {
236 dialog->settings_widget =
237 empathy_account_widget_icq_new (account);
239 else if (!tp_strdiff(config_ui, "aim")) {
240 dialog->settings_widget =
241 empathy_account_widget_aim_new (account);
243 else if (!tp_strdiff (config_ui, "yahoo")) {
244 dialog->settings_widget =
245 empathy_account_widget_yahoo_new (account);
247 else if (!tp_strdiff (config_ui, "sofiasip")) {
248 dialog->settings_widget =
249 empathy_account_widget_sip_new (account);
251 else if (!tp_strdiff (config_ui, "groupwise")) {
252 dialog->settings_widget =
253 empathy_account_widget_groupwise_new (account);
256 dialog->settings_widget =
257 empathy_account_widget_generic_new (account);
260 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
261 dialog->settings_widget);
262 gtk_widget_show (dialog->settings_widget);
265 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
266 mc_profile_get_icon_name (profile),
267 GTK_ICON_SIZE_DIALOG);
268 gtk_widget_set_tooltip_text (dialog->image_type,
269 mc_profile_get_display_name (profile));
271 accounts_dialog_update_name_label (dialog, account);
273 g_object_unref (profile);
277 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
280 GtkTreeSelection *selection;
282 store = gtk_list_store_new (COL_COUNT,
283 G_TYPE_BOOLEAN, /* enabled */
284 G_TYPE_STRING, /* name */
285 G_TYPE_UINT, /* status */
286 MC_TYPE_ACCOUNT); /* account */
288 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
289 GTK_TREE_MODEL (store));
291 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
292 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
294 g_signal_connect (selection, "changed",
295 G_CALLBACK (accounts_dialog_model_selection_changed),
298 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
299 COL_NAME, GTK_SORT_ASCENDING);
301 accounts_dialog_model_add_columns (dialog);
303 g_object_unref (store);
307 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
310 EmpathyAccountsDialog *dialog)
314 GtkTreePath *treepath;
317 if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
318 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
319 (GSourceFunc) accounts_dialog_flash_connecting_cb,
323 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
324 treepath = gtk_tree_path_new_from_string (path);
325 gtk_tree_model_get_iter (model, &iter, treepath);
326 gtk_tree_model_get (model, &iter,
327 COL_ACCOUNT_POINTER, &account,
329 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
332 gtk_tree_path_free (treepath);
334 mc_account_set_display_name (account, new_text);
335 g_object_unref (account);
339 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
341 EmpathyAccountsDialog *dialog)
345 GtkTreePath *treepath;
349 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
350 treepath = gtk_tree_path_new_from_string (path);
351 gtk_tree_model_get_iter (model, &iter, treepath);
352 gtk_tree_model_get (model, &iter,
353 COL_ACCOUNT_POINTER, &account,
355 gtk_tree_path_free (treepath);
357 enabled = mc_account_is_enabled (account);
358 mc_account_set_enabled (account, !enabled);
360 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
361 mc_account_get_display_name(account));
363 g_object_unref (account);
367 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
368 GtkCellEditable *editable,
370 EmpathyAccountsDialog *dialog)
372 if (dialog->connecting_id) {
373 g_source_remove (dialog->connecting_id);
375 DEBUG ("Editing account name started; stopping flashing");
379 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
382 GtkTreeViewColumn *column;
383 GtkCellRenderer *cell;
385 view = GTK_TREE_VIEW (dialog->treeview);
386 gtk_tree_view_set_headers_visible (view, TRUE);
389 cell = gtk_cell_renderer_toggle_new ();
390 gtk_tree_view_insert_column_with_attributes (view, -1,
393 "active", COL_ENABLED,
395 g_signal_connect (cell, "toggled",
396 G_CALLBACK (accounts_dialog_enable_toggled_cb),
400 column = gtk_tree_view_column_new ();
401 gtk_tree_view_column_set_title (column, _("Accounts"));
402 gtk_tree_view_column_set_expand (column, TRUE);
403 gtk_tree_view_append_column (view, column);
406 cell = gtk_cell_renderer_pixbuf_new ();
407 gtk_tree_view_column_pack_start (column, cell, FALSE);
408 gtk_tree_view_column_set_cell_data_func (column, cell,
409 (GtkTreeCellDataFunc)
410 accounts_dialog_model_pixbuf_data_func,
415 cell = gtk_cell_renderer_text_new ();
417 "ellipsize", PANGO_ELLIPSIZE_END,
420 gtk_tree_view_column_pack_start (column, cell, TRUE);
421 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
422 g_signal_connect (cell, "edited",
423 G_CALLBACK (accounts_dialog_name_edited_cb),
425 g_signal_connect (cell, "editing-started",
426 G_CALLBACK (accounts_dialog_name_editing_started_cb),
431 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
435 GtkTreeSelection *selection;
439 view = GTK_TREE_VIEW (dialog->treeview);
440 model = gtk_tree_view_get_model (view);
442 if (gtk_tree_model_get_iter_first (model, &iter)) {
443 selection = gtk_tree_view_get_selection (view);
444 gtk_tree_selection_select_iter (selection, &iter);
446 accounts_dialog_update_account (dialog, NULL);
451 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
452 GtkCellRenderer *cell,
455 EmpathyAccountsDialog *dialog)
458 const gchar *icon_name;
460 TpConnectionStatus status;
462 gtk_tree_model_get (model, iter,
464 COL_ACCOUNT_POINTER, &account,
467 icon_name = empathy_icon_name_from_account (account);
468 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
471 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
472 (status == TP_CONNECTION_STATUS_CONNECTING &&
473 !dialog->connecting_show)) {
474 GdkPixbuf *modded_pixbuf;
476 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
479 gdk_pixbuf_get_width (pixbuf),
480 gdk_pixbuf_get_height (pixbuf));
482 gdk_pixbuf_saturate_and_pixelate (pixbuf,
486 g_object_unref (pixbuf);
487 pixbuf = modded_pixbuf;
496 g_object_unref (account);
498 g_object_unref (pixbuf);
503 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
508 GtkTreeSelection *selection;
512 /* Update the status in the model */
513 view = GTK_TREE_VIEW (dialog->treeview);
514 selection = gtk_tree_view_get_selection (view);
515 model = gtk_tree_view_get_model (view);
517 for (ok = gtk_tree_model_get_iter_first (model, iter);
519 ok = gtk_tree_model_iter_next (model, iter)) {
520 McAccount *this_account;
523 gtk_tree_model_get (model, iter,
524 COL_ACCOUNT_POINTER, &this_account,
527 equal = empathy_account_equal (this_account, account);
528 g_object_unref (this_account);
539 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
543 GtkTreeSelection *selection;
547 view = GTK_TREE_VIEW (dialog->treeview);
548 selection = gtk_tree_view_get_selection (view);
550 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
554 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
560 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
563 GtkTreeSelection *selection;
566 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
567 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
568 gtk_tree_selection_select_iter (selection, &iter);
573 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
577 GtkTreeSelection *selection;
580 view = GTK_TREE_VIEW (dialog->treeview);
581 selection = gtk_tree_view_get_selection (view);
583 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
587 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
591 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
592 EmpathyAccountsDialog *dialog)
597 gboolean is_selection;
599 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
601 account = accounts_dialog_model_get_selected (dialog);
602 accounts_dialog_update_account (dialog, account);
605 g_object_unref (account);
610 accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
615 TpConnectionStatus status;
619 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
620 status = mission_control_get_connection_status (dialog->mc, account, NULL);
621 name = mc_account_get_display_name (account);
622 enabled = mc_account_is_enabled (account);
624 if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
625 DEBUG ("Adding new account");
626 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
629 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
630 COL_ENABLED, enabled,
633 COL_ACCOUNT_POINTER, account,
636 accounts_dialog_connection_changed_cb (dialog->account_manager,
638 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
640 TP_CONNECTION_STATUS_DISCONNECTED,
645 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
647 EmpathyAccountsDialog *dialog)
649 const gchar *current_name;
650 gchar *account_param = NULL;
652 accounts_dialog_add_or_update_account (dialog, account);
654 /* Change the display name to "%s (%s)" % (protocol, account).
655 * - The protocol is the display name of the profile.
656 * - The account should be the normalized name of the McAccount but
657 * it's not set until first connection, so we get the "account"
658 * parameter for CM that have it. */
659 current_name = mc_account_get_display_name (account);
660 mc_account_get_param_string (account, "account", &account_param);
661 if (!EMP_STR_EMPTY (account_param)) {
663 const gchar *profile_name;
666 profile = mc_account_get_profile (account);
667 profile_name = mc_profile_get_display_name (profile);
668 new_name = g_strdup_printf ("%s (%s)", profile_name,
671 DEBUG ("Setting new display name for account %s: '%s'",
672 mc_account_get_unique_name (account), new_name);
674 mc_account_set_display_name (account, new_name);
676 g_object_unref (profile);
678 /* FIXME: This CM has no account parameter, what can be done? */
680 g_free (account_param);
684 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
686 EmpathyAccountsDialog *dialog)
689 accounts_dialog_model_set_selected (dialog, account);
690 accounts_dialog_model_remove_selected (dialog);
694 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
699 gtk_tree_model_row_changed (model, path, iter);
705 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
710 dialog->connecting_show = !dialog->connecting_show;
712 view = GTK_TREE_VIEW (dialog->treeview);
713 model = gtk_tree_view_get_model (view);
715 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
721 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
723 TpConnectionStatusReason reason,
724 TpConnectionStatus current,
725 TpConnectionStatus previous,
726 EmpathyAccountsDialog *dialog)
732 /* Update the status in the model */
733 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
735 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
738 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
742 path = gtk_tree_model_get_path (model, &iter);
743 gtk_tree_model_row_changed (model, path, &iter);
744 gtk_tree_path_free (path);
747 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
749 if (!found && dialog->connecting_id) {
750 g_source_remove (dialog->connecting_id);
751 dialog->connecting_id = 0;
754 if (found && !dialog->connecting_id) {
755 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
756 (GSourceFunc) accounts_dialog_flash_connecting_cb,
762 enable_or_disable_account (EmpathyAccountsDialog *dialog,
769 /* Update the status in the model */
770 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
772 DEBUG ("Account %s is now %s",
773 mc_account_get_display_name (account),
774 enabled ? "enabled" : "disabled");
776 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
777 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
778 COL_ENABLED, enabled,
784 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
786 EmpathyAccountsDialog *dialog)
788 enable_or_disable_account (dialog, account, FALSE);
792 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
794 EmpathyAccountsDialog *dialog)
796 enable_or_disable_account (dialog, account, TRUE);
800 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
802 EmpathyAccountsDialog *dialog)
804 McAccount *selected_account;
806 accounts_dialog_add_or_update_account (dialog, account);
807 selected_account = accounts_dialog_model_get_selected (dialog);
808 if (empathy_account_equal (account, selected_account)) {
809 accounts_dialog_update_name_label (dialog, account);
814 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
815 EmpathyAccountsDialog *dialog)
820 McProfileCapabilityFlags cap;
822 profile = empathy_profile_chooser_dup_selected (dialog->combobox_profile);
825 account = mc_account_create (profile);
826 if (account == NULL) {
827 /* We can't display an error to the user as MC doesn't give us
828 * any clue about the reason of the failure... */
829 g_object_unref (profile);
833 /* To translator: %s is the protocol name */
834 str = g_strdup_printf (_("New %s account"),
835 mc_profile_get_display_name (profile));
836 mc_account_set_display_name (account, str);
839 cap = mc_profile_get_capabilities (profile);
840 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
843 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register));
845 mc_account_set_param_boolean (account, "register", TRUE);
849 accounts_dialog_add_or_update_account (dialog, account);
850 accounts_dialog_model_set_selected (dialog, account);
852 g_object_unref (account);
853 g_object_unref (profile);
857 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
858 EmpathyAccountsDialog *dialog)
862 account = accounts_dialog_model_get_selected (dialog);
863 accounts_dialog_update_account (dialog, account);
867 accounts_dialog_profile_changed_cb (GtkWidget *widget,
868 EmpathyAccountsDialog *dialog)
871 McProfileCapabilityFlags cap;
873 profile = empathy_profile_chooser_dup_selected (dialog->combobox_profile);
874 cap = mc_profile_get_capabilities (profile);
876 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
877 gtk_widget_show (dialog->checkbutton_register);
879 gtk_widget_hide (dialog->checkbutton_register);
881 g_object_unref (profile);
885 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
886 EmpathyAccountsDialog *dialog)
889 GtkTreeSelection *selection;
892 view = GTK_TREE_VIEW (dialog->treeview);
893 model = gtk_tree_view_get_model (view);
894 selection = gtk_tree_view_get_selection (view);
895 gtk_tree_selection_unselect_all (selection);
897 gtk_widget_set_sensitive (dialog->button_add, FALSE);
898 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
899 gtk_widget_hide (dialog->vbox_details);
900 gtk_widget_hide (dialog->frame_no_profile);
901 gtk_widget_show (dialog->frame_new_account);
903 /* If we have no account, no need of a back button */
904 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
905 gtk_widget_show (dialog->button_back);
907 gtk_widget_hide (dialog->button_back);
910 accounts_dialog_profile_changed_cb (dialog->checkbutton_register, dialog);
911 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register),
913 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
914 gtk_widget_grab_focus (dialog->combobox_profile);
918 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
919 EmpathyAccountsDialog *dialog)
921 empathy_url_show (button, "ghelp:empathy?empathy-create-account");
925 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
926 EmpathyAccountsDialog *dialog)
929 GtkWidget *message_dialog;
932 account = accounts_dialog_model_get_selected (dialog);
934 if (!mc_account_is_complete (account)) {
935 accounts_dialog_model_remove_selected (dialog);
936 accounts_dialog_model_select_first (dialog);
939 message_dialog = gtk_message_dialog_new
940 (GTK_WINDOW (dialog->window),
941 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
942 GTK_MESSAGE_QUESTION,
944 _("You are about to remove your %s account!\n"
945 "Are you sure you want to proceed?"),
946 mc_account_get_display_name (account));
948 gtk_message_dialog_format_secondary_text
949 (GTK_MESSAGE_DIALOG (message_dialog),
950 _("Any associated conversations and chat rooms will NOT be "
951 "removed if you decide to proceed.\n"
953 "Should you decide to add the account back at a later time, "
954 "they will still be available."));
956 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
959 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
963 gtk_widget_show (message_dialog);
964 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
966 if (res == GTK_RESPONSE_YES) {
967 mc_account_delete (account);
968 accounts_dialog_model_select_first (dialog);
970 gtk_widget_destroy (message_dialog);
974 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
975 EmpathyAccountsDialog *dialog)
977 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
981 accounts_dialog_response_cb (GtkWidget *widget,
983 EmpathyAccountsDialog *dialog)
985 if (response == GTK_RESPONSE_CLOSE) {
986 gtk_widget_destroy (widget);
991 accounts_dialog_destroy_cb (GtkWidget *widget,
992 EmpathyAccountsDialog *dialog)
996 /* Disconnect signals */
997 g_signal_handlers_disconnect_by_func (dialog->account_manager,
998 accounts_dialog_account_added_cb,
1000 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1001 accounts_dialog_account_removed_cb,
1003 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1004 accounts_dialog_account_enabled_cb,
1006 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1007 accounts_dialog_account_disabled_cb,
1009 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1010 accounts_dialog_account_changed_cb,
1012 g_signal_handlers_disconnect_by_func (dialog->account_manager,
1013 accounts_dialog_connection_changed_cb,
1016 /* Delete incomplete accounts */
1017 accounts = mc_accounts_list ();
1018 for (l = accounts; l; l = l->next) {
1022 if (!mc_account_is_complete (account)) {
1023 /* FIXME: Warn the user the account is not complete
1024 * and is going to be removed. */
1025 mc_account_delete (account);
1028 g_object_unref (account);
1030 g_list_free (accounts);
1032 if (dialog->connecting_id) {
1033 g_source_remove (dialog->connecting_id);
1036 g_object_unref (dialog->account_manager);
1037 g_object_unref (dialog->mc);
1043 empathy_accounts_dialog_show (GtkWindow *parent,
1044 McAccount *selected_account)
1046 static EmpathyAccountsDialog *dialog = NULL;
1049 GList *accounts, *l;
1050 gboolean import_asked;
1053 gtk_window_present (GTK_WINDOW (dialog->window));
1054 return dialog->window;
1057 dialog = g_new0 (EmpathyAccountsDialog, 1);
1059 filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
1061 gui = empathy_builder_get_file (filename,
1062 "accounts_dialog", &dialog->window,
1063 "vbox_details", &dialog->vbox_details,
1064 "frame_no_profile", &dialog->frame_no_profile,
1065 "alignment_settings", &dialog->alignment_settings,
1066 "treeview", &dialog->treeview,
1067 "frame_new_account", &dialog->frame_new_account,
1068 "hbox_type", &dialog->hbox_type,
1069 "button_create", &dialog->button_create,
1070 "button_back", &dialog->button_back,
1071 "checkbutton_register", &dialog->checkbutton_register,
1072 "image_type", &dialog->image_type,
1073 "label_name", &dialog->label_name,
1074 "button_add", &dialog->button_add,
1075 "button_remove", &dialog->button_remove,
1076 "button_import", &dialog->button_import,
1080 empathy_builder_connect (gui, dialog,
1081 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1082 "accounts_dialog", "response", accounts_dialog_response_cb,
1083 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1084 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1085 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1086 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1087 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1088 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1091 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1093 g_object_unref (gui);
1095 /* Create profile chooser */
1096 dialog->combobox_profile = empathy_profile_chooser_new ();
1097 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1098 dialog->combobox_profile,
1100 gtk_widget_show (dialog->combobox_profile);
1101 g_signal_connect (dialog->combobox_profile, "changed",
1102 G_CALLBACK (accounts_dialog_profile_changed_cb),
1105 /* Set up signalling */
1106 dialog->account_manager = empathy_account_manager_dup_singleton ();
1107 dialog->mc = empathy_mission_control_dup_singleton ();
1109 g_signal_connect (dialog->account_manager, "account-created",
1110 G_CALLBACK (accounts_dialog_account_added_cb),
1112 g_signal_connect (dialog->account_manager, "account-deleted",
1113 G_CALLBACK (accounts_dialog_account_removed_cb),
1115 g_signal_connect (dialog->account_manager, "account-enabled",
1116 G_CALLBACK (accounts_dialog_account_enabled_cb),
1118 g_signal_connect (dialog->account_manager, "account-disabled",
1119 G_CALLBACK (accounts_dialog_account_disabled_cb),
1121 g_signal_connect (dialog->account_manager, "account-changed",
1122 G_CALLBACK (accounts_dialog_account_changed_cb),
1124 g_signal_connect (dialog->account_manager, "account-connection-changed",
1125 G_CALLBACK (accounts_dialog_connection_changed_cb),
1128 accounts_dialog_model_setup (dialog);
1130 /* Add existing accounts */
1131 accounts = mc_accounts_list ();
1132 for (l = accounts; l; l = l->next) {
1133 accounts_dialog_add_or_update_account (dialog, l->data);
1134 g_object_unref (l->data);
1136 g_list_free (accounts);
1138 if (selected_account) {
1139 accounts_dialog_model_set_selected (dialog, selected_account);
1141 accounts_dialog_model_select_first (dialog);
1145 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1146 GTK_WINDOW (parent));
1149 gtk_widget_show (dialog->window);
1151 empathy_conf_get_bool (empathy_conf_get (),
1152 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1155 if (empathy_import_dialog_accounts_to_import ()) {
1157 if (!import_asked) {
1158 empathy_conf_set_bool (empathy_conf_get (),
1159 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1160 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1164 gtk_widget_set_sensitive (dialog->button_import, FALSE);
1167 return dialog->window;