From f24639ef9250be9334259086c943ad4161afced0 Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Tue, 10 Sep 2013 00:15:38 +0200 Subject: [PATCH 6/7] locator: Keep track of last notified location ... and emit the LocationUpdated signal when we cross the distance threshold compared to the previously notified location. https://bugs.freedesktop.org/show_bug.cgi?id=69105 --- src/gclue-locator.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/gclue-locator.c b/src/gclue-locator.c index 10a72f6..462c70c 100644 --- a/src/gclue-locator.c +++ b/src/gclue-locator.c @@ -34,6 +34,7 @@ struct _GClueLocatorPrivate GClueIpclient *ipclient; GClueLocationInfo *location; + GClueLocationInfo *last_notified_location; guint threshold; GCancellable *cancellable; @@ -64,6 +65,7 @@ gclue_locator_finalize (GObject *object) gclue_locator_stop_sync (GCLUE_LOCATOR (object)); g_clear_object (&priv->ipclient); g_clear_object (&priv->location); + g_clear_object (&priv->last_notified_location); G_OBJECT_CLASS (gclue_locator_parent_class)->finalize (object); } @@ -161,26 +163,37 @@ gclue_locator_update_location (GClueLocator *locator, GClueLocationInfo *location) { GClueLocatorPrivate *priv = locator->priv; + gboolean notify_location = TRUE; gdouble distance; gdouble threshold_km; if (priv->location == NULL) goto update; - threshold_km = priv->threshold / 1000.0; - distance = gclue_location_info_get_distance_from (priv->location, - location); - if (gclue_location_info_equal (priv->location, location) && - distance < threshold_km) { + if (gclue_location_info_equal (priv->location, location)) { g_debug ("Location remains unchanged"); return; } + if (priv->last_notified_location != NULL) { + threshold_km = priv->threshold / 1000.0; + distance = gclue_location_info_get_distance_from (priv->last_notified_location, + location); + if (distance < threshold_km) + notify_location = FALSE; + } + update: g_debug ("Updating location"); g_clear_object (&priv->location); priv->location = g_object_ref (location); - g_object_notify (G_OBJECT (locator), "location"); + + if (notify_location) { + g_debug ("Notifying location update"); + g_clear_object (&priv->last_notified_location); + priv->last_notified_location = g_object_ref (location); + g_object_notify (G_OBJECT (locator), "location"); + } } static void -- 1.8.3.1