[geocode-glib/gnome-maps: 6/6] lib: Turn GeocodeLocation into a proper GObject



commit 26ae290385f8a5c0910ebe17b859fbad8346fa39
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sun Mar 24 23:48:14 2013 +0200

    lib: Turn GeocodeLocation into a proper GObject
    
    While I made this change under the wrong impression that gjs is not very
    happy about GeocodeLocation not being a gobject, this IMO is still a
    good change and I put some time into it so I'm sending this patch.
    
    I wasn't exactly sure if we want to have 'timestamp' property writable or
    not but since it was writable already, I left it as such. Perhaps it
    should be construct-only?
    
    I also took the liberty of changing all tabs to spaces in
    geocode-location.[ch]. Looking at geocode-ipclient.c, this seem to be
    the desired coding-style.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696528

 geocode-glib/geocode-forward.c    |    6 +-
 geocode-glib/geocode-glib.symbols |    9 +-
 geocode-glib/geocode-ipclient.c   |   15 +-
 geocode-glib/geocode-location.c   |  371 +++++++++++++++++++++++++++++-------
 geocode-glib/geocode-location.h   |   65 +++++--
 geocode-glib/geocode-reverse.c    |    7 +-
 geocode-glib/test-gcglib.c        |   51 +++---
 geocode-glib/test-geoip.c         |    5 +-
 8 files changed, 397 insertions(+), 132 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index 33a7202..eaadc7c 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -472,7 +472,7 @@ geocode_forward_search_async (GeocodeForward      *forward,
  *
  * Returns: (element-type GeocodeLocation) (transfer container): A list of
  * locations or %NULL in case of errors. Free the returned list with
- * g_list_free() when done.
+ * g_object_unref() when done.
  **/
 GList *
 geocode_forward_search_finish (GeocodeForward       *forward,
@@ -646,7 +646,7 @@ make_location_list_from_tree (GNode   *node,
                 * and set it to the description of the loc object */
                loc = (GeocodeLocation *) node->data;
 
-               name = loc->description;
+               name = geocode_location_get_description (loc);
 
                /* To print the attributes in a meaningful manner
                 * reverse the s_array */
@@ -770,7 +770,7 @@ parse:
  *
  * Returns: (element-type GeocodeLocation) (transfer container): A list of
  * locations or %NULL in case of errors. Free the returned list with
- * g_list_free() when done.
+ * g_object_unref() when done.
  **/
 GList *
 geocode_forward_search (GeocodeForward      *forward,
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index b6b62df..87d91d9 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -2,8 +2,15 @@ geocode_location_get_type
 geocode_location_new
 geocode_location_new_with_description
 geocode_location_free
+geocode_location_get_description
 geocode_location_get_distance_from
+geocode_location_get_latitude
+geocode_location_get_longitude
+geocode_location_get_timestamp
 geocode_location_set_description
+geocode_location_set_latitude
+geocode_location_set_longitude
+geocode_location_set_timestamp
 geocode_location_accuracy_get_type
 geocode_forward_get_type
 geocode_forward_new_for_string
@@ -26,4 +33,4 @@ geocode_ipclient_new
 geocode_ipclient_new_for_ip
 geocode_ipclient_search_async
 geocode_ipclient_search
-geocode_ipclient_search_finish
\ No newline at end of file
+geocode_ipclient_search_finish
diff --git a/geocode-glib/geocode-ipclient.c b/geocode-glib/geocode-ipclient.c
index 185f99a..9540d56 100644
--- a/geocode-glib/geocode-ipclient.c
+++ b/geocode-glib/geocode-ipclient.c
@@ -387,8 +387,8 @@ json_to_location (const char              *json,
                 return NULL;
 
         location = geocode_location_new (0, 0);
-        location->latitude = json_object_get_double_member (object, "latitude");
-        location->longitude = json_object_get_double_member (object, "longitude");
+        geocode_location_set_latitude (location, json_object_get_double_member (object, "latitude"));
+        geocode_location_set_longitude (location, json_object_get_double_member (object, "longitude"));
 
         string = g_string_new ("");
         if (json_object_has_member (object, "city")) {
@@ -413,7 +413,8 @@ json_to_location (const char              *json,
         if (accuracy != NULL)
                 *accuracy = get_accuracy_from_json_location (object);
 
-        location->description = g_string_free (string, FALSE);
+        geocode_location_set_description (location, string->str);
+        g_string_free (string, TRUE);
         g_object_unref (parser);
 
         return location;
@@ -428,8 +429,8 @@ json_to_location (const char              *json,
  *
  * Finishes a geolocation search operation. See geocode_ipclient_search_async().
  *
- * Returns: A #GeocodeLocation object or %NULL in case of errors.
- * Free the returned object with g_object_unref() when done.
+ * Returns: (transfer full): A #GeocodeLocation object or %NULL in case of
+ * errors. Free the returned object with g_object_unref() when done.
  **/
 GeocodeLocation *
 geocode_ipclient_search_finish (GeocodeIpclient         *ipclient,
@@ -463,8 +464,8 @@ geocode_ipclient_search_finish (GeocodeIpclient         *ipclient,
  *
  * Gets the geolocation data for an IP address from the server.
  *
- * Returns: A #GeocodeLocation object or %NULL in case of errors.
- * Free the returned object with g_object_unref() when done.
+ * Returns: (transfer full): A #GeocodeLocation object or %NULL in case of
+ * errors. Free the returned object with g_object_unref() when done.
  **/
 GeocodeLocation *
 geocode_ipclient_search (GeocodeIpclient         *ipclient,
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c
index 9855f39..c4cd882 100644
--- a/geocode-glib/geocode-location.c
+++ b/geocode-glib/geocode-location.c
@@ -20,8 +20,11 @@
 
  */
 
+#include <config.h>
+
 #include <geocode-location.h>
 #include <math.h>
+#include <glib/gi18n-lib.h>
 
 #define EARTH_RADIUS_KM 6372.795
 
@@ -30,37 +33,195 @@
  * @short_description: Geocode location object
  * @include: geocode-glib/geocode-glib.h
  *
- * An object representing a location, with optional description.
+ * The #GeocodeLocation instance represents a location on earth, with an
+ * optional description.
  **/
-static gpointer
-geocode_location_copy (gpointer boxed)
+
+struct _GeocodeLocationPrivate {
+        gdouble longitude;
+        gdouble latitude;
+        gint64  timestamp;
+        char   *description;
+};
+
+enum {
+        PROP_0,
+
+        PROP_LATITUDE,
+        PROP_LONGITUDE,
+        PROP_DESCRIPTION,
+        PROP_TIMESTAMP
+};
+
+G_DEFINE_TYPE (GeocodeLocation, geocode_location, G_TYPE_OBJECT)
+
+static void
+geocode_location_get_property (GObject    *object,
+                               guint       property_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
 {
-       GeocodeLocation *from, *to;
+        GeocodeLocation *location = GEOCODE_LOCATION (object);
 
-       from = (GeocodeLocation *) boxed;
-       to = g_new (GeocodeLocation, 1);
-       to->longitude = from->longitude;
-       to->latitude = from->latitude;
-       to->timestamp = from->timestamp;
-       to->description = from->description;
+        switch (property_id) {
+        case PROP_DESCRIPTION:
+                g_value_set_string (value,
+                                    geocode_location_get_description (location));
+                break;
 
-       return to;
+        case PROP_LATITUDE:
+                g_value_set_double (value,
+                                    geocode_location_get_latitude (location));
+                break;
+
+        case PROP_LONGITUDE:
+                g_value_set_double (value,
+                                    geocode_location_get_longitude (location));
+                break;
+
+        case PROP_TIMESTAMP:
+                g_value_set_int64 (value,
+                                   geocode_location_get_timestamp (location));
+                break;
+
+        default:
+                /* We don't have any other property... */
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
 }
 
-/**
- * geocode_location_free:
- * @loc: a #GeocodeLocation object
- *
- * Frees a #GeocodeLocation object.
- **/
-void
-geocode_location_free (GeocodeLocation *loc)
+static void
+geocode_location_set_property(GObject      *object,
+                              guint         property_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
 {
-       g_free (loc->description);
-       g_free (loc);
+        GeocodeLocation *location = GEOCODE_LOCATION (object);
+
+        switch (property_id) {
+        case PROP_DESCRIPTION:
+                geocode_location_set_description (location,
+                                                  g_value_get_string (value));
+                break;
+
+        case PROP_LATITUDE:
+                geocode_location_set_latitude (location,
+                                               g_value_get_double (value));
+                break;
+
+        case PROP_LONGITUDE:
+                geocode_location_set_longitude (location,
+                                                g_value_get_double (value));
+                break;
+
+        case PROP_TIMESTAMP:
+                geocode_location_set_timestamp (location,
+                                                g_value_get_int64 (value));
+                break;
+
+        default:
+                /* We don't have any other property... */
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
 }
 
-G_DEFINE_BOXED_TYPE(GeocodeLocation, geocode_location, geocode_location_copy, geocode_location_free)
+static void
+geocode_location_finalize (GObject *glocation)
+{
+        GeocodeLocation *location = (GeocodeLocation *) glocation;
+
+        g_clear_pointer (&location->priv->description, g_free);
+
+        G_OBJECT_CLASS (geocode_location_parent_class)->finalize (glocation);
+}
+
+static void
+geocode_location_class_init (GeocodeLocationClass *klass)
+{
+        GObjectClass *glocation_class = G_OBJECT_CLASS (klass);
+        GParamSpec *pspec;
+
+        glocation_class->finalize = geocode_location_finalize;
+        glocation_class->get_property = geocode_location_get_property;
+        glocation_class->set_property = geocode_location_set_property;
+
+        g_type_class_add_private (klass, sizeof (GeocodeLocationPrivate));
+
+        /**
+         * GeocodeLocation:description:
+         *
+         * The description of this location.
+         */
+        pspec = g_param_spec_string ("description",
+                                     "Description",
+                                     _("Description of this location"),
+                                     NULL /* default value */,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (glocation_class, PROP_DESCRIPTION, pspec);
+
+        /**
+         * GeocodeLocation:latitude:
+         *
+         * The latitude of this location in degrees.
+         */
+        pspec = g_param_spec_double ("latitude",
+                                     "Latitude",
+                                     _("The latitude of this location in degrees"),
+                                     -90.0,
+                                     90.0,
+                                     0.0 /* default value */,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (glocation_class, PROP_LATITUDE, pspec);
+
+        /**
+         * GeocodeLocation:longitude:
+         *
+         * The longitude of this location in degrees.
+         */
+        pspec = g_param_spec_double ("longitude",
+                                     "Longitude",
+                                     _("The longitude of this location in degrees"),
+                                     -180.0,
+                                     180.0,
+                                     0.0 /* default value */,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (glocation_class, PROP_LONGITUDE, pspec);
+
+        /**
+         * GeocodeLocation:timestamp:
+         *
+         * A timestamp in seconds since
+         * <ulink url="http://en.wikipedia.org/wiki/Unix_epoch";>Epoch</ulink>.
+         */
+        pspec = g_param_spec_int64 ("timestamp",
+                                    "Timestamp",
+                                    _("The timestamp of this location "
+                                      "in seconds since Epoch"),
+                                    0,
+                                    G_MAXINT64,
+                                    0.0 /* default value */,
+                                    G_PARAM_READWRITE |
+                                    G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (glocation_class, PROP_TIMESTAMP, pspec);
+}
+
+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;
+}
 
 /**
  * geocode_location_new:
@@ -69,31 +230,16 @@ G_DEFINE_BOXED_TYPE(GeocodeLocation, geocode_location, geocode_location_copy, ge
  *
  * Creates a new #GeocodeLocation object.
  *
- * Returns: a new #GeocodeLocation object. Use geocode_location_free() when done.
+ * Returns: a new #GeocodeLocation object. Use g_object_unref() when done.
  **/
 GeocodeLocation *
 geocode_location_new (gdouble latitude,
-                     gdouble longitude)
+                      gdouble longitude)
 {
-       GeocodeLocation *ret;
-       GTimeVal tv;
-
-       if (longitude < -180.0 || longitude > 180.0) {
-               g_warning ("Invalid longitude %lf passed, using 0.0 instead", longitude);
-               longitude = 0.0;
-       }
-       if (latitude < -90.0 || latitude > 90.0) {
-               g_warning ("Invalid latitude %lf passed, using 0.0 instead", latitude);
-               latitude = 0.0;
-       }
-
-       ret = g_new0 (GeocodeLocation, 1);
-       ret->longitude = longitude;
-       ret->latitude = latitude;
-       g_get_current_time (&tv);
-       ret->timestamp = tv.tv_sec;
-
-       return ret;
+        return g_object_new (GEOCODE_TYPE_LOCATION,
+                             "latitude", latitude,
+                             "longitude", longitude,
+                             NULL);
 }
 
 /**
@@ -104,36 +250,116 @@ geocode_location_new (gdouble latitude,
  *
  * Creates a new #GeocodeLocation object.
  *
- * Returns: a new #GeocodeLocation object. Use geocode_location_free() when done.
+ * Returns: a new #GeocodeLocation object. Use g_object_unref() when done.
  **/
 GeocodeLocation *
 geocode_location_new_with_description (gdouble     latitude,
-                                      gdouble     longitude,
-                                      const char *description)
+                                       gdouble     longitude,
+                                       const char *description)
 {
-       GeocodeLocation *ret;
-
-       ret = geocode_location_new (latitude, longitude);
-       ret->description = g_strdup (description);
-
-       return ret;
+        return g_object_new (GEOCODE_TYPE_LOCATION,
+                             "latitude", latitude,
+                             "longitude", longitude,
+                             "description", description,
+                             NULL);
 }
 
 /**
  * geocode_location_set_description:
  * @description: a description for the location
  *
- * Sets the #GeocodeLocation object's @description to
- * the passed value.
+ * Sets the description of @loc to @description.
  **/
 void
 geocode_location_set_description (GeocodeLocation *loc,
-                                 const char      *description)
+                                  const char      *description)
+{
+        g_return_if_fail (GEOCODE_IS_LOCATION (loc));
+        g_return_if_fail (description != NULL);
+
+        g_free (loc->priv->description);
+        loc->priv->description = g_strdup (description);
+}
+
+const char *
+geocode_location_get_description (GeocodeLocation *loc)
+{
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), NULL);
+
+        return loc->priv->description;
+}
+
+/**
+ * geocode_location_set_latitude:
+ * @latitude: a latitude, in degrees
+ *
+ * Sets the latitude of @loc to @latitude.
+ **/
+void
+geocode_location_set_latitude (GeocodeLocation *loc,
+                               gdouble          latitude)
+{
+        g_return_if_fail (GEOCODE_IS_LOCATION (loc));
+        g_return_if_fail (latitude >= -90.0 && latitude <= 90.0);
+
+        loc->priv->latitude = latitude;
+}
+
+gdouble
+geocode_location_get_latitude (GeocodeLocation *loc)
+{
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), 0.0);
+
+        return loc->priv->latitude;
+}
+
+/**
+ * geocode_location_set_longitude:
+ * @longitude: a longitude, in degrees
+ *
+ * Sets the longitude of @loc to @longitude.
+ **/
+void
+geocode_location_set_longitude (GeocodeLocation *loc,
+                                gdouble          longitude)
+{
+        g_return_if_fail (GEOCODE_IS_LOCATION (loc));
+        g_return_if_fail (longitude >= -180.0 && longitude <= 180.0);
+
+        loc->priv->longitude = longitude;
+}
+
+gdouble
+geocode_location_get_longitude (GeocodeLocation *loc)
+{
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), 0.0);
+
+        return loc->priv->longitude;
+}
+
+/**
+ * geocode_location_set_timestamp:
+ * @timestamp: a timestamp in seconds since
+ * <ulink url="http://en.wikipedia.org/wiki/Unix_epoch";>Epoch</ulink>.
+ *
+ * Sets the timestamp of @loc to @timestamp.
+ **/
+void
+geocode_location_set_timestamp (GeocodeLocation *loc,
+                                gint64           timestamp)
+{
+        g_return_if_fail (GEOCODE_IS_LOCATION (loc));
+        g_return_if_fail (timestamp > 0);
+
+        loc->priv->timestamp = timestamp;
+}
+
+gint64
+geocode_location_get_timestamp (GeocodeLocation *loc)
 {
-       g_return_if_fail (loc != NULL);
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), -1);
 
-       g_free (loc->description);
-       loc->description = g_strdup (description);
+        return loc->priv->timestamp;
 }
 
 /**
@@ -149,23 +375,24 @@ geocode_location_set_description (GeocodeLocation *loc,
  **/
 double
 geocode_location_get_distance_from (GeocodeLocation *loca,
-                                   GeocodeLocation *locb)
+                                    GeocodeLocation *locb)
 {
-       gdouble dlat, dlon, lat1, lat2;
-       gdouble a, c;
+        gdouble dlat, dlon, lat1, lat2;
+        gdouble a, c;
 
-       g_return_val_if_fail (loca != NULL || locb != NULL, 0.0);
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (loca), 0.0);
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (locb), 0.0);
 
-       /* Algorithm from:
-        * http://www.movable-type.co.uk/scripts/latlong.html */
+        /* Algorithm from:
+         * http://www.movable-type.co.uk/scripts/latlong.html */
 
-       dlat = (locb->latitude - loca->latitude) * M_PI / 180.0;
-       dlon = (locb->longitude - loca->longitude) * M_PI / 180.0;
-       lat1 = loca->latitude * M_PI / 180.0;
-       lat2 = locb->latitude * M_PI / 180.0;
+        dlat = (locb->priv->latitude - loca->priv->latitude) * M_PI / 180.0;
+        dlon = (locb->priv->longitude - loca->priv->longitude) * M_PI / 180.0;
+        lat1 = loca->priv->latitude * M_PI / 180.0;
+        lat2 = locb->priv->latitude * M_PI / 180.0;
 
-       a = sin (dlat / 2) * sin (dlat / 2) +
-               sin (dlon / 2) * sin (dlon / 2) * cos (lat1) * cos (lat2);
-       c = 2 * atan2 (sqrt (a), sqrt (1-a));
-       return EARTH_RADIUS_KM * c;
+        a = sin (dlat / 2) * sin (dlat / 2) +
+            sin (dlon / 2) * sin (dlon / 2) * cos (lat1) * cos (lat2);
+        c = 2 * atan2 (sqrt (a), sqrt (1-a));
+        return EARTH_RADIUS_KM * c;
 }
diff --git a/geocode-glib/geocode-location.h b/geocode-glib/geocode-location.h
index 351bf59..7f024da 100644
--- a/geocode-glib/geocode-location.h
+++ b/geocode-glib/geocode-location.h
@@ -27,43 +27,66 @@
 
 G_BEGIN_DECLS
 
-typedef struct _GeocodeLocation GeocodeLocation;
+GType geocode_location_get_type (void) G_GNUC_CONST;
+
+#define GEOCODE_TYPE_LOCATION                  (geocode_location_get_type ())
+#define GEOCODE_LOCATION(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCODE_TYPE_LOCATION, 
GeocodeLocation))
+#define GEOCODE_IS_LOCATION(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOCODE_TYPE_LOCATION))
+#define GEOCODE_LOCATION_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GEOCODE_TYPE_LOCATION, 
GeocodeLocationClass))
+#define GEOCODE_IS_LOCATION_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GEOCODE_TYPE_LOCATION))
+#define GEOCODE_LOCATION_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GEOCODE_TYPE_LOCATION, 
GeocodeLocationClass))
 
 /**
  * GeocodeLocation:
- * @longitude: a longitude, in degrees
- * @latitude: a latitude, in degrees
- * @timestamp: a timestamp in seconds since <ulink 
url="http://en.wikipedia.org/wiki/Unix_epoch";>Epoch</ulink>.
- * @description: a description for display
  *
- * The #GeocodeLocation structure represents a location
- * on earth, with an optional description.
- **/
+ * All the fields in the #GeocodeLocation structure are private and should never be accessed directly.
+**/
+typedef struct _GeocodeLocation        GeocodeLocation;
+typedef struct _GeocodeLocationClass   GeocodeLocationClass;
+typedef struct _GeocodeLocationPrivate GeocodeLocationPrivate;
+
 struct _GeocodeLocation {
-       gdouble longitude;
-       gdouble latitude;
-       gint64  timestamp;
-       char   *description;
+        /* <private> */
+        GObject parent_instance;
+        GeocodeLocationPrivate *priv;
 };
 
-#define GEOCODE_TYPE_LOCATION (geocode_location_get_type ())
-
-GType geocode_location_get_type (void) G_GNUC_CONST;
+/**
+ * GeocodeLocationClass:
+ *
+ * All the fields in the #GeocodeLocationClass structure are private and should never be accessed directly.
+**/
+struct _GeocodeLocationClass {
+        /* <private> */
+        GObjectClass parent_class;
+};
 
 GeocodeLocation *geocode_location_new (gdouble latitude,
-                                      gdouble longitude);
+                                       gdouble longitude);
 
 GeocodeLocation *geocode_location_new_with_description (gdouble     latitude,
-                                                       gdouble     longitude,
-                                                       const char *description);
+                                                        gdouble     longitude,
+                                                        const char *description);
 
 double geocode_location_get_distance_from (GeocodeLocation *loca,
-                                          GeocodeLocation *locb);
+                                           GeocodeLocation *locb);
 
 void geocode_location_set_description (GeocodeLocation *loc,
-                                      const char      *description);
+                                       const char      *description);
+
+const char *geocode_location_get_description (GeocodeLocation *loc);
+
+gdouble geocode_location_get_latitude (GeocodeLocation *loc);
+void geocode_location_set_latitude (GeocodeLocation *loc,
+                                    gdouble          latitude);
+
+gdouble geocode_location_get_longitude (GeocodeLocation *loc);
+void geocode_location_set_longitude (GeocodeLocation *loc,
+                                     gdouble          longitude);
 
-void geocode_location_free (GeocodeLocation *loc);
+void geocode_location_set_timestamp (GeocodeLocation *loc,
+                                     gint64           timestamp);
+gint64 geocode_location_get_timestamp (GeocodeLocation *loc);
 
 G_END_DECLS
 
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 2c1e0a2..7aa5c25 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -92,11 +92,12 @@ geocode_reverse_new_for_location (GeocodeLocation *location)
 
        object = g_object_new (GEOCODE_TYPE_REVERSE, NULL);
 
+       g_ascii_formatd (buf, sizeof (buf), "%g", geocode_location_get_latitude (location));
+       g_ascii_formatd (buf2, sizeof (buf2), "%g", geocode_location_get_longitude (location));
+
        g_hash_table_insert (object->priv->ht,
                             g_strdup ("location"),
-                            g_strdup_printf ("%s, %s",
-                                             g_ascii_formatd (buf, sizeof (buf), "%g", location->latitude),
-                                             g_ascii_formatd (buf2, sizeof (buf2), "%g", 
location->longitude)));
+                            g_strdup_printf ("%s, %s", buf, buf2));
 
        return object;
 }
diff --git a/geocode-glib/test-gcglib.c b/geocode-glib/test-gcglib.c
index 5ccf107..27d4c72 100644
--- a/geocode-glib/test-gcglib.c
+++ b/geocode-glib/test-gcglib.c
@@ -15,7 +15,10 @@ static char **params = NULL;
 static void
 print_loc (GeocodeLocation *loc)
 {
-       g_print ("\t%s @ %lf, %lf\n", loc->description, loc->latitude, loc->longitude);
+       g_print ("\t%s @ %lf, %lf\n",
+             geocode_location_get_description (loc),
+             geocode_location_get_latitude (loc),
+             geocode_location_get_longitude (loc));
 }
 
 static void
@@ -72,7 +75,7 @@ got_geocode_search_cb (GObject *source_object,
 
                g_print ("Got geocode search answer:\n");
                print_loc (loc);
-               geocode_location_free (loc);
+               g_object_unref (loc);
        }
        g_list_free (results);
 
@@ -91,7 +94,7 @@ test_rev (void)
 
        loc = geocode_location_new (51.237070, -0.589669);
        rev = geocode_reverse_new_for_location (loc);
-       geocode_location_free (loc);
+       g_object_unref (loc);
 
        ht = geocode_reverse_resolve (rev, &error);
        if (ht == NULL) {
@@ -153,10 +156,10 @@ test_xep (void)
        g_object_unref (object);
 
        loc = res->data;
-       g_assert_cmpfloat (loc->latitude, ==, -0.589669);
-       g_assert_cmpfloat (loc->longitude, ==, 51.237070);
+       g_assert_cmpfloat (geocode_location_get_latitude (loc), ==, -0.589669);
+       g_assert_cmpfloat (geocode_location_get_longitude (loc), ==, 51.237070);
 
-       geocode_location_free (loc);
+       g_object_unref (loc);
        g_list_free (res);
 }
 
@@ -182,10 +185,10 @@ test_pub (void)
        g_assert_cmpint (g_list_length (res), ==, 1);
        loc = res->data;
 
-       g_assert_cmpfloat (loc->latitude, ==, -0.589669);
-       g_assert_cmpfloat (loc->longitude, ==, 51.237070);
+       g_assert_cmpfloat (geocode_location_get_latitude (loc), ==, -0.589669);
+       g_assert_cmpfloat (geocode_location_get_longitude (loc), ==, 51.237070);
 
-       geocode_location_free (loc);
+       g_object_unref (loc);
        g_list_free (res);
 }
 
@@ -220,12 +223,12 @@ test_search (void)
        for (l = results; l != NULL; l = l->next) {
                GeocodeLocation *loc = l->data;
 
-               if (g_strcmp0 (loc->description, "Paris, France") == 0)
+               if (g_strcmp0 (geocode_location_get_description (loc), "Paris, France") == 0)
                        got_france = TRUE;
-               else if (g_strcmp0 (loc->description, "Paris, Texas, United States") == 0)
+               else if (g_strcmp0 (geocode_location_get_description (loc), "Paris, Texas, United States") == 
0)
                        got_texas = TRUE;
 
-               geocode_location_free (loc);
+               g_object_unref (loc);
 
                if (got_france && got_texas)
                        break;
@@ -257,10 +260,10 @@ test_search_lat_long (void)
        g_object_unref (object);
 
        loc = res->data;
-       g_assert_cmpfloat (loc->latitude - 21.800699, <, 0.000001);
-       g_assert_cmpfloat (loc->longitude - -100.735626, <, 0.000001);
+       g_assert_cmpfloat (geocode_location_get_latitude (loc) - 21.800699, <, 0.000001);
+       g_assert_cmpfloat (geocode_location_get_longitude (loc) - -100.735626, <, 0.000001);
 
-       g_list_free_full (res, (GDestroyNotify) geocode_location_free);
+       g_list_free_full (res, (GDestroyNotify) g_object_unref);
 }
 
 /* Test case from:
@@ -301,12 +304,12 @@ test_locale (void)
        g_object_unref (object);
 
        loc = res->data;
-       g_assert_cmpstr (loc->description, ==, "Moskva, Rusko");
-       g_assert_cmpfloat (loc->latitude - 55.756950, <, 0.000001);
-       g_assert_cmpfloat (loc->longitude - 37.614971, <, 0.000001);
+       g_assert_cmpstr (geocode_location_get_description (loc), ==, "Moskva, Rusko");
+       g_assert_cmpfloat (geocode_location_get_latitude (loc) - 55.756950, <, 0.000001);
+       g_assert_cmpfloat (geocode_location_get_longitude (loc) - 37.614971, <, 0.000001);
        print_loc (loc);
 
-       g_list_free_full (res, (GDestroyNotify) geocode_location_free);
+       g_list_free_full (res, (GDestroyNotify) g_object_unref);
 
        /* Check Bonneville's region in French */
        setlocale (LC_MESSAGES, "fr_FR.UTF-8");
@@ -320,10 +323,10 @@ test_locale (void)
        g_object_unref (object);
 
        loc = res->data;
-       g_assert_cmpstr (loc->description, ==, "Bonneville, Rhône-Alpes, France");
+       g_assert_cmpstr (geocode_location_get_description (loc), ==, "Bonneville, Rhône-Alpes, France");
        print_loc (loc);
 
-       g_list_free_full (res, (GDestroyNotify) geocode_location_free);
+       g_list_free_full (res, (GDestroyNotify) g_object_unref);
 
        /* And reset the locale */
        setlocale (LC_MESSAGES, old_locale);
@@ -398,9 +401,9 @@ test_search_json (void)
        g_assert_cmpint (g_list_length (list), ==, 10);
 
        loc = list->data;
-       g_assert_cmpstr (loc->description, ==, "Rio de Janeiro, Brazil");
+       g_assert_cmpstr (geocode_location_get_description (loc), ==, "Rio de Janeiro, Brazil");
 
-       g_list_free_full (list, (GDestroyNotify) geocode_location_free);
+       g_list_free_full (list, (GDestroyNotify) g_object_unref);
 }
 
 static GeocodeLocation *
@@ -477,7 +480,7 @@ int main (int argc, char **argv)
                }
                print_loc (loc);
                reverse = geocode_reverse_new_for_location (loc);
-               geocode_location_free (loc);
+               g_object_unref (loc);
                geocode_reverse_resolve_async (reverse, NULL, got_geocode_cb, NULL);
        }
 
diff --git a/geocode-glib/test-geoip.c b/geocode-glib/test-geoip.c
index 320cd3b..3953810 100644
--- a/geocode-glib/test-geoip.c
+++ b/geocode-glib/test-geoip.c
@@ -51,7 +51,10 @@ print_geolocation_info_cb (GObject          *source_object,
                 g_error_free (error);
                 exit (1);
         }
-        g_print ("Location: %s (%f,%f)\n", location->description, location->latitude,  location->longitude);
+        g_print ("Location: %s (%f,%f)\n",
+                 geocode_location_get_description (location),
+                 geocode_location_get_latitude (location),
+                 geocode_location_get_longitude (location));
 
         g_object_unref (location);
         g_object_unref (object);


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