summaryrefslogtreecommitdiff
path: root/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis@xfce.org>2009-06-08 20:31:41 +0200
committerJannis Pohlmann <jannis@xfce.org>2009-06-08 20:31:41 +0200
commit9d5f1b7b03bd0ad50365fa8186a0d9bce690f31d (patch)
tree9aed893b732fd3266c52fdbed77a1ac754199879 /plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c
parent04bb883f2b53aea6f848672ee7dea42cf7a6af86 (diff)
downloadtumbler-9d5f1b7b03bd0ad50365fa8186a0d9bce690f31d.tar.gz
Add plugin interface for cache and thumbnailer implementations.
This is a major refactoring of the source code. Amongst others, the classes TumblerProviderFactory, TumblerThumbnailer, TumblerAbstractThumbnailer, TumblerThumbnailerProvider, TumblerCache, TumblerCacheProvider and TumblerFileInfo have been added. From now on tumbler supports different storage backends and thumbnailers as plugins. Storage backends have to implement TumblerCache, thumbnailers have to implement TumblerThumbnailer. Plugins have to implement three methods: tumbler_plugin_initialize(), tumbler_plugin_shutdown() and tumbler_plugin_get_types(). The latter is expected to return a list of provider types for cache or thumbnailer implementations. Two example plugins have been added, one for the XDG thumbnail cache and one for a GdkPixbuf based thumbnailer. The code of tumblerd was updated to reflect these changes in libtumbler.
Diffstat (limited to 'plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c')
-rw-r--r--plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c b/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c
new file mode 100644
index 0000000..774e3fc
--- /dev/null
+++ b/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c
@@ -0,0 +1,170 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009 Jannis Pohlmann <jannis@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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include <tumbler/tumbler.h>
+
+#include <pixbuf-thumbnailer/pixbuf-thumbnailer-provider.h>
+#include <pixbuf-thumbnailer/pixbuf-thumbnailer-thumbnailer.h>
+
+
+
+static void pixbuf_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
+static GList *pixbuf_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider);
+
+
+
+struct _PixbufThumbnailerProviderClass
+{
+ GObjectClass __parent__;
+};
+
+struct _PixbufThumbnailerProvider
+{
+ GObject __parent__;
+};
+
+
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (PixbufThumbnailerProvider,
+ pixbuf_thumbnailer_provider,
+ G_TYPE_OBJECT,
+ 0,
+ G_IMPLEMENT_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER,
+ pixbuf_thumbnailer_provider_thumbnailer_provider_init));
+
+
+
+void
+pixbuf_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
+{
+ pixbuf_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
+}
+
+
+
+static void
+pixbuf_thumbnailer_provider_class_init (PixbufThumbnailerProviderClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ /* Determine the parent type class */
+ pixbuf_thumbnailer_provider_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class = G_OBJECT_CLASS (klass);
+}
+
+
+
+static void
+pixbuf_thumbnailer_provider_class_finalize (PixbufThumbnailerProviderClass *klass)
+{
+}
+
+
+
+static void
+pixbuf_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
+{
+ iface->get_thumbnailers = pixbuf_thumbnailer_provider_get_thumbnailers;
+}
+
+
+
+static void
+pixbuf_thumbnailer_provider_init (PixbufThumbnailerProvider *provider)
+{
+}
+
+
+
+static GList *
+pixbuf_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
+{
+ PixbufThumbnailerThumbnailer *thumbnailer;
+ static const gchar *uri_schemes[] = { "file", "sftp", "http", NULL, };
+ GHashTable *types;
+ GSList *formats;
+ GSList *fp;
+ GList *keys;
+ GList *lp;
+ GList *thumbnailers = NULL;
+ GStrv format_types;
+ GStrv mime_types;
+ gint n;
+
+ /* create a hash table to collect unique MIME types */
+ types = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ /* get a list of all formats supported by GdkPixbuf */
+ formats = gdk_pixbuf_get_formats ();
+
+ /* iterate over all formats */
+ for (fp = formats; fp != NULL; fp = fp->next)
+ {
+ /* ignore the disabled ones */
+ if (!gdk_pixbuf_format_is_disabled (fp->data))
+ {
+ /* get a list of MIME types supported by this format */
+ format_types = gdk_pixbuf_format_get_mime_types (fp->data);
+
+ /* put them all in the unqiue MIME type hash table */
+ for (n = 0; format_types != NULL && format_types[n] != NULL; ++n)
+ g_hash_table_replace (types, g_strdup (format_types[n]), NULL);
+
+ /* free the string array */
+ g_strfreev (format_types);
+ }
+ }
+
+ /* free the format list */
+ g_slist_free (formats);
+
+ /* get a list with all unique MIME types */
+ keys = g_hash_table_get_keys (types);
+
+ /* allocate a string array for them */
+ mime_types = g_new0 (gchar *, g_list_length (keys) + 1);
+
+ /* copy all MIME types into the string array */
+ for (lp = keys, n = 0; lp != NULL; lp = lp->next, ++n)
+ mime_types[n] = g_strdup (lp->data);
+
+ /* NULL-terminate the array */
+ mime_types[n] = NULL;
+
+ /* create the pixbuf thumbnailer */
+ thumbnailer = g_object_new (PIXBUF_THUMBNAILER_TYPE_THUMBNAILER,
+ "uri-schemes", uri_schemes, "mime-types", mime_types,
+ NULL);
+
+ /* add the thumbnailer to the list */
+ thumbnailers = g_list_append (thumbnailers, thumbnailer);
+
+ return thumbnailers;
+}