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/gossip-debug.h>
42 #include <libempathy/gossip-utils.h>
43 #include <libempathy-gtk/gossip-ui-utils.h>
45 #include "gossip-accounts-dialog.h"
46 #include "gossip-profile-chooser.h"
47 #include "gossip-account-widget-generic.h"
48 #include "gossip-account-widget-jabber.h"
50 #define DEBUG_DOMAIN "AccountDialog"
52 /* Flashing delay for icons (milliseconds). */
53 #define FLASH_TIMEOUT 500
58 GtkWidget
*alignment_settings
;
60 GtkWidget
*vbox_details
;
61 GtkWidget
*frame_no_account
;
62 GtkWidget
*label_no_account
;
63 GtkWidget
*label_no_account_blurb
;
67 GtkWidget
*button_remove
;
68 GtkWidget
*button_connect
;
70 GtkWidget
*frame_new_account
;
71 GtkWidget
*combobox_profile
;
72 GtkWidget
*entry_name
;
73 GtkWidget
*table_new_account
;
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
;
88 } GossipAccountsDialog
;
97 static void accounts_dialog_setup (GossipAccountsDialog
*dialog
);
98 static void accounts_dialog_update_account (GossipAccountsDialog
*dialog
,
100 static void accounts_dialog_model_setup (GossipAccountsDialog
*dialog
);
101 static void accounts_dialog_model_add_columns (GossipAccountsDialog
*dialog
);
102 static void accounts_dialog_model_select_first (GossipAccountsDialog
*dialog
);
103 static void accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn
*tree_column
,
104 GtkCellRenderer
*cell
,
107 GossipAccountsDialog
*dialog
);
108 static McAccount
*accounts_dialog_model_get_selected (GossipAccountsDialog
*dialog
);
109 static void accounts_dialog_model_set_selected (GossipAccountsDialog
*dialog
,
111 static gboolean
accounts_dialog_model_remove_selected (GossipAccountsDialog
*dialog
);
112 static void accounts_dialog_model_selection_changed (GtkTreeSelection
*selection
,
113 GossipAccountsDialog
*dialog
);
114 static void accounts_dialog_add_account (GossipAccountsDialog
*dialog
,
116 static void accounts_dialog_account_added_cb (McAccountMonitor
*monitor
,
118 GossipAccountsDialog
*dialog
);
119 static void accounts_dialog_account_removed_cb (McAccountMonitor
*monitor
,
121 GossipAccountsDialog
*dialog
);
122 static gboolean
accounts_dialog_row_changed_foreach (GtkTreeModel
*model
,
126 static gboolean
accounts_dialog_flash_connecting_cb (GossipAccountsDialog
*dialog
);
127 static void accounts_dialog_status_changed_cb (MissionControl
*mc
,
128 TelepathyConnectionStatus status
,
130 TelepathyConnectionStatusReason reason
,
131 const gchar
*unique_name
,
132 GossipAccountsDialog
*dialog
);
133 static void accounts_dialog_entry_name_changed_cb (GtkWidget
*widget
,
134 GossipAccountsDialog
*dialog
);
135 static void accounts_dialog_button_create_clicked_cb (GtkWidget
*button
,
136 GossipAccountsDialog
*dialog
);
137 static void accounts_dialog_button_back_clicked_cb (GtkWidget
*button
,
138 GossipAccountsDialog
*dialog
);
139 static void accounts_dialog_button_connect_clicked_cb (GtkWidget
*button
,
140 GossipAccountsDialog
*dialog
);
141 static void accounts_dialog_button_add_clicked_cb (GtkWidget
*button
,
142 GossipAccountsDialog
*dialog
);
143 static void accounts_dialog_remove_response_cb (GtkWidget
*dialog
,
146 static void accounts_dialog_button_remove_clicked_cb (GtkWidget
*button
,
147 GossipAccountsDialog
*dialog
);
148 static void accounts_dialog_treeview_row_activated_cb (GtkTreeView
*tree_view
,
150 GtkTreeViewColumn
*column
,
151 GossipAccountsDialog
*dialog
);
152 static void accounts_dialog_response_cb (GtkWidget
*widget
,
154 GossipAccountsDialog
*dialog
);
155 static void accounts_dialog_destroy_cb (GtkWidget
*widget
,
156 GossipAccountsDialog
*dialog
);
159 accounts_dialog_setup (GossipAccountsDialog
*dialog
)
163 GtkTreeSelection
*selection
;
167 view
= GTK_TREE_VIEW (dialog
->treeview
);
168 store
= GTK_LIST_STORE (gtk_tree_view_get_model (view
));
169 selection
= gtk_tree_view_get_selection (view
);
171 accounts
= mc_accounts_list ();
173 for (l
= accounts
; l
; l
= l
->next
) {
176 TelepathyConnectionStatus status
;
180 name
= mc_account_get_display_name (account
);
185 status
= mission_control_get_connection_status (dialog
->mc
, account
, NULL
);
187 gtk_list_store_insert_with_values (store
, &iter
,
191 COL_ACCOUNT_POINTER
, account
,
194 accounts_dialog_status_changed_cb (dialog
->mc
,
197 TP_CONN_STATUS_REASON_NONE_SPECIFIED
,
198 mc_account_get_unique_name (account
),
201 g_object_unref (account
);
204 g_list_free (accounts
);
208 accounts_dialog_update_connect_button (GossipAccountsDialog
*dialog
)
212 const gchar
*stock_id
;
215 account
= accounts_dialog_model_get_selected (dialog
);
218 gtk_widget_set_sensitive (dialog
->button_connect
, FALSE
);
222 if (mc_account_is_enabled (account
)) {
223 label
= _("Disable");
224 stock_id
= GTK_STOCK_DISCONNECT
;
227 stock_id
= GTK_STOCK_CONNECT
;
230 image
= gtk_image_new_from_stock (stock_id
, GTK_ICON_SIZE_BUTTON
);
232 gtk_button_set_label (GTK_BUTTON (dialog
->button_connect
), label
);
233 gtk_button_set_image (GTK_BUTTON (dialog
->button_connect
), image
);
237 accounts_dialog_update_account (GossipAccountsDialog
*dialog
,
240 if (dialog
->settings_widget
) {
241 gtk_widget_destroy (dialog
->settings_widget
);
242 dialog
->settings_widget
= NULL
;
249 gtk_widget_show (dialog
->frame_no_account
);
250 gtk_widget_hide (dialog
->vbox_details
);
252 gtk_widget_set_sensitive (dialog
->button_connect
, FALSE
);
253 gtk_widget_set_sensitive (dialog
->button_remove
, FALSE
);
255 view
= GTK_TREE_VIEW (dialog
->treeview
);
256 model
= gtk_tree_view_get_model (view
);
258 if (gtk_tree_model_iter_n_children (model
, NULL
) > 0) {
259 gtk_label_set_markup (GTK_LABEL (dialog
->label_no_account
),
260 _("<b>No Account Selected</b>"));
261 gtk_label_set_markup (GTK_LABEL (dialog
->label_no_account_blurb
),
262 _("To add a new account, you can click on the "
263 "'Add' button and a new entry will be created "
264 "for you to start configuring.\n"
266 "If you do not want to add an account, simply "
267 "click on the account you want to configure in "
268 "the list on the left."));
270 gtk_label_set_markup (GTK_LABEL (dialog
->label_no_account
),
271 _("<b>No Accounts Configured</b>"));
272 gtk_label_set_markup (GTK_LABEL (dialog
->label_no_account_blurb
),
273 _("To add a new account, you can click on the "
274 "'Add' button and a new entry will be created "
275 "for you to start configuring."));
279 const gchar
*config_ui
;
281 gtk_widget_hide (dialog
->frame_no_account
);
282 gtk_widget_show (dialog
->vbox_details
);
284 profile
= mc_account_get_profile (account
);
285 config_ui
= mc_profile_get_configuration_ui (profile
);
287 if (strcmp (config_ui
, "jabber") == 0) {
288 dialog
->settings_widget
=
289 gossip_account_widget_jabber_new (account
);
291 dialog
->settings_widget
=
292 gossip_account_widget_generic_new (account
,
296 gtk_widget_grab_focus (dialog
->settings_widget
);
299 if (dialog
->settings_widget
) {
300 gtk_container_add (GTK_CONTAINER (dialog
->alignment_settings
),
301 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
);
313 gtk_label_set_text (GTK_LABEL (dialog
->label_type
),
314 mc_profile_get_display_name (profile
));
315 gtk_label_set_text (GTK_LABEL (dialog
->label_name
),
316 mc_account_get_display_name (account
));
321 accounts_dialog_model_setup (GossipAccountsDialog
*dialog
)
324 GtkTreeSelection
*selection
;
326 store
= gtk_list_store_new (COL_COUNT
,
327 G_TYPE_STRING
, /* name */
328 G_TYPE_UINT
, /* status */
329 MC_TYPE_ACCOUNT
); /* account */
331 gtk_tree_view_set_model (GTK_TREE_VIEW (dialog
->treeview
),
332 GTK_TREE_MODEL (store
));
334 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog
->treeview
));
335 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_SINGLE
);
337 g_signal_connect (selection
, "changed",
338 G_CALLBACK (accounts_dialog_model_selection_changed
),
341 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
342 COL_NAME
, GTK_SORT_ASCENDING
);
344 accounts_dialog_model_add_columns (dialog
);
346 g_object_unref (store
);
350 accounts_dialog_model_add_columns (GossipAccountsDialog
*dialog
)
353 GtkTreeViewColumn
*column
;
354 GtkCellRenderer
*cell
;
356 view
= GTK_TREE_VIEW (dialog
->treeview
);
357 gtk_tree_view_set_headers_visible (view
, TRUE
);
359 /* account name/status */
360 column
= gtk_tree_view_column_new ();
361 gtk_tree_view_column_set_title (column
, _("Accounts"));
363 cell
= gtk_cell_renderer_pixbuf_new ();
364 gtk_tree_view_column_pack_start (column
, cell
, FALSE
);
365 gtk_tree_view_column_set_cell_data_func (column
, cell
,
366 (GtkTreeCellDataFunc
)
367 accounts_dialog_model_pixbuf_data_func
,
371 cell
= gtk_cell_renderer_text_new ();
372 g_object_set (cell
, "ellipsize", PANGO_ELLIPSIZE_END
, NULL
);
373 gtk_tree_view_column_pack_start (column
, cell
, TRUE
);
374 gtk_tree_view_column_add_attribute (column
,
378 gtk_tree_view_column_set_expand (column
, TRUE
);
379 gtk_tree_view_append_column (view
, column
);
383 accounts_dialog_model_select_first (GossipAccountsDialog
*dialog
)
387 GtkTreeSelection
*selection
;
391 view
= GTK_TREE_VIEW (dialog
->treeview
);
392 model
= gtk_tree_view_get_model (view
);
394 if (gtk_tree_model_get_iter_first (model
, &iter
)) {
395 selection
= gtk_tree_view_get_selection (view
);
396 gtk_tree_selection_select_iter (selection
, &iter
);
398 accounts_dialog_update_account (dialog
, NULL
);
403 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn
*tree_column
,
404 GtkCellRenderer
*cell
,
407 GossipAccountsDialog
*dialog
)
410 const gchar
*icon_name
;
412 TelepathyConnectionStatus status
;
414 gtk_tree_model_get (model
, iter
,
416 COL_ACCOUNT_POINTER
, &account
,
419 icon_name
= gossip_icon_name_from_account (account
);
420 pixbuf
= gossip_pixbuf_from_icon_name (icon_name
, GTK_ICON_SIZE_BUTTON
);
423 if (status
== TP_CONN_STATUS_DISCONNECTED
||
424 (status
== TP_CONN_STATUS_CONNECTING
&&
425 !dialog
->connecting_show
)) {
426 GdkPixbuf
*modded_pixbuf
;
428 modded_pixbuf
= gdk_pixbuf_new (GDK_COLORSPACE_RGB
,
431 gdk_pixbuf_get_width (pixbuf
),
432 gdk_pixbuf_get_height (pixbuf
));
434 gdk_pixbuf_saturate_and_pixelate (pixbuf
,
438 g_object_unref (pixbuf
);
439 pixbuf
= modded_pixbuf
;
448 g_object_unref (account
);
450 g_object_unref (pixbuf
);
455 accounts_dialog_model_get_selected (GossipAccountsDialog
*dialog
)
459 GtkTreeSelection
*selection
;
463 view
= GTK_TREE_VIEW (dialog
->treeview
);
464 selection
= gtk_tree_view_get_selection (view
);
466 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
)) {
470 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT_POINTER
, &account
, -1);
476 accounts_dialog_model_set_selected (GossipAccountsDialog
*dialog
,
480 GtkTreeSelection
*selection
;
485 view
= GTK_TREE_VIEW (dialog
->treeview
);
486 model
= gtk_tree_view_get_model (view
);
487 selection
= gtk_tree_view_get_selection (view
);
489 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
491 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
492 McAccount
*this_account
;
495 gtk_tree_model_get (model
, &iter
,
496 COL_ACCOUNT_POINTER
, &this_account
,
499 equal
= gossip_account_equal (this_account
, account
);
500 g_object_unref (this_account
);
503 gtk_tree_selection_select_iter (selection
, &iter
);
510 accounts_dialog_model_remove_selected (GossipAccountsDialog
*dialog
)
514 GtkTreeSelection
*selection
;
517 view
= GTK_TREE_VIEW (dialog
->treeview
);
518 selection
= gtk_tree_view_get_selection (view
);
520 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
)) {
524 return gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
528 accounts_dialog_model_selection_changed (GtkTreeSelection
*selection
,
529 GossipAccountsDialog
*dialog
)
534 gboolean is_selection
;
536 is_selection
= gtk_tree_selection_get_selected (selection
, &model
, &iter
);
538 gtk_widget_set_sensitive (dialog
->button_remove
, is_selection
);
539 gtk_widget_set_sensitive (dialog
->button_connect
, is_selection
);
541 accounts_dialog_update_connect_button (dialog
);
543 account
= accounts_dialog_model_get_selected (dialog
);
544 accounts_dialog_update_account (dialog
, account
);
547 g_object_unref (account
);
552 accounts_dialog_add_account (GossipAccountsDialog
*dialog
,
555 TelepathyConnectionStatus status
;
563 view
= GTK_TREE_VIEW (dialog
->treeview
);
564 model
= gtk_tree_view_get_model (view
);
565 store
= GTK_LIST_STORE (model
);
567 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
569 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
570 McAccount
*this_account
;
573 gtk_tree_model_get (model
, &iter
,
574 COL_ACCOUNT_POINTER
, &this_account
,
577 equal
= gossip_account_equal (this_account
, account
);
578 g_object_unref (this_account
);
585 status
= mission_control_get_connection_status (dialog
->mc
, account
, NULL
);
586 name
= mc_account_get_display_name (account
);
588 g_return_if_fail (name
!= NULL
);
590 gossip_debug (DEBUG_DOMAIN
, "Adding new account: %s", name
);
592 gtk_list_store_insert_with_values (store
, &iter
,
596 COL_ACCOUNT_POINTER
, account
,
601 accounts_dialog_account_added_cb (McAccountMonitor
*monitor
,
603 GossipAccountsDialog
*dialog
)
607 account
= mc_account_lookup (unique_name
);
608 accounts_dialog_add_account (dialog
, account
);
609 g_object_unref (account
);
613 accounts_dialog_account_removed_cb (McAccountMonitor
*monitor
,
615 GossipAccountsDialog
*dialog
)
619 account
= mc_account_lookup (unique_name
);
621 accounts_dialog_model_set_selected (dialog
, account
);
622 accounts_dialog_model_remove_selected (dialog
);
624 g_object_unref (account
);
628 accounts_dialog_row_changed_foreach (GtkTreeModel
*model
,
633 gtk_tree_model_row_changed (model
, path
, iter
);
639 accounts_dialog_flash_connecting_cb (GossipAccountsDialog
*dialog
)
644 dialog
->connecting_show
= !dialog
->connecting_show
;
646 view
= GTK_TREE_VIEW (dialog
->treeview
);
647 model
= gtk_tree_view_get_model (view
);
649 gtk_tree_model_foreach (model
, accounts_dialog_row_changed_foreach
, NULL
);
655 accounts_dialog_status_changed_cb (MissionControl
*mc
,
656 TelepathyConnectionStatus status
,
658 TelepathyConnectionStatusReason reason
,
659 const gchar
*unique_name
,
660 GossipAccountsDialog
*dialog
)
663 GtkTreeSelection
*selection
;
669 gboolean found
= FALSE
;
671 /* Update the status in the model */
672 view
= GTK_TREE_VIEW (dialog
->treeview
);
673 selection
= gtk_tree_view_get_selection (view
);
674 model
= gtk_tree_view_get_model (view
);
675 account
= mc_account_lookup (unique_name
);
677 gossip_debug (DEBUG_DOMAIN
, "Status changed for account %s: "
678 "status=%d presence=%d",
679 unique_name
, status
, presence
);
681 for (ok
= gtk_tree_model_get_iter_first (model
, &iter
);
683 ok
= gtk_tree_model_iter_next (model
, &iter
)) {
684 McAccount
*this_account
;
687 gtk_tree_model_get (model
, &iter
,
688 COL_ACCOUNT_POINTER
, &this_account
,
691 equal
= gossip_account_equal (this_account
, account
);
692 g_object_unref (this_account
);
697 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
701 path
= gtk_tree_model_get_path (model
, &iter
);
702 gtk_tree_model_row_changed (model
, path
, &iter
);
703 gtk_tree_path_free (path
);
709 g_object_unref (account
);
711 /* Start to flash account if status is connecting */
712 if (status
== TP_CONN_STATUS_CONNECTING
) {
713 if (!dialog
->connecting_id
) {
714 dialog
->connecting_id
= g_timeout_add (FLASH_TIMEOUT
,
715 (GSourceFunc
) accounts_dialog_flash_connecting_cb
,
722 /* Stop to flash if no account is connecting */
723 accounts
= mc_accounts_list ();
724 for (l
= accounts
; l
; l
= l
->next
) {
725 McAccount
*this_account
;
727 this_account
= l
->data
;
729 if (mission_control_get_connection_status (mc
, this_account
, NULL
) == TP_CONN_STATUS_CONNECTING
) {
734 g_object_unref (this_account
);
736 g_list_free (accounts
);
738 if (!found
&& dialog
->connecting_id
) {
739 g_source_remove (dialog
->connecting_id
);
740 dialog
->connecting_id
= 0;
743 gtk_widget_show (dialog
->window
);
747 accounts_dialog_entry_name_changed_cb (GtkWidget
*widget
,
748 GossipAccountsDialog
*dialog
)
752 str
= gtk_entry_get_text (GTK_ENTRY (widget
));
753 gtk_widget_set_sensitive (dialog
->button_create
, !G_STR_EMPTY (str
));
757 accounts_dialog_button_create_clicked_cb (GtkWidget
*button
,
758 GossipAccountsDialog
*dialog
)
765 gtk_widget_show (dialog
->vbox_details
);
766 gtk_widget_hide (dialog
->frame_no_account
);
767 gtk_widget_hide (dialog
->frame_new_account
);
769 profile
= gossip_profile_chooser_get_selected (dialog
->combobox_profile
);
772 account
= mc_account_create (profile
);
774 str
= gtk_entry_get_text (GTK_ENTRY (dialog
->entry_name
));
775 mc_account_set_display_name (account
, str
);
777 accounts_dialog_add_account (dialog
, account
);
778 accounts_dialog_model_set_selected (dialog
, account
);
780 g_object_unref (account
);
781 g_object_unref (profile
);
785 accounts_dialog_button_back_clicked_cb (GtkWidget
*button
,
786 GossipAccountsDialog
*dialog
)
790 gtk_widget_hide (dialog
->vbox_details
);
791 gtk_widget_hide (dialog
->frame_no_account
);
792 gtk_widget_hide (dialog
->frame_new_account
);
794 account
= accounts_dialog_model_get_selected (dialog
);
795 accounts_dialog_update_account (dialog
, account
);
799 accounts_dialog_button_connect_clicked_cb (GtkWidget
*button
,
800 GossipAccountsDialog
*dialog
)
805 account
= accounts_dialog_model_get_selected (dialog
);
806 enable
= (!mc_account_is_enabled (account
));
807 mc_account_set_enabled (account
, enable
);
808 accounts_dialog_update_connect_button (dialog
);
810 g_object_unref (account
);
814 accounts_dialog_button_add_clicked_cb (GtkWidget
*button
,
815 GossipAccountsDialog
*dialog
)
817 gtk_widget_hide (dialog
->vbox_details
);
818 gtk_widget_hide (dialog
->frame_no_account
);
819 gtk_widget_show (dialog
->frame_new_account
);
821 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->combobox_profile
), 0);
822 gtk_entry_set_text (GTK_ENTRY (dialog
->entry_name
), "");
823 gtk_widget_grab_focus (dialog
->entry_name
);
827 accounts_dialog_remove_response_cb (GtkWidget
*dialog
,
831 if (response
== GTK_RESPONSE_YES
) {
832 mc_account_delete (account
);
835 gtk_widget_destroy (dialog
);
839 accounts_dialog_button_remove_clicked_cb (GtkWidget
*button
,
840 GossipAccountsDialog
*dialog
)
843 GtkWidget
*message_dialog
;
845 account
= accounts_dialog_model_get_selected (dialog
);
847 if (!mc_account_is_complete (account
)) {
848 accounts_dialog_model_remove_selected (dialog
);
851 message_dialog
= gtk_message_dialog_new
852 (GTK_WINDOW (dialog
->window
),
853 GTK_DIALOG_DESTROY_WITH_PARENT
,
854 GTK_MESSAGE_QUESTION
,
856 _("You are about to remove your %s account!\n"
857 "Are you sure you want to proceed?"),
858 mc_account_get_display_name (account
));
860 gtk_message_dialog_format_secondary_text
861 (GTK_MESSAGE_DIALOG (message_dialog
),
862 _("Any associated conversations and chat rooms will NOT be "
863 "removed if you decide to proceed.\n"
865 "Should you decide to add the account back at a later time, "
866 "they will still be available."));
868 gtk_dialog_add_button (GTK_DIALOG (message_dialog
),
871 gtk_dialog_add_button (GTK_DIALOG (message_dialog
),
875 g_signal_connect (message_dialog
, "response",
876 G_CALLBACK (accounts_dialog_remove_response_cb
),
879 gtk_widget_show (message_dialog
);
883 accounts_dialog_treeview_row_activated_cb (GtkTreeView
*tree_view
,
885 GtkTreeViewColumn
*column
,
886 GossipAccountsDialog
*dialog
)
889 accounts_dialog_button_connect_clicked_cb (dialog
->button_connect
,
894 accounts_dialog_response_cb (GtkWidget
*widget
,
896 GossipAccountsDialog
*dialog
)
898 gtk_widget_destroy (widget
);
902 accounts_dialog_destroy_cb (GtkWidget
*widget
,
903 GossipAccountsDialog
*dialog
)
907 /* Disconnect signals */
908 g_signal_handlers_disconnect_by_func (dialog
->monitor
,
909 accounts_dialog_account_added_cb
,
911 g_signal_handlers_disconnect_by_func (dialog
->monitor
,
912 accounts_dialog_account_removed_cb
,
914 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (dialog
->mc
),
915 "AccountStatusChanged",
916 G_CALLBACK (accounts_dialog_status_changed_cb
),
919 /* Delete incomplete accounts */
920 accounts
= mc_accounts_list ();
921 for (l
= accounts
; l
; l
= l
->next
) {
925 if (!mc_account_is_complete (account
)) {
926 /* FIXME: Warn the user the account is not complete
927 * and is going to be removed. */
928 mc_account_delete (account
);
931 g_object_unref (account
);
933 g_list_free (accounts
);
935 if (dialog
->connecting_id
) {
936 g_source_remove (dialog
->connecting_id
);
939 g_object_unref (dialog
->mc
);
940 g_object_unref (dialog
->monitor
);
946 gossip_accounts_dialog_show (GtkWindow
*parent
)
948 static GossipAccountsDialog
*dialog
= NULL
;
951 GtkWidget
*button_close
;
954 gtk_window_present (GTK_WINDOW (dialog
->window
));
955 return dialog
->window
;
958 dialog
= g_new0 (GossipAccountsDialog
, 1);
960 glade
= gossip_glade_get_file ("gossip-accounts-dialog.glade",
963 "accounts_dialog", &dialog
->window
,
964 "vbox_details", &dialog
->vbox_details
,
965 "frame_no_account", &dialog
->frame_no_account
,
966 "label_no_account", &dialog
->label_no_account
,
967 "label_no_account_blurb", &dialog
->label_no_account_blurb
,
968 "alignment_settings", &dialog
->alignment_settings
,
969 "dialog-action_area", &bbox
,
970 "treeview", &dialog
->treeview
,
971 "frame_new_account", &dialog
->frame_new_account
,
972 "entry_name", &dialog
->entry_name
,
973 "table_new_account", &dialog
->table_new_account
,
974 "button_create", &dialog
->button_create
,
975 "button_back", &dialog
->button_back
,
976 "image_type", &dialog
->image_type
,
977 "label_type", &dialog
->label_type
,
978 "label_name", &dialog
->label_name
,
979 "button_remove", &dialog
->button_remove
,
980 "button_connect", &dialog
->button_connect
,
981 "button_close", &button_close
,
984 gossip_glade_connect (glade
,
986 "accounts_dialog", "destroy", accounts_dialog_destroy_cb
,
987 "accounts_dialog", "response", accounts_dialog_response_cb
,
988 "button_create", "clicked", accounts_dialog_button_create_clicked_cb
,
989 "button_back", "clicked", accounts_dialog_button_back_clicked_cb
,
990 "entry_name", "changed", accounts_dialog_entry_name_changed_cb
,
991 "treeview", "row-activated", accounts_dialog_treeview_row_activated_cb
,
992 "button_connect", "clicked", accounts_dialog_button_connect_clicked_cb
,
993 "button_add", "clicked", accounts_dialog_button_add_clicked_cb
,
994 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb
,
997 g_object_add_weak_pointer (G_OBJECT (dialog
->window
), (gpointer
) &dialog
);
999 g_object_unref (glade
);
1001 /* Create profile chooser */
1002 dialog
->combobox_profile
= gossip_profile_chooser_new ();
1003 gtk_table_attach_defaults (GTK_TABLE (dialog
->table_new_account
),
1004 dialog
->combobox_profile
,
1007 gtk_widget_show (dialog
->combobox_profile
);
1009 /* Set up signalling */
1010 dialog
->mc
= gossip_mission_control_new ();
1011 dialog
->monitor
= mc_account_monitor_new ();
1013 /* FIXME: connect account-enabled/disabled too */
1014 g_signal_connect (dialog
->monitor
, "account-created",
1015 G_CALLBACK (accounts_dialog_account_added_cb
),
1017 g_signal_connect (dialog
->monitor
, "account-deleted",
1018 G_CALLBACK (accounts_dialog_account_removed_cb
),
1020 dbus_g_proxy_connect_signal (DBUS_G_PROXY (dialog
->mc
), "AccountStatusChanged",
1021 G_CALLBACK (accounts_dialog_status_changed_cb
),
1024 accounts_dialog_model_setup (dialog
);
1025 accounts_dialog_setup (dialog
);
1026 accounts_dialog_model_select_first (dialog
);
1029 gtk_window_set_transient_for (GTK_WINDOW (dialog
->window
),
1030 GTK_WINDOW (parent
));
1033 gtk_widget_show (dialog
->window
);
1035 return dialog
->window
;