]> git.0d.be Git - empathy.git/commitdiff
Move the geoclue geocoding in EmpathyTpContactFactory
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 27 May 2009 15:57:14 +0000 (11:57 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 27 May 2009 16:52:10 +0000 (12:52 -0400)
This code needs to be run when ever there is a new location available
It makes more sens for it to be there. This makes the geolocation informtion
ritcher as it can be displayed on a map.

libempathy/Makefile.am
libempathy/empathy-tp-contact-factory.c
src/Makefile.am
src/empathy-map-view.c

index d7c9263cb4031c2435e677b5630e564310716e11..2406a0f9d6ba11392db06db661a6f11ea264d48e 100644 (file)
@@ -7,6 +7,7 @@ AM_CPPFLAGS =                                           \
        -DDATADIR=\""$(datadir)"\"                      \
        -DLOCALEDIR=\""$(datadir)/locale"\"             \
        $(LIBEMPATHY_CFLAGS)                            \
        -DDATADIR=\""$(datadir)"\"                      \
        -DLOCALEDIR=\""$(datadir)/locale"\"             \
        $(LIBEMPATHY_CFLAGS)                            \
+       $(GEOCLUE_CFLAGS)                               \
        $(WARN_CFLAGS)                                  \
        $(DISABLE_DEPRECATED)
 
        $(WARN_CFLAGS)                                  \
        $(DISABLE_DEPRECATED)
 
@@ -59,7 +60,8 @@ nodist_libempathy_la_SOURCES =\
 
 libempathy_la_LIBADD =         \
        $(top_builddir)/extensions/libemp-extensions.la \
 
 libempathy_la_LIBADD =         \
        $(top_builddir)/extensions/libemp-extensions.la \
-       $(LIBEMPATHY_LIBS)
+       $(LIBEMPATHY_LIBS) \
+       $(GEOCLUE_LIBS)
 
 libempathy_la_LDFLAGS =                \
        -version-info ${LIBEMPATHY_CURRENT}:${LIBEMPATHY_REVISION}:${LIBEMPATHY_AGE} \
 
 libempathy_la_LDFLAGS =                \
        -version-info ${LIBEMPATHY_CURRENT}:${LIBEMPATHY_REVISION}:${LIBEMPATHY_AGE} \
index 0ddf91b29d915e68789bc536251011d073261ca2..cd7824a7a88f9af8543ac3e73fde7c202abc490a 100644 (file)
 #include <telepathy-glib/util.h>
 #include <telepathy-glib/gtypes.h>
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/util.h>
 #include <telepathy-glib/gtypes.h>
 #include <telepathy-glib/dbus.h>
+#if HAVE_GEOCLUE
+#include <geoclue/geoclue-geocode.h>
+#endif
 
 #include <extensions/extensions.h>
 
 #include "empathy-tp-contact-factory.h"
 #include "empathy-utils.h"
 
 #include <extensions/extensions.h>
 
 #include "empathy-tp-contact-factory.h"
 #include "empathy-utils.h"
+#include "empathy-location.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CONTACT
 #include "empathy-debug.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CONTACT
 #include "empathy-debug.h"
@@ -391,6 +395,126 @@ tp_contact_factory_got_capabilities (EmpathyTpContactFactory *tp_factory,
        g_ptr_array_free (capabilities, TRUE);
 }
 
        g_ptr_array_free (capabilities, TRUE);
 }
 
+#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 userdata)
+{
+       GValue *new_value;
+       GHashTable *location;
+
+       location = empathy_contact_get_location (EMPATHY_CONTACT (userdata));
+
+       if (error != NULL) {
+               DEBUG ("Error geocoding location : %s", error->message);
+               g_object_unref (geocode);
+               g_object_unref (userdata);
+               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 (userdata, "location");
+       g_object_unref (geocode);
+       g_object_unref (userdata);
+}
+#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);
+       if (str != NULL)
+               g_hash_table_insert (address, g_strdup ("country"), str);
+
+       str = get_dup_string (location, EMPATHY_LOCATION_POSTAL_CODE);
+       if (str != NULL)
+               g_hash_table_insert (address, g_strdup ("postalcode"), str);
+
+       str = get_dup_string (location, EMPATHY_LOCATION_LOCALITY);
+       if (str != NULL)
+               g_hash_table_insert (address, g_strdup ("locality"), str);
+
+       str = get_dup_string (location, EMPATHY_LOCATION_STREET);
+       if (str != NULL)
+               g_hash_table_insert (address, g_strdup ("street"), str);
+
+       g_object_ref (contact);
+       geoclue_geocode_address_to_position_async (geocode, address,
+               geocode_cb, contact);
+
+       g_hash_table_unref (address);
+       return;
+#endif
+}
+
 static void
 tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory,
                                    guint handle,
 static void
 tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory,
                                    guint handle,
@@ -398,6 +522,7 @@ tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory,
 {
        EmpathyContact *contact;
        GHashTable     *new_location;
 {
        EmpathyContact *contact;
        GHashTable     *new_location;
+       GValue         *value;
 
        contact = tp_contact_factory_find_by_handle (tp_factory, handle);
 
 
        contact = tp_contact_factory_find_by_handle (tp_factory, handle);
 
@@ -410,6 +535,11 @@ 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);
                (GBoxedCopyFunc) tp_g_value_slice_dup);
        empathy_contact_set_location (contact, new_location);
        g_hash_table_unref (new_location);
+
+       value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
+       if (value == NULL) {
+               tp_contact_factory_geocode (contact);
+       }
 }
 
 static void
 }
 
 static void
index ef6311f29f39c82e71af4a2b6de49d4ca164a093..8973d533f28ee21dc39d46fdc3e83f85440f9db7 100644 (file)
@@ -4,7 +4,6 @@ AM_CPPFLAGS =                                           \
        -I$(top_srcdir)                                 \
        $(EMPATHY_CFLAGS)                               \
        $(LIBNOTIFY_CFLAGS)                             \
        -I$(top_srcdir)                                 \
        $(EMPATHY_CFLAGS)                               \
        $(LIBNOTIFY_CFLAGS)                             \
-       $(GEOCLUE_CFLAGS)                               \
        $(LIBCHAMPLAIN_CFLAGS)                          \
        $(DISABLE_DEPRECATED)
        $(WARN_CFLAGS)
        $(LIBCHAMPLAIN_CFLAGS)                          \
        $(DISABLE_DEPRECATED)
        $(WARN_CFLAGS)
@@ -15,8 +14,7 @@ LDADD =                                                               \
        $(top_builddir)/extensions/libemp-extensions.la         \
        $(LIBNOTIFY_LIBS)                                       \
        $(EMPATHY_LIBS)                                         \
        $(top_builddir)/extensions/libemp-extensions.la         \
        $(LIBNOTIFY_LIBS)                                       \
        $(EMPATHY_LIBS)                                         \
-       $(LIBCHAMPLAIN_LIBS)                                    \
-       $(GEOCLUE_LIBS)
+       $(LIBCHAMPLAIN_LIBS)
 
 bin_PROGRAMS =                 \
        empathy                 \
 
 bin_PROGRAMS =                 \
        empathy                 \
index 692bdc0f26257e7ca980b218f9f611714a300067..c55e5c73aa1da797454a7a3983219653fd9b3f91 100644 (file)
@@ -27,9 +27,6 @@
 #include <champlain/champlain.h>
 #include <champlain-gtk/champlain-gtk.h>
 #include <clutter-gtk/gtk-clutter-embed.h>
 #include <champlain/champlain.h>
 #include <champlain-gtk/champlain-gtk.h>
 #include <clutter-gtk/gtk-clutter-embed.h>
-#if HAVE_GEOCLUE
-#include <geoclue/geoclue-geocode.h>
-#endif
 #include <telepathy-glib/util.h>
 
 #include <libempathy/empathy-contact.h>
 #include <telepathy-glib/util.h>
 
 #include <libempathy/empathy-contact.h>
@@ -71,8 +68,6 @@ static void map_view_zoom_out_cb (GtkWidget *widget,
 static void map_view_contact_location_notify (GObject *gobject,
     GParamSpec *arg1,
     gpointer user_data);
 static void map_view_contact_location_notify (GObject *gobject,
     GParamSpec *arg1,
     gpointer user_data);
-static gchar * get_dup_string (GHashTable *location,
-    gchar *key);
 
 GtkWidget *
 empathy_map_view_show (void)
 
 GtkWidget *
 empathy_map_view_show (void)
@@ -170,74 +165,6 @@ map_view_destroy_cb (GtkWidget *widget,
   g_slice_free (EmpathyMapView, window);
 }
 
   g_slice_free (EmpathyMapView, window);
 }
 
-#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
-map_view_geocode_cb (GeoclueGeocode *geocode,
-    GeocluePositionFields fields,
-    double latitude,
-    double longitude,
-    double altitude,
-    GeoclueAccuracy *accuracy,
-    GError *error,
-    gpointer userdata)
-{
-  GValue *new_value;
-  GHashTable *location;
-
-  location = empathy_contact_get_location (EMPATHY_CONTACT (userdata));
-
-  if (error != NULL)
-    {
-      DEBUG ("Error geocoding location : %s", error->message);
-      return;
-    }
-
-  if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)
-    {
-      new_value = tp_g_value_slice_new_double (longitude);
-      g_hash_table_replace (location, EMPATHY_LOCATION_LON, new_value);
-      DEBUG ("\t - Longitude: %f", longitude);
-    }
-  if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)
-    {
-      new_value = tp_g_value_slice_new_double (latitude);
-      g_hash_table_replace (location, EMPATHY_LOCATION_LAT, new_value);
-      DEBUG ("\t - Latitude: %f", latitude);
-    }
-  if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)
-    {
-      new_value = tp_g_value_slice_new_double (altitude);
-      g_hash_table_replace (location, 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 (userdata, "location");
-  g_object_unref (geocode);
-}
-#endif
-
-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;
-}
-
 static void
 map_view_marker_update_position (ChamplainMarker *marker,
     EmpathyContact *contact)
 static void
 map_view_marker_update_position (ChamplainMarker *marker,
     EmpathyContact *contact)
@@ -248,48 +175,6 @@ map_view_marker_update_position (ChamplainMarker *marker,
 
   location = empathy_contact_get_location (contact);
 
 
   location = empathy_contact_get_location (contact);
 
-#if HAVE_GEOCLUE
-  gchar *str;
-  GHashTable *address;
-
-  value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
-  if (value == NULL)
-      {
-        static GeoclueGeocode *geocode;
-        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);
-        if (str != NULL)
-          g_hash_table_insert (address, g_strdup ("country"), str);
-
-        str = get_dup_string (location, EMPATHY_LOCATION_POSTAL_CODE);
-        if (str != NULL)
-          g_hash_table_insert (address, g_strdup ("postalcode"), str);
-
-        str = get_dup_string (location, EMPATHY_LOCATION_LOCALITY);
-        if (str != NULL)
-          g_hash_table_insert (address, g_strdup ("locality"), str);
-
-        str = get_dup_string (location, EMPATHY_LOCATION_STREET);
-        if (str != NULL)
-          g_hash_table_insert (address, g_strdup ("street"), str);
-
-        geoclue_geocode_address_to_position_async (geocode, address,
-            map_view_geocode_cb, contact);
-
-        g_hash_table_unref (address);
-        return;
-      }
-#endif
-
   if (location == NULL ||
       g_hash_table_size (location) == 0)
   {
   if (location == NULL ||
       g_hash_table_size (location) == 0)
   {