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;
83 gboolean account_changed;
86 McAccountMonitor *monitor;
88 } EmpathyAccountsDialog;
98 static void accounts_dialog_setup (EmpathyAccountsDialog *dialog);
99 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
101 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
102 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
103 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
104 GtkCellEditable *editable,
106 EmpathyAccountsDialog *dialog);
107 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
108 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
109 GtkCellRenderer *cell,
112 EmpathyAccountsDialog *dialog);
113 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
114 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
116 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
117 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
118 EmpathyAccountsDialog *dialog);
119 static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
121 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
123 EmpathyAccountsDialog *dialog);
124 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
126 EmpathyAccountsDialog *dialog);
127 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
131 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
132 static gboolean accounts_dialog_are_accounts_connecting (MissionControl *mc);
133 static void accounts_dialog_status_changed_cb (MissionControl *mc,
134 TpConnectionStatus status,
136 TpConnectionStatusReason reason,
137 const gchar *unique_name,
138 EmpathyAccountsDialog *dialog);
139 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
140 EmpathyAccountsDialog *dialog);
141 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
142 EmpathyAccountsDialog *dialog);
143 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
144 EmpathyAccountsDialog *dialog);
145 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
146 EmpathyAccountsDialog *dialog);
147 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
148 EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_response_cb (GtkWidget *widget,
151 EmpathyAccountsDialog *dialog);
152 static void accounts_dialog_destroy_cb (GtkWidget *widget,
153 EmpathyAccountsDialog *dialog);
156 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
163 view = GTK_TREE_VIEW (dialog->treeview);
164 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
166 accounts = mc_accounts_list ();
168 for (l = accounts; l; l = l->next) {
171 TpConnectionStatus status;
176 name = mc_account_get_display_name (account);
178 g_object_unref (account);
182 status = mission_control_get_connection_status (dialog->mc, account, NULL);
183 enabled = mc_account_is_enabled (account);
185 gtk_list_store_insert_with_values (store, &iter,
187 COL_ENABLED, enabled,
190 COL_ACCOUNT_POINTER, account,
193 accounts_dialog_status_changed_cb (dialog->mc,
196 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
197 mc_account_get_unique_name (account),
200 g_object_unref (account);
203 g_list_free (accounts);
207 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
211 const gchar *config_ui;
218 view = GTK_TREE_VIEW (dialog->treeview);
219 model = gtk_tree_view_get_model (view);
221 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
222 /* We have configured accounts, select the first one */
223 accounts_dialog_model_select_first (dialog);
226 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
227 /* We have no account configured but we have some
228 * profiles instsalled. The user obviously wants to add
229 * an account. Click on the Add button for him. */
230 accounts_dialog_button_add_clicked_cb (dialog->button_add,
235 /* No account and no profile, warn the user */
236 gtk_widget_hide (dialog->vbox_details);
237 gtk_widget_hide (dialog->frame_new_account);
238 gtk_widget_show (dialog->frame_no_profile);
239 gtk_widget_set_sensitive (dialog->button_add, FALSE);
240 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
244 /* We have an account selected, destroy old settings and create a new
245 * one for the account selected */
246 gtk_widget_hide (dialog->frame_new_account);
247 gtk_widget_hide (dialog->frame_no_profile);
248 gtk_widget_show (dialog->vbox_details);
249 gtk_widget_set_sensitive (dialog->button_add, TRUE);
250 gtk_widget_set_sensitive (dialog->button_remove, TRUE);
252 if (dialog->settings_widget) {
253 gtk_widget_destroy (dialog->settings_widget);
254 dialog->settings_widget = NULL;
257 profile = mc_account_get_profile (account);
258 config_ui = mc_profile_get_configuration_ui (profile);
259 if (!tp_strdiff (config_ui, "jabber")) {
260 dialog->settings_widget =
261 empathy_account_widget_jabber_new (account);
263 else if (!tp_strdiff (config_ui, "msn")) {
264 dialog ->settings_widget =
265 empathy_account_widget_msn_new (account);
267 else if (!tp_strdiff (config_ui, "local-xmpp")) {
268 dialog->settings_widget =
269 empathy_account_widget_salut_new (account);
271 else if (!tp_strdiff (config_ui, "irc")) {
272 dialog->settings_widget =
273 empathy_account_widget_irc_new (account);
275 else if (!tp_strdiff(config_ui, "icq")) {
276 dialog->settings_widget =
277 empathy_account_widget_icq_new (account);
279 else if (!tp_strdiff(config_ui, "aim")) {
280 dialog->settings_widget =
281 empathy_account_widget_aim_new (account);
283 else if (!tp_strdiff (config_ui, "yahoo")) {
284 dialog->settings_widget =
285 empathy_account_widget_yahoo_new (account);
287 else if (!tp_strdiff (config_ui, "sofiasip")) {
288 dialog->settings_widget =
289 empathy_account_widget_sip_new (account);
291 else if (!tp_strdiff (config_ui, "groupwise")) {
292 dialog->settings_widget =
293 empathy_account_widget_groupwise_new (account);
296 dialog->settings_widget =
297 empathy_account_widget_generic_new (account);
300 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
301 dialog->settings_widget);
304 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
305 mc_profile_get_icon_name (profile),
306 GTK_ICON_SIZE_DIALOG);
307 gtk_widget_set_tooltip_text (dialog->image_type,
308 mc_profile_get_display_name (profile));
310 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
311 mc_account_get_display_name (account));
312 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
315 g_object_unref (profile);
319 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
322 GtkTreeSelection *selection;
324 store = gtk_list_store_new (COL_COUNT,
325 G_TYPE_BOOLEAN, /* enabled */
326 G_TYPE_STRING, /* name */
327 G_TYPE_UINT, /* status */
328 MC_TYPE_ACCOUNT); /* account */
330 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
331 GTK_TREE_MODEL (store));
333 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
334 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
336 g_signal_connect (selection, "changed",
337 G_CALLBACK (accounts_dialog_model_selection_changed),
340 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
341 COL_NAME, GTK_SORT_ASCENDING);
343 accounts_dialog_model_add_columns (dialog);
345 g_object_unref (store);
349 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
352 EmpathyAccountsDialog *dialog)
356 GtkTreePath *treepath;
359 if (accounts_dialog_are_accounts_connecting (dialog->mc)) {
360 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
361 (GSourceFunc) accounts_dialog_flash_connecting_cb,
365 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
366 treepath = gtk_tree_path_new_from_string (path);
367 gtk_tree_model_get_iter (model, &iter, treepath);
368 gtk_tree_model_get (model, &iter,
369 COL_ACCOUNT_POINTER, &account,
371 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
374 gtk_tree_path_free (treepath);
376 mc_account_set_display_name (account, new_text);
377 g_object_unref (account);
381 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
383 EmpathyAccountsDialog *dialog)
387 GtkTreePath *treepath;
391 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
392 treepath = gtk_tree_path_new_from_string (path);
393 gtk_tree_model_get_iter (model, &iter, treepath);
394 gtk_tree_model_get (model, &iter,
395 COL_ACCOUNT_POINTER, &account,
397 gtk_tree_path_free (treepath);
399 enabled = mc_account_is_enabled (account);
400 mc_account_set_enabled (account, !enabled);
402 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
403 mc_account_get_display_name(account));
405 g_object_unref (account);
409 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
410 GtkCellEditable *editable,
412 EmpathyAccountsDialog *dialog)
414 if (dialog->connecting_id) {
415 g_source_remove (dialog->connecting_id);
417 DEBUG ("Editing account name started; stopping flashing");
421 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
424 GtkTreeViewColumn *column;
425 GtkCellRenderer *cell;
427 view = GTK_TREE_VIEW (dialog->treeview);
428 gtk_tree_view_set_headers_visible (view, TRUE);
431 cell = gtk_cell_renderer_toggle_new ();
432 gtk_tree_view_insert_column_with_attributes (view, -1,
435 "active", COL_ENABLED,
437 g_signal_connect (cell, "toggled",
438 G_CALLBACK (accounts_dialog_enable_toggled_cb),
442 column = gtk_tree_view_column_new ();
443 gtk_tree_view_column_set_title (column, _("Accounts"));
444 gtk_tree_view_column_set_expand (column, TRUE);
445 gtk_tree_view_append_column (view, column);
448 cell = gtk_cell_renderer_pixbuf_new ();
449 gtk_tree_view_column_pack_start (column, cell, FALSE);
450 gtk_tree_view_column_set_cell_data_func (column, cell,
451 (GtkTreeCellDataFunc)
452 accounts_dialog_model_pixbuf_data_func,
457 cell = gtk_cell_renderer_text_new ();
459 "ellipsize", PANGO_ELLIPSIZE_END,
462 gtk_tree_view_column_pack_start (column, cell, TRUE);
463 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
464 g_signal_connect (cell, "edited",
465 G_CALLBACK (accounts_dialog_name_edited_cb),
467 g_signal_connect (cell, "editing-started",
468 G_CALLBACK (accounts_dialog_name_editing_started_cb),
473 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
477 GtkTreeSelection *selection;
481 view = GTK_TREE_VIEW (dialog->treeview);
482 model = gtk_tree_view_get_model (view);
484 if (gtk_tree_model_get_iter_first (model, &iter)) {
485 selection = gtk_tree_view_get_selection (view);
486 gtk_tree_selection_select_iter (selection, &iter);
488 accounts_dialog_update_account (dialog, NULL);
493 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
494 GtkCellRenderer *cell,
497 EmpathyAccountsDialog *dialog)
500 const gchar *icon_name;
502 TpConnectionStatus status;
504 gtk_tree_model_get (model, iter,
506 COL_ACCOUNT_POINTER, &account,
509 icon_name = empathy_icon_name_from_account (account);
510 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
513 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
514 (status == TP_CONNECTION_STATUS_CONNECTING &&
515 !dialog->connecting_show)) {
516 GdkPixbuf *modded_pixbuf;
518 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
521 gdk_pixbuf_get_width (pixbuf),
522 gdk_pixbuf_get_height (pixbuf));
524 gdk_pixbuf_saturate_and_pixelate (pixbuf,
528 g_object_unref (pixbuf);
529 pixbuf = modded_pixbuf;
538 g_object_unref (account);
540 g_object_unref (pixbuf);
545 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
550 GtkTreeSelection *selection;
554 /* Update the status in the model */
555 view = GTK_TREE_VIEW (dialog->treeview);
556 selection = gtk_tree_view_get_selection (view);
557 model = gtk_tree_view_get_model (view);
559 for (ok = gtk_tree_model_get_iter_first (model, iter);
561 ok = gtk_tree_model_iter_next (model, iter)) {
562 McAccount *this_account;
565 gtk_tree_model_get (model, iter,
566 COL_ACCOUNT_POINTER, &this_account,
569 equal = empathy_account_equal (this_account, account);
570 g_object_unref (this_account);
581 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
585 GtkTreeSelection *selection;
589 view = GTK_TREE_VIEW (dialog->treeview);
590 selection = gtk_tree_view_get_selection (view);
592 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
596 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
602 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
605 GtkTreeSelection *selection;
608 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
609 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
610 gtk_tree_selection_select_iter (selection, &iter);
615 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
619 GtkTreeSelection *selection;
622 view = GTK_TREE_VIEW (dialog->treeview);
623 selection = gtk_tree_view_get_selection (view);
625 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
629 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
633 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
634 EmpathyAccountsDialog *dialog)
639 gboolean is_selection;
641 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
643 account = accounts_dialog_model_get_selected (dialog);
644 accounts_dialog_update_account (dialog, account);
647 g_object_unref (account);
652 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
657 TpConnectionStatus status;
661 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
665 status = mission_control_get_connection_status (dialog->mc, account, NULL);
666 name = mc_account_get_display_name (account);
667 enabled = mc_account_is_enabled (account);
669 g_return_if_fail (name != NULL);
671 DEBUG ("Adding new account: %s", name);
673 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
674 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter,
676 COL_ENABLED, enabled,
679 COL_ACCOUNT_POINTER, account,
684 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
686 EmpathyAccountsDialog *dialog)
690 account = mc_account_lookup (unique_name);
691 accounts_dialog_add_account (dialog, account);
692 g_object_unref (account);
696 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
698 EmpathyAccountsDialog *dialog)
702 account = mc_account_lookup (unique_name);
704 accounts_dialog_model_set_selected (dialog, account);
705 accounts_dialog_model_remove_selected (dialog);
707 g_object_unref (account);
711 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
716 gtk_tree_model_row_changed (model, path, iter);
722 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
727 dialog->connecting_show = !dialog->connecting_show;
729 view = GTK_TREE_VIEW (dialog->treeview);
730 model = gtk_tree_view_get_model (view);
732 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
738 accounts_dialog_are_accounts_connecting (MissionControl *mc)
741 gboolean found = FALSE;
743 /* Check if there is still accounts in CONNECTING state */
744 accounts = mc_accounts_list_by_enabled (TRUE);
745 for (l = accounts; l; l = l->next) {
746 McAccount *this_account = l->data;
747 TpConnectionStatus status;
749 status = mission_control_get_connection_status (mc, this_account,
751 if (status == TP_CONNECTION_STATUS_CONNECTING) {
756 mc_accounts_list_free (accounts);
762 accounts_dialog_status_changed_cb (MissionControl *mc,
763 TpConnectionStatus status,
765 TpConnectionStatusReason reason,
766 const gchar *unique_name,
767 EmpathyAccountsDialog *dialog)
772 gboolean found = FALSE;
774 /* Update the status in the model */
775 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
776 account = mc_account_lookup (unique_name);
778 DEBUG ("Status changed for account %s: status=%d presence=%d",
779 unique_name, status, presence);
781 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
784 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
788 path = gtk_tree_model_get_path (model, &iter);
789 gtk_tree_model_row_changed (model, path, &iter);
790 gtk_tree_path_free (path);
792 g_object_unref (account);
794 found = accounts_dialog_are_accounts_connecting (mc);
796 if (!found && dialog->connecting_id) {
797 g_source_remove (dialog->connecting_id);
798 dialog->connecting_id = 0;
800 if (found && !dialog->connecting_id) {
801 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
802 (GSourceFunc) accounts_dialog_flash_connecting_cb,
808 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
810 EmpathyAccountsDialog *dialog)
817 /* Update the status in the model */
818 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
819 account = mc_account_lookup (unique_name);
820 enabled = mc_account_is_enabled (account);
822 DEBUG ("Account %s is now %s",
823 mc_account_get_display_name (account),
824 enabled ? "enabled" : "disabled");
826 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
827 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
828 COL_ENABLED, enabled,
832 g_object_unref (account);
836 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
837 EmpathyAccountsDialog *dialog)
842 McProfileCapabilityFlags cap;
844 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
847 account = mc_account_create (profile);
848 str = mc_account_get_unique_name (account);
849 mc_account_set_display_name (account, str);
851 cap = mc_profile_get_capabilities (profile);
852 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
855 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register));
857 mc_account_set_param_boolean (account, "register", TRUE);
861 accounts_dialog_add_account (dialog, account);
862 accounts_dialog_model_set_selected (dialog, account);
864 g_object_unref (account);
865 g_object_unref (profile);
869 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
870 EmpathyAccountsDialog *dialog)
874 account = accounts_dialog_model_get_selected (dialog);
875 accounts_dialog_update_account (dialog, account);
879 accounts_dialog_profile_changed_cb (GtkWidget *widget,
880 EmpathyAccountsDialog *dialog)
883 McProfileCapabilityFlags cap;
885 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
886 cap = mc_profile_get_capabilities (profile);
888 if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
889 gtk_widget_show (dialog->checkbutton_register);
891 gtk_widget_hide (dialog->checkbutton_register);
893 g_object_unref (profile);
897 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
898 EmpathyAccountsDialog *dialog)
901 GtkTreeSelection *selection;
904 view = GTK_TREE_VIEW (dialog->treeview);
905 model = gtk_tree_view_get_model (view);
906 selection = gtk_tree_view_get_selection (view);
907 gtk_tree_selection_unselect_all (selection);
909 gtk_widget_set_sensitive (dialog->button_add, FALSE);
910 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
911 gtk_widget_hide (dialog->vbox_details);
912 gtk_widget_hide (dialog->frame_no_profile);
913 gtk_widget_show (dialog->frame_new_account);
915 /* If we have no account, no need of a back button */
916 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
917 gtk_widget_show (dialog->button_back);
919 gtk_widget_hide (dialog->button_back);
922 accounts_dialog_profile_changed_cb (dialog->checkbutton_register, dialog);
923 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbutton_register),
925 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
926 gtk_widget_grab_focus (dialog->combobox_profile);
930 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
931 EmpathyAccountsDialog *dialog)
933 empathy_url_show ("ghelp:empathy?empathy-create-account");
937 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
938 EmpathyAccountsDialog *dialog)
941 GtkWidget *message_dialog;
944 account = accounts_dialog_model_get_selected (dialog);
946 if (!mc_account_is_complete (account)) {
947 accounts_dialog_model_remove_selected (dialog);
948 accounts_dialog_model_select_first (dialog);
951 message_dialog = gtk_message_dialog_new
952 (GTK_WINDOW (dialog->window),
953 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
954 GTK_MESSAGE_QUESTION,
956 _("You are about to remove your %s account!\n"
957 "Are you sure you want to proceed?"),
958 mc_account_get_display_name (account));
960 gtk_message_dialog_format_secondary_text
961 (GTK_MESSAGE_DIALOG (message_dialog),
962 _("Any associated conversations and chat rooms will NOT be "
963 "removed if you decide to proceed.\n"
965 "Should you decide to add the account back at a later time, "
966 "they will still be available."));
968 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
971 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
975 gtk_widget_show (message_dialog);
976 res = gtk_dialog_run (GTK_DIALOG (message_dialog));
978 if (res == GTK_RESPONSE_YES) {
979 mc_account_delete (account);
980 accounts_dialog_model_select_first (dialog);
982 gtk_widget_destroy (message_dialog);
986 accounts_dialog_response_cb (GtkWidget *widget,
988 EmpathyAccountsDialog *dialog)
990 if (response == GTK_RESPONSE_CLOSE) {
991 gtk_widget_destroy (widget);
996 accounts_dialog_destroy_cb (GtkWidget *widget,
997 EmpathyAccountsDialog *dialog)
1001 /* Disconnect signals */
1002 g_signal_handlers_disconnect_by_func (dialog->monitor,
1003 accounts_dialog_account_added_cb,
1005 g_signal_handlers_disconnect_by_func (dialog->monitor,
1006 accounts_dialog_account_removed_cb,
1008 g_signal_handlers_disconnect_by_func (dialog->monitor,
1009 accounts_dialog_account_enabled_cb,
1011 empathy_disconnect_account_status_changed (dialog->token);
1013 /* Delete incomplete accounts */
1014 accounts = mc_accounts_list ();
1015 for (l = accounts; l; l = l->next) {
1019 if (!mc_account_is_complete (account)) {
1020 /* FIXME: Warn the user the account is not complete
1021 * and is going to be removed. */
1022 mc_account_delete (account);
1025 g_object_unref (account);
1027 g_list_free (accounts);
1029 if (dialog->connecting_id) {
1030 g_source_remove (dialog->connecting_id);
1033 g_object_unref (dialog->mc);
1034 g_object_unref (dialog->monitor);
1040 empathy_accounts_dialog_show (GtkWindow *parent,
1041 McAccount *selected_account)
1043 static EmpathyAccountsDialog *dialog = NULL;
1048 gtk_window_present (GTK_WINDOW (dialog->window));
1049 return dialog->window;
1052 dialog = g_new0 (EmpathyAccountsDialog, 1);
1054 filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
1056 glade = empathy_glade_get_file (filename,
1059 "accounts_dialog", &dialog->window,
1060 "vbox_details", &dialog->vbox_details,
1061 "frame_no_profile", &dialog->frame_no_profile,
1062 "alignment_settings", &dialog->alignment_settings,
1063 "treeview", &dialog->treeview,
1064 "frame_new_account", &dialog->frame_new_account,
1065 "hbox_type", &dialog->hbox_type,
1066 "button_create", &dialog->button_create,
1067 "button_back", &dialog->button_back,
1068 "checkbutton_register", &dialog->checkbutton_register,
1069 "image_type", &dialog->image_type,
1070 "label_name", &dialog->label_name,
1071 "button_add", &dialog->button_add,
1072 "button_remove", &dialog->button_remove,
1076 empathy_glade_connect (glade,
1078 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1079 "accounts_dialog", "response", accounts_dialog_response_cb,
1080 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1081 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1082 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1083 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1084 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1087 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1089 g_object_unref (glade);
1091 /* Create profile chooser */
1092 dialog->combobox_profile = empathy_profile_chooser_new ();
1093 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1094 dialog->combobox_profile,
1096 gtk_widget_show (dialog->combobox_profile);
1097 g_signal_connect (dialog->combobox_profile, "changed",
1098 G_CALLBACK (accounts_dialog_profile_changed_cb),
1101 /* Set up signalling */
1102 dialog->mc = empathy_mission_control_new ();
1103 dialog->monitor = mc_account_monitor_new ();
1105 g_signal_connect (dialog->monitor, "account-created",
1106 G_CALLBACK (accounts_dialog_account_added_cb),
1108 g_signal_connect (dialog->monitor, "account-deleted",
1109 G_CALLBACK (accounts_dialog_account_removed_cb),
1111 g_signal_connect (dialog->monitor, "account-enabled",
1112 G_CALLBACK (accounts_dialog_account_enabled_cb),
1114 g_signal_connect (dialog->monitor, "account-disabled",
1115 G_CALLBACK (accounts_dialog_account_enabled_cb),
1117 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1118 G_CALLBACK (accounts_dialog_status_changed_cb),
1121 accounts_dialog_model_setup (dialog);
1122 accounts_dialog_setup (dialog);
1124 if (selected_account) {
1125 accounts_dialog_model_set_selected (dialog, selected_account);
1127 accounts_dialog_model_select_first (dialog);
1131 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1132 GTK_WINDOW (parent));
1135 gtk_widget_show (dialog->window);
1137 return dialog->window;