[telepathy-mission-control/master] McdConnection: emit presence changes as a signal rather than poking the Account
Simon McVittie
simon.mcvittie at collabora.co.uk
Thu Apr 16 07:49:35 PDT 2009
Ideally, McdConnection shouldn't have to call *any* methods on the
McdAccount - it's conceptually "smaller".
---
.../tmpl/mcd-connection.sgml | 10 +++++++
src/mcd-account-priv.h | 4 ---
src/mcd-account.c | 25 ++++++++---------
src/mcd-connection.c | 28 +++++++++++++++-----
4 files changed, 43 insertions(+), 24 deletions(-)
diff --git a/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml b/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml
index 3e79b73..a1681d5 100644
--- a/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml
+++ b/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml
@@ -23,6 +23,16 @@ McdConnection
</para>
+<!-- ##### SIGNAL McdConnection::self-presence-changed ##### -->
+<para>
+
+</para>
+
+ at mcdconnection: the object which received the signal.
+ at arg1:
+ at arg2:
+ at arg3:
+
<!-- ##### ARG McdConnection:account ##### -->
<para>
diff --git a/src/mcd-account-priv.h b/src/mcd-account-priv.h
index 89b878c..953cea4 100644
--- a/src/mcd-account-priv.h
+++ b/src/mcd-account-priv.h
@@ -44,10 +44,6 @@ G_GNUC_INTERNAL void _mcd_account_set_parameter (McdAccount *account,
const gchar *name,
const GValue *value);
-G_GNUC_INTERNAL void _mcd_account_set_current_presence (McdAccount *account,
- TpConnectionPresenceType presence, const gchar *status,
- const gchar *message);
-
G_GNUC_INTERNAL void _mcd_account_request_temporary_presence (McdAccount *self,
TpConnectionPresenceType type, const gchar *status);
diff --git a/src/mcd-account.c b/src/mcd-account.c
index feb3a94..c485ea2 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -1862,20 +1862,14 @@ mcd_account_request_presence (McdAccount *account,
}
}
-/*
- * _mcd_account_set_current_presence:
- * @account: the #McdAccount.
- * @presence: a #TpConnectionPresenceType.
- * @status: presence status.
- * @message: presence status message.
- *
- * Set a presence status on the account.
- */
-void
-_mcd_account_set_current_presence (McdAccount *account,
- TpConnectionPresenceType presence,
- const gchar *status, const gchar *message)
+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;
gboolean changed = FALSE;
GValue value = { 0 };
@@ -2426,6 +2420,9 @@ _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_object_unref (priv->connection);
}
priv->connection = connection;
@@ -2433,6 +2430,8 @@ _mcd_account_set_connection (McdAccount *account, McdConnection *connection)
{
g_return_if_fail (MCD_IS_CONNECTION (connection));
g_object_ref (connection);
+ g_signal_connect (connection, "self-presence-changed",
+ G_CALLBACK (on_conn_self_presence_changed), account);
g_signal_connect (connection, "abort",
G_CALLBACK (on_connection_abort), account);
}
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 7f7ade0..092b957 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -65,6 +65,7 @@
#include "mcd-misc.h"
#include "sp_timestamp.h"
+#include "mcd-signals-marshal.h"
#include "_gen/interfaces.h"
#include "_gen/gtypes.h"
#include "_gen/cli-Connection_Interface_Contact_Capabilities.h"
@@ -166,6 +167,14 @@ enum
PROP_DISPATCHER,
};
+enum
+{
+ SELF_PRESENCE_CHANGED,
+ N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
struct request_id {
guint requestor_serial;
const gchar *requestor_client_id;
@@ -242,8 +251,8 @@ presence_set_status_cb (TpConnection *proxy, const GError *error,
* been changed -- but we hope it didn't */
mcd_account_get_requested_presence (priv->account,
&presence, &status, &message);
- _mcd_account_set_current_presence (priv->account,
- presence, status, message);
+ g_signal_emit (weak_object, signals[SELF_PRESENCE_CHANGED], 0,
+ presence, status, message);
}
}
@@ -382,8 +391,8 @@ on_presences_changed (TpConnection *proxy, GHashTable *presences,
presence = g_value_get_uint (va->values);
status = g_value_get_string (va->values + 1);
message = g_value_get_string (va->values + 2);
- _mcd_account_set_current_presence (priv->account,
- presence, status, message);
+ g_signal_emit (weak_object, signals[SELF_PRESENCE_CHANGED], 0,
+ presence, status, message);
priv->got_presences_changed = TRUE;
}
}
@@ -1634,9 +1643,8 @@ _mcd_connection_release_tp_connection (McdConnection *connection)
McdConnectionPrivate *priv = MCD_CONNECTION_PRIV (connection);
DEBUG ("%p", connection);
- _mcd_account_set_current_presence (priv->account,
- TP_CONNECTION_PRESENCE_TYPE_OFFLINE,
- "offline", NULL);
+ g_signal_emit (connection, signals[SELF_PRESENCE_CHANGED], 0,
+ TP_CONNECTION_PRESENCE_TYPE_OFFLINE, "offline", "");
_mcd_account_set_connection_status (priv->account,
TP_CONNECTION_STATUS_DISCONNECTED,
priv->abort_reason);
@@ -1952,6 +1960,12 @@ mcd_connection_class_init (McdConnectionClass * klass)
"Account",
MCD_TYPE_ACCOUNT,
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, _mcd_marshal_VOID__UINT_STRING_STRING,
+ G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
}
static void
--
1.5.6.5
More information about the telepathy-commits
mailing list