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;
77 GtkWidget *image_type;
78 GtkWidget *label_name;
79 GtkWidget *label_type;
80 GtkWidget *settings_widget;
82 gboolean connecting_show;
84 gboolean account_changed;
87 McAccountMonitor *monitor;
89 } EmpathyAccountsDialog;
99 static void accounts_dialog_setup (EmpathyAccountsDialog *dialog);
100 static void accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
102 static void accounts_dialog_model_setup (EmpathyAccountsDialog *dialog);
103 static void accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog);
104 static void accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
105 GtkCellEditable *editable,
107 EmpathyAccountsDialog *dialog);
108 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
109 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
110 GtkCellRenderer *cell,
113 EmpathyAccountsDialog *dialog);
114 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
115 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
117 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
118 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
119 EmpathyAccountsDialog *dialog);
120 static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
122 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
124 EmpathyAccountsDialog *dialog);
125 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
127 EmpathyAccountsDialog *dialog);
128 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
132 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
133 static gboolean accounts_dialog_are_accounts_connecting (MissionControl *mc);
134 static void accounts_dialog_status_changed_cb (MissionControl *mc,
135 TpConnectionStatus status,
137 TpConnectionStatusReason reason,
138 const gchar *unique_name,
139 EmpathyAccountsDialog *dialog);
140 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
143 EmpathyAccountsDialog *dialog);
144 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
145 EmpathyAccountsDialog *dialog);
146 static void accounts_dialog_button_help_clicked_cb (GtkWidget *button,
147 EmpathyAccountsDialog *dialog);
148 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
151 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
152 EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_response_cb (GtkWidget *widget,
155 EmpathyAccountsDialog *dialog);
156 static void accounts_dialog_destroy_cb (GtkWidget *widget,
157 EmpathyAccountsDialog *dialog);
160 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
167 view = GTK_TREE_VIEW (dialog->treeview);
168 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
170 accounts = mc_accounts_list ();
172 for (l = accounts; l; l = l->next) {
175 TpConnectionStatus status;
180 name = mc_account_get_display_name (account);
182 g_object_unref (account);
186 status = mission_control_get_connection_status (dialog->mc, account, NULL);
187 enabled = mc_account_is_enabled (account);
189 gtk_list_store_insert_with_values (store, &iter,
191 COL_ENABLED, enabled,
194 COL_ACCOUNT_POINTER, account,
197 accounts_dialog_status_changed_cb (dialog->mc,
200 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
201 mc_account_get_unique_name (account),
204 g_object_unref (account);
207 g_list_free (accounts);
211 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
214 if (dialog->settings_widget) {
215 gtk_widget_destroy (dialog->settings_widget);
216 dialog->settings_widget = NULL;
225 gtk_widget_show (dialog->frame_no_account);
226 gtk_widget_hide (dialog->vbox_details);
228 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
230 view = GTK_TREE_VIEW (dialog->treeview);
231 model = gtk_tree_view_get_model (view);
233 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
234 string = g_string_new (_("To add a new account, you can click on the "
235 "'Add' button and a new entry will be created "
236 "for you to start configuring."));
238 string = g_string_new (_("To add a new account, you first have to "
239 "install a backend for each protocol "
240 "you want to use."));
243 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
244 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
245 _("<b>No Account Selected</b>"));
246 g_string_append (string, _("\n\n"
247 "If you do not want to add an account, simply "
248 "click on the account you want to configure in "
249 "the list on the left."));
251 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
252 _("<b>No Accounts Configured</b>"));
255 str = g_string_free (string, FALSE);
256 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
261 const gchar *config_ui;
263 gtk_widget_hide (dialog->frame_no_account);
264 gtk_widget_show (dialog->vbox_details);
266 profile = mc_account_get_profile (account);
267 config_ui = mc_profile_get_configuration_ui (profile);
268 g_object_unref (profile);
270 if (!tp_strdiff (config_ui, "jabber")) {
271 dialog->settings_widget =
272 empathy_account_widget_jabber_new (account);
274 else if (!tp_strdiff (config_ui, "msn")) {
275 dialog ->settings_widget =
276 empathy_account_widget_msn_new (account);
278 else if (!tp_strdiff (config_ui, "local-xmpp")) {
279 dialog->settings_widget =
280 empathy_account_widget_salut_new (account);
282 else if (!tp_strdiff (config_ui, "irc")) {
283 dialog->settings_widget =
284 empathy_account_widget_irc_new (account);
286 else if (!tp_strdiff(config_ui, "icq")) {
287 dialog->settings_widget =
288 empathy_account_widget_icq_new (account);
290 else if (!tp_strdiff(config_ui, "aim")) {
291 dialog->settings_widget =
292 empathy_account_widget_aim_new (account);
294 else if (!tp_strdiff (config_ui, "yahoo")) {
295 dialog->settings_widget =
296 empathy_account_widget_yahoo_new (account);
298 else if (!tp_strdiff (config_ui, "sofiasip")) {
299 dialog->settings_widget =
300 empathy_account_widget_sip_new (account);
302 else if (!tp_strdiff (config_ui, "groupwise")) {
303 dialog->settings_widget =
304 empathy_account_widget_groupwise_new (account);
307 dialog->settings_widget =
308 empathy_account_widget_generic_new (account);
312 if (dialog->settings_widget) {
313 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
314 dialog->settings_widget);
321 profile = mc_account_get_profile (account);
322 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
323 mc_profile_get_icon_name (profile),
324 GTK_ICON_SIZE_DIALOG);
325 gtk_widget_set_tooltip_text (dialog->image_type,
326 mc_profile_get_display_name (profile));
328 text = g_markup_printf_escaped ("<big><b>%s</b></big>",
329 mc_account_get_display_name (account));
330 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
336 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
339 GtkTreeSelection *selection;
341 store = gtk_list_store_new (COL_COUNT,
342 G_TYPE_BOOLEAN, /* enabled */
343 G_TYPE_STRING, /* name */
344 G_TYPE_UINT, /* status */
345 MC_TYPE_ACCOUNT); /* account */
347 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
348 GTK_TREE_MODEL (store));
350 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
351 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
353 g_signal_connect (selection, "changed",
354 G_CALLBACK (accounts_dialog_model_selection_changed),
357 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
358 COL_NAME, GTK_SORT_ASCENDING);
360 accounts_dialog_model_add_columns (dialog);
362 g_object_unref (store);
366 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
369 EmpathyAccountsDialog *dialog)
373 GtkTreePath *treepath;
376 if (accounts_dialog_are_accounts_connecting (dialog->mc)) {
377 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
378 (GSourceFunc) accounts_dialog_flash_connecting_cb,
382 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
383 treepath = gtk_tree_path_new_from_string (path);
384 gtk_tree_model_get_iter (model, &iter, treepath);
385 gtk_tree_model_get (model, &iter,
386 COL_ACCOUNT_POINTER, &account,
388 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
391 gtk_tree_path_free (treepath);
393 mc_account_set_display_name (account, new_text);
394 g_object_unref (account);
398 accounts_dialog_enable_toggled_cb (GtkCellRendererToggle *cell_renderer,
400 EmpathyAccountsDialog *dialog)
404 GtkTreePath *treepath;
408 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
409 treepath = gtk_tree_path_new_from_string (path);
410 gtk_tree_model_get_iter (model, &iter, treepath);
411 gtk_tree_model_get (model, &iter,
412 COL_ACCOUNT_POINTER, &account,
414 gtk_tree_path_free (treepath);
416 enabled = mc_account_is_enabled (account);
417 mc_account_set_enabled (account, !enabled);
419 DEBUG ("%s account %s", enabled ? "Disabled" : "Enable",
420 mc_account_get_display_name(account));
422 g_object_unref (account);
426 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
427 GtkCellEditable *editable,
429 EmpathyAccountsDialog *dialog)
431 if (dialog->connecting_id) {
432 g_source_remove (dialog->connecting_id);
434 DEBUG ("Editing account name started; stopping flashing");
438 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
441 GtkTreeViewColumn *column;
442 GtkCellRenderer *cell;
444 view = GTK_TREE_VIEW (dialog->treeview);
445 gtk_tree_view_set_headers_visible (view, TRUE);
448 cell = gtk_cell_renderer_toggle_new ();
449 gtk_tree_view_insert_column_with_attributes (view, -1,
452 "active", COL_ENABLED,
454 g_signal_connect (cell, "toggled",
455 G_CALLBACK (accounts_dialog_enable_toggled_cb),
459 column = gtk_tree_view_column_new ();
460 gtk_tree_view_column_set_title (column, _("Accounts"));
461 gtk_tree_view_column_set_expand (column, TRUE);
462 gtk_tree_view_append_column (view, column);
465 cell = gtk_cell_renderer_pixbuf_new ();
466 gtk_tree_view_column_pack_start (column, cell, FALSE);
467 gtk_tree_view_column_set_cell_data_func (column, cell,
468 (GtkTreeCellDataFunc)
469 accounts_dialog_model_pixbuf_data_func,
474 cell = gtk_cell_renderer_text_new ();
476 "ellipsize", PANGO_ELLIPSIZE_END,
479 gtk_tree_view_column_pack_start (column, cell, TRUE);
480 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
481 g_signal_connect (cell, "edited",
482 G_CALLBACK (accounts_dialog_name_edited_cb),
484 g_signal_connect (cell, "editing-started",
485 G_CALLBACK (accounts_dialog_name_editing_started_cb),
490 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
494 GtkTreeSelection *selection;
498 view = GTK_TREE_VIEW (dialog->treeview);
499 model = gtk_tree_view_get_model (view);
501 if (gtk_tree_model_get_iter_first (model, &iter)) {
502 selection = gtk_tree_view_get_selection (view);
503 gtk_tree_selection_select_iter (selection, &iter);
505 accounts_dialog_update_account (dialog, NULL);
510 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
511 GtkCellRenderer *cell,
514 EmpathyAccountsDialog *dialog)
517 const gchar *icon_name;
519 TpConnectionStatus status;
521 gtk_tree_model_get (model, iter,
523 COL_ACCOUNT_POINTER, &account,
526 icon_name = empathy_icon_name_from_account (account);
527 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
530 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
531 (status == TP_CONNECTION_STATUS_CONNECTING &&
532 !dialog->connecting_show)) {
533 GdkPixbuf *modded_pixbuf;
535 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
538 gdk_pixbuf_get_width (pixbuf),
539 gdk_pixbuf_get_height (pixbuf));
541 gdk_pixbuf_saturate_and_pixelate (pixbuf,
545 g_object_unref (pixbuf);
546 pixbuf = modded_pixbuf;
555 g_object_unref (account);
557 g_object_unref (pixbuf);
562 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
567 GtkTreeSelection *selection;
571 /* Update the status in the model */
572 view = GTK_TREE_VIEW (dialog->treeview);
573 selection = gtk_tree_view_get_selection (view);
574 model = gtk_tree_view_get_model (view);
576 for (ok = gtk_tree_model_get_iter_first (model, iter);
578 ok = gtk_tree_model_iter_next (model, iter)) {
579 McAccount *this_account;
582 gtk_tree_model_get (model, iter,
583 COL_ACCOUNT_POINTER, &this_account,
586 equal = empathy_account_equal (this_account, account);
587 g_object_unref (this_account);
598 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
602 GtkTreeSelection *selection;
606 view = GTK_TREE_VIEW (dialog->treeview);
607 selection = gtk_tree_view_get_selection (view);
609 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
613 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
619 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
622 GtkTreeSelection *selection;
625 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
626 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
627 gtk_tree_selection_select_iter (selection, &iter);
632 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
636 GtkTreeSelection *selection;
639 view = GTK_TREE_VIEW (dialog->treeview);
640 selection = gtk_tree_view_get_selection (view);
642 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
646 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
650 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
651 EmpathyAccountsDialog *dialog)
656 gboolean is_selection;
658 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
660 gtk_widget_set_sensitive (dialog->button_add, TRUE);
661 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
663 account = accounts_dialog_model_get_selected (dialog);
664 accounts_dialog_update_account (dialog, account);
667 g_object_unref (account);
670 /* insure new account frame is hidden when a row is selected*/
671 gtk_widget_hide (dialog->frame_new_account);
675 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
680 TpConnectionStatus status;
684 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
688 status = mission_control_get_connection_status (dialog->mc, account, NULL);
689 name = mc_account_get_display_name (account);
690 enabled = mc_account_is_enabled (account);
692 g_return_if_fail (name != NULL);
694 DEBUG ("Adding new account: %s", name);
696 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
697 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter,
699 COL_ENABLED, enabled,
702 COL_ACCOUNT_POINTER, account,
707 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
709 EmpathyAccountsDialog *dialog)
713 account = mc_account_lookup (unique_name);
714 accounts_dialog_add_account (dialog, account);
715 g_object_unref (account);
719 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
721 EmpathyAccountsDialog *dialog)
725 account = mc_account_lookup (unique_name);
727 accounts_dialog_model_set_selected (dialog, account);
728 accounts_dialog_model_remove_selected (dialog);
730 g_object_unref (account);
734 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
739 gtk_tree_model_row_changed (model, path, iter);
745 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
750 dialog->connecting_show = !dialog->connecting_show;
752 view = GTK_TREE_VIEW (dialog->treeview);
753 model = gtk_tree_view_get_model (view);
755 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
761 accounts_dialog_are_accounts_connecting (MissionControl *mc)
764 gboolean found = FALSE;
766 /* Check if there is still accounts in CONNECTING state */
767 accounts = mc_accounts_list_by_enabled (TRUE);
768 for (l = accounts; l; l = l->next) {
769 McAccount *this_account = l->data;
770 TpConnectionStatus status;
772 status = mission_control_get_connection_status (mc, this_account,
774 if (status == TP_CONNECTION_STATUS_CONNECTING) {
779 mc_accounts_list_free (accounts);
785 accounts_dialog_status_changed_cb (MissionControl *mc,
786 TpConnectionStatus status,
788 TpConnectionStatusReason reason,
789 const gchar *unique_name,
790 EmpathyAccountsDialog *dialog)
795 gboolean found = FALSE;
797 /* Update the status in the model */
798 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
799 account = mc_account_lookup (unique_name);
801 DEBUG ("Status changed for account %s: status=%d presence=%d",
802 unique_name, status, presence);
804 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
807 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
811 path = gtk_tree_model_get_path (model, &iter);
812 gtk_tree_model_row_changed (model, path, &iter);
813 gtk_tree_path_free (path);
815 g_object_unref (account);
817 found = accounts_dialog_are_accounts_connecting (mc);
819 if (!found && dialog->connecting_id) {
820 g_source_remove (dialog->connecting_id);
821 dialog->connecting_id = 0;
823 if (found && !dialog->connecting_id) {
824 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
825 (GSourceFunc) accounts_dialog_flash_connecting_cb,
831 accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
833 EmpathyAccountsDialog *dialog)
840 /* Update the status in the model */
841 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
842 account = mc_account_lookup (unique_name);
843 enabled = mc_account_is_enabled (account);
845 DEBUG ("Account %s is now %s",
846 mc_account_get_display_name (account),
847 enabled ? "enabled" : "disabled");
849 if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
850 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
851 COL_ENABLED, enabled,
855 g_object_unref (account);
859 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
860 EmpathyAccountsDialog *dialog)
867 gtk_widget_show (dialog->vbox_details);
868 gtk_widget_hide (dialog->frame_no_account);
869 gtk_widget_hide (dialog->frame_new_account);
871 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
874 account = mc_account_create (profile);
876 str = mc_account_get_unique_name (account);
877 mc_account_set_display_name (account, str);
879 accounts_dialog_add_account (dialog, account);
880 accounts_dialog_model_set_selected (dialog, account);
882 g_object_unref (account);
883 g_object_unref (profile);
887 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
888 EmpathyAccountsDialog *dialog)
892 gtk_widget_hide (dialog->vbox_details);
893 gtk_widget_hide (dialog->frame_no_account);
894 gtk_widget_hide (dialog->frame_new_account);
896 gtk_widget_set_sensitive (dialog->button_add, TRUE);
898 account = accounts_dialog_model_get_selected (dialog);
899 accounts_dialog_update_account (dialog, account);
903 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
904 EmpathyAccountsDialog *dialog)
907 GtkTreeSelection *selection;
909 view = GTK_TREE_VIEW (dialog->treeview);
910 selection = gtk_tree_view_get_selection (view);
911 gtk_tree_selection_unselect_all (selection);
913 gtk_widget_set_sensitive (dialog->button_add, FALSE);
914 gtk_widget_hide (dialog->vbox_details);
915 gtk_widget_hide (dialog->frame_no_account);
916 gtk_widget_show (dialog->frame_new_account);
918 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
919 gtk_widget_grab_focus (dialog->combobox_profile);
923 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
924 EmpathyAccountsDialog *dialog)
926 empathy_url_show ("ghelp:empathy?empathy-create-account");
930 accounts_dialog_remove_response_cb (GtkWidget *dialog,
934 if (response == GTK_RESPONSE_YES) {
935 mc_account_delete (account);
938 gtk_widget_destroy (dialog);
942 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
943 EmpathyAccountsDialog *dialog)
946 GtkWidget *message_dialog;
948 account = accounts_dialog_model_get_selected (dialog);
950 if (!mc_account_is_complete (account)) {
951 accounts_dialog_model_remove_selected (dialog);
954 message_dialog = gtk_message_dialog_new
955 (GTK_WINDOW (dialog->window),
956 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
957 GTK_MESSAGE_QUESTION,
959 _("You are about to remove your %s account!\n"
960 "Are you sure you want to proceed?"),
961 mc_account_get_display_name (account));
963 gtk_message_dialog_format_secondary_text
964 (GTK_MESSAGE_DIALOG (message_dialog),
965 _("Any associated conversations and chat rooms will NOT be "
966 "removed if you decide to proceed.\n"
968 "Should you decide to add the account back at a later time, "
969 "they will still be available."));
971 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
974 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
978 g_signal_connect (message_dialog, "response",
979 G_CALLBACK (accounts_dialog_remove_response_cb),
982 gtk_widget_show (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_account", &dialog->frame_no_account,
1062 "label_no_account", &dialog->label_no_account,
1063 "label_no_account_blurb", &dialog->label_no_account_blurb,
1064 "alignment_settings", &dialog->alignment_settings,
1065 "treeview", &dialog->treeview,
1066 "frame_new_account", &dialog->frame_new_account,
1067 "hbox_type", &dialog->hbox_type,
1068 "button_create", &dialog->button_create,
1069 "button_back", &dialog->button_back,
1070 "image_type", &dialog->image_type,
1071 "label_name", &dialog->label_name,
1072 "button_add", &dialog->button_add,
1073 "button_remove", &dialog->button_remove,
1077 empathy_glade_connect (glade,
1079 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1080 "accounts_dialog", "response", accounts_dialog_response_cb,
1081 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1082 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1083 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1084 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1085 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1088 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1090 g_object_unref (glade);
1092 /* Create profile chooser */
1093 dialog->combobox_profile = empathy_profile_chooser_new ();
1094 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1095 dialog->combobox_profile,
1097 gtk_widget_show (dialog->combobox_profile);
1098 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) <= 0) {
1099 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1102 /* Set up signalling */
1103 dialog->mc = empathy_mission_control_new ();
1104 dialog->monitor = mc_account_monitor_new ();
1106 g_signal_connect (dialog->monitor, "account-created",
1107 G_CALLBACK (accounts_dialog_account_added_cb),
1109 g_signal_connect (dialog->monitor, "account-deleted",
1110 G_CALLBACK (accounts_dialog_account_removed_cb),
1112 g_signal_connect (dialog->monitor, "account-enabled",
1113 G_CALLBACK (accounts_dialog_account_enabled_cb),
1115 g_signal_connect (dialog->monitor, "account-disabled",
1116 G_CALLBACK (accounts_dialog_account_enabled_cb),
1118 dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
1119 G_CALLBACK (accounts_dialog_status_changed_cb),
1122 accounts_dialog_model_setup (dialog);
1123 accounts_dialog_setup (dialog);
1125 if (selected_account) {
1126 accounts_dialog_model_set_selected (dialog, selected_account);
1128 accounts_dialog_model_select_first (dialog);
1132 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1133 GTK_WINDOW (parent));
1136 gtk_widget_show (dialog->window);
1138 return dialog->window;