summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-06 15:55:46 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-08 13:43:49 (GMT)
commit59151add78160af40f9230663a5bfab2c0e3cf6c (patch)
treee62d45b7b37f733a3bc437a116495839487f2105
parent975e149bf499f2a58201d00d511b7c89c0e32484 (diff)
downloadtraprain-59151add78160af40f9230663a5bfab2c0e3cf6c.tar.gz
traprain-59151add78160af40f9230663a5bfab2c0e3cf6c.tar.xz
client: expose segment descriptions using TrpLanguagesMap
Getting rid of the 'geo_desc_hash' temporary hack. 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/D4207
-rw-r--r--tests/test-helper.c32
-rw-r--r--traprain-client/route.c28
-rw-r--r--traprain-client/route.h2
3 files changed, 26 insertions, 36 deletions
diff --git a/tests/test-helper.c b/tests/test-helper.c
index a8f0d05..232efa6 100644
--- a/tests/test-helper.c
+++ b/tests/test-helper.c
@@ -122,7 +122,7 @@ void
check_first_client_route (TrpClientRoute *route)
{
gdouble lat, lon;
- GHashTable *desc;
+ TrpLanguagesMap *desc;
const gchar *d;
check_client_route (route, FST_ROUTE_DISTANCE, FST_ROUTE_TIME, FST_ROUTE_TITLE_EN, FST_ROUTE_TITLE_FR, 2);
@@ -130,9 +130,9 @@ check_first_client_route (TrpClientRoute *route)
trp_client_route_get_segment (route, 0, &lat, &lon, &desc);
g_assert_cmpfloat (lat, ==, FST_ROUTE_FST_SEG_LAT);
g_assert_cmpfloat (lon, ==, FST_ROUTE_FST_SEG_LON);
- g_assert_cmpuint (g_hash_table_size (desc), ==, 2);
- g_assert_cmpstr (g_hash_table_lookup (desc, "en_US"), ==, FST_ROUTE_FST_SEG_DESC_EN);
- g_assert_cmpstr (g_hash_table_lookup (desc, "fr_FR"), ==, FST_ROUTE_FST_SEG_DESC_FR);
+ g_assert_cmpuint (desc->len, ==, 2);
+ g_assert_cmpstr (trp_languages_map_lookup (desc, "en_US"), ==, FST_ROUTE_FST_SEG_DESC_EN);
+ g_assert_cmpstr (trp_languages_map_lookup (desc, "fr_FR"), ==, FST_ROUTE_FST_SEG_DESC_FR);
trp_client_route_get_segment_in_language (route, 0, "en_US", NULL, NULL, &d);
g_assert_cmpstr (d, ==, FST_ROUTE_FST_SEG_DESC_EN);
trp_client_route_get_segment_in_language (route, 0, "fr_FR", NULL, NULL, &d);
@@ -141,8 +141,8 @@ check_first_client_route (TrpClientRoute *route)
trp_client_route_get_segment (route, 1, &lat, &lon, &desc);
g_assert_cmpfloat (lat, ==, FST_ROUTE_SND_SEG_LAT);
g_assert_cmpfloat (lon, ==, FST_ROUTE_SND_SEG_LON);
- g_assert_cmpuint (g_hash_table_size (desc), ==, 1);
- g_assert_cmpstr (g_hash_table_lookup (desc, "en_US"), ==, FST_ROUTE_SND_SEG_DESC_EN);
+ g_assert_cmpuint (desc->len, ==, 1);
+ g_assert_cmpstr (trp_languages_map_lookup (desc, "en_US"), ==, FST_ROUTE_SND_SEG_DESC_EN);
trp_client_route_get_segment_in_language (route, 1, "en_US", NULL, NULL, &d);
g_assert_cmpstr (d, ==, FST_ROUTE_SND_SEG_DESC_EN);
}
@@ -151,7 +151,7 @@ void
check_second_client_route (TrpClientRoute *route)
{
gdouble lat, lon;
- GHashTable *desc;
+ TrpLanguagesMap *desc;
const gchar *d;
check_client_route (route, SND_ROUTE_DISTANCE, SND_ROUTE_TIME, SND_ROUTE_TITLE_EN, SND_ROUTE_TITLE_FR, 2);
@@ -159,16 +159,16 @@ check_second_client_route (TrpClientRoute *route)
trp_client_route_get_segment (route, 0, &lat, &lon, &desc);
g_assert_cmpfloat (lat, ==, SND_ROUTE_FST_SEG_LAT);
g_assert_cmpfloat (lon, ==, SND_ROUTE_FST_SEG_LON);
- g_assert_cmpuint (g_hash_table_size (desc), ==, 1);
- g_assert_cmpstr (g_hash_table_lookup (desc, "fr_FR"), ==, SND_ROUTE_FST_SEG_DESC_FR);
+ g_assert_cmpuint (desc->len, ==, 1);
+ g_assert_cmpstr (trp_languages_map_lookup (desc, "fr_FR"), ==, SND_ROUTE_FST_SEG_DESC_FR);
trp_client_route_get_segment_in_language (route, 0, "fr_FR", NULL, NULL, &d);
g_assert_cmpstr (d, ==, SND_ROUTE_FST_SEG_DESC_FR);
trp_client_route_get_segment (route, 1, &lat, &lon, &desc);
g_assert_cmpfloat (lat, ==, SND_ROUTE_SND_SEG_LAT);
g_assert_cmpfloat (lon, ==, SND_ROUTE_SND_SEG_LON);
- g_assert_cmpuint (g_hash_table_size (desc), ==, 0);
- g_assert (g_hash_table_lookup (desc, "en_US") == NULL);
+ g_assert_cmpuint (desc->len, ==, 0);
+ g_assert (trp_languages_map_lookup (desc, "en_US") == NULL);
trp_client_route_get_segment_in_language (route, 1, "en_US", NULL, NULL, &d);
g_assert (d == NULL);
}
@@ -177,7 +177,7 @@ void
check_third_client_route (TrpClientRoute *route)
{
gdouble lat, lon;
- GHashTable *desc;
+ TrpLanguagesMap *desc;
const gchar *d;
check_client_route (route, THD_ROUTE_DISTANCE, THD_ROUTE_TIME, THD_ROUTE_TITLE_EN, NULL, 2);
@@ -185,16 +185,16 @@ check_third_client_route (TrpClientRoute *route)
trp_client_route_get_segment (route, 0, &lat, &lon, &desc);
g_assert_cmpfloat (lat, ==, THD_ROUTE_FST_SEG_LAT);
g_assert_cmpfloat (lon, ==, THD_ROUTE_FST_SEG_LON);
- g_assert_cmpuint (g_hash_table_size (desc), ==, 1);
- g_assert_cmpstr (g_hash_table_lookup (desc, "fr_FR"), ==, THD_ROUTE_FST_SEG_DESC_FR);
+ g_assert_cmpuint (desc->len, ==, 1);
+ g_assert_cmpstr (trp_languages_map_lookup (desc, "fr_FR"), ==, THD_ROUTE_FST_SEG_DESC_FR);
trp_client_route_get_segment_in_language (route, 0, "fr_FR", NULL, NULL, &d);
g_assert_cmpstr (d, ==, THD_ROUTE_FST_SEG_DESC_FR);
trp_client_route_get_segment (route, 1, &lat, &lon, &desc);
g_assert_cmpfloat (lat, ==, THD_ROUTE_SND_SEG_LAT);
g_assert_cmpfloat (lon, ==, THD_ROUTE_SND_SEG_LON);
- g_assert_cmpuint (g_hash_table_size (desc), ==, 0);
- g_assert (g_hash_table_lookup (desc, "en_US") == NULL);
+ g_assert_cmpuint (desc->len, ==, 0);
+ g_assert (trp_languages_map_lookup (desc, "en_US") == NULL);
trp_client_route_get_segment_in_language (route, 1, "en_US", NULL, NULL, &d);
g_assert (d == NULL);
}
diff --git a/traprain-client/route.c b/traprain-client/route.c
index 974115e..0eab346 100644
--- a/traprain-client/route.c
+++ b/traprain-client/route.c
@@ -38,7 +38,6 @@ 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->geo_desc_hash, g_hash_table_unref);
g_clear_pointer (&self->title, _trp_languages_map_unref);
G_OBJECT_CLASS (trp_client_route_parent_class)
@@ -177,37 +176,29 @@ get_route_info (TrpClientRoute *self, guint index, gdouble *lat, gdouble *lon)
* @index: the index of the segment
* @lat: (out) (optional): pointer used to return the latitude of the segment
* @lon: (out) (optional): pointer used to return the longitude of the segment
- * @descriptions: (out) (optional) (element-type utf8 utf8) (transfer none): pointer used to return the descriptions of the segment
+ * @descriptions: (out) (optional) (transfer none): pointer used to return the descriptions of the segment
*
* Return the latitude, longitude and human-readable descriptions of the segment at position @index.
*
- * The #GHashTable returned using @descriptions has the same format as the one returned by
- * trp_client_route_get_titles().
- *
* Since: UNRELEASED
*/
void
-trp_client_route_get_segment (TrpClientRoute *self, guint index, gdouble *lat, gdouble *lon, GHashTable **descriptions)
+trp_client_route_get_segment (TrpClientRoute *self, guint index, gdouble *lat, gdouble *lon, TrpLanguagesMap **descriptions)
{
if (!get_route_info (self, index, lat, lon))
return;
if (descriptions)
{
- TrpLanguagesMap *map;
-
- *descriptions = g_hash_table_lookup (self->geo_desc_hash, GUINT_TO_POINTER (index));
- if (*descriptions != NULL)
- return;
+ *descriptions = g_hash_table_lookup (self->geo_desc, GUINT_TO_POINTER (index));
- map = g_hash_table_lookup (self->geo_desc, GUINT_TO_POINTER (index));
- if (map != NULL)
- *descriptions = _trp_languages_map_to_hash (map);
- else
- *descriptions = g_hash_table_new (NULL, NULL);
+ if (*descriptions == NULL)
+ {
+ *descriptions = _trp_languages_map_new ();
- /* transfer ownership */
- g_hash_table_insert (self->geo_desc_hash, GUINT_TO_POINTER (index), *descriptions);
+ /* transfer ownership */
+ g_hash_table_insert (self->geo_desc, GUINT_TO_POINTER (index), *descriptions);
+ }
}
}
@@ -290,7 +281,6 @@ _trp_client_route_new (TrpOrgApertisNavigation1Route *proxy)
/* 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);
- self->geo_desc_hash = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_hash_table_unref);
return self;
}
diff --git a/traprain-client/route.h b/traprain-client/route.h
index 0c94c26..f27d41b 100644
--- a/traprain-client/route.h
+++ b/traprain-client/route.h
@@ -27,7 +27,7 @@ TrpLanguagesMap *trp_client_route_get_titles (TrpClientRoute *self);
const gchar *trp_client_route_get_title (TrpClientRoute *self, const gchar *language);
guint trp_client_route_get_n_segments (TrpClientRoute *self);
-void trp_client_route_get_segment (TrpClientRoute *self, guint index, gdouble *lat, gdouble *lon, GHashTable **descriptions);
+void trp_client_route_get_segment (TrpClientRoute *self, guint index, gdouble *lat, gdouble *lon, TrpLanguagesMap **descriptions);
void trp_client_route_get_segment_in_language (TrpClientRoute *self, guint index, const gchar *language, gdouble *lat, gdouble *lon, const gchar **description);
G_END_DECLS