[frogr] Use the new class FrogrLocation instead of FspDataLocation



commit 1d5b83f63218e0b9f0cbb1f606cf7fc0835d9fa0
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Thu Aug 25 20:03:28 2011 +0200

    Use the new class FrogrLocation instead of FspDataLocation

 src/frogr-controller.c     |   23 ++++++++++++----
 src/frogr-picture-loader.c |   51 ++++++++++++++++-------------------
 src/frogr-picture.c        |   63 +++++++++++++++++++++++--------------------
 src/frogr-picture.h        |    9 +++---
 4 files changed, 80 insertions(+), 66 deletions(-)
---
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index acd7ff2..0df2cf0 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -723,25 +723,33 @@ _set_location_on_idle (gpointer data)
   FrogrController *controller = NULL;
   FrogrControllerPrivate *priv = NULL;
   FrogrPicture *picture = NULL;
-  FspDataLocation *location;
+  FrogrLocation *location = NULL;
+  FspDataLocation *data_location = NULL;
 
   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;
 
+  picture = up_st->picture;
+  location = frogr_picture_get_location (picture);
+  data_location = FSP_DATA_LOCATION (fsp_data_new (FSP_LOCATION));
+  data_location->latitude = frogr_location_get_latitude (location);
+  data_location->longitude = frogr_location_get_longitude (location);
+ 
   _notify_setting_location (controller, picture);
   fsp_session_set_location_async (priv->session,
                                   frogr_picture_get_id (picture),
-                                  location,
+                                  data_location,
                                   priv->last_cancellable,
                                   _set_location_cb,
                                   up_st);
+
+  fsp_data_free (FSP_DATA (data_location));
+
   return FALSE;
 }
 
@@ -1096,7 +1104,7 @@ _notify_setting_location (FrogrController *self,
 {
   FrogrControllerPrivate *priv = NULL;
   const gchar *picture_title = NULL;
-  FspDataLocation *location;
+  FrogrLocation *location;
   gchar *debug_msg = NULL;
 
   priv = FROGR_CONTROLLER_GET_PRIVATE (self);
@@ -1104,8 +1112,11 @@ _notify_setting_location (FrogrController *self,
 
   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);
+                               frogr_location_get_latitude (location),
+                               frogr_location_get_longitude (location),
+                               picture_title);
   DEBUG ("%s", debug_msg);
 
   g_free (debug_msg);
diff --git a/src/frogr-picture-loader.c b/src/frogr-picture-loader.c
index 413e9e3..b2e7a42 100644
--- a/src/frogr-picture-loader.c
+++ b/src/frogr-picture-loader.c
@@ -27,6 +27,7 @@
 #include "frogr-config.h"
 #include "frogr-controller.h"
 #include "frogr-global-defs.h"
+#include "frogr-location.h"
 #include "frogr-main-view.h"
 #include "frogr-picture.h"
 #include "frogr-util.h"
@@ -100,7 +101,7 @@ static gboolean get_gps_coordinate (ExifData *exif,
                                     ExifTag   tag,
                                     ExifTag   reftag,
                                     gdouble  *coordinate);
-static FspDataLocation *get_location_from_exif (ExifData *exif_data);
+static FrogrLocation *get_location_from_exif (ExifData *exif_data);
 
 static gchar *remove_spaces_from_keyword (const gchar *keyword);
 static gchar *import_tags_from_xmp_keywords (const char *buffer, size_t len);
@@ -298,7 +299,7 @@ _load_next_picture_cb (GObject *object,
           exif_data = exif_loader_get_data (exif_loader);
           if (exif_data)
             {
-              FspDataLocation *location;
+              FrogrLocation *location = NULL;
 
               /* Date and time for picture taken */
               exif_entry = exif_data_get_entry (exif_data, EXIF_TAG_DATE_TIME);
@@ -335,7 +336,7 @@ _load_next_picture_cb (GObject *object,
                 {
                   /* frogr_picture_set_location takes ownership of location */
                   frogr_picture_set_location (fpicture, location);
-                  fsp_data_free (FSP_DATA (location));
+                  g_object_unref (location);
                 }
               exif_data_unref (exif_data);
             }
@@ -444,32 +445,28 @@ get_gps_coordinate (ExifData *exif,
   return FALSE;
 }
 
-static FspDataLocation *
+static FrogrLocation *
 get_location_from_exif (ExifData *exif_data)
 {
-    FspDataLocation *location;
-    gdouble coordinate;
-    gboolean found;
-
-    if (!exif_data)
-      return NULL;
-    found = get_gps_coordinate (exif_data, EXIF_TAG_GPS_LATITUDE,
-                                EXIF_TAG_GPS_LATITUDE_REF, &coordinate);
-    if (!found)
-      return NULL;
-
-    location = FSP_DATA_LOCATION (fsp_data_new (FSP_LOCATION));
-    location->latitude = coordinate;
-
-    found = get_gps_coordinate (exif_data, EXIF_TAG_GPS_LONGITUDE,
-                                EXIF_TAG_GPS_LONGITUDE_REF, &location->longitude);
-    if (!found)
-      {
-        fsp_data_free (FSP_DATA (location));
-        return NULL;
-      }
-
-    return location;
+  FrogrLocation *location = NULL;
+  gdouble latitude;
+  gdouble longitude;
+  gboolean has_latitude;
+
+  if (exif_data)
+    {
+      has_latitude = get_gps_coordinate (exif_data, EXIF_TAG_GPS_LATITUDE,
+                                         EXIF_TAG_GPS_LATITUDE_REF, &latitude);
+
+      /* We need both latitude and longitude */
+      if (has_latitude && get_gps_coordinate (exif_data, EXIF_TAG_GPS_LONGITUDE,
+                                              EXIF_TAG_GPS_LONGITUDE_REF, &longitude))
+        {
+          location = frogr_location_new (latitude, longitude);
+        }
+    }
+
+  return location;
 }
 
 static gchar *
diff --git a/src/frogr-picture.c b/src/frogr-picture.c
index 677b973..b35ac75 100644
--- a/src/frogr-picture.c
+++ b/src/frogr-picture.c
@@ -53,7 +53,7 @@ struct _FrogrPicturePrivate
   FspSafetyLevel safety_level;
   FspContentType content_type;
   FspLicense license;
-  FspDataLocation *location;
+  FrogrLocation *location;
   gboolean show_in_search;
   gboolean send_location;
 
@@ -74,6 +74,7 @@ enum  {
   PROP_SAFETY_LEVEL,
   PROP_CONTENT_TYPE,
   PROP_LICENSE,
+  PROP_LOCATION,
   PROP_SHOW_IN_SEARCH,
   PROP_SEND_LOCATION,
   PROP_PIXBUF,
@@ -224,6 +225,9 @@ _frogr_picture_set_property (GObject *object,
     case PROP_LICENSE:
       frogr_picture_set_license (self, g_value_get_int (value));
       break;
+    case PROP_LOCATION:
+      frogr_picture_set_location (self, g_value_get_pointer (value));
+      break;
     case PROP_SHOW_IN_SEARCH:
       frogr_picture_set_show_in_search (self, g_value_get_boolean (value));
       break;
@@ -288,6 +292,9 @@ _frogr_picture_get_property (GObject *object,
     case PROP_LICENSE:
       g_value_set_int (value, priv->license);
       break;
+    case PROP_LOCATION:
+      g_value_set_pointer (value, priv->location);
+      break;
     case PROP_SHOW_IN_SEARCH:
       g_value_set_boolean (value, priv->show_in_search);
       break;
@@ -314,13 +321,18 @@ _frogr_picture_dispose (GObject* object)
 {
   FrogrPicturePrivate *priv = FROGR_PICTURE_GET_PRIVATE (object);
 
-  /* Free pixbuf, if present */
   if (priv->pixbuf)
     {
       g_object_unref (priv->pixbuf);
       priv->pixbuf = NULL;
     }
 
+  if (priv->location)
+    {
+      g_object_unref (priv->location);
+      priv->location = NULL;
+    }
+
   if (priv->sets)
     {
       g_slist_foreach (priv->sets, (GFunc) g_object_unref, NULL);
@@ -356,9 +368,6 @@ _frogr_picture_finalize (GObject* object)
   g_slist_foreach (priv->tags_list, (GFunc) g_free, NULL);
   g_slist_free (priv->tags_list);
 
-  /* free structs */
-  fsp_data_free (FSP_DATA (priv->location));
-
   /* call super class */
   G_OBJECT_CLASS (frogr_picture_parent_class)->finalize(object);
 }
@@ -460,14 +469,12 @@ frogr_picture_class_init(FrogrPictureClass *klass)
                                                      FSP_CONTENT_TYPE_PHOTO,
                                                      G_PARAM_READWRITE));
   g_object_class_install_property (obj_class,
-                                   PROP_LICENSE,
-                                   g_param_spec_int ("license",
-                                                     "license",
-                                                     "License for this picture",
-                                                     FSP_LICENSE_NONE,
-                                                     FSP_LICENSE_ND,
-                                                     FSP_LICENSE_NONE,
-                                                     G_PARAM_READWRITE));
+                                   PROP_LOCATION,
+                                   g_param_spec_pointer ("location",
+                                                         "location",
+                                                         "Location for this picture",
+                                                         G_PARAM_READWRITE));
+
   g_object_class_install_property (obj_class,
                                    PROP_SHOW_IN_SEARCH,
                                    g_param_spec_boolean ("show-in-search",
@@ -539,6 +546,7 @@ frogr_picture_init (FrogrPicture *self)
   priv->safety_level = FSP_SAFETY_LEVEL_SAFE;
   priv->content_type = FSP_CONTENT_TYPE_PHOTO;
   priv->license = FSP_LICENSE_NONE;
+  priv->location = NULL;
 
   priv->show_in_search = TRUE;
   priv->send_location = FALSE;
@@ -866,54 +874,51 @@ frogr_picture_set_license (FrogrPicture *self, FspLicense license)
   priv->license = license;
 }
 
-gboolean
-frogr_picture_send_location (FrogrPicture *self)
+FrogrLocation *
+frogr_picture_get_location (FrogrPicture *self)
 {
   FrogrPicturePrivate *priv = NULL;
 
   g_return_val_if_fail(FROGR_IS_PICTURE(self), FALSE);
 
   priv = FROGR_PICTURE_GET_PRIVATE (self);
-  return priv->send_location;
+  return priv->location;
 }
 
 void
-frogr_picture_set_send_location (FrogrPicture *self, gboolean send_location)
+frogr_picture_set_location (FrogrPicture *self, FrogrLocation *location)
 {
   FrogrPicturePrivate *priv = NULL;
 
   g_return_if_fail(FROGR_IS_PICTURE(self));
 
   priv = FROGR_PICTURE_GET_PRIVATE (self);
-  priv->send_location = send_location;
+  if (priv->location)
+    g_object_unref (priv->location);
+
+  priv->location = FROGR_IS_LOCATION (location) ? g_object_ref (location) : NULL;
 }
 
-FspDataLocation *
-frogr_picture_get_location (FrogrPicture *self)
+gboolean
+frogr_picture_send_location (FrogrPicture *self)
 {
   FrogrPicturePrivate *priv = NULL;
 
   g_return_val_if_fail(FROGR_IS_PICTURE(self), FALSE);
 
   priv = FROGR_PICTURE_GET_PRIVATE (self);
-  return priv->location;
+  return priv->send_location;
 }
 
 void
-frogr_picture_set_location (FrogrPicture *self, FspDataLocation *location)
+frogr_picture_set_send_location (FrogrPicture *self, gboolean send_location)
 {
   FrogrPicturePrivate *priv = NULL;
 
   g_return_if_fail(FROGR_IS_PICTURE(self));
 
   priv = FROGR_PICTURE_GET_PRIVATE (self);
-  if (priv->location)
-    fsp_data_free (FSP_DATA (priv->location));
-
-  if (location)
-    priv->location = FSP_DATA_LOCATION (fsp_data_copy (FSP_DATA (location)));
-  else
-    priv->location = NULL;
+  priv->send_location = send_location;
 }
 
 gboolean
diff --git a/src/frogr-picture.h b/src/frogr-picture.h
index bdfe5ac..04bad59 100644
--- a/src/frogr-picture.h
+++ b/src/frogr-picture.h
@@ -21,8 +21,9 @@
 #ifndef _FROGR_PICTURE_H
 #define _FROGR_PICTURE_H
 
-#include "frogr-photoset.h"
 #include "frogr-group.h"
+#include "frogr-location.h"
+#include "frogr-photoset.h"
 
 #include <glib.h>
 #include <glib-object.h>
@@ -106,12 +107,12 @@ void frogr_picture_set_content_type (FrogrPicture *self,
 FspLicense frogr_picture_get_license (FrogrPicture *self);
 void frogr_picture_set_license (FrogrPicture *self, FspLicense license);
 
+FrogrLocation *frogr_picture_get_location (FrogrPicture *self);
+void frogr_picture_set_location (FrogrPicture *self, FrogrLocation *location);
+
 gboolean frogr_picture_send_location (FrogrPicture *self);
 void frogr_picture_set_send_location (FrogrPicture *self, gboolean send_location);
 
-FspDataLocation *frogr_picture_get_location (FrogrPicture *self);
-void frogr_picture_set_location (FrogrPicture *self, FspDataLocation *location);
-
 gboolean frogr_picture_show_in_search (FrogrPicture *self);
 void frogr_picture_set_show_in_search (FrogrPicture *self,
                                        gboolean show_in_search);



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