[geocode-glib/wip/place-details: 2/3] lib: Introducing GeocodePlace class



commit 1165653e798be730af571df37cd982cb0c7ef6a1
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Apr 24 19:34:02 2013 +0300

    lib: Introducing GeocodePlace class
    
    Add a new class to represent particular places with a proper name and
    type. Also optionally includes all sorts of properties, like location,
    town, state, country etc.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697405

 docs/geocode-glib-docs.xml        |    1 +
 geocode-glib/Makefile.am          |    6 +-
 geocode-glib/geocode-glib.h       |    1 +
 geocode-glib/geocode-glib.symbols |   26 ++
 geocode-glib/geocode-place.c      |  750 +++++++++++++++++++++++++++++++++++++
 geocode-glib/geocode-place.h      |  183 +++++++++
 6 files changed, 965 insertions(+), 2 deletions(-)
---
diff --git a/docs/geocode-glib-docs.xml b/docs/geocode-glib-docs.xml
index a21008c..fc6534d 100644
--- a/docs/geocode-glib-docs.xml
+++ b/docs/geocode-glib-docs.xml
@@ -21,6 +21,7 @@
        <xi:include href="xml/geocode-error.xml"/>
        <xi:include href="xml/geocode-forward.xml"/>
        <xi:include href="xml/geocode-location.xml"/>
+       <xi:include href="xml/geocode-place.xml"/>
        <xi:include href="xml/geocode-reverse.xml"/>
        <xi:include href="xml/geocode-ipclient.xml"/>
 
diff --git a/geocode-glib/Makefile.am b/geocode-glib/Makefile.am
index f886178..b7c3458 100644
--- a/geocode-glib/Makefile.am
+++ b/geocode-glib/Makefile.am
@@ -16,7 +16,8 @@ libgeocode_glib_la_SOURCES =                          \
        geocode-error.c                                 \
        geocode-ipclient.c                              \
        geocode-enum-types.c                            \
-       geocode-glib-private.h
+       geocode-glib-private.h                          \
+       geocode-place.c
 
 libgeocode_glib_la_LIBADD = $(GEOCODE_LIBS) $(LIBS)
 
@@ -32,7 +33,8 @@ GCGLIB_HEADER_FILES = \
        geocode-forward.h                               \
        geocode-reverse.h                               \
        geocode-error.h                                 \
-       geocode-ipclient.h
+       geocode-ipclient.h                              \
+       geocode-place.h
 
 gcglibdir = $(pkgincludedir)
 gcglib_HEADERS =                                       \
diff --git a/geocode-glib/geocode-glib.h b/geocode-glib/geocode-glib.h
index 53a5fba..917e6bb 100644
--- a/geocode-glib/geocode-glib.h
+++ b/geocode-glib/geocode-glib.h
@@ -26,6 +26,7 @@
 #include <glib.h>
 #include <gio/gio.h>
 #include <geocode-glib/geocode-location.h>
+#include <geocode-glib/geocode-place.h>
 #include <geocode-glib/geocode-forward.h>
 #include <geocode-glib/geocode-reverse.h>
 #include <geocode-glib/geocode-ipclient.h>
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index f6291e9..64c635a 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -31,3 +31,29 @@ geocode_ipclient_new_for_ip
 geocode_ipclient_search_async
 geocode_ipclient_search
 geocode_ipclient_search_finish
+geocode_place_get_type
+geocode_place_type_get_type
+geocode_place_new
+geocode_place_new_with_location
+geocode_place_get_name
+geocode_place_get_place_type
+geocode_place_set_location
+geocode_place_get_location
+geocode_place_set_street_address
+geocode_place_get_street_address
+geocode_place_set_postal_code
+geocode_place_get_postal_code
+geocode_place_set_town
+geocode_place_get_town
+geocode_place_set_county
+geocode_place_get_county
+geocode_place_set_state
+geocode_place_get_state
+geocode_place_set_administrative_area
+geocode_place_get_administrative_area
+geocode_place_set_country_code
+geocode_place_get_country_code
+geocode_place_set_country
+geocode_place_get_country
+geocode_place_set_continent
+geocode_place_get_continent
diff --git a/geocode-glib/geocode-place.c b/geocode-glib/geocode-place.c
new file mode 100644
index 0000000..4beae55
--- /dev/null
+++ b/geocode-glib/geocode-place.c
@@ -0,0 +1,750 @@
+/*
+   Copyright (C) 2012 Bastien Nocera
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301  USA.
+
+   Authors: Bastien Nocera <hadess hadess net>
+            Zeeshan Ali (Khattak) <zeeshanak gnome org>
+
+ */
+
+#include "geocode-place.h"
+#include "geocode-enum-types.h"
+
+/**
+ * SECTION:geocode-place
+ * @short_description: Geocode place object
+ * @include: geocode-glib/geocode-glib.h
+ *
+ * The #GeocodePlace instance represents a place on earth. While
+ * #GeocodeLocation represents a point on the planet, #GeocodePlace represents
+ * places, e.g street, town, village, county, country or points of interest
+ * (POI) etc.
+ **/
+
+struct _GeocodePlacePrivate {
+        char *name;
+        GeocodePlaceType place_type;
+        GeocodeLocation *location;
+
+        char *street_address;
+        char *postal_code;
+        char *town;
+        char *county;
+        char *state;
+        char *admin_area;
+        char *country_code;
+        char *country;
+        char *continent;
+};
+
+enum {
+        PROP_0,
+
+        PROP_NAME,
+        PROP_PLACE_TYPE,
+        PROP_LOCATION,
+        PROP_STREET_ADDRESS,
+        PROP_POSTAL_CODE,
+        PROP_TOWN,
+        PROP_COUNTY,
+        PROP_STATE,
+        PROP_ADMINISTRATIVE_AREA,
+        PROP_COUNTRY_CODE,
+        PROP_COUNTRY,
+        PROP_CONTINENT,
+};
+
+G_DEFINE_TYPE (GeocodePlace, geocode_place, G_TYPE_OBJECT)
+
+static void
+geocode_place_get_property (GObject    *object,
+                            guint       property_id,
+                            GValue     *value,
+                            GParamSpec *pspec)
+{
+        GeocodePlace *place = GEOCODE_PLACE (object);
+
+        switch (property_id) {
+        case PROP_NAME:
+                g_value_set_string (value,
+                                    geocode_place_get_name (place));
+                break;
+
+        case PROP_PLACE_TYPE:
+                g_value_set_enum (value,
+                                  geocode_place_get_place_type (place));
+                break;
+
+        case PROP_LOCATION:
+                g_value_set_object (value,
+                                    geocode_place_get_location (place));
+                break;
+
+        case PROP_STREET_ADDRESS:
+                g_value_set_string (value,
+                                    geocode_place_get_street_address (place));
+                break;
+
+        case PROP_POSTAL_CODE:
+                g_value_set_string (value,
+                                    geocode_place_get_postal_code (place));
+                break;
+
+        case PROP_TOWN:
+                g_value_set_string (value,
+                                    geocode_place_get_town (place));
+                break;
+
+        case PROP_COUNTY:
+                g_value_set_string (value,
+                                    geocode_place_get_county (place));
+                break;
+
+        case PROP_STATE:
+                g_value_set_string (value,
+                                    geocode_place_get_state (place));
+                break;
+
+        case PROP_ADMINISTRATIVE_AREA:
+                g_value_set_string (value,
+                                    geocode_place_get_administrative_area (place));
+                break;
+
+        case PROP_COUNTRY_CODE:
+                g_value_set_string (value,
+                                    geocode_place_get_country_code (place));
+                break;
+
+        case PROP_COUNTRY:
+                g_value_set_string (value,
+                                    geocode_place_get_country (place));
+                break;
+
+        case PROP_CONTINENT:
+                g_value_set_string (value,
+                                    geocode_place_get_continent (place));
+                break;
+
+        default:
+                /* We don't have any other property... */
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+geocode_place_set_property(GObject      *object,
+                           guint         property_id,
+                           const GValue *value,
+                           GParamSpec   *pspec)
+{
+        GeocodePlace *place = GEOCODE_PLACE (object);
+
+        switch (property_id) {
+        case PROP_NAME:
+                place->priv->name = g_value_dup_string (value);
+                break;
+
+        case PROP_PLACE_TYPE:
+                place->priv->place_type = g_value_get_enum (value);
+                break;
+
+        case PROP_LOCATION:
+                place->priv->location = g_value_dup_object (value);
+                break;
+
+        case PROP_STREET_ADDRESS:
+                geocode_place_set_street_address (place,
+                                                  g_value_get_string (value));
+                break;
+
+        case PROP_POSTAL_CODE:
+                geocode_place_set_postal_code (place,
+                                               g_value_get_string (value));
+                break;
+
+        case PROP_TOWN:
+                geocode_place_set_town (place, g_value_get_string (value));
+                break;
+
+        case PROP_COUNTY:
+                geocode_place_set_county (place, g_value_get_string (value));
+                break;
+
+        case PROP_STATE:
+                geocode_place_set_state (place, g_value_get_string (value));
+                break;
+
+        case PROP_ADMINISTRATIVE_AREA:
+                geocode_place_set_administrative_area (place,
+                                                       g_value_get_string (value));
+                break;
+
+        case PROP_COUNTRY_CODE:
+                geocode_place_set_country_code (place,
+                                                g_value_get_string (value));
+                break;
+
+        case PROP_COUNTRY:
+                geocode_place_set_country (place,
+                                           g_value_get_string (value));
+                break;
+
+        case PROP_CONTINENT:
+                geocode_place_set_continent (place, g_value_get_string (value));
+                break;
+
+        default:
+                /* We don't have any other property... */
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                break;
+        }
+}
+
+static void
+geocode_place_dispose (GObject *gplace)
+{
+        GeocodePlace *place = (GeocodePlace *) gplace;
+
+        g_clear_object (&place->priv->location);
+
+        G_OBJECT_CLASS (geocode_place_parent_class)->dispose (gplace);
+}
+
+static void
+geocode_place_finalize (GObject *gplace)
+{
+        GeocodePlace *place = (GeocodePlace *) gplace;
+
+        g_clear_pointer (&place->priv->name, g_free);
+        g_clear_pointer (&place->priv->street_address, g_free);
+        g_clear_pointer (&place->priv->postal_code, g_free);
+        g_clear_pointer (&place->priv->town, g_free);
+        g_clear_pointer (&place->priv->county, g_free);
+        g_clear_pointer (&place->priv->state, g_free);
+        g_clear_pointer (&place->priv->admin_area, g_free);
+        g_clear_pointer (&place->priv->country_code, g_free);
+        g_clear_pointer (&place->priv->country, g_free);
+        g_clear_pointer (&place->priv->continent, g_free);
+
+        G_OBJECT_CLASS (geocode_place_parent_class)->finalize (gplace);
+}
+
+static void
+geocode_place_class_init (GeocodePlaceClass *klass)
+{
+        GObjectClass *gplace_class = G_OBJECT_CLASS (klass);
+        GParamSpec *pspec;
+
+        gplace_class->dispose = geocode_place_dispose;
+        gplace_class->finalize = geocode_place_finalize;
+        gplace_class->get_property = geocode_place_get_property;
+        gplace_class->set_property = geocode_place_set_property;
+
+        g_type_class_add_private (klass, sizeof (GeocodePlacePrivate));
+
+        /**
+         * GeocodePlace:name:
+         *
+         * The name of the place.
+         */
+        pspec = g_param_spec_string ("name",
+                                     "Name",
+                                     "Name",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_CONSTRUCT_ONLY |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_NAME, pspec);
+
+        /**
+         * GeocodePlace:place-type:
+         *
+         * The type of the place.
+         */
+        pspec = g_param_spec_enum ("place-type",
+                                   "PlaceType",
+                                   "Place Type",
+                                   GEOCODE_TYPE_PLACE_TYPE,
+                                   GEOCODE_PLACE_TYPE_UNKNOWN,
+                                   G_PARAM_READWRITE |
+                                   G_PARAM_CONSTRUCT_ONLY |
+                                   G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_PLACE_TYPE, pspec);
+
+        /**
+         * GeocodePlace:location:
+         *
+         * The location info for the place.
+         */
+        pspec = g_param_spec_object ("location",
+                                     "Location",
+                                     "Location Info",
+                                     GEOCODE_TYPE_LOCATION,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_LOCATION, pspec);
+
+        /**
+         * GeocodePlace:street-address:
+         *
+         * The street address.
+         */
+        pspec = g_param_spec_string ("street-address",
+                                     "StreetAddress",
+                                     "Street Address",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_STREET_ADDRESS, pspec);
+
+        /**
+         * GeocodePlace:postal-code:
+         *
+         * The postal code.
+         */
+        pspec = g_param_spec_string ("postal-code",
+                                     "PostalCode",
+                                     "Postal Code",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_POSTAL_CODE, pspec);
+
+        /**
+         * GeocodePlace:town:
+         *
+         * The town.
+         */
+        pspec = g_param_spec_string ("town",
+                                     "Town",
+                                     "Town",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_TOWN, pspec);
+
+        /**
+         * GeocodePlace:state:
+         *
+         * The state.
+         */
+        pspec = g_param_spec_string ("state",
+                                     "State",
+                                     "State",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_STATE, pspec);
+
+        /**
+         * GeocodePlace:county:
+         *
+         * The county.
+         */
+        pspec = g_param_spec_string ("county",
+                                     "County",
+                                     "County",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_COUNTY, pspec);
+
+        /**
+         * GeocodePlace:administrative-area:
+         *
+         * The local administrative area.
+         */
+        pspec = g_param_spec_string ("administrative-area",
+                                     "AdministrativeArea",
+                                     "Local administrative area",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_ADMINISTRATIVE_AREA, pspec);
+
+        /**
+         * GeocodePlace:country-code:
+         *
+         * The country code.
+         */
+        pspec = g_param_spec_string ("country-code",
+                                     "CountryCode",
+                                     "ISO Country Code",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_COUNTRY_CODE, pspec);
+
+        /**
+         * GeocodePlace:country:
+         *
+         * The country.
+         */
+        pspec = g_param_spec_string ("country",
+                                     "Country",
+                                     "Country",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_COUNTRY, pspec);
+
+        /**
+         * GeocodePlace:continent:
+         *
+         * The continent.
+         */
+        pspec = g_param_spec_string ("continent",
+                                     "Continent",
+                                     "Continent",
+                                     NULL,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_STATIC_STRINGS);
+        g_object_class_install_property (gplace_class, PROP_CONTINENT, pspec);
+}
+
+static void
+geocode_place_init (GeocodePlace *place)
+{
+        place->priv = G_TYPE_INSTANCE_GET_PRIVATE ((place),
+                                                      GEOCODE_TYPE_PLACE,
+                                                      GeocodePlacePrivate);
+}
+
+/**
+ * geocode_place_new:
+ * @name: the name of place
+ * @place_type: the type of place
+ *
+ * Creates a new #GeocodePlace object.
+ *
+ * Returns: a new #GeocodePlace object. Use g_object_unref() when done.
+ **/
+GeocodePlace *
+geocode_place_new (const char      *name,
+                   GeocodePlaceType place_type)
+{
+        return g_object_new (GEOCODE_TYPE_PLACE,
+                             "name", name,
+                             "place-type", place_type,
+                             NULL);
+}
+
+/**
+ * geocode_place_new_with_description:
+ * @name: the name of place
+ * @place_type: the type of place
+ * @location: the location info for the place
+ *
+ * Creates a new #GeocodePlace object.
+ *
+ * Returns: a new #GeocodePlace object. Use g_object_unref() when done.
+ **/
+GeocodePlace *
+geocode_place_new_with_location (const char      *name,
+                                 GeocodePlaceType place_type,
+                                 GeocodeLocation *location)
+{
+        return g_object_new (GEOCODE_TYPE_PLACE,
+                             "name", name,
+                             "place-type", place_type,
+                             "location", location,
+                             NULL);
+}
+
+const char *
+geocode_place_get_name (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->name;
+}
+
+GeocodePlaceType
+geocode_place_get_place_type (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place),
+                              GEOCODE_PLACE_TYPE_UNKNOWN);
+
+        return place->priv->place_type;
+}
+
+/**
+ * geocode_place_set_location:
+ * @place: A place
+ * @location: A location
+ *
+ * Sets the location of @place to @location.
+ **/
+void
+geocode_place_set_location (GeocodePlace *place,
+                            GeocodeLocation *location)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (GEOCODE_IS_LOCATION (location));
+
+        g_clear_object (&place->priv->location);
+        place->priv->location = g_object_ref (location);
+}
+
+/**
+ * geocode_place_get_location:
+ * @place: A place
+ *
+ * Returns: (transfer none): The associated location object.
+ **/
+GeocodeLocation *
+geocode_place_get_location (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->location;
+}
+
+/**
+ * geocode_place_set_street_address:
+ * @place: A place
+ * @street_address: a street address for the place
+ *
+ * Sets the street address of @place to @street_address.
+ **/
+void
+geocode_place_set_street_address (GeocodePlace *place,
+                                  const char   *street_address)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (street_address != NULL);
+
+        g_free (place->priv->street_address);
+        place->priv->street_address = g_strdup (street_address);
+}
+
+const char *
+geocode_place_get_street_address (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->street_address;
+}
+
+/**
+ * geocode_place_set_postal_code:
+ * @place: A place
+ * @postal_code: a postal code for the place
+ *
+ * Sets the postal code of @place to @postal_code.
+ **/
+void
+geocode_place_set_postal_code (GeocodePlace *place,
+                               const char   *postal_code)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (postal_code != NULL);
+
+        g_free (place->priv->postal_code);
+        place->priv->postal_code = g_strdup (postal_code);
+}
+
+const char *
+geocode_place_get_postal_code (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->postal_code;
+}
+
+/**
+ * geocode_place_set_town:
+ * @place: A place
+ * @town: a town for the place
+ *
+ * Sets the town of @place to @town.
+ **/
+void
+geocode_place_set_town (GeocodePlace *place,
+                        const char   *town)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (town != NULL);
+
+        g_free (place->priv->town);
+        place->priv->town = g_strdup (town);
+}
+
+const char *
+geocode_place_get_town (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->town;
+}
+
+/**
+ * geocode_place_set_county:
+ * @place: A place
+ * @county: a county for the place
+ *
+ * Sets the county of @place to @county.
+ **/
+void
+geocode_place_set_county (GeocodePlace *place,
+                          const char   *county)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (county != NULL);
+
+        g_free (place->priv->county);
+        place->priv->county = g_strdup (county);
+}
+
+const char *
+geocode_place_get_county (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->county;
+}
+
+/**
+ * geocode_place_set_state:
+ * @place: A place
+ * @state: a state for the place
+ *
+ * Sets the state of @place to @state.
+ **/
+void
+geocode_place_set_state (GeocodePlace *place,
+                         const char   *state)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (state != NULL);
+
+        g_free (place->priv->state);
+        place->priv->state = g_strdup (state);
+}
+
+const char *
+geocode_place_get_state (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->state;
+}
+
+/**
+ * geocode_place_set_administrative_area:
+ * @place: A place
+ * @admin_area: an administrative area for the place
+ *
+ * Sets the local administrative area of @place to @admin_area.
+ **/
+void
+geocode_place_set_administrative_area (GeocodePlace *place,
+                                       const char   *admin_area)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (admin_area != NULL);
+
+        g_free (place->priv->admin_area);
+        place->priv->admin_area = g_strdup (admin_area);
+}
+
+const char *
+geocode_place_get_administrative_area (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->admin_area;
+}
+
+/**
+ * geocode_place_set_country_code:
+ * @place: A place
+ * @country_code: an ISO country code for the place
+ *
+ * Sets the ISO country code of @place to @country_code.
+ **/
+void
+geocode_place_set_country_code (GeocodePlace *place,
+                                const char   *country_code)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (country_code != NULL);
+
+        g_free (place->priv->country_code);
+        place->priv->country_code = g_strdup (country_code);
+}
+
+const char *
+geocode_place_get_country_code (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->country_code;
+}
+
+/**
+ * geocode_place_set_country:
+ * @place: A place
+ * @country: a country for the place
+ *
+ * Sets the country of @place to @country.
+ **/
+void
+geocode_place_set_country (GeocodePlace *place,
+                           const char   *country)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (country != NULL);
+
+        g_free (place->priv->country);
+        place->priv->country = g_strdup (country);
+}
+
+const char *
+geocode_place_get_country (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->country;
+}
+
+/**
+ * geocode_place_set_continent:
+ * @place: A place
+ * @continent: a continent for the place
+ *
+ * Sets the continent of @place to @continent.
+ **/
+void
+geocode_place_set_continent (GeocodePlace *place,
+                             const char   *continent)
+{
+        g_return_if_fail (GEOCODE_IS_PLACE (place));
+        g_return_if_fail (continent != NULL);
+
+        g_free (place->priv->continent);
+        place->priv->continent = g_strdup (continent);
+}
+
+const char *
+geocode_place_get_continent (GeocodePlace *place)
+{
+        g_return_val_if_fail (GEOCODE_IS_PLACE (place), NULL);
+
+        return place->priv->continent;
+}
diff --git a/geocode-glib/geocode-place.h b/geocode-glib/geocode-place.h
new file mode 100644
index 0000000..d4ef648
--- /dev/null
+++ b/geocode-glib/geocode-place.h
@@ -0,0 +1,183 @@
+/*
+   Copyright (C) 2012 Bastien Nocera
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301  USA.
+
+   Authors: Bastien Nocera <hadess hadess net>
+            Zeeshan Ali (Khattak) <zeeshanak gnome org>
+
+ */
+
+#ifndef GEOCODE_PLACE_H
+#define GEOCODE_PLACE_H
+
+#include <glib-object.h>
+#include "geocode-location.h"
+
+G_BEGIN_DECLS
+
+GType geocode_place_get_type (void) G_GNUC_CONST;
+
+#define GEOCODE_TYPE_PLACE                  (geocode_place_get_type ())
+#define GEOCODE_PLACE(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCODE_TYPE_PLACE, 
GeocodePlace))
+#define GEOCODE_IS_PLACE(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOCODE_TYPE_PLACE))
+#define GEOCODE_PLACE_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GEOCODE_TYPE_PLACE, 
GeocodePlaceClass))
+#define GEOCODE_IS_PLACE_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GEOCODE_TYPE_PLACE))
+#define GEOCODE_PLACE_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GEOCODE_TYPE_PLACE, 
GeocodePlaceClass))
+
+typedef struct _GeocodePlace        GeocodePlace;
+typedef struct _GeocodePlaceClass   GeocodePlaceClass;
+typedef struct _GeocodePlacePrivate GeocodePlacePrivate;
+
+/**
+ * GeocodePlace:
+ *
+ * All the fields in the #GeocodePlace structure are private and should never be accessed directly.
+**/
+struct _GeocodePlace {
+        /* <private> */
+        GObject parent_instance;
+        GeocodePlacePrivate *priv;
+};
+
+/**
+ * GeocodePlaceClass:
+ *
+ * All the fields in the #GeocodePlaceClass structure are private and should never be accessed directly.
+**/
+struct _GeocodePlaceClass {
+        /* <private> */
+        GObjectClass parent_class;
+};
+
+/**
+ * GeocodePlaceType:
+ * @GEOCODE_PLACE_TYPE_UNKNOWN: Type is unknown for this place.
+ * @GEOCODE_PLACE_TYPE_TOWN: A populated settlement such as a city, town, village.
+ * @GEOCODE_PLACE_TYPE_STATE: One of the primary administrative areas within a country.
+ * @GEOCODE_PLACE_TYPE_COUNTY: One of the secondary administrative areas within a country.
+ * @GEOCODE_PLACE_TYPE_LOCAL_ADMINISTRATIVE_AREA: One of the tertiary administrative areas within a country.
+ * @GEOCODE_PLACE_TYPE_POSTAL_CODE: A partial or full postal code.
+ * @GEOCODE_PLACE_TYPE_COUNTRY: One of the countries or dependent territories defined by the ISO 3166-1 
standard.
+ * @GEOCODE_PLACE_TYPE_ISLAND: An island.
+ * @GEOCODE_PLACE_TYPE_AIRPORT: An airport.
+ * @GEOCODE_PLACE_TYPE_DRAINAGE: A water feature such as a river, canal, lake, bay or ocean.
+ * @GEOCODE_PLACE_TYPE_LAND_FEATURE: A land feature such as a park, mountain or beach.
+ * @GEOCODE_PLACE_TYPE_MISCELLANEOUS: A uncategorized place.
+ * @GEOCODE_PLACE_TYPE_SUPERNAME: An area covering multiple countries.
+ * @GEOCODE_PLACE_TYPE_POINT_OF_INTEREST: A point of interest such as a school, hospital or tourist 
attraction.
+ * @GEOCODE_PLACE_TYPE_SUBURB: A subdivision of a town such as a suburb or neighborhood.
+ * @GEOCODE_PLACE_TYPE_COLLOQUIAL: A place known by a colloquial name.
+ * @GEOCODE_PLACE_TYPE_ZONE: An area known within a specific context such as MSA or area code.
+ * @GEOCODE_PLACE_TYPE_HISTORICAL_STATE: A historical primary administrative area within a country.
+ * @GEOCODE_PLACE_TYPE_HISTORICAL_COUNTY: A historical secondary administrative area within a country.
+ * @GEOCODE_PLACE_TYPE_CONTINENT: One of the major land masses on the Earth.
+ * @GEOCODE_PLACE_TYPE_TIME_ZONE: An area defined by the Olson standard (tz database).
+ * @GEOCODE_PLACE_TYPE_ESTATE: A housing development or subdivision known by name.
+ * @GEOCODE_PLACE_TYPE_HISTORICAL_TOWN: A historical populated settlement that is no longer known by its 
original name.
+ * @GEOCODE_PLACE_TYPE_OCEAN: One of the five major bodies of water on the Earth.
+ * @GEOCODE_PLACE_TYPE_SEA: An area of open water smaller than an ocean.
+ *
+ * Type of the place.
+ */
+typedef enum {
+        GEOCODE_PLACE_TYPE_UNKNOWN = 0,
+        GEOCODE_PLACE_TYPE_TOWN = 7,
+        GEOCODE_PLACE_TYPE_STATE = 8,
+        GEOCODE_PLACE_TYPE_COUNTY = 9,
+        GEOCODE_PLACE_TYPE_LOCAL_ADMINISTRATIVE_AREA = 10,
+        GEOCODE_PLACE_TYPE_POSTAL_CODE = 11,
+        GEOCODE_PLACE_TYPE_COUNTRY = 12,
+        GEOCODE_PLACE_TYPE_ISLAND = 13,
+        GEOCODE_PLACE_TYPE_AIRPORT = 14,
+        GEOCODE_PLACE_TYPE_DRAINAGE = 15,
+        GEOCODE_PLACE_TYPE_LAND_FEATURE = 16,
+        GEOCODE_PLACE_TYPE_MISCELLANEOUS = 17,
+        GEOCODE_PLACE_TYPE_SUPERNAME = 19,
+        GEOCODE_PLACE_TYPE_POINT_OF_INTEREST = 20,
+        GEOCODE_PLACE_TYPE_SUBURB = 22,
+        GEOCODE_PLACE_TYPE_COLLOQUIAL = 24,
+        GEOCODE_PLACE_TYPE_ZONE = 25,
+        GEOCODE_PLACE_TYPE_HISTORICAL_STATE = 26,
+        GEOCODE_PLACE_TYPE_HISTORICAL_COUNTY = 27,
+        GEOCODE_PLACE_TYPE_CONTINENT = 29,
+        GEOCODE_PLACE_TYPE_TIME_ZONE = 31,
+        GEOCODE_PLACE_TYPE_ESTATE = 33,
+        GEOCODE_PLACE_TYPE_HISTORICAL_TOWN = 35,
+        GEOCODE_PLACE_TYPE_OCEAN = 37,
+        GEOCODE_PLACE_TYPE_SEA = 38
+} GeocodePlaceType;
+
+/* The above values and their explanation is based on Yahoo places API:
+ *
+ * http://where.yahooapis.com/v1/placetypes?select=long&appid=YOUR_APP_ID
+ */
+
+#define GEOCODE_TYPE_PLACE (geocode_place_get_type ())
+
+GeocodePlace *geocode_place_new                   (const char      *name,
+                                                   GeocodePlaceType place_type);
+GeocodePlace *geocode_place_new_with_location     (const char      *name,
+                                                   GeocodePlaceType place_type,
+                                                   GeocodeLocation *location);
+
+const char *geocode_place_get_name                (GeocodePlace *place);
+
+GeocodePlaceType geocode_place_get_place_type     (GeocodePlace *place);
+
+void geocode_place_set_location                   (GeocodePlace    *place,
+                                                   GeocodeLocation *location);
+GeocodeLocation *geocode_place_get_location       (GeocodePlace *place);
+
+void geocode_place_set_street_address             (GeocodePlace *place,
+                                                   const char   *street_address);
+const char *geocode_place_get_street_address      (GeocodePlace *place);
+
+void geocode_place_set_postal_code                (GeocodePlace *place,
+                                                   const char   *postal_code);
+const char *geocode_place_get_postal_code         (GeocodePlace *place);
+
+void geocode_place_set_town                       (GeocodePlace *place,
+                                                   const char   *town);
+const char *geocode_place_get_town                (GeocodePlace *place);
+
+void geocode_place_set_county                     (GeocodePlace *place,
+                                                   const char   *county);
+const char *geocode_place_get_county              (GeocodePlace *place);
+
+void geocode_place_set_state                      (GeocodePlace *place,
+                                                   const char   *state);
+const char *geocode_place_get_state               (GeocodePlace *place);
+
+void geocode_place_set_administrative_area        (GeocodePlace *place,
+                                                   const char   *admin_area);
+const char *geocode_place_get_administrative_area (GeocodePlace *place);
+
+void geocode_place_set_country_code               (GeocodePlace *place,
+                                                   const char   *country_code);
+const char *geocode_place_get_country_code        (GeocodePlace *place);
+
+void geocode_place_set_country                    (GeocodePlace *place,
+                                                   const char   *country);
+const char *geocode_place_get_country             (GeocodePlace *place);
+
+void geocode_place_set_continent                  (GeocodePlace *place,
+                                                   const char   *continent);
+const char *geocode_place_get_continent           (GeocodePlace *place);
+
+G_END_DECLS
+
+#endif /* GEOCODE_PLACE_H */


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