2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
24 * Danielle Madeley <danielle.madeley@collabora.co.uk>
28 #include "empathy-accounts-dialog.h"
30 #include <glib/gi18n-lib.h>
31 #include <tp-account-widgets/tpaw-account-widget.h>
32 #include <tp-account-widgets/tpaw-builder.h>
33 #include <tp-account-widgets/tpaw-user-info.h>
34 #include <tp-account-widgets/tpaw-pixbuf-utils.h>
35 #include <tp-account-widgets/tpaw-utils.h>
37 #include "empathy-accounts-common.h"
38 #include "empathy-import-dialog.h"
39 #include "empathy-import-utils.h"
40 #include "empathy-local-xmpp-assistant-widget.h"
41 #include "empathy-new-account-dialog.h"
42 #include "empathy-pkg-kit.h"
43 #include "empathy-ui-utils.h"
44 #include "empathy-utils.h"
46 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
47 #include "empathy-debug.h"
49 /* Flashing delay for icons (milliseconds). */
50 #define FLASH_TIMEOUT 500
52 /* The primary text of the dialog shown to the user when he is about to lose
54 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
55 _("There are unsaved modifications to your %.50s account.")
56 /* The primary text of the dialog shown to the user when he is about to lose
57 * an unsaved new account */
58 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
59 _("Your new account has not been saved yet.")
61 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
62 G_DEFINE_TYPE (EmpathyAccountsDialog
, empathy_accounts_dialog
, GTK_TYPE_DIALOG
);
66 NOTEBOOK_PAGE_ACCOUNT
= 0,
67 NOTEBOOK_PAGE_LOADING
,
68 NOTEBOOK_PAGE_NO_PROTOCOL
72 GtkWidget
*alignment_settings
;
73 GtkWidget
*alignment_infobar
;
75 GtkWidget
*vbox_details
;
77 GtkWidget
*label_status
;
78 GtkWidget
*image_status
;
80 GtkWidget
*enabled_switch
;
83 GtkCellRenderer
*name_renderer
;
85 GtkWidget
*button_add
;
86 GtkWidget
*button_remove
;
87 GtkWidget
*button_import
;
89 GtkWidget
*image_type
;
90 GtkWidget
*label_name
;
91 GtkWidget
*label_type
;
92 GtkWidget
*dialog_content
;
95 GtkWidget
*notebook_account
;
99 /* We have to keep a weak reference on the actual TpawAccountWidget, not
100 * just its GtkWidget. It is the only reliable source we can query to know if
101 * there are any unsaved changes to the currently selected account. We can't
102 * look at the account settings because it does not contain everything that
103 * can be changed using the TpawAccountWidget. For instance, it does not
104 * contain the state of the "Enabled" checkbox.
106 * Even if we create it ourself, we just get a weak ref and not a strong one
107 * as TpawAccountWidget unrefs itself when the GtkWidget is destroyed.
108 * That's kinda ugly; cf bgo #640417.
111 TpawAccountWidget
*setting_widget
;
113 gboolean connecting_show
;
116 gulong settings_ready_id
;
117 TpawAccountSettings
*settings_ready
;
119 TpAccountManager
*account_manager
;
120 TpawConnectionManagers
*cms
;
121 GNetworkMonitor
*connectivity
;
123 GtkWindow
*parent_window
;
124 TpAccount
*initial_selection
;
126 /* Those are needed when changing the selected row. When a user selects
127 * another account and there are unsaved changes on the currently selected
128 * one, a confirmation message box is presented to him. Since his answer
129 * is retrieved asynchronously, we keep some information as member of the
130 * EmpathyAccountsDialog object. */
131 gboolean force_change_row
;
132 GtkTreeRowReference
*destination_row
;
134 GHashTable
*icons_cache
;
135 } EmpathyAccountsDialogPriv
;
141 COL_ACCOUNT_SETTINGS
,
149 static TpawAccountSettings
* accounts_dialog_model_get_selected_settings (
150 EmpathyAccountsDialog
*dialog
);
152 static void accounts_dialog_model_select_first (EmpathyAccountsDialog
*dialog
);
154 static void accounts_dialog_update_settings (EmpathyAccountsDialog
*dialog
,
155 TpawAccountSettings
*settings
);
157 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog
*dialog
,
160 static void accounts_dialog_connection_changed_cb (TpAccount
*account
,
164 gchar
*dbus_error_name
,
166 EmpathyAccountsDialog
*dialog
);
168 static void accounts_dialog_presence_changed_cb (TpAccount
*account
,
171 gchar
*status_message
,
172 EmpathyAccountsDialog
*dialog
);
174 static void accounts_dialog_model_selection_changed (
175 GtkTreeSelection
*selection
,
176 EmpathyAccountsDialog
*dialog
);
178 static gboolean
accounts_dialog_has_pending_change (
179 EmpathyAccountsDialog
*dialog
, TpAccount
**account
);
182 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog
*dialog
,
183 const gchar
*message
)
185 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
186 gchar
*message_markup
;
188 message_markup
= g_markup_printf_escaped ("<i>%s</i>", message
);
189 gtk_label_set_markup (GTK_LABEL (priv
->label_status
), message_markup
);
191 gtk_widget_set_tooltip_text (priv
->label_status
, message
);
193 g_free (message_markup
);
197 accounts_dialog_enable_account_cb (GObject
*object
,
198 GAsyncResult
*result
,
201 TpAccount
*account
= TP_ACCOUNT (object
);
202 gboolean enable
= GPOINTER_TO_UINT (user_data
);
203 GError
*error
= NULL
;
204 TpAccountManager
*am
;
206 if (!tp_account_set_enabled_finish (account
, result
, &error
))
208 DEBUG ("Could not enable the account: %s", error
->message
);
209 g_error_free (error
);
213 /* tp_account_is_enabled() is not updated yet at this point */
216 am
= tp_account_manager_dup ();
218 tpaw_connect_new_account (account
, am
);
224 enable_and_connect_account (TpAccount
*account
,
227 tp_account_set_enabled_async (account
, enable
,
228 accounts_dialog_enable_account_cb
, GUINT_TO_POINTER (enable
));
232 accounts_dialog_enable_switch_active_cb (GtkSwitch
*sw
,
234 EmpathyAccountsDialog
*dialog
)
236 TpawAccountSettings
*settings
;
240 settings
= accounts_dialog_model_get_selected_settings (dialog
);
241 if (settings
== NULL
)
244 account
= tpaw_account_settings_get_account (settings
);
248 enable
= gtk_switch_get_active (sw
);
250 enable_and_connect_account (account
, enable
);
254 install_haze_cb (GObject
*source
,
255 GAsyncResult
*result
,
258 GError
*error
= NULL
;
260 if (!empathy_pkg_kit_install_packages_finish (result
, &error
))
262 DEBUG ("Failed to install telepathy-haze: %s", error
->message
);
264 g_error_free (error
);
269 account_is_selected (EmpathyAccountsDialog
*dialog
,
272 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
273 GtkTreeSelection
*selection
;
276 TpAccount
*selected_account
;
281 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
282 if (selection
== NULL
)
285 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
))
288 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT
, &selected_account
, -1);
290 if (selected_account
!= NULL
)
291 g_object_unref (selected_account
);
293 return account
== selected_account
;
297 account_can_be_enabled (TpAccount
*account
)
299 TpStorageRestrictionFlags storage_restrictions
;
301 storage_restrictions
= tp_account_get_storage_restrictions (account
);
302 if (storage_restrictions
& TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED
)
305 /* Butterfly accounts shouldn't be used any more */
306 if (!tp_strdiff (tp_account_get_cm_name (account
),
314 accounts_dialog_update_status_infobar (EmpathyAccountsDialog
*dialog
,
317 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
318 gchar
*status_message
= NULL
;
322 gboolean account_enabled
;
323 gboolean creating_account
;
324 gboolean display_switch
= TRUE
;
326 /* do not update the infobar when the account is not selected */
327 if (!account_is_selected (dialog
, account
))
334 status
= tp_account_get_connection_status (account
, &reason
);
335 presence
= tp_account_get_current_presence (account
, NULL
, &status_message
);
336 account_enabled
= tp_account_is_enabled (account
);
337 creating_account
= FALSE
;
339 if (status
== TP_CONNECTION_STATUS_CONNECTED
&&
340 (presence
== TP_CONNECTION_PRESENCE_TYPE_OFFLINE
||
341 presence
== TP_CONNECTION_PRESENCE_TYPE_UNSET
))
342 /* If presence is Unset (CM doesn't implement SimplePresence) but we
343 * are connected, consider ourself as Available.
344 * We also check Offline because of this MC5 bug: fd.o #26060 */
345 presence
= TP_CONNECTION_PRESENCE_TYPE_AVAILABLE
;
347 /* set presence to offline if account is disabled
348 * (else no icon is shown in infobar)*/
349 if (!account_enabled
)
350 presence
= TP_CONNECTION_PRESENCE_TYPE_OFFLINE
;
352 display_switch
= account_can_be_enabled (account
);
354 text
= g_markup_printf_escaped ("<b>%.50s</b>",
355 tp_account_get_display_name (account
));
356 gtk_label_set_markup (GTK_LABEL (priv
->label_name
), text
);
361 status
= TP_CONNECTION_STATUS_DISCONNECTED
;
362 presence
= TP_CONNECTION_PRESENCE_TYPE_OFFLINE
;
363 account_enabled
= FALSE
;
364 creating_account
= TRUE
;
367 gtk_image_set_from_icon_name (GTK_IMAGE (priv
->image_status
),
368 empathy_icon_name_for_presence (presence
), GTK_ICON_SIZE_SMALL_TOOLBAR
);
370 /* update the enabled switch */
371 g_signal_handlers_block_by_func (priv
->enabled_switch
,
372 accounts_dialog_enable_switch_active_cb
, dialog
);
373 gtk_switch_set_active (GTK_SWITCH (priv
->enabled_switch
),
375 g_signal_handlers_unblock_by_func (priv
->enabled_switch
,
376 accounts_dialog_enable_switch_active_cb
, dialog
);
378 /* Display the Enable switch if account supports it */
379 gtk_widget_set_visible (priv
->enabled_switch
, display_switch
);
385 case TP_CONNECTION_STATUS_CONNECTING
:
386 accounts_dialog_status_infobar_set_message (dialog
,
388 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv
->infobar
),
391 gtk_spinner_start (GTK_SPINNER (priv
->throbber
));
392 gtk_widget_show (priv
->throbber
);
393 gtk_widget_hide (priv
->image_status
);
395 case TP_CONNECTION_STATUS_CONNECTED
:
396 if (g_strcmp0 (status_message
, "") == 0)
400 message
= g_strdup_printf ("%s",
401 empathy_presence_get_default_message (presence
));
403 accounts_dialog_status_infobar_set_message (dialog
, message
);
410 message
= g_strdup_printf ("%s — %s",
411 empathy_presence_get_default_message (presence
),
414 accounts_dialog_status_infobar_set_message (dialog
, message
);
417 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv
->infobar
),
420 gtk_widget_show (priv
->image_status
);
421 gtk_widget_hide (priv
->throbber
);
423 case TP_CONNECTION_STATUS_DISCONNECTED
:
424 if (reason
== TP_CONNECTION_STATUS_REASON_REQUESTED
)
428 message
= g_strdup_printf (_("Offline — %s"),
429 empathy_account_get_error_message (account
, NULL
));
430 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv
->infobar
),
431 GTK_MESSAGE_WARNING
);
433 accounts_dialog_status_infobar_set_message (dialog
, message
);
440 message
= g_strdup_printf (_("Disconnected — %s"),
441 empathy_account_get_error_message (account
, NULL
));
442 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv
->infobar
),
445 accounts_dialog_status_infobar_set_message (dialog
, message
);
449 if (!g_network_monitor_get_network_available (priv
->connectivity
))
450 accounts_dialog_status_infobar_set_message (dialog
,
451 _("Offline — No Network Connection"));
453 gtk_spinner_stop (GTK_SPINNER (priv
->throbber
));
454 gtk_widget_show (priv
->image_status
);
455 gtk_widget_hide (priv
->throbber
);
458 accounts_dialog_status_infobar_set_message (dialog
, _("Unknown Status"));
459 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv
->infobar
),
460 GTK_MESSAGE_WARNING
);
462 gtk_spinner_stop (GTK_SPINNER (priv
->throbber
));
463 gtk_widget_hide (priv
->image_status
);
464 gtk_widget_hide (priv
->throbber
);
469 if (!tp_strdiff (tp_account_get_cm_name (account
),
472 const gchar
*packages
[] = { "telepathy-haze", NULL
};
474 accounts_dialog_status_infobar_set_message (dialog
,
475 _("This account has been disabled because it relies on an old, "
476 "unsupported backend. Please install telepathy-haze and "
477 "restart your session to migrate the account."));
479 empathy_pkg_kit_install_packages_async (0, packages
, NULL
, NULL
,
480 install_haze_cb
, NULL
);
484 accounts_dialog_status_infobar_set_message (dialog
,
485 _("Offline — Account Disabled"));
488 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv
->infobar
),
489 GTK_MESSAGE_WARNING
);
490 gtk_spinner_stop (GTK_SPINNER (priv
->throbber
));
491 gtk_widget_show (priv
->image_status
);
492 gtk_widget_hide (priv
->throbber
);
495 gtk_widget_show (priv
->label_status
);
497 if (!creating_account
)
498 gtk_widget_show (priv
->infobar
);
500 gtk_widget_hide (priv
->infobar
);
502 g_free (status_message
);
506 empathy_account_dialog_cancel (EmpathyAccountsDialog
*dialog
)
510 GtkTreeSelection
*selection
;
512 TpawAccountSettings
*settings
;
514 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
516 view
= GTK_TREE_VIEW (priv
->treeview
);
517 selection
= gtk_tree_view_get_selection (view
);
519 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
))
522 gtk_tree_model_get (model
, &iter
,
523 COL_ACCOUNT_SETTINGS
, &settings
,
524 COL_ACCOUNT
, &account
, -1);
526 tpaw_account_widget_discard_pending_changes (priv
->setting_widget
);
530 /* We were creating an account. We remove the selected row */
531 gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
535 /* We were modifying an account. We discard the changes by reloading the
536 * settings and the UI. */
537 accounts_dialog_update_settings (dialog
, settings
);
538 g_object_unref (account
);
541 gtk_widget_set_sensitive (priv
->treeview
, TRUE
);
542 gtk_widget_set_sensitive (priv
->button_add
, TRUE
);
543 gtk_widget_set_sensitive (priv
->button_remove
, TRUE
);
544 gtk_widget_set_sensitive (priv
->button_import
, TRUE
);
546 if (settings
!= NULL
)
547 g_object_unref (settings
);
551 empathy_account_dialog_widget_cancelled_cb (
552 TpawAccountWidget
*widget_object
,
553 EmpathyAccountsDialog
*dialog
)
555 empathy_account_dialog_cancel (dialog
);
559 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog
*dialog
)
561 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
566 g_object_get (priv
->setting_widget
,
567 "creating-account", &creating
, NULL
);
572 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
574 if (gtk_tree_model_get_iter_first (model
, &iter
))
575 return gtk_tree_model_iter_next (model
, &iter
);
581 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog
*dialog
)
583 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
584 TpawAccountSettings
*settings
;
585 GtkWidget
*subdialog
, *content_area
, *align
;
587 settings
= accounts_dialog_model_get_selected_settings (dialog
);
588 if (settings
== NULL
)
591 subdialog
= gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
593 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
596 gtk_window_set_resizable (GTK_WINDOW (subdialog
), FALSE
);
598 priv
->setting_widget
= (TpawAccountWidget
*)
599 tpaw_account_widget_new_for_protocol (settings
, NULL
, FALSE
);
601 g_object_add_weak_pointer (G_OBJECT (priv
->setting_widget
),
602 (gpointer
*) &priv
->setting_widget
);
604 if (accounts_dialog_has_valid_accounts (dialog
))
605 tpaw_account_widget_set_other_accounts_exist (
606 priv
->setting_widget
, TRUE
);
608 g_signal_connect (priv
->setting_widget
, "cancelled",
609 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb
), dialog
);
611 g_signal_connect_swapped (priv
->setting_widget
, "close",
612 G_CALLBACK (gtk_widget_destroy
), subdialog
);
614 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (subdialog
));
616 align
= gtk_alignment_new (0.5, 0.5, 1, 1);
617 gtk_alignment_set_padding (GTK_ALIGNMENT (align
), 6, 0, 6, 6);
619 gtk_container_add (GTK_CONTAINER (align
), GTK_WIDGET (priv
->setting_widget
));
620 gtk_box_pack_start (GTK_BOX (content_area
), align
, TRUE
, TRUE
, 0);
622 gtk_widget_show (GTK_WIDGET (priv
->setting_widget
));
623 gtk_widget_show (align
);
624 gtk_widget_show (subdialog
);
628 use_external_storage_provider (EmpathyAccountsDialog
*self
,
631 const gchar
*provider
;
633 provider
= tp_account_get_storage_provider (account
);
634 if (!tp_strdiff (provider
, "com.meego.libsocialweb"))
636 empathy_launch_external_app ("gnome-control-center.desktop",
637 "bisho.desktop", NULL
);
640 else if (!tp_strdiff (provider
, EMPATHY_GOA_PROVIDER
))
642 empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
646 else if (!tp_strdiff (provider
, EMPATHY_UOA_PROVIDER
))
648 empathy_launch_external_app ("unity-credentials-panel.desktop",
654 DEBUG ("Don't know how to handle %s", provider
);
660 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog
*dialog
,
663 TpawAccountSettings
*settings
;
665 TpStorageRestrictionFlags storage_restrictions
;
667 settings
= accounts_dialog_model_get_selected_settings (dialog
);
668 if (settings
== NULL
)
671 account
= tpaw_account_settings_get_account (settings
);
672 g_return_if_fail (account
!= NULL
);
674 storage_restrictions
= tp_account_get_storage_restrictions (account
);
676 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
677 if (storage_restrictions
& TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS
)
679 DEBUG ("Account is provided by an external storage provider");
681 use_external_storage_provider (dialog
, account
);
685 account_dialog_create_edit_params_dialog (dialog
);
690 account_dialog_create_dialog_content (EmpathyAccountsDialog
*dialog
,
691 TpawAccountSettings
*settings
)
693 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
694 const gchar
*icon_name
;
696 GtkWidget
*bbox
, *button
;
699 account
= tpaw_account_settings_get_account (settings
);
701 priv
->dialog_content
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 6);
702 gtk_container_add (GTK_CONTAINER (priv
->alignment_settings
),
703 priv
->dialog_content
);
704 gtk_widget_show (priv
->dialog_content
);
706 alig
= gtk_alignment_new (0.5, 0, 1, 1);
707 priv
->user_info
= tpaw_user_info_new (account
);
708 gtk_container_add (GTK_CONTAINER (alig
), priv
->user_info
);
709 gtk_box_pack_start (GTK_BOX (priv
->dialog_content
), alig
, TRUE
, TRUE
, 0);
710 gtk_widget_show (alig
);
711 gtk_widget_show (priv
->user_info
);
713 bbox
= gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL
);
714 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox
), GTK_BUTTONBOX_END
);
715 gtk_box_pack_end (GTK_BOX (priv
->dialog_content
), bbox
, FALSE
, TRUE
, 0);
716 gtk_widget_show (bbox
);
718 button
= gtk_button_new_with_mnemonic (_("_Edit Connection Parameters…"));
719 gtk_box_pack_start (GTK_BOX (bbox
), button
, FALSE
, TRUE
, 0);
720 gtk_widget_show (button
);
721 g_signal_connect_swapped (button
, "clicked",
722 G_CALLBACK (account_dialow_show_edit_params_dialog
), dialog
);
724 icon_name
= tpaw_account_settings_get_icon_name (settings
);
726 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
728 /* show the default icon; keep this in sync with the default
729 * one in empathy-accounts-dialog.ui.
731 icon_name
= GTK_STOCK_CUT
;
733 gtk_image_set_from_icon_name (GTK_IMAGE (priv
->image_type
),
734 icon_name
, GTK_ICON_SIZE_DIALOG
);
735 gtk_widget_set_tooltip_text (priv
->image_type
,
736 tpaw_protocol_name_to_display_name
737 (tpaw_account_settings_get_protocol (settings
)));
738 gtk_widget_show (priv
->image_type
);
740 accounts_dialog_update_status_infobar (dialog
, account
);
744 account_dialog_settings_ready_cb (TpawAccountSettings
*settings
,
746 EmpathyAccountsDialog
*dialog
)
748 if (tpaw_account_settings_is_ready (settings
))
749 account_dialog_create_dialog_content (dialog
, settings
);
753 accounts_dialog_model_select_first (EmpathyAccountsDialog
*dialog
)
757 GtkTreeSelection
*selection
;
759 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
762 view
= GTK_TREE_VIEW (priv
->treeview
);
763 model
= gtk_tree_view_get_model (view
);
765 if (gtk_tree_model_get_iter_first (model
, &iter
))
767 selection
= gtk_tree_view_get_selection (view
);
768 gtk_tree_selection_select_iter (selection
, &iter
);
772 accounts_dialog_update_settings (dialog
, NULL
);
777 accounts_dialog_has_pending_change (EmpathyAccountsDialog
*dialog
,
782 GtkTreeSelection
*selection
;
783 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
785 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
787 if (gtk_tree_selection_get_selected (selection
, &model
, &iter
))
788 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT
, account
, -1);
790 return priv
->setting_widget
!= NULL
791 && tpaw_account_widget_contains_pending_changes (
792 priv
->setting_widget
);
796 accounts_dialog_show_question_dialog (EmpathyAccountsDialog
*dialog
,
797 const gchar
*primary_text
,
798 const gchar
*secondary_text
,
799 GCallback response_callback
,
801 const gchar
*first_button_text
,
805 GtkWidget
*message_dialog
;
806 const gchar
*button_text
;
808 message_dialog
= gtk_message_dialog_new (GTK_WINDOW (dialog
),
809 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
810 GTK_MESSAGE_QUESTION
,
814 gtk_message_dialog_format_secondary_text (
815 GTK_MESSAGE_DIALOG (message_dialog
), "%s", secondary_text
);
817 va_start (button_args
, first_button_text
);
818 for (button_text
= first_button_text
;
820 button_text
= va_arg (button_args
, const gchar
*))
823 response_id
= va_arg (button_args
, gint
);
825 gtk_dialog_add_button (GTK_DIALOG (message_dialog
), button_text
,
828 va_end (button_args
);
830 g_signal_connect (message_dialog
, "response", response_callback
, user_data
);
832 gtk_widget_show (message_dialog
);
836 get_dialog_primary_text (TpAccount
*account
)
840 /* Existing account */
841 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT
,
842 tp_account_get_display_name (account
));
846 /* Newly created account */
847 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT
);
852 accounts_dialog_button_add_clicked_cb (GtkWidget
*button
,
853 EmpathyAccountsDialog
*self
)
858 dialog
= empathy_new_account_dialog_new (GTK_WINDOW (self
));
859 gtk_window_set_modal (GTK_WINDOW (dialog
), TRUE
);
861 response
= gtk_dialog_run (GTK_DIALOG (dialog
));
863 if (response
== GTK_RESPONSE_APPLY
)
865 TpawAccountSettings
*settings
;
868 settings
= empathy_new_account_dialog_get_settings (
869 EMPATHY_NEW_ACCOUNT_DIALOG (dialog
));
871 /* The newly created account has already been added by
872 * accounts_dialog_account_validity_changed_cb so we just
873 * have to select it. */
874 account
= tpaw_account_settings_get_account (settings
);
875 accounts_dialog_model_set_selected (self
, account
);
878 gtk_widget_destroy (dialog
);
882 accounts_dialog_update_settings (EmpathyAccountsDialog
*dialog
,
883 TpawAccountSettings
*settings
)
885 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
887 if (priv
->settings_ready
!= NULL
)
889 g_signal_handler_disconnect (priv
->settings_ready
,
890 priv
->settings_ready_id
);
891 priv
->settings_ready
= NULL
;
892 priv
->settings_ready_id
= 0;
899 GtkTreeSelection
*selection
;
901 view
= GTK_TREE_VIEW (priv
->treeview
);
902 model
= gtk_tree_view_get_model (view
);
903 selection
= gtk_tree_view_get_selection (view
);
905 if (gtk_tree_model_iter_n_children (model
, NULL
) > 0)
907 /* We have configured accounts, select the first one if there
908 * is no other account selected already. */
909 if (!gtk_tree_selection_get_selected (selection
, NULL
, NULL
))
910 accounts_dialog_model_select_first (dialog
);
915 /* No account selected */
916 gtk_widget_hide (priv
->vbox_details
);
917 gtk_widget_set_sensitive (priv
->button_add
, TRUE
);
918 gtk_widget_set_sensitive (priv
->button_remove
, FALSE
);
920 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv
->notebook_account
),
921 NOTEBOOK_PAGE_NO_PROTOCOL
);
925 /* We have an account selected, destroy old settings and create a new
926 * one for the account selected */
927 gtk_widget_show (priv
->vbox_details
);
929 if (priv
->user_info
!= NULL
)
931 tpaw_user_info_apply_async ((TpawUserInfo
*) priv
->user_info
,
933 priv
->user_info
= NULL
;
935 if (priv
->dialog_content
)
937 gtk_widget_destroy (priv
->dialog_content
);
938 priv
->dialog_content
= NULL
;
941 if (tpaw_account_settings_is_ready (settings
))
943 account_dialog_create_dialog_content (dialog
, settings
);
947 priv
->settings_ready
= settings
;
948 priv
->settings_ready_id
=
949 g_signal_connect (settings
, "notify::ready",
950 G_CALLBACK (account_dialog_settings_ready_cb
), dialog
);
956 accounts_dialog_name_editing_started_cb (GtkCellRenderer
*renderer
,
957 GtkCellEditable
*editable
,
959 EmpathyAccountsDialog
*dialog
)
961 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
963 if (priv
->connecting_id
)
964 g_source_remove (priv
->connecting_id
);
966 DEBUG ("Editing account name started; stopping flashing");
970 get_status_icon_for_account (EmpathyAccountsDialog
*self
,
973 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (self
);
974 TpConnectionStatus status
;
975 TpConnectionStatusReason reason
;
976 TpConnectionPresenceType presence
;
979 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE
);
981 if (!tp_account_is_enabled (account
))
982 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE
);
984 status
= tp_account_get_connection_status (account
, &reason
);
986 if (status
== TP_CONNECTION_STATUS_DISCONNECTED
)
988 if (reason
!= TP_CONNECTION_STATUS_REASON_REQUESTED
)
989 /* An error occured */
990 return GTK_STOCK_DIALOG_ERROR
;
992 presence
= TP_CONNECTION_PRESENCE_TYPE_OFFLINE
;
994 else if (status
== TP_CONNECTION_STATUS_CONNECTING
)
996 /* Account is connecting. Display a blinking account alternating between
997 * the offline icon and the requested presence. */
998 if (priv
->connecting_show
)
999 presence
= tp_account_get_requested_presence (account
, NULL
, NULL
);
1001 presence
= TP_CONNECTION_PRESENCE_TYPE_OFFLINE
;
1005 /* status == TP_CONNECTION_STATUS_CONNECTED */
1006 presence
= tp_account_get_current_presence (account
, NULL
, NULL
);
1008 /* If presence is Unset (CM doesn't implement SimplePresence),
1009 * display the 'available' icon.
1010 * We also check Offline because of this MC5 bug: fd.o #26060 */
1011 if (presence
== TP_CONNECTION_PRESENCE_TYPE_OFFLINE
||
1012 presence
== TP_CONNECTION_PRESENCE_TYPE_UNSET
)
1013 presence
= TP_CONNECTION_PRESENCE_TYPE_AVAILABLE
;
1016 return empathy_icon_name_for_presence (presence
);
1020 ensure_icon (EmpathyAccountsDialog
*self
,
1021 const gchar
*icon_name
)
1023 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (self
);
1026 pixbuf
= g_hash_table_lookup (priv
->icons_cache
, icon_name
);
1029 pixbuf
= tpaw_pixbuf_from_icon_name (icon_name
, GTK_ICON_SIZE_BUTTON
);
1034 g_hash_table_insert (priv
->icons_cache
, g_strdup (icon_name
),
1038 return g_object_ref (pixbuf
);
1042 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn
*tree_column
,
1043 GtkCellRenderer
*cell
,
1044 GtkTreeModel
*model
,
1046 EmpathyAccountsDialog
*dialog
)
1049 const gchar
*icon_name
;
1052 gtk_tree_model_get (model
, iter
, COL_ACCOUNT
, &account
, -1);
1054 icon_name
= get_status_icon_for_account (dialog
, account
);
1055 pixbuf
= ensure_icon (dialog
, icon_name
);
1061 if (account
!= NULL
)
1062 g_object_unref (account
);
1065 g_object_unref (pixbuf
);
1069 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn
*tree_column
,
1070 GtkCellRenderer
*cell
,
1071 GtkTreeModel
*model
,
1073 EmpathyAccountsDialog
*dialog
)
1075 TpawAccountSettings
*settings
;
1078 TpConnectionStatus status
;
1080 gtk_tree_model_get (model
, iter
,
1081 COL_STATUS
, &status
,
1082 COL_ACCOUNT_SETTINGS
, &settings
,
1085 icon_name
= tpaw_account_settings_get_icon_name (settings
);
1086 pixbuf
= ensure_icon (dialog
, icon_name
);
1093 g_object_unref (settings
);
1096 g_object_unref (pixbuf
);
1100 accounts_dialog_row_changed_foreach (GtkTreeModel
*model
,
1107 gtk_tree_model_get (model
, iter
, COL_ACCOUNT
, &account
, -1);
1109 if (account
== NULL
)
1112 if (tp_account_get_connection_status (account
, NULL
) ==
1113 TP_CONNECTION_STATUS_CONNECTING
)
1115 /* Only update the row where we have a connecting account as that's the
1116 * ones having a blinking icon. */
1117 gtk_tree_model_row_changed (model
, path
, iter
);
1120 g_object_unref (account
);
1125 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog
*dialog
)
1128 GtkTreeModel
*model
;
1129 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1131 priv
->connecting_show
= !priv
->connecting_show
;
1133 view
= GTK_TREE_VIEW (priv
->treeview
);
1134 model
= gtk_tree_view_get_model (view
);
1136 gtk_tree_model_foreach (model
, accounts_dialog_row_changed_foreach
, NULL
);
1142 accounts_dialog_name_edited_cb (GtkCellRendererText
*renderer
,
1145 EmpathyAccountsDialog
*dialog
)
1147 TpawAccountSettings
*settings
;
1148 GtkTreeModel
*model
;
1149 GtkTreePath
*treepath
;
1151 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1152 gboolean connecting
;
1154 empathy_account_manager_get_accounts_connected (&connecting
);
1158 priv
->connecting_id
= g_timeout_add (FLASH_TIMEOUT
,
1159 (GSourceFunc
) accounts_dialog_flash_connecting_cb
,
1163 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1164 treepath
= gtk_tree_path_new_from_string (path
);
1165 gtk_tree_model_get_iter (model
, &iter
, treepath
);
1166 gtk_tree_model_get (model
, &iter
,
1167 COL_ACCOUNT_SETTINGS
, &settings
,
1169 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
1172 gtk_tree_path_free (treepath
);
1174 tpaw_account_settings_set_display_name_async (settings
, new_text
,
1176 g_object_set (settings
, "display-name-overridden", TRUE
, NULL
);
1177 g_object_unref (settings
);
1181 accounts_dialog_delete_account_response_cb (GtkDialog
*message_dialog
,
1186 GtkTreeModel
*model
;
1188 GtkTreeSelection
*selection
;
1189 EmpathyAccountsDialog
*account_dialog
= EMPATHY_ACCOUNTS_DIALOG (user_data
);
1190 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (account_dialog
);
1192 if (response_id
== GTK_RESPONSE_YES
)
1194 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
1196 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
))
1199 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT
, &account
, -1);
1201 if (account
!= NULL
)
1203 tp_account_remove_async (account
, NULL
, NULL
);
1204 g_object_unref (account
);
1208 /* No need to call accounts_dialog_model_selection_changed while
1209 * removing as we are going to call accounts_dialog_model_select_first
1210 * right after which will update the selection. */
1211 g_signal_handlers_block_by_func (selection
,
1212 accounts_dialog_model_selection_changed
, account_dialog
);
1214 gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
1216 g_signal_handlers_unblock_by_func (selection
,
1217 accounts_dialog_model_selection_changed
, account_dialog
);
1219 accounts_dialog_model_select_first (account_dialog
);
1222 gtk_widget_destroy (GTK_WIDGET (message_dialog
));
1226 accounts_dialog_remove_account_iter (EmpathyAccountsDialog
*dialog
,
1229 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1231 GtkTreeModel
*model
;
1232 gchar
*question_dialog_primary_text
;
1234 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1236 gtk_tree_model_get (model
, iter
, COL_ACCOUNT
, &account
, -1);
1238 if (account
== NULL
|| !tp_account_is_valid (account
))
1240 if (account
!= NULL
)
1241 g_object_unref (account
);
1242 gtk_list_store_remove (GTK_LIST_STORE (model
), iter
);
1243 accounts_dialog_model_select_first (dialog
);
1247 question_dialog_primary_text
= g_strdup_printf (
1248 _("Do you want to remove %.50s from your computer?"),
1249 tp_account_get_display_name (account
));
1251 accounts_dialog_show_question_dialog (dialog
, question_dialog_primary_text
,
1252 _("This will not remove your account on the server."),
1253 G_CALLBACK (accounts_dialog_delete_account_response_cb
),
1255 GTK_STOCK_CANCEL
, GTK_RESPONSE_NO
,
1256 GTK_STOCK_REMOVE
, GTK_RESPONSE_YES
, NULL
);
1258 g_free (question_dialog_primary_text
);
1259 g_object_unref (account
);
1263 accounts_dialog_button_remove_clicked_cb (GtkWidget
*button
,
1264 EmpathyAccountsDialog
*dialog
)
1266 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1268 GtkTreeSelection
*selection
;
1271 view
= GTK_TREE_VIEW (priv
->treeview
);
1272 selection
= gtk_tree_view_get_selection (view
);
1273 if (!gtk_tree_selection_get_selected (selection
, NULL
, &iter
))
1276 accounts_dialog_remove_account_iter (dialog
, &iter
);
1280 accounts_dialog_model_add_columns (EmpathyAccountsDialog
*dialog
)
1283 GtkTreeViewColumn
*column
;
1284 GtkCellRenderer
*cell
;
1285 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1287 view
= GTK_TREE_VIEW (priv
->treeview
);
1288 gtk_tree_view_set_headers_visible (view
, FALSE
);
1290 /* Account column */
1291 column
= gtk_tree_view_column_new ();
1292 gtk_tree_view_column_set_expand (column
, TRUE
);
1293 gtk_tree_view_append_column (view
, column
);
1295 /* Status icon renderer */
1296 cell
= gtk_cell_renderer_pixbuf_new ();
1297 gtk_tree_view_column_pack_start (column
, cell
, FALSE
);
1298 gtk_tree_view_column_set_cell_data_func (column
, cell
,
1299 (GtkTreeCellDataFunc
)
1300 accounts_dialog_model_status_pixbuf_data_func
,
1304 /* Protocol icon renderer */
1305 cell
= gtk_cell_renderer_pixbuf_new ();
1306 gtk_tree_view_column_pack_start (column
, cell
, FALSE
);
1307 gtk_tree_view_column_set_cell_data_func (column
, cell
,
1308 (GtkTreeCellDataFunc
)
1309 accounts_dialog_model_protocol_pixbuf_data_func
,
1314 priv
->name_renderer
= gtk_cell_renderer_text_new ();
1315 g_object_set (priv
->name_renderer
,
1316 "ellipsize", PANGO_ELLIPSIZE_END
,
1320 gtk_tree_view_column_pack_start (column
, priv
->name_renderer
, TRUE
);
1321 gtk_tree_view_column_add_attribute (column
, priv
->name_renderer
,
1323 g_signal_connect (priv
->name_renderer
, "edited",
1324 G_CALLBACK (accounts_dialog_name_edited_cb
),
1326 g_signal_connect (priv
->name_renderer
, "editing-started",
1327 G_CALLBACK (accounts_dialog_name_editing_started_cb
),
1329 g_object_set (priv
->name_renderer
, "ypad", 4, NULL
);
1332 static TpawAccountSettings
*
1333 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog
*dialog
)
1336 GtkTreeModel
*model
;
1337 GtkTreeSelection
*selection
;
1339 TpawAccountSettings
*settings
;
1340 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1342 view
= GTK_TREE_VIEW (priv
->treeview
);
1343 selection
= gtk_tree_view_get_selection (view
);
1345 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
))
1348 gtk_tree_model_get (model
, &iter
,
1349 COL_ACCOUNT_SETTINGS
, &settings
, -1);
1355 accounts_dialog_model_selection_changed (GtkTreeSelection
*selection
,
1356 EmpathyAccountsDialog
*dialog
)
1358 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1359 TpawAccountSettings
*settings
;
1360 GtkTreeModel
*model
;
1362 gboolean is_selection
;
1363 gboolean creating
= FALSE
;
1365 is_selection
= gtk_tree_selection_get_selected (selection
, &model
, &iter
);
1367 settings
= accounts_dialog_model_get_selected_settings (dialog
);
1368 accounts_dialog_update_settings (dialog
, settings
);
1370 if (settings
!= NULL
)
1371 g_object_unref (settings
);
1373 if (priv
->setting_widget
!= NULL
)
1375 g_object_get (priv
->setting_widget
,
1376 "creating-account", &creating
, NULL
);
1379 /* Update remove button sensitivity */
1380 gtk_widget_set_sensitive (priv
->button_remove
, is_selection
&& !creating
&&
1385 accounts_dialog_selection_change_response_cb (GtkDialog
*message_dialog
,
1387 gpointer
*user_data
)
1389 EmpathyAccountsDialog
*dialog
= EMPATHY_ACCOUNTS_DIALOG (user_data
);
1390 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1392 gtk_widget_destroy (GTK_WIDGET (message_dialog
));
1394 if (response_id
== GTK_RESPONSE_YES
&& priv
->destination_row
!= NULL
)
1396 /* The user wants to lose unsaved changes to the currently selected
1397 * account and select another account. We discard the changes and
1398 * select the other account. */
1400 GtkTreeSelection
*selection
;
1402 priv
->force_change_row
= TRUE
;
1403 tpaw_account_widget_discard_pending_changes (
1404 priv
->setting_widget
);
1406 path
= gtk_tree_row_reference_get_path (priv
->destination_row
);
1407 selection
= gtk_tree_view_get_selection (
1408 GTK_TREE_VIEW (priv
->treeview
));
1412 /* This will trigger a call to
1413 * accounts_dialog_account_selection_change() */
1414 gtk_tree_selection_select_path (selection
, path
);
1415 gtk_tree_path_free (path
);
1418 gtk_tree_row_reference_free (priv
->destination_row
);
1422 priv
->force_change_row
= FALSE
;
1427 accounts_dialog_account_selection_change (GtkTreeSelection
*selection
,
1428 GtkTreeModel
*model
,
1430 gboolean path_currently_selected
,
1433 TpAccount
*account
= NULL
;
1434 EmpathyAccountsDialog
*dialog
= EMPATHY_ACCOUNTS_DIALOG (data
);
1435 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1438 if (priv
->force_change_row
)
1440 /* We came back here because the user wants to discard changes to his
1441 * modified account. The changes have already been discarded so we
1442 * just change the selected row. */
1443 priv
->force_change_row
= FALSE
;
1447 if (accounts_dialog_has_pending_change (dialog
, &account
))
1449 /* The currently selected account has some unsaved changes. We ask
1450 * the user if he really wants to lose his changes and select another
1452 gchar
*question_dialog_primary_text
= get_dialog_primary_text (account
);
1453 priv
->destination_row
= gtk_tree_row_reference_new (model
, path
);
1455 accounts_dialog_show_question_dialog (dialog
,
1456 question_dialog_primary_text
,
1457 _("You are about to select another account, which will discard\n"
1458 "your changes. Are you sure you want to proceed?"),
1459 G_CALLBACK (accounts_dialog_selection_change_response_cb
),
1461 GTK_STOCK_CANCEL
, GTK_RESPONSE_NO
,
1462 GTK_STOCK_DISCARD
, GTK_RESPONSE_YES
, NULL
);
1464 g_free (question_dialog_primary_text
);
1472 if (account
!= NULL
)
1473 g_object_unref (account
);
1479 accounts_dialog_model_setup (EmpathyAccountsDialog
*dialog
)
1481 GtkListStore
*store
;
1482 GtkTreeSelection
*selection
;
1483 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1485 store
= gtk_list_store_new (COL_COUNT
,
1486 G_TYPE_STRING
, /* name */
1487 G_TYPE_UINT
, /* status */
1488 TP_TYPE_ACCOUNT
, /* account */
1489 TPAW_TYPE_ACCOUNT_SETTINGS
); /* settings */
1491 gtk_tree_view_set_model (GTK_TREE_VIEW (priv
->treeview
),
1492 GTK_TREE_MODEL (store
));
1494 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
1495 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_SINGLE
);
1496 gtk_tree_selection_set_select_function (selection
,
1497 accounts_dialog_account_selection_change
, dialog
, NULL
);
1499 g_signal_connect (selection
, "changed",
1500 G_CALLBACK (accounts_dialog_model_selection_changed
),
1503 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store
),
1504 COL_NAME
, GTK_SORT_ASCENDING
);
1506 accounts_dialog_model_add_columns (dialog
);
1508 g_object_unref (store
);
1512 accounts_dialog_get_account_iter (EmpathyAccountsDialog
*dialog
,
1517 GtkTreeModel
*model
;
1519 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1521 /* Update the status in the model */
1522 view
= GTK_TREE_VIEW (priv
->treeview
);
1523 model
= gtk_tree_view_get_model (view
);
1525 for (ok
= gtk_tree_model_get_iter_first (model
, iter
);
1527 ok
= gtk_tree_model_iter_next (model
, iter
))
1529 TpAccount
*this_account
;
1532 gtk_tree_model_get (model
, iter
,
1533 COL_ACCOUNT
, &this_account
,
1536 equal
= (this_account
== account
);
1537 g_object_unref (this_account
);
1547 select_and_scroll_to_iter (EmpathyAccountsDialog
*dialog
,
1550 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1551 GtkTreeSelection
*selection
;
1553 GtkTreeModel
*model
;
1555 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
1557 gtk_tree_selection_select_iter (selection
, iter
);
1559 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1560 path
= gtk_tree_model_get_path (model
, iter
);
1562 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv
->treeview
), path
, NULL
,
1565 gtk_tree_path_free (path
);
1569 accounts_dialog_model_set_selected (EmpathyAccountsDialog
*dialog
,
1574 if (accounts_dialog_get_account_iter (dialog
, account
, &iter
))
1575 select_and_scroll_to_iter (dialog
, &iter
);
1579 accounts_dialog_treeview_enabled_cb (GtkMenuItem
*item
,
1584 enabled
= tp_account_is_enabled (account
);
1586 enable_and_connect_account (account
, !enabled
);
1590 accounts_dialog_treeview_rename_cb (GtkMenuItem
*item
,
1591 EmpathyAccountsDialog
*self
)
1593 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (self
);
1596 GtkTreeSelection
*selection
;
1597 GtkTreeModel
*model
;
1599 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
1600 if (!gtk_tree_selection_get_selected (selection
, &model
, &iter
))
1602 path
= gtk_tree_model_get_path (model
, &iter
);
1604 g_object_set (G_OBJECT (priv
->name_renderer
), "editable", TRUE
, NULL
);
1606 gtk_widget_grab_focus (GTK_WIDGET (priv
->treeview
));
1607 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv
->treeview
), path
,
1608 gtk_tree_view_get_column (GTK_TREE_VIEW (priv
->treeview
), 0), TRUE
);
1610 gtk_tree_path_free (path
);
1614 accounts_dialog_treeview_button_press_event_cb (GtkTreeView
*view
,
1615 GdkEventButton
*event
,
1616 EmpathyAccountsDialog
*dialog
)
1618 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1619 TpAccount
*account
= NULL
;
1620 GtkTreeModel
*model
= NULL
;
1621 GtkTreePath
*path
= NULL
;
1626 /* ignore multiple clicks */
1627 if (event
->type
!= GDK_BUTTON_PRESS
)
1630 if (event
->button
!= 3)
1633 /* Selection is not yet set, so we have to get account from event position */
1634 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1635 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv
->treeview
),
1636 event
->x
, event
->y
, &path
, NULL
, NULL
, NULL
))
1639 if (!gtk_tree_model_get_iter (model
, &iter
, path
))
1642 gtk_tree_model_get (model
, &iter
, COL_ACCOUNT
, &account
, -1);
1644 /* Create the menu */
1645 menu
= empathy_context_menu_new (GTK_WIDGET (view
));
1647 /* Menu item: to enabled/disable the account */
1648 item
= gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1650 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1652 if (account_can_be_enabled (account
))
1656 active
= tp_account_is_enabled (account
);
1657 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item
),
1660 tp_g_signal_connect_object (item
, "activate",
1661 G_CALLBACK (accounts_dialog_treeview_enabled_cb
), account
, 0);
1665 gtk_widget_set_sensitive (item
, FALSE
);
1668 gtk_widget_show (item
);
1670 /* Menu item: Rename */
1671 item
= gtk_menu_item_new_with_mnemonic (_("Rename"));
1672 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1674 tp_g_signal_connect_object (item
, "activate",
1675 G_CALLBACK (accounts_dialog_treeview_rename_cb
), dialog
, 0);
1677 gtk_widget_show (item
);
1679 /* FIXME: Add here presence items, to be able to set per-account presence */
1682 gtk_menu_popup (GTK_MENU (menu
), NULL
, NULL
, NULL
, NULL
,
1683 event
->button
, event
->time
);
1686 tp_clear_object (&account
);
1687 gtk_tree_path_free (path
);
1693 reload_account_widget (EmpathyAccountsDialog
*self
)
1695 TpawAccountSettings
*settings
;
1697 settings
= accounts_dialog_model_get_selected_settings (self
);
1698 accounts_dialog_update_settings (self
, settings
);
1702 accounts_dialog_connection_changed_cb (TpAccount
*account
,
1706 gchar
*dbus_error_name
,
1707 GHashTable
*details
,
1708 EmpathyAccountsDialog
*dialog
)
1710 GtkTreeModel
*model
;
1713 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1715 /* Update the status-infobar in the details view */
1716 accounts_dialog_update_status_infobar (dialog
, account
);
1718 /* Update the status in the model */
1719 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1721 if (accounts_dialog_get_account_iter (dialog
, account
, &iter
))
1725 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
1726 COL_STATUS
, current
,
1729 path
= gtk_tree_model_get_path (model
, &iter
);
1730 gtk_tree_model_row_changed (model
, path
, &iter
);
1731 gtk_tree_path_free (path
);
1734 empathy_account_manager_get_accounts_connected (&found
);
1736 if (!found
&& priv
->connecting_id
)
1738 g_source_remove (priv
->connecting_id
);
1739 priv
->connecting_id
= 0;
1742 if (found
&& !priv
->connecting_id
)
1743 priv
->connecting_id
= g_timeout_add (FLASH_TIMEOUT
,
1744 (GSourceFunc
) accounts_dialog_flash_connecting_cb
,
1749 update_account_in_treeview (EmpathyAccountsDialog
*self
,
1752 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (self
);
1754 GtkTreeModel
*model
;
1756 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1757 if (accounts_dialog_get_account_iter (self
, account
, &iter
))
1761 path
= gtk_tree_model_get_path (model
, &iter
);
1762 gtk_tree_model_row_changed (model
, path
, &iter
);
1763 gtk_tree_path_free (path
);
1768 accounts_dialog_presence_changed_cb (TpAccount
*account
,
1771 gchar
*status_message
,
1772 EmpathyAccountsDialog
*dialog
)
1774 /* Update the status-infobar in the details view */
1775 accounts_dialog_update_status_infobar (dialog
, account
);
1777 update_account_in_treeview (dialog
, account
);
1781 accounts_dialog_account_display_name_changed_cb (TpAccount
*account
,
1783 EmpathyAccountsDialog
*dialog
)
1785 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1786 GtkTreeModel
*model
;
1789 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1790 if (accounts_dialog_get_account_iter (dialog
, account
, &iter
))
1792 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
1793 COL_NAME
, tp_account_get_display_name (account
),
1797 accounts_dialog_update_status_infobar (dialog
, account
);
1801 conn_prepare_cb (GObject
*source
,
1802 GAsyncResult
*result
,
1805 EmpathyAccountsDialog
*self
= user_data
;
1807 reload_account_widget (self
);
1811 accounts_dialog_notify_connection_cb (TpAccount
*account
,
1813 EmpathyAccountsDialog
*self
)
1816 if (!account_is_selected (self
, account
))
1819 conn
= tp_account_get_connection (account
);
1822 reload_account_widget (self
);
1826 /* Wait for this feature so TpConnection will have fetch the
1828 GQuark features
[] = { TP_CONNECTION_FEATURE_CONNECTED
, 0 };
1830 tp_proxy_prepare_async (conn
, features
, conn_prepare_cb
, self
);
1835 accounts_dialog_add_account (EmpathyAccountsDialog
*dialog
,
1838 TpawAccountSettings
*settings
;
1839 GtkTreeModel
*model
;
1841 TpConnectionStatus status
;
1843 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1844 gboolean selected
= FALSE
;
1845 GtkTreeSelection
*selection
;
1847 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
1848 status
= tp_account_get_connection_status (account
, NULL
);
1849 name
= tp_account_get_display_name (account
);
1851 settings
= tpaw_account_settings_new_for_account (account
);
1853 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
1855 if (!accounts_dialog_get_account_iter (dialog
, account
, &iter
))
1857 /* Select the account if it's the first added */
1858 if (gtk_tree_selection_count_selected_rows (selection
) == 0)
1861 gtk_list_store_insert_with_values (GTK_LIST_STORE (model
), &iter
, -1,
1864 COL_ACCOUNT
, account
,
1865 COL_ACCOUNT_SETTINGS
, settings
,
1870 selected
= gtk_tree_selection_iter_is_selected (selection
, &iter
);
1872 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
,
1875 COL_ACCOUNT
, account
,
1876 COL_ACCOUNT_SETTINGS
, settings
,
1882 /* We just modified the selected account. Its display name may have been
1883 * changed and so it's place in the treeview. Scroll to it so it stays
1885 select_and_scroll_to_iter (dialog
, &iter
);
1888 accounts_dialog_connection_changed_cb (account
,
1891 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED
,
1896 tp_g_signal_connect_object (account
, "notify::display-name",
1897 G_CALLBACK (accounts_dialog_account_display_name_changed_cb
),
1900 tp_g_signal_connect_object (account
, "status-changed",
1901 G_CALLBACK (accounts_dialog_connection_changed_cb
), dialog
, 0);
1902 tp_g_signal_connect_object (account
, "presence-changed",
1903 G_CALLBACK (accounts_dialog_presence_changed_cb
), dialog
, 0);
1904 tp_g_signal_connect_object (account
, "notify::connection",
1905 G_CALLBACK (accounts_dialog_notify_connection_cb
), dialog
, 0);
1907 g_object_unref (settings
);
1911 accounts_dialog_account_validity_changed_cb (TpAccountManager
*manager
,
1914 EmpathyAccountsDialog
*dialog
)
1916 accounts_dialog_add_account (dialog
, account
);
1920 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel
*model
,
1923 EmpathyAccountsDialog
*dialog
)
1925 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1927 if (priv
->setting_widget
!= NULL
&&
1928 accounts_dialog_has_valid_accounts (dialog
))
1930 tpaw_account_widget_set_other_accounts_exist (
1931 priv
->setting_widget
, TRUE
);
1936 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel
*model
,
1938 EmpathyAccountsDialog
*dialog
)
1940 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1942 if (priv
->setting_widget
!= NULL
&&
1943 !accounts_dialog_has_valid_accounts (dialog
))
1945 tpaw_account_widget_set_other_accounts_exist (
1946 priv
->setting_widget
, FALSE
);
1951 accounts_dialog_account_removed_cb (TpAccountManager
*manager
,
1953 EmpathyAccountsDialog
*dialog
)
1956 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1958 if (accounts_dialog_get_account_iter (dialog
, account
, &iter
))
1960 gtk_list_store_remove (GTK_LIST_STORE (
1961 gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
))), &iter
);
1966 enable_or_disable_account (EmpathyAccountsDialog
*dialog
,
1970 /* Update the status-infobar in the details view */
1971 accounts_dialog_update_status_infobar (dialog
, account
);
1973 DEBUG ("Account %s is now %s",
1974 tp_account_get_display_name (account
),
1975 enabled
? "enabled" : "disabled");
1979 accounts_dialog_account_disabled_cb (TpAccountManager
*manager
,
1981 EmpathyAccountsDialog
*dialog
)
1983 enable_or_disable_account (dialog
, account
, FALSE
);
1984 update_account_in_treeview (dialog
, account
);
1988 accounts_dialog_account_enabled_cb (TpAccountManager
*manager
,
1990 EmpathyAccountsDialog
*dialog
)
1992 enable_or_disable_account (dialog
, account
, TRUE
);
1996 display_import_dialog (EmpathyAccountsDialog
*dialog
)
1998 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
1999 GtkWidget
*import_dialog
;
2001 import_dialog
= empathy_import_dialog_new (GTK_WINDOW (dialog
),
2003 gtk_widget_show (import_dialog
);
2005 return import_dialog
;
2009 accounts_dialog_button_import_clicked_cb (GtkWidget
*button
,
2010 EmpathyAccountsDialog
*dialog
)
2012 display_import_dialog (dialog
);
2016 accounts_dialog_close_response_cb (GtkDialog
*message_dialog
,
2020 GtkWidget
*account_dialog
= GTK_WIDGET (user_data
);
2022 gtk_widget_destroy (GTK_WIDGET (message_dialog
));
2024 if (response_id
== GTK_RESPONSE_YES
)
2025 gtk_widget_destroy (account_dialog
);
2029 accounts_dialog_delete_event_cb (GtkWidget
*widget
,
2031 EmpathyAccountsDialog
*dialog
)
2033 /* we maunally handle responses to delete events */
2038 accounts_dialog_set_selected_account (EmpathyAccountsDialog
*dialog
,
2043 if (accounts_dialog_get_account_iter (dialog
, account
, &iter
))
2044 select_and_scroll_to_iter (dialog
, &iter
);
2048 salut_valid_cb (GtkWidget
*widget
,
2052 gtk_widget_set_sensitive (button
, valid
);
2056 maybe_show_salut_dialog (EmpathyAccountsDialog
*self
)
2058 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (self
);
2059 GtkWidget
*dialog
, *widget
, *content
, *button
;
2062 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2063 priv
->account_manager
))
2066 widget
= empathy_local_xmpp_assistant_widget_new ();
2067 gtk_widget_show (widget
);
2069 dialog
= gtk_dialog_new ();
2071 gtk_window_set_modal (GTK_WINDOW (dialog
), TRUE
);
2073 gtk_dialog_add_button (GTK_DIALOG (dialog
), _("_Skip"),
2076 button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
2077 _("_Connect"), GTK_RESPONSE_YES
);
2078 gtk_widget_set_sensitive (button
,
2079 empathy_local_xmpp_assistant_widget_is_valid (
2080 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget
)));
2082 g_signal_connect (widget
, "valid", G_CALLBACK (salut_valid_cb
),
2085 content
= gtk_dialog_get_content_area (GTK_DIALOG (dialog
));
2086 gtk_box_pack_start (GTK_BOX (content
), widget
, TRUE
, TRUE
, 0);
2088 response
= gtk_dialog_run (GTK_DIALOG (dialog
));
2090 if (response
== GTK_RESPONSE_YES
)
2092 empathy_local_xmpp_assistant_widget_create_account (
2093 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget
));
2096 gtk_widget_destroy (dialog
);
2100 import_dialog_response_cb (GtkDialog
*dialog
,
2102 EmpathyAccountsDialog
*self
)
2104 maybe_show_salut_dialog (self
);
2108 maybe_show_import_dialog (EmpathyAccountsDialog
*self
)
2110 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (self
);
2113 if (empathy_accounts_has_non_salut_accounts (priv
->account_manager
))
2116 if (!empathy_import_accounts_to_import ())
2118 maybe_show_salut_dialog (self
);
2122 dialog
= display_import_dialog (self
);
2124 tp_g_signal_connect_object (dialog
, "response",
2125 G_CALLBACK (import_dialog_response_cb
), self
, 0);
2129 finished_loading (EmpathyAccountsDialog
*self
)
2131 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (self
);
2132 GtkTreeSelection
*selection
;
2133 gboolean has_selected
;
2135 priv
->loading
= FALSE
;
2137 gtk_widget_set_sensitive (priv
->button_add
, TRUE
);
2138 gtk_widget_set_sensitive (priv
->button_import
, TRUE
);
2139 gtk_widget_set_sensitive (priv
->treeview
, TRUE
);
2141 /* Sensitive the remove button if there is an account selected */
2142 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (priv
->treeview
));
2143 has_selected
= gtk_tree_selection_get_selected (selection
, NULL
, NULL
);
2144 gtk_widget_set_sensitive (priv
->button_remove
, has_selected
);
2146 gtk_spinner_stop (GTK_SPINNER (priv
->spinner
));
2147 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv
->notebook_account
),
2148 NOTEBOOK_PAGE_ACCOUNT
);
2150 maybe_show_import_dialog (self
);
2154 accounts_dialog_cms_prepare_cb (GObject
*source
,
2155 GAsyncResult
*result
,
2158 TpawConnectionManagers
*cms
= TPAW_CONNECTION_MANAGERS (source
);
2159 EmpathyAccountsDialog
*dialog
= user_data
;
2160 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
2162 if (!tpaw_connection_managers_prepare_finish (cms
, result
, NULL
))
2165 /* No need to update the settings if we are already preparing one */
2166 if (priv
->settings_ready
== NULL
)
2167 accounts_dialog_update_settings (dialog
, NULL
);
2169 if (priv
->initial_selection
!= NULL
)
2171 accounts_dialog_set_selected_account (dialog
, priv
->initial_selection
);
2172 g_object_unref (priv
->initial_selection
);
2173 priv
->initial_selection
= NULL
;
2177 finished_loading (dialog
);
2181 accounts_dialog_accounts_setup (EmpathyAccountsDialog
*dialog
)
2183 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
2184 GList
*accounts
, *l
;
2186 g_signal_connect (priv
->account_manager
, "account-validity-changed",
2187 G_CALLBACK (accounts_dialog_account_validity_changed_cb
),
2189 g_signal_connect (priv
->account_manager
, "account-removed",
2190 G_CALLBACK (accounts_dialog_account_removed_cb
),
2192 g_signal_connect (priv
->account_manager
, "account-enabled",
2193 G_CALLBACK (accounts_dialog_account_enabled_cb
),
2195 g_signal_connect (priv
->account_manager
, "account-disabled",
2196 G_CALLBACK (accounts_dialog_account_disabled_cb
),
2199 /* Add existing accounts */
2200 accounts
= tp_account_manager_dup_valid_accounts (priv
->account_manager
);
2201 for (l
= accounts
; l
; l
= l
->next
)
2203 accounts_dialog_add_account (dialog
, l
->data
);
2205 g_list_free_full (accounts
, g_object_unref
);
2207 priv
->cms
= tpaw_connection_managers_dup_singleton ();
2209 tpaw_connection_managers_prepare_async (priv
->cms
,
2210 accounts_dialog_cms_prepare_cb
, dialog
);
2212 accounts_dialog_model_select_first (dialog
);
2216 accounts_dialog_manager_ready_cb (GObject
*source_object
,
2217 GAsyncResult
*result
,
2220 TpAccountManager
*manager
= TP_ACCOUNT_MANAGER (source_object
);
2221 GError
*error
= NULL
;
2223 if (!tp_proxy_prepare_finish (manager
, result
, &error
))
2225 DEBUG ("Failed to prepare account manager: %s", error
->message
);
2226 g_error_free (error
);
2230 accounts_dialog_accounts_setup (user_data
);
2234 dialog_response_cb (GtkWidget
*widget
,
2238 EmpathyAccountsDialog
*dialog
= EMPATHY_ACCOUNTS_DIALOG (widget
);
2240 if (response_id
== GTK_RESPONSE_HELP
)
2242 empathy_url_show (widget
, "help:empathy/accounts-window");
2244 else if (response_id
== GTK_RESPONSE_CLOSE
||
2245 response_id
== GTK_RESPONSE_DELETE_EVENT
)
2247 TpAccount
*account
= NULL
;
2249 if (accounts_dialog_has_pending_change (dialog
, &account
))
2251 gchar
*question_dialog_primary_text
= get_dialog_primary_text (
2254 accounts_dialog_show_question_dialog (dialog
,
2255 question_dialog_primary_text
,
2256 _("You are about to close the window, which will discard\n"
2257 "your changes. Are you sure you want to proceed?"),
2258 G_CALLBACK (accounts_dialog_close_response_cb
),
2260 GTK_STOCK_CANCEL
, GTK_RESPONSE_NO
,
2261 GTK_STOCK_DISCARD
, GTK_RESPONSE_YES
, NULL
);
2263 g_free (question_dialog_primary_text
);
2267 gtk_widget_destroy (widget
);
2270 if (account
!= NULL
)
2271 g_object_unref (account
);
2276 accounts_dialog_build_ui (EmpathyAccountsDialog
*dialog
)
2278 GtkWidget
*top_hbox
;
2281 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
2282 GtkWidget
*content_area
, *action_area
;
2283 GtkWidget
*grid
, *hbox
;
2285 GtkWidget
*sw
, *toolbar
;
2286 GtkStyleContext
*context
;
2288 filename
= empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2290 gui
= tpaw_builder_get_file (filename
,
2291 "accounts_dialog_hbox", &top_hbox
,
2292 "vbox_details", &priv
->vbox_details
,
2293 "alignment_settings", &priv
->alignment_settings
,
2294 "alignment_infobar", &priv
->alignment_infobar
,
2295 "treeview", &priv
->treeview
,
2296 "button_add", &priv
->button_add
,
2297 "button_remove", &priv
->button_remove
,
2298 "button_import", &priv
->button_import
,
2299 "notebook_account", &priv
->notebook_account
,
2300 "alignment_loading", &alig
,
2302 "add_remove_toolbar", &toolbar
,
2306 tpaw_builder_connect (gui
, dialog
,
2307 "button_add", "clicked", accounts_dialog_button_add_clicked_cb
,
2308 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb
,
2309 "button_import", "clicked", accounts_dialog_button_import_clicked_cb
,
2310 "treeview", "button-press-event",
2311 accounts_dialog_treeview_button_press_event_cb
,
2314 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (dialog
));
2316 gtk_box_pack_start (GTK_BOX (content_area
), top_hbox
, TRUE
, TRUE
, 0);
2318 g_object_unref (gui
);
2320 action_area
= gtk_dialog_get_action_area (GTK_DIALOG (dialog
));
2322 /* Display loading page */
2323 priv
->loading
= TRUE
;
2325 priv
->spinner
= gtk_spinner_new ();
2327 gtk_spinner_start (GTK_SPINNER (priv
->spinner
));
2328 gtk_widget_show (priv
->spinner
);
2330 gtk_container_add (GTK_CONTAINER (alig
), priv
->spinner
);
2332 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv
->notebook_account
),
2333 NOTEBOOK_PAGE_LOADING
);
2335 /* Remove button is insensitive until we have a selected account */
2336 gtk_widget_set_sensitive (priv
->button_remove
, FALSE
);
2338 /* Add and Import buttons and treeview are insensitive while the dialog
2340 gtk_widget_set_sensitive (priv
->button_add
, FALSE
);
2341 gtk_widget_set_sensitive (priv
->button_import
, FALSE
);
2342 gtk_widget_set_sensitive (priv
->treeview
, FALSE
);
2344 if (priv
->parent_window
)
2345 gtk_window_set_transient_for (GTK_WINDOW (dialog
),
2346 priv
->parent_window
);
2348 priv
->infobar
= gtk_info_bar_new ();
2349 gtk_container_add (GTK_CONTAINER (priv
->alignment_infobar
),
2351 gtk_widget_show (priv
->infobar
);
2353 grid
= gtk_grid_new ();
2354 gtk_grid_set_column_spacing (GTK_GRID (grid
), 6);
2356 GTK_CONTAINER (gtk_info_bar_get_content_area (
2357 GTK_INFO_BAR (priv
->infobar
))),
2360 priv
->image_type
= gtk_image_new_from_stock (GTK_STOCK_CUT
,
2361 GTK_ICON_SIZE_DIALOG
);
2362 gtk_misc_set_alignment (GTK_MISC (priv
->image_type
), 0.0, 0.5);
2363 gtk_grid_attach (GTK_GRID (grid
), priv
->image_type
, 0, 0, 1, 2);
2366 priv
->label_name
= gtk_label_new (NULL
);
2367 gtk_label_set_ellipsize (GTK_LABEL (priv
->label_name
), PANGO_ELLIPSIZE_END
);
2368 gtk_grid_attach (GTK_GRID (grid
), priv
->label_name
, 1, 0, 1, 1);
2371 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 2);
2372 gtk_widget_set_hexpand (hbox
, TRUE
);
2373 gtk_widget_set_halign (hbox
, GTK_ALIGN_CENTER
);
2374 gtk_grid_attach (GTK_GRID (grid
), hbox
, 1, 1, 1, 1);
2376 /* set up spinner */
2377 priv
->throbber
= gtk_spinner_new ();
2379 priv
->image_status
= gtk_image_new_from_icon_name (
2380 empathy_icon_name_for_presence (
2381 TP_CONNECTION_PRESENCE_TYPE_OFFLINE
), GTK_ICON_SIZE_SMALL_TOOLBAR
);
2383 priv
->label_status
= gtk_label_new (NULL
);
2384 gtk_label_set_ellipsize (GTK_LABEL (priv
->label_status
), PANGO_ELLIPSIZE_END
);
2386 gtk_box_pack_start (GTK_BOX (hbox
), priv
->throbber
, FALSE
, FALSE
, 0);
2387 gtk_box_pack_start (GTK_BOX (hbox
), priv
->image_status
, FALSE
, FALSE
, 0);
2388 gtk_box_pack_start (GTK_BOX (hbox
), priv
->label_status
, FALSE
, FALSE
, 0);
2390 /* enabled switch */
2391 priv
->enabled_switch
= gtk_switch_new ();
2392 gtk_widget_set_valign (priv
->enabled_switch
, GTK_ALIGN_CENTER
);
2393 g_signal_connect (priv
->enabled_switch
, "notify::active",
2394 G_CALLBACK (accounts_dialog_enable_switch_active_cb
), dialog
);
2395 gtk_grid_attach (GTK_GRID (grid
), priv
->enabled_switch
, 2, 0, 1, 2);
2397 gtk_widget_show_all (grid
);
2399 /* Tweak the dialog */
2400 gtk_window_set_title (GTK_WINDOW (dialog
), _("Messaging and VoIP Accounts"));
2401 gtk_window_set_role (GTK_WINDOW (dialog
), "accounts");
2403 gtk_window_set_default_size (GTK_WINDOW (dialog
), 640, 450);
2405 gtk_window_set_type_hint (GTK_WINDOW (dialog
), GDK_WINDOW_TYPE_HINT_DIALOG
);
2407 /* join the add/remove toolbar to the treeview */
2408 context
= gtk_widget_get_style_context (sw
);
2409 gtk_style_context_set_junction_sides (context
, GTK_JUNCTION_BOTTOM
);
2411 context
= gtk_widget_get_style_context (toolbar
);
2412 gtk_style_context_set_junction_sides (context
, GTK_JUNCTION_TOP
);
2414 /* add dialog buttons */
2415 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area
), GTK_BUTTONBOX_END
);
2417 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
2418 GTK_STOCK_HELP
, GTK_RESPONSE_HELP
,
2419 GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
,
2422 g_signal_connect (dialog
, "response",
2423 G_CALLBACK (dialog_response_cb
), dialog
);
2425 g_signal_connect (dialog
, "delete-event",
2426 G_CALLBACK (accounts_dialog_delete_event_cb
), dialog
);
2430 do_dispose (GObject
*obj
)
2432 EmpathyAccountsDialog
*dialog
= EMPATHY_ACCOUNTS_DIALOG (obj
);
2433 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
2435 if (priv
->user_info
!= NULL
)
2437 tpaw_user_info_apply_async ((TpawUserInfo
*) priv
->user_info
,
2439 priv
->user_info
= NULL
;
2442 if (priv
->connecting_id
!= 0)
2444 g_source_remove (priv
->connecting_id
);
2445 priv
->connecting_id
= 0;
2448 if (priv
->connectivity
)
2450 g_object_unref (priv
->connectivity
);
2451 priv
->connectivity
= NULL
;
2454 if (priv
->account_manager
!= NULL
)
2456 g_object_unref (priv
->account_manager
);
2457 priv
->account_manager
= NULL
;
2460 if (priv
->cms
!= NULL
)
2462 g_object_unref (priv
->cms
);
2466 if (priv
->initial_selection
!= NULL
)
2468 g_object_unref (priv
->initial_selection
);
2469 priv
->initial_selection
= NULL
;
2472 tp_clear_pointer (&priv
->icons_cache
, g_hash_table_unref
);
2474 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class
)->dispose (obj
);
2478 do_get_property (GObject
*object
,
2483 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (object
);
2485 switch (property_id
)
2488 g_value_set_object (value
, priv
->parent_window
);
2491 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
2496 do_set_property (GObject
*object
,
2498 const GValue
*value
,
2501 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (object
);
2503 switch (property_id
)
2506 priv
->parent_window
= g_value_get_object (value
);
2509 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
2514 do_constructed (GObject
*object
)
2516 EmpathyAccountsDialog
*dialog
= EMPATHY_ACCOUNTS_DIALOG (object
);
2517 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
2518 GtkTreeModel
*model
;
2520 accounts_dialog_build_ui (dialog
);
2521 accounts_dialog_model_setup (dialog
);
2523 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (priv
->treeview
));
2524 g_signal_connect (model
, "row-inserted",
2525 (GCallback
) accounts_dialog_accounts_model_row_inserted_cb
, dialog
);
2526 g_signal_connect (model
, "row-deleted",
2527 (GCallback
) accounts_dialog_accounts_model_row_deleted_cb
, dialog
);
2529 /* Set up signalling */
2530 priv
->account_manager
= tp_account_manager_dup ();
2532 tp_proxy_prepare_async (priv
->account_manager
, NULL
,
2533 accounts_dialog_manager_ready_cb
, dialog
);
2535 priv
->connectivity
= g_network_monitor_get_default ();
2536 g_object_ref (priv
->connectivity
);
2540 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass
*klass
)
2542 GObjectClass
*oclass
= G_OBJECT_CLASS (klass
);
2543 GParamSpec
*param_spec
;
2545 oclass
->dispose
= do_dispose
;
2546 oclass
->constructed
= do_constructed
;
2547 oclass
->set_property
= do_set_property
;
2548 oclass
->get_property
= do_get_property
;
2550 param_spec
= g_param_spec_object ("parent",
2551 "parent", "The parent window",
2553 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY
);
2554 g_object_class_install_property (oclass
, PROP_PARENT
, param_spec
);
2556 g_type_class_add_private (klass
, sizeof (EmpathyAccountsDialogPriv
));
2560 empathy_accounts_dialog_init (EmpathyAccountsDialog
*dialog
)
2562 EmpathyAccountsDialogPriv
*priv
;
2564 priv
= G_TYPE_INSTANCE_GET_PRIVATE ((dialog
),
2565 EMPATHY_TYPE_ACCOUNTS_DIALOG
,
2566 EmpathyAccountsDialogPriv
);
2567 dialog
->priv
= priv
;
2569 priv
->icons_cache
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
2570 g_free
, g_object_unref
);
2573 /* public methods */
2576 empathy_accounts_dialog_show (GtkWindow
*parent
,
2577 TpAccount
*selected_account
)
2579 EmpathyAccountsDialog
*dialog
;
2580 EmpathyAccountsDialogPriv
*priv
;
2582 dialog
= g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG
,
2583 "parent", parent
, NULL
);
2585 priv
= GET_PRIV (dialog
);
2587 if (selected_account
)
2589 if (priv
->cms
!= NULL
&& tpaw_connection_managers_is_ready (priv
->cms
))
2590 accounts_dialog_set_selected_account (dialog
, selected_account
);
2592 /* save the selection to set it later when the cms
2595 priv
->initial_selection
= g_object_ref (selected_account
);
2598 gtk_window_present (GTK_WINDOW (dialog
));
2600 return GTK_WIDGET (dialog
);
2610 static LaunchUOACtx
*
2611 launch_uoa_ctx_new (TpAccount
*account
,
2616 ctx
= g_slice_new0 (LaunchUOACtx
);
2617 if (account
!= NULL
)
2618 ctx
->account
= g_object_ref (account
);
2619 ctx
->if_needed
= if_needed
;
2625 launch_uoa_ctx_free (LaunchUOACtx
*ctx
)
2627 g_clear_object (&ctx
->account
);
2628 g_slice_free (LaunchUOACtx
, ctx
);
2632 am_prepare_cb (GObject
*source
,
2633 GAsyncResult
*result
,
2636 TpAccountManager
*manager
= TP_ACCOUNT_MANAGER (source
);
2637 GError
*error
= NULL
;
2638 LaunchUOACtx
*ctx
= user_data
;
2641 if (!tp_proxy_prepare_finish (manager
, result
, &error
))
2643 DEBUG ("Failed to prepare account manager: %s", error
->message
);
2644 g_error_free (error
);
2648 if (ctx
->if_needed
&& empathy_accounts_has_non_salut_accounts (manager
))
2651 if (ctx
->account
!= NULL
)
2653 const GValue
*value
;
2655 value
= tp_account_get_storage_identifier (ctx
->account
);
2657 if (G_VALUE_HOLDS_UINT (value
))
2658 args
= g_strdup_printf ("account-details=%u", g_value_get_uint (value
));
2661 empathy_launch_external_app ("unity-credentials-panel.desktop", args
, NULL
);
2665 launch_uoa_ctx_free (ctx
);
2669 launch_uoa_panel (TpAccount
*selected_account
,
2673 TpAccountManager
*manager
;
2679 manager
= tp_account_manager_dup ();
2681 tp_proxy_prepare_async (manager
, NULL
, am_prepare_cb
,
2682 launch_uoa_ctx_new (selected_account
, if_needed
));
2684 g_object_unref (manager
);
2687 #else /* HAVE_UOA */
2690 launch_empathy_accounts (TpAccount
*selected_account
,
2696 g_return_if_fail (!selected_account
|| TP_IS_ACCOUNT (selected_account
));
2698 args
= g_string_new (NULL
);
2700 if (selected_account
!= NULL
)
2701 g_string_append_printf (args
, " --select-account=%s",
2702 tp_account_get_path_suffix (selected_account
));
2705 g_string_append_printf (args
, " --if-needed");
2708 g_string_append_printf (args
, " --hidden");
2710 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2712 selected_account
== NULL
? "<none selected>" :
2713 tp_proxy_get_object_path (TP_PROXY (selected_account
)));
2715 empathy_launch_program (BIN_DIR
, "empathy-accounts", args
->str
);
2717 g_string_free (args
, TRUE
);
2719 #endif /* HAVE_UOA */
2722 empathy_accounts_dialog_show_application (GdkScreen
*screen
,
2723 TpAccount
*selected_account
,
2728 launch_uoa_panel (selected_account
, if_needed
, hidden
);
2730 launch_empathy_accounts (selected_account
, if_needed
, hidden
);
2735 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog
*dialog
)
2737 EmpathyAccountsDialogPriv
*priv
= GET_PRIV (dialog
);
2738 gboolean result
= FALSE
;
2740 if (priv
->setting_widget
== NULL
)
2743 g_object_get (priv
->setting_widget
,
2744 "creating-account", &result
, NULL
);