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)
639 const gchar *current_name;
640 gchar *account_param = NULL;
642 account = mc_account_lookup (unique_name);
643 accounts_dialog_add_or_update_account (dialog, account);
645 /* Change the display name to "%s (%s)" % (protocol, account).
646 * - The protocol is the display name of the profile.
647 * - The account should be the normalized name of the McAccount but
648 * it's not set until first connection, so we get the "account"
649 * parameter for CM that have it. */
650 current_name = mc_account_get_display_name (account);
651 mc_account_get_param_string (account, "account", &account_param);
652 if (!G_STR_EMPTY (account_param)) {
654 const gchar *profile_name;
657 profile = mc_account_get_profile (account);
658 profile_name = mc_profile_get_display_name (profile);
659 new_name = g_strdup_printf ("%s (%s)", profile_name,
662 DEBUG ("Setting new display name for account %s: '%s'",
663 unique_name, new_name);
665 mc_account_set_display_name (account, new_name);
667 g_object_unref (profile);
669 /* FIXME: This CM has no account parameter, what can be done? */
671 g_free (account_param);
672 g_object_unref (account);
676 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
678 EmpathyAccountsDialog *dialog)
682 account = mc_account_lookup (unique_name);
684 accounts_dialog_model_set_selected (dialog, account);
685 accounts_dialog_model_remove_selected (dialog);
687 g_object_unref (account);
691 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
696 gtk_tree_model_row_changed (model, path, iter);
702 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
707 dialog->connecting_show = !dialog->connecting_show;
709 view = GTK_TREE_VIEW (dialog->treeview);
710 model = gtk_tree_view_get_model (view);
712 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
718 accounts_dialog_are_accounts_connecting (MissionControl *mc)
721 gboolean found = FALSE;
723 /* Check if there is still accounts in CONNECTING state */
724 accounts = mc_accounts_list_by_enabled (TRUE);
725 for (l = accounts; l; l = l->next) {
726 McAccount *this_account = l->data;
727 TpConnectionStatus status;
729 status = mission_control_get_connection_status (mc, this_account,
731 if (status == TP_CONNECTION_STATUS_CONNECTING) {
736 mc_accounts_list_free (accounts);
742 accounts_dialog_status_changed_cb (MissionControl *mc,
743 TpConnectionStatus status,
745 TpConnectionStatusReason reason,
746 const gchar *unique_name,
747 EmpathyAccountsDialog *dialog)
752 gboolean found = FALSE;
754 /* Update the status in the model */
755 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
756 account = mc_account_lookup (unique_name);
761 DEBUG ("Status changed for account %s: status=%d presence=%d",
762 unique_name, status, presence);
764 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
767 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
771 path = gtk_tree_model_get_path (model, &iter);
772 gtk_tree_model_row_changed (model, path, &iter);
773 gtk_tree_path_free (path);
775 g_object_unref (account);
777 found = accounts_dialog_are_accounts_connecting (mc);
779 if (!found && dialog->connecting_id) {
780 g_source_remove (dialog->connecting_id);
781 dialog->connecting_id = 0;
783 if (found && !dialog->connecting_id) {
784 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
785 (GSourceFunc) accounts_dialog_flash_connecting_cb,
791 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
793 EmpathyAccountsDialog *dialog)
800 /* Update the status in the model */
801 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
802 account = mc_account_lookup (unique_name);
803 enabled = mc_account_is_enabled (account);
805 DEBUG ("Account %s is now %s",
806 mc_account_get_display_name (account),
807 enabled ? "enabled" : "disabled");
809 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
810 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
811 COL_ENABLED, enabled,
815 g_object_unref (account);
819 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
820 EmpathyAccountsDialog *dialog)
825 McProfileCapabilityFlags cap;
827 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
830 account = mc_account_create (profile);
831 /* To translator: %s is the protocol name */
832 str = g_strdup_printf (_("New %s account"),
833 mc_profile_get_display_name (profile));
834 mc_account_set_display_name (account, str);
837 cap = mc_profile_get_capabilities (profile);
838 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
841 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register));
843 mc_account_set_param_boolean (account, "register", TRUE);
847 accounts_dialog_add_or_update_account (dialog, account);
848 accounts_dialog_model_set_selected (dialog, account);
850 g_object_unref (account);
851 g_object_unref (profile);
855 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
856 EmpathyAccountsDialog *dialog)
860 account = accounts_dialog_model_get_selected (dialog);
861 accounts_dialog_update_account (dialog, account);
865 accounts_dialog_profile_changed_cb (GtkWidget *widget,
866 EmpathyAccountsDialog *dialog)
869 McProfileCapabilityFlags cap;
871 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
872 cap = mc_profile_get_capabilities (profile);
874 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
875 gtk_widget_show (dialog->checkbutton_register);
877 gtk_widget_hide (dialog->checkbutton_register);
879 g_object_unref (profile);
883 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
884 EmpathyAccountsDialog *dialog)
887 GtkTreeSelection *selection;
890 view = GTK_TREE_VIEW (dialog->treeview);
891 model = gtk_tree_view_get_model (view);
892 selection = gtk_tree_view_get_selection (view);
893 gtk_tree_selection_unselect_all (selection);
895 gtk_widget_set_sensitive (dialog->button_add, FALSE);
896 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
897 gtk_widget_hide (dialog->vbox_details);
898 gtk_widget_hide (dialog->frame_no_profile);
899 gtk_widget_show (dialog->frame_new_account);
901 /* If we have no account, no need of a back button */
902 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
903 gtk_widget_show (dialog->button_back);
905 gtk_widget_hide (dialog->button_back);
908 accounts_dialog_profile_changed_cb (dialog->checkbutton_register, dialog);
909 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register),
911 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
912 gtk_widget_grab_focus (dialog->combobox_profile);
916 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
917 EmpathyAccountsDialog *dialog)
919 empathy_url_show ("ghelp:empathy?empathy-create-account");
923 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
924 EmpathyAccountsDialog *dialog)
927 GtkWidget *message_dialog;
930 account = accounts_dialog_model_get_selected (dialog);
932 if (!mc_account_is_complete (account)) {
933 accounts_dialog_model_remove_selected (dialog);
934 accounts_dialog_model_select_first (dialog);
937 message_dialog = gtk_message_dialog_new
938 (GTK_WINDOW (dialog->window),
939 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
940 GTK_MESSAGE_QUESTION,
942 _("You are about to remove your %s account!\n"
943 "Are you sure you want to proceed?"),
944 mc_account_get_display_name (account));
946 gtk_message_dialog_format_secondary_text
947 (GTK_MESSAGE_DIALOG (message_dialog),
948 _("Any associated conversations and chat rooms will NOT be "
949 "removed if you decide to proceed.\n"
951 "Should you decide to add the account back at a later time, "
952 "they will still be available."));
954 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
957 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
961 gtk_widget_show (message_dialog);
962 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
964 if (res == GTK_RESPONSE_YES) {
965 mc_account_delete (account);
966 accounts_dialog_model_select_first (dialog);
968 gtk_widget_destroy (message_dialog);
972 accounts_dialog_response_cb (GtkWidget *widget,
974 EmpathyAccountsDialog *dialog)
976 if (response == GTK_RESPONSE_CLOSE) {
977 gtk_widget_destroy (widget);
982 accounts_dialog_destroy_cb (GtkWidget *widget,
983 EmpathyAccountsDialog *dialog)
987 /* Disconnect signals */
988 g_signal_handlers_disconnect_by_func (dialog->monitor,
989 accounts_dialog_account_added_cb,
991 g_signal_handlers_disconnect_by_func (dialog->monitor,
992 accounts_dialog_account_removed_cb,
994 g_signal_handlers_disconnect_by_func (dialog->monitor,
995 accounts_dialog_account_enabled_cb,
997 empathy_disconnect_account_status_changed (dialog->token);
999 /* Delete incomplete accounts */
1000 accounts = mc_accounts_list ();
1001 for (l = accounts; l; l = l->next) {
1005 if (!mc_account_is_complete (account)) {
1006 /* FIXME: Warn the user the account is not complete
1007 * and is going to be removed. */
1008 mc_account_delete (account);
1011 g_object_unref (account);
1013 g_list_free (accounts);
1015 if (dialog->connecting_id) {
1016 g_source_remove (dialog->connecting_id);
1019 g_object_unref (dialog->mc);
1020 g_object_unref (dialog->monitor);
1026 empathy_accounts_dialog_show (GtkWindow *parent,
1027 McAccount *selected_account)
1029 static EmpathyAccountsDialog *dialog = NULL;
1032 GList *accounts, *l;
1035 gtk_window_present (GTK_WINDOW (dialog->window));
1036 return dialog->window;
1039 dialog = g_new0 (EmpathyAccountsDialog, 1);
1041 filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
1043 glade = empathy_glade_get_file (filename,
1046 "accounts_dialog", &dialog->window,
1047 "vbox_details", &dialog->vbox_details,
1048 "frame_no_profile", &dialog->frame_no_profile,
1049 "alignment_settings", &dialog->alignment_settings,
1050 "treeview", &dialog->treeview,
1051 "frame_new_account", &dialog->frame_new_account,
1052 "hbox_type", &dialog->hbox_type,
1053 "button_create", &dialog->button_create,
1054 "button_back", &dialog->button_back,
1055 "checkbutton_register", &dialog->checkbutton_register,
1056 "image_type", &dialog->image_type,
1057 "label_name", &dialog->label_name,
1058 "button_add", &dialog->button_add,
1059 "button_remove", &dialog->button_remove,
1063 empathy_glade_connect (glade,
1065 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1066 "accounts_dialog", "response", accounts_dialog_response_cb,
1067 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1068 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1069 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1070 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1071 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1074 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1076 g_object_unref (glade);
1078 /* Create profile chooser */
1079 dialog->combobox_profile = empathy_profile_chooser_new ();
1080 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1081 dialog->combobox_profile,
1083 gtk_widget_show (dialog->combobox_profile);
1084 g_signal_connect (dialog->combobox_profile, "changed",
1085 G_CALLBACK (accounts_dialog_profile_changed_cb),
1088 /* Set up signalling */
1089 dialog->mc = empathy_mission_control_new ();
1090 dialog->monitor = mc_account_monitor_new ();
1092 g_signal_connect (dialog->monitor, "account-created",
1093 G_CALLBACK (accounts_dialog_account_added_cb),
1095 g_signal_connect (dialog->monitor, "account-deleted",
1096 G_CALLBACK (accounts_dialog_account_removed_cb),
1098 g_signal_connect (dialog->monitor, "account-enabled",
1099 G_CALLBACK (accounts_dialog_account_enabled_cb),
1101 g_signal_connect (dialog->monitor, "account-disabled",
1102 G_CALLBACK (accounts_dialog_account_enabled_cb),
1104 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1105 G_CALLBACK (accounts_dialog_status_changed_cb),
1108 accounts_dialog_model_setup (dialog);
1110 /* Add existing accounts */
1111 accounts = mc_accounts_list ();
1112 for (l = accounts; l; l = l->next) {
1113 accounts_dialog_add_or_update_account (dialog, l->data);
1114 g_object_unref (l->data);
1116 g_list_free (accounts);
1118 if (selected_account) {
1119 accounts_dialog_model_set_selected (dialog, selected_account);
1121 accounts_dialog_model_select_first (dialog);
1125 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1126 GTK_WINDOW (parent));
1129 gtk_widget_show (dialog->window);
1131 return dialog->window;