]> git.0d.be Git - empathy.git/commitdiff
geocode_cb: don't update location if we didn't get the full position
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 8 Apr 2010 11:51:41 +0000 (13:51 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 8 Apr 2010 13:51:50 +0000 (15:51 +0200)
libempathy/empathy-contact.c

index 4f554419c9a24856d9bfcc1a064f98d43e6991cb..387370097d053a536ba58d6910e629c7b516c923 100644 (file)
@@ -1239,26 +1239,23 @@ geocode_cb (GeoclueGeocode *geocode,
   if (error != NULL)
     {
       DEBUG ("Error geocoding location : %s", error->message);
-      g_object_unref (geocode);
-      g_object_unref (contact);
-      return;
+      goto out;
     }
 
-  if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)
-    {
-      new_value = tp_g_value_slice_new_double (latitude);
-      g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_LAT),
-        new_value);
-      DEBUG ("\t - Latitude: %f", latitude);
-    }
+  /* No need to change location if we didn't find the position */
+  if (!(fields & GEOCLUE_POSITION_FIELDS_LATITUDE))
+    goto out;
 
-  if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)
-    {
-      new_value = tp_g_value_slice_new_double (longitude);
-      g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_LON),
-        new_value);
-      DEBUG ("\t - Longitude: %f", longitude);
-    }
+  if (!(fields & GEOCLUE_POSITION_FIELDS_LONGITUDE))
+    goto out;
+
+  g_hash_table_insert (location, g_strdup (EMPATHY_LOCATION_LAT),
+      tp_g_value_slice_new_double (latitude));
+  DEBUG ("\t - Latitude: %f", latitude);
+
+  g_hash_table_insert (location, g_strdup (EMPATHY_LOCATION_LON),
+    tp_g_value_slice_new_double (longitude));
+  DEBUG ("\t - Longitude: %f", longitude);
 
   if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)
     {
@@ -1270,6 +1267,7 @@ geocode_cb (GeoclueGeocode *geocode,
 
   /* Don't change the accuracy as we used an address to get this position */
   g_object_notify (contact, "location");
+out:
   g_object_unref (geocode);
   g_object_unref (contact);
 }