Commit 308437d1 authored by Zeeshan Ali's avatar Zeeshan Ali

locator: Derive from LocationSource

Locator itself is just a master LocationSource really.
parent 11f09d77
......@@ -29,14 +29,17 @@
/* This class will be responsible for doing the actual geolocating. */
G_DEFINE_TYPE (GClueLocator, gclue_locator, G_TYPE_OBJECT)
static void
gclue_locator_start (GClueLocationSource *source);
static void
gclue_locator_stop (GClueLocationSource *source);
G_DEFINE_TYPE (GClueLocator, gclue_locator, GCLUE_TYPE_LOCATION_SOURCE)
struct _GClueLocatorPrivate
{
GList *sources;
GeocodeLocation *location;
gboolean active;
GClueAccuracyLevel accuracy_level;
......@@ -45,21 +48,12 @@ struct _GClueLocatorPrivate
enum
{
PROP_0,
PROP_LOCATION,
PROP_ACCURACY_LEVEL,
LAST_PROP
};
static GParamSpec *gParamSpecs[LAST_PROP];
static void
gclue_locator_finalize (GObject *object)
{
gclue_locator_stop (GCLUE_LOCATOR (object));
G_OBJECT_CLASS (gclue_locator_parent_class)->finalize (object);
}
static void
gclue_locator_get_property (GObject *object,
guint prop_id,
......@@ -69,10 +63,6 @@ gclue_locator_get_property (GObject *object,
GClueLocator *locator = GCLUE_LOCATOR (object);
switch (prop_id) {
case PROP_LOCATION:
g_value_set_object (value, locator->priv->location);
break;
case PROP_ACCURACY_LEVEL:
g_value_set_enum (value, locator->priv->accuracy_level);
break;
......@@ -103,23 +93,17 @@ gclue_locator_set_property (GObject *object,
static void
gclue_locator_class_init (GClueLocatorClass *klass)
{
GClueLocationSourceClass *source_class = GCLUE_LOCATION_SOURCE_CLASS (klass);
GObjectClass *object_class;
source_class->start = gclue_locator_start;
source_class->stop = gclue_locator_stop;
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gclue_locator_finalize;
object_class->get_property = gclue_locator_get_property;
object_class->set_property = gclue_locator_set_property;
g_type_class_add_private (object_class, sizeof (GClueLocatorPrivate));
gParamSpecs[PROP_LOCATION] = g_param_spec_object ("location",
"Location",
"Location",
GEOCODE_TYPE_LOCATION,
G_PARAM_READABLE);
g_object_class_install_property (object_class,
PROP_LOCATION,
gParamSpecs[PROP_LOCATION]);
gParamSpecs[PROP_ACCURACY_LEVEL] = g_param_spec_enum ("accuracy-level",
"AccuracyLevel",
"Accuracy level",
......@@ -151,17 +135,18 @@ on_location_changed (GObject *gobject,
GParamSpec *pspec,
gpointer user_data)
{
GClueLocator *locator = GCLUE_LOCATOR (user_data);
GClueLocatorPrivate *priv = locator->priv;
GClueLocationSource *locator = GCLUE_LOCATION_SOURCE (user_data);
GClueLocationSource *source = GCLUE_LOCATION_SOURCE (gobject);
GeocodeLocation *location = gclue_location_source_get_location (source);
GeocodeLocation *location, *cur_location;
cur_location = gclue_location_source_get_location (locator);
location = gclue_location_source_get_location (source);
g_debug ("New location available");
if (priv->location == NULL)
priv->location = g_object_new (GEOCODE_TYPE_LOCATION, NULL);
else if (geocode_location_get_accuracy (location) >=
geocode_location_get_accuracy (priv->location)) {
if (cur_location != NULL &&
geocode_location_get_accuracy (location) >=
geocode_location_get_accuracy (cur_location)) {
/* We only take the new location if its more or as accurate as
* the previous one.
*/
......@@ -169,19 +154,13 @@ on_location_changed (GObject *gobject,
return;
}
g_object_set (priv->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");
gclue_location_source_set_location (locator, location);
}
void
gclue_locator_start (GClueLocator *locator)
static void
gclue_locator_start (GClueLocationSource *source)
{
GClueLocator *locator = GCLUE_LOCATOR (source);
GClueIpclient *ipclient;
GClueWifi *wifi;
GList *node;
......@@ -211,9 +190,10 @@ gclue_locator_start (GClueLocator *locator)
}
}
void
gclue_locator_stop (GClueLocator *locator)
static void
gclue_locator_stop (GClueLocationSource *source)
{
GClueLocator *locator = GCLUE_LOCATOR (source);
GClueLocatorPrivate *priv = locator->priv;
GList *node;
......@@ -221,17 +201,9 @@ gclue_locator_stop (GClueLocator *locator)
gclue_location_source_stop (GCLUE_LOCATION_SOURCE (node->data));
g_list_free_full (priv->sources, g_object_unref);
priv->sources = NULL;
g_clear_object (&priv->location);
locator->priv->active = FALSE;
}
GeocodeLocation * gclue_locator_get_location (GClueLocator *locator)
{
g_return_val_if_fail (GCLUE_IS_LOCATOR (locator), NULL);
return locator->priv->location;
}
GClueAccuracyLevel
gclue_locator_get_accuracy_level (GClueLocator *locator)
{
......
......@@ -26,6 +26,7 @@
#include <gio/gio.h>
#include "geocode-location.h"
#include "gclue-enum-types.h"
#include "gclue-location-source.h"
G_BEGIN_DECLS
......@@ -43,7 +44,7 @@ typedef struct _GClueLocatorPrivate GClueLocatorPrivate;
struct _GClueLocator
{
GObject parent;
GClueLocationSource parent;
/*< private >*/
GClueLocatorPrivate *priv;
......@@ -51,15 +52,12 @@ struct _GClueLocator
struct _GClueLocatorClass
{
GObjectClass parent_class;
GClueLocationSourceClass parent_class;
};
GType gclue_locator_get_type (void) G_GNUC_CONST;
GClueLocator * gclue_locator_new (void);
void gclue_locator_start (GClueLocator *locator);
void gclue_locator_stop (GClueLocator *locator);
GeocodeLocation * gclue_locator_get_location (GClueLocator *locator);
GClueAccuracyLevel gclue_locator_get_accuracy_level
(GClueLocator *locator);
void gclue_locator_set_accuracy_level
......
......@@ -145,13 +145,13 @@ on_locator_location_changed (GObject *gobject,
{
GClueServiceClient *client = GCLUE_SERVICE_CLIENT (user_data);
GClueServiceClientPrivate *priv = client->priv;
GClueLocator *locator = GCLUE_LOCATOR (gobject);
GClueLocationSource *locator = GCLUE_LOCATION_SOURCE (gobject);
GeocodeLocation *location_info;
char *path = NULL;
const char *prev_path;
GError *error = NULL;
location_info = gclue_locator_get_location (locator);
location_info = gclue_location_source_get_location (locator);
if (priv->location != NULL && below_threshold (client, location_info)) {
g_debug ("Updating location, below threshold");
......@@ -243,7 +243,7 @@ on_authorize_app_ready (GObject *source_object,
"notify::location",
G_CALLBACK (on_locator_location_changed),
data->client);
gclue_locator_start (priv->locator);
gclue_location_source_start (GCLUE_LOCATION_SOURCE (priv->locator));
gclue_client_complete_start (GCLUE_CLIENT (data->client),
data->invocation);
......@@ -296,7 +296,7 @@ gclue_service_client_handle_start (GClueClient *client,
G_CALLBACK (on_locator_location_changed),
data->client);
gclue_locator_start (priv->locator);
gclue_location_source_start (GCLUE_LOCATION_SOURCE (priv->locator));
gclue_client_complete_start (GCLUE_CLIENT (client),
invocation);
start_data_free (data);
......@@ -330,7 +330,7 @@ gclue_service_client_handle_stop (GClueClient *client,
priv->location_change_id = 0;
}
gclue_locator_stop (priv->locator);
gclue_location_source_start (GCLUE_LOCATION_SOURCE (priv->locator));
gclue_client_complete_stop (client, invocation);
return TRUE;
......
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