summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-01 10:59:34 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-06 13:44:04 (GMT)
commitbbc79d31cd0df4ec05839eb4147408cb61e639d2 (patch)
tree5aa2f555cf9a0ed1445951b2106f2cc9c249e1f3
parent5c34442e44d4344205e5d86b4a6542c573b4ebe6 (diff)
downloadtraprain-bbc79d31cd0df4ec05839eb4147408cb61e639d2.tar.gz
traprain-bbc79d31cd0df4ec05839eb4147408cb61e639d2.tar.xz
common: factor out _trp_route_to_variants()
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/D4171
-rw-r--r--traprain-common/route-internal.h5
-rw-r--r--traprain-common/route.c38
-rw-r--r--traprain-service/navigation.c35
3 files changed, 49 insertions, 29 deletions
diff --git a/traprain-common/route-internal.h b/traprain-common/route-internal.h
index 6ac70c2..07c07fb 100644
--- a/traprain-common/route-internal.h
+++ b/traprain-common/route-internal.h
@@ -38,6 +38,11 @@ struct _TrpRoute
gboolean writable;
};
+void _trp_route_to_variants (TrpRoute *route,
+ GVariant **title,
+ GVariant **geometry,
+ GVariant **geometry_desc);
+
G_END_DECLS
#endif /* __TRAPRAIN_COMMON_ROUTE_INTERNAL_H__ */
diff --git a/traprain-common/route.c b/traprain-common/route.c
index 5c12e59..6e95dc8 100644
--- a/traprain-common/route.c
+++ b/traprain-common/route.c
@@ -172,3 +172,41 @@ trp_route_add_segment_description (TrpRoute *route,
s = g_ptr_array_index (route->geometry, index);
_trp_languages_map_add (s->description, language, description);
}
+
+void
+_trp_route_to_variants (TrpRoute *route,
+ GVariant **title,
+ GVariant **geometry,
+ GVariant **geometry_desc)
+{
+ GVariantBuilder geometry_builder, desc_builder;
+ guint i;
+
+ g_return_if_fail (TRP_IS_ROUTE (route));
+ g_return_if_fail (title != NULL);
+ g_return_if_fail (geometry != NULL);
+ g_return_if_fail (geometry_desc != NULL);
+
+ *title = _trp_languages_map_to_variant (route->title);
+
+ g_variant_builder_init (&geometry_builder, G_VARIANT_TYPE ("a(dd)"));
+ g_variant_builder_init (&desc_builder, G_VARIANT_TYPE ("a{ua{ss}}"));
+
+ for (i = 0; i < route->geometry->len; i++)
+ {
+ _TrpSegment *s = g_ptr_array_index (route->geometry, i);
+
+ g_variant_builder_add (&geometry_builder, "(dd)", s->latitude, s->longitude);
+
+ /* add descriptions */
+ if (s->description->len > 0)
+ {
+ g_variant_builder_add_value (&desc_builder, g_variant_new_dict_entry (
+ g_variant_new_uint32 (i),
+ _trp_languages_map_to_variant (s->description)));
+ }
+ }
+
+ *geometry = g_variant_builder_end (&geometry_builder);
+ *geometry_desc = g_variant_builder_end (&desc_builder);
+}
diff --git a/traprain-service/navigation.c b/traprain-service/navigation.c
index fe6241e..3c5f502 100644
--- a/traprain-service/navigation.c
+++ b/traprain-service/navigation.c
@@ -201,8 +201,7 @@ service_route_export (TrpServiceNavigation *self,
{
TrpRoute *route = (TrpRoute *) service_route;
g_autofree gchar *path = NULL;
- GVariantBuilder geometry, desc;
- guint j;
+ GVariant *title, *geometry, *geometry_desc;
g_return_val_if_fail (service_route->service == NULL, FALSE);
g_return_val_if_fail (self->service != NULL, FALSE);
@@ -220,35 +219,13 @@ service_route_export (TrpServiceNavigation *self,
route->writable = FALSE;
trp_object_skeleton_set_org_apertis_navigation1_route (service_route->object, service_route->service);
+ _trp_route_to_variants (route, &title, &geometry, &geometry_desc);
+
trp_org_apertis_navigation1_route_set_total_distance (service_route->service, route->total_distance);
trp_org_apertis_navigation1_route_set_total_time (service_route->service, route->total_time);
-
- /* Title */
-
- trp_org_apertis_navigation1_route_set_title (service_route->service,
- _trp_languages_map_to_variant (route->title));
-
- /* Geometry and GeometryDescriptions */
- g_variant_builder_init (&geometry, G_VARIANT_TYPE ("a(dd)"));
- g_variant_builder_init (&desc, G_VARIANT_TYPE ("a{ua{ss}}"));
-
- for (j = 0; j < route->geometry->len; j++)
- {
- _TrpSegment *s = g_ptr_array_index (route->geometry, j);
-
- g_variant_builder_add (&geometry, "(dd)", s->latitude, s->longitude);
-
- /* add descriptions */
- if (s->description->len > 0)
- {
- g_variant_builder_add_value (&desc, g_variant_new_dict_entry (
- g_variant_new_uint32 (j),
- _trp_languages_map_to_variant (s->description)));
- }
- }
-
- trp_org_apertis_navigation1_route_set_geometry (service_route->service, g_variant_builder_end (&geometry));
- trp_org_apertis_navigation1_route_set_geometry_descriptions (service_route->service, g_variant_builder_end (&desc));
+ trp_org_apertis_navigation1_route_set_title (service_route->service, title);
+ trp_org_apertis_navigation1_route_set_geometry (service_route->service, geometry);
+ trp_org_apertis_navigation1_route_set_geometry_descriptions (service_route->service, geometry_desc);
g_dbus_object_manager_server_export (self->object_mgr, G_DBUS_OBJECT_SKELETON (service_route->object));