[geocode-glib: 5/6] lib: geocode_reverse_resolve*() now returns GeocodePlace
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib: 5/6] lib: geocode_reverse_resolve*() now returns GeocodePlace
- Date: Tue, 30 Jul 2013 13:07:11 +0000 (UTC)
commit fad7155b8bc8e5f74ac22d529df82529c1a47580
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Jun 18 18:22:32 2013 +0200
lib: geocode_reverse_resolve*() now returns GeocodePlace
Instead of returning a hashtable, reverse geocoding functions now return
a GeocodePlace instance.
https://bugzilla.gnome.org/show_bug.cgi?id=705112
geocode-glib/geocode-reverse.c | 45 +++++++++++++++++++---------------
geocode-glib/geocode-reverse.h | 11 ++++----
geocode-glib/test-gcglib.c | 51 ++++++++++++++++-----------------------
3 files changed, 52 insertions(+), 55 deletions(-)
---
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 8d36549..79cd19d 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -236,7 +236,7 @@ resolve_json (const char *contents,
ret = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
- _geocode_read_nominatim_attributes (reader, ret, TRUE);
+ _geocode_read_nominatim_attributes (reader, ret, FALSE);
g_object_unref (parser);
g_object_unref (reader);
@@ -292,7 +292,7 @@ on_cache_data_loaded (GObject *source_object,
GFile *cache;
GError *error = NULL;
char *contents;
- gpointer ret;
+ GHashTable *result;
cache = G_FILE (source_object);
if (g_file_load_contents_finish (cache,
@@ -314,13 +314,18 @@ on_cache_data_loaded (GObject *source_object,
return;
}
- ret = resolve_json (contents, &error);
+ result = resolve_json (contents, &error);
g_free (contents);
- if (ret == NULL)
+ if (result == NULL) {
g_simple_async_result_take_error (simple, error);
- else
- g_simple_async_result_set_op_res_gpointer (simple, ret, NULL);
+ } else {
+ GeocodePlace *place;
+
+ place = _geocode_create_place_from_attributes (result);
+ g_hash_table_destroy (result);
+ g_simple_async_result_set_op_res_gpointer (simple, place, NULL);
+ }
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
@@ -439,12 +444,10 @@ geocode_reverse_resolve_async (GeocodeReverse *object,
*
* Finishes a reverse geocoding operation. See geocode_reverse_resolve_async().
*
- * Returns: (element-type utf8 utf8) (transfer full):
- * a #GHashTable containing the results of the query
- * or %NULL in case of errors.
- * Free the returned string with g_hash_table_destroy() when done.
+ * Returns: (transfer full): A #GeocodePlace instance, or %NULL in case of
+ * errors. Free the returned instance with #g_object_unref() when done.
**/
-GHashTable *
+GeocodePlace *
geocode_reverse_resolve_finish (GeocodeReverse *object,
GAsyncResult *res,
GError **error)
@@ -469,18 +472,17 @@ geocode_reverse_resolve_finish (GeocodeReverse *object,
* Gets the result of a reverse geocoding
* query using a web service.
*
- * Returns: (element-type utf8 utf8) (transfer full):
- * a #GHashTable containing the results of the query
- * or %NULL in case of errors.
- * Free the returned string with g_hash_table_destroy() when done.
+ * Returns: (transfer full): A #GeocodePlace instance, or %NULL in case of
+ * errors. Free the returned instance with #g_object_unref() when done.
**/
-GHashTable *
+GeocodePlace *
geocode_reverse_resolve (GeocodeReverse *object,
GError **error)
{
SoupMessage *query;
char *contents;
- GHashTable *ret;
+ GHashTable *result;
+ GeocodePlace *place;
gboolean to_cache = FALSE;
g_return_val_if_fail (GEOCODE_IS_REVERSE (object), NULL);
@@ -500,12 +502,15 @@ geocode_reverse_resolve (GeocodeReverse *object,
to_cache = TRUE;
}
- ret = resolve_json (contents, error);
- if (to_cache && ret != NULL)
+ result = resolve_json (contents, error);
+ if (to_cache && result != NULL)
_geocode_glib_cache_save (query, contents);
g_free (contents);
g_object_unref (query);
- return ret;
+ place = _geocode_create_place_from_attributes (result);
+ g_hash_table_destroy (result);
+
+ return place;
}
diff --git a/geocode-glib/geocode-reverse.h b/geocode-glib/geocode-reverse.h
index 5e7d688..a64d535 100644
--- a/geocode-glib/geocode-reverse.h
+++ b/geocode-glib/geocode-reverse.h
@@ -25,6 +25,7 @@
#include <glib.h>
#include <gio/gio.h>
+#include "geocode-place.h"
G_BEGIN_DECLS
@@ -69,12 +70,12 @@ void geocode_reverse_resolve_async (GeocodeReverse *object,
GAsyncReadyCallback callback,
gpointer user_data);
-GHashTable *geocode_reverse_resolve_finish (GeocodeReverse *object,
- GAsyncResult *res,
- GError **error);
+GeocodePlace *geocode_reverse_resolve_finish (GeocodeReverse *object,
+ GAsyncResult *res,
+ GError **error);
-GHashTable *geocode_reverse_resolve (GeocodeReverse *object,
- GError **error);
+GeocodePlace *geocode_reverse_resolve (GeocodeReverse *object,
+ GError **error);
G_END_DECLS
diff --git a/geocode-glib/test-gcglib.c b/geocode-glib/test-gcglib.c
index 03d5840..3f9a135 100644
--- a/geocode-glib/test-gcglib.c
+++ b/geocode-glib/test-gcglib.c
@@ -31,33 +31,24 @@ print_place (GeocodePlace *place)
}
static void
-print_res (const char *key,
- const char *value,
- gpointer data)
-{
- g_print ("\t%s = %s\n", key, value);
-}
-
-static void
got_geocode_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GeocodeReverse *object = (GeocodeReverse *) source_object;
- GHashTable *ht;
+ GeocodePlace *place;
GError *error = NULL;
- ht = geocode_reverse_resolve_finish (object, res, &error);
- if (ht == NULL) {
+ place = geocode_reverse_resolve_finish (object, res, &error);
+ if (place == NULL) {
g_message ("Failed to get geocode: %s", error->message);
g_error_free (error);
exit (1);
}
g_print ("Got geocode answer:\n");
- g_hash_table_foreach (ht, (GHFunc) print_res, NULL);
- g_hash_table_destroy (ht);
-
+ print_place (place);
+ g_object_unref (place);
g_object_unref (object);
exit (0);
@@ -99,34 +90,34 @@ test_rev (void)
GeocodeLocation *loc;
GeocodeReverse *rev;
GError *error = NULL;
- GHashTable *ht;
+ GeocodePlace *place;
loc = geocode_location_new (51.237070, -0.589669, GEOCODE_LOCATION_ACCURACY_UNKNOWN);
rev = geocode_reverse_new_for_location (loc);
g_object_unref (loc);
- ht = geocode_reverse_resolve (rev, &error);
- if (ht == NULL) {
+ place = geocode_reverse_resolve (rev, &error);
+ if (place == NULL) {
g_warning ("Failed at reverse geocoding: %s", error->message);
g_error_free (error);
}
- g_assert (ht != NULL);
+ g_assert (place != NULL);
g_object_unref (rev);
- g_assert_cmpstr (g_hash_table_lookup (ht, "postalcode"), ==, "GU2 7UP");
- g_assert_cmpstr (g_hash_table_lookup (ht, "area"), ==, "Guildford Park");
- g_assert_cmpstr (g_hash_table_lookup (ht, "countrycode"), ==, "gb");
- g_assert_cmpstr (g_hash_table_lookup (ht, "street"), ==, "Old Palace Road");
- g_assert_cmpstr (g_hash_table_lookup (ht, "county"), ==, "Surrey");
- g_assert_cmpstr (g_hash_table_lookup (ht, "locality"), ==, "Guildford");
- g_assert_cmpstr (g_hash_table_lookup (ht, "pub"), ==, "The Astolat");
- g_assert_cmpstr (g_hash_table_lookup (ht, "country"), ==, "United Kingdom");
- g_assert_cmpstr (g_hash_table_lookup (ht, "state_district"), ==, "South East England");
- g_assert_cmpstr (g_hash_table_lookup (ht, "region"), ==, "England");
+ g_assert_cmpstr (geocode_place_get_name (place), ==, "The Astolat");
+ g_assert_cmpstr (geocode_place_get_postal_code (place), ==, "GU2 7UP");
+ g_assert_cmpstr (geocode_place_get_area (place), ==, "Guildford Park");
+ g_assert_cmpstr (geocode_place_get_country_code (place), ==, "gb");
+ g_assert_cmpstr (geocode_place_get_street (place), ==, "Old Palace Road");
+ g_assert_cmpstr (geocode_place_get_county (place), ==, "Surrey");
+ g_assert_cmpstr (geocode_place_get_town (place), ==, "Guildford");
+ g_assert_cmpstr (geocode_place_get_country (place), ==, "United Kingdom");
+ g_assert_cmpstr (geocode_place_get_administrative_area (place), ==, "South East England");
+ g_assert_cmpstr (geocode_place_get_state (place), ==, "England");
g_print ("Got geocode answer:\n");
- g_hash_table_foreach (ht, (GHFunc) print_res, NULL);
- g_hash_table_destroy (ht);
+ print_place (place);
+ g_object_unref (place);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]