diff options
author | Jannis Pohlmann <jannis@xfce.org> | 2009-06-08 20:31:41 +0200 |
---|---|---|
committer | Jannis Pohlmann <jannis@xfce.org> | 2009-06-08 20:31:41 +0200 |
commit | 9d5f1b7b03bd0ad50365fa8186a0d9bce690f31d (patch) | |
tree | 9aed893b732fd3266c52fdbed77a1ac754199879 /tumbler/tumbler-thumbnailer.c | |
parent | 04bb883f2b53aea6f848672ee7dea42cf7a6af86 (diff) | |
download | tumbler-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 'tumbler/tumbler-thumbnailer.c')
-rw-r--r-- | tumbler/tumbler-thumbnailer.c | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/tumbler/tumbler-thumbnailer.c b/tumbler/tumbler-thumbnailer.c new file mode 100644 index 0000000..1756570 --- /dev/null +++ b/tumbler/tumbler-thumbnailer.c @@ -0,0 +1,224 @@ +/* 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 <tumbler/tumbler-marshal.h> +#include <tumbler/tumbler-thumbnailer.h> + + + +/* signal identifiers */ +enum +{ + SIGNAL_READY, + SIGNAL_ERROR, + SIGNAL_UNREGISTER, + LAST_SIGNAL, +}; + + + +static void tumbler_thumbnailer_class_init (TumblerThumbnailerIface *klass); + + + +static guint tumbler_thumbnailer_signals[LAST_SIGNAL]; + + + +GType +tumbler_thumbnailer_get_type (void) +{ + static GType type = G_TYPE_INVALID; + + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + type = g_type_register_static_simple (G_TYPE_INTERFACE, + "TumblerThumbnailer", + sizeof (TumblerThumbnailerIface), + (GClassInitFunc) tumbler_thumbnailer_class_init, + 0, + NULL, + 0); + + g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); + } + + return type; +} + + + +static void +tumbler_thumbnailer_class_init (TumblerThumbnailerIface *klass) +{ + g_object_interface_install_property (klass, + g_param_spec_pointer ("mime-types", + "mime-types", + "mime-types", + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE)); + + g_object_interface_install_property (klass, + g_param_spec_pointer ("uri-schemes", + "uri-schemes", + "uri-schemes", + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE)); + + g_object_interface_install_property (klass, + g_param_spec_pointer ("hash-keys", + "hash-keys", + "hash-keys", + G_PARAM_READABLE)); + + tumbler_thumbnailer_signals[SIGNAL_READY] = + g_signal_new ("ready", + TUMBLER_TYPE_THUMBNAILER, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (TumblerThumbnailerIface, ready), + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + + tumbler_thumbnailer_signals[SIGNAL_ERROR] = + g_signal_new ("error", + TUMBLER_TYPE_THUMBNAILER, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (TumblerThumbnailerIface, error), + NULL, + NULL, + tumbler_marshal_VOID__STRING_INT_STRING, + G_TYPE_NONE, + 3, + G_TYPE_STRING, + G_TYPE_INT, + G_TYPE_STRING); + + tumbler_thumbnailer_signals[SIGNAL_UNREGISTER] = + g_signal_new ("unregister", + TUMBLER_TYPE_THUMBNAILER, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (TumblerThumbnailerIface, unregister), + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); +} + + + +void +tumbler_thumbnailer_create (TumblerThumbnailer *thumbnailer, + const gchar *uri, + const gchar *mime_hint) +{ + g_return_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer)); + g_return_if_fail (uri != NULL); + g_return_if_fail (mime_hint != NULL); + g_return_if_fail (TUMBLER_THUMBNAILER_GET_IFACE (thumbnailer)->create != NULL); + + return (*TUMBLER_THUMBNAILER_GET_IFACE (thumbnailer)->create) (thumbnailer, + uri, + mime_hint); +} + + + +GStrv +tumbler_thumbnailer_get_hash_keys (TumblerThumbnailer *thumbnailer) +{ + GStrv hash_keys; + + g_return_val_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer), NULL); + + g_object_get (thumbnailer, "hash-keys", &hash_keys, NULL); + return hash_keys; +} + + + +GStrv +tumbler_thumbnailer_get_mime_types (TumblerThumbnailer *thumbnailer) +{ + GStrv mime_types; + + g_return_val_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer), NULL); + + g_object_get (thumbnailer, "mime-types", &mime_types, NULL); + return mime_types; +} + + + +GStrv +tumbler_thumbnailer_get_uri_schemes (TumblerThumbnailer *thumbnailer) +{ + GStrv uri_schemes; + + g_return_val_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer), NULL); + + g_object_get (thumbnailer, "uri-schemes", &uri_schemes, NULL); + return uri_schemes; +} + + + +TumblerThumbnailer ** +tumbler_thumbnailer_array_copy (TumblerThumbnailer **thumbnailers, + gint length) +{ + TumblerThumbnailer **copy; + gint n; + + g_return_val_if_fail (thumbnailers != NULL, NULL); + + copy = g_new0 (TumblerThumbnailer *, length+1); + + for (n = 0; n < length; ++n) + if (thumbnailers[n] != NULL) + copy[n] = g_object_ref (thumbnailers[n]); + + copy[n] = NULL; + + return copy; +} + + + +void +tumbler_thumbnailer_array_free (TumblerThumbnailer **thumbnailers, + gint length) +{ + gint n; + + for (n = 0; thumbnailers != NULL && n < length; ++n) + if (thumbnailers[n] != NULL) + g_object_unref (thumbnailers[n]); + + g_free (thumbnailers); +} |