From b100bd95fda7dcee89bf660f3fadae3e60ced24b Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 27 Jun 2011 11:59:08 +0200 Subject: [PATCH] Fallback to Offline instead of Busy if Hidden is not supported (#38366) That makes more sense as if you really want to be invisible you should be ready to sacrifice some connectivity to get it. --- src/mcd-connection.c | 40 +++++++++++++++++++++++++++++++++++----- 1 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/mcd-connection.c b/src/mcd-connection.c index 3aaf37c..17694b4 100644 --- a/src/mcd-connection.c +++ b/src/mcd-connection.c @@ -192,7 +192,7 @@ static guint signals[N_SIGNALS] = { 0 }; static const gchar * const _available_fb[] = { NULL }; static const gchar * const _away_fb[] = { "away", NULL }; static const gchar * const _ext_away_fb[] = { "xa", "away", NULL }; -static const gchar * const _hidden_fb[] = { "hidden", "dnd", "busy", "away", NULL }; +static const gchar * const _hidden_fb[] = { "hidden", "offline", "dnd", "busy", "away", NULL }; static const gchar * const _busy_fb[] = { "busy", "dnd", "away", NULL }; static const gchar * const *presence_fallbacks[] = { _available_fb, _away_fb, _ext_away_fb, _hidden_fb, _busy_fb @@ -224,6 +224,23 @@ presence_set_status_cb (TpConnection *proxy, const GError *error, } } +static void +presence_disconnect_cb (TpConnection *proxy, const GError *error, + gpointer user_data, GObject *weak_object) +{ + McdConnectionPrivate *priv = user_data; + + if (error) + { + _mcd_account_set_changing_presence (priv->account, FALSE); + + g_warning ("%s: Disconnection of %s failed: %s", + G_STRFUNC, mcd_account_get_unique_name (priv->account), + error->message); + } +} + + static gboolean _check_presence (McdConnectionPrivate *priv, TpConnectionPresenceType presence, const gchar **status) @@ -252,7 +269,10 @@ _check_presence (McdConnectionPrivate *priv, TpConnectionPresenceType presence, presence_fallbacks[presence - TP_CONNECTION_PRESENCE_TYPE_AVAILABLE]; for (; *fallbacks != NULL; fallbacks++) - if (g_hash_table_lookup (priv->recognized_presences, *fallbacks)) + if (g_hash_table_lookup (priv->recognized_presences, *fallbacks) || + /* We can always set the presence to offline by disconnecting the + * connection. */ + !tp_strdiff (*fallbacks, "offline")) break; /* assume that "available" is always supported -- otherwise, an error will @@ -348,9 +368,19 @@ _mcd_connection_set_presence (McdConnection * connection, _mcd_account_set_changing_presence (priv->account, FALSE); } - tp_cli_connection_interface_simple_presence_call_set_presence - (priv->tp_conn, -1, adj_status, message, presence_set_status_cb, - priv, NULL, (GObject *)connection); + if (!tp_strdiff (adj_status, "offline")) + { + DEBUG ("Call Disconnect() as we can't call SetPresence with ", + "'offline'"); + tp_cli_connection_call_disconnect (priv->tp_conn, -1, + presence_set_status_cb, priv, NULL, (GObject *) connection); + } + else + { + tp_cli_connection_interface_simple_presence_call_set_presence + (priv->tp_conn, -1, adj_status, message, presence_disconnect_cb, + priv, NULL, (GObject *)connection); + } } else { -- 1.7.4.1