[gnome-photos/wip/rishi/collection: 35/42] base-item: Add a create_thumbnail_path virtual method



commit 3258b10bd1f37638c5869512e908c9c6f0a4dfe1
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jan 24 18:57:19 2018 +0100

    base-item: Add a create_thumbnail_path virtual method
    
    This will enable a future BaseItem sub-class for attached devices to
    specify a different location for its thumbnails. The default
    implementation specifies the current location which is what most
    sub-classes will end up using.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751212

 src/photos-base-item.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h |  3 +++
 2 files changed, 52 insertions(+)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 35281796..37bff9e9 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -187,6 +187,11 @@ static GdkPixbuf *thumbnailing_icon;
 static GThreadPool *create_thumbnail_pool;
 static const gint PIXEL_SIZES[] = {2048, 1024};
 
+enum
+{
+  THUMBNAIL_GENERATION = 0
+};
+
 
 static void photos_base_item_refresh_icon (PhotosBaseItem *self);
 
@@ -571,6 +576,37 @@ photos_base_item_create_thumbnail_finish (PhotosBaseItem *self, GAsyncResult *re
 }
 
 
+static gchar *
+photos_base_item_default_create_thumbnail_path (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv;
+  const gchar *cache_dir;
+  g_autofree gchar *filename = NULL;
+  g_autofree gchar *md5 = NULL;
+  gchar *path;
+  g_autofree gchar *thumbnails_subdir = NULL;
+  gint size;
+
+  priv = photos_base_item_get_instance_private (self);
+
+  md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->uri, -1);
+  filename = g_strconcat (md5, ".png", NULL);
+
+  cache_dir = g_get_user_cache_dir ();
+  size = photos_utils_get_icon_size ();
+  thumbnails_subdir = g_strdup_printf ("%d-%d", size, THUMBNAIL_GENERATION);
+
+  path = g_build_filename (cache_dir,
+                           PACKAGE_TARNAME,
+                           "thumbnails",
+                           thumbnails_subdir,
+                           filename,
+                           NULL);
+
+  return path;
+}
+
+
 static void
 photos_base_item_default_set_favorite (PhotosBaseItem *self, gboolean favorite)
 {
@@ -2986,6 +3022,7 @@ photos_base_item_class_init (PhotosBaseItemClass *class)
   object_class->finalize = photos_base_item_finalize;
   object_class->get_property = photos_base_item_get_property;
   object_class->set_property = photos_base_item_set_property;
+  class->create_thumbnail_path = photos_base_item_default_create_thumbnail_path;
   class->metadata_add_shared = photos_base_item_default_metadata_add_shared;
   class->open = photos_base_item_default_open;
   class->populate_from_cursor = photos_base_item_default_populate_from_cursor;
@@ -3171,6 +3208,18 @@ photos_base_item_create_preview (PhotosBaseItem *self,
 }
 
 
+gchar *
+photos_base_item_create_thumbnail_path (PhotosBaseItem *self)
+{
+  gchar *thumbnail_path;
+
+  g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), NULL);
+
+  thumbnail_path = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_thumbnail_path (self);
+  return thumbnail_path;
+}
+
+
 void
 photos_base_item_destroy (PhotosBaseItem *self)
 {
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 4b95ede3..9ab91f70 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -60,6 +60,7 @@ struct _PhotosBaseItemClass
   gchar      *(*create_name_fallback)       (PhotosBaseItem *self);
   gchar      *(*create_pipeline_path)       (PhotosBaseItem *self);
   gboolean    (*create_thumbnail)           (PhotosBaseItem *self, GCancellable *cancellable, GError 
**error);
+  gchar      *(*create_thumbnail_path)      (PhotosBaseItem *self);
   gchar      *(*download)                   (PhotosBaseItem *self, GCancellable *cancellable, GError 
**error);
   GtkWidget  *(*get_source_widget)          (PhotosBaseItem *self);
   gboolean    (*metadata_add_shared)        (PhotosBaseItem  *self,
@@ -89,6 +90,8 @@ cairo_surface_t    *photos_base_item_create_preview          (PhotosBaseItem *se
                                                               const gchar *first_property_name,
                                                               ...) G_GNUC_NULL_TERMINATED 
G_GNUC_WARN_UNUSED_RESULT;
 
+gchar              *photos_base_item_create_thumbnail_path   (PhotosBaseItem *self) 
G_GNUC_WARN_UNUSED_RESULT;
+
 void                photos_base_item_destroy                 (PhotosBaseItem *self);
 
 gchar              *photos_base_item_download                (PhotosBaseItem *self,


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