[geocode-glib] lib: Add geocode_object_new_for_params_str() function
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] lib: Add geocode_object_new_for_params_str() function
- Date: Wed, 24 Oct 2012 16:42:36 +0000 (UTC)
commit 81dd3b883a95673c85de34b55a0cfa8da89e8bb1
Author: Bastien Nocera <hadess hadess net>
Date: Wed Oct 24 16:02:19 2012 +0200
lib: Add geocode_object_new_for_params_str() function
geocode-glib/geocode-glib.c | 71 +++++++++++++++++++++++++++++++------
geocode-glib/geocode-glib.h | 9 +++--
geocode-glib/geocode-glib.symbols | 1 +
3 files changed, 66 insertions(+), 15 deletions(-)
---
diff --git a/geocode-glib/geocode-glib.c b/geocode-glib/geocode-glib.c
index af9cd10..8d9fb48 100644
--- a/geocode-glib/geocode-glib.c
+++ b/geocode-glib/geocode-glib.c
@@ -244,6 +244,40 @@ struct {
{ "language", NULL }, /* FIXME: Should we ignore this? */
};
+static void
+geocode_object_fill_params (GeocodeObject *object,
+ GHashTable *params,
+ gboolean value_is_str)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (attrs_map); i++) {
+ const char *str;
+
+ if (attrs_map[i].gc_attr == NULL)
+ continue;
+
+ if (value_is_str == FALSE) {
+ GValue *value;
+
+ value = g_hash_table_lookup (params, attrs_map[i].tp_attr);
+ if (value == NULL)
+ continue;
+
+ str = g_value_get_string (value);
+ } else {
+ str = g_hash_table_lookup (params, attrs_map[i].tp_attr);
+ }
+
+ if (str == NULL)
+ continue;
+
+ geocode_object_add (object,
+ attrs_map[i].gc_attr,
+ str);
+ }
+}
+
/**
* geocode_object_new_for_params:
* @params: (transfer none) (element-type utf8 GValue): a #GHashTable with string keys, and #GValue values.
@@ -260,7 +294,6 @@ GeocodeObject *
geocode_object_new_for_params (GHashTable *params)
{
GeocodeObject *object;
- guint i;
g_return_val_if_fail (params != NULL, NULL);
@@ -271,22 +304,38 @@ geocode_object_new_for_params (GHashTable *params)
}
object = g_object_new (GEOCODE_TYPE_OBJECT, NULL);
+ geocode_object_fill_params (object, params, FALSE);
- for (i = 0; i < G_N_ELEMENTS (attrs_map); i++) {
- GValue *value;
+ return object;
+}
- if (attrs_map[i].gc_attr == NULL)
- continue;
+/**
+ * geocode_object_new_for_params_str:
+ * @params_str: (transfer none) (element-type utf8 utf8): a #GHashTable with string keys, and string values.
+ *
+ * Creates a new #GeocodeObject to perform geocoding with. The
+ * #GHashTable uses the same keys used by Telepathy, and documented
+ * on <ulink url="http://telepathy.freedesktop.org/spec/Connection_Interface_Location.html#Mapping:Location">Telepathy's specification site</ulink>,
+ * with the difference that all the values are passed as strings.
+ *
+ * Returns: a new #GeocodeObject. Use g_object_unref() when done.
+ **/
+GeocodeObject *
+geocode_object_new_for_params_str (GHashTable *params_str)
+{
+ GeocodeObject *object;
- value = g_hash_table_lookup (params, attrs_map[i].tp_attr);
- if (value == NULL)
- continue;
+ g_return_val_if_fail (params_str != NULL, NULL);
- geocode_object_add (object,
- attrs_map[i].gc_attr,
- g_value_get_string (value));
+ if (g_hash_table_lookup (params_str, "lat") != NULL &&
+ g_hash_table_lookup (params_str, "long") != NULL) {
+ g_warning ("You already have longitude and latitude in those parameters");
+ return NULL;
}
+ object = g_object_new (GEOCODE_TYPE_OBJECT, NULL);
+ geocode_object_fill_params (object, params_str, TRUE);
+
return object;
}
diff --git a/geocode-glib/geocode-glib.h b/geocode-glib/geocode-glib.h
index 9ad5009..be34540 100644
--- a/geocode-glib/geocode-glib.h
+++ b/geocode-glib/geocode-glib.h
@@ -259,10 +259,11 @@ struct _GeocodeObjectClass {
**/
#define GEOCODE_OBJECT_FIELD_OFFSETLON "offsetlon"
-GeocodeObject *geocode_object_new_for_params (GHashTable *params);
-GeocodeObject *geocode_object_new_for_location (const char *location);
-GeocodeObject *geocode_object_new_for_coords (gdouble latitude,
- gdouble longitude);
+GeocodeObject *geocode_object_new_for_params (GHashTable *params);
+GeocodeObject *geocode_object_new_for_params_str (GHashTable *params_str);
+GeocodeObject *geocode_object_new_for_location (const char *location);
+GeocodeObject *geocode_object_new_for_coords (gdouble latitude,
+ gdouble longitude);
void geocode_object_add (GeocodeObject *object,
const char *key,
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index 13933f4..b715cb1 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -2,6 +2,7 @@ geocode_error_quark
geocode_object_get_type
geocode_object_new
geocode_object_new_for_params
+geocode_object_new_for_params_str
geocode_object_new_for_coords
geocode_object_new_for_location
geocode_object_add
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]