[gnome-photos/wip/rishi/collection: 24/44] Let the BaseItem sub-classes specify where to place their thumbnails



commit 91c7571c2dbf6e3bf6e11364954c764320ae6eca
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jan 24 17:56:27 2018 +0100

    Let the BaseItem sub-classes specify where to place their thumbnails
    
    So far, all thumbnails were located at:
      ~/.cache/gnome-photos/thumbnails/<size>-<generation>/<hash-of-URI>
    
    A subsequent series of commits will add support for importing content
    from attached devices, and it will be nice to separate out those
    thumbnails a bit. Cameras adhering to DCF [1] can use the same URI to
    refer to different images over time, regardless of whether it is the
    same device or not. Manufacturers use the same URI naming scheme for
    all their products, so it is likely that two different devices made by
    the same manufacturer will have two distinct images at the same URI.
    Given enough time, once various counters have wrapped around, it will
    happen with images taken by the same camera too.
    
    Therefore, it is desirable to not put all those thumbnails in the same
    bucket, and have some degree of separation. This means that
    ThumbnailFactory can't continue to determine the location for
    everything, and should instead let the BaseItem sub-classes specify
    where their thumbnails should be placed.
    
    [1] https://en.wikipedia.org/wiki/Design_rule_for_Camera_File_system
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/29

 src/photos-local-item.c        | 3 +++
 src/photos-media-server-item.c | 3 +++
 src/photos-thumbnail-factory.c | 3 +--
 src/photos-thumbnail-factory.h | 1 +
 src/photos-utils.c             | 2 ++
 src/photos-utils.h             | 1 +
 6 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index f7f161c7..14553028 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -149,6 +149,7 @@ photos_local_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancella
   const gchar *uri;
   g_autofree gchar *pipeline_path = NULL;
   g_autofree gchar *pipeline_uri = NULL;
+  g_autofree gchar *thumbnail_path = NULL;
   gint64 height;
   gint64 mtime;
   gint64 width;
@@ -160,6 +161,7 @@ photos_local_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancella
   orientation = photos_base_item_get_orientation (PHOTOS_BASE_ITEM (self));
   height = photos_base_item_get_height (PHOTOS_BASE_ITEM (self));
   width = photos_base_item_get_width (PHOTOS_BASE_ITEM (self));
+  thumbnail_path = photos_utils_get_thumbnail_path_for_uri (uri);
 
   pipeline_path = photos_local_item_get_pipeline_path (self);
   pipeline_uri = photos_utils_convert_path_to_uri (pipeline_path);
@@ -171,6 +173,7 @@ photos_local_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancella
                                       height,
                                       width,
                                       pipeline_uri,
+                                      thumbnail_path,
                                       cancellable,
                                       error))
     goto out;
diff --git a/src/photos-media-server-item.c b/src/photos-media-server-item.c
index 67c71cb7..deed7ba3 100644
--- a/src/photos-media-server-item.c
+++ b/src/photos-media-server-item.c
@@ -81,6 +81,7 @@ photos_media_server_item_create_thumbnail (PhotosBaseItem *item, GCancellable *c
   g_autoptr (GFile) file = NULL;
   GQuark orientation;
   gboolean ret_val;
+  g_autofree gchar *thumbnail_path = NULL;
   const gchar *mime_type;
   const gchar *uri;
   gint64 height;
@@ -94,6 +95,7 @@ photos_media_server_item_create_thumbnail (PhotosBaseItem *item, GCancellable *c
   orientation = photos_base_item_get_orientation (item);
   height = photos_base_item_get_height (item);
   width = photos_base_item_get_width (item);
+  thumbnail_path = photos_utils_get_thumbnail_path_for_uri (uri);
 
   ret_val = photos_utils_create_thumbnail (file,
                                            mime_type,
@@ -102,6 +104,7 @@ photos_media_server_item_create_thumbnail (PhotosBaseItem *item, GCancellable *c
                                            height,
                                            width,
                                            "",
+                                           thumbnail_path,
                                            cancellable,
                                            error);
 
diff --git a/src/photos-thumbnail-factory.c b/src/photos-thumbnail-factory.c
index d587e5ef..91e7b41e 100644
--- a/src/photos-thumbnail-factory.c
+++ b/src/photos-thumbnail-factory.c
@@ -321,6 +321,7 @@ photos_thumbnail_factory_generate_thumbnail (PhotosThumbnailFactory *self,
                                              gint64 original_height,
                                              gint64 original_width,
                                              const gchar *pipeline_uri,
+                                             const gchar *thumbnail_path,
                                              GCancellable *cancellable,
                                              GError **error)
 {
@@ -397,7 +398,6 @@ photos_thumbnail_factory_generate_thumbnail (PhotosThumbnailFactory *self,
   else
     {
       const gchar *orientation_str;
-      g_autofree gchar *thumbnail_path = NULL;
       g_autofree gchar *uri = NULL;
       gint thumbnail_size;
 
@@ -405,7 +405,6 @@ photos_thumbnail_factory_generate_thumbnail (PhotosThumbnailFactory *self,
 
       uri = g_file_get_uri (file);
       orientation_str = g_quark_to_string (orientation);
-      thumbnail_path = photos_utils_get_thumbnail_path_for_file (file);
       thumbnail_size = photos_utils_get_icon_size ();
 
       photos_debug (PHOTOS_DEBUG_THUMBNAILER, "Calling GenerateThumbnail for %s", uri);
diff --git a/src/photos-thumbnail-factory.h b/src/photos-thumbnail-factory.h
index 63d1226f..2d9018fe 100644
--- a/src/photos-thumbnail-factory.h
+++ b/src/photos-thumbnail-factory.h
@@ -36,6 +36,7 @@ gboolean                 photos_thumbnail_factory_generate_thumbnail     (Photos
                                                                           gint64 original_height,
                                                                           gint64 original_width,
                                                                           const gchar *pipeline_uri,
+                                                                          const gchar *thumbnail_path,
                                                                           GCancellable *cancellable,
                                                                           GError **error);
 
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 1eb4ade6..b1817775 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -362,6 +362,7 @@ photos_utils_create_thumbnail (GFile *file,
                                gint64 original_height,
                                gint64 original_width,
                                const gchar *pipeline_uri,
+                               const gchar *thumbnail_path,
                                GCancellable *cancellable,
                                GError **error)
 {
@@ -376,6 +377,7 @@ photos_utils_create_thumbnail (GFile *file,
                                                     original_height,
                                                     original_width,
                                                     pipeline_uri,
+                                                    thumbnail_path,
                                                     cancellable,
                                                     error))
     goto out;
diff --git a/src/photos-utils.h b/src/photos-utils.h
index ef3af5a6..fad7c0d1 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -76,6 +76,7 @@ gboolean         photos_utils_create_thumbnail            (GFile *file,
                                                            gint64 original_height,
                                                            gint64 original_width,
                                                            const gchar *pipeline_uri,
+                                                           const gchar *thumbnail_path,
                                                            GCancellable *cancellable,
                                                            GError **error);
 


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