Commit f82aa454 authored by Bastien Nocera's avatar Bastien Nocera

Remove custom GClueLocationInfo object

And use a copy-pasted version of geocode-glib's GeocodeLocation
object instead, so we don't end up duplicating bug fixes in
both projects.
parent bf7371e9
......@@ -31,8 +31,6 @@ geoclue_SOURCES = \
gclue-error.c \
gclue-ipclient.h \
gclue-ipclient.c \
gclue-location-info.h \
gclue-location-info.c \
gclue-locator.h \
gclue-locator.c \
gclue-service-manager.h \
......@@ -41,6 +39,8 @@ geoclue_SOURCES = \
gclue-service-client.c \
gclue-service-location.h \
gclue-service-location.c \
geocode-location.c \
geocode-location.h \
$(NULL)
geoclue_CFLAGS = $(GEOCLUE_CFLAGS) \
......
......@@ -29,6 +29,7 @@
#include "gclue-ipclient.h"
#include "gclue-error.h"
#include "geoip-server/geoip-server.h"
#include "geocode-location.h"
/**
* SECTION:gclue-ipclient
......@@ -395,17 +396,17 @@ static gdouble
get_accuracy_from_string (const char *str)
{
if (strcmp (str, "street") == 0)
return GCLUE_LOCATION_INFO_ACCURACY_STREET;
return GEOCODE_LOCATION_ACCURACY_STREET;
else if (strcmp (str, "city") == 0)
return GCLUE_LOCATION_INFO_ACCURACY_CITY;
return GEOCODE_LOCATION_ACCURACY_CITY;
else if (strcmp (str, "region") == 0)
return GCLUE_LOCATION_INFO_ACCURACY_REGION;
return GEOCODE_LOCATION_ACCURACY_REGION;
else if (strcmp (str, "country") == 0)
return GCLUE_LOCATION_INFO_ACCURACY_COUNTRY;
return GEOCODE_LOCATION_ACCURACY_COUNTRY;
else if (strcmp (str, "continent") == 0)
return GCLUE_LOCATION_INFO_ACCURACY_CONTINENT;
return GEOCODE_LOCATION_ACCURACY_CONTINENT;
else
return GCLUE_LOCATION_INFO_ACCURACY_UNKNOWN;
return GEOCODE_LOCATION_ACCURACY_UNKNOWN;
}
static gdouble
......@@ -417,28 +418,28 @@ get_accuracy_from_json_location (JsonObject *object)
str = json_object_get_string_member (object, "accuracy");
return get_accuracy_from_string (str);
} else if (json_object_has_member (object, "street")) {
return GCLUE_LOCATION_INFO_ACCURACY_STREET;
return GEOCODE_LOCATION_ACCURACY_STREET;
} else if (json_object_has_member (object, "city")) {
return GCLUE_LOCATION_INFO_ACCURACY_CITY;
return GEOCODE_LOCATION_ACCURACY_CITY;
} else if (json_object_has_member (object, "region_name")) {
return GCLUE_LOCATION_INFO_ACCURACY_REGION;
return GEOCODE_LOCATION_ACCURACY_REGION;
} else if (json_object_has_member (object, "country_name")) {
return GCLUE_LOCATION_INFO_ACCURACY_COUNTRY;
return GEOCODE_LOCATION_ACCURACY_COUNTRY;
} else if (json_object_has_member (object, "continent")) {
return GCLUE_LOCATION_INFO_ACCURACY_CONTINENT;
return GEOCODE_LOCATION_ACCURACY_CONTINENT;
} else {
return GCLUE_LOCATION_INFO_ACCURACY_UNKNOWN;
return GEOCODE_LOCATION_ACCURACY_UNKNOWN;
}
}
static GClueLocationInfo *
static GeocodeLocation *
_gclue_ip_json_to_location (const char *json,
GError **error)
{
JsonParser *parser;
JsonNode *node;
JsonObject *object;
GClueLocationInfo *location;
GeocodeLocation *location;
gdouble latitude, longitude, accuracy;
char *desc = NULL;
......@@ -457,7 +458,7 @@ _gclue_ip_json_to_location (const char *json,
longitude = json_object_get_double_member (object, "longitude");
accuracy = get_accuracy_from_json_location (object);
location = gclue_location_info_new (latitude, longitude, accuracy);
location = geocode_location_new (latitude, longitude, accuracy);
if (json_object_has_member (object, "country_name")) {
if (json_object_has_member (object, "region_name")) {
......@@ -478,7 +479,7 @@ _gclue_ip_json_to_location (const char *json,
}
if (desc != NULL) {
gclue_location_info_set_description (location, desc);
geocode_location_set_description (location, desc);
g_free (desc);
}
......@@ -495,17 +496,17 @@ _gclue_ip_json_to_location (const char *json,
*
* Finishes a geolocation search operation. See gclue_ipclient_search_async().
*
* Returns: (transfer full): A #GClueLocationInfo object or %NULL in case of
* Returns: (transfer full): A #GeocodeLocation object or %NULL in case of
* errors. Free the returned object with g_object_unref() when done.
**/
GClueLocationInfo *
GeocodeLocation *
gclue_ipclient_search_finish (GClueIpclient *ipclient,
GAsyncResult *res,
GError **error)
{
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
char *contents = NULL;
GClueLocationInfo *location;
GeocodeLocation *location;
g_return_val_if_fail (GCLUE_IS_IPCLIENT (ipclient), NULL);
......@@ -529,16 +530,16 @@ gclue_ipclient_search_finish (GClueIpclient *ipclient,
*
* Gets the geolocation data for an IP address from the server.
*
* Returns: (transfer full): A #GClueLocationInfo object or %NULL in case of
* Returns: (transfer full): A #GeocodeLocation object or %NULL in case of
* errors. Free the returned object with g_object_unref() when done.
**/
GClueLocationInfo *
GeocodeLocation *
gclue_ipclient_search (GClueIpclient *ipclient,
GError **error)
{
char *contents;
SoupMessage *query;
GClueLocationInfo *location;
GeocodeLocation *location;
g_return_val_if_fail (GCLUE_IS_IPCLIENT (ipclient), NULL);
g_return_val_if_fail (ipclient->priv->server != NULL, NULL);
......
......@@ -26,7 +26,7 @@
#include <glib.h>
#include <gio/gio.h>
#include "gclue-location-info.h"
#include "geocode-location.h"
G_BEGIN_DECLS
......@@ -72,11 +72,11 @@ void gclue_ipclient_search_async (GClueIpclient *ipclient,
GAsyncReadyCallback callback,
gpointer user_data);
GClueLocationInfo *gclue_ipclient_search_finish (GClueIpclient *ipclient,
GeocodeLocation *gclue_ipclient_search_finish (GClueIpclient *ipclient,
GAsyncResult *res,
GError **error);
GClueLocationInfo *gclue_ipclient_search (GClueIpclient *ipclient,
GeocodeLocation *gclue_ipclient_search (GClueIpclient *ipclient,
GError **error);
G_END_DECLS
......
This diff is collapsed.
/* vim: set et ts=8 sw=8: */
/* gclue-location-info.h
*
* Copyright (C) 2013 Red Hat, Inc.
* Copyright (C) 2012 Bastien Nocera
*
* Geoclue is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* Geoclue 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 General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with Geoclue; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Bastien Nocera <hadess@hadess.net>
* Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
*/
#ifndef GCLUE_LOCATION_INFO_H
#define GCLUE_LOCATION_INFO_H
#include <glib-object.h>
G_BEGIN_DECLS
GType gclue_location_info_get_type (void) G_GNUC_CONST;
#define GCLUE_TYPE_LOCATION_INFO (gclue_location_info_get_type ())
#define GCLUE_LOCATION_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCLUE_TYPE_LOCATION_INFO, GClueLocationInfo))
#define GCLUE_IS_LOCATION_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCLUE_TYPE_LOCATION_INFO))
#define GCLUE_LOCATION_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCLUE_TYPE_LOCATION_INFO, GClueLocationInfoClass))
#define GCLUE_IS_LOCATION_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCLUE_TYPE_LOCATION_INFO))
#define GCLUE_LOCATION_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCLUE_TYPE_LOCATION_INFO, GClueLocationInfoClass))
typedef struct _GClueLocationInfo GClueLocationInfo;
typedef struct _GClueLocationInfoClass GClueLocationInfoClass;
typedef struct _GClueLocationInfoPrivate GClueLocationInfoPrivate;
/**
* GClueLocationInfo:
*
* All the fields in the #GClueLocationInfo structure are private and should never be accessed directly.
**/
struct _GClueLocationInfo {
/* <private> */
GObject parent_instance;
GClueLocationInfoPrivate *priv;
};
/**
* GClueLocationInfoClass:
*
* All the fields in the #GClueLocationInfoClass structure are private and should never be accessed directly.
**/
struct _GClueLocationInfoClass {
/* <private> */
GObjectClass parent_class;
};
#define GCLUE_LOCATION_INFO_ACCURACY_UNKNOWN -1
#define GCLUE_LOCATION_INFO_ACCURACY_STREET 1000 /* 1 km */
#define GCLUE_LOCATION_INFO_ACCURACY_CITY 15000 /* 15 km */
#define GCLUE_LOCATION_INFO_ACCURACY_REGION 50000 /* 50 km */
#define GCLUE_LOCATION_INFO_ACCURACY_COUNTRY 300000 /* 300 km */
#define GCLUE_LOCATION_INFO_ACCURACY_CONTINENT 3000000 /* 3000 km */
GClueLocationInfo *gclue_location_info_new (gdouble latitude,
gdouble longitude,
gdouble accuracy);
GClueLocationInfo *gclue_location_info_new_with_description (gdouble latitude,
gdouble longitude,
gdouble accuracy,
const char *description);
double gclue_location_info_get_distance_from (GClueLocationInfo *loca,
GClueLocationInfo *locb);
void gclue_location_info_set_description (GClueLocationInfo *loc,
const char *description);
const char *gclue_location_info_get_description (GClueLocationInfo *loc);
gdouble gclue_location_info_get_latitude (GClueLocationInfo *loc);
gdouble gclue_location_info_get_longitude (GClueLocationInfo *loc);
gdouble gclue_location_info_get_accuracy (GClueLocationInfo *loc);
guint64 gclue_location_info_get_timestamp (GClueLocationInfo *loc);
G_END_DECLS
#endif /* GCLUE_LOCATION_INFO_H */
......@@ -33,7 +33,7 @@ struct _GClueLocatorPrivate
{
GClueIpclient *ipclient;
GClueLocationInfo *location;
GeocodeLocation *location;
GCancellable *cancellable;
......@@ -107,7 +107,7 @@ gclue_locator_class_init (GClueLocatorClass *klass)
gParamSpecs[PROP_LOCATION] = g_param_spec_object ("location",
"Location",
"Location",
GCLUE_TYPE_LOCATION_INFO,
GEOCODE_TYPE_LOCATION,
G_PARAM_READABLE);
g_object_class_install_property (object_class,
PROP_LOCATION,
......@@ -131,19 +131,19 @@ gclue_locator_new (void)
}
static void
gclue_locator_update_location (GClueLocator *locator,
GClueLocationInfo *location)
gclue_locator_update_location (GClueLocator *locator,
GeocodeLocation *location)
{
GClueLocatorPrivate *priv = locator->priv;
if (priv->location == NULL)
priv->location = g_object_new (GCLUE_TYPE_LOCATION_INFO, NULL);
priv->location = g_object_new (GEOCODE_TYPE_LOCATION, NULL);
g_object_set (priv->location,
"latitude", gclue_location_info_get_latitude (location),
"longitude", gclue_location_info_get_longitude (location),
"accuracy", gclue_location_info_get_accuracy (location),
"description", gclue_location_info_get_description (location),
"latitude", geocode_location_get_latitude (location),
"longitude", geocode_location_get_longitude (location),
"accuracy", geocode_location_get_accuracy (location),
"description", geocode_location_get_description (location),
NULL);
g_object_notify (G_OBJECT (locator), "location");
......@@ -156,7 +156,7 @@ on_ipclient_search_ready (GObject *source_object,
{
GClueIpclient *ipclient = GCLUE_IPCLIENT (source_object);
GClueLocator *locator = GCLUE_LOCATOR (user_data);
GClueLocationInfo *location;
GeocodeLocation *location;
GError *error = NULL;
location = gclue_ipclient_search_finish (ipclient, res, &error);
......@@ -300,7 +300,7 @@ gclue_locator_stop_finish (GClueLocator *locator,
return TRUE;
}
GClueLocationInfo * gclue_locator_get_location (GClueLocator *locator)
GeocodeLocation * gclue_locator_get_location (GClueLocator *locator)
{
g_return_val_if_fail (GCLUE_IS_LOCATOR (locator), NULL);
......
......@@ -24,7 +24,7 @@
#define GCLUE_LOCATOR_H
#include <gio/gio.h>
#include "gclue-location-info.h"
#include "geocode-location.h"
G_BEGIN_DECLS
......@@ -70,7 +70,7 @@ void gclue_locator_stop (GClueLocator *locator,
gboolean gclue_locator_stop_finish (GClueLocator *locator,
GAsyncResult *res,
GError **error);
GClueLocationInfo * gclue_locator_get_location (GClueLocator *locator);
GeocodeLocation * gclue_locator_get_location (GClueLocator *locator);
guint gclue_locator_get_threshold (GClueLocator *locator);
void gclue_locator_set_threshold (GClueLocator *locator,
guint threshold);
......
......@@ -114,10 +114,10 @@ emit_location_updated (GClueServiceClient *client,
static gboolean
below_threshold (GClueServiceClient *client,
GClueLocationInfo *location)
GeocodeLocation *location)
{
GClueServiceClientPrivate *priv = client->priv;
GClueLocationInfo *cur_location;
GeocodeLocation *cur_location;
gdouble distance;
gdouble threshold_km;
......@@ -127,8 +127,8 @@ below_threshold (GClueServiceClient *client,
g_object_get (priv->location,
"location", &cur_location,
NULL);
distance = gclue_location_info_get_distance_from (cur_location,
location);
distance = geocode_location_get_distance_from (cur_location,
location);
g_object_unref (cur_location);
threshold_km = priv->threshold / 1000.0;
......@@ -146,7 +146,7 @@ on_locator_location_changed (GObject *gobject,
GClueServiceClient *client = GCLUE_SERVICE_CLIENT (user_data);
GClueServiceClientPrivate *priv = client->priv;
GClueLocator *locator = GCLUE_LOCATOR (gobject);
GClueLocationInfo *location_info;
GeocodeLocation *location_info;
char *path = NULL;
const char *prev_path;
GError *error = NULL;
......
......@@ -89,9 +89,9 @@ gclue_service_location_get_property (GObject *object,
case PROP_LOCATION:
{
GClueLocationInfo *loc;
GeocodeLocation *loc;
loc = gclue_location_info_new_with_description
loc = geocode_location_new_with_description
(gclue_location_get_latitude (location),
gclue_location_get_longitude (location),
gclue_location_get_accuracy (location),
......@@ -130,17 +130,17 @@ gclue_service_location_set_property (GObject *object,
case PROP_LOCATION:
{
GClueLocationInfo *loc;
GeocodeLocation *loc;
loc = g_value_get_object (value);
gclue_location_set_latitude
(location, gclue_location_info_get_latitude (loc));
(location, geocode_location_get_latitude (loc));
gclue_location_set_longitude
(location, gclue_location_info_get_longitude (loc));
(location, geocode_location_get_longitude (loc));
gclue_location_set_accuracy
(location, gclue_location_info_get_accuracy (loc));
(location, geocode_location_get_accuracy (loc));
gclue_location_set_description
(location, gclue_location_info_get_description (loc));
(location, geocode_location_get_description (loc));
break;
}
......@@ -312,7 +312,7 @@ gclue_service_location_class_init (GClueServiceLocationClass *klass)
gParamSpecs[PROP_LOCATION] = g_param_spec_object ("location",
"Location",
"Location",
GCLUE_TYPE_LOCATION_INFO,
GEOCODE_TYPE_LOCATION,
G_PARAM_READWRITE);
g_object_class_install_property (object_class,
PROP_LOCATION,
......@@ -349,7 +349,7 @@ GClueServiceLocation *
gclue_service_location_new (const char *peer,
const char *path,
GDBusConnection *connection,
GClueLocationInfo *location,
GeocodeLocation *location,
GError **error)
{
return g_initable_new (GCLUE_TYPE_SERVICE_LOCATION,
......
......@@ -24,7 +24,7 @@
#define GCLUE_SERVICE_LOCATION_H
#include <glib-object.h>
#include "gclue-location-info.h"
#include "geocode-location.h"
#include "geoclue-interface.h"
G_BEGIN_DECLS
......@@ -59,7 +59,7 @@ GType gclue_service_location_get_type (void) G_GNUC_CONST;
GClueServiceLocation * gclue_service_location_new (const char *peer,
const char *path,
GDBusConnection *connection,
GClueLocationInfo *location,
GeocodeLocation *location,
GError **error);
const char * gclue_service_location_get_path (GClueServiceLocation *location);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment