[empathy] move tp_contact_factory_geocode to empathy-contact



commit 561bd44882f577b3d1f9bb83d43fb58b8e448453
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Fri Apr 2 13:09:06 2010 +0200

    move tp_contact_factory_geocode to empathy-contact

 libempathy/empathy-contact.c            |  156 +++++++++++++++++++++++++++++++
 libempathy/empathy-tp-contact-factory.c |  154 ------------------------------
 2 files changed, 156 insertions(+), 154 deletions(-)
---
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index df7d04e..e5c406a 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -31,10 +31,15 @@
 #include <telepathy-logger/contact.h>
 #endif /* ENABLE_TPL */
 
+#if HAVE_GEOCLUE
+#include <geoclue/geoclue-geocode.h>
+#endif
+
 #include "empathy-contact.h"
 #include "empathy-utils.h"
 #include "empathy-enum-types.h"
 #include "empathy-marshal.h"
+#include "empathy-location.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
 #include "empathy-debug.h"
@@ -65,6 +70,8 @@ static void contact_get_property (GObject *object, guint param_id,
 static void contact_set_property (GObject *object, guint param_id,
     const GValue *value, GParamSpec *pspec);
 
+static void update_geocode (EmpathyContact *contact);
+
 G_DEFINE_TYPE (EmpathyContact, empathy_contact, G_TYPE_OBJECT);
 
 enum
@@ -1136,6 +1143,7 @@ empathy_contact_set_location (EmpathyContact *contact,
     g_hash_table_unref (priv->location);
 
   priv->location = g_hash_table_ref (location);
+  update_geocode (contact);
   g_object_notify (G_OBJECT (contact), "location");
 }
 
@@ -1175,3 +1183,151 @@ empathy_contact_equal (gconstpointer contact1,
   }
   return FALSE;
 }
+
+#if HAVE_GEOCLUE
+#define GEOCODE_SERVICE "org.freedesktop.Geoclue.Providers.Yahoo"
+#define GEOCODE_PATH "/org/freedesktop/Geoclue/Providers/Yahoo"
+
+/* This callback is called by geoclue when it found a position
+ * for the given address.  A position is necessary for a contact
+ * to show up on the map
+ */
+static void
+geocode_cb (GeoclueGeocode *geocode,
+	    GeocluePositionFields fields,
+	    double latitude,
+	    double longitude,
+	    double altitude,
+	    GeoclueAccuracy *accuracy,
+	    GError *error,
+	    gpointer contact)
+{
+	GValue *new_value;
+	GHashTable *location;
+
+	location = empathy_contact_get_location (EMPATHY_CONTACT (contact));
+
+	if (error != NULL) {
+		DEBUG ("Error geocoding location : %s", error->message);
+		g_object_unref (geocode);
+		g_object_unref (contact);
+		return;
+	}
+
+	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);
+	}
+	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_ALTITUDE) {
+		new_value = tp_g_value_slice_new_double (altitude);
+		g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_ALT),
+			new_value);
+		DEBUG ("\t - Altitude: %f", altitude);
+	}
+
+	/* Don't change the accuracy as we used an address to get this position */
+	g_object_notify (contact, "location");
+	g_object_unref (geocode);
+	g_object_unref (contact);
+}
+#endif
+
+#if HAVE_GEOCLUE
+static gchar *
+get_dup_string (GHashTable *location,
+    gchar *key)
+{
+  GValue *value;
+
+  value = g_hash_table_lookup (location, key);
+  if (value != NULL)
+    return g_value_dup_string (value);
+
+  return NULL;
+}
+#endif
+
+static void
+update_geocode (EmpathyContact *contact)
+{
+#if HAVE_GEOCLUE
+	static GeoclueGeocode *geocode;
+	gchar *str;
+	GHashTable *address;
+	GValue* value;
+	GHashTable *location;
+
+	location = empathy_contact_get_location (contact);
+	if (location == NULL)
+		return;
+
+	value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
+	if (value != NULL)
+		return;
+
+	if (geocode == NULL) {
+		geocode = geoclue_geocode_new (GEOCODE_SERVICE, GEOCODE_PATH);
+		g_object_add_weak_pointer (G_OBJECT (geocode), (gpointer *) &geocode);
+	}
+	else
+		g_object_ref (geocode);
+
+	address = geoclue_address_details_new ();
+
+	str = get_dup_string (location, EMPATHY_LOCATION_COUNTRY_CODE);
+	if (str != NULL) {
+		g_hash_table_insert (address,
+			g_strdup (GEOCLUE_ADDRESS_KEY_COUNTRYCODE), str);
+		DEBUG ("\t - countrycode: %s", str);
+	}
+
+	str = get_dup_string (location, EMPATHY_LOCATION_COUNTRY);
+	if (str != NULL) {
+		g_hash_table_insert (address,
+			g_strdup (GEOCLUE_ADDRESS_KEY_COUNTRY), str);
+		DEBUG ("\t - country: %s", str);
+	}
+
+	str = get_dup_string (location, EMPATHY_LOCATION_POSTAL_CODE);
+	if (str != NULL) {
+		g_hash_table_insert (address,
+			g_strdup (GEOCLUE_ADDRESS_KEY_POSTALCODE), str);
+		DEBUG ("\t - postalcode: %s", str);
+	}
+
+	str = get_dup_string (location, EMPATHY_LOCATION_REGION);
+	if (str != NULL) {
+		g_hash_table_insert (address,
+			g_strdup (GEOCLUE_ADDRESS_KEY_REGION), str);
+		DEBUG ("\t - region: %s", str);
+	}
+
+	str = get_dup_string (location, EMPATHY_LOCATION_LOCALITY);
+	if (str != NULL) {
+		g_hash_table_insert (address,
+			g_strdup (GEOCLUE_ADDRESS_KEY_LOCALITY), str);
+		DEBUG ("\t - locality: %s", str);
+	}
+
+	str = get_dup_string (location, EMPATHY_LOCATION_STREET);
+	if (str != NULL) {
+		g_hash_table_insert (address,
+			g_strdup (GEOCLUE_ADDRESS_KEY_STREET), str);
+		DEBUG ("\t - street: %s", str);
+	}
+
+	g_object_ref (contact);
+	geoclue_geocode_address_to_position_async (geocode, address,
+		geocode_cb, contact);
+
+	g_hash_table_unref (address);
+#endif
+}
diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c
index 9343c7c..7cc234f 100644
--- a/libempathy/empathy-tp-contact-factory.c
+++ b/libempathy/empathy-tp-contact-factory.c
@@ -28,10 +28,6 @@
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/interfaces.h>
 
-#if HAVE_GEOCLUE
-#include <geoclue/geoclue-geocode.h>
-#endif
-
 #include <extensions/extensions.h>
 
 #include "empathy-tp-contact-factory.h"
@@ -373,154 +369,6 @@ tp_contact_factory_got_capabilities (TpConnection    *connection,
 	}
 }
 
-#if HAVE_GEOCLUE
-#define GEOCODE_SERVICE "org.freedesktop.Geoclue.Providers.Yahoo"
-#define GEOCODE_PATH "/org/freedesktop/Geoclue/Providers/Yahoo"
-
-/* This callback is called by geoclue when it found a position
- * for the given address.  A position is necessary for a contact
- * to show up on the map
- */
-static void
-geocode_cb (GeoclueGeocode *geocode,
-	    GeocluePositionFields fields,
-	    double latitude,
-	    double longitude,
-	    double altitude,
-	    GeoclueAccuracy *accuracy,
-	    GError *error,
-	    gpointer contact)
-{
-	GValue *new_value;
-	GHashTable *location;
-
-	location = empathy_contact_get_location (EMPATHY_CONTACT (contact));
-
-	if (error != NULL) {
-		DEBUG ("Error geocoding location : %s", error->message);
-		g_object_unref (geocode);
-		g_object_unref (contact);
-		return;
-	}
-
-	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);
-	}
-	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_ALTITUDE) {
-		new_value = tp_g_value_slice_new_double (altitude);
-		g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_ALT),
-			new_value);
-		DEBUG ("\t - Altitude: %f", altitude);
-	}
-
-	/* Don't change the accuracy as we used an address to get this position */
-	g_object_notify (contact, "location");
-	g_object_unref (geocode);
-	g_object_unref (contact);
-}
-#endif
-
-#if HAVE_GEOCLUE
-static gchar *
-get_dup_string (GHashTable *location,
-    gchar *key)
-{
-  GValue *value;
-
-  value = g_hash_table_lookup (location, key);
-  if (value != NULL)
-    return g_value_dup_string (value);
-
-  return NULL;
-}
-#endif
-
-static void
-tp_contact_factory_geocode (EmpathyContact *contact)
-{
-#if HAVE_GEOCLUE
-	static GeoclueGeocode *geocode;
-	gchar *str;
-	GHashTable *address;
-	GValue* value;
-	GHashTable *location;
-
-	location = empathy_contact_get_location (contact);
-	if (location == NULL)
-		return;
-
-	value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
-	if (value != NULL)
-		return;
-
-	if (geocode == NULL) {
-		geocode = geoclue_geocode_new (GEOCODE_SERVICE, GEOCODE_PATH);
-		g_object_add_weak_pointer (G_OBJECT (geocode), (gpointer *) &geocode);
-	}
-	else
-		g_object_ref (geocode);
-
-	address = geoclue_address_details_new ();
-
-	str = get_dup_string (location, EMPATHY_LOCATION_COUNTRY_CODE);
-	if (str != NULL) {
-		g_hash_table_insert (address,
-			g_strdup (GEOCLUE_ADDRESS_KEY_COUNTRYCODE), str);
-		DEBUG ("\t - countrycode: %s", str);
-	}
-
-	str = get_dup_string (location, EMPATHY_LOCATION_COUNTRY);
-	if (str != NULL) {
-		g_hash_table_insert (address,
-			g_strdup (GEOCLUE_ADDRESS_KEY_COUNTRY), str);
-		DEBUG ("\t - country: %s", str);
-	}
-
-	str = get_dup_string (location, EMPATHY_LOCATION_POSTAL_CODE);
-	if (str != NULL) {
-		g_hash_table_insert (address,
-			g_strdup (GEOCLUE_ADDRESS_KEY_POSTALCODE), str);
-		DEBUG ("\t - postalcode: %s", str);
-	}
-
-	str = get_dup_string (location, EMPATHY_LOCATION_REGION);
-	if (str != NULL) {
-		g_hash_table_insert (address,
-			g_strdup (GEOCLUE_ADDRESS_KEY_REGION), str);
-		DEBUG ("\t - region: %s", str);
-	}
-
-	str = get_dup_string (location, EMPATHY_LOCATION_LOCALITY);
-	if (str != NULL) {
-		g_hash_table_insert (address,
-			g_strdup (GEOCLUE_ADDRESS_KEY_LOCALITY), str);
-		DEBUG ("\t - locality: %s", str);
-	}
-
-	str = get_dup_string (location, EMPATHY_LOCATION_STREET);
-	if (str != NULL) {
-		g_hash_table_insert (address,
-			g_strdup (GEOCLUE_ADDRESS_KEY_STREET), str);
-		DEBUG ("\t - street: %s", str);
-	}
-
-	g_object_ref (contact);
-	geoclue_geocode_address_to_position_async (geocode, address,
-		geocode_cb, contact);
-
-	g_hash_table_unref (address);
-#endif
-}
-
 static void
 tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory,
 				    guint handle,
@@ -540,8 +388,6 @@ tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory,
 		(GBoxedCopyFunc) tp_g_value_slice_dup);
 	empathy_contact_set_location (contact, new_location);
 	g_hash_table_unref (new_location);
-
-	tp_contact_factory_geocode (contact);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]