summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-06 14:55:13 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-08 13:43:40 (GMT)
commitef6a9b7ecce489f18a1912789f7d303ff73d5732 (patch)
treea8bb99b985cc56ee4751e27a2d70458766005d40
parent0005ac1a1cf3affd0a49ed53af8de89705858fb1 (diff)
downloadtraprain-ef6a9b7ecce489f18a1912789f7d303ff73d5732.tar.gz
traprain-ef6a9b7ecce489f18a1912789f7d303ff73d5732.tar.xz
client: use a _TrpLanguagesMap to store the titles
First step to start using the languages map in the client side API. _TrpLanguagesMap is a more efficient container saving us from the GHashTable overhead and not dupping the language strings. Signed-off-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk> Differential Revision: https://phabricator.apertis.org/D4202
-rw-r--r--traprain-client/route-internal.h2
-rw-r--r--traprain-client/route.c27
2 files changed, 15 insertions, 14 deletions
diff --git a/traprain-client/route-internal.h b/traprain-client/route-internal.h
index 75c4bec..6b52278 100644
--- a/traprain-client/route-internal.h
+++ b/traprain-client/route-internal.h
@@ -14,6 +14,7 @@
#include "route.h"
#include "dbus/org.apertis.Navigation1.h"
+#include "traprain-common/languages-map-internal.h"
G_BEGIN_DECLS
@@ -24,6 +25,7 @@ struct _TrpClientRoute
TrpOrgApertisNavigation1Route *proxy; /* owned */
GHashTable /* <guint> -> <owned GHashTable *> */ *geo_desc; /* owned */
+ _TrpLanguagesMap *title; /* owned */
/* ID used by TrpClientNavigation to identify route objects which are no
* longer exposed by the service and so can be destroyed. */
diff --git a/traprain-client/route.c b/traprain-client/route.c
index c35aec5..bbce8f6 100644
--- a/traprain-client/route.c
+++ b/traprain-client/route.c
@@ -38,6 +38,7 @@ trp_client_route_dispose (GObject *object)
g_clear_object (&self->proxy);
g_clear_pointer (&self->geo_desc, g_hash_table_unref);
+ g_clear_pointer (&self->title, g_array_unref);
G_OBJECT_CLASS (trp_client_route_parent_class)
->dispose (object);
@@ -121,15 +122,9 @@ build_ass_hash_table (GVariant *v)
GHashTable *
trp_client_route_get_titles (TrpClientRoute *self)
{
- GHashTable *titles;
- GVariant *v;
-
g_return_val_if_fail (TRP_CLIENT_IS_ROUTE (self), NULL);
- v = trp_org_apertis_navigation1_route_get_title (self->proxy);
- titles = build_ass_hash_table (v);
-
- return titles;
+ return _trp_languages_map_to_hash (self->title);
}
/**
@@ -145,16 +140,10 @@ trp_client_route_get_titles (TrpClientRoute *self)
const gchar *
trp_client_route_get_title (TrpClientRoute *self, const gchar *language)
{
- GVariant *v;
- const gchar *title = NULL;
-
g_return_val_if_fail (TRP_CLIENT_IS_ROUTE (self), NULL);
g_return_val_if_fail (language != NULL, NULL);
- v = trp_org_apertis_navigation1_route_get_title (self->proxy);
-
- g_variant_lookup (v, language, "&s", &title);
- return title;
+ return _trp_languages_map_lookup (self->title, language);
}
/**
@@ -288,6 +277,15 @@ build_geometry_descriptions (TrpClientRoute *self)
return result;
}
+static _TrpLanguagesMap *
+build_title (TrpClientRoute *self)
+{
+ GVariant *v;
+
+ v = trp_org_apertis_navigation1_route_get_title (self->proxy);
+ return _trp_languages_map_new_from_variant (v);
+}
+
TrpClientRoute *
_trp_client_route_new (TrpOrgApertisNavigation1Route *proxy)
{
@@ -299,6 +297,7 @@ _trp_client_route_new (TrpOrgApertisNavigation1Route *proxy)
* the API */
self->proxy = g_object_ref (proxy);
+ self->title = build_title (self);
/* Convert all the geometry descriptions variants to array to save us from
* iterating on all of them in trp_client_route_get_segment(). */
self->geo_desc = build_geometry_descriptions (self);