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 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>
40 #include <libtelepathy/tp-constants.h>
42 #include <libempathy/empathy-debug.h>
43 #include <libempathy/empathy-utils.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
46 #include "empathy-accounts-dialog.h"
47 #include "empathy-profile-chooser.h"
48 #include "empathy-account-widget-generic.h"
49 #include "empathy-account-widget-jabber.h"
50 #include "empathy-account-widget-msn.h"
51 #include "empathy-account-widget-salut.h"
53 #define DEBUG_DOMAIN "AccountDialog"
55 /* Flashing delay for icons (milliseconds). */
56 #define FLASH_TIMEOUT 500
61 GtkWidget *alignment_settings;
63 GtkWidget *vbox_details;
64 GtkWidget *frame_no_account;
65 GtkWidget *label_no_account;
66 GtkWidget *label_no_account_blurb;
70 GtkWidget *button_add;
71 GtkWidget *button_remove;
72 GtkWidget *button_connect;
74 GtkWidget *frame_new_account;
75 GtkWidget *combobox_profile;
77 GtkWidget *button_create;
78 GtkWidget *button_back;
80 GtkWidget *image_type;
81 GtkWidget *label_name;
82 GtkWidget *label_type;
83 GtkWidget *settings_widget;
85 gboolean connecting_show;
87 gboolean account_changed;
90 McAccountMonitor *monitor;
91 } 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_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_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 void accounts_dialog_status_changed_cb (MissionControl *mc,
131 TpConnectionStatus status,
133 TpConnectionStatusReason reason,
134 const gchar *unique_name,
135 EmpathyAccountsDialog *dialog);
136 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
137 EmpathyAccountsDialog *dialog);
138 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
139 EmpathyAccountsDialog *dialog);
140 static void accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
143 EmpathyAccountsDialog *dialog);
144 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
147 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
148 EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
151 GtkTreeViewColumn *column,
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;
179 name = mc_account_get_display_name (account);
184 status = mission_control_get_connection_status (dialog->mc, account, NULL);
186 gtk_list_store_insert_with_values (store, &iter,
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_connect_button (EmpathyAccountsDialog *dialog)
211 const gchar *stock_id;
214 account = accounts_dialog_model_get_selected (dialog);
216 gtk_widget_set_sensitive (dialog->button_connect, account != NULL);
218 if (account && mc_account_is_enabled (account)) {
219 label = _("Disable");
220 stock_id = GTK_STOCK_DISCONNECT;
223 stock_id = GTK_STOCK_CONNECT;
226 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
228 gtk_button_set_label (GTK_BUTTON (dialog->button_connect), label);
229 gtk_button_set_image (GTK_BUTTON (dialog->button_connect), image);
233 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
236 if (dialog->settings_widget) {
237 gtk_widget_destroy (dialog->settings_widget);
238 dialog->settings_widget = NULL;
247 gtk_widget_show (dialog->frame_no_account);
248 gtk_widget_hide (dialog->vbox_details);
250 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
251 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
253 view = GTK_TREE_VIEW (dialog->treeview);
254 model = gtk_tree_view_get_model (view);
256 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) > 0) {
257 string = g_string_new (_("To add a new account, you can click on the "
258 "'Add' button and a new entry will be created "
259 "for you to start configuring."));
261 string = g_string_new (_("To add a new account, you first have to "
262 "install a backend for each protocol "
263 "you want to use."));
266 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
267 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
268 _("<b>No Account Selected</b>"));
269 g_string_append (string, _("\n\n"
270 "If you do not want to add an account, simply "
271 "click on the account you want to configure in "
272 "the list on the left."));
274 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
275 _("<b>No Accounts Configured</b>"));
278 str = g_string_free (string, FALSE);
279 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
284 const gchar *config_ui;
286 gtk_widget_hide (dialog->frame_no_account);
287 gtk_widget_show (dialog->vbox_details);
289 profile = mc_account_get_profile (account);
290 config_ui = mc_profile_get_configuration_ui (profile);
291 g_object_unref (profile);
293 if (!tp_strdiff (config_ui, "jabber")) {
294 dialog->settings_widget =
295 empathy_account_widget_jabber_new (account);
297 else if (!tp_strdiff (config_ui, "msn")) {
298 dialog ->settings_widget =
299 empathy_account_widget_msn_new (account);
301 else if (!tp_strdiff (config_ui, "local-xmpp")) {
302 dialog->settings_widget =
303 empathy_account_widget_salut_new (account);
306 dialog->settings_widget =
307 empathy_account_widget_generic_new (account);
311 if (dialog->settings_widget) {
312 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
313 dialog->settings_widget);
320 profile = mc_account_get_profile (account);
321 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
322 mc_profile_get_icon_name (profile),
323 GTK_ICON_SIZE_DIALOG);
324 gtk_widget_set_tooltip_text (dialog->image_type,
325 mc_profile_get_display_name (profile));
327 text = g_strdup_printf ("<big><b>%s</b></big>", mc_account_get_display_name (account));
328 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
334 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
337 GtkTreeSelection *selection;
339 store = gtk_list_store_new (COL_COUNT,
340 G_TYPE_STRING, /* name */
341 G_TYPE_UINT, /* status */
342 MC_TYPE_ACCOUNT); /* account */
344 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
345 GTK_TREE_MODEL (store));
347 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
348 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
350 g_signal_connect (selection, "changed",
351 G_CALLBACK (accounts_dialog_model_selection_changed),
354 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
355 COL_NAME, GTK_SORT_ASCENDING);
357 accounts_dialog_model_add_columns (dialog);
359 g_object_unref (store);
363 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
366 EmpathyAccountsDialog *dialog)
370 GtkTreePath *treepath;
373 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
374 treepath = gtk_tree_path_new_from_string (path);
375 gtk_tree_model_get_iter (model, &iter, treepath);
376 gtk_tree_model_get (model, &iter,
377 COL_ACCOUNT_POINTER, &account,
379 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
382 gtk_tree_path_free (treepath);
384 mc_account_set_display_name (account, new_text);
385 g_object_unref (account);
389 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
392 GtkTreeViewColumn *column;
393 GtkCellRenderer *cell;
395 view = GTK_TREE_VIEW (dialog->treeview);
396 gtk_tree_view_set_headers_visible (view, TRUE);
398 /* account name/status */
399 column = gtk_tree_view_column_new ();
400 gtk_tree_view_column_set_title (column, _("Accounts"));
402 cell = gtk_cell_renderer_pixbuf_new ();
403 gtk_tree_view_column_pack_start (column, cell, FALSE);
404 gtk_tree_view_column_set_cell_data_func (column, cell,
405 (GtkTreeCellDataFunc)
406 accounts_dialog_model_pixbuf_data_func,
410 cell = gtk_cell_renderer_text_new ();
412 "ellipsize", PANGO_ELLIPSIZE_END,
415 gtk_tree_view_column_pack_start (column, cell, TRUE);
416 gtk_tree_view_column_add_attribute (column,
419 g_signal_connect (cell, "edited",
420 G_CALLBACK (accounts_dialog_name_edited_cb),
423 gtk_tree_view_column_set_expand (column, TRUE);
424 gtk_tree_view_append_column (view, column);
428 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
432 GtkTreeSelection *selection;
436 view = GTK_TREE_VIEW (dialog->treeview);
437 model = gtk_tree_view_get_model (view);
439 if (gtk_tree_model_get_iter_first (model, &iter)) {
440 selection = gtk_tree_view_get_selection (view);
441 gtk_tree_selection_select_iter (selection, &iter);
443 accounts_dialog_update_account (dialog, NULL);
448 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
449 GtkCellRenderer *cell,
452 EmpathyAccountsDialog *dialog)
455 const gchar *icon_name;
457 TpConnectionStatus status;
459 gtk_tree_model_get (model, iter,
461 COL_ACCOUNT_POINTER, &account,
464 icon_name = empathy_icon_name_from_account (account);
465 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
468 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
469 (status == TP_CONNECTION_STATUS_CONNECTING &&
470 !dialog->connecting_show)) {
471 GdkPixbuf *modded_pixbuf;
473 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
476 gdk_pixbuf_get_width (pixbuf),
477 gdk_pixbuf_get_height (pixbuf));
479 gdk_pixbuf_saturate_and_pixelate (pixbuf,
483 g_object_unref (pixbuf);
484 pixbuf = modded_pixbuf;
493 g_object_unref (account);
495 g_object_unref (pixbuf);
500 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
504 GtkTreeSelection *selection;
508 view = GTK_TREE_VIEW (dialog->treeview);
509 selection = gtk_tree_view_get_selection (view);
511 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
515 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
521 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
525 GtkTreeSelection *selection;
530 view = GTK_TREE_VIEW (dialog->treeview);
531 model = gtk_tree_view_get_model (view);
532 selection = gtk_tree_view_get_selection (view);
534 for (ok = gtk_tree_model_get_iter_first (model, &iter);
536 ok = gtk_tree_model_iter_next (model, &iter)) {
537 McAccount *this_account;
540 gtk_tree_model_get (model, &iter,
541 COL_ACCOUNT_POINTER, &this_account,
544 equal = empathy_account_equal (this_account, account);
545 g_object_unref (this_account);
548 gtk_tree_selection_select_iter (selection, &iter);
555 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
559 GtkTreeSelection *selection;
562 view = GTK_TREE_VIEW (dialog->treeview);
563 selection = gtk_tree_view_get_selection (view);
565 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
569 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
573 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
574 EmpathyAccountsDialog *dialog)
579 gboolean is_selection;
581 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
583 gtk_widget_set_sensitive (dialog->button_add, TRUE);
584 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
585 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
587 accounts_dialog_update_connect_button (dialog);
589 account = accounts_dialog_model_get_selected (dialog);
590 accounts_dialog_update_account (dialog, account);
593 g_object_unref (account);
596 /* insure new account frame is hidden when a row is selected*/
597 gtk_widget_hide (dialog->frame_new_account);
601 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
604 TpConnectionStatus status;
612 view = GTK_TREE_VIEW (dialog->treeview);
613 model = gtk_tree_view_get_model (view);
614 store = GTK_LIST_STORE (model);
616 for (ok = gtk_tree_model_get_iter_first (model, &iter);
618 ok = gtk_tree_model_iter_next (model, &iter)) {
619 McAccount *this_account;
622 gtk_tree_model_get (model, &iter,
623 COL_ACCOUNT_POINTER, &this_account,
626 equal = empathy_account_equal (this_account, account);
627 g_object_unref (this_account);
634 status = mission_control_get_connection_status (dialog->mc, account, NULL);
635 name = mc_account_get_display_name (account);
637 g_return_if_fail (name != NULL);
639 empathy_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
641 gtk_list_store_insert_with_values (store, &iter,
645 COL_ACCOUNT_POINTER, account,
650 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
652 EmpathyAccountsDialog *dialog)
656 account = mc_account_lookup (unique_name);
657 accounts_dialog_add_account (dialog, account);
658 g_object_unref (account);
662 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
664 EmpathyAccountsDialog *dialog)
668 account = mc_account_lookup (unique_name);
670 accounts_dialog_model_set_selected (dialog, account);
671 accounts_dialog_model_remove_selected (dialog);
673 g_object_unref (account);
677 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
682 gtk_tree_model_row_changed (model, path, iter);
688 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
693 dialog->connecting_show = !dialog->connecting_show;
695 view = GTK_TREE_VIEW (dialog->treeview);
696 model = gtk_tree_view_get_model (view);
698 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
704 accounts_dialog_status_changed_cb (MissionControl *mc,
705 TpConnectionStatus status,
707 TpConnectionStatusReason reason,
708 const gchar *unique_name,
709 EmpathyAccountsDialog *dialog)
712 GtkTreeSelection *selection;
718 gboolean found = FALSE;
720 /* Update the status in the model */
721 view = GTK_TREE_VIEW (dialog->treeview);
722 selection = gtk_tree_view_get_selection (view);
723 model = gtk_tree_view_get_model (view);
724 account = mc_account_lookup (unique_name);
726 empathy_debug (DEBUG_DOMAIN, "Status changed for account %s: "
727 "status=%d presence=%d",
728 unique_name, status, presence);
730 for (ok = gtk_tree_model_get_iter_first (model, &iter);
732 ok = gtk_tree_model_iter_next (model, &iter)) {
733 McAccount *this_account;
736 gtk_tree_model_get (model, &iter,
737 COL_ACCOUNT_POINTER, &this_account,
740 equal = empathy_account_equal (this_account, account);
741 g_object_unref (this_account);
746 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
750 path = gtk_tree_model_get_path (model, &iter);
751 gtk_tree_model_row_changed (model, path, &iter);
752 gtk_tree_path_free (path);
757 g_object_unref (account);
759 /* Check if there is still accounts in CONNECTING state */
760 accounts = mc_accounts_list ();
761 for (l = accounts; l; l = l->next) {
762 McAccount *this_account;
763 TpConnectionStatus status;
765 this_account = l->data;
767 status = mission_control_get_connection_status (mc, this_account, NULL);
768 if (status == TP_CONNECTION_STATUS_CONNECTING) {
773 g_object_unref (this_account);
775 g_list_free (accounts);
777 if (!found && dialog->connecting_id) {
778 g_source_remove (dialog->connecting_id);
779 dialog->connecting_id = 0;
781 if (found && !dialog->connecting_id) {
782 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
783 (GSourceFunc) accounts_dialog_flash_connecting_cb,
789 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
790 EmpathyAccountsDialog *dialog)
797 gtk_widget_show (dialog->vbox_details);
798 gtk_widget_hide (dialog->frame_no_account);
799 gtk_widget_hide (dialog->frame_new_account);
801 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
804 account = mc_account_create (profile);
806 str = mc_account_get_unique_name (account);
807 mc_account_set_display_name (account, str);
809 accounts_dialog_add_account (dialog, account);
810 accounts_dialog_model_set_selected (dialog, account);
812 g_object_unref (account);
813 g_object_unref (profile);
817 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
818 EmpathyAccountsDialog *dialog)
822 gtk_widget_hide (dialog->vbox_details);
823 gtk_widget_hide (dialog->frame_no_account);
824 gtk_widget_hide (dialog->frame_new_account);
826 gtk_widget_set_sensitive (dialog->button_add, TRUE);
828 account = accounts_dialog_model_get_selected (dialog);
829 accounts_dialog_update_account (dialog, account);
833 accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
834 EmpathyAccountsDialog *dialog)
839 account = accounts_dialog_model_get_selected (dialog);
840 enable = (!mc_account_is_enabled (account));
841 mc_account_set_enabled (account, enable);
842 accounts_dialog_update_connect_button (dialog);
844 g_object_unref (account);
848 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
849 EmpathyAccountsDialog *dialog)
852 GtkTreeSelection *selection;
854 view = GTK_TREE_VIEW (dialog->treeview);
855 selection = gtk_tree_view_get_selection (view);
856 gtk_tree_selection_unselect_all (selection);
858 gtk_widget_set_sensitive (dialog->button_add, FALSE);
859 gtk_widget_hide (dialog->vbox_details);
860 gtk_widget_hide (dialog->frame_no_account);
861 gtk_widget_show (dialog->frame_new_account);
863 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
864 gtk_widget_grab_focus (dialog->combobox_profile);
868 accounts_dialog_remove_response_cb (GtkWidget *dialog,
872 if (response == GTK_RESPONSE_YES) {
873 mc_account_delete (account);
876 gtk_widget_destroy (dialog);
880 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
881 EmpathyAccountsDialog *dialog)
884 GtkWidget *message_dialog;
886 account = accounts_dialog_model_get_selected (dialog);
888 if (!mc_account_is_complete (account)) {
889 accounts_dialog_model_remove_selected (dialog);
892 message_dialog = gtk_message_dialog_new
893 (GTK_WINDOW (dialog->window),
894 GTK_DIALOG_DESTROY_WITH_PARENT,
895 GTK_MESSAGE_QUESTION,
897 _("You are about to remove your %s account!\n"
898 "Are you sure you want to proceed?"),
899 mc_account_get_display_name (account));
901 gtk_message_dialog_format_secondary_text
902 (GTK_MESSAGE_DIALOG (message_dialog),
903 _("Any associated conversations and chat rooms will NOT be "
904 "removed if you decide to proceed.\n"
906 "Should you decide to add the account back at a later time, "
907 "they will still be available."));
909 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
912 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
916 g_signal_connect (message_dialog, "response",
917 G_CALLBACK (accounts_dialog_remove_response_cb),
920 gtk_widget_show (message_dialog);
924 accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
926 GtkTreeViewColumn *column,
927 EmpathyAccountsDialog *dialog)
930 accounts_dialog_button_connect_clicked_cb (dialog->button_connect,
935 accounts_dialog_response_cb (GtkWidget *widget,
937 EmpathyAccountsDialog *dialog)
939 gtk_widget_destroy (widget);
943 accounts_dialog_destroy_cb (GtkWidget *widget,
944 EmpathyAccountsDialog *dialog)
948 /* Disconnect signals */
949 g_signal_handlers_disconnect_by_func (dialog->monitor,
950 accounts_dialog_account_added_cb,
952 g_signal_handlers_disconnect_by_func (dialog->monitor,
953 accounts_dialog_account_removed_cb,
955 g_signal_handlers_disconnect_by_func (dialog->monitor,
956 accounts_dialog_update_connect_button,
958 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog->mc),
959 "AccountStatusChanged",
960 G_CALLBACK (accounts_dialog_status_changed_cb),
963 /* Delete incomplete accounts */
964 accounts = mc_accounts_list ();
965 for (l = accounts; l; l = l->next) {
969 if (!mc_account_is_complete (account)) {
970 /* FIXME: Warn the user the account is not complete
971 * and is going to be removed. */
972 mc_account_delete (account);
975 g_object_unref (account);
977 g_list_free (accounts);
979 if (dialog->connecting_id) {
980 g_source_remove (dialog->connecting_id);
983 g_object_unref (dialog->mc);
984 g_object_unref (dialog->monitor);
990 empathy_accounts_dialog_show (GtkWindow *parent)
992 static EmpathyAccountsDialog *dialog = NULL;
995 GtkWidget *button_close;
998 gtk_window_present (GTK_WINDOW (dialog->window));
999 return dialog->window;
1002 dialog = g_new0 (EmpathyAccountsDialog, 1);
1004 glade = empathy_glade_get_file ("empathy-accounts-dialog.glade",
1007 "accounts_dialog", &dialog->window,
1008 "vbox_details", &dialog->vbox_details,
1009 "frame_no_account", &dialog->frame_no_account,
1010 "label_no_account", &dialog->label_no_account,
1011 "label_no_account_blurb", &dialog->label_no_account_blurb,
1012 "alignment_settings", &dialog->alignment_settings,
1013 "dialog-action_area", &bbox,
1014 "treeview", &dialog->treeview,
1015 "frame_new_account", &dialog->frame_new_account,
1016 "hbox_type", &dialog->hbox_type,
1017 "button_create", &dialog->button_create,
1018 "button_back", &dialog->button_back,
1019 "image_type", &dialog->image_type,
1020 "label_name", &dialog->label_name,
1021 "button_add", &dialog->button_add,
1022 "button_remove", &dialog->button_remove,
1023 "button_connect", &dialog->button_connect,
1024 "button_close", &button_close,
1027 empathy_glade_connect (glade,
1029 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1030 "accounts_dialog", "response", accounts_dialog_response_cb,
1031 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1032 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1033 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
1034 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
1035 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1036 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1039 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1041 g_object_unref (glade);
1043 /* Create profile chooser */
1044 dialog->combobox_profile = empathy_profile_chooser_new ();
1045 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1046 dialog->combobox_profile,
1048 gtk_widget_show (dialog->combobox_profile);
1049 if (empathy_profile_chooser_n_profiles (dialog->combobox_profile) <= 0) {
1050 gtk_widget_set_sensitive (dialog->button_add, FALSE);
1053 /* Set up signalling */
1054 dialog->mc = empathy_mission_control_new ();
1055 dialog->monitor = mc_account_monitor_new ();
1057 g_signal_connect (dialog->monitor, "account-created",
1058 G_CALLBACK (accounts_dialog_account_added_cb),
1060 g_signal_connect (dialog->monitor, "account-deleted",
1061 G_CALLBACK (accounts_dialog_account_removed_cb),
1063 g_signal_connect_swapped (dialog->monitor, "account-enabled",
1064 G_CALLBACK (accounts_dialog_update_connect_button),
1066 g_signal_connect_swapped (dialog->monitor, "account-disabled",
1067 G_CALLBACK (accounts_dialog_update_connect_button),
1069 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog->mc), "AccountStatusChanged",
1070 G_CALLBACK (accounts_dialog_status_changed_cb),
1073 accounts_dialog_model_setup (dialog);
1074 accounts_dialog_setup (dialog);
1075 accounts_dialog_model_select_first (dialog);
1078 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1079 GTK_WINDOW (parent));
1082 gtk_widget_show (dialog->window);
1084 return dialog->window;