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_account;
63 GtkWidget *label_no_account;
64 GtkWidget *label_no_account_blurb;
68 GtkWidget *button_add;
69 GtkWidget *button_remove;
71 GtkWidget *frame_new_account;
72 GtkWidget *combobox_profile;
74 GtkWidget *button_create;
75 GtkWidget *button_back;
76 GtkWidget *checkbutton_register;
78 GtkWidget *image_type;
79 GtkWidget *label_name;
80 GtkWidget *label_type;
81 GtkWidget *settings_widget;
83 gboolean connecting_show;
85 gboolean account_changed;
88 McAccountMonitor *monitor;
90 } EmpathyAccountsDialog;
100 static void accounts_dialog_setup (EmpathyAccountsDialog *dialog);
101 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
103 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
104 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
105 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
106 GtkCellEditable *editable,
108 EmpathyAccountsDialog *dialog);
109 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
110 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
111 GtkCellRenderer *cell,
114 EmpathyAccountsDialog *dialog);
115 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
116 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
118 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
119 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
120 EmpathyAccountsDialog *dialog);
121 static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
123 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
125 EmpathyAccountsDialog *dialog);
126 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
128 EmpathyAccountsDialog *dialog);
129 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
133 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
134 static gboolean accounts_dialog_are_accounts_connecting (MissionControl *mc);
135 static void accounts_dialog_status_changed_cb (MissionControl *mc,
136 TpConnectionStatus status,
138 TpConnectionStatusReason reason,
139 const gchar *unique_name,
140 EmpathyAccountsDialog *dialog);
141 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
142 EmpathyAccountsDialog *dialog);
143 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
144 EmpathyAccountsDialog *dialog);
145 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
146 EmpathyAccountsDialog *dialog);
147 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
148 EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
152 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
153 EmpathyAccountsDialog *dialog);
154 static void accounts_dialog_response_cb (GtkWidget *widget,
156 EmpathyAccountsDialog *dialog);
157 static void accounts_dialog_destroy_cb (GtkWidget *widget,
158 EmpathyAccountsDialog *dialog);
161 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
168 view = GTK_TREE_VIEW (dialog->treeview);
169 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
171 accounts = mc_accounts_list ();
173 for (l = accounts; l; l = l->next) {
176 TpConnectionStatus status;
181 name = mc_account_get_display_name (account);
183 g_object_unref (account);
187 status = mission_control_get_connection_status (dialog->mc, account, NULL);
188 enabled = mc_account_is_enabled (account);
190 gtk_list_store_insert_with_values (store, &iter,
192 COL_ENABLED, enabled,
195 COL_ACCOUNT_POINTER, account,
198 accounts_dialog_status_changed_cb (dialog->mc,
201 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
202 mc_account_get_unique_name (account),
205 g_object_unref (account);
208 g_list_free (accounts);
212 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
215 if (dialog->settings_widget) {
216 gtk_widget_destroy (dialog->settings_widget);
217 dialog->settings_widget = NULL;
226 gtk_widget_show (dialog->frame_no_account);
227 gtk_widget_hide (dialog->vbox_details);
229 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
231 view = GTK_TREE_VIEW (dialog->treeview);
232 model = gtk_tree_view_get_model (view);
234 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
235 string = g_string_new (_("To add a new account, you can click on the "
236 "'Add' button and a new entry will be created "
237 "for you to start configuring."));
239 string = g_string_new (_("To add a new account, you first have to "
240 "install a backend for each protocol "
241 "you want to use."));
244 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
245 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
246 _("<b>No Account Selected</b>"));
247 g_string_append (string, _("\n\n"
248 "If you do not want to add an account, simply "
249 "click on the account you want to configure in "
250 "the list on the left."));
252 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
253 _("<b>No Accounts Configured</b>"));
256 str = g_string_free (string, FALSE);
257 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
262 const gchar *config_ui;
264 gtk_widget_hide (dialog->frame_no_account);
265 gtk_widget_show (dialog->vbox_details);
267 profile = mc_account_get_profile (account);
268 config_ui = mc_profile_get_configuration_ui (profile);
269 g_object_unref (profile);
271 if (!tp_strdiff (config_ui, "jabber")) {
272 dialog->settings_widget =
273 empathy_account_widget_jabber_new (account);
275 else if (!tp_strdiff (config_ui, "msn")) {
276 dialog ->settings_widget =
277 empathy_account_widget_msn_new (account);
279 else if (!tp_strdiff (config_ui, "local-xmpp")) {
280 dialog->settings_widget =
281 empathy_account_widget_salut_new (account);
283 else if (!tp_strdiff (config_ui, "irc")) {
284 dialog->settings_widget =
285 empathy_account_widget_irc_new (account);
287 else if (!tp_strdiff(config_ui, "icq")) {
288 dialog->settings_widget =
289 empathy_account_widget_icq_new (account);
291 else if (!tp_strdiff(config_ui, "aim")) {
292 dialog->settings_widget =
293 empathy_account_widget_aim_new (account);
295 else if (!tp_strdiff (config_ui, "yahoo")) {
296 dialog->settings_widget =
297 empathy_account_widget_yahoo_new (account);
299 else if (!tp_strdiff (config_ui, "sofiasip")) {
300 dialog->settings_widget =
301 empathy_account_widget_sip_new (account);
303 else if (!tp_strdiff (config_ui, "groupwise")) {
304 dialog->settings_widget =
305 empathy_account_widget_groupwise_new (account);
308 dialog->settings_widget =
309 empathy_account_widget_generic_new (account);
313 if (dialog->settings_widget) {
314 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
315 dialog->settings_widget);
322 profile = mc_account_get_profile (account);
323 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
324 mc_profile_get_icon_name (profile),
325 GTK_ICON_SIZE_DIALOG);
326 gtk_widget_set_tooltip_text (dialog->image_type,
327 mc_profile_get_display_name (profile));
329 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
330 mc_account_get_display_name (account));
331 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
337 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
340 GtkTreeSelection *selection;
342 store = gtk_list_store_new (COL_COUNT,
343 G_TYPE_BOOLEAN, /* enabled */
344 G_TYPE_STRING, /* name */
345 G_TYPE_UINT, /* status */
346 MC_TYPE_ACCOUNT); /* account */
348 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
349 GTK_TREE_MODEL (store));
351 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
352 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
354 g_signal_connect (selection, "changed",
355 G_CALLBACK (accounts_dialog_model_selection_changed),
358 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
359 COL_NAME, GTK_SORT_ASCENDING);
361 accounts_dialog_model_add_columns (dialog);
363 g_object_unref (store);
367 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
370 EmpathyAccountsDialog *dialog)
374 GtkTreePath *treepath;
377 if (accounts_dialog_are_accounts_connecting (dialog->mc)) {
378 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
379 (GSourceFunc) accounts_dialog_flash_connecting_cb,
383 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
384 treepath = gtk_tree_path_new_from_string (path);
385 gtk_tree_model_get_iter (model, &iter, treepath);
386 gtk_tree_model_get (model, &iter,
387 COL_ACCOUNT_POINTER, &account,
389 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
392 gtk_tree_path_free (treepath);
394 mc_account_set_display_name (account, new_text);
395 g_object_unref (account);
399 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
401 EmpathyAccountsDialog *dialog)
405 GtkTreePath *treepath;
409 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
410 treepath = gtk_tree_path_new_from_string (path);
411 gtk_tree_model_get_iter (model, &iter, treepath);
412 gtk_tree_model_get (model, &iter,
413 COL_ACCOUNT_POINTER, &account,
415 gtk_tree_path_free (treepath);
417 enabled = mc_account_is_enabled (account);
418 mc_account_set_enabled (account, !enabled);
420 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
421 mc_account_get_display_name(account));
423 g_object_unref (account);
427 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
428 GtkCellEditable *editable,
430 EmpathyAccountsDialog *dialog)
432 if (dialog->connecting_id) {
433 g_source_remove (dialog->connecting_id);
435 DEBUG ("Editing account name started; stopping flashing");
439 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
442 GtkTreeViewColumn *column;
443 GtkCellRenderer *cell;
445 view = GTK_TREE_VIEW (dialog->treeview);
446 gtk_tree_view_set_headers_visible (view, TRUE);
449 cell = gtk_cell_renderer_toggle_new ();
450 gtk_tree_view_insert_column_with_attributes (view, -1,
453 "active", COL_ENABLED,
455 g_signal_connect (cell, "toggled",
456 G_CALLBACK (accounts_dialog_enable_toggled_cb),
460 column = gtk_tree_view_column_new ();
461 gtk_tree_view_column_set_title (column, _("Accounts"));
462 gtk_tree_view_column_set_expand (column, TRUE);
463 gtk_tree_view_append_column (view, column);
466 cell = gtk_cell_renderer_pixbuf_new ();
467 gtk_tree_view_column_pack_start (column, cell, FALSE);
468 gtk_tree_view_column_set_cell_data_func (column, cell,
469 (GtkTreeCellDataFunc)
470 accounts_dialog_model_pixbuf_data_func,
475 cell = gtk_cell_renderer_text_new ();
477 "ellipsize", PANGO_ELLIPSIZE_END,
480 gtk_tree_view_column_pack_start (column, cell, TRUE);
481 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
482 g_signal_connect (cell, "edited",
483 G_CALLBACK (accounts_dialog_name_edited_cb),
485 g_signal_connect (cell, "editing-started",
486 G_CALLBACK (accounts_dialog_name_editing_started_cb),
491 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
495 GtkTreeSelection *selection;
499 view = GTK_TREE_VIEW (dialog->treeview);
500 model = gtk_tree_view_get_model (view);
502 if (gtk_tree_model_get_iter_first (model, &iter)) {
503 selection = gtk_tree_view_get_selection (view);
504 gtk_tree_selection_select_iter (selection, &iter);
506 accounts_dialog_update_account (dialog, NULL);
511 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
512 GtkCellRenderer *cell,
515 EmpathyAccountsDialog *dialog)
518 const gchar *icon_name;
520 TpConnectionStatus status;
522 gtk_tree_model_get (model, iter,
524 COL_ACCOUNT_POINTER, &account,
527 icon_name = empathy_icon_name_from_account (account);
528 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
531 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
532 (status == TP_CONNECTION_STATUS_CONNECTING &&
533 !dialog->connecting_show)) {
534 GdkPixbuf *modded_pixbuf;
536 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
539 gdk_pixbuf_get_width (pixbuf),
540 gdk_pixbuf_get_height (pixbuf));
542 gdk_pixbuf_saturate_and_pixelate (pixbuf,
546 g_object_unref (pixbuf);
547 pixbuf = modded_pixbuf;
556 g_object_unref (account);
558 g_object_unref (pixbuf);
563 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
568 GtkTreeSelection *selection;
572 /* Update the status in the model */
573 view = GTK_TREE_VIEW (dialog->treeview);
574 selection = gtk_tree_view_get_selection (view);
575 model = gtk_tree_view_get_model (view);
577 for (ok = gtk_tree_model_get_iter_first (model, iter);
579 ok = gtk_tree_model_iter_next (model, iter)) {
580 McAccount *this_account;
583 gtk_tree_model_get (model, iter,
584 COL_ACCOUNT_POINTER, &this_account,
587 equal = empathy_account_equal (this_account, account);
588 g_object_unref (this_account);
599 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
603 GtkTreeSelection *selection;
607 view = GTK_TREE_VIEW (dialog->treeview);
608 selection = gtk_tree_view_get_selection (view);
610 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
614 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
620 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
623 GtkTreeSelection *selection;
626 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
627 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
628 gtk_tree_selection_select_iter (selection, &iter);
633 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
637 GtkTreeSelection *selection;
640 view = GTK_TREE_VIEW (dialog->treeview);
641 selection = gtk_tree_view_get_selection (view);
643 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
647 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
651 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
652 EmpathyAccountsDialog *dialog)
657 gboolean is_selection;
659 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
661 gtk_widget_set_sensitive (dialog->button_add, TRUE);
662 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
664 account = accounts_dialog_model_get_selected (dialog);
665 accounts_dialog_update_account (dialog, account);
668 g_object_unref (account);
671 /* insure new account frame is hidden when a row is selected*/
672 gtk_widget_hide (dialog->frame_new_account);
676 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
681 TpConnectionStatus status;
685 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
689 status = mission_control_get_connection_status (dialog->mc, account, NULL);
690 name = mc_account_get_display_name (account);
691 enabled = mc_account_is_enabled (account);
693 g_return_if_fail (name != NULL);
695 DEBUG ("Adding new account: %s", name);
697 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
698 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter,
700 COL_ENABLED, enabled,
703 COL_ACCOUNT_POINTER, account,
708 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
710 EmpathyAccountsDialog *dialog)
714 account = mc_account_lookup (unique_name);
715 accounts_dialog_add_account (dialog, account);
716 g_object_unref (account);
720 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
722 EmpathyAccountsDialog *dialog)
726 account = mc_account_lookup (unique_name);
728 accounts_dialog_model_set_selected (dialog, account);
729 accounts_dialog_model_remove_selected (dialog);
731 g_object_unref (account);
735 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
740 gtk_tree_model_row_changed (model, path, iter);
746 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
751 dialog->connecting_show = !dialog->connecting_show;
753 view = GTK_TREE_VIEW (dialog->treeview);
754 model = gtk_tree_view_get_model (view);
756 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
762 accounts_dialog_are_accounts_connecting (MissionControl *mc)
765 gboolean found = FALSE;
767 /* Check if there is still accounts in CONNECTING state */
768 accounts = mc_accounts_list_by_enabled (TRUE);
769 for (l = accounts; l; l = l->next) {
770 McAccount *this_account = l->data;
771 TpConnectionStatus status;
773 status = mission_control_get_connection_status (mc, this_account,
775 if (status == TP_CONNECTION_STATUS_CONNECTING) {
780 mc_accounts_list_free (accounts);
786 accounts_dialog_status_changed_cb (MissionControl *mc,
787 TpConnectionStatus status,
789 TpConnectionStatusReason reason,
790 const gchar *unique_name,
791 EmpathyAccountsDialog *dialog)
796 gboolean found = FALSE;
798 /* Update the status in the model */
799 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
800 account = mc_account_lookup (unique_name);
802 DEBUG ("Status changed for account %s: status=%d presence=%d",
803 unique_name, status, presence);
805 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
808 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
812 path = gtk_tree_model_get_path (model, &iter);
813 gtk_tree_model_row_changed (model, path, &iter);
814 gtk_tree_path_free (path);
816 g_object_unref (account);
818 found = accounts_dialog_are_accounts_connecting (mc);
820 if (!found && dialog->connecting_id) {
821 g_source_remove (dialog->connecting_id);
822 dialog->connecting_id = 0;
824 if (found && !dialog->connecting_id) {
825 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
826 (GSourceFunc) accounts_dialog_flash_connecting_cb,
832 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
834 EmpathyAccountsDialog *dialog)
841 /* Update the status in the model */
842 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
843 account = mc_account_lookup (unique_name);
844 enabled = mc_account_is_enabled (account);
846 DEBUG ("Account %s is now %s",
847 mc_account_get_display_name (account),
848 enabled ? "enabled" : "disabled");
850 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
851 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
852 COL_ENABLED, enabled,
856 g_object_unref (account);
860 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
861 EmpathyAccountsDialog *dialog)
866 McProfileCapabilityFlags cap;
869 gtk_widget_show (dialog->vbox_details);
870 gtk_widget_hide (dialog->frame_no_account);
871 gtk_widget_hide (dialog->frame_new_account);
873 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
876 account = mc_account_create (profile);
877 str = mc_account_get_unique_name (account);
878 mc_account_set_display_name (account, str);
880 cap = mc_profile_get_capabilities (profile);
881 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
884 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register));
886 mc_account_set_param_boolean (account, "register", TRUE);
890 accounts_dialog_add_account (dialog, account);
891 accounts_dialog_model_set_selected (dialog, account);
893 g_object_unref (account);
894 g_object_unref (profile);
898 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
899 EmpathyAccountsDialog *dialog)
903 gtk_widget_hide (dialog->vbox_details);
904 gtk_widget_hide (dialog->frame_no_account);
905 gtk_widget_hide (dialog->frame_new_account);
907 gtk_widget_set_sensitive (dialog->button_add, TRUE);
909 account = accounts_dialog_model_get_selected (dialog);
910 accounts_dialog_update_account (dialog, account);
914 accounts_dialog_profile_changed_cb (GtkWidget *widget,
915 EmpathyAccountsDialog *dialog)
918 McProfileCapabilityFlags cap;
920 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
921 cap = mc_profile_get_capabilities (profile);
923 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
924 gtk_widget_show (dialog->checkbutton_register);
926 gtk_widget_hide (dialog->checkbutton_register);
928 g_object_unref (profile);
932 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
933 EmpathyAccountsDialog *dialog)
936 GtkTreeSelection *selection;
938 view = GTK_TREE_VIEW (dialog->treeview);
939 selection = gtk_tree_view_get_selection (view);
940 gtk_tree_selection_unselect_all (selection);
942 gtk_widget_set_sensitive (dialog->button_add, FALSE);
943 gtk_widget_hide (dialog->vbox_details);
944 gtk_widget_hide (dialog->frame_no_account);
945 gtk_widget_show (dialog->frame_new_account);
947 accounts_dialog_profile_changed_cb (dialog->checkbutton_register, dialog);
948 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register),
950 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
951 gtk_widget_grab_focus (dialog->combobox_profile);
955 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
956 EmpathyAccountsDialog *dialog)
958 empathy_url_show ("ghelp:empathy?empathy-create-account");
962 accounts_dialog_remove_response_cb (GtkWidget *dialog,
966 if (response == GTK_RESPONSE_YES) {
967 mc_account_delete (account);
970 gtk_widget_destroy (dialog);
974 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
975 EmpathyAccountsDialog *dialog)
978 GtkWidget *message_dialog;
980 account = accounts_dialog_model_get_selected (dialog);
982 if (!mc_account_is_complete (account)) {
983 accounts_dialog_model_remove_selected (dialog);
986 message_dialog = gtk_message_dialog_new
987 (GTK_WINDOW (dialog->window),
988 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
989 GTK_MESSAGE_QUESTION,
991 _("You are about to remove your %s account!\n"
992 "Are you sure you want to proceed?"),
993 mc_account_get_display_name (account));
995 gtk_message_dialog_format_secondary_text
996 (GTK_MESSAGE_DIALOG (message_dialog),
997 _("Any associated conversations and chat rooms will NOT be "
998 "removed if you decide to proceed.\n"
1000 "Should you decide to add the account back at a later time, "
1001 "they will still be available."));
1003 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1006 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
1010 g_signal_connect (message_dialog, "response",
1011 G_CALLBACK (accounts_dialog_remove_response_cb),
1014 gtk_widget_show (message_dialog);
1018 accounts_dialog_response_cb (GtkWidget *widget,
1020 EmpathyAccountsDialog *dialog)
1022 if (response == GTK_RESPONSE_CLOSE) {
1023 gtk_widget_destroy (widget);
1028 accounts_dialog_destroy_cb (GtkWidget *widget,
1029 EmpathyAccountsDialog *dialog)
1031 GList *accounts, *l;
1033 /* Disconnect signals */
1034 g_signal_handlers_disconnect_by_func (dialog->monitor,
1035 accounts_dialog_account_added_cb,
1037 g_signal_handlers_disconnect_by_func (dialog->monitor,
1038 accounts_dialog_account_removed_cb,
1040 g_signal_handlers_disconnect_by_func (dialog->monitor,
1041 accounts_dialog_account_enabled_cb,
1043 empathy_disconnect_account_status_changed (dialog->token);
1045 /* Delete incomplete accounts */
1046 accounts = mc_accounts_list ();
1047 for (l = accounts; l; l = l->next) {
1051 if (!mc_account_is_complete (account)) {
1052 /* FIXME: Warn the user the account is not complete
1053 * and is going to be removed. */
1054 mc_account_delete (account);
1057 g_object_unref (account);
1059 g_list_free (accounts);
1061 if (dialog->connecting_id) {
1062 g_source_remove (dialog->connecting_id);
1065 g_object_unref (dialog->mc);
1066 g_object_unref (dialog->monitor);
1072 empathy_accounts_dialog_show (GtkWindow *parent,
1073 McAccount *selected_account)
1075 static EmpathyAccountsDialog *dialog = NULL;
1080 gtk_window_present (GTK_WINDOW (dialog->window));
1081 return dialog->window;
1084 dialog = g_new0 (EmpathyAccountsDialog, 1);
1086 filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
1088 glade = empathy_glade_get_file (filename,
1091 "accounts_dialog", &dialog->window,
1092 "vbox_details", &dialog->vbox_details,
1093 "frame_no_account", &dialog->frame_no_account,
1094 "label_no_account", &dialog->label_no_account,
1095 "label_no_account_blurb", &dialog->label_no_account_blurb,
1096 "alignment_settings", &dialog->alignment_settings,
1097 "treeview", &dialog->treeview,
1098 "frame_new_account", &dialog->frame_new_account,
1099 "hbox_type", &dialog->hbox_type,
1100 "button_create", &dialog->button_create,
1101 "button_back", &dialog->button_back,
1102 "checkbutton_register", &dialog->checkbutton_register,
1103 "image_type", &dialog->image_type,
1104 "label_name", &dialog->label_name,
1105 "button_add", &dialog->button_add,
1106 "button_remove", &dialog->button_remove,
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_help", "clicked", accounts_dialog_button_help_clicked_cb,
1121 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1123 g_object_unref (glade);
1125 /* Create profile chooser */
1126 dialog->combobox_profile = empathy_profile_chooser_new ();
1127 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1128 dialog->combobox_profile,
1130 gtk_widget_show (dialog->combobox_profile);
1131 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) <= 0) {
1132 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1134 g_signal_connect (dialog->combobox_profile, "changed",
1135 G_CALLBACK (accounts_dialog_profile_changed_cb),
1138 /* Set up signalling */
1139 dialog->mc = empathy_mission_control_new ();
1140 dialog->monitor = mc_account_monitor_new ();
1142 g_signal_connect (dialog->monitor, "account-created",
1143 G_CALLBACK (accounts_dialog_account_added_cb),
1145 g_signal_connect (dialog->monitor, "account-deleted",
1146 G_CALLBACK (accounts_dialog_account_removed_cb),
1148 g_signal_connect (dialog->monitor, "account-enabled",
1149 G_CALLBACK (accounts_dialog_account_enabled_cb),
1151 g_signal_connect (dialog->monitor, "account-disabled",
1152 G_CALLBACK (accounts_dialog_account_enabled_cb),
1154 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1155 G_CALLBACK (accounts_dialog_status_changed_cb),
1158 accounts_dialog_model_setup (dialog);
1159 accounts_dialog_setup (dialog);
1161 if (selected_account) {
1162 accounts_dialog_model_set_selected (dialog, selected_account);
1164 accounts_dialog_model_select_first (dialog);
1168 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1169 GTK_WINDOW (parent));
1172 gtk_widget_show (dialog->window);
1174 return dialog->window;