[geocode-glib] location: Make timestamp prop writable on construction



commit 11d6c40e48630bb73077e861daabdaa7adab077c
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Sep 4 21:14:43 2015 +0100

    location: Make timestamp prop writable on construction
    
    While this isn't exactly (nor is it likely to be) needed by geocode-glib
    itself but is needed in geoclue, where we need to set the timestamps on the
    derived GClueLocation object from GPS.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754797

 geocode-glib/geocode-location.c |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c
index 6f70c58..14223dc 100644
--- a/geocode-glib/geocode-location.c
+++ b/geocode-glib/geocode-location.c
@@ -157,6 +157,28 @@ geocode_location_set_crs(GeocodeLocation   *loc,
 }
 
 static void
+geocode_location_set_timestamp (GeocodeLocation *loc,
+                                guint64          timestamp)
+{
+        g_return_if_fail (GEOCODE_IS_LOCATION (loc));
+
+        loc->priv->timestamp = timestamp;
+}
+
+static void
+geocode_location_constructed (GObject *object)
+{
+        GeocodeLocation *location = GEOCODE_LOCATION (object);
+        GTimeVal tv;
+
+        if (location->priv->timestamp != 0)
+                return;
+
+        g_get_current_time (&tv);
+        geocode_location_set_timestamp (location, tv.tv_sec);
+}
+
+static void
 geocode_location_set_property(GObject      *object,
                               guint         property_id,
                               const GValue *value,
@@ -195,6 +217,11 @@ geocode_location_set_property(GObject      *object,
                                           g_value_get_enum (value));
                 break;
 
+        case PROP_TIMESTAMP:
+                geocode_location_set_timestamp (location,
+                                                g_value_get_uint64 (value));
+                break;
+
         default:
                 /* We don't have any other property... */
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -481,6 +508,7 @@ geocode_location_class_init (GeocodeLocationClass *klass)
         glocation_class->finalize = geocode_location_finalize;
         glocation_class->get_property = geocode_location_get_property;
         glocation_class->set_property = geocode_location_set_property;
+        glocation_class->constructed = geocode_location_constructed;
 
         g_type_class_add_private (klass, sizeof (GeocodeLocationPrivate));
 
@@ -579,6 +607,8 @@ geocode_location_class_init (GeocodeLocationClass *klass)
          *
          * A timestamp in seconds since
          * <ulink url="http://en.wikipedia.org/wiki/Unix_epoch";>Epoch</ulink>.
+         *
+         * A value of 0 (zero) will be interpreted as the current time.
          */
         pspec = g_param_spec_uint64 ("timestamp",
                                      "Timestamp",
@@ -587,7 +617,8 @@ geocode_location_class_init (GeocodeLocationClass *klass)
                                      0,
                                      G_MAXINT64,
                                      0,
-                                     G_PARAM_READABLE |
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_CONSTRUCT_ONLY |
                                      G_PARAM_STATIC_STRINGS);
         g_object_class_install_property (glocation_class, PROP_TIMESTAMP, pspec);
 }
@@ -595,14 +626,10 @@ geocode_location_class_init (GeocodeLocationClass *klass)
 static void
 geocode_location_init (GeocodeLocation *location)
 {
-        GTimeVal tv;
-
         location->priv = G_TYPE_INSTANCE_GET_PRIVATE ((location),
                                                       GEOCODE_TYPE_LOCATION,
                                                       GeocodeLocationPrivate);
 
-        g_get_current_time (&tv);
-        location->priv->timestamp = tv.tv_sec;
         location->priv->altitude = GEOCODE_LOCATION_ALTITUDE_UNKNOWN;
         location->priv->accuracy = GEOCODE_LOCATION_ACCURACY_UNKNOWN;
         location->priv->crs = GEOCODE_LOCATION_CRS_WGS84;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]