[tracker-miner-chatlog] entity: Add identifier field



commit 48ac2107d21609843e321b4313750a1a0139cc0f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Dec 28 18:03:08 2015 +0100

    entity: Add identifier field
    
    And set it through all subclasses. Also, use the identifier as the
    key in entity pools, so we know for sure the key is unique. Fixes
    some errors produced from contacts having inconsistent casing
    (eg. "FooBar" vs "foobar") depending on those being created from
    TpContacts or TplEntities.

 src/contact.c       |    4 +++-
 src/contact.h       |    3 ++-
 src/conversation.c  |    1 +
 src/entity-pool.c   |    4 ++--
 src/entity.c        |   29 +++++++++++++++++++++++++++++
 src/entity.h        |    1 +
 src/helpers.c       |    7 ++++---
 src/logger-dumper.c |    7 ++++---
 src/room.c          |    1 +
 9 files changed, 47 insertions(+), 10 deletions(-)
---
diff --git a/src/contact.c b/src/contact.c
index 679d98e..7719689 100644
--- a/src/contact.c
+++ b/src/contact.c
@@ -41,11 +41,13 @@ tmc_contact_init (TmcContact *contact)
 
 TmcEntity *
 tmc_contact_new (const gchar *nickname,
-                 const gchar *protocol)
+                 const gchar *protocol,
+                 const gchar *identifier)
 {
        return g_object_new (TMC_TYPE_CONTACT,
                             "name", nickname,
                             "protocol", protocol,
+                            "identifier", identifier,
                             NULL);
 }
 
diff --git a/src/contact.h b/src/contact.h
index fe0bb04..892a203 100644
--- a/src/contact.h
+++ b/src/contact.h
@@ -29,7 +29,8 @@
 G_DECLARE_FINAL_TYPE (TmcContact, tmc_contact, TMC, CONTACT, TmcEntity)
 
 TmcEntity * tmc_contact_new      (const gchar *nickname,
-                                  const gchar *protocol);
+                                  const gchar *protocol,
+                                  const gchar *identifier);
 TmcEntity * tmc_contact_self_get (void);
 
 #endif /* __TMC_CONTACT_H__ */
diff --git a/src/conversation.c b/src/conversation.c
index 63b1cae..7d5e867 100644
--- a/src/conversation.c
+++ b/src/conversation.c
@@ -121,6 +121,7 @@ tmc_conversation_new (TmcContact *peer)
        return g_object_new (TMC_TYPE_CONVERSATION,
                             "name", tmc_entity_get_name (TMC_ENTITY (peer)),
                             "protocol", tmc_entity_get_protocol (TMC_ENTITY (peer)),
+                            "identifier", tmc_entity_get_identifier (TMC_ENTITY (peer)),
                             "peer", peer,
                             NULL);
 }
diff --git a/src/entity-pool.c b/src/entity-pool.c
index f90f1f6..fa68959 100644
--- a/src/entity-pool.c
+++ b/src/entity-pool.c
@@ -80,7 +80,7 @@ tmc_entity_pool_add (TmcEntityPool *pool,
        priv = tmc_entity_pool_get_instance_private (pool);
 
        g_hash_table_insert (priv->entities,
-                            (gpointer) tmc_entity_get_name (entity),
+                            (gpointer) tmc_entity_get_identifier (entity),
                             entity);
 }
 
@@ -96,7 +96,7 @@ tmc_entity_pool_remove (TmcEntityPool *pool,
        priv = tmc_entity_pool_get_instance_private (pool);
 
        g_hash_table_remove (priv->entities,
-                            tmc_entity_get_name (entity));
+                            tmc_entity_get_identifier (entity));
 }
 
 TmcEntity *
diff --git a/src/entity.c b/src/entity.c
index 0b080fb..0ad41a5 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -26,12 +26,14 @@ typedef struct _TmcEntityPrivate TmcEntityPrivate;
 struct _TmcEntityPrivate {
        gchar *name;
        gchar *protocol;
+       gchar *identifier;
 };
 
 enum {
        PROP_0,
        PROP_NAME,
        PROP_PROTOCOL,
+       PROP_IDENTIFIER,
        PROP_LAST
 };
 
@@ -47,6 +49,7 @@ tmc_entity_finalize (GObject *object)
 
        g_clear_pointer (&priv->name, g_free);
        g_clear_pointer (&priv->protocol, g_free);
+       g_clear_pointer (&priv->identifier, g_free);
 
        G_OBJECT_CLASS (tmc_entity_parent_class)->finalize (object);
 }
@@ -69,6 +72,10 @@ tmc_entity_set_property (GObject      *object,
                g_clear_pointer (&priv->protocol, g_free);
                priv->protocol = g_value_dup_string (value);
                break;
+       case PROP_IDENTIFIER:
+               g_clear_pointer (&priv->identifier, g_free);
+               priv->identifier = g_value_dup_string (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        }
@@ -90,6 +97,9 @@ tmc_entity_get_property (GObject    *object,
        case PROP_PROTOCOL:
                g_value_set_string (value, priv->protocol);
                break;
+       case PROP_IDENTIFIER:
+               g_value_set_string (value, priv->identifier);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        }
@@ -118,6 +128,13 @@ tmc_entity_class_init (TmcEntityClass *klass)
                                     NULL,
                                     G_PARAM_READWRITE |
                                     G_PARAM_CONSTRUCT_ONLY);
+       props[PROP_IDENTIFIER] =
+               g_param_spec_string ("identifier",
+                                    "Identifier",
+                                    "Identifier",
+                                    NULL,
+                                    G_PARAM_READWRITE |
+                                    G_PARAM_CONSTRUCT_ONLY);
 
        g_object_class_install_properties (object_class, PROP_LAST, props);
 }
@@ -150,3 +167,15 @@ tmc_entity_get_protocol (TmcEntity *entity)
 
        return priv->protocol;
 }
+
+const gchar *
+tmc_entity_get_identifier (TmcEntity *entity)
+{
+       TmcEntityPrivate *priv;
+
+       g_return_val_if_fail (TMC_IS_ENTITY (entity), NULL);
+
+       priv = tmc_entity_get_instance_private (entity);
+
+       return priv->identifier;
+}
diff --git a/src/entity.h b/src/entity.h
index 02f8b8f..a1cdb84 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -34,5 +34,6 @@ struct _TmcEntityClass {
 
 const gchar * tmc_entity_get_name     (TmcEntity *entity);
 const gchar * tmc_entity_get_protocol (TmcEntity *entity);
+const gchar * tmc_entity_get_identifier (TmcEntity *entity);
 
 #endif /* __TMC_ENTITY_H__ */
diff --git a/src/helpers.c b/src/helpers.c
index 08772da..48af554 100644
--- a/src/helpers.c
+++ b/src/helpers.c
@@ -32,16 +32,17 @@ tmc_ensure_contact (TpContact *contact)
        TmcEntity *entity;
        const gchar *name;
 
-       name = tp_contact_get_alias (contact);
+       name = tp_contact_get_identifier (contact);
        entity = tmc_entity_pool_lookup (contacts, name);
 
        if (!entity) {
                TpConnection *connection;
-               const gchar *protocol;
+               const gchar *protocol, *identifier;
 
                connection = tp_contact_get_connection (contact);
                protocol = tp_connection_get_protocol_name (connection);
-               entity = tmc_contact_new (name, protocol);
+               identifier = tp_contact_get_identifier (contact);
+               entity = tmc_contact_new (name, protocol, identifier);
                tmc_entity_pool_add (contacts, entity);
        }
 
diff --git a/src/logger-dumper.c b/src/logger-dumper.c
index f58ce34..4c96825 100644
--- a/src/logger-dumper.c
+++ b/src/logger-dumper.c
@@ -148,11 +148,12 @@ translate_contact (TplEntity *entity)
        case TPL_ENTITY_SELF:
                return tmc_contact_self_get ();
        case TPL_ENTITY_CONTACT:
-               contact = tmc_entity_pool_lookup (pool, tpl_entity_get_alias (entity));
+               contact = tmc_entity_pool_lookup (pool, tpl_entity_get_identifier (entity));
 
                if (!contact) {
                        contact = tmc_contact_new (tpl_entity_get_alias (entity),
-                                                  "irc");
+                                                  "irc",
+                                                  tpl_entity_get_identifier (entity));
                        tmc_entity_pool_add (pool, contact);
                }
 
@@ -166,7 +167,7 @@ translate_channel (QueryOperation *op)
        TmcEntityPool *pool = tmc_entity_pool_channels_get ();
        TmcEntity *channel;
 
-       channel = tmc_entity_pool_lookup (pool, tpl_entity_get_alias (op->entity));
+       channel = tmc_entity_pool_lookup (pool, tpl_entity_get_identifier (op->entity));
 
        if (!channel) {
                switch (tpl_entity_get_entity_type (op->entity)) {
diff --git a/src/room.c b/src/room.c
index 5bf2386..addfb88 100644
--- a/src/room.c
+++ b/src/room.c
@@ -46,5 +46,6 @@ tmc_room_new (const gchar *name,
        return g_object_new (TMC_TYPE_ROOM,
                             "name", name,
                             "protocol", protocol,
+                            "identifier", name,
                             NULL);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]