[gnome-desktop/wip/thumbnail-resources: 4/7] thumbnail: Add gnome_desktop_factory_give_me_a_thumbnail



commit c3c219709d206623293b4723ff7124aeb44afd39
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Sep 5 18:50:48 2012 -0300

    thumbnail: Add gnome_desktop_factory_give_me_a_thumbnail
    
    This is a simple method on the factory that gives you a thumbnail,
    maybe from the cache, maybe not, you don't care. You just want a
    thumbnail.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684026

 libgnome-desktop/gnome-desktop-thumbnail.c |   67 ++++++++++++++++++++++++++++
 libgnome-desktop/gnome-desktop-thumbnail.h |    5 ++
 2 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index 7a78895..f375537 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -1522,3 +1522,70 @@ gnome_desktop_thumbnail_is_valid (GdkPixbuf          *pixbuf,
   
   return TRUE;
 }
+
+/**
+ * gnome_desktop_thumbnail_give_me_a_thumbnail:
+ * @factory: A #GnomeDesktopThumbnailFactory
+ * @uri: The URI to thumbnail
+ * @mime_type: The MIME type of the file
+ * @mtime: The mtime of the file
+ *
+ * Give me a thumbnail for @uri. If the file is newer than
+ * @mtime, this function may generate a new thumbnail. This
+ * function may cache the generated thumbnail, or it may
+ * return a cached thumbnail. This function should always
+ * return a valid path.
+ *
+ * Returns: (transfer full): a valid path to a thumbnail.
+ */
+char *
+gnome_desktop_thumbnail_factory_give_me_a_thumbnail (GnomeDesktopThumbnailFactory *factory,
+                                                     char                         *uri,
+                                                     char                         *mime_type,
+                                                     time_t                        mtime)
+{
+  GnomeDesktopThumbnailFactoryPrivate *priv = factory->priv;
+  GdkPixbuf *pixbuf;
+  char *good_path, *failed_path;
+
+  good_path = lookup_thumbnail_path (uri, mtime, priv->size, FALSE);
+  failed_path = lookup_thumbnail_path (uri, mtime, priv->size, TRUE);
+
+  /* Check for a good thumbnail first. */
+  if (good_path != NULL)
+    {
+      g_free (failed_path);
+      return good_path;
+    }
+
+  /* Otherwise, check for a failed thumbnail. */
+  if (failed_path != NULL)
+    {
+      g_free (good_path);
+      return failed_path;
+    }
+
+  /* OK, fallback case: generate a new thumbnail. */
+  pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (factory, uri, mime_type);
+  if (save_thumbnail (pixbuf, good_path, uri, mtime))
+    {
+      g_clear_object (&pixbuf);
+      g_free (failed_path);
+      return good_path;
+    }
+
+  g_clear_object (&pixbuf);
+
+  /* If we don't have that, generate a failed thumbnail. */
+  pixbuf = make_failed_thumbnail ();
+  if (save_thumbnail (pixbuf, failed_path, uri, mtime))
+    {
+      g_clear_object (&pixbuf);
+      g_free (good_path);
+      return failed_path;
+    }
+
+  /* FIXME: we cannot write anything to the thumbnal dir, apparently.
+   * What should we do here? */
+  return "";
+}
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.h b/libgnome-desktop/gnome-desktop-thumbnail.h
index b8e409f..a35e541 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.h
+++ b/libgnome-desktop/gnome-desktop-thumbnail.h
@@ -105,6 +105,11 @@ GdkPixbuf *gnome_desktop_thumbnail_scale_down_pixbuf (GdkPixbuf          *pixbuf
 						      int                 dest_width,
 						      int                 dest_height);
 
+char * gnome_desktop_thumbnail_factory_give_me_a_thumbnail (GnomeDesktopThumbnailFactory *factory,
+                                                            char                         *uri,
+                                                            char                         *mime_type,
+                                                            time_t                        mtime);
+
 G_END_DECLS
 
 #endif /* GNOME_DESKTOP_THUMBNAIL_H */



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