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 <glade/glade.h>
32 #include <glib/gi18n.h>
33 #include <dbus/dbus-glib.h>
35 #include <libmissioncontrol/mc-account.h>
36 #include <libmissioncontrol/mc-profile.h>
37 #include <libmissioncontrol/mission-control.h>
38 #include <libmissioncontrol/mc-account-monitor.h>
39 #include <telepathy-glib/util.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy-gtk/empathy-ui-utils.h>
43 #include <libempathy-gtk/empathy-profile-chooser.h>
44 #include <libempathy-gtk/empathy-account-widget.h>
45 #include <libempathy-gtk/empathy-account-widget-irc.h>
46 #include <libempathy-gtk/empathy-account-widget-sip.h>
47 #include <libempathy-gtk/empathy-conf.h>
49 #include "empathy-accounts-dialog.h"
50 #include "empathy-import-dialog.h"
52 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
53 #include <libempathy/empathy-debug.h>
55 /* Flashing delay for icons (milliseconds). */
56 #define FLASH_TIMEOUT 500
61 GtkWidget *alignment_settings;
63 GtkWidget *vbox_details;
64 GtkWidget *frame_no_profile;
68 GtkWidget *button_add;
69 GtkWidget *button_remove;
70 GtkWidget *button_import;
72 GtkWidget *frame_new_account;
73 GtkWidget *combobox_profile;
75 GtkWidget *button_create;
76 GtkWidget *button_back;
77 GtkWidget *checkbutton_register;
79 GtkWidget *image_type;
80 GtkWidget *label_name;
81 GtkWidget *label_type;
82 GtkWidget *settings_widget;
84 gboolean connecting_show;
88 McAccountMonitor *monitor;
90 } EmpathyAccountsDialog;
100 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
102 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
103 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
104 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
105 GtkCellEditable *editable,
107 EmpathyAccountsDialog *dialog);
108 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
109 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
110 GtkCellRenderer *cell,
113 EmpathyAccountsDialog *dialog);
114 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
115 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
117 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
118 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
119 EmpathyAccountsDialog *dialog);
120 static void accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
122 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
124 EmpathyAccountsDialog *dialog);
125 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
127 EmpathyAccountsDialog *dialog);
128 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
132 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
133 static gboolean accounts_dialog_are_accounts_connecting (MissionControl *mc);
134 static void accounts_dialog_status_changed_cb (MissionControl *mc,
135 TpConnectionStatus status,
137 TpConnectionStatusReason reason,
138 const gchar *unique_name,
139 EmpathyAccountsDialog *dialog);
140 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
143 EmpathyAccountsDialog *dialog);
144 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
145 EmpathyAccountsDialog *dialog);
146 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
147 EmpathyAccountsDialog *dialog);
148 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
149 EmpathyAccountsDialog *dialog);
150 static void accounts_dialog_button_import_clicked_cb (GtkWidget *button,
151 EmpathyAccountsDialog *dialog);
152 static void accounts_dialog_response_cb (GtkWidget *widget,
154 EmpathyAccountsDialog *dialog);
155 static void accounts_dialog_destroy_cb (GtkWidget *widget,
156 EmpathyAccountsDialog *dialog);
159 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
164 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
165 mc_account_get_display_name (account));
166 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
172 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
176 const gchar *config_ui;
182 view = GTK_TREE_VIEW (dialog->treeview);
183 model = gtk_tree_view_get_model (view);
185 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
186 /* We have configured accounts, select the first one */
187 accounts_dialog_model_select_first (dialog);
190 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
191 /* We have no account configured but we have some
192 * profiles instsalled. The user obviously wants to add
193 * an account. Click on the Add button for him. */
194 accounts_dialog_button_add_clicked_cb (dialog->button_add,
199 /* No account and no profile, warn the user */
200 gtk_widget_hide (dialog->vbox_details);
201 gtk_widget_hide (dialog->frame_new_account);
202 gtk_widget_show (dialog->frame_no_profile);
203 gtk_widget_set_sensitive (dialog->button_add, FALSE);
204 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
208 /* We have an account selected, destroy old settings and create a new
209 * one for the account selected */
210 gtk_widget_hide (dialog->frame_new_account);
211 gtk_widget_hide (dialog->frame_no_profile);
212 gtk_widget_show (dialog->vbox_details);
213 gtk_widget_set_sensitive (dialog->button_add, TRUE);
214 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
216 if (dialog->settings_widget) {
217 gtk_widget_destroy (dialog->settings_widget);
218 dialog->settings_widget = NULL;
221 profile = mc_account_get_profile (account);
222 config_ui = mc_profile_get_configuration_ui (profile);
223 if (!tp_strdiff (config_ui, "jabber")) {
224 dialog->settings_widget =
225 empathy_account_widget_jabber_new (account);
227 else if (!tp_strdiff (config_ui, "msn")) {
228 dialog ->settings_widget =
229 empathy_account_widget_msn_new (account);
231 else if (!tp_strdiff (config_ui, "local-xmpp")) {
232 dialog->settings_widget =
233 empathy_account_widget_salut_new (account);
235 else if (!tp_strdiff (config_ui, "irc")) {
236 dialog->settings_widget =
237 empathy_account_widget_irc_new (account);
239 else if (!tp_strdiff(config_ui, "icq")) {
240 dialog->settings_widget =
241 empathy_account_widget_icq_new (account);
243 else if (!tp_strdiff(config_ui, "aim")) {
244 dialog->settings_widget =
245 empathy_account_widget_aim_new (account);
247 else if (!tp_strdiff (config_ui, "yahoo")) {
248 dialog->settings_widget =
249 empathy_account_widget_yahoo_new (account);
251 else if (!tp_strdiff (config_ui, "sofiasip")) {
252 dialog->settings_widget =
253 empathy_account_widget_sip_new (account);
255 else if (!tp_strdiff (config_ui, "groupwise")) {
256 dialog->settings_widget =
257 empathy_account_widget_groupwise_new (account);
260 dialog->settings_widget =
261 empathy_account_widget_generic_new (account);
264 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
265 dialog->settings_widget);
268 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
269 mc_profile_get_icon_name (profile),
270 GTK_ICON_SIZE_DIALOG);
271 gtk_widget_set_tooltip_text (dialog->image_type,
272 mc_profile_get_display_name (profile));
274 accounts_dialog_update_name_label (dialog, account);
276 g_object_unref (profile);
280 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
283 GtkTreeSelection *selection;
285 store = gtk_list_store_new (COL_COUNT,
286 G_TYPE_BOOLEAN, /* enabled */
287 G_TYPE_STRING, /* name */
288 G_TYPE_UINT, /* status */
289 MC_TYPE_ACCOUNT); /* account */
291 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
292 GTK_TREE_MODEL (store));
294 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
295 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
297 g_signal_connect (selection, "changed",
298 G_CALLBACK (accounts_dialog_model_selection_changed),
301 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
302 COL_NAME, GTK_SORT_ASCENDING);
304 accounts_dialog_model_add_columns (dialog);
306 g_object_unref (store);
310 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
313 EmpathyAccountsDialog *dialog)
317 GtkTreePath *treepath;
320 if (accounts_dialog_are_accounts_connecting (dialog->mc)) {
321 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
322 (GSourceFunc) accounts_dialog_flash_connecting_cb,
326 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
327 treepath = gtk_tree_path_new_from_string (path);
328 gtk_tree_model_get_iter (model, &iter, treepath);
329 gtk_tree_model_get (model, &iter,
330 COL_ACCOUNT_POINTER, &account,
332 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
335 gtk_tree_path_free (treepath);
337 mc_account_set_display_name (account, new_text);
338 g_object_unref (account);
342 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
344 EmpathyAccountsDialog *dialog)
348 GtkTreePath *treepath;
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_POINTER, &account,
358 gtk_tree_path_free (treepath);
360 enabled = mc_account_is_enabled (account);
361 mc_account_set_enabled (account, !enabled);
363 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
364 mc_account_get_display_name(account));
366 g_object_unref (account);
370 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
371 GtkCellEditable *editable,
373 EmpathyAccountsDialog *dialog)
375 if (dialog->connecting_id) {
376 g_source_remove (dialog->connecting_id);
378 DEBUG ("Editing account name started; stopping flashing");
382 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
385 GtkTreeViewColumn *column;
386 GtkCellRenderer *cell;
388 view = GTK_TREE_VIEW (dialog->treeview);
389 gtk_tree_view_set_headers_visible (view, TRUE);
392 cell = gtk_cell_renderer_toggle_new ();
393 gtk_tree_view_insert_column_with_attributes (view, -1,
396 "active", COL_ENABLED,
398 g_signal_connect (cell, "toggled",
399 G_CALLBACK (accounts_dialog_enable_toggled_cb),
403 column = gtk_tree_view_column_new ();
404 gtk_tree_view_column_set_title (column, _("Accounts"));
405 gtk_tree_view_column_set_expand (column, TRUE);
406 gtk_tree_view_append_column (view, column);
409 cell = gtk_cell_renderer_pixbuf_new ();
410 gtk_tree_view_column_pack_start (column, cell, FALSE);
411 gtk_tree_view_column_set_cell_data_func (column, cell,
412 (GtkTreeCellDataFunc)
413 accounts_dialog_model_pixbuf_data_func,
418 cell = gtk_cell_renderer_text_new ();
420 "ellipsize", PANGO_ELLIPSIZE_END,
423 gtk_tree_view_column_pack_start (column, cell, TRUE);
424 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
425 g_signal_connect (cell, "edited",
426 G_CALLBACK (accounts_dialog_name_edited_cb),
428 g_signal_connect (cell, "editing-started",
429 G_CALLBACK (accounts_dialog_name_editing_started_cb),
434 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
438 GtkTreeSelection *selection;
442 view = GTK_TREE_VIEW (dialog->treeview);
443 model = gtk_tree_view_get_model (view);
445 if (gtk_tree_model_get_iter_first (model, &iter)) {
446 selection = gtk_tree_view_get_selection (view);
447 gtk_tree_selection_select_iter (selection, &iter);
449 accounts_dialog_update_account (dialog, NULL);
454 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
455 GtkCellRenderer *cell,
458 EmpathyAccountsDialog *dialog)
461 const gchar *icon_name;
463 TpConnectionStatus status;
465 gtk_tree_model_get (model, iter,
467 COL_ACCOUNT_POINTER, &account,
470 icon_name = empathy_icon_name_from_account (account);
471 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
474 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
475 (status == TP_CONNECTION_STATUS_CONNECTING &&
476 !dialog->connecting_show)) {
477 GdkPixbuf *modded_pixbuf;
479 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
482 gdk_pixbuf_get_width (pixbuf),
483 gdk_pixbuf_get_height (pixbuf));
485 gdk_pixbuf_saturate_and_pixelate (pixbuf,
489 g_object_unref (pixbuf);
490 pixbuf = modded_pixbuf;
499 g_object_unref (account);
501 g_object_unref (pixbuf);
506 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
511 GtkTreeSelection *selection;
515 /* Update the status in the model */
516 view = GTK_TREE_VIEW (dialog->treeview);
517 selection = gtk_tree_view_get_selection (view);
518 model = gtk_tree_view_get_model (view);
520 for (ok = gtk_tree_model_get_iter_first (model, iter);
522 ok = gtk_tree_model_iter_next (model, iter)) {
523 McAccount *this_account;
526 gtk_tree_model_get (model, iter,
527 COL_ACCOUNT_POINTER, &this_account,
530 equal = empathy_account_equal (this_account, account);
531 g_object_unref (this_account);
542 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
546 GtkTreeSelection *selection;
550 view = GTK_TREE_VIEW (dialog->treeview);
551 selection = gtk_tree_view_get_selection (view);
553 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
557 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
563 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
566 GtkTreeSelection *selection;
569 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
570 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
571 gtk_tree_selection_select_iter (selection, &iter);
576 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
580 GtkTreeSelection *selection;
583 view = GTK_TREE_VIEW (dialog->treeview);
584 selection = gtk_tree_view_get_selection (view);
586 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
590 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
594 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
595 EmpathyAccountsDialog *dialog)
600 gboolean is_selection;
602 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
604 account = accounts_dialog_model_get_selected (dialog);
605 accounts_dialog_update_account (dialog, account);
608 g_object_unref (account);
613 accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
618 TpConnectionStatus status;
622 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
623 status = mission_control_get_connection_status (dialog->mc, account, NULL);
624 name = mc_account_get_display_name (account);
625 enabled = mc_account_is_enabled (account);
627 if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
628 DEBUG ("Adding new account");
629 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
632 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
633 COL_ENABLED, enabled,
636 COL_ACCOUNT_POINTER, account,
639 accounts_dialog_status_changed_cb (dialog->mc,
642 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
643 mc_account_get_unique_name (account),
648 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
650 EmpathyAccountsDialog *dialog)
653 const gchar *current_name;
654 gchar *account_param = NULL;
656 account = mc_account_lookup (unique_name);
657 accounts_dialog_add_or_update_account (dialog, account);
659 /* Change the display name to "%s (%s)" % (protocol, account).
660 * - The protocol is the display name of the profile.
661 * - The account should be the normalized name of the McAccount but
662 * it's not set until first connection, so we get the "account"
663 * parameter for CM that have it. */
664 current_name = mc_account_get_display_name (account);
665 mc_account_get_param_string (account, "account", &account_param);
666 if (!G_STR_EMPTY (account_param)) {
668 const gchar *profile_name;
671 profile = mc_account_get_profile (account);
672 profile_name = mc_profile_get_display_name (profile);
673 new_name = g_strdup_printf ("%s (%s)", profile_name,
676 DEBUG ("Setting new display name for account %s: '%s'",
677 unique_name, new_name);
679 mc_account_set_display_name (account, new_name);
681 g_object_unref (profile);
683 /* FIXME: This CM has no account parameter, what can be done? */
685 g_free (account_param);
686 g_object_unref (account);
690 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
692 EmpathyAccountsDialog *dialog)
696 account = mc_account_lookup (unique_name);
698 accounts_dialog_model_set_selected (dialog, account);
699 accounts_dialog_model_remove_selected (dialog);
701 g_object_unref (account);
705 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
710 gtk_tree_model_row_changed (model, path, iter);
716 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
721 dialog->connecting_show = !dialog->connecting_show;
723 view = GTK_TREE_VIEW (dialog->treeview);
724 model = gtk_tree_view_get_model (view);
726 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
732 accounts_dialog_are_accounts_connecting (MissionControl *mc)
735 gboolean found = FALSE;
737 /* Check if there is still accounts in CONNECTING state */
738 accounts = mc_accounts_list_by_enabled (TRUE);
739 for (l = accounts; l; l = l->next) {
740 McAccount *this_account = l->data;
741 TpConnectionStatus status;
743 status = mission_control_get_connection_status (mc, this_account,
745 if (status == TP_CONNECTION_STATUS_CONNECTING) {
750 mc_accounts_list_free (accounts);
756 accounts_dialog_status_changed_cb (MissionControl *mc,
757 TpConnectionStatus status,
759 TpConnectionStatusReason reason,
760 const gchar *unique_name,
761 EmpathyAccountsDialog *dialog)
766 gboolean found = FALSE;
768 /* Update the status in the model */
769 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
770 account = mc_account_lookup (unique_name);
775 DEBUG ("Status changed for account %s: status=%d presence=%d",
776 unique_name, status, presence);
778 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
781 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
785 path = gtk_tree_model_get_path (model, &iter);
786 gtk_tree_model_row_changed (model, path, &iter);
787 gtk_tree_path_free (path);
789 g_object_unref (account);
791 found = accounts_dialog_are_accounts_connecting (mc);
793 if (!found && dialog->connecting_id) {
794 g_source_remove (dialog->connecting_id);
795 dialog->connecting_id = 0;
797 if (found && !dialog->connecting_id) {
798 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
799 (GSourceFunc) accounts_dialog_flash_connecting_cb,
805 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
807 EmpathyAccountsDialog *dialog)
814 /* Update the status in the model */
815 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
816 account = mc_account_lookup (unique_name);
817 enabled = mc_account_is_enabled (account);
819 DEBUG ("Account %s is now %s",
820 mc_account_get_display_name (account),
821 enabled ? "enabled" : "disabled");
823 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
824 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
825 COL_ENABLED, enabled,
829 g_object_unref (account);
833 accounts_dialog_account_changed_cb (McAccountMonitor *monitor,
835 EmpathyAccountsDialog *dialog)
839 McAccount *selected_account;
841 account = mc_account_lookup (unique_name);
846 accounts_dialog_add_or_update_account (dialog, account);
847 selected_account = accounts_dialog_model_get_selected (dialog);
848 if (empathy_account_equal (account, selected_account)) {
849 accounts_dialog_update_name_label (dialog, account);
854 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
855 EmpathyAccountsDialog *dialog)
860 McProfileCapabilityFlags cap;
862 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
865 account = mc_account_create (profile);
866 /* To translator: %s is the protocol name */
867 str = g_strdup_printf (_("New %s account"),
868 mc_profile_get_display_name (profile));
869 mc_account_set_display_name (account, str);
872 cap = mc_profile_get_capabilities (profile);
873 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
876 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register));
878 mc_account_set_param_boolean (account, "register", TRUE);
882 accounts_dialog_add_or_update_account (dialog, account);
883 accounts_dialog_model_set_selected (dialog, account);
885 g_object_unref (account);
886 g_object_unref (profile);
890 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
891 EmpathyAccountsDialog *dialog)
895 account = accounts_dialog_model_get_selected (dialog);
896 accounts_dialog_update_account (dialog, account);
900 accounts_dialog_profile_changed_cb (GtkWidget *widget,
901 EmpathyAccountsDialog *dialog)
904 McProfileCapabilityFlags cap;
906 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
907 cap = mc_profile_get_capabilities (profile);
909 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
910 gtk_widget_show (dialog->checkbutton_register);
912 gtk_widget_hide (dialog->checkbutton_register);
914 g_object_unref (profile);
918 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
919 EmpathyAccountsDialog *dialog)
922 GtkTreeSelection *selection;
925 view = GTK_TREE_VIEW (dialog->treeview);
926 model = gtk_tree_view_get_model (view);
927 selection = gtk_tree_view_get_selection (view);
928 gtk_tree_selection_unselect_all (selection);
930 gtk_widget_set_sensitive (dialog->button_add, FALSE);
931 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
932 gtk_widget_hide (dialog->vbox_details);
933 gtk_widget_hide (dialog->frame_no_profile);
934 gtk_widget_show (dialog->frame_new_account);
936 /* If we have no account, no need of a back button */
937 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
938 gtk_widget_show (dialog->button_back);
940 gtk_widget_hide (dialog->button_back);
943 accounts_dialog_profile_changed_cb (dialog->checkbutton_register, dialog);
944 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register),
946 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
947 gtk_widget_grab_focus (dialog->combobox_profile);
951 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
952 EmpathyAccountsDialog *dialog)
954 empathy_url_show ("ghelp:empathy?empathy-create-account");
958 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
959 EmpathyAccountsDialog *dialog)
962 GtkWidget *message_dialog;
965 account = accounts_dialog_model_get_selected (dialog);
967 if (!mc_account_is_complete (account)) {
968 accounts_dialog_model_remove_selected (dialog);
969 accounts_dialog_model_select_first (dialog);
972 message_dialog = gtk_message_dialog_new
973 (GTK_WINDOW (dialog->window),
974 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
975 GTK_MESSAGE_QUESTION,
977 _("You are about to remove your %s account!\n"
978 "Are you sure you want to proceed?"),
979 mc_account_get_display_name (account));
981 gtk_message_dialog_format_secondary_text
982 (GTK_MESSAGE_DIALOG (message_dialog),
983 _("Any associated conversations and chat rooms will NOT be "
984 "removed if you decide to proceed.\n"
986 "Should you decide to add the account back at a later time, "
987 "they will still be available."));
989 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
992 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
996 gtk_widget_show (message_dialog);
997 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
999 if (res == GTK_RESPONSE_YES) {
1000 mc_account_delete (account);
1001 accounts_dialog_model_select_first (dialog);
1003 gtk_widget_destroy (message_dialog);
1007 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1008 EmpathyAccountsDialog *dialog)
1010 empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
1014 accounts_dialog_response_cb (GtkWidget *widget,
1016 EmpathyAccountsDialog *dialog)
1018 if (response == GTK_RESPONSE_CLOSE) {
1019 gtk_widget_destroy (widget);
1024 accounts_dialog_destroy_cb (GtkWidget *widget,
1025 EmpathyAccountsDialog *dialog)
1027 GList *accounts, *l;
1029 /* Disconnect signals */
1030 g_signal_handlers_disconnect_by_func (dialog->monitor,
1031 accounts_dialog_account_added_cb,
1033 g_signal_handlers_disconnect_by_func (dialog->monitor,
1034 accounts_dialog_account_removed_cb,
1036 g_signal_handlers_disconnect_by_func (dialog->monitor,
1037 accounts_dialog_account_enabled_cb,
1039 g_signal_handlers_disconnect_by_func (dialog->monitor,
1040 accounts_dialog_account_changed_cb,
1042 empathy_disconnect_account_status_changed (dialog->token);
1044 /* Delete incomplete accounts */
1045 accounts = mc_accounts_list ();
1046 for (l = accounts; l; l = l->next) {
1050 if (!mc_account_is_complete (account)) {
1051 /* FIXME: Warn the user the account is not complete
1052 * and is going to be removed. */
1053 mc_account_delete (account);
1056 g_object_unref (account);
1058 g_list_free (accounts);
1060 if (dialog->connecting_id) {
1061 g_source_remove (dialog->connecting_id);
1064 g_object_unref (dialog->mc);
1065 g_object_unref (dialog->monitor);
1071 empathy_accounts_dialog_show (GtkWindow *parent,
1072 McAccount *selected_account)
1074 static EmpathyAccountsDialog *dialog = NULL;
1077 GList *accounts, *l;
1078 gboolean import_asked;
1081 gtk_window_present (GTK_WINDOW (dialog->window));
1082 return dialog->window;
1085 dialog = g_new0 (EmpathyAccountsDialog, 1);
1087 filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
1089 glade = empathy_glade_get_file (filename,
1092 "accounts_dialog", &dialog->window,
1093 "vbox_details", &dialog->vbox_details,
1094 "frame_no_profile", &dialog->frame_no_profile,
1095 "alignment_settings", &dialog->alignment_settings,
1096 "treeview", &dialog->treeview,
1097 "frame_new_account", &dialog->frame_new_account,
1098 "hbox_type", &dialog->hbox_type,
1099 "button_create", &dialog->button_create,
1100 "button_back", &dialog->button_back,
1101 "checkbutton_register", &dialog->checkbutton_register,
1102 "image_type", &dialog->image_type,
1103 "label_name", &dialog->label_name,
1104 "button_add", &dialog->button_add,
1105 "button_remove", &dialog->button_remove,
1106 "button_import", &dialog->button_import,
1110 empathy_glade_connect (glade,
1112 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1113 "accounts_dialog", "response", accounts_dialog_response_cb,
1114 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1115 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1116 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1117 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1118 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1119 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1122 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1124 g_object_unref (glade);
1126 /* Create profile chooser */
1127 dialog->combobox_profile = empathy_profile_chooser_new ();
1128 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1129 dialog->combobox_profile,
1131 gtk_widget_show (dialog->combobox_profile);
1132 g_signal_connect (dialog->combobox_profile, "changed",
1133 G_CALLBACK (accounts_dialog_profile_changed_cb),
1136 /* Set up signalling */
1137 dialog->mc = empathy_mission_control_new ();
1138 dialog->monitor = mc_account_monitor_new ();
1140 g_signal_connect (dialog->monitor, "account-created",
1141 G_CALLBACK (accounts_dialog_account_added_cb),
1143 g_signal_connect (dialog->monitor, "account-deleted",
1144 G_CALLBACK (accounts_dialog_account_removed_cb),
1146 g_signal_connect (dialog->monitor, "account-enabled",
1147 G_CALLBACK (accounts_dialog_account_enabled_cb),
1149 g_signal_connect (dialog->monitor, "account-disabled",
1150 G_CALLBACK (accounts_dialog_account_enabled_cb),
1152 g_signal_connect (dialog->monitor, "account-changed",
1153 G_CALLBACK (accounts_dialog_account_changed_cb),
1155 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1156 G_CALLBACK (accounts_dialog_status_changed_cb),
1159 accounts_dialog_model_setup (dialog);
1161 /* Add existing accounts */
1162 accounts = mc_accounts_list ();
1163 for (l = accounts; l; l = l->next) {
1164 accounts_dialog_add_or_update_account (dialog, l->data);
1165 g_object_unref (l->data);
1167 g_list_free (accounts);
1169 if (selected_account) {
1170 accounts_dialog_model_set_selected (dialog, selected_account);
1172 accounts_dialog_model_select_first (dialog);
1176 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1177 GTK_WINDOW (parent));
1180 gtk_widget_show (dialog->window);
1182 empathy_conf_get_bool (empathy_conf_get (),
1183 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1185 if (!import_asked) {
1186 empathy_conf_set_bool (empathy_conf_get (),
1187 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1188 empathy_import_dialog_show (GTK_WINDOW (dialog->window),
1192 return dialog->window;