]> git.0d.be Git - empathy.git/commitdiff
Fix reduced accuracy concerns
authorPierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk>
Thu, 2 Jul 2009 18:25:48 +0000 (14:25 -0400)
committerPierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk>
Thu, 6 Aug 2009 13:58:18 +0000 (09:58 -0400)
As pointed out by users, the previous reduced accuracy mode
was not the best.  It is better to trunkate the coordinates
rather than adding a random value to it.

This patch also replaces strcmp by tp_strdiff

libempathy-gtk/empathy-location-manager.c
src/empathy-preferences.ui

index 278af72f263d0e88f093cb8963140cb6ea0911a3..087ce5644d85ac7f87b2ffd5b02ebfabc5d7b6eb 100644 (file)
 
 #include "config.h"
 
+/* Needed for trunc */
+#define _ISOC9X_SOURCE 1
+#define _ISOC99_SOURCE 1
+#include <math.h>
 #include <string.h>
 #include <time.h>
 
@@ -63,7 +67,6 @@ typedef struct {
     GeoclueAddress *gc_address;
 
     gboolean reduce_accuracy;
-    gdouble reduce_value;
     EmpathyAccountManager *account_manager;
 
     /* The idle id for publish_on_idle func */
@@ -312,7 +315,8 @@ address_changed_cb (GeoclueAddress *address,
     {
       GValue *new_value;
       /* Discard street information if reduced accuracy is on */
-      if (priv->reduce_accuracy && strcmp (key, EMPATHY_LOCATION_STREET) == 0)
+      if (priv->reduce_accuracy &&
+          !tp_strdiff (key, EMPATHY_LOCATION_STREET))
         continue;
 
       new_value = tp_g_value_slice_new_string (value);
@@ -368,7 +372,11 @@ position_changed_cb (GeocluePosition *position,
 
   if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)
     {
-      longitude += priv->reduce_value;
+
+      if (priv->reduce_accuracy)
+        /* Truncate at 1 decimal place */
+        longitude = trunc (longitude * 10.0) / 10.0;
+
       new_value = tp_g_value_slice_new_double (longitude);
       g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_LON),
           new_value);
@@ -381,7 +389,10 @@ position_changed_cb (GeocluePosition *position,
 
   if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)
     {
-      latitude += priv->reduce_value;
+      if (priv->reduce_accuracy)
+        /* Truncate at 1 decimal place */
+        latitude = trunc (latitude * 10.0) / 10.0;
+
       new_value = tp_g_value_slice_new_double (latitude);
       g_hash_table_replace (priv->location, g_strdup (EMPATHY_LOCATION_LAT),
           new_value);
@@ -577,11 +588,11 @@ resource_cb (EmpathyConf  *conf,
   if (!empathy_conf_get_bool (conf, key, &resource_enabled))
     return;
 
-  if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK) == 0)
+  if (tp_strdiff (key, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK) == FALSE)
     resource = GEOCLUE_RESOURCE_NETWORK;
-  if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_CELL) == 0)
+  if (tp_strdiff (key, EMPATHY_PREFS_LOCATION_RESOURCE_CELL) == FALSE)
     resource = GEOCLUE_RESOURCE_CELL;
-  if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_GPS) == 0)
+  if (tp_strdiff (key, EMPATHY_PREFS_LOCATION_RESOURCE_GPS) == FALSE)
     resource = GEOCLUE_RESOURCE_GPS;
 
   if (resource_enabled)
@@ -609,17 +620,6 @@ accuracy_cb (EmpathyConf  *conf,
     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->geoclue_is_setup)
     return;
 
index a383607aacd84f11a36aee16236da6d068bb8740..1e3a425806004df9e97e5285dd110959fa1792a7 100644 (file)
                                     <property name="visible">True</property>
                                     <property name="xalign">0</property>
                                     <property name="wrap">True</property>
-                                    <property name="label" translatable="yes">Reduced location accuracy means that nothing more precise than your city, state and country will be published.  GPS coordinates will have a random value added (&#xB1;0.25&#xB0;).</property>
+                                    <property name="label" translatable="yes">Reduced location accuracy means that nothing more precise than your city, state and country will be published.  GPS coordinates will be accurate to 1 decimal place.</property>
                                     <attributes>
                                       <attribute name="scale" value="0.8"/>
                                     </attributes>