telepathy-glib: Add tp_contact_is_self()

Xavier Claessens xclaesse at kemper.freedesktop.org
Thu May 3 01:34:42 PDT 2012


Module: telepathy-glib
Branch: master
Commit: aa611fb0084b0c94f5e3b3c9c7e5ae30b8556c67
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=aa611fb0084b0c94f5e3b3c9c7e5ae30b8556c67

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Wed May  2 17:24:58 2012 +0200

Add tp_contact_is_self()

---

 docs/reference/telepathy-glib-sections.txt |    1 +
 telepathy-glib/channel-contacts.c          |    6 +++
 telepathy-glib/connection.c                |    5 +++
 telepathy-glib/contact-internal.h          |    3 ++
 telepathy-glib/contact.c                   |   51 +++++++++++++++++++++++++++-
 telepathy-glib/contact.h                   |    1 +
 tests/dbus/channel.c                       |    1 +
 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 27818ab..b7a81a4 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 6896a46..dd65b09 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 3a6f256..40e601f 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 fde16cd..9e0daad 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 1c7a00e..3521137 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 f1dc7b6..16eb402 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 bb3235f..37ea9f1 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 at 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 617f0b9..d57133b 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



More information about the telepathy-commits mailing list