summaryrefslogtreecommitdiff
path: root/tumbler/tumbler-cache-plugin.c
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis@xfce.org>2009-10-27 03:13:42 +0100
committerJannis Pohlmann <jannis@xfce.org>2009-10-27 03:13:42 +0100
commitae5d1fcdbd406efa945a9ff631991bc08b1fa31e (patch)
tree378f5aea375c541221a62fe6ed468c383d6c0dcc /tumbler/tumbler-cache-plugin.c
parent7a1e43d0806ec976eb2872209affb3d8a0dad7d0 (diff)
downloadtumbler-ae5d1fcdbd406efa945a9ff631991bc08b1fa31e.tar.gz
Massive refactoring to support flavors properly.
Refactor the entire code to use TumblerFileInfo instead of separate URI/MIME/flavor arrays. We now support flavors which means that applications can request "normal" and "large" thumbnails and thus have more control over what is created. This simplifies the code in a lot of places. We now use a real GObject class called TumblerThumbnailFlavor instead of a fixed-size enum. Cache backends can return as many flavors as they want, each consisting of a name, a width and a height. As a consequence, we can also get rid of the configure flags to enable/disable normal, large and cropped thumbnails. The default cache plugin shipped with Tumbler only supports "normal" (128x128px) and "large" (256x256px). Optimize the code a little bit. We now load the TunarFileInfo and ThunarThumbnail only *once* for each URI instead of loading them once in the scheduler and again in thumbnailer plugins. This needs careful testing. I might have introduced a few memory leaks here and there, plus new bugs... you never know.
Diffstat (limited to 'tumbler/tumbler-cache-plugin.c')
-rw-r--r--tumbler/tumbler-cache-plugin.c219
1 files changed, 219 insertions, 0 deletions
diff --git a/tumbler/tumbler-cache-plugin.c b/tumbler/tumbler-cache-plugin.c
new file mode 100644
index 0000000..4a92b1c
--- /dev/null
+++ b/tumbler/tumbler-cache-plugin.c
@@ -0,0 +1,219 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009 Jannis Pohlmann <jannis@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
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; 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/gi18n.h>
+#include <glib-object.h>
+#include <gmodule.h>
+
+#include <tumbler/tumbler-cache.h>
+#include <tumbler/tumbler-cache-plugin.h>
+
+
+
+static void tumbler_cache_plugin_constructed (GObject *object);
+static void tumbler_cache_plugin_dispose (GObject *object);
+static void tumbler_cache_plugin_finalize (GObject *object);
+static gboolean tumbler_cache_plugin_load (GTypeModule *type_module);
+static void tumbler_cache_plugin_unload (GTypeModule *type_module);
+
+
+
+struct _TumblerCachePluginClass
+{
+ GTypeModuleClass __parent__;
+};
+
+struct _TumblerCachePlugin
+{
+ GTypeModule __parent__;
+
+ GModule *library;
+
+ void (*initialize) (TumblerCachePlugin *plugin);
+ void (*shutdown) (void);
+ TumblerCache *(*get_cache) (void);
+};
+
+
+
+G_DEFINE_TYPE (TumblerCachePlugin, tumbler_cache_plugin, G_TYPE_TYPE_MODULE);
+
+
+
+static void
+tumbler_cache_plugin_class_init (TumblerCachePluginClass *klass)
+{
+ GTypeModuleClass *gtype_module_class;
+ GObjectClass *gobject_class;
+
+ /* Determine the parent type class */
+ tumbler_cache_plugin_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->constructed = tumbler_cache_plugin_constructed;
+ gobject_class->dispose = tumbler_cache_plugin_dispose;
+ gobject_class->finalize = tumbler_cache_plugin_finalize;
+
+ gtype_module_class = G_TYPE_MODULE_CLASS (klass);
+ gtype_module_class->load = tumbler_cache_plugin_load;
+ gtype_module_class->unload = tumbler_cache_plugin_unload;
+}
+
+
+
+static void
+tumbler_cache_plugin_cache_init (TumblerCacheIface *iface)
+{
+}
+
+
+
+static void
+tumbler_cache_plugin_init (TumblerCachePlugin *plugin)
+{
+}
+
+
+
+static void
+tumbler_cache_plugin_constructed (GObject *object)
+{
+ TumblerCachePlugin *plugin = TUMBLER_CACHE_PLUGIN (object);
+}
+
+
+
+static void
+tumbler_cache_plugin_dispose (GObject *object)
+{
+ TumblerCachePlugin *plugin = TUMBLER_CACHE_PLUGIN (object);
+
+ (*G_OBJECT_CLASS (tumbler_cache_plugin_parent_class)->dispose) (object);
+}
+
+
+
+static void
+tumbler_cache_plugin_finalize (GObject *object)
+{
+ TumblerCachePlugin *plugin = TUMBLER_CACHE_PLUGIN (object);
+
+ (*G_OBJECT_CLASS (tumbler_cache_plugin_parent_class)->finalize) (object);
+}
+
+
+
+static gboolean
+tumbler_cache_plugin_load (GTypeModule *type_module)
+{
+ TumblerCachePlugin *plugin = TUMBLER_CACHE_PLUGIN (type_module);
+ gchar *path;
+
+ /* load the module using the runtime link eeditor */
+ path = g_build_filename (TUMBLER_PLUGIN_DIRECTORY, G_DIR_SEPARATOR_S,
+ "cache", G_DIR_SEPARATOR_S, type_module->name, NULL);
+ plugin->library = g_module_open (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
+ g_free (path);
+
+ /* check if the load operation was successful */
+ if (G_LIKELY (plugin->library != NULL))
+ {
+ /* verify that all required public symbols are present in the plugin */
+ if (g_module_symbol (plugin->library, "tumbler_plugin_initialize",
+ (gpointer) &plugin->initialize)
+ && g_module_symbol (plugin->library, "tumbler_plugin_shutdown",
+ (gpointer) &plugin->shutdown)
+ && g_module_symbol (plugin->library, "tumbler_plugin_get_cache",
+ (gpointer) &plugin->get_cache))
+ {
+ /* initialize the plugin */
+ (*plugin->initialize) (plugin);
+ return TRUE;
+ }
+ else
+ {
+ g_warning (_("Cache plugin \"%s\" lacks required symbols"), type_module->name);
+ g_module_close (plugin->library);
+ plugin->library = NULL;
+ return FALSE;
+ }
+ }
+ else
+ {
+ g_warning (_("Failed to load the cache plugin \"%s\": %s"), type_module->name,
+ g_module_error ());
+ return FALSE;
+ }
+}
+
+
+
+static void
+tumbler_cache_plugin_unload (GTypeModule *type_module)
+{
+ TumblerCachePlugin *plugin = TUMBLER_CACHE_PLUGIN (type_module);
+
+ /* shutdown the plugin */
+ (*plugin->shutdown) ();
+
+ /* unload the plugin from memory */
+ g_module_close (plugin->library);
+ plugin->library = NULL;
+
+ /* reset plugin state */
+ plugin->initialize = NULL;
+ plugin->shutdown = NULL;
+ plugin->get_cache = NULL;
+}
+
+
+
+GTypeModule *
+tumbler_cache_plugin_get_default (void)
+{
+ static TumblerCachePlugin *plugin = NULL;
+
+ if (plugin == NULL)
+ {
+ plugin = g_object_new (TUMBLER_TYPE_CACHE_PLUGIN, NULL);
+ g_type_module_set_name (G_TYPE_MODULE (plugin),
+ "tumbler-cache-plugin." G_MODULE_SUFFIX);
+ g_object_add_weak_pointer (G_OBJECT (plugin), (gpointer) &plugin);
+
+ if (!g_type_module_use (G_TYPE_MODULE (plugin)))
+ return NULL;
+ }
+
+ return G_TYPE_MODULE (plugin);
+}
+
+
+
+TumblerCache *
+tumbler_cache_plugin_get_cache (TumblerCachePlugin *plugin)
+{
+ g_return_val_if_fail (TUMBLER_IS_CACHE_PLUGIN (plugin), NULL);
+ return (*plugin->get_cache) ();
+}