diff options
author | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-05-02 17:24:58 +0200 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-05-03 10:34:29 +0200 |
commit | aa611fb0084b0c94f5e3b3c9c7e5ae30b8556c67 (patch) | |
tree | ec0bad40258d848c52c798cb805f87f768906e1f | |
parent | 4a0739c2a00b833fdc3a312680686a87c49258a0 (diff) |
Add tp_contact_is_self()
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 1 | ||||
-rw-r--r-- | telepathy-glib/channel-contacts.c | 6 | ||||
-rw-r--r-- | telepathy-glib/connection.c | 5 | ||||
-rw-r--r-- | telepathy-glib/contact-internal.h | 3 | ||||
-rw-r--r-- | telepathy-glib/contact.c | 51 | ||||
-rw-r--r-- | telepathy-glib/contact.h | 1 | ||||
-rw-r--r-- | tests/dbus/channel.c | 1 | ||||
-rw-r--r-- | tests/dbus/contacts.c | 1 |
8 files changed, 68 insertions, 1 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 27818abe3..b7a81a420 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -4926,6 +4926,7 @@ tp_connection_get_contacts_by_id TpConnectionUpgradeContactsCb tp_connection_upgrade_contacts tp_connection_refresh_contact_info +tp_contact_is_self tp_contact_get_alias tp_contact_get_avatar_token tp_contact_get_avatar_file diff --git a/telepathy-glib/channel-contacts.c b/telepathy-glib/channel-contacts.c index 6896a463c..dd65b0968 100644 --- a/telepathy-glib/channel-contacts.c +++ b/telepathy-glib/channel-contacts.c @@ -29,6 +29,7 @@ #define DEBUG_FLAG TP_DEBUG_GROUPS #include "telepathy-glib/connection-internal.h" +#include "telepathy-glib/contact-internal.h" #include "telepathy-glib/debug-internal.h" #include "telepathy-glib/util-internal.h" @@ -211,6 +212,7 @@ _tp_channel_contacts_group_init (TpChannel *self, self->priv->group_self_contact = dup_contact (self, self->priv->group_self_handle, identifiers); + _tp_contact_set_is_self (self->priv->group_self_contact, TRUE); self->priv->group_members_contacts = dup_contacts_table (self, self->priv->group_members, identifiers); @@ -751,6 +753,10 @@ self_contact_changed_prepared_cb (GObject *object, _tp_channel_contacts_queue_prepare_finish (self, result, NULL, NULL); + if (self->priv->group_self_contact != NULL) + _tp_contact_set_is_self (self->priv->group_self_contact, FALSE); + _tp_contact_set_is_self (contact, TRUE); + g_clear_object (&self->priv->group_self_contact); self->priv->group_self_contact = contact; diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index 3a6f2567d..40e601f07 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -42,6 +42,7 @@ #include "telepathy-glib/capabilities-internal.h" #include "telepathy-glib/connection-internal.h" #include "telepathy-glib/connection-contact-list.h" +#include "telepathy-glib/contact-internal.h" #include "telepathy-glib/dbus-internal.h" #include "telepathy-glib/debug-internal.h" #include "telepathy-glib/proxy-internal.h" @@ -787,6 +788,10 @@ tp_connection_set_self_contact (TpConnection *self, { TpContact *tmp = self->priv->self_contact; + if (self->priv->self_contact != NULL) + _tp_contact_set_is_self (self->priv->self_contact, FALSE); + _tp_contact_set_is_self (contact, TRUE); + self->priv->self_contact = g_object_ref (contact); tp_clear_object (&tmp); g_object_notify ((GObject *) self, "self-contact"); diff --git a/telepathy-glib/contact-internal.h b/telepathy-glib/contact-internal.h index fde16cd19..9e0daadf8 100644 --- a/telepathy-glib/contact-internal.h +++ b/telepathy-glib/contact-internal.h @@ -44,6 +44,9 @@ void _tp_contact_set_subscription_states (TpContact *self, void _tp_contact_set_is_blocked (TpContact *self, gboolean is_blocked); +void _tp_contact_set_is_self (TpContact *self, + gboolean is_self); + G_END_DECLS #endif diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c index 1c7a00ef6..352113722 100644 --- a/telepathy-glib/contact.c +++ b/telepathy-glib/contact.c @@ -184,6 +184,7 @@ enum { PROP_PUBLISH_REQUEST, PROP_CONTACT_GROUPS, PROP_IS_BLOCKED, + PROP_IS_SELF, N_PROPS }; @@ -218,6 +219,7 @@ struct _TpContactPrivate { TpHandle handle; gchar *identifier; ContactFeatureFlags has_features; + gboolean is_self; /* aliasing */ gchar *alias; @@ -369,6 +371,33 @@ tp_contact_has_feature (TpContact *self, return ((self->priv->has_features & (1 << feature)) != 0); } +/** + * tp_contact_is_self: + * @self: a contact + * + * <!-- --> + * + * Returns: the value of #TpContact:is-self property + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_is_self (TpContact *self) +{ + g_return_val_if_fail (TP_IS_CONTACT (self), FALSE); + + return self->priv->is_self; +} + +void +_tp_contact_set_is_self (TpContact *self, + gboolean is_self) +{ + g_return_if_fail (TP_IS_CONTACT (self)); + + self->priv->is_self = is_self; + g_object_notify ((GObject *) self, "is-self"); +} + /** * tp_contact_get_alias: @@ -956,6 +985,10 @@ tp_contact_get_property (GObject *object, g_value_set_boolean (value, tp_contact_is_blocked (self)); break; + case PROP_IS_SELF: + g_value_set_boolean (value, tp_contact_is_self (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -1331,7 +1364,7 @@ tp_contact_class_init (TpContactClass *klass) g_object_class_install_property (object_class, PROP_CONTACT_GROUPS, param_spec); -/** + /** * TpContact:is-blocked: * * %TRUE if the contact has been blocked. @@ -1350,6 +1383,22 @@ tp_contact_class_init (TpContactClass *klass) g_object_class_install_property (object_class, PROP_IS_BLOCKED, param_spec); /** + * TpContact:is-self: + * + * This is %TRUE if the contact is set as + * #TpConnection's #TpConnection:self-contact or + * #TpChannel's #TpChannel:group-self-contact, %FALSE otherwise. + * + * Since: 0.UNRELEASED + */ + param_spec = g_param_spec_boolean ("is-self", + "is local user", + "TRUE if contact is local user", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_IS_SELF, param_spec); + + /** * TpContact::contact-groups-changed: * @contact: A #TpContact * @added: A #GStrv with added contact groups diff --git a/telepathy-glib/contact.h b/telepathy-glib/contact.h index f1dc7b608..16eb40290 100644 --- a/telepathy-glib/contact.h +++ b/telepathy-glib/contact.h @@ -77,6 +77,7 @@ TpConnection *tp_contact_get_connection (TpContact *self); TpHandle tp_contact_get_handle (TpContact *self); const gchar *tp_contact_get_identifier (TpContact *self); gboolean tp_contact_has_feature (TpContact *self, TpContactFeature feature); +gboolean tp_contact_is_self (TpContact *self); /* TP_CONTACT_FEATURE_ALIAS */ const gchar *tp_contact_get_alias (TpContact *self); diff --git a/tests/dbus/channel.c b/tests/dbus/channel.c index bb3235f88..37ea9f1bf 100644 --- a/tests/dbus/channel.c +++ b/tests/dbus/channel.c @@ -633,6 +633,7 @@ test_contacts (Test *test, contact = tp_channel_group_get_self_contact (test->channel_room); g_assert_cmpstr (tp_contact_get_identifier (contact), ==, "me@test.com"); + g_assert (tp_contact_is_self (contact)); /* Add a member in the room, assert that the member fetched its alias before * being signaled. */ diff --git a/tests/dbus/contacts.c b/tests/dbus/contacts.c index 617f0b97f..d57133b03 100644 --- a/tests/dbus/contacts.c +++ b/tests/dbus/contacts.c @@ -2851,6 +2851,7 @@ test_self_contact (Fixture *f, contact = tp_connection_get_self_contact (f->client_conn); g_assert (contact != NULL); g_assert (tp_contact_has_feature (contact, TP_CONTACT_FEATURE_ALIAS)); + g_assert (tp_contact_is_self (contact)); } static void |