aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>2008-12-17 06:40:49 +0800
committerPierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk>2009-06-01 23:35:30 +0800
commit5faf7832ec78b463808f857a6ffdb8da958355ca (patch)
tree438d6860463f0eca06784e4d5e7ff2b9bb3ae4aa
parent82235fee6f56b8dc3c0d7c84e9349a06ceb616e9 (diff)
downloadgsoc2013-empathy-5faf7832ec78b463808f857a6ffdb8da958355ca.tar
gsoc2013-empathy-5faf7832ec78b463808f857a6ffdb8da958355ca.tar.gz
gsoc2013-empathy-5faf7832ec78b463808f857a6ffdb8da958355ca.tar.bz2
gsoc2013-empathy-5faf7832ec78b463808f857a6ffdb8da958355ca.tar.lz
gsoc2013-empathy-5faf7832ec78b463808f857a6ffdb8da958355ca.tar.xz
gsoc2013-empathy-5faf7832ec78b463808f857a6ffdb8da958355ca.tar.zst
gsoc2013-empathy-5faf7832ec78b463808f857a6ffdb8da958355ca.zip
Implement reduced accuracy
-rw-r--r--libempathy-gtk/empathy-location-manager.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/libempathy-gtk/empathy-location-manager.c b/libempathy-gtk/empathy-location-manager.c
index 2e61d8d5e..caa40b5cd 100644
--- a/libempathy-gtk/empathy-location-manager.c
+++ b/libempathy-gtk/empathy-location-manager.c
@@ -57,6 +57,8 @@ typedef struct {
GeocluePosition *gc_position;
GeoclueAddress *gc_address;
#endif
+ gboolean reduce_accuracy;
+ gdouble reduce_value;
} EmpathyLocationManagerPriv;
static void location_manager_finalize (GObject *object);
@@ -77,6 +79,8 @@ static void publish_cb (EmpathyConf *conf, const gchar *key,
static void update_resources (EmpathyLocationManager *location_manager);
static void resource_cb (EmpathyConf *conf, const gchar *key,
gpointer user_data);
+static void accuracy_cb (EmpathyConf *conf, const gchar *key,
+ gpointer user_data);
#endif
G_DEFINE_TYPE (EmpathyLocationManager, empathy_location_manager, G_TYPE_OBJECT);
@@ -178,10 +182,13 @@ empathy_location_manager_init (EmpathyLocationManager *location_manager)
resource_cb, location_manager);
empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
resource_cb, location_manager);
+ empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
+ accuracy_cb, location_manager);
resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK, location_manager);
resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_CELL, location_manager);
resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS, location_manager);
+ accuracy_cb (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY, location_manager);
publish_cb (conf, EMPATHY_PREFS_LOCATION_PUBLISH, location_manager);
// Setup account status callbacks
@@ -315,6 +322,7 @@ position_changed_cb (GeocluePosition *position,
if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)
{
+ longitude += priv->reduce_value;
new_value = tp_g_value_slice_new (G_TYPE_DOUBLE);
g_value_set_double (new_value, longitude);
g_hash_table_insert (priv->location, EMPATHY_LOCATION_LON, new_value);
@@ -322,6 +330,7 @@ position_changed_cb (GeocluePosition *position,
}
if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)
{
+ latitude += priv->reduce_value;
new_value = tp_g_value_slice_new (G_TYPE_DOUBLE);
g_value_set_double (new_value, latitude);
g_hash_table_insert (priv->location, EMPATHY_LOCATION_LAT, new_value);
@@ -360,6 +369,10 @@ address_foreach_cb (gpointer key,
EmpathyLocationManagerPriv *priv;
priv = GET_PRIV (location_manager);
+ // Discard street information if reduced accuracy is on
+ if (priv->reduce_accuracy && strcmp (key, EMPATHY_LOCATION_STREET) == 0)
+ return;
+
GValue *new_value = tp_g_value_slice_new (G_TYPE_STRING);
g_value_set_string (new_value, value);
@@ -510,7 +523,42 @@ publish_cb (EmpathyConf *conf,
}
-static void
+static void
+accuracy_cb (EmpathyConf *conf,
+ const gchar *key,
+ gpointer user_data)
+{
+ EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
+ EmpathyLocationManagerPriv *priv;
+
+ gboolean enabled;
+
+ priv = GET_PRIV (manager);
+ DEBUG ("%s changed", key);
+
+ if (!empathy_conf_get_bool (conf, key, &enabled))
+ return;
+ priv->reduce_accuracy = enabled;
+
+ if (enabled)
+ {
+ GRand *rand = g_rand_new_with_seed (time (NULL));
+ priv->reduce_value = g_rand_double_range (rand, -0.25, 0.25);
+ g_rand_free (rand);
+ }
+ else
+ priv->reduce_value = 0.0;
+
+ if (!priv->is_setup)
+ return;
+
+ geoclue_address_get_address_async (priv->gc_address,
+ initial_address_cb, manager);
+ geoclue_position_get_position_async (priv->gc_position,
+ initial_position_cb, manager);
+}
+
+static void
resource_cb (EmpathyConf *conf,
const gchar *key,
gpointer user_data)