diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-03-07 17:27:37 +0100 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-03-07 17:27:37 +0100 |
commit | 84d4cd74cfbddaa885c4047547a2d6e766b599e1 (patch) | |
tree | e555e6f3f5775e85964fbe9c06279d7e4a30a390 /mission-control | |
parent | b15ae8030e511c907a1713ea2a0bc85dbc5a4f79 (diff) |
Set account to offline after a timeout after last Release()
Diffstat (limited to 'mission-control')
-rw-r--r-- | mission-control/mcp-account-manager-ytstenut.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/mission-control/mcp-account-manager-ytstenut.c b/mission-control/mcp-account-manager-ytstenut.c index 82a50d8..2203b3c 100644 --- a/mission-control/mcp-account-manager-ytstenut.c +++ b/mission-control/mcp-account-manager-ytstenut.c @@ -49,6 +49,9 @@ /* For using a GHashTable as a hash set */ #define NO_VALUE (GUINT_TO_POINTER (1)) +/* Timeout after last release before going offline, in ms */ +#define RELEASE_TIMEOUT 5000 + /* properties */ enum { @@ -61,6 +64,7 @@ struct _McpAccountManagerYtstenutPrivate { GHashTable *hold_requests; TpDBusDaemon *dbus_daemon; TpAccount *account_proxy; + gulong timeout_id; }; typedef struct { @@ -204,6 +208,21 @@ account_manager_set_presence (McpAccountManagerYtstenut *self, on_account_request_presence_ready, g_object_ref (self)); } +static gboolean +on_release_timeout (gpointer user_data) +{ + McpAccountManagerYtstenut *self = MCP_ACCOUNT_MANAGER_YTSTENUT (user_data); + McpAccountManagerYtstenutPrivate *priv = self->priv; + + priv->timeout_id = 0; + + if (g_hash_table_size (priv->hold_requests) == 0) + account_manager_set_presence (self, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); + + /* Remove this source */ + return FALSE; +} + static void on_name_owner_changed (TpDBusDaemon *bus_daemon, const gchar *name, @@ -239,8 +258,9 @@ account_manager_release (McpAccountManagerYtstenut *self, const gchar *client) tp_dbus_daemon_cancel_name_owner_watch (priv->dbus_daemon, client, on_name_owner_changed, self); - if (g_hash_table_size (priv->hold_requests) == 0) - account_manager_set_presence (self, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); + if (g_hash_table_size (priv->hold_requests) == 0 && !priv->timeout_id) + priv->timeout_id = g_timeout_add_seconds (RELEASE_TIMEOUT, + on_release_timeout, self); } /* ----------------------------------------------------------------------------- |