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 <libtelepathy/tp-constants.h>
41 #include <libempathy/empathy-debug.h>
42 #include <libempathy/empathy-utils.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include "empathy-accounts-dialog.h"
46 #include "empathy-profile-chooser.h"
47 #include "empathy-account-widget-generic.h"
48 #include "empathy-account-widget-jabber.h"
49 #include "empathy-account-widget-msn.h"
51 #define DEBUG_DOMAIN "AccountDialog"
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;
70 GtkWidget *button_connect;
72 GtkWidget *frame_new_account;
73 GtkWidget *combobox_profile;
75 GtkWidget *button_create;
76 GtkWidget *button_back;
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;
89 } 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_model_select_first (EmpathyAccountsDialog *dialog);
104 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
105 GtkCellRenderer *cell,
108 EmpathyAccountsDialog *dialog);
109 static McAccount *accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog);
110 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
112 static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
113 static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
114 EmpathyAccountsDialog *dialog);
115 static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
117 static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
119 EmpathyAccountsDialog *dialog);
120 static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
122 EmpathyAccountsDialog *dialog);
123 static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
127 static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
128 static void accounts_dialog_status_changed_cb (MissionControl *mc,
129 TelepathyConnectionStatus status,
131 TelepathyConnectionStatusReason reason,
132 const gchar *unique_name,
133 EmpathyAccountsDialog *dialog);
134 static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
135 EmpathyAccountsDialog *dialog);
136 static void accounts_dialog_button_back_clicked_cb (GtkWidget *button,
137 EmpathyAccountsDialog *dialog);
138 static void accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
139 EmpathyAccountsDialog *dialog);
140 static void accounts_dialog_button_add_clicked_cb (GtkWidget *button,
141 EmpathyAccountsDialog *dialog);
142 static void accounts_dialog_remove_response_cb (GtkWidget *dialog,
145 static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
146 EmpathyAccountsDialog *dialog);
147 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
149 GtkTreeViewColumn *column,
150 EmpathyAccountsDialog *dialog);
151 static void accounts_dialog_response_cb (GtkWidget *widget,
153 EmpathyAccountsDialog *dialog);
154 static void accounts_dialog_destroy_cb (GtkWidget *widget,
155 EmpathyAccountsDialog *dialog);
158 accounts_dialog_setup (EmpathyAccountsDialog *dialog)
165 view = GTK_TREE_VIEW (dialog->treeview);
166 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
168 accounts = mc_accounts_list ();
170 for (l = accounts; l; l = l->next) {
173 TelepathyConnectionStatus status;
177 name = mc_account_get_display_name (account);
182 status = mission_control_get_connection_status (dialog->mc, account, NULL);
184 gtk_list_store_insert_with_values (store, &iter,
188 COL_ACCOUNT_POINTER, account,
191 accounts_dialog_status_changed_cb (dialog->mc,
194 TP_CONN_STATUS_REASON_NONE_SPECIFIED,
195 mc_account_get_unique_name (account),
198 g_object_unref (account);
201 g_list_free (accounts);
205 accounts_dialog_update_connect_button (EmpathyAccountsDialog *dialog)
209 const gchar *stock_id;
212 account = accounts_dialog_model_get_selected (dialog);
214 gtk_widget_set_sensitive (dialog->button_connect, account != NULL);
216 if (account && mc_account_is_enabled (account)) {
217 label = _("Disable");
218 stock_id = GTK_STOCK_DISCONNECT;
221 stock_id = GTK_STOCK_CONNECT;
224 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
226 gtk_button_set_label (GTK_BUTTON (dialog->button_connect), label);
227 gtk_button_set_image (GTK_BUTTON (dialog->button_connect), image);
231 accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
234 if (dialog->settings_widget) {
235 gtk_widget_destroy (dialog->settings_widget);
236 dialog->settings_widget = NULL;
243 gtk_widget_show (dialog->frame_no_account);
244 gtk_widget_hide (dialog->vbox_details);
246 gtk_widget_set_sensitive (dialog->button_connect, FALSE);
247 gtk_widget_set_sensitive (dialog->button_remove, FALSE);
249 view = GTK_TREE_VIEW (dialog->treeview);
250 model = gtk_tree_view_get_model (view);
252 if (gtk_tree_model_iter_n_children (model, NULL) > 0) {
253 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
254 _("<b>No Account Selected</b>"));
255 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
256 _("To add a new account, you can click on the "
257 "'Add' button and a new entry will be created "
258 "for you to start configuring.\n"
260 "If you do not want to add an account, simply "
261 "click on the account you want to configure in "
262 "the list on the left."));
264 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account),
265 _("<b>No Accounts Configured</b>"));
266 gtk_label_set_markup (GTK_LABEL (dialog->label_no_account_blurb),
267 _("To add a new account, you can click on the "
268 "'Add' button and a new entry will be created "
269 "for you to start configuring."));
273 const gchar *config_ui;
275 gtk_widget_hide (dialog->frame_no_account);
276 gtk_widget_show (dialog->vbox_details);
278 profile = mc_account_get_profile (account);
279 config_ui = mc_profile_get_configuration_ui (profile);
280 g_object_unref (profile);
282 if (!empathy_strdiff (config_ui, "jabber")) {
283 dialog->settings_widget =
284 empathy_account_widget_jabber_new (account);
286 else if (!empathy_strdiff (config_ui, "msn")) {
287 dialog ->settings_widget =
288 empathy_account_widget_msn_new (account);
291 dialog->settings_widget =
292 empathy_account_widget_generic_new (account);
295 gtk_widget_grab_focus (dialog->settings_widget);
298 if (dialog->settings_widget) {
299 gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
300 dialog->settings_widget);
307 profile = mc_account_get_profile (account);
308 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
309 mc_profile_get_icon_name (profile),
310 GTK_ICON_SIZE_DIALOG);
311 /* FIXME: Uncomment once we depend on GTK+ 2.12
312 gtk_widget_set_tooltip_text (dialog->image_type,
313 mc_profile_get_display_name (profile));
316 text = g_strdup_printf ("<big><b>%s</b></big>", mc_account_get_display_name (account));
317 gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
323 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
326 GtkTreeSelection *selection;
328 store = gtk_list_store_new (COL_COUNT,
329 G_TYPE_STRING, /* name */
330 G_TYPE_UINT, /* status */
331 MC_TYPE_ACCOUNT); /* account */
333 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->treeview),
334 GTK_TREE_MODEL (store));
336 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->treeview));
337 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
339 g_signal_connect (selection, "changed",
340 G_CALLBACK (accounts_dialog_model_selection_changed),
343 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
344 COL_NAME, GTK_SORT_ASCENDING);
346 accounts_dialog_model_add_columns (dialog);
348 g_object_unref (store);
352 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
355 EmpathyAccountsDialog *dialog)
359 GtkTreePath *treepath;
362 model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
363 treepath = gtk_tree_path_new_from_string (path);
364 gtk_tree_model_get_iter (model, &iter, treepath);
365 gtk_tree_model_get (model, &iter,
366 COL_ACCOUNT_POINTER, &account,
368 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
371 gtk_tree_path_free (treepath);
373 mc_account_set_display_name (account, new_text);
374 g_object_unref (account);
378 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
381 GtkTreeViewColumn *column;
382 GtkCellRenderer *cell;
384 view = GTK_TREE_VIEW (dialog->treeview);
385 gtk_tree_view_set_headers_visible (view, TRUE);
387 /* account name/status */
388 column = gtk_tree_view_column_new ();
389 gtk_tree_view_column_set_title (column, _("Accounts"));
391 cell = gtk_cell_renderer_pixbuf_new ();
392 gtk_tree_view_column_pack_start (column, cell, FALSE);
393 gtk_tree_view_column_set_cell_data_func (column, cell,
394 (GtkTreeCellDataFunc)
395 accounts_dialog_model_pixbuf_data_func,
399 cell = gtk_cell_renderer_text_new ();
401 "ellipsize", PANGO_ELLIPSIZE_END,
404 gtk_tree_view_column_pack_start (column, cell, TRUE);
405 gtk_tree_view_column_add_attribute (column,
408 g_signal_connect (cell, "edited",
409 G_CALLBACK (accounts_dialog_name_edited_cb),
412 gtk_tree_view_column_set_expand (column, TRUE);
413 gtk_tree_view_append_column (view, column);
417 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
421 GtkTreeSelection *selection;
425 view = GTK_TREE_VIEW (dialog->treeview);
426 model = gtk_tree_view_get_model (view);
428 if (gtk_tree_model_get_iter_first (model, &iter)) {
429 selection = gtk_tree_view_get_selection (view);
430 gtk_tree_selection_select_iter (selection, &iter);
432 accounts_dialog_update_account (dialog, NULL);
437 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
438 GtkCellRenderer *cell,
441 EmpathyAccountsDialog *dialog)
444 const gchar *icon_name;
446 TelepathyConnectionStatus status;
448 gtk_tree_model_get (model, iter,
450 COL_ACCOUNT_POINTER, &account,
453 icon_name = empathy_icon_name_from_account (account);
454 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
457 if (status == TP_CONN_STATUS_DISCONNECTED ||
458 (status == TP_CONN_STATUS_CONNECTING &&
459 !dialog->connecting_show)) {
460 GdkPixbuf *modded_pixbuf;
462 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
465 gdk_pixbuf_get_width (pixbuf),
466 gdk_pixbuf_get_height (pixbuf));
468 gdk_pixbuf_saturate_and_pixelate (pixbuf,
472 g_object_unref (pixbuf);
473 pixbuf = modded_pixbuf;
482 g_object_unref (account);
484 g_object_unref (pixbuf);
489 accounts_dialog_model_get_selected (EmpathyAccountsDialog *dialog)
493 GtkTreeSelection *selection;
497 view = GTK_TREE_VIEW (dialog->treeview);
498 selection = gtk_tree_view_get_selection (view);
500 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
504 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
510 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
514 GtkTreeSelection *selection;
519 view = GTK_TREE_VIEW (dialog->treeview);
520 model = gtk_tree_view_get_model (view);
521 selection = gtk_tree_view_get_selection (view);
523 for (ok = gtk_tree_model_get_iter_first (model, &iter);
525 ok = gtk_tree_model_iter_next (model, &iter)) {
526 McAccount *this_account;
529 gtk_tree_model_get (model, &iter,
530 COL_ACCOUNT_POINTER, &this_account,
533 equal = empathy_account_equal (this_account, account);
534 g_object_unref (this_account);
537 gtk_tree_selection_select_iter (selection, &iter);
544 accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog)
548 GtkTreeSelection *selection;
551 view = GTK_TREE_VIEW (dialog->treeview);
552 selection = gtk_tree_view_get_selection (view);
554 if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
558 return gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
562 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
563 EmpathyAccountsDialog *dialog)
568 gboolean is_selection;
570 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
572 gtk_widget_set_sensitive (dialog->button_add, TRUE);
573 gtk_widget_set_sensitive (dialog->button_remove, is_selection);
574 gtk_widget_set_sensitive (dialog->button_connect, is_selection);
576 accounts_dialog_update_connect_button (dialog);
578 account = accounts_dialog_model_get_selected (dialog);
579 accounts_dialog_update_account (dialog, account);
582 g_object_unref (account);
585 /* insure new account frame is hidden when a row is selected*/
586 gtk_widget_hide (dialog->frame_new_account);
590 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
593 TelepathyConnectionStatus status;
601 view = GTK_TREE_VIEW (dialog->treeview);
602 model = gtk_tree_view_get_model (view);
603 store = GTK_LIST_STORE (model);
605 for (ok = gtk_tree_model_get_iter_first (model, &iter);
607 ok = gtk_tree_model_iter_next (model, &iter)) {
608 McAccount *this_account;
611 gtk_tree_model_get (model, &iter,
612 COL_ACCOUNT_POINTER, &this_account,
615 equal = empathy_account_equal (this_account, account);
616 g_object_unref (this_account);
623 status = mission_control_get_connection_status (dialog->mc, account, NULL);
624 name = mc_account_get_display_name (account);
626 g_return_if_fail (name != NULL);
628 empathy_debug (DEBUG_DOMAIN, "Adding new account: %s", name);
630 gtk_list_store_insert_with_values (store, &iter,
634 COL_ACCOUNT_POINTER, account,
639 accounts_dialog_account_added_cb (McAccountMonitor *monitor,
641 EmpathyAccountsDialog *dialog)
645 account = mc_account_lookup (unique_name);
646 accounts_dialog_add_account (dialog, account);
647 g_object_unref (account);
651 accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
653 EmpathyAccountsDialog *dialog)
657 account = mc_account_lookup (unique_name);
659 accounts_dialog_model_set_selected (dialog, account);
660 accounts_dialog_model_remove_selected (dialog);
662 g_object_unref (account);
666 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
671 gtk_tree_model_row_changed (model, path, iter);
677 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
682 dialog->connecting_show = !dialog->connecting_show;
684 view = GTK_TREE_VIEW (dialog->treeview);
685 model = gtk_tree_view_get_model (view);
687 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
693 accounts_dialog_status_changed_cb (MissionControl *mc,
694 TelepathyConnectionStatus status,
696 TelepathyConnectionStatusReason reason,
697 const gchar *unique_name,
698 EmpathyAccountsDialog *dialog)
701 GtkTreeSelection *selection;
707 gboolean found = FALSE;
709 /* Update the status in the model */
710 view = GTK_TREE_VIEW (dialog->treeview);
711 selection = gtk_tree_view_get_selection (view);
712 model = gtk_tree_view_get_model (view);
713 account = mc_account_lookup (unique_name);
715 empathy_debug (DEBUG_DOMAIN, "Status changed for account %s: "
716 "status=%d presence=%d",
717 unique_name, status, presence);
719 for (ok = gtk_tree_model_get_iter_first (model, &iter);
721 ok = gtk_tree_model_iter_next (model, &iter)) {
722 McAccount *this_account;
725 gtk_tree_model_get (model, &iter,
726 COL_ACCOUNT_POINTER, &this_account,
729 equal = empathy_account_equal (this_account, account);
730 g_object_unref (this_account);
735 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
739 path = gtk_tree_model_get_path (model, &iter);
740 gtk_tree_model_row_changed (model, path, &iter);
741 gtk_tree_path_free (path);
747 g_object_unref (account);
749 /* Start to flash account if status is connecting */
750 if (status == TP_CONN_STATUS_CONNECTING) {
751 if (!dialog->connecting_id) {
752 dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
753 (GSourceFunc) accounts_dialog_flash_connecting_cb,
760 /* Stop to flash if no account is connecting */
761 accounts = mc_accounts_list ();
762 for (l = accounts; l; l = l->next) {
763 McAccount *this_account;
765 this_account = l->data;
767 if (mission_control_get_connection_status (mc, this_account, NULL) == TP_CONN_STATUS_CONNECTING) {
772 g_object_unref (this_account);
774 g_list_free (accounts);
776 if (!found && dialog->connecting_id) {
777 g_source_remove (dialog->connecting_id);
778 dialog->connecting_id = 0;
781 gtk_widget_show (dialog->window);
785 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
786 EmpathyAccountsDialog *dialog)
793 gtk_widget_show (dialog->vbox_details);
794 gtk_widget_hide (dialog->frame_no_account);
795 gtk_widget_hide (dialog->frame_new_account);
797 profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
800 account = mc_account_create (profile);
802 str = mc_account_get_unique_name (account);
803 mc_account_set_display_name (account, str);
805 accounts_dialog_add_account (dialog, account);
806 accounts_dialog_model_set_selected (dialog, account);
808 g_object_unref (account);
809 g_object_unref (profile);
813 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
814 EmpathyAccountsDialog *dialog)
818 gtk_widget_hide (dialog->vbox_details);
819 gtk_widget_hide (dialog->frame_no_account);
820 gtk_widget_hide (dialog->frame_new_account);
822 gtk_widget_set_sensitive (dialog->button_add, TRUE);
824 account = accounts_dialog_model_get_selected (dialog);
825 accounts_dialog_update_account (dialog, account);
829 accounts_dialog_button_connect_clicked_cb (GtkWidget *button,
830 EmpathyAccountsDialog *dialog)
835 account = accounts_dialog_model_get_selected (dialog);
836 enable = (!mc_account_is_enabled (account));
837 mc_account_set_enabled (account, enable);
838 accounts_dialog_update_connect_button (dialog);
840 g_object_unref (account);
844 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
845 EmpathyAccountsDialog *dialog)
848 GtkTreeSelection *selection;
850 view = GTK_TREE_VIEW (dialog->treeview);
851 selection = gtk_tree_view_get_selection (view);
852 gtk_tree_selection_unselect_all (selection);
854 gtk_widget_set_sensitive (dialog->button_add, FALSE);
855 gtk_widget_hide (dialog->vbox_details);
856 gtk_widget_hide (dialog->frame_no_account);
857 gtk_widget_show (dialog->frame_new_account);
859 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->combobox_profile), 0);
860 gtk_widget_grab_focus (dialog->combobox_profile);
864 accounts_dialog_remove_response_cb (GtkWidget *dialog,
868 if (response == GTK_RESPONSE_YES) {
869 mc_account_delete (account);
872 gtk_widget_destroy (dialog);
876 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
877 EmpathyAccountsDialog *dialog)
880 GtkWidget *message_dialog;
882 account = accounts_dialog_model_get_selected (dialog);
884 if (!mc_account_is_complete (account)) {
885 accounts_dialog_model_remove_selected (dialog);
888 message_dialog = gtk_message_dialog_new
889 (GTK_WINDOW (dialog->window),
890 GTK_DIALOG_DESTROY_WITH_PARENT,
891 GTK_MESSAGE_QUESTION,
893 _("You are about to remove your %s account!\n"
894 "Are you sure you want to proceed?"),
895 mc_account_get_display_name (account));
897 gtk_message_dialog_format_secondary_text
898 (GTK_MESSAGE_DIALOG (message_dialog),
899 _("Any associated conversations and chat rooms will NOT be "
900 "removed if you decide to proceed.\n"
902 "Should you decide to add the account back at a later time, "
903 "they will still be available."));
905 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
908 gtk_dialog_add_button (GTK_DIALOG (message_dialog),
912 g_signal_connect (message_dialog, "response",
913 G_CALLBACK (accounts_dialog_remove_response_cb),
916 gtk_widget_show (message_dialog);
920 accounts_dialog_treeview_row_activated_cb (GtkTreeView *tree_view,
922 GtkTreeViewColumn *column,
923 EmpathyAccountsDialog *dialog)
926 accounts_dialog_button_connect_clicked_cb (dialog->button_connect,
931 accounts_dialog_response_cb (GtkWidget *widget,
933 EmpathyAccountsDialog *dialog)
935 gtk_widget_destroy (widget);
939 accounts_dialog_destroy_cb (GtkWidget *widget,
940 EmpathyAccountsDialog *dialog)
944 /* Disconnect signals */
945 g_signal_handlers_disconnect_by_func (dialog->monitor,
946 accounts_dialog_account_added_cb,
948 g_signal_handlers_disconnect_by_func (dialog->monitor,
949 accounts_dialog_account_removed_cb,
951 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog->mc),
952 "AccountStatusChanged",
953 G_CALLBACK (accounts_dialog_status_changed_cb),
956 /* Delete incomplete accounts */
957 accounts = mc_accounts_list ();
958 for (l = accounts; l; l = l->next) {
962 if (!mc_account_is_complete (account)) {
963 /* FIXME: Warn the user the account is not complete
964 * and is going to be removed. */
965 mc_account_delete (account);
968 g_object_unref (account);
970 g_list_free (accounts);
972 if (dialog->connecting_id) {
973 g_source_remove (dialog->connecting_id);
976 g_object_unref (dialog->mc);
977 g_object_unref (dialog->monitor);
983 empathy_accounts_dialog_show (GtkWindow *parent)
985 static EmpathyAccountsDialog *dialog = NULL;
988 GtkWidget *button_close;
991 gtk_window_present (GTK_WINDOW (dialog->window));
992 return dialog->window;
995 dialog = g_new0 (EmpathyAccountsDialog, 1);
997 glade = empathy_glade_get_file ("empathy-accounts-dialog.glade",
1000 "accounts_dialog", &dialog->window,
1001 "vbox_details", &dialog->vbox_details,
1002 "frame_no_account", &dialog->frame_no_account,
1003 "label_no_account", &dialog->label_no_account,
1004 "label_no_account_blurb", &dialog->label_no_account_blurb,
1005 "alignment_settings", &dialog->alignment_settings,
1006 "dialog-action_area", &bbox,
1007 "treeview", &dialog->treeview,
1008 "frame_new_account", &dialog->frame_new_account,
1009 "hbox_type", &dialog->hbox_type,
1010 "button_create", &dialog->button_create,
1011 "button_back", &dialog->button_back,
1012 "image_type", &dialog->image_type,
1013 "label_name", &dialog->label_name,
1014 "button_add", &dialog->button_add,
1015 "button_remove", &dialog->button_remove,
1016 "button_connect", &dialog->button_connect,
1017 "button_close", &button_close,
1020 empathy_glade_connect (glade,
1022 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1023 "accounts_dialog", "response", accounts_dialog_response_cb,
1024 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1025 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1026 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb,
1027 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb,
1028 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1029 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1032 g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
1034 g_object_unref (glade);
1036 /* Create profile chooser */
1037 dialog->combobox_profile = empathy_profile_chooser_new ();
1038 gtk_box_pack_end (GTK_BOX (dialog->hbox_type),
1039 dialog->combobox_profile,
1041 gtk_widget_show (dialog->combobox_profile);
1043 /* Set up signalling */
1044 dialog->mc = empathy_mission_control_new ();
1045 dialog->monitor = mc_account_monitor_new ();
1047 /* FIXME: connect account-enabled/disabled too */
1048 g_signal_connect (dialog->monitor, "account-created",
1049 G_CALLBACK (accounts_dialog_account_added_cb),
1051 g_signal_connect (dialog->monitor, "account-deleted",
1052 G_CALLBACK (accounts_dialog_account_removed_cb),
1054 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog->mc), "AccountStatusChanged",
1055 G_CALLBACK (accounts_dialog_status_changed_cb),
1058 accounts_dialog_model_setup (dialog);
1059 accounts_dialog_setup (dialog);
1060 accounts_dialog_model_select_first (dialog);
1063 gtk_window_set_transient_for (GTK_WINDOW (dialog->window),
1064 GTK_WINDOW (parent));
1067 gtk_widget_show (dialog->window);
1069 return dialog->window;