From 0eb14eeb66bbec5985a12c0be24bf45d00ed311c Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 13 Oct 2009 20:25:04 -0400 Subject: make the presence chooser insensitive no accounts are enabled When there are no accounts enabled, there isn't really any point in setting a presence and it's a bit confusing to the user as their action doesn't actually have a result Fixes #598354 --- libempathy-gtk/empathy-presence-chooser.c | 61 +++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk/empathy-presence-chooser.c') diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c index 373b851d5..ab48775fa 100644 --- a/libempathy-gtk/empathy-presence-chooser.c +++ b/libempathy-gtk/empathy-presence-chooser.c @@ -39,6 +39,7 @@ #include #include #include +#include #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include @@ -114,6 +115,8 @@ typedef struct { TpConnectionPresenceType flash_state_1; TpConnectionPresenceType flash_state_2; guint flash_timeout_id; + + EmpathyAccountManager *account_manager; } EmpathyPresenceChooserPriv; /* States to be listed in the menu. @@ -713,12 +716,46 @@ presence_chooser_entry_focus_out_cb (EmpathyPresenceChooser *chooser, return FALSE; } +static void +presence_chooser_update_sensitivity (EmpathyPresenceChooser *chooser) +{ + EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser); + gboolean sensitive = FALSE; + GList *accounts, *l; + + accounts = empathy_account_manager_dup_accounts (priv->account_manager); + + for (l = accounts ; l != NULL ; l = g_list_next (l)) { + EmpathyAccount *a = EMPATHY_ACCOUNT (l->data); + + if (empathy_account_is_enabled (a)) + sensitive = TRUE; + + g_object_unref (a); + } + + g_list_free (accounts); + + if (!empathy_connectivity_is_online (priv->connectivity)) + sensitive = FALSE; + + gtk_widget_set_sensitive (GTK_WIDGET (chooser), sensitive); +} + +static void +presence_chooser_account_manager_account (EmpathyAccountManager *manager, + EmpathyAccount *account, + EmpathyPresenceChooser *chooser) +{ + presence_chooser_update_sensitivity (chooser); +} + static void presence_chooser_connectivity_state_change (EmpathyConnectivity *connectivity, gboolean new_online, EmpathyPresenceChooser *chooser) { - gtk_widget_set_sensitive (GTK_WIDGET (chooser), new_online); + presence_chooser_update_sensitivity (chooser); } static void @@ -789,6 +826,21 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser) G_CALLBACK (presence_chooser_presence_changed_cb), chooser); + priv->account_manager = empathy_account_manager_dup_singleton (); + + g_signal_connect (priv->account_manager, "account-created", + G_CALLBACK (presence_chooser_account_manager_account), + chooser); + g_signal_connect (priv->account_manager, "account-deleted", + G_CALLBACK (presence_chooser_account_manager_account), + chooser); + g_signal_connect (priv->account_manager, "account-enabled", + G_CALLBACK (presence_chooser_account_manager_account), + chooser); + g_signal_connect (priv->account_manager, "account-disabled", + G_CALLBACK (presence_chooser_account_manager_account), + chooser); + /* FIXME: this string sucks */ gtk_widget_set_tooltip_text (GTK_WIDGET (chooser), _("Set your presence and current status")); @@ -798,8 +850,8 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser) "state-change", G_CALLBACK (presence_chooser_connectivity_state_change), chooser); - presence_chooser_connectivity_state_change (priv->connectivity, - empathy_connectivity_is_online (priv->connectivity), chooser); + + presence_chooser_update_sensitivity (chooser); } static void @@ -817,6 +869,9 @@ presence_chooser_finalize (GObject *object) g_source_remove (priv->focus_out_idle_source); } + if (priv->account_manager != NULL) + g_object_unref (priv->account_manager); + g_signal_handlers_disconnect_by_func (priv->idle, presence_chooser_presence_changed_cb, object); -- cgit v1.2.3