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>
48 #include "empathy-accounts-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;
69 GtkWidget *frame_new_account;
70 GtkWidget *combobox_profile;
72 GtkWidget *button_create;
73 GtkWidget *button_back;
74 GtkWidget *checkbutton_register;
76 GtkWidget *image_type;
77 GtkWidget *label_name;
78 GtkWidget *label_type;
79 GtkWidget *settings_widget;
81 gboolean connecting_show;
85 McAccountMonitor *monitor;
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 (McAccountMonitor *monitor,
121 EmpathyAccountsDialog *dialog);
122 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
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 gboolean accounts_dialog_are_accounts_connecting (MissionControl *mc);
131 static void accounts_dialog_status_changed_cb (MissionControl *mc,
132 TpConnectionStatus status,
134 TpConnectionStatusReason reason,
135 const gchar *unique_name,
136 EmpathyAccountsDialog *dialog);
137 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
138 EmpathyAccountsDialog *dialog);
139 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
140 EmpathyAccountsDialog *dialog);
141 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
142 EmpathyAccountsDialog *dialog);
143 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
144 EmpathyAccountsDialog *dialog);
145 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
146 EmpathyAccountsDialog *dialog);
147 static void accounts_dialog_response_cb (GtkWidget *widget,
149 EmpathyAccountsDialog *dialog);
150 static void accounts_dialog_destroy_cb (GtkWidget *widget,
151 EmpathyAccountsDialog *dialog);
154 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
158 const gchar *config_ui;
165 view = GTK_TREE_VIEW (dialog->treeview);
166 model = gtk_tree_view_get_model (view);
168 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
169 /* We have configured accounts, select the first one */
170 accounts_dialog_model_select_first (dialog);
173 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
174 /* We have no account configured but we have some
175 * profiles instsalled. The user obviously wants to add
176 * an account. Click on the Add button for him. */
177 accounts_dialog_button_add_clicked_cb (dialog->button_add,
182 /* No account and no profile, warn the user */
183 gtk_widget_hide (dialog->vbox_details);
184 gtk_widget_hide (dialog->frame_new_account);
185 gtk_widget_show (dialog->frame_no_profile);
186 gtk_widget_set_sensitive (dialog->button_add, FALSE);
187 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
191 /* We have an account selected, destroy old settings and create a new
192 * one for the account selected */
193 gtk_widget_hide (dialog->frame_new_account);
194 gtk_widget_hide (dialog->frame_no_profile);
195 gtk_widget_show (dialog->vbox_details);
196 gtk_widget_set_sensitive (dialog->button_add, TRUE);
197 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
199 if (dialog->settings_widget) {
200 gtk_widget_destroy (dialog->settings_widget);
201 dialog->settings_widget = NULL;
204 profile = mc_account_get_profile (account);
205 config_ui = mc_profile_get_configuration_ui (profile);
206 if (!tp_strdiff (config_ui, "jabber")) {
207 dialog->settings_widget =
208 empathy_account_widget_jabber_new (account);
210 else if (!tp_strdiff (config_ui, "msn")) {
211 dialog ->settings_widget =
212 empathy_account_widget_msn_new (account);
214 else if (!tp_strdiff (config_ui, "local-xmpp")) {
215 dialog->settings_widget =
216 empathy_account_widget_salut_new (account);
218 else if (!tp_strdiff (config_ui, "irc")) {
219 dialog->settings_widget =
220 empathy_account_widget_irc_new (account);
222 else if (!tp_strdiff(config_ui, "icq")) {
223 dialog->settings_widget =
224 empathy_account_widget_icq_new (account);
226 else if (!tp_strdiff(config_ui, "aim")) {
227 dialog->settings_widget =
228 empathy_account_widget_aim_new (account);
230 else if (!tp_strdiff (config_ui, "yahoo")) {
231 dialog->settings_widget =
232 empathy_account_widget_yahoo_new (account);
234 else if (!tp_strdiff (config_ui, "sofiasip")) {
235 dialog->settings_widget =
236 empathy_account_widget_sip_new (account);
238 else if (!tp_strdiff (config_ui, "groupwise")) {
239 dialog->settings_widget =
240 empathy_account_widget_groupwise_new (account);
243 dialog->settings_widget =
244 empathy_account_widget_generic_new (account);
247 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
248 dialog->settings_widget);
251 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
252 mc_profile_get_icon_name (profile),
253 GTK_ICON_SIZE_DIALOG);
254 gtk_widget_set_tooltip_text (dialog->image_type,
255 mc_profile_get_display_name (profile));
257 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
258 mc_account_get_display_name (account));
259 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
262 g_object_unref (profile);
266 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
269 GtkTreeSelection *selection;
271 store = gtk_list_store_new (COL_COUNT,
272 G_TYPE_BOOLEAN, /* enabled */
273 G_TYPE_STRING, /* name */
274 G_TYPE_UINT, /* status */
275 MC_TYPE_ACCOUNT); /* account */
277 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
278 GTK_TREE_MODEL (store));
280 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
281 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
283 g_signal_connect (selection, "changed",
284 G_CALLBACK (accounts_dialog_model_selection_changed),
287 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
288 COL_NAME, GTK_SORT_ASCENDING);
290 accounts_dialog_model_add_columns (dialog);
292 g_object_unref (store);
296 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
299 EmpathyAccountsDialog *dialog)
303 GtkTreePath *treepath;
306 if (accounts_dialog_are_accounts_connecting (dialog->mc)) {
307 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
308 (GSourceFunc) accounts_dialog_flash_connecting_cb,
312 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
313 treepath = gtk_tree_path_new_from_string (path);
314 gtk_tree_model_get_iter (model, &iter, treepath);
315 gtk_tree_model_get (model, &iter,
316 COL_ACCOUNT_POINTER, &account,
318 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
321 gtk_tree_path_free (treepath);
323 mc_account_set_display_name (account, new_text);
324 g_object_unref (account);
328 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
330 EmpathyAccountsDialog *dialog)
334 GtkTreePath *treepath;
338 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
339 treepath = gtk_tree_path_new_from_string (path);
340 gtk_tree_model_get_iter (model, &iter, treepath);
341 gtk_tree_model_get (model, &iter,
342 COL_ACCOUNT_POINTER, &account,
344 gtk_tree_path_free (treepath);
346 enabled = mc_account_is_enabled (account);
347 mc_account_set_enabled (account, !enabled);
349 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
350 mc_account_get_display_name(account));
352 g_object_unref (account);
356 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
357 GtkCellEditable *editable,
359 EmpathyAccountsDialog *dialog)
361 if (dialog->connecting_id) {
362 g_source_remove (dialog->connecting_id);
364 DEBUG ("Editing account name started; stopping flashing");
368 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
371 GtkTreeViewColumn *column;
372 GtkCellRenderer *cell;
374 view = GTK_TREE_VIEW (dialog->treeview);
375 gtk_tree_view_set_headers_visible (view, TRUE);
378 cell = gtk_cell_renderer_toggle_new ();
379 gtk_tree_view_insert_column_with_attributes (view, -1,
382 "active", COL_ENABLED,
384 g_signal_connect (cell, "toggled",
385 G_CALLBACK (accounts_dialog_enable_toggled_cb),
389 column = gtk_tree_view_column_new ();
390 gtk_tree_view_column_set_title (column, _("Accounts"));
391 gtk_tree_view_column_set_expand (column, TRUE);
392 gtk_tree_view_append_column (view, column);
395 cell = gtk_cell_renderer_pixbuf_new ();
396 gtk_tree_view_column_pack_start (column, cell, FALSE);
397 gtk_tree_view_column_set_cell_data_func (column, cell,
398 (GtkTreeCellDataFunc)
399 accounts_dialog_model_pixbuf_data_func,
404 cell = gtk_cell_renderer_text_new ();
406 "ellipsize", PANGO_ELLIPSIZE_END,
409 gtk_tree_view_column_pack_start (column, cell, TRUE);
410 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
411 g_signal_connect (cell, "edited",
412 G_CALLBACK (accounts_dialog_name_edited_cb),
414 g_signal_connect (cell, "editing-started",
415 G_CALLBACK (accounts_dialog_name_editing_started_cb),
420 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
424 GtkTreeSelection *selection;
428 view = GTK_TREE_VIEW (dialog->treeview);
429 model = gtk_tree_view_get_model (view);
431 if (gtk_tree_model_get_iter_first (model, &iter)) {
432 selection = gtk_tree_view_get_selection (view);
433 gtk_tree_selection_select_iter (selection, &iter);
435 accounts_dialog_update_account (dialog, NULL);
440 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
441 GtkCellRenderer *cell,
444 EmpathyAccountsDialog *dialog)
447 const gchar *icon_name;
449 TpConnectionStatus status;
451 gtk_tree_model_get (model, iter,
453 COL_ACCOUNT_POINTER, &account,
456 icon_name = empathy_icon_name_from_account (account);
457 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
460 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
461 (status == TP_CONNECTION_STATUS_CONNECTING &&
462 !dialog->connecting_show)) {
463 GdkPixbuf *modded_pixbuf;
465 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
468 gdk_pixbuf_get_width (pixbuf),
469 gdk_pixbuf_get_height (pixbuf));
471 gdk_pixbuf_saturate_and_pixelate (pixbuf,
475 g_object_unref (pixbuf);
476 pixbuf = modded_pixbuf;
485 g_object_unref (account);
487 g_object_unref (pixbuf);
492 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
497 GtkTreeSelection *selection;
501 /* Update the status in the model */
502 view = GTK_TREE_VIEW (dialog->treeview);
503 selection = gtk_tree_view_get_selection (view);
504 model = gtk_tree_view_get_model (view);
506 for (ok = gtk_tree_model_get_iter_first (model, iter);
508 ok = gtk_tree_model_iter_next (model, iter)) {
509 McAccount *this_account;
512 gtk_tree_model_get (model, iter,
513 COL_ACCOUNT_POINTER, &this_account,
516 equal = empathy_account_equal (this_account, account);
517 g_object_unref (this_account);
528 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
532 GtkTreeSelection *selection;
536 view = GTK_TREE_VIEW (dialog->treeview);
537 selection = gtk_tree_view_get_selection (view);
539 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
543 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
549 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
552 GtkTreeSelection *selection;
555 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
556 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
557 gtk_tree_selection_select_iter (selection, &iter);
562 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
566 GtkTreeSelection *selection;
569 view = GTK_TREE_VIEW (dialog->treeview);
570 selection = gtk_tree_view_get_selection (view);
572 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
576 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
580 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
581 EmpathyAccountsDialog *dialog)
586 gboolean is_selection;
588 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
590 account = accounts_dialog_model_get_selected (dialog);
591 accounts_dialog_update_account (dialog, account);
594 g_object_unref (account);
599 accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
604 TpConnectionStatus status;
608 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
609 status = mission_control_get_connection_status (dialog->mc, account, NULL);
610 name = mc_account_get_display_name (account);
611 enabled = mc_account_is_enabled (account);
613 if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
614 DEBUG ("Adding new account");
615 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
618 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
619 COL_ENABLED, enabled,
622 COL_ACCOUNT_POINTER, account,
625 accounts_dialog_status_changed_cb (dialog->mc,
628 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
629 mc_account_get_unique_name (account),
634 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
636 EmpathyAccountsDialog *dialog)
640 account = mc_account_lookup (unique_name);
641 accounts_dialog_add_or_update_account (dialog, account);
642 g_object_unref (account);
646 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
648 EmpathyAccountsDialog *dialog)
652 account = mc_account_lookup (unique_name);
654 accounts_dialog_model_set_selected (dialog, account);
655 accounts_dialog_model_remove_selected (dialog);
657 g_object_unref (account);
661 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
666 gtk_tree_model_row_changed (model, path, iter);
672 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
677 dialog->connecting_show = !dialog->connecting_show;
679 view = GTK_TREE_VIEW (dialog->treeview);
680 model = gtk_tree_view_get_model (view);
682 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
688 accounts_dialog_are_accounts_connecting (MissionControl *mc)
691 gboolean found = FALSE;
693 /* Check if there is still accounts in CONNECTING state */
694 accounts = mc_accounts_list_by_enabled (TRUE);
695 for (l = accounts; l; l = l->next) {
696 McAccount *this_account = l->data;
697 TpConnectionStatus status;
699 status = mission_control_get_connection_status (mc, this_account,
701 if (status == TP_CONNECTION_STATUS_CONNECTING) {
706 mc_accounts_list_free (accounts);
712 accounts_dialog_status_changed_cb (MissionControl *mc,
713 TpConnectionStatus status,
715 TpConnectionStatusReason reason,
716 const gchar *unique_name,
717 EmpathyAccountsDialog *dialog)
722 gboolean found = FALSE;
724 /* Update the status in the model */
725 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
726 account = mc_account_lookup (unique_name);
728 DEBUG ("Status changed for account %s: status=%d presence=%d",
729 unique_name, status, presence);
731 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
734 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
738 path = gtk_tree_model_get_path (model, &iter);
739 gtk_tree_model_row_changed (model, path, &iter);
740 gtk_tree_path_free (path);
742 g_object_unref (account);
744 found = accounts_dialog_are_accounts_connecting (mc);
746 if (!found && dialog->connecting_id) {
747 g_source_remove (dialog->connecting_id);
748 dialog->connecting_id = 0;
750 if (found && !dialog->connecting_id) {
751 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
752 (GSourceFunc) accounts_dialog_flash_connecting_cb,
758 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
760 EmpathyAccountsDialog *dialog)
767 /* Update the status in the model */
768 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
769 account = mc_account_lookup (unique_name);
770 enabled = mc_account_is_enabled (account);
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,
782 g_object_unref (account);
786 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
787 EmpathyAccountsDialog *dialog)
792 McProfileCapabilityFlags cap;
794 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
797 account = mc_account_create (profile);
798 str = mc_account_get_unique_name (account);
799 mc_account_set_display_name (account, str);
801 cap = mc_profile_get_capabilities (profile);
802 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
805 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register));
807 mc_account_set_param_boolean (account, "register", TRUE);
811 accounts_dialog_add_or_update_account (dialog, account);
812 accounts_dialog_model_set_selected (dialog, account);
814 g_object_unref (account);
815 g_object_unref (profile);
819 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
820 EmpathyAccountsDialog *dialog)
824 account = accounts_dialog_model_get_selected (dialog);
825 accounts_dialog_update_account (dialog, account);
829 accounts_dialog_profile_changed_cb (GtkWidget *widget,
830 EmpathyAccountsDialog *dialog)
833 McProfileCapabilityFlags cap;
835 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
836 cap = mc_profile_get_capabilities (profile);
838 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
839 gtk_widget_show (dialog->checkbutton_register);
841 gtk_widget_hide (dialog->checkbutton_register);
843 g_object_unref (profile);
847 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
848 EmpathyAccountsDialog *dialog)
851 GtkTreeSelection *selection;
854 view = GTK_TREE_VIEW (dialog->treeview);
855 model = gtk_tree_view_get_model (view);
856 selection = gtk_tree_view_get_selection (view);
857 gtk_tree_selection_unselect_all (selection);
859 gtk_widget_set_sensitive (dialog->button_add, FALSE);
860 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
861 gtk_widget_hide (dialog->vbox_details);
862 gtk_widget_hide (dialog->frame_no_profile);
863 gtk_widget_show (dialog->frame_new_account);
865 /* If we have no account, no need of a back button */
866 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
867 gtk_widget_show (dialog->button_back);
869 gtk_widget_hide (dialog->button_back);
872 accounts_dialog_profile_changed_cb (dialog->checkbutton_register, dialog);
873 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register),
875 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
876 gtk_widget_grab_focus (dialog->combobox_profile);
880 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
881 EmpathyAccountsDialog *dialog)
883 empathy_url_show ("ghelp:empathy?empathy-create-account");
887 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
888 EmpathyAccountsDialog *dialog)
891 GtkWidget *message_dialog;
894 account = accounts_dialog_model_get_selected (dialog);
896 if (!mc_account_is_complete (account)) {
897 accounts_dialog_model_remove_selected (dialog);
898 accounts_dialog_model_select_first (dialog);
901 message_dialog = gtk_message_dialog_new
902 (GTK_WINDOW (dialog->window),
903 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
904 GTK_MESSAGE_QUESTION,
906 _("You are about to remove your %s account!\n"
907 "Are you sure you want to proceed?"),
908 mc_account_get_display_name (account));
910 gtk_message_dialog_format_secondary_text
911 (GTK_MESSAGE_DIALOG (message_dialog),
912 _("Any associated conversations and chat rooms will NOT be "
913 "removed if you decide to proceed.\n"
915 "Should you decide to add the account back at a later time, "
916 "they will still be available."));
918 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
921 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
925 gtk_widget_show (message_dialog);
926 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
928 if (res == GTK_RESPONSE_YES) {
929 mc_account_delete (account);
930 accounts_dialog_model_select_first (dialog);
932 gtk_widget_destroy (message_dialog);
936 accounts_dialog_response_cb (GtkWidget *widget,
938 EmpathyAccountsDialog *dialog)
940 if (response == GTK_RESPONSE_CLOSE) {
941 gtk_widget_destroy (widget);
946 accounts_dialog_destroy_cb (GtkWidget *widget,
947 EmpathyAccountsDialog *dialog)
951 /* Disconnect signals */
952 g_signal_handlers_disconnect_by_func (dialog->monitor,
953 accounts_dialog_account_added_cb,
955 g_signal_handlers_disconnect_by_func (dialog->monitor,
956 accounts_dialog_account_removed_cb,
958 g_signal_handlers_disconnect_by_func (dialog->monitor,
959 accounts_dialog_account_enabled_cb,
961 empathy_disconnect_account_status_changed (dialog->token);
963 /* Delete incomplete accounts */
964 accounts = mc_accounts_list ();
965 for (l = accounts; l; l = l->next) {
969 if (!mc_account_is_complete (account)) {
970 /* FIXME: Warn the user the account is not complete
971 * and is going to be removed. */
972 mc_account_delete (account);
975 g_object_unref (account);
977 g_list_free (accounts);
979 if (dialog->connecting_id) {
980 g_source_remove (dialog->connecting_id);
983 g_object_unref (dialog->mc);
984 g_object_unref (dialog->monitor);
990 empathy_accounts_dialog_show (GtkWindow *parent,
991 McAccount *selected_account)
993 static EmpathyAccountsDialog *dialog = NULL;
999 gtk_window_present (GTK_WINDOW (dialog->window));
1000 return dialog->window;
1003 dialog = g_new0 (EmpathyAccountsDialog, 1);
1005 filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
1007 glade = empathy_glade_get_file (filename,
1010 "accounts_dialog", &dialog->window,
1011 "vbox_details", &dialog->vbox_details,
1012 "frame_no_profile", &dialog->frame_no_profile,
1013 "alignment_settings", &dialog->alignment_settings,
1014 "treeview", &dialog->treeview,
1015 "frame_new_account", &dialog->frame_new_account,
1016 "hbox_type", &dialog->hbox_type,
1017 "button_create", &dialog->button_create,
1018 "button_back", &dialog->button_back,
1019 "checkbutton_register", &dialog->checkbutton_register,
1020 "image_type", &dialog->image_type,
1021 "label_name", &dialog->label_name,
1022 "button_add", &dialog->button_add,
1023 "button_remove", &dialog->button_remove,
1027 empathy_glade_connect (glade,
1029 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1030 "accounts_dialog", "response", accounts_dialog_response_cb,
1031 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1032 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1033 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1034 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1035 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1038 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1040 g_object_unref (glade);
1042 /* Create profile chooser */
1043 dialog->combobox_profile = empathy_profile_chooser_new ();
1044 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1045 dialog->combobox_profile,
1047 gtk_widget_show (dialog->combobox_profile);
1048 g_signal_connect (dialog->combobox_profile, "changed",
1049 G_CALLBACK (accounts_dialog_profile_changed_cb),
1052 /* Set up signalling */
1053 dialog->mc = empathy_mission_control_new ();
1054 dialog->monitor = mc_account_monitor_new ();
1056 g_signal_connect (dialog->monitor, "account-created",
1057 G_CALLBACK (accounts_dialog_account_added_cb),
1059 g_signal_connect (dialog->monitor, "account-deleted",
1060 G_CALLBACK (accounts_dialog_account_removed_cb),
1062 g_signal_connect (dialog->monitor, "account-enabled",
1063 G_CALLBACK (accounts_dialog_account_enabled_cb),
1065 g_signal_connect (dialog->monitor, "account-disabled",
1066 G_CALLBACK (accounts_dialog_account_enabled_cb),
1068 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1069 G_CALLBACK (accounts_dialog_status_changed_cb),
1072 accounts_dialog_model_setup (dialog);
1074 /* Add existing accounts */
1075 accounts = mc_accounts_list ();
1076 for (l = accounts; l; l = l->next) {
1077 accounts_dialog_add_or_update_account (dialog, l->data);
1078 g_object_unref (l->data);
1080 g_list_free (accounts);
1082 if (selected_account) {
1083 accounts_dialog_model_set_selected (dialog, selected_account);
1085 accounts_dialog_model_select_first (dialog);
1089 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1090 GTK_WINDOW (parent));
1093 gtk_widget_show (dialog->window);
1095 return dialog->window;