[frogr] send geolocation data if available



commit 0d5a2ec6bf515c57eb593029df095c3e2d24209f
Author: Christophe Fergeau <teuf gnome org>
Date:   Sat Aug 13 23:48:27 2011 +0200

    send geolocation data if available

 src/frogr-controller.c |   94 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 92 insertions(+), 2 deletions(-)
---
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index 672f457..e5962d7 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -80,6 +80,7 @@ struct _FrogrControllerPrivate
   gboolean fetching_groups;
   gboolean fetching_tags;
   gboolean setting_license;
+  gboolean setting_location;
   gboolean adding_to_set;
   gboolean adding_to_group;
 
@@ -159,6 +160,10 @@ static void _upload_picture_cb (GObject *object, GAsyncResult *res, gpointer dat
 
 static void _set_license_cb (GObject *object, GAsyncResult *res, gpointer data);
 
+static void _set_location_cb (GObject *object, GAsyncResult *res, gpointer data);
+
+static gboolean _set_location_on_idle (gpointer data);
+
 static gboolean _create_set_or_add_picture_on_idle (gpointer data);
 
 static gboolean _create_set_or_add_picture (FrogrController *self,
@@ -178,6 +183,9 @@ static gboolean _complete_picture_upload_on_idle (gpointer data);
 static void _notify_setting_license (FrogrController *self,
                                      FrogrPicture *picture);
 
+static void _notify_setting_location (FrogrController *self,
+                                      FrogrPicture *picture);
+
 static void _notify_creating_set (FrogrController *self,
                                   FrogrPicture *picture,
                                   FrogrPhotoSet *set);
@@ -629,6 +637,11 @@ _upload_picture_cb (GObject *object, GAsyncResult *res, gpointer data)
                                          up_st);
         }
 
+      if (frogr_picture_get_location (picture) != NULL)
+        {
+          gdk_threads_add_timeout (DEFAULT_TIMEOUT, _set_location_on_idle, up_st);
+        }
+
       /* Add picture to set if needed (and maybe create a new one) */
       if (g_slist_length (sets) > 0)
         {
@@ -676,23 +689,78 @@ _set_license_cb (GObject *object, GAsyncResult *res, gpointer data)
   priv->setting_license = FALSE;
 }
 
+static void
+_set_location_cb (GObject *object, GAsyncResult *res, gpointer data)
+{
+  FspSession *session = NULL;
+  upload_picture_st *up_st = NULL;
+  FrogrController *controller = NULL;
+  FrogrControllerPrivate *priv = NULL;
+  GError *error = NULL;
+
+  session = FSP_SESSION (object);
+  up_st = (upload_picture_st*) data;
+  controller = up_st->controller;
+
+  fsp_session_set_location_finish (session, res, &error);
+  if (error)
+    {
+      /* We do not anything special if something went wrong here */
+      DEBUG ("Error setting location for picture: %s", error->message);
+      g_free (error);
+    }
+
+  priv = FROGR_CONTROLLER_GET_PRIVATE (controller);
+  priv->setting_location = FALSE;
+}
+
 static gboolean
-_create_set_or_add_picture_on_idle (gpointer data)
+_set_location_on_idle (gpointer data)
 {
   upload_picture_st *up_st = NULL;
   FrogrController *controller = NULL;
   FrogrControllerPrivate *priv = NULL;
   FrogrPicture *picture = NULL;
+  FspLocation *location;
 
   up_st = (upload_picture_st*) data;
   controller = up_st->controller;
   picture = up_st->picture;
+  location = frogr_picture_get_location (picture);
 
   /* Keep the source while busy */
   priv = FROGR_CONTROLLER_GET_PRIVATE (controller);
   if (priv->setting_license)
     return TRUE;
 
+  priv->setting_location = TRUE;
+  _notify_setting_location (controller, picture);
+  fsp_session_set_location_async (priv->session,
+                                  frogr_picture_get_id (picture),
+                                  location,
+                                  priv->last_cancellable,
+                                  _set_location_cb,
+                                  up_st);
+  return FALSE;
+}
+
+static gboolean
+_create_set_or_add_picture_on_idle (gpointer data)
+{
+  upload_picture_st *up_st = NULL;
+  FrogrController *controller = NULL;
+  FrogrControllerPrivate *priv = NULL;
+  FrogrPicture *picture = NULL;
+
+  up_st = (upload_picture_st*) data;
+  controller = up_st->controller;
+  picture = up_st->picture;
+
+  /* Keep the source while busy */
+  priv = FROGR_CONTROLLER_GET_PRIVATE (controller);
+  if ((priv->setting_license) || (priv->setting_location))
+    return TRUE;
+
   _create_set_or_add_picture (controller, picture, up_st);
   return FALSE;
 }
@@ -971,7 +1039,7 @@ _complete_picture_upload_on_idle (gpointer data)
   priv = FROGR_CONTROLLER_GET_PRIVATE (controller);
 
   /* Keep the source while busy */
-  if (priv->setting_license || priv->adding_to_set || priv->adding_to_group)
+  if (priv->setting_license || priv->setting_location || priv->adding_to_set || priv->adding_to_group)
     {
       frogr_main_view_pulse_progress (priv->mainview);
       return TRUE;
@@ -1022,6 +1090,27 @@ _notify_setting_license (FrogrController *self,
 }
 
 static void
+_notify_setting_location (FrogrController *self,
+                          FrogrPicture *picture)
+{
+  FrogrControllerPrivate *priv = NULL;
+  const gchar *picture_title = NULL;
+  FspLocation *location;
+  gchar *debug_msg = NULL;
+
+  priv = FROGR_CONTROLLER_GET_PRIVATE (self);
+  frogr_main_view_set_progress_description(priv->mainview, _("Setting geolocation for pictureâ"));
+
+  picture_title = frogr_picture_get_title (picture);
+  location = frogr_picture_get_location (picture);
+  debug_msg = g_strdup_printf ("Setting geolocation (%f, %f) for picture %sâ",
+                               location->latitude, location->longitude, picture_title);
+  DEBUG ("%s", debug_msg);
+
+  g_free (debug_msg);
+}
+
+static void
 _notify_creating_set (FrogrController *self,
                       FrogrPicture *picture,
                       FrogrPhotoSet *set)
@@ -1952,6 +2041,7 @@ frogr_controller_init (FrogrController *self)
   priv->fetching_groups = FALSE;
   priv->fetching_tags = FALSE;
   priv->setting_license = FALSE;
+  priv->setting_location = FALSE;
   priv->adding_to_set = FALSE;
   priv->adding_to_group = FALSE;
   priv->account_info_fetched = FALSE;



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