summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-02-22 18:44:15 -0500
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-02-22 18:44:15 -0500
commit2fc6dc7fe60e1ea689557d464f45ceea2119cd73 (patch)
tree19030a7503d9edb53b5ec1cd1e9c2d537c7c2ebf
parentb24f7974e6afb33e03b986339fab4595b07e4419 (diff)
downloadtelepathy-logger-2fc6dc7fe60e1ea689557d464f45ceea2119cd73.tar.gz
Make TplEntity constructors public
Implement a generic constructor along with making public all TplEntity constructors. This is required now that the LogManager API require TplEntity object instead of id/is_room pair.
-rw-r--r--telepathy-logger/dbus-service.c5
-rw-r--r--telepathy-logger/entity-internal.h3
-rw-r--r--telepathy-logger/entity.c73
-rw-r--r--telepathy-logger/entity.h7
-rw-r--r--telepathy-logger/log-store-pidgin.c34
-rw-r--r--telepathy-logger/log-store-sqlite.c6
-rw-r--r--telepathy-logger/log-store-xml.c47
-rw-r--r--telepathy-logger/text-channel.c12
-rw-r--r--tests/dbus/test-entity.c23
-rw-r--r--tests/dbus/test-searches.c4
-rw-r--r--tests/dbus/test-tpl-log-store-pidgin.c17
-rw-r--r--tests/dbus/test-tpl-log-store-xml.c11
12 files changed, 105 insertions, 137 deletions
diff --git a/telepathy-logger/dbus-service.c b/telepathy-logger/dbus-service.c
index 16d2a95..536733d 100644
--- a/telepathy-logger/dbus-service.c
+++ b/telepathy-logger/dbus-service.c
@@ -830,10 +830,7 @@ tpl_dbus_service_clear_entity (TplSvcLogger *logger,
goto out;
}
- entity = g_object_new (TPL_TYPE_ENTITY,
- "type", type,
- "identifier", identifier,
- NULL);
+ entity = tpl_entity_new (identifier, type, NULL, NULL);
/* We want to clear synchronously to avoid concurent write */
_tpl_log_manager_clear_entity (self->priv->manager, account, entity);
diff --git a/telepathy-logger/entity-internal.h b/telepathy-logger/entity-internal.h
index ab29e47..f8a3ade 100644
--- a/telepathy-logger/entity-internal.h
+++ b/telepathy-logger/entity-internal.h
@@ -37,8 +37,5 @@ typedef struct
GObjectClass parent_class;
} TplEntityClass;
-TplEntity *_tpl_entity_new_from_tp_contact (TpContact *contact, TplEntityType type);
-TplEntity *_tpl_entity_new_from_room_id (const gchar *room_id);
-
G_END_DECLS
#endif // __TPL_ENTITY_INTERNAL_H__
diff --git a/telepathy-logger/entity.c b/telepathy-logger/entity.c
index 4b09088..bb7fd12 100644
--- a/telepathy-logger/entity.c
+++ b/telepathy-logger/entity.c
@@ -210,33 +210,58 @@ tpl_entity_init (TplEntity *self)
self->priv = priv;
}
-
-/* _tpl_entity_new_from_room_id:
- * @room_id: the room id which will be the identifier for the entity
- *
- * Return a TplEntity instance with identifier, alias copied from
- * @room_id. It also sets %TPL_ENTITY_ROOM as type for
- * the #TplEntity returned.
- */
TplEntity *
-_tpl_entity_new_from_room_id (const gchar *room_id)
+tpl_entity_new (const gchar *id,
+ TplEntityType type,
+ const gchar *alias,
+ const gchar *avatar_token)
{
TplEntity *ret;
- g_return_val_if_fail (room_id != NULL, NULL);
+ g_return_val_if_fail (!TPL_STR_EMPTY (id), NULL);
ret = g_object_new (TPL_TYPE_ENTITY,
- "type", TPL_ENTITY_ROOM,
- "identifier", room_id,
- "alias", room_id,
+ "identifier", id,
+ "type", type,
+ "alias", alias == NULL ? id : alias,
+ "avatar-token", avatar_token,
NULL);
- DEBUG ("Chatroom id: %s", room_id);
+ switch (type)
+ {
+ case TPL_ENTITY_ROOM:
+ DEBUG ("Room id: %s", id);
+ break;
+ case TPL_ENTITY_CONTACT:
+ DEBUG ("Contact id: %s, tok: %s", id, avatar_token);
+ break;
+ case TPL_ENTITY_SELF:
+ DEBUG ("Self id: %s, tok: %s", id, avatar_token);
+ break;
+ default:
+ g_warning ("Unkown entity type %i", type);
+ g_object_unref (ret);
+ ret = NULL;
+ }
+
return ret;
}
+/** tpl_entity_new_from_room_id:
+ * @room_id: the room id which will be the identifier for the entity
+ *
+ * Return a TplEntity instance with identifier, alias copied from
+ * @room_id. It also sets %TPL_ENTITY_ROOM as type for
+ * the #TplEntity returned.
+ */
+TplEntity *
+tpl_entity_new_from_room_id (const gchar *room_id)
+{
+ return tpl_entity_new (room_id, TPL_ENTITY_ROOM, NULL, NULL);
+}
+
-/* _tpl_entity_new_from_tp_contact:
+/** tpl_entity_new_from_tp_contact:
* @contact: the TpContact instance to create the TplEntity from
* @type: the #TplEntity type
*
@@ -246,25 +271,17 @@ _tpl_entity_new_from_room_id (const gchar *room_id)
* %TPL_ENTITY_SELF are accepted.
*/
TplEntity *
-_tpl_entity_new_from_tp_contact (TpContact *contact,
+tpl_entity_new_from_tp_contact (TpContact *contact,
TplEntityType type)
{
- TplEntity *ret;
-
g_return_val_if_fail (TP_IS_CONTACT (contact), NULL);
g_return_val_if_fail (type == TPL_ENTITY_CONTACT || type == TPL_ENTITY_SELF,
NULL);
- ret = g_object_new (TPL_TYPE_ENTITY,
- "type", type,
- "identifier", tp_contact_get_identifier (contact),
- "alias", tp_contact_get_alias (contact),
- "avatar-token", tp_contact_get_avatar_token (contact),
- NULL);
-
- DEBUG ("ID: %s, TOK: %s", tpl_entity_get_identifier (ret),
- tpl_entity_get_avatar_token (ret));
- return ret;
+ return tpl_entity_new (tp_contact_get_identifier (contact),
+ type,
+ tp_contact_get_alias (contact),
+ tp_contact_get_avatar_token (contact));
}
diff --git a/telepathy-logger/entity.h b/telepathy-logger/entity.h
index 809186f..474e6a9 100644
--- a/telepathy-logger/entity.h
+++ b/telepathy-logger/entity.h
@@ -67,6 +67,13 @@ typedef struct
GType tpl_entity_get_type (void);
+TplEntity *tpl_entity_new (const gchar *id,
+ TplEntityType type,
+ const gchar *alias,
+ const gchar *avatar_token);
+TplEntity *tpl_entity_new_from_tp_contact (TpContact *contact, TplEntityType type);
+TplEntity *tpl_entity_new_from_room_id (const gchar *room_id);
+
const gchar *tpl_entity_get_alias (TplEntity *self);
const gchar *tpl_entity_get_identifier (TplEntity *self);
TplEntityType tpl_entity_get_entity_type (TplEntity *self);
diff --git a/telepathy-logger/log-store-pidgin.c b/telepathy-logger/log-store-pidgin.c
index 2733cf8..4ec5fd3 100644
--- a/telepathy-logger/log-store-pidgin.c
+++ b/telepathy-logger/log-store-pidgin.c
@@ -621,11 +621,7 @@ log_store_pidgin_search_hit_new (TplLogStore *self,
else
id = g_strdup (strv[len-2]);
- hit->target = g_object_new (TPL_TYPE_ENTITY,
- "identifier", id,
- "alias", id,
- "type", type,
- NULL);
+ hit->target = tpl_entity_new (id, type, NULL, NULL);
g_free (id);
@@ -835,11 +831,10 @@ log_store_pidgin_get_events_for_files (TplLogStore *self,
/* FIXME: in text format (is_html==FALSE) there is no actual way to
* understand what type the entity is, it might lead to inaccuracy,
* as is_user will be always FALSE */
- sender = g_object_new (TPL_TYPE_ENTITY,
- "identifier", is_user ? own_user : sender_name,
- "type", is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT,
- "alias", sender_name,
- NULL);
+ sender = tpl_entity_new (
+ is_user ? own_user : sender_name,
+ is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT,
+ sender_name, NULL);
/* FIXME: in text format it's not possible to guess who is the
* receiver (unless we are in a room). In this case the receiver will
@@ -866,11 +861,8 @@ log_store_pidgin_get_events_for_files (TplLogStore *self,
receiver_type = TPL_ENTITY_SELF;
}
- receiver = g_object_new (TPL_TYPE_ENTITY,
- "identifier", receiver_id,
- "type", receiver_type,
- "alias", receiver_id,
- NULL);
+ receiver = tpl_entity_new (receiver_id, receiver_type,
+ NULL, NULL);
}
@@ -1074,19 +1066,11 @@ log_store_pidgin_get_entities_for_dir (TplLogStore *self,
if (g_str_has_suffix (name, ".chat"))
{
gchar *id = g_strndup (name, strlen (name) - 5);
- entity = g_object_new (TPL_TYPE_ENTITY,
- "identifier", id,
- "alias", id,
- "type", TPL_ENTITY_ROOM,
- NULL);
+ entity = tpl_entity_new_from_room_id (id);
g_free (id);
}
else
- entity = g_object_new (TPL_TYPE_ENTITY,
- "identifier", name,
- "alias", name,
- "type", TPL_ENTITY_CONTACT,
- NULL);
+ entity = tpl_entity_new (name, TPL_ENTITY_CONTACT, NULL, NULL);
entities = g_list_prepend (entities, entity);
}
diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c
index 41c23f3..90668ea 100644
--- a/telepathy-logger/log-store-sqlite.c
+++ b/telepathy-logger/log-store-sqlite.c
@@ -1165,11 +1165,7 @@ tpl_log_store_sqlite_get_entities (TplLogStore *self,
DEBUG ("identifier = %s, chatroom = %i", identifier, chatroom);
- entity = g_object_new (TPL_TYPE_ENTITY,
- "identifier", identifier,
- "type", type,
- "alias", identifier, /* FIXME Faking alias with identifier */
- NULL);
+ entity = tpl_entity_new (identifier, type, NULL, NULL);
list = g_list_prepend (list, entity);
}
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index d7caa9f..f100790 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -738,13 +738,9 @@ log_store_xml_search_hit_new (TplLogStoreXml *self,
g_list_free (accounts);
if (is_chatroom)
- target = _tpl_entity_new_from_room_id (chat_id);
+ target = tpl_entity_new_from_room_id (chat_id);
else
- target = g_object_new (TPL_TYPE_ENTITY,
- "identifier", chat_id,
- "type", TPL_ENTITY_CONTACT,
- "alias", chat_id,
- NULL);
+ target = tpl_entity_new (chat_id, TPL_ENTITY_CONTACT, NULL, NULL);
hit = _tpl_log_manager_search_hit_new (account, target, date);
@@ -873,30 +869,17 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self,
timestamp = _tpl_time_parse (time_str);
- if (is_user || is_room)
- {
- receiver = g_object_new (TPL_TYPE_ENTITY,
- "identifier", target_id,
- "type", is_room ? TPL_ENTITY_ROOM : TPL_ENTITY_CONTACT,
- "alias", target_id,
- NULL);
- }
+ if (is_room)
+ receiver = tpl_entity_new_from_room_id (target_id);
+ else if (is_user)
+ receiver = tpl_entity_new (target_id, TPL_ENTITY_CONTACT, NULL, NULL);
else
- {
- const gchar *alias = tp_account_get_nickname (account);
- receiver = g_object_new (TPL_TYPE_ENTITY,
- "identifier", self_id,
- "type", TPL_ENTITY_SELF,
- "alias", alias == NULL ? self_id : alias,
- NULL);
- }
+ receiver = tpl_entity_new (self_id, TPL_ENTITY_SELF,
+ tp_account_get_nickname (account), NULL);
- sender = g_object_new (TPL_TYPE_ENTITY,
- "identifier", sender_id,
- "type", is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT,
- "alias", sender_name,
- "avatar-token", sender_avatar_token,
- NULL);
+ sender = tpl_entity_new (sender_id,
+ is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT,
+ sender_name, sender_avatar_token);
if (self->priv->empathy_legacy)
{
@@ -1127,13 +1110,9 @@ log_store_xml_get_entities_for_dir (TplLogStoreXml *self,
}
if (is_chatroom)
- entity = _tpl_entity_new_from_room_id (name);
+ entity = tpl_entity_new_from_room_id (name);
else
- entity = g_object_new (TPL_TYPE_ENTITY,
- "identifier", name,
- "type", TPL_ENTITY_CONTACT,
- "alias", name, /* FIXME Faking alias with identifier */
- NULL);
+ entity = tpl_entity_new (name, TPL_ENTITY_CONTACT, NULL, NULL);
entities = g_list_prepend (entities, entity);
}
diff --git a/telepathy-logger/text-channel.c b/telepathy-logger/text-channel.c
index 28abfe2..1645510 100644
--- a/telepathy-logger/text-channel.c
+++ b/telepathy-logger/text-channel.c
@@ -1074,7 +1074,7 @@ on_sent_signal_cb (TpChannel *proxy,
/* Initialize data for TplEntity */
me = _tpl_text_channel_get_my_contact (tpl_text);
- sender = _tpl_entity_new_from_tp_contact (me, TPL_ENTITY_SELF);
+ sender = tpl_entity_new_from_tp_contact (me, TPL_ENTITY_SELF);
if (!_tpl_text_channel_is_chatroom (tpl_text))
{
@@ -1085,7 +1085,7 @@ on_sent_signal_cb (TpChannel *proxy,
GUINT_TO_POINTER (handle));
g_assert (remote != NULL);
- receiver = _tpl_entity_new_from_tp_contact (remote, TPL_ENTITY_CONTACT);
+ receiver = tpl_entity_new_from_tp_contact (remote, TPL_ENTITY_CONTACT);
DEBUG ("sent:\n\tlog_id=\"%s\"\n\tto=\"%s "
"(%s)\"\n\tfrom=\"%s (%s)\"\n\tmsg=\"%s\"",
@@ -1099,7 +1099,7 @@ on_sent_signal_cb (TpChannel *proxy,
}
else
{
- receiver = _tpl_entity_new_from_room_id (
+ receiver = tpl_entity_new_from_room_id (
_tpl_text_channel_get_chatroom_id (tpl_text));
DEBUG ("sent:\n\tlog_id=\"%s\"\n\tto "
@@ -1166,18 +1166,18 @@ keepon_on_receiving_signal (TplTextChannel *tpl_text,
TplEntity *sender;
TplEntity *receiver;
- sender = _tpl_entity_new_from_tp_contact (remote, TPL_ENTITY_CONTACT);
+ sender = tpl_entity_new_from_tp_contact (remote, TPL_ENTITY_CONTACT);
if (_tpl_text_channel_is_chatroom (tpl_text))
{
const gchar *receiver_id = _tpl_text_channel_get_chatroom_id (tpl_text);
- receiver = _tpl_entity_new_from_room_id (receiver_id);
+ receiver = tpl_entity_new_from_room_id (receiver_id);
}
else
{
TpContact *me;
me = _tpl_text_channel_get_my_contact (tpl_text);
- receiver = _tpl_entity_new_from_tp_contact (me, TPL_ENTITY_SELF);
+ receiver = tpl_entity_new_from_tp_contact (me, TPL_ENTITY_SELF);
}
/* Initialize TplTextEvent */
diff --git a/tests/dbus/test-entity.c b/tests/dbus/test-entity.c
index 5877a5d..0f7cda4 100644
--- a/tests/dbus/test-entity.c
+++ b/tests/dbus/test-entity.c
@@ -11,12 +11,8 @@ test_entity_instantiation (void)
{
TplEntity *entity;
- entity = g_object_new (TPL_TYPE_ENTITY,
- "identifier", "my-identifier",
- "type", TPL_ENTITY_CONTACT,
- "alias", "my-alias",
- "avatar-token", "my-token",
- NULL);
+ entity = tpl_entity_new ("my-identifier", TPL_ENTITY_CONTACT,
+ "my-alias", "my-token");
g_assert_cmpstr (tpl_entity_get_identifier (entity), ==, "my-identifier");
g_assert (tpl_entity_get_entity_type (entity) == TPL_ENTITY_CONTACT);
@@ -24,6 +20,15 @@ test_entity_instantiation (void)
g_assert_cmpstr (tpl_entity_get_avatar_token (entity), ==, "my-token");
g_object_unref (entity);
+
+ /* Check that identifier is copied in absence of ID */
+ entity = tpl_entity_new ("my-identifier", TPL_ENTITY_CONTACT,
+ NULL, NULL);
+
+ g_assert_cmpstr (tpl_entity_get_alias (entity), ==, "my-identifier");
+ g_assert (tpl_entity_get_avatar_token (entity) == NULL);
+
+ g_object_unref (entity);
}
static void
@@ -31,7 +36,7 @@ test_entity_instantiation_from_room_id (void)
{
TplEntity *entity;
- entity = _tpl_entity_new_from_room_id ("my-room-id");
+ entity = tpl_entity_new_from_room_id ("my-room-id");
g_assert_cmpstr (tpl_entity_get_identifier (entity), ==, "my-room-id");
g_assert (tpl_entity_get_entity_type (entity) == TPL_ENTITY_ROOM);
@@ -115,7 +120,7 @@ test_entity_instantiation_from_tp_contact (void)
NULL, NULL);
g_main_loop_run (result.loop);
- entity = _tpl_entity_new_from_tp_contact (result.contacts[0],
+ entity = tpl_entity_new_from_tp_contact (result.contacts[0],
TPL_ENTITY_SELF);
g_assert_cmpstr (tpl_entity_get_identifier (entity), ==, "alice");
@@ -124,7 +129,7 @@ test_entity_instantiation_from_tp_contact (void)
g_assert_cmpstr (tpl_entity_get_avatar_token (entity), ==, avatar_tokens[0]);
g_object_unref (entity);
- entity = _tpl_entity_new_from_tp_contact (result.contacts[1],
+ entity = tpl_entity_new_from_tp_contact (result.contacts[1],
TPL_ENTITY_CONTACT);
g_assert_cmpstr (tpl_entity_get_identifier (entity), ==, "bob");
diff --git a/tests/dbus/test-searches.c b/tests/dbus/test-searches.c
index 422619b..dbf3f56 100644
--- a/tests/dbus/test-searches.c
+++ b/tests/dbus/test-searches.c
@@ -94,9 +94,7 @@ test_get_dates (TestCaseFixture *fixture,
GList *ret, *loc;
TplEntity *entity;
- entity = g_object_new (TPL_TYPE_ENTITY,
- "identifier", ID,
- "type", TPL_ENTITY_CONTACT);
+ entity = tpl_entity_new (ID, TPL_ENTITY_CONTACT, NULL, NULL);
ret = _tpl_log_manager_get_dates (fixture->manager, fixture->account, entity);
g_object_unref (entity);
diff --git a/tests/dbus/test-tpl-log-store-pidgin.c b/tests/dbus/test-tpl-log-store-pidgin.c
index 2ff9e9b..0a6435f 100644
--- a/tests/dbus/test-tpl-log-store-pidgin.c
+++ b/tests/dbus/test-tpl-log-store-pidgin.c
@@ -174,20 +174,13 @@ setup (PidginTestCaseFixture* fixture,
"testmode", TRUE,
NULL);
- fixture->room = g_object_new (TPL_TYPE_ENTITY,
- "identifier", "test@conference.collabora.co.uk",
- "type", TPL_ENTITY_ROOM,
- NULL);
+ fixture->room = tpl_entity_new_from_room_id (
+ "test@conference.collabora.co.uk");
- fixture->irc_room = g_object_new (TPL_TYPE_ENTITY,
- "identifier", "#telepathy",
- "type", TPL_ENTITY_ROOM,
- NULL);
+ fixture->irc_room = tpl_entity_new_from_room_id ("#telepathy");
- fixture->contact = g_object_new (TPL_TYPE_ENTITY,
- "identifier", "user2@collabora.co.uk",
- "type", TPL_ENTITY_CONTACT,
- NULL);
+ fixture->contact = tpl_entity_new ("user2@collabora.co.uk",
+ TPL_ENTITY_CONTACT, NULL, NULL);
if (user_data != NULL)
setup_service (fixture, user_data);
diff --git a/tests/dbus/test-tpl-log-store-xml.c b/tests/dbus/test-tpl-log-store-xml.c
index 5069ecd..7090584 100644
--- a/tests/dbus/test-tpl-log-store-xml.c
+++ b/tests/dbus/test-tpl-log-store-xml.c
@@ -207,15 +207,10 @@ test_clear_entity (XmlTestCaseFixture *fixture,
g_assert (account != NULL);
if (is_room)
- entity = g_object_new (TPL_TYPE_ENTITY,
- "type", TPL_ENTITY_ROOM,
- "identifier", "meego@conference.collabora.co.uk",
- NULL);
+ entity = tpl_entity_new_from_room_id ("meego@conference.collabora.co.uk");
else
- entity = g_object_new (TPL_TYPE_ENTITY,
- "type", TPL_ENTITY_CONTACT,
- "identifier", "derek.foreman@collabora.co.uk",
- NULL);
+ entity = tpl_entity_new ("derek.foreman@collabora.co.uk",
+ TPL_ENTITY_CONTACT, NULL, NULL);
_tpl_log_store_clear_entity (TPL_LOG_STORE (fixture->store), account, entity);
g_object_unref (account);