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



commit 0b5f1a50f857a94f485d8713ce1f4b73ce726a11
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 a8d58794..2dacd105 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -189,6 +189,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_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor);
 
@@ -873,6 +878,37 @@ photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpo
 }
 
 
+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)
 {
@@ -2994,6 +3030,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->set_favorite = photos_base_item_default_set_favorite;
@@ -3178,6 +3215,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 9383a921..bc929f1d 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -59,6 +59,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,
@@ -87,6 +88,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]