summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-08-28 15:35:38 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-09-04 13:28:56 +0100
commit6e88e909f5f1cb4b0f0d33f88b26f5cb6d3fc9c7 (patch)
tree32a9b7382e8d0da4b9795a012d7613e6ca68bd4a
parentc5e96690fd558b4de8de794bce04fb3937b03799 (diff)
downloadtelepathy-mission-control-6e88e909f5f1cb4b0f0d33f88b26f5cb6d3fc9c7.tar.gz
Track presence via TpContact, not McdConnection
Now that McdAccount has a TpContact for the self-contact, this is really easy. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68905 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--src/mcd-account.c68
-rw-r--r--src/mcd-connection.c67
2 files changed, 29 insertions, 106 deletions
diff --git a/src/mcd-account.c b/src/mcd-account.c
index ddc27371..77b6153d 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -4,7 +4,7 @@
* This file is part of mission-control
*
* Copyright © 2008–2010 Nokia Corporation.
- * Copyright © 2009–2012 Collabora Ltd.
+ * Copyright © 2009–2013 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -3981,14 +3981,18 @@ mcd_account_request_presence (McdAccount *account,
static void
mcd_account_update_self_presence (McdAccount *account,
- TpConnectionPresenceType presence,
+ guint presence,
const gchar *status,
- const gchar *message)
+ const gchar *message,
+ TpContact *self_contact)
{
McdAccountPrivate *priv = account->priv;
gboolean changed = FALSE;
GValue value = G_VALUE_INIT;
+ if (self_contact != account->priv->self_contact)
+ return;
+
if (priv->curr_presence_type != presence)
{
priv->curr_presence_type = presence;
@@ -4025,21 +4029,6 @@ mcd_account_update_self_presence (McdAccount *account,
g_value_unset (&value);
}
-
-static void
-on_conn_self_presence_changed (McdConnection *connection,
- TpConnectionPresenceType presence,
- const gchar *status,
- const gchar *message,
- gpointer user_data)
-{
- McdAccount *account = MCD_ACCOUNT (user_data);
- McdAccountPrivate *priv = account->priv;
-
- g_assert (priv->connection == connection);
- mcd_account_update_self_presence (account, presence, status, message);
-}
-
/* TODO: remove when the relative members will become public */
void
mcd_account_get_requested_presence (McdAccount *account,
@@ -4508,6 +4497,14 @@ _mcd_account_set_connection_status (McdAccount *account,
}
else if (status == TP_CONNECTION_STATUS_DISCONNECTED)
{
+ /* we'll get this from the TpContact soon, but it makes sense
+ * to bundle everything together into one signal */
+ mcd_account_update_self_presence (account,
+ TP_CONNECTION_PRESENCE_TYPE_OFFLINE,
+ "offline",
+ "",
+ priv->self_contact);
+
if (dbus_error == NULL)
dbus_error = "";
@@ -4915,6 +4912,18 @@ mcd_account_self_contact_upgraded_cb (GObject *source_object,
G_CALLBACK (mcd_account_self_contact_notify_avatar_file_cb),
self, G_CONNECT_SWAPPED);
mcd_account_process_initial_avatar_token (self);
+
+ tp_g_signal_connect_object (self_contact, "presence-changed",
+ G_CALLBACK (mcd_account_update_self_presence),
+ self, G_CONNECT_SWAPPED);
+
+ /* If the connection doesn't support SimplePresence then the
+ * presence will be (UNSET, '', '') which is what we want anyway. */
+ mcd_account_update_self_presence (self,
+ tp_contact_get_presence_type (self_contact),
+ tp_contact_get_presence_status (self_contact),
+ tp_contact_get_presence_message (self_contact),
+ self_contact);
}
else
{
@@ -4943,7 +4952,8 @@ mcd_account_self_contact_changed_cb (McdAccount *self,
static const TpContactFeature contact_features[] = {
TP_CONTACT_FEATURE_AVATAR_TOKEN,
TP_CONTACT_FEATURE_AVATAR_DATA,
- TP_CONTACT_FEATURE_ALIAS
+ TP_CONTACT_FEATURE_ALIAS,
+ TP_CONTACT_FEATURE_PRESENCE
};
TpContact *self_contact;
@@ -5031,21 +5041,6 @@ mcd_account_connection_ready_cb (McdAccount *account,
}
g_free (nickname);
-
- if (!tp_proxy_has_interface_by_id (tp_connection,
- TP_IFACE_QUARK_CONNECTION_INTERFACE_SIMPLE_PRESENCE))
- {
- /* This connection doesn't have SimplePresence, but it's online.
- * TpConnection only emits connection-ready when the account is online
- * and we've introspected it, so we know that if this interface isn't
- * present now, it's not going to appear.
- *
- * So, the spec says that we should set CurrentPresence to Unset.
- */
- mcd_account_update_self_presence (account,
- TP_CONNECTION_PRESENCE_TYPE_UNSET, "", "");
- }
-
}
void
@@ -5062,9 +5057,6 @@ _mcd_account_set_connection (McdAccount *account, McdConnection *connection)
g_signal_handlers_disconnect_by_func (priv->connection,
on_connection_abort, account);
g_signal_handlers_disconnect_by_func (priv->connection,
- on_conn_self_presence_changed,
- account);
- g_signal_handlers_disconnect_by_func (priv->connection,
on_conn_status_changed,
account);
g_signal_handlers_disconnect_by_func (priv->connection,
@@ -5092,8 +5084,6 @@ _mcd_account_set_connection (McdAccount *account, McdConnection *connection)
G_CALLBACK (mcd_account_connection_ready_cb), account);
}
- g_signal_connect (connection, "self-presence-changed",
- G_CALLBACK (on_conn_self_presence_changed), account);
g_signal_connect (connection, "connection-status-changed",
G_CALLBACK (on_conn_status_changed), account);
g_signal_connect (connection, "abort",
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index c82f2d54..9e3ef298 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -114,9 +114,6 @@ struct _McdConnectionPrivate
* dispatched */
guint dispatched_initial_channels : 1;
- /* FALSE until we got the first PresencesChanged for the self handle */
- guint got_presences_changed : 1;
-
/* TRUE if the last status change was to CONNECTED */
guint connected : 1;
@@ -159,7 +156,6 @@ enum
enum
{
READY,
- SELF_PRESENCE_CHANGED,
CONNECTION_STATUS_CHANGED,
N_SIGNALS
};
@@ -412,64 +408,9 @@ presence_get_statuses_cb (TpProxy *proxy, const GValue *v_statuses,
}
static void
-on_presences_changed (TpConnection *proxy, GHashTable *presences,
- gpointer user_data, GObject *weak_object)
-{
- McdConnectionPrivate *priv = user_data;
- GValueArray *va;
- TpHandle self_handle;
-
- self_handle = tp_connection_get_self_handle (proxy);
- va = g_hash_table_lookup (presences, GUINT_TO_POINTER (self_handle));
- if (va)
- {
- TpConnectionPresenceType presence;
- const gchar *status, *message;
-
- presence = g_value_get_uint (va->values);
- status = g_value_get_string (va->values + 1);
- message = g_value_get_string (va->values + 2);
- g_signal_emit (weak_object, signals[SELF_PRESENCE_CHANGED], 0,
- presence, status, message);
- priv->got_presences_changed = TRUE;
- }
-}
-
-static void
-mcd_connection_initial_presence_cb (TpConnection *proxy,
- GHashTable *presences,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
-{
- if (error != NULL)
- {
- DEBUG ("GetPresences([SelfHandle]) failed: %s", error->message);
- return;
- }
-
- on_presences_changed (proxy, presences, user_data, weak_object);
-}
-
-static void
_mcd_connection_setup_presence (McdConnection *connection)
{
McdConnectionPrivate *priv = connection->priv;
- GArray *self_handle_array;
- guint self_handle;
-
- tp_cli_connection_interface_simple_presence_connect_to_presences_changed
- (priv->tp_conn, on_presences_changed, priv, NULL,
- (GObject *)connection, NULL);
-
- self_handle_array = g_array_new (FALSE, FALSE, sizeof (guint));
- self_handle = tp_connection_get_self_handle (priv->tp_conn);
- g_array_append_val (self_handle_array, self_handle);
- tp_cli_connection_interface_simple_presence_call_get_presences
- (priv->tp_conn, -1, self_handle_array,
- mcd_connection_initial_presence_cb, priv, NULL,
- (GObject *) connection);
- g_array_unref (self_handle_array);
tp_cli_dbus_properties_call_get
(priv->tp_conn, -1, TP_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE,
@@ -1616,8 +1557,6 @@ _mcd_connection_release_tp_connection (McdConnection *connection,
McdConnectionPrivate *priv = MCD_CONNECTION_PRIV (connection);
DEBUG ("%p", connection);
- g_signal_emit (connection, signals[SELF_PRESENCE_CHANGED], 0,
- TP_CONNECTION_PRESENCE_TYPE_OFFLINE, "offline", "");
if (priv->abort_reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
{
@@ -2008,12 +1947,6 @@ mcd_connection_class_init (McdConnectionClass * klass)
MCD_TYPE_SLACKER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- signals[SELF_PRESENCE_CHANGED] = g_signal_new ("self-presence-changed",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
-
/**
* @status:
* @status_reason: