[Xfce4-commits] <tumbler:jannis/folder-thumbnails> Add simple folder thumbnailer based on the JPEG thumbnailer.

Jannis Pohlmann noreply at xfce.org
Mon Jan 10 00:22:03 CET 2011


Updating branch refs/heads/jannis/folder-thumbnails
         to 4c5c0972e639b78ef5976feb64a3e9f8aa6fbe1f (commit)
       from 68640975a8b03fbda3e56cea7daa976bdd1f2d54 (commit)

commit 4c5c0972e639b78ef5976feb64a3e9f8aa6fbe1f
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Mon Jan 10 00:18:39 2011 +0100

    Add simple folder thumbnailer based on the JPEG thumbnailer.
    
    This thumbnailer searches all directories for
    {F,f}older.{jpg,jpeg,JPG,JPEG} files and tries to use the first one
    found as the thumbnail image for the folder.
    
    It is just an example implementation that shows that this CAN be done.
    It shouldn't necessarily be done this way.

 acinclude.m4                                       |   44 +++++++++-
 configure.ac                                       |   11 ++-
 plugins/Makefile.am                                |    3 +-
 .../Makefile.am                                    |   28 +++---
 .../folder-thumbnailer-plugin.c}                   |   16 ++--
 .../folder-thumbnailer-provider.c}                 |   69 +++++---------
 .../folder-thumbnailer-provider.h                  |   43 +++++++++
 .../folder-thumbnailer.c}                          |  100 +++++++++++++-------
 plugins/folder-thumbnailer/folder-thumbnailer.h    |   43 +++++++++
 9 files changed, 253 insertions(+), 104 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index e2d374b..cefece0 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1,6 +1,6 @@
 dnl vi:set et ai sw=2 sts=2 ts=2: */
 dnl -
-dnl Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+dnl Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
 dnl
 dnl This program is free software; you can redistribute it and/or 
 dnl modify it under the terms of the GNU General Public License as
@@ -39,6 +39,48 @@ AC_MSG_RESULT([$ac_tumbler_pixbuf_thumbnailer])
 
 
 
+dnl TUMBLER_FOLDER_THUMBNAILER()
+dnl
+dnl Check whether to build and install the folder thumbnailer plugin.
+dnl
+AC_DEFUN([TUMBLER_FOLDER_THUMBNAILER],
+[
+AC_ARG_ENABLE([folder-thumbnailer], [AC_HELP_STRING([--disable-folder-thumbnailer], [Don't build the folder thumbnailer plugin])],
+  [ac_tumbler_folder_thumbnailer=$enableval], [ac_tumbler_folder_thumbnailer=yes])
+if test x"$ac_tumbler_folder_thumbnailer" = x"yes"; then
+  dnl Check for gdk-pixbuf 
+  PKG_CHECK_MODULES([GDK_PIXBUF], [gdk-pixbuf-2.0 >= 2.14], 
+  [
+    dnl Check for libjpeg
+    LIBJPEG_LIBS=""
+    LIBJPEG_CFLAGS=""
+    AC_CHECK_LIB([jpeg], [jpeg_start_decompress],
+    [
+      AC_CHECK_HEADER([jpeglib.h],
+      [
+        LIBJPEG_LIBS="-ljpeg -lm"
+      ],
+      [
+        dnl We can only build the JPEG thumbnailer if the JPEG headers are available
+        ac_tumbler_jpeg_thumbnailer=no
+      ])
+    ],
+    [
+      dnl We can only build the JPEG thumbnailer if libjpeg is available
+      ac_tumbler_jpeg_thumbnailer=no
+    ])
+    AC_SUBST([LIBJPEG_CFLAGS])
+    AC_SUBST([LIBJPEG_LIBS])
+  ], [ac_tumbler_jpeg_thumbnailer=no])
+fi
+
+AC_MSG_CHECKING([whether to build the folder thumbnailer plugin])
+AM_CONDITIONAL([TUMBLER_FOLDER_THUMBNAILER], [test x"$ac_tumbler_folder_thumbnailer" = x"yes"])
+AC_MSG_RESULT([$ac_tumbler_folder_thumbnailer])
+])
+
+
+
 dnl TUMBLER_FONT_THUMBNAILER()
 dnl
 dnl Check whether to build and install the FreeType2 font thumbnailer plugin.
diff --git a/configure.ac b/configure.ac
index 45ec523..fd91b02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 # vi:set et ai sw=2 sts=2 ts=2: */
 # -
-# Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>
+# Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
 # 
 # This program is free software; you can redistribute it and/or 
 # modify it under the terms of the GNU General Public License as
@@ -35,7 +35,7 @@ m4_define([tumbler_debug_default], [minimum])
 dnl ***************************
 dnl *** Initialize autoconf ***
 dnl ***************************
-AC_COPYRIGHT([Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>])
+AC_COPYRIGHT([Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>])
 AC_INIT([tumbler], [tumbler_version], [http://bugzilla.xfce.org/])
 AC_PREREQ([2.50])
 AC_CANONICAL_TARGET()
@@ -150,6 +150,7 @@ PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1 >= 0.72])
 dnl *************************
 dnl *** Check for plugins ***
 dnl *************************
+TUMBLER_FOLDER_THUMBNAILER()
 TUMBLER_FONT_THUMBNAILER()
 TUMBLER_JPEG_THUMBNAILER()
 TUMBLER_PIXBUF_THUMBNAILER()
@@ -180,6 +181,7 @@ docs/reference/Makefile
 docs/reference/tumbler/Makefile
 docs/reference/tumbler/version.xml
 plugins/Makefile
+plugins/folder-thumbnailer/Makefile
 plugins/font-thumbnailer/Makefile
 plugins/jpeg-thumbnailer/Makefile
 plugins/pixbuf-thumbnailer/Makefile
@@ -203,6 +205,11 @@ echo "  * Debug:                                     $enable_debug"
 echo
 echo "Plugins:"
 echo
+if test x"$ac_tumbler_folder_thumbnailer" = x"yes"; then
+echo "  * Folder thumbnailer plugin:                        yes"
+else
+echo "  * Folder thumbnailer plugin:                        no"
+fi
 if test x"$ac_tumbler_pixbuf_thumbnailer" = x"yes"; then
 echo "  * GdkPixbuf thumbnailer plugin:                     yes"
 else
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 7894a05..49984a3 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,6 +1,6 @@
 # vi:set ts=8 sw=8 noet ai nocindent:
 # -
-# Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+# Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
 # 
 # This program is free software; you can redistribute it and/or 
 # modify it under the terms of the GNU General Public License as
@@ -18,6 +18,7 @@
 # Boston, MA 02110-1301, USA.
 
 SUBDIRS =								\
+	folder-thumbnailer						\
 	font-thumbnailer						\
 	jpeg-thumbnailer						\
 	pixbuf-thumbnailer						\
diff --git a/plugins/jpeg-thumbnailer/Makefile.am b/plugins/folder-thumbnailer/Makefile.am
similarity index 72%
copy from plugins/jpeg-thumbnailer/Makefile.am
copy to plugins/folder-thumbnailer/Makefile.am
index a47ea08..9c0fd65 100644
--- a/plugins/jpeg-thumbnailer/Makefile.am
+++ b/plugins/folder-thumbnailer/Makefile.am
@@ -1,6 +1,6 @@
 # vi:set ts=8 sw=8 noet ai nocindent:
 # -
-# Copyright (c) 2009-2010 Jannis Pohlmann <jannis at xfce.org>
+# Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
 # 
 # This program is free software; you can redistribute it and/or 
 # modify it under the terms of the GNU General Public License as
@@ -17,25 +17,25 @@
 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
-if TUMBLER_JPEG_THUMBNAILER
+if TUMBLER_FOLDER_THUMBNAILER
 
 tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins
 tumbler_plugin_LTLIBRARIES =						\
-	tumbler-jpeg-thumbnailer.la
+	tumbler-folder-thumbnailer.la
 
-tumbler_jpeg_thumbnailer_la_SOURCES =					\
-	jpeg-thumbnailer-plugin.c					\
-	jpeg-thumbnailer-provider.c					\
-	jpeg-thumbnailer-provider.h					\
-	jpeg-thumbnailer.c						\
-	jpeg-thumbnailer.h
+tumbler_folder_thumbnailer_la_SOURCES =					\
+	folder-thumbnailer-plugin.c					\
+	folder-thumbnailer-provider.c					\
+	folder-thumbnailer-provider.h					\
+	folder-thumbnailer.c						\
+	folder-thumbnailer.h
 
-tumbler_jpeg_thumbnailer_la_CFLAGS =					\
+tumbler_folder_thumbnailer_la_CFLAGS =					\
 	-I$(top_builddir)						\
 	-I$(top_builddir)/plugins					\
 	-I$(top_srcdir)							\
 	-I$(top_srcdir)/plugins						\
-	-DG_LOG_DOMAIN=\"tumbler-jpeg-thumbnailer\"			\
+	-DG_LOG_DOMAIN=\"tumbler-folder-thumbnailer\"			\
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
 	$(GDK_PIXBUF_CFLAGS)						\
 	$(GIO_CFLAGS)							\
@@ -43,20 +43,20 @@ tumbler_jpeg_thumbnailer_la_CFLAGS =					\
 	$(LIBJPEG_CFLAGS)						\
 	$(PLATFORM_CPPFLAGS)
 
-tumbler_jpeg_thumbnailer_la_LDFLAGS =					\
+tumbler_folder_thumbnailer_la_LDFLAGS =					\
 	-avoid-version							\
 	-export-dynamic							\
 	-module								\
 	$(PLATFORM_LDFLAGS)
 
-tumbler_jpeg_thumbnailer_la_LIBADD =					\
+tumbler_folder_thumbnailer_la_LIBADD =					\
 	$(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la	\
 	$(GDK_PIXBUF_LIBS)						\
 	$(GIO_LIBS)							\
 	$(GLIB_LIBS)							\
 	$(LIBJPEG_LIBS)
 
-tumbler_jpeg_thumbnailer_la_DEPENDENCIES =				\
+tumbler_folder_thumbnailer_la_DEPENDENCIES =				\
 	$(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la
 
 endif
diff --git a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-plugin.c b/plugins/folder-thumbnailer/folder-thumbnailer-plugin.c
similarity index 82%
copy from plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-plugin.c
copy to plugins/folder-thumbnailer/folder-thumbnailer-plugin.c
index 0cf1fc3..02730a9 100644
--- a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-plugin.c
+++ b/plugins/folder-thumbnailer/folder-thumbnailer-plugin.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -28,8 +28,8 @@
 
 #include <tumbler/tumbler.h>
 
-#include <pixbuf-thumbnailer/pixbuf-thumbnailer-provider.h>
-#include <pixbuf-thumbnailer/pixbuf-thumbnailer.h>
+#include <folder-thumbnailer/folder-thumbnailer-provider.h>
+#include <folder-thumbnailer/folder-thumbnailer.h>
 
 
 
@@ -59,15 +59,15 @@ tumbler_plugin_initialize (TumblerProviderPlugin *plugin)
     }
 
 #ifdef DEBUG
-  g_message (_("Initializing the Tumbler Pixbuf Thumbnailer plugin"));
+  g_message (_("Initializing the Tumbler Folder Thumbnailer plugin"));
 #endif
 
   /* register the types provided by this plugin */
-  pixbuf_thumbnailer_register (plugin);
-  pixbuf_thumbnailer_provider_register (plugin);
+  folder_thumbnailer_register (plugin);
+  folder_thumbnailer_provider_register (plugin);
 
   /* set up the plugin provider type list */
-  type_list[0] = TYPE_PIXBUF_THUMBNAILER_PROVIDER;
+  type_list[0] = TYPE_FOLDER_THUMBNAILER_PROVIDER;
 }
 
 
@@ -76,7 +76,7 @@ void
 tumbler_plugin_shutdown (void)
 {
 #ifdef DEBUG
-  g_message (_("Shutting down the Tumbler Pixbuf Thumbnailer plugin"));
+  g_message (_("Shutting down the Tumbler Folder Thumbnailer plugin"));
 #endif
 }
 
diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c b/plugins/folder-thumbnailer/folder-thumbnailer-provider.c
similarity index 55%
copy from plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c
copy to plugins/folder-thumbnailer/folder-thumbnailer-provider.c
index 16175e8..11eff6e 100644
--- a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c
+++ b/plugins/folder-thumbnailer/folder-thumbnailer-provider.c
@@ -1,7 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
- * Copyright (c) 2010 Lionel Le Folgoc <mrpouit at ubuntu.com>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -30,47 +29,47 @@
 
 #include <tumbler/tumbler.h>
 
-#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.h>
-#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer.h>
+#include <folder-thumbnailer/folder-thumbnailer-provider.h>
+#include <folder-thumbnailer/folder-thumbnailer.h>
 
 
 
-static void   ffmpeg_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
-static GList *ffmpeg_thumbnailer_provider_get_thumbnailers          (TumblerThumbnailerProvider      *provider);
+static void   folder_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
+static GList *folder_thumbnailer_provider_get_thumbnailers          (TumblerThumbnailerProvider      *provider);
 
 
 
-struct _FfmpegThumbnailerProviderClass
+struct _FolderThumbnailerProviderClass
 {
   GObjectClass __parent__;
 };
 
-struct _FfmpegThumbnailerProvider
+struct _FolderThumbnailerProvider
 {
   GObject __parent__;
 };
 
 
 
-G_DEFINE_DYNAMIC_TYPE_EXTENDED (FfmpegThumbnailerProvider,
-                                ffmpeg_thumbnailer_provider,
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (FolderThumbnailerProvider,
+                                folder_thumbnailer_provider,
                                 G_TYPE_OBJECT,
                                 0,
                                 TUMBLER_ADD_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER,
-                                                       ffmpeg_thumbnailer_provider_thumbnailer_provider_init));
+                                                       folder_thumbnailer_provider_thumbnailer_provider_init));
 
 
 
 void
-ffmpeg_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
+folder_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
 {
-  ffmpeg_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
+  folder_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
 }
 
 
 
 static void
-ffmpeg_thumbnailer_provider_class_init (FfmpegThumbnailerProviderClass *klass)
+folder_thumbnailer_provider_class_init (FolderThumbnailerProviderClass *klass)
 {
   GObjectClass *gobject_class;
 
@@ -80,64 +79,48 @@ ffmpeg_thumbnailer_provider_class_init (FfmpegThumbnailerProviderClass *klass)
 
 
 static void
-ffmpeg_thumbnailer_provider_class_finalize (FfmpegThumbnailerProviderClass *klass)
+folder_thumbnailer_provider_class_finalize (FolderThumbnailerProviderClass *klass)
 {
 }
 
 
 
 static void
-ffmpeg_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
+folder_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
 {
-  iface->get_thumbnailers = ffmpeg_thumbnailer_provider_get_thumbnailers;
+  iface->get_thumbnailers = folder_thumbnailer_provider_get_thumbnailers;
 }
 
 
 
 static void
-ffmpeg_thumbnailer_provider_init (FfmpegThumbnailerProvider *provider)
+folder_thumbnailer_provider_init (FolderThumbnailerProvider *provider)
 {
 }
 
 
 
 static GList *
-ffmpeg_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
+folder_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
 {
-  static const gchar *mime_types[] =
-  {
-    "video/jpeg",
-    "video/mp4",
-    "video/mpeg",
-    "video/quicktime",
-    "video/x-ms-asf",
-    "video/x-ms-wm",
-    "video/x-ms-wmv",
-    "video/x-msvideo",
-    "video/x-flv",
-    "application/x-flash-video",
-    "video/3gpp",
-    "video/x-matroska",
-    "video/ogg",
-    NULL
-  };
-  FfmpegThumbnailer  *thumbnailer;
+  FolderThumbnailer  *thumbnailer;
   GList              *thumbnailers = NULL;
   GStrv               uri_schemes;
+  const gchar *const  mime_types[2] = { "inode/directory", NULL };
 
-  /* determine the URI schemes supported by GIO */
+  /* determine which URI schemes are supported by GIO */
   uri_schemes = tumbler_util_get_supported_uri_schemes ();
 
   /* create the pixbuf thumbnailer */
-  thumbnailer = g_object_new (TYPE_FFMPEG_THUMBNAILER,
-                              "uri-schemes", uri_schemes, "mime-types", mime_types,
+  thumbnailer = g_object_new (TYPE_FOLDER_THUMBNAILER, 
+                              "uri-schemes", uri_schemes, "mime-types", mime_types, 
                               NULL);
 
+  /* free URI schemes and MIME types */
+  g_strfreev (uri_schemes);
+
   /* add the thumbnailer to the list */
   thumbnailers = g_list_append (thumbnailers, thumbnailer);
 
-  /* free URI schemes */
-  g_strfreev (uri_schemes);
-
   return thumbnailers;
 }
diff --git a/plugins/folder-thumbnailer/folder-thumbnailer-provider.h b/plugins/folder-thumbnailer/folder-thumbnailer-provider.h
new file mode 100644
index 0000000..7cd016b
--- /dev/null
+++ b/plugins/folder-thumbnailer/folder-thumbnailer-provider.h
@@ -0,0 +1,43 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General 
+ * Public License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __FOLDER_THUMBNAILER_PROVIDER_H__
+#define __FOLDER_THUMBNAILER_PROVIDER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS;
+
+#define TYPE_FOLDER_THUMBNAILER_PROVIDER            (folder_thumbnailer_provider_get_type ())
+#define FOLDER_THUMBNAILER_PROVIDER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOLDER_THUMBNAILER_PROVIDER, FolderThumbnailerProvider))
+#define FOLDER_THUMBNAILER_PROVIDER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOLDER_THUMBNAILER_PROVIDER, FolderThumbnailerProviderClass))
+#define IS_FOLDER_THUMBNAILER_PROVIDER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOLDER_THUMBNAILER_PROVIDER))
+#define IS_FOLDER_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOLDER_THUMBNAILER_PROVIDER)
+#define FOLDER_THUMBNAILER_PROVIDER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOLDER_THUMBNAILER_PROVIDER, FolderThumbnailerProviderClass))
+
+typedef struct _FolderThumbnailerProviderClass FolderThumbnailerProviderClass;
+typedef struct _FolderThumbnailerProvider      FolderThumbnailerProvider;
+
+GType folder_thumbnailer_provider_get_type (void) G_GNUC_CONST;
+void  folder_thumbnailer_provider_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS;
+
+#endif /* !__FOLDER_THUMBNAILER_PROVIDER_H__ */
diff --git a/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c b/plugins/folder-thumbnailer/folder-thumbnailer.c
similarity index 90%
copy from plugins/jpeg-thumbnailer/jpeg-thumbnailer.c
copy to plugins/folder-thumbnailer/folder-thumbnailer.c
index 2d55046..ada44c5 100644
--- a/plugins/jpeg-thumbnailer/jpeg-thumbnailer.c
+++ b/plugins/folder-thumbnailer/folder-thumbnailer.c
@@ -1,7 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -17,9 +16,6 @@
  * Public License along with this library; if not, write to the 
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
- *
- * Based on code written by Alexander Larsson <alexl at redhat.com>
- * for libgnomeui.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -70,63 +66,75 @@
 
 #include <tumbler/tumbler.h>
 
-#include <jpeg-thumbnailer/jpeg-thumbnailer.h>
+#include <folder-thumbnailer/folder-thumbnailer.h>
+
+
+
+static const gchar * const cover_filenames[] = {
+  "folder.jpg",
+  "folder.jpeg",
+  "folder.JPG",
+  "folder.JPEG",
+  "Folder.jpg",
+  "Folder.jpeg",
+  "Folder.JPG",
+  "Folder.JPEG",
+};
 
 
 
-static void fatal_error_handler     (j_common_ptr                cinfo) G_GNUC_NORETURN;
-static void jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
-                                     GCancellable               *cancellable,
-                                     TumblerFileInfo            *info);
+static void folder_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+                                       GCancellable               *cancellable,
+                                       TumblerFileInfo            *info);
 
 
 
-struct _JPEGThumbnailerClass
+struct _FolderThumbnailerClass
 {
   TumblerAbstractThumbnailerClass __parent__;
 };
 
-struct _JPEGThumbnailer
+struct _FolderThumbnailer
 {
   TumblerAbstractThumbnailer __parent__;
 };
 
 
 
-G_DEFINE_DYNAMIC_TYPE (JPEGThumbnailer, 
-                       jpeg_thumbnailer,
+G_DEFINE_DYNAMIC_TYPE (FolderThumbnailer, 
+                       folder_thumbnailer,
                        TUMBLER_TYPE_ABSTRACT_THUMBNAILER);
 
 
 
 void
-jpeg_thumbnailer_register (TumblerProviderPlugin *plugin)
+folder_thumbnailer_register (TumblerProviderPlugin *plugin)
 {
-  jpeg_thumbnailer_register_type (G_TYPE_MODULE (plugin));
+  folder_thumbnailer_register_type (G_TYPE_MODULE (plugin));
 }
 
 
 
 static void
-jpeg_thumbnailer_class_init (JPEGThumbnailerClass *klass)
+folder_thumbnailer_class_init (FolderThumbnailerClass *klass)
 {
   TumblerAbstractThumbnailerClass *abstractthumbnailer_class;
 
   abstractthumbnailer_class = TUMBLER_ABSTRACT_THUMBNAILER_CLASS (klass);
-  abstractthumbnailer_class->create = jpeg_thumbnailer_create;
+  abstractthumbnailer_class->create = folder_thumbnailer_create;
 }
 
 
 
 static void
-jpeg_thumbnailer_class_finalize (JPEGThumbnailerClass *klass)
+folder_thumbnailer_class_finalize (FolderThumbnailerClass *klass)
 {
 }
 
 
 
 static void
-jpeg_thumbnailer_init (JPEGThumbnailer *thumbnailer)
+folder_thumbnailer_init (FolderThumbnailer *thumbnailer)
 {
 }
 
@@ -147,7 +155,7 @@ typedef struct
 
 
 
-static void
+static G_GNUC_NORETURN void
 fatal_error_handler (j_common_ptr cinfo)
 {
   TvtjErrorHandler *handler = (TvtjErrorHandler *) cinfo->err;
@@ -670,28 +678,30 @@ tvtj_jpeg_load_thumbnail (const JOCTET *content,
 
 
 static void
-jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
-                         GCancellable               *cancellable,
-                         TumblerFileInfo            *info)
+folder_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+                           GCancellable               *cancellable,
+                           TumblerFileInfo            *info)
 {
   TumblerThumbnailFlavor *flavor;
   TumblerImageData        data;
   TumblerThumbnail       *thumbnail;
   struct stat             statb;
   const gchar            *uri;
-  GdkPixbuf              *pixbuf;
+  GdkPixbuf              *pixbuf = NULL;
   gboolean                streaming_needed = TRUE;
   JOCTET                 *content;
   GError                 *error = NULL;
-  GFile                  *file;
+  GFile                  *file = NULL;
+  GFile                  *folder;
   gchar                  *path;
   gsize                   length;
+  guint                   n;
   gint                    fd;
   gint                    height;
   gint                    width;
   gint                    size;
 
-  g_return_if_fail (IS_JPEG_THUMBNAILER (thumbnailer));
+  g_return_if_fail (IS_FOLDER_THUMBNAILER (thumbnailer));
   g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
   g_return_if_fail (TUMBLER_IS_FILE_INFO (info));
 
@@ -699,22 +709,39 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
   if (g_cancellable_is_cancelled (cancellable)) 
     return;
 
-  uri = tumbler_file_info_get_uri (info);
-
-  /* try to open the source file for reading */
-  file = g_file_new_for_uri (uri);
-
   thumbnail = tumbler_file_info_get_thumbnail (info);
   g_assert (thumbnail != NULL);
 
   flavor = tumbler_thumbnail_get_flavor (thumbnail);
   g_assert (flavor != NULL);
 
+  uri = tumbler_file_info_get_uri (info);
+
+  /* try to open the source file for reading */
+  folder = g_file_new_for_uri (uri);
+  for (n = 0; file == NULL && n < G_N_ELEMENTS (cover_filenames); ++n)
+    {
+      file = g_file_get_child (folder, cover_filenames[n]);
+      if (!g_file_query_exists (file, cancellable))
+        {
+          g_object_unref (file);
+          file = NULL;
+        }
+    }
+  g_object_unref (folder);
+
+  if (file == NULL)
+    {
+      g_set_error (&error, TUMBLER_ERROR, 
+                   TUMBLER_ERROR_INVALID_FORMAT,
+                   _("No album cover file found in this folder"));
+    }
+
   tumbler_thumbnail_flavor_get_size (flavor, &width, &height);
   size = MIN (width, height);
 
 #ifdef HAVE_MMAP
-  if (g_file_is_native (file))
+  if (error == NULL && g_file_is_native (file))
     {
       path = g_file_get_path (file);
 
@@ -766,7 +793,7 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
     }
 #endif
 
-  if (streaming_needed)
+  if (error == NULL && streaming_needed)
     {
       g_file_load_contents (file, cancellable, (gchar **)&content, &length, 
                             NULL, &error);
@@ -819,5 +846,8 @@ jpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
 
   g_object_unref (flavor);
   g_object_unref (thumbnail);
-  g_object_unref (file);
+ 
+  if (file != NULL) 
+    g_object_unref (file);
 }
+
diff --git a/plugins/folder-thumbnailer/folder-thumbnailer.h b/plugins/folder-thumbnailer/folder-thumbnailer.h
new file mode 100644
index 0000000..055f584
--- /dev/null
+++ b/plugins/folder-thumbnailer/folder-thumbnailer.h
@@ -0,0 +1,43 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General 
+ * Public License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __FOLDER_THUMBNAILER_H__
+#define __FOLDER_THUMBNAILER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS;
+
+#define TYPE_FOLDER_THUMBNAILER            (folder_thumbnailer_get_type ())
+#define FOLDER_THUMBNAILER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOLDER_THUMBNAILER, FolderThumbnailer))
+#define FOLDER_THUMBNAILER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOLDER_THUMBNAILER, FolderThumbnailerClass))
+#define IS_FOLDER_THUMBNAILER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOLDER_THUMBNAILER))
+#define IS_FOLDER_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOLDER_THUMBNAILER)
+#define FOLDER_THUMBNAILER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOLDER_THUMBNAILER, FolderThumbnailerClass))
+
+typedef struct _FolderThumbnailerClass   FolderThumbnailerClass;
+typedef struct _FolderThumbnailer        FolderThumbnailer;
+
+GType folder_thumbnailer_get_type (void) G_GNUC_CONST;
+void  folder_thumbnailer_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS;
+
+#endif /* !__FOLDER_THUMBNAILER_H__ */



More information about the Xfce4-commits mailing list