From 58fb84ae6ca58fe52c70354ec01ee452790ee3c2 Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Thu, 12 Sep 2013 00:32:48 +0200 Subject: [PATCH 1/4] service-location: Use property binding to keep locations in sync Instead of copying values over from location_info to service_location, just keep a ref to location_info and let gobject property binding keep the properties in sync. https://bugs.freedesktop.org/show_bug.cgi?id=69105 --- src/gclue-service-location.c | 49 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/gclue-service-location.c b/src/gclue-service-location.c index 2cec788..5618417 100644 --- a/src/gclue-service-location.c +++ b/src/gclue-service-location.c @@ -38,6 +38,7 @@ struct _GClueServiceLocationPrivate const char *peer; const char *path; GDBusConnection *connection; + GClueLocationInfo *location_info; }; enum @@ -60,6 +61,7 @@ gclue_service_location_finalize (GObject *object) g_clear_pointer (&priv->peer, g_free); g_clear_pointer (&priv->path, g_free); g_clear_object (&priv->connection); + g_clear_object (&priv->location_info); /* Chain up to the parent class */ G_OBJECT_CLASS (gclue_service_location_parent_class)->finalize (object); @@ -72,7 +74,6 @@ gclue_service_location_get_property (GObject *object, GParamSpec *pspec) { GClueServiceLocation *self = GCLUE_SERVICE_LOCATION (object); - GClueLocation *location = GCLUE_LOCATION (object); switch (prop_id) { case PROP_PEER: @@ -88,21 +89,8 @@ gclue_service_location_get_property (GObject *object, break; case PROP_LOCATION: - { - GClueLocationInfo *loc; - const char *desc; - - loc = gclue_location_info_new - (gclue_location_get_latitude (location), - gclue_location_get_longitude (location), - gclue_location_get_accuracy (location)); - desc = gclue_location_get_description (location); - if (desc != NULL) - gclue_location_info_set_description (loc, desc); - - g_value_take_object (value, loc); + g_value_set_object (value, self->priv->location_info); break; - } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -132,20 +120,25 @@ gclue_service_location_set_property (GObject *object, break; case PROP_LOCATION: - { - GClueLocationInfo *loc; - - loc = g_value_get_object (value); - gclue_location_set_latitude - (location, gclue_location_info_get_latitude (loc)); - gclue_location_set_longitude - (location, gclue_location_info_get_longitude (loc)); - gclue_location_set_accuracy - (location, gclue_location_info_get_accuracy (loc)); - gclue_location_set_description - (location, gclue_location_info_get_description (loc)); + self->priv->location_info = g_value_dup_object (value); + + g_object_bind_property (self->priv->location_info, "latitude", + location, "latitude", + G_BINDING_SYNC_CREATE); + + g_object_bind_property (self->priv->location_info, "longitude", + location, "longitude", + G_BINDING_SYNC_CREATE); + + g_object_bind_property (self->priv->location_info, "accuracy", + location, "accuracy", + G_BINDING_SYNC_CREATE); + + g_object_bind_property (self->priv->location_info, "description", + location, "description", + G_BINDING_SYNC_CREATE); + break; - } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); -- 1.8.3.1