summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-22 19:21:48 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-25 14:03:04 -0400
commit29ee71548ed00054947ae76022f0fabc6602cdd5 (patch)
tree5c4ddd503c0b61163a75fde6668de7da5f8b286e
parent8fb76e8733f2719c3f64e9baa0801ee9ef257798 (diff)
downloadtelepathy-logger-29ee71548ed00054947ae76022f0fabc6602cdd5.tar.gz
Add private helper to serialize TplEntityType into a string
-rw-r--r--telepathy-logger/entity-internal.h2
-rw-r--r--telepathy-logger/entity.c29
2 files changed, 31 insertions, 0 deletions
diff --git a/telepathy-logger/entity-internal.h b/telepathy-logger/entity-internal.h
index c89d82c..4058a25 100644
--- a/telepathy-logger/entity-internal.h
+++ b/telepathy-logger/entity-internal.h
@@ -38,6 +38,8 @@ typedef struct
} TplEntityClass;
gint _tpl_entity_compare (TplEntity *e1, TplEntity *e2);
+TplEntityType _tpl_entity_type_from_str (const gchar *type_str);
+const gchar * _tpl_entity_type_to_str (TplEntityType type);
G_END_DECLS
#endif // __TPL_ENTITY_INTERNAL_H__
diff --git a/telepathy-logger/entity.c b/telepathy-logger/entity.c
index f816e8d..504e0c5 100644
--- a/telepathy-logger/entity.c
+++ b/telepathy-logger/entity.c
@@ -62,6 +62,14 @@ enum
PROP_AVATAR_TOKEN
};
+static const gchar * entity_types[] = {
+ "unknown",
+ "contact",
+ "room",
+ "self"
+};
+
+
static void
tpl_entity_finalize (GObject *obj)
{
@@ -379,3 +387,24 @@ _tpl_entity_compare (TplEntity *a,
else
return 1;
}
+
+
+TplEntityType
+_tpl_entity_type_from_str (const gchar *type_str)
+{
+ guint i;
+ for (i = 0; i < G_N_ELEMENTS (entity_types); ++i)
+ if (!tp_strdiff (type_str, entity_types[i]))
+ return (TplEntityType) i;
+
+ /* default case */
+ return TPL_ENTITY_UNKNOWN;
+}
+
+
+const gchar *
+_tpl_entity_type_to_str (TplEntityType type)
+{
+ g_return_val_if_fail (G_N_ELEMENTS (entity_types) >= type, "unknown");
+ return entity_types[type];
+}