diff options
author | Jannis Pohlmann <jannis@xfce.org> | 2009-10-27 03:13:42 +0100 |
---|---|---|
committer | Jannis Pohlmann <jannis@xfce.org> | 2009-10-27 03:13:42 +0100 |
commit | ae5d1fcdbd406efa945a9ff631991bc08b1fa31e (patch) | |
tree | 378f5aea375c541221a62fe6ed468c383d6c0dcc /tumbler | |
parent | 7a1e43d0806ec976eb2872209affb3d8a0dad7d0 (diff) | |
download | tumbler-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')
-rw-r--r-- | tumbler/Makefile.am | 2 | ||||
-rw-r--r-- | tumbler/tumbler-abstract-thumbnailer.c | 16 | ||||
-rw-r--r-- | tumbler/tumbler-abstract-thumbnailer.h | 6 | ||||
-rw-r--r-- | tumbler/tumbler-cache-plugin.c | 219 | ||||
-rw-r--r-- | tumbler/tumbler-cache-plugin.h | 46 | ||||
-rw-r--r-- | tumbler/tumbler-cache-provider.c | 64 | ||||
-rw-r--r-- | tumbler/tumbler-cache-provider.h | 56 | ||||
-rw-r--r-- | tumbler/tumbler-cache.c | 50 | ||||
-rw-r--r-- | tumbler/tumbler-cache.h | 73 | ||||
-rw-r--r-- | tumbler/tumbler-enum-types.c | 24 | ||||
-rw-r--r-- | tumbler/tumbler-enum-types.h | 12 | ||||
-rw-r--r-- | tumbler/tumbler-file-info.c | 184 | ||||
-rw-r--r-- | tumbler/tumbler-file-info.h | 31 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnail-flavor.c | 240 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnail-flavor.h | 57 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnail.c | 68 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnail.h | 10 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnailer.c | 26 | ||||
-rw-r--r-- | tumbler/tumbler-thumbnailer.h | 22 | ||||
-rw-r--r-- | tumbler/tumbler.h | 3 |
20 files changed, 861 insertions, 348 deletions
diff --git a/tumbler/Makefile.am b/tumbler/Makefile.am index 12f8d0b..b8ccf7f 100644 --- a/tumbler/Makefile.am +++ b/tumbler/Makefile.am @@ -42,6 +42,7 @@ libtumbler_headers = \ tumbler-thumbnailer-provider.h \ tumbler-thumbnailer.h \ tumbler-thumbnail.h \ + tumbler-thumbnail-flavor.h \ tumbler-util.h \ tumbler.h @@ -58,6 +59,7 @@ libtumbler_sources = \ tumbler-thumbnailer-provider.c \ tumbler-thumbnailer.c \ tumbler-thumbnail.c \ + tumbler-thumbnail-flavor.c \ tumbler-util.c libtumblerincludedir = $(includedir)/tumbler-$(TUMBLER_VERSION_API)/tumbler diff --git a/tumbler/tumbler-abstract-thumbnailer.c b/tumbler/tumbler-abstract-thumbnailer.c index 3497393..31a8f79 100644 --- a/tumbler/tumbler-abstract-thumbnailer.c +++ b/tumbler/tumbler-abstract-thumbnailer.c @@ -26,6 +26,7 @@ #include <glib-object.h> #include <tumbler/tumbler-abstract-thumbnailer.h> +#include <tumbler/tumbler-file-info.h> #include <tumbler/tumbler-thumbnailer.h> @@ -58,9 +59,7 @@ static void tumbler_abstract_thumbnailer_set_property (GObject GParamSpec *pspec); static void tumbler_abstract_thumbnailer_create (TumblerThumbnailer *thumbnailer, GCancellable *cancellable, - const gchar *uri, - const gchar *mime_hint, - const gchar *flavor); + TumblerFileInfo *info); @@ -236,17 +235,12 @@ tumbler_abstract_thumbnailer_set_property (GObject *object, static void tumbler_abstract_thumbnailer_create (TumblerThumbnailer *thumbnailer, GCancellable *cancellable, - const gchar *uri, - const gchar *mime_hint, - const gchar *flavor) + TumblerFileInfo *info) { g_return_if_fail (TUMBLER_IS_ABSTRACT_THUMBNAILER (thumbnailer)); - g_return_if_fail (uri != NULL && *uri != '\0'); - g_return_if_fail (flavor != NULL && *flavor != '\0'); + g_return_if_fail (TUMBLER_IS_FILE_INFO (info)); g_return_if_fail (TUMBLER_ABSTRACT_THUMBNAILER_GET_CLASS (thumbnailer)->create != NULL); TUMBLER_ABSTRACT_THUMBNAILER_GET_CLASS (thumbnailer)->create (TUMBLER_ABSTRACT_THUMBNAILER (thumbnailer), - cancellable, uri, - mime_hint, - flavor); + cancellable, info); } diff --git a/tumbler/tumbler-abstract-thumbnailer.h b/tumbler/tumbler-abstract-thumbnailer.h index d82a154..f4435c4 100644 --- a/tumbler/tumbler-abstract-thumbnailer.h +++ b/tumbler/tumbler-abstract-thumbnailer.h @@ -28,6 +28,8 @@ #include <glib-object.h> #include <gio/gio.h> +#include <tumbler/tumbler-file-info.h> + G_BEGIN_DECLS; #define TUMBLER_TYPE_ABSTRACT_THUMBNAILER (tumbler_abstract_thumbnailer_get_type ()) @@ -48,9 +50,7 @@ struct _TumblerAbstractThumbnailerClass /* virtual methods */ void (*create) (TumblerAbstractThumbnailer *thumbnailer, GCancellable *cancellable, - const gchar *uri, - const gchar *mime_hint, - const gchar *flavor); + TumblerFileInfo *info); }; struct _TumblerAbstractThumbnailer 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) (); +} diff --git a/tumbler/tumbler-cache-plugin.h b/tumbler/tumbler-cache-plugin.h new file mode 100644 index 0000000..13a9dc1 --- /dev/null +++ b/tumbler/tumbler-cache-plugin.h @@ -0,0 +1,46 @@ +/* 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. + */ + +#ifndef __TUMBLER_CACHE_PLUGIN_H__ +#define __TUMBLER_CACHE_PLUGIN_H__ + +#include <tumbler/tumbler-cache.h> + +G_BEGIN_DECLS + +#define TUMBLER_TYPE_CACHE_PLUGIN (tumbler_cache_plugin_get_type ()) +#define TUMBLER_CACHE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUMBLER_TYPE_CACHE_PLUGIN, TumblerCachePlugin)) +#define TUMBLER_CACHE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUMBLER_TYPE_CACHE_PLUGIN, TumblerCachePluginClass)) +#define TUMBLER_IS_CACHE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUMBLER_TYPE_CACHE_PLUGIN)) +#define TUMBLER_IS_CACHE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUMBLER_TYPE_CACHE_PLUGIN) +#define TUMBLER_CACHE_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUMBLER_TYPE_CACHE_PLUGIN, TumblerCachePluginClass)) + +typedef struct _TumblerCachePluginPrivate TumblerCachePluginPrivate; +typedef struct _TumblerCachePluginClass TumblerCachePluginClass; +typedef struct _TumblerCachePlugin TumblerCachePlugin; + +GType tumbler_cache_plugin_get_type (void) G_GNUC_CONST; + +GTypeModule *tumbler_cache_plugin_get_default (void); +TumblerCache *tumbler_cache_plugin_get_cache (TumblerCachePlugin *plugin); + +G_END_DECLS + +#endif /* !__TUMBLER_CACHE_PLUGIN_H__ */ diff --git a/tumbler/tumbler-cache-provider.c b/tumbler/tumbler-cache-provider.c deleted file mode 100644 index f7949ab..0000000 --- a/tumbler/tumbler-cache-provider.c +++ /dev/null @@ -1,64 +0,0 @@ -/* 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-object.h> - -#include <tumbler/tumbler-cache-provider.h> - - - -GType -tumbler_cache_provider_get_type (void) -{ - static volatile gsize g_define_type_id__volatile = 0; - - if (g_once_init_enter (&g_define_type_id__volatile)) - { - GType g_define_type_id = - g_type_register_static_simple (G_TYPE_INTERFACE, - "TumblerCacheProvider", - sizeof (TumblerCacheProviderIface), - NULL, - 0, - NULL, - 0); - - g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT); - - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); - } - - return g_define_type_id__volatile; -} - - - -GList * -tumbler_cache_provider_get_caches (TumblerCacheProvider *provider) -{ - g_return_val_if_fail (TUMBLER_IS_CACHE_PROVIDER (provider), NULL); - g_return_val_if_fail (TUMBLER_CACHE_PROVIDER_GET_IFACE (provider)->get_caches != NULL, NULL); - - return (TUMBLER_CACHE_PROVIDER_GET_IFACE (provider)->get_caches) (provider); -} diff --git a/tumbler/tumbler-cache-provider.h b/tumbler/tumbler-cache-provider.h deleted file mode 100644 index efd65d4..0000000 --- a/tumbler/tumbler-cache-provider.h +++ /dev/null @@ -1,56 +0,0 @@ -/* 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. - */ - -#if !defined (TUMBLER_INSIDE_TUMBLER_H) && !defined (TUMBLER_COMPILATION) -#error "Only <tumbler/tumbler.h> may be included directly. This file might disappear or change contents." -#endif - -#ifndef __TUMBLER_CACHE_PROVIDER_H__ -#define __TUMBLER_CACHE_PROVIDER_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define TUMBLER_TYPE_CACHE_PROVIDER (tumbler_cache_provider_get_type ()) -#define TUMBLER_CACHE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUMBLER_TYPE_CACHE_PROVIDER, TumblerCacheProvider)) -#define TUMBLER_IS_CACHE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUMBLER_TYPE_CACHE_PROVIDER)) -#define TUMBLER_CACHE_PROVIDER_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TUMBLER_TYPE_CACHE_PROVIDER, TumblerCacheProviderIface)) - -typedef struct _TumblerCacheProvider TumblerCacheProvider; -typedef struct _TumblerCacheProviderIface TumblerCacheProviderIface; - -struct _TumblerCacheProviderIface -{ - GTypeInterface __parent__; - - /* signals */ - - /* virtual methods */ - GList *(*get_caches) (TumblerCacheProvider *provider); -}; - -GType tumbler_cache_provider_get_type (void) G_GNUC_CONST; - -GList *tumbler_cache_provider_get_caches (TumblerCacheProvider *provider) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; - -G_END_DECLS - -#endif /* !__TUMBLER_CACHE_PROVIDER_H__ */ diff --git a/tumbler/tumbler-cache.c b/tumbler/tumbler-cache.c index cdb5156..76dbf43 100644 --- a/tumbler/tumbler-cache.c +++ b/tumbler/tumbler-cache.c @@ -26,6 +26,8 @@ #include <tumbler/tumbler-cache.h> #include <tumbler/tumbler-cache-plugin.h> +#include <tumbler/tumbler-thumbnail.h> +#include <tumbler/tumbler-thumbnail-flavor.h> @@ -82,15 +84,17 @@ tumbler_cache_get_default (void) -GList * -tumbler_cache_get_thumbnails (TumblerCache *cache, - const gchar *uri) +TumblerThumbnail * +tumbler_cache_get_thumbnail (TumblerCache *cache, + const gchar *uri, + TumblerThumbnailFlavor *flavor) { g_return_val_if_fail (TUMBLER_IS_CACHE (cache), NULL); g_return_val_if_fail (uri != NULL && *uri != '\0', NULL); - g_return_val_if_fail (TUMBLER_CACHE_GET_IFACE (cache)->get_thumbnails != NULL, NULL); + g_return_val_if_fail (TUMBLER_IS_THUMBNAIL_FLAVOR (flavor), NULL); + g_return_val_if_fail (TUMBLER_CACHE_GET_IFACE (cache)->get_thumbnail != NULL, NULL); - return (TUMBLER_CACHE_GET_IFACE (cache)->get_thumbnails) (cache, uri); + return (TUMBLER_CACHE_GET_IFACE (cache)->get_thumbnail) (cache, uri, flavor); } @@ -163,3 +167,39 @@ tumbler_cache_is_thumbnail (TumblerCache *cache, return (TUMBLER_CACHE_GET_IFACE (cache)->is_thumbnail) (cache, uri); } + + + +GList * +tumbler_cache_get_flavors (TumblerCache *cache) +{ + g_return_val_if_fail (TUMBLER_IS_CACHE (cache), NULL); + g_return_val_if_fail (TUMBLER_CACHE_GET_IFACE (cache)->get_flavors != NULL, NULL); + + return (TUMBLER_CACHE_GET_IFACE (cache)->get_flavors) (cache); +} + + + +TumblerThumbnailFlavor * +tumbler_cache_get_flavor (TumblerCache *cache, + const gchar *name) +{ + TumblerThumbnailFlavor *flavor = NULL; + GList *flavors; + GList *iter; + + g_return_val_if_fail (TUMBLER_IS_CACHE (cache), NULL); + g_return_val_if_fail (name != NULL && *name != '\0', NULL); + + flavors = tumbler_cache_get_flavors (cache); + + for (iter = flavors; flavor == NULL && iter != NULL; iter = iter->next) + if (g_strcmp0 (tumbler_thumbnail_flavor_get_name (iter->data), name) == 0) + flavor = g_object_ref (iter->data); + + g_list_foreach (flavors, (GFunc) g_object_unref, NULL); + g_list_free (flavors); + + return flavor; +} diff --git a/tumbler/tumbler-cache.h b/tumbler/tumbler-cache.h index 7e42539..49f18ff 100644 --- a/tumbler/tumbler-cache.h +++ b/tumbler/tumbler-cache.h @@ -25,7 +25,8 @@ #ifndef __TUMBLER_CACHE_H__ #define __TUMBLER_CACHE_H__ -#include <glib-object.h> +#include <tumbler/tumbler-thumbnail.h> +#include <tumbler/tumbler-thumbnail-flavor.h> G_BEGIN_DECLS @@ -44,42 +45,48 @@ struct _TumblerCacheIface /* signals */ /* virtual methods */ - GList *(*get_thumbnails) (TumblerCache *cache, - const gchar *uri); - void (*cleanup) (TumblerCache *cache, - const gchar *uri, - guint64 since); - void (*delete) (TumblerCache *cache, - const GStrv uris); - void (*copy) (TumblerCache *cache, - const GStrv from_uris, - const GStrv to_uris); - void (*move) (TumblerCache *cache, - const GStrv from_uris, - const GStrv to_uris); - gboolean (*is_thumbnail) (TumblerCache *cache, - const gchar *uri); + TumblerThumbnail *(*get_thumbnail) (TumblerCache *cache, + const gchar *uri, + TumblerThumbnailFlavor *flavor); + void (*cleanup) (TumblerCache *cache, + const gchar *uri, + guint64 since); + void (*delete) (TumblerCache *cache, + const GStrv uris); + void (*copy) (TumblerCache *cache, + const GStrv from_uris, + const GStrv to_uris); + void (*move) (TumblerCache *cache, + const GStrv from_uris, + const GStrv to_uris); + gboolean (*is_thumbnail) (TumblerCache *cache, + const gchar *uri); + GList *(*get_flavors) (TumblerCache *cache); }; -GType tumbler_cache_get_type (void) G_GNUC_CONST; +GType tumbler_cache_get_type (void) G_GNUC_CONST; -TumblerCache *tumbler_cache_get_default (void) G_GNUC_WARN_UNUSED_RESULT; +TumblerCache *tumbler_cache_get_default (void) G_GNUC_WARN_UNUSED_RESULT; -GList *tumbler_cache_get_thumbnails (TumblerCache *cache, - const gchar *uri) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -void tumbler_cache_cleanup (TumblerCache *cache, - const gchar *uri_prefix, - guint64 since); -void tumbler_cache_delete (TumblerCache *cache, - const GStrv uris); -void tumbler_cache_copy (TumblerCache *cache, - const GStrv from_uris, - const GStrv to_uris); -void tumbler_cache_move (TumblerCache *cache, - const GStrv from_uris, - const GStrv to_uris); -gboolean tumbler_cache_is_thumbnail (TumblerCache *cache, - const gchar *uri); +TumblerThumbnail *tumbler_cache_get_thumbnail (TumblerCache *cache, + const gchar *uri, + TumblerThumbnailFlavor *flavor) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +void tumbler_cache_cleanup (TumblerCache *cache, + const gchar *uri_prefix, + guint64 since); +void tumbler_cache_delete (TumblerCache *cache, + const GStrv uris); +void tumbler_cache_copy (TumblerCache *cache, + const GStrv from_uris, + const GStrv to_uris); +void tumbler_cache_move (TumblerCache *cache, + const GStrv from_uris, + const GStrv to_uris); +gboolean tumbler_cache_is_thumbnail (TumblerCache *cache, + const gchar *uri); +GList *tumbler_cache_get_flavors (TumblerCache *cache) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +TumblerThumbnailFlavor *tumbler_cache_get_flavor (TumblerCache *cache, + const gchar *name) G_GNUC_WARN_UNUSED_RESULT; G_END_DECLS diff --git a/tumbler/tumbler-enum-types.c b/tumbler/tumbler-enum-types.c index baba55f..1e2cdd3 100644 --- a/tumbler/tumbler-enum-types.c +++ b/tumbler/tumbler-enum-types.c @@ -38,30 +38,6 @@ GType -tumbler_thumbnail_flavor_get_type (void) -{ - GType type = G_TYPE_INVALID; - - if (G_UNLIKELY (type == G_TYPE_INVALID)) - { - static const GEnumValue values[] = - { - { TUMBLER_THUMBNAIL_FLAVOR_INVALID, "TUMBLER_THUMBNAIL_FLAVOR_INVALID", N_ ("Invalid format"), }, - { TUMBLER_THUMBNAIL_FLAVOR_NORMAL, "TUMBLER_THUMBNAIL_FLAVOR_NORMAL", N_ ("Normal"), }, - { TUMBLER_THUMBNAIL_FLAVOR_LARGE, "TUMBLER_THUMBNAIL_FLAVOR_LARGE", N_ ("Large"), }, - { TUMBLER_THUMBNAIL_FLAVOR_CROPPED, "TUMBLER_THUMBNAIL_FLAVOR_CROPPED", N_ ("Cropped"), }, - { 0, NULL, NULL, }, - }; - - type = g_enum_register_static ("TumblerThumbnailFlavor", values); - } - - return type; -} - - - -GType tumbler_thumbnail_format_get_type (void) { GType type = G_TYPE_INVALID; diff --git a/tumbler/tumbler-enum-types.h b/tumbler/tumbler-enum-types.h index ea784c3..d40caa4 100644 --- a/tumbler/tumbler-enum-types.h +++ b/tumbler/tumbler-enum-types.h @@ -29,18 +29,6 @@ G_BEGIN_DECLS -#define TUMBLER_TYPE_THUMBNAIL_FLAVOR (tumbler_thumbnail_flavor_get_type ()) - -typedef enum /*< enum >*/ -{ - TUMBLER_THUMBNAIL_FLAVOR_INVALID, - TUMBLER_THUMBNAIL_FLAVOR_NORMAL, - TUMBLER_THUMBNAIL_FLAVOR_LARGE, - TUMBLER_THUMBNAIL_FLAVOR_CROPPED, -} TumblerThumbnailFlavor; - -GType tumbler_thumbnail_flavor_get_type (void); - #define TUMBLER_TYPE_THUMBNAIL_FORMAT (tumbler_thumbnail_format_get_type ()) typedef enum /*< enum >*/ diff --git a/tumbler/tumbler-file-info.c b/tumbler/tumbler-file-info.c index c2cbde8..aaac622 100644 --- a/tumbler/tumbler-file-info.c +++ b/tumbler/tumbler-file-info.c @@ -26,11 +26,13 @@ #include <glib/gi18n.h> #include <glib-object.h> +#include <tumbler/tumbler-cache.h> #include <tumbler/tumbler-error.h> #include <tumbler/tumbler-file-info.h> #include <tumbler/tumbler-provider-factory.h> #include <tumbler/tumbler-cache-provider.h> #include <tumbler/tumbler-thumbnail.h> +#include <tumbler/tumbler-thumbnail-flavor.h> @@ -40,6 +42,8 @@ enum PROP_0, PROP_MTIME, PROP_URI, + PROP_MIME_TYPE, + PROP_FLAVOR, }; @@ -65,9 +69,12 @@ struct _TumblerFileInfo { GObject __parent__; - guint64 mtime; - GList *thumbnails; - gchar *uri; + TumblerThumbnailFlavor *flavor; + TumblerThumbnail *thumbnail; + + guint64 mtime; + gchar *uri; + gchar *mime_type; }; @@ -101,6 +108,22 @@ tumbler_file_info_class_init (TumblerFileInfoClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (gobject_class, PROP_MIME_TYPE, + g_param_spec_string ("mime-type", + "mime-type", + "mime-type", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (gobject_class, PROP_FLAVOR, + g_param_spec_object ("flavor", + "flavor", + "flavor", + TUMBLER_TYPE_THUMBNAIL_FLAVOR, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); } @@ -110,7 +133,8 @@ tumbler_file_info_init (TumblerFileInfo *info) { info->mtime = 0; info->uri = NULL; - info->thumbnails = NULL; + info->mime_type = NULL; + info->thumbnail = NULL; } @@ -120,9 +144,12 @@ tumbler_file_info_finalize (GObject *object) { TumblerFileInfo *info = TUMBLER_FILE_INFO (object); - g_list_foreach (info->thumbnails, (GFunc) g_object_unref, NULL); - g_list_free (info->thumbnails); + if (info->thumbnail != NULL) + g_object_unref (info->thumbnail); + + g_object_unref (info->flavor); + g_free (info->mime_type); g_free (info->uri); (*G_OBJECT_CLASS (tumbler_file_info_parent_class)->finalize) (object); @@ -146,6 +173,12 @@ tumbler_file_info_get_property (GObject *object, case PROP_URI: g_value_set_string (value, info->uri); break; + case PROP_MIME_TYPE: + g_value_set_string (value, info->mime_type); + break; + case PROP_FLAVOR: + g_value_set_object (value, info->flavor); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -170,6 +203,12 @@ tumbler_file_info_set_property (GObject *object, case PROP_URI: info->uri = g_value_dup_string (value); break; + case PROP_MIME_TYPE: + info->mime_type = g_value_dup_string (value); + break; + case PROP_FLAVOR: + info->flavor = g_value_dup_object (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -179,10 +218,16 @@ tumbler_file_info_set_property (GObject *object, TumblerFileInfo * -tumbler_file_info_new (const gchar *uri) +tumbler_file_info_new (const gchar *uri, + const gchar *mime_type, + TumblerThumbnailFlavor *flavor) { - g_return_val_if_fail (uri != NULL, NULL); - return g_object_new (TUMBLER_TYPE_FILE_INFO, "uri", uri, NULL); + g_return_val_if_fail (uri != NULL && *uri != '\0', NULL); + g_return_val_if_fail (mime_type != NULL && *mime_type != '\0', NULL); + g_return_val_if_fail (TUMBLER_IS_THUMBNAIL_FLAVOR (flavor), NULL); + + return g_object_new (TUMBLER_TYPE_FILE_INFO, "uri", uri, "mime-type", mime_type, + "flavor", flavor, NULL); } @@ -230,11 +275,13 @@ tumbler_file_info_load (TumblerFileInfo *info, /* we no longer need the file information */ g_object_unref (file_info); - /* make sure to clear the thumbnails list before we load the info, just in - * case someone decides to load the info twice */ - g_list_foreach (info->thumbnails, (GFunc) g_object_unref, NULL); - g_list_free (info->thumbnails); - info->thumbnails = NULL; + /* make sure to clear the thumbnail before we load the info, just in + * case someone decides to load it twice */ + if (info->thumbnail != NULL) + { + g_object_unref (info->thumbnail); + info->thumbnail = NULL; + } /* query the default cache implementation */ cache = tumbler_cache_get_default (); @@ -244,16 +291,10 @@ tumbler_file_info_load (TumblerFileInfo *info, if (!tumbler_cache_is_thumbnail (cache, info->uri)) { /* query thumbnail infos for this URI from the current cache */ - thumbnails = tumbler_cache_get_thumbnails (cache, info->uri); + info->thumbnail = tumbler_cache_get_thumbnail (cache, info->uri, info->flavor); - /* try to load thumbnail infos. the loop will terminate if - * one of them fails */ - for (tp = thumbnails; err == NULL && tp != NULL; tp = tp->next) - tumbler_thumbnail_load (tp->data, cancellable, &err); - - /* add all queried thumbnails to the list */ - info->thumbnails = g_list_concat (info->thumbnails, - thumbnails); + /* try to load thumbnail info */ + tumbler_thumbnail_load (info->thumbnail, cancellable, &err); } else { @@ -271,10 +312,9 @@ tumbler_file_info_load (TumblerFileInfo *info, /* propagate errors */ g_propagate_error (error, err); - /* release thumbnails as we assume not to have any on errors */ - g_list_foreach (info->thumbnails, (GFunc) g_object_unref, NULL); - g_list_free (info->thumbnails); - info->thumbnails = NULL; + /* release the thumbnail info */ + g_object_unref (info->thumbnail); + info->thumbnail = NULL; return FALSE; } @@ -295,6 +335,15 @@ tumbler_file_info_get_uri (TumblerFileInfo *info) +const gchar * +tumbler_file_info_get_mime_type (TumblerFileInfo *info) +{ + g_return_val_if_fail (TUMBLER_IS_FILE_INFO (info), NULL); + return info->mime_type; +} + + + guint64 tumbler_file_info_get_mtime (TumblerFileInfo *info) { @@ -308,16 +357,14 @@ gboolean tumbler_file_info_needs_update (TumblerFileInfo *info) { gboolean needs_update = FALSE; - GList *lp; g_return_val_if_fail (TUMBLER_IS_FILE_INFO (info), FALSE); - /* iterate over all thumbnails and check if at least one of them needs an update */ - for (lp = info->thumbnails; !needs_update && lp != NULL; lp = lp->next) + if (info->thumbnail != NULL) { - needs_update = needs_update || tumbler_thumbnail_needs_update (lp->data, - info->uri, - info->mtime); + /* check if the thumbnail for the URI needs an update */ + needs_update = tumbler_thumbnail_needs_update (info->thumbnail, + info->uri, info->mtime); } return needs_update; @@ -325,9 +372,74 @@ tumbler_file_info_needs_update (TumblerFileInfo *info) -GList * -tumbler_file_info_get_thumbnails (TumblerFileInfo *info) +TumblerThumbnail * +tumbler_file_info_get_thumbnail (TumblerFileInfo *info) { g_return_val_if_fail (TUMBLER_IS_FILE_INFO (info), NULL); - return info->thumbnails; + return g_object_ref (info->thumbnail); +} + + + +TumblerFileInfo ** +tumbler_file_info_array_new_with_flavor (const gchar *const *uris, + const gchar *const *mime_types, + TumblerThumbnailFlavor *flavor, + guint *length) +{ + TumblerFileInfo **infos = NULL; + guint num_uris; + guint num_mime_types; + guint n; + + g_return_val_if_fail (uris != NULL, NULL); + + num_uris = g_strv_length ((GStrv) uris); + num_mime_types = g_strv_length ((GStrv) mime_types); + + if (length != NULL) + *length = MIN (num_uris, num_mime_types); + + infos = g_new0 (TumblerFileInfo *, MIN (num_uris, num_mime_types) + 1); + + for (n = 0; n < MIN (num_uris, num_mime_types); ++n) + infos[n] = tumbler_file_info_new (uris[n], mime_types[n], flavor); + + infos[n] = NULL; + + return infos; +} + + + +TumblerFileInfo ** +tumbler_file_info_array_copy (TumblerFileInfo **infos, + guint length) +{ + TumblerFileInfo **copy; + gint n; + + g_return_val_if_fail (infos != NULL, NULL); + + copy = g_new0 (TumblerFileInfo *, length + 1); + + for (n = 0; infos != NULL && infos[n] != NULL && n < length; ++n) + copy[n] = g_object_ref (infos[n]); + + copy[n] = NULL; + + return copy; +} + + + +void +tumbler_file_info_array_free (TumblerFileInfo **infos) +{ + gint n; + + for (n = 0; infos != NULL && infos[n] != NULL; ++n) + g_object_unref (infos[n]); + + g_free (infos); } diff --git a/tumbler/tumbler-file-info.h b/tumbler/tumbler-file-info.h index a30f7b6..a1330c3 100644 --- a/tumbler/tumbler-file-info.h +++ b/tumbler/tumbler-file-info.h @@ -27,6 +27,8 @@ #include <gio/gio.h> +#include <tumbler/tumbler-thumbnail.h> + G_BEGIN_DECLS; #define TUMBLER_TYPE_FILE_INFO (tumbler_file_info_get_type ()) @@ -39,16 +41,27 @@ G_BEGIN_DECLS; typedef struct _TumblerFileInfoClass TumblerFileInfoClass; typedef struct _TumblerFileInfo TumblerFileInfo; -GType tumbler_file_info_get_type (void) G_GNUC_CONST; +GType tumbler_file_info_get_type (void) G_GNUC_CONST; + +TumblerFileInfo *tumbler_file_info_new (const gchar *uri, + const gchar *mime_type, + TumblerThumbnailFlavor *flavor) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +gboolean tumbler_file_info_load (TumblerFileInfo *info, + GCancellable *cancellable, + GError **error); +const gchar *tumbler_file_info_get_uri (TumblerFileInfo *info); +const gchar *tumbler_file_info_get_mime_type (TumblerFileInfo *info); +guint64 tumbler_file_info_get_mtime (TumblerFileInfo *info); +gboolean tumbler_file_info_needs_update (TumblerFileInfo *info); +TumblerThumbnail *tumbler_file_info_get_thumbnail (TumblerFileInfo *info) G_GNUC_WARN_UNUSED_RESULT; -TumblerFileInfo *tumbler_file_info_new (const gchar *uri) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; -gboolean tumbler_file_info_load (TumblerFileInfo *info, - GCancellable *cancellable, - GError **error); -const gchar *tumbler_file_info_get_uri (TumblerFileInfo *info); -guint64 tumbler_file_info_get_mtime (TumblerFileInfo *info); -gboolean tumbler_file_info_needs_update (TumblerFileInfo *info); -GList *tumbler_file_info_get_thumbnails (TumblerFileInfo *info); +TumblerFileInfo **tumbler_file_info_array_new_with_flavor (const gchar *const *uris, + const gchar *const *mime_types, + TumblerThumbnailFlavor *flavor, + guint *length) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +TumblerFileInfo **tumbler_file_info_array_copy (TumblerFileInfo **infos, + guint length) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +void tumbler_file_info_array_free (TumblerFileInfo **infos); G_END_DECLS; diff --git a/tumbler/tumbler-thumbnail-flavor.c b/tumbler/tumbler-thumbnail-flavor.c new file mode 100644 index 0000000..cb4bdd1 --- /dev/null +++ b/tumbler/tumbler-thumbnail-flavor.c @@ -0,0 +1,240 @@ +/* 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-object.h> + +#include <tumbler/tumbler-thumbnail-flavor.h> + + + +/* property identifiers */ +enum +{ + PROP_0, + PROP_NAME, + PROP_WIDTH, + PROP_HEIGHT, +}; + + + +static void tumbler_thumbnail_flavor_finalize (GObject *object); +static void tumbler_thumbnail_flavor_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void tumbler_thumbnail_flavor_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); + + + +struct _TumblerThumbnailFlavorClass +{ + GObjectClass __parent__; +}; + +struct _TumblerThumbnailFlavor +{ + GObject __parent__; + + gchar *name; + gint width; + gint height; +}; + + + +G_DEFINE_TYPE (TumblerThumbnailFlavor, tumbler_thumbnail_flavor, G_TYPE_OBJECT) + + + +static void +tumbler_thumbnail_flavor_class_init (TumblerThumbnailFlavorClass *klass) +{ + GObjectClass *gobject_class; + + /* Determine the parent type class */ + tumbler_thumbnail_flavor_parent_class = g_type_class_peek_parent (klass); + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = tumbler_thumbnail_flavor_finalize; + gobject_class->get_property = tumbler_thumbnail_flavor_get_property; + gobject_class->set_property = tumbler_thumbnail_flavor_set_property; + + g_object_class_install_property (gobject_class, PROP_NAME, + g_param_spec_string ("name", + "name", + "name", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (gobject_class, PROP_WIDTH, + g_param_spec_int ("width", + "width", + "width", + -1, G_MAXINT, 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (gobject_class, PROP_HEIGHT, + g_param_spec_int ("height", + "height", + "height", + -1, G_MAXINT, 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + + + +static void +tumbler_thumbnail_flavor_init (TumblerThumbnailFlavor *flavor) +{ +} + + + +static void +tumbler_thumbnail_flavor_finalize (GObject *object) +{ + TumblerThumbnailFlavor *flavor = TUMBLER_THUMBNAIL_FLAVOR (object); + + g_free (flavor->name); + + (*G_OBJECT_CLASS (tumbler_thumbnail_flavor_parent_class)->finalize) (object); +} + + + +static void +tumbler_thumbnail_flavor_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TumblerThumbnailFlavor *flavor = TUMBLER_THUMBNAIL_FLAVOR (object); + + switch (prop_id) + { + case PROP_NAME: + g_value_set_string (value, flavor->name); + break; + case PROP_WIDTH: + g_value_set_int (value, flavor->width); + break; + case PROP_HEIGHT: + g_value_set_int (value, flavor->height); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + + +static void +tumbler_thumbnail_flavor_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + TumblerThumbnailFlavor *flavor = TUMBLER_THUMBNAIL_FLAVOR (object); + + switch (prop_id) + { + case PROP_NAME: + flavor->name = g_value_dup_string (value); + break; + case PROP_WIDTH: + flavor->width = g_value_get_int (value); + break; + case PROP_HEIGHT: + flavor->height = g_value_get_int (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + + +TumblerThumbnailFlavor * +tumbler_thumbnail_flavor_new (const gchar *name, + gint width, + gint height) +{ + g_return_val_if_fail (name != NULL && *name != '\0', NULL); + + return g_object_new (TUMBLER_TYPE_THUMBNAIL_FLAVOR, "name", name, + "width", width, "height", height, NULL); +} + + + +TumblerThumbnailFlavor * +tumbler_thumbnail_flavor_new_normal (void) +{ + return g_object_new (TUMBLER_TYPE_THUMBNAIL_FLAVOR, "name", "normal", + "width", 128, "height", 128, NULL); +} + + + +TumblerThumbnailFlavor * +tumbler_thumbnail_flavor_new_large (void) +{ + return g_object_new (TUMBLER_TYPE_THUMBNAIL_FLAVOR, "name", "large", + "width", 256, "height", 256, NULL); +} + + + +const gchar * +tumbler_thumbnail_flavor_get_name (TumblerThumbnailFlavor *flavor) +{ + g_return_val_if_fail (TUMBLER_IS_THUMBNAIL_FLAVOR (flavor), NULL); + return flavor->name; +} + + + +void +tumbler_thumbnail_flavor_get_size (TumblerThumbnailFlavor *flavor, + gint *width, + gint *height) +{ + g_return_if_fail (TUMBLER_IS_THUMBNAIL_FLAVOR (flavor)); + + if (width != NULL) + *width = flavor->width; + + if (height != NULL) + *height = flavor->height; +} diff --git a/tumbler/tumbler-thumbnail-flavor.h b/tumbler/tumbler-thumbnail-flavor.h new file mode 100644 index 0000000..f442166 --- /dev/null +++ b/tumbler/tumbler-thumbnail-flavor.h @@ -0,0 +1,57 @@ +/* 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. + */ + +#if !defined (TUMBLER_INSIDE_TUMBLER_H) && !defined (TUMBLER_COMPILATION) +#error "Only <tumbler/tumbler.h> may be included directly. This file might disappear or change contents." +#endif + +#ifndef __TUMBLER_THUMBNAIL_FLAVOR_H__ +#define __TUMBLER_THUMBNAIL_FLAVOR_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define TUMBLER_TYPE_THUMBNAIL_FLAVOR (tumbler_thumbnail_flavor_get_type ()) +#define TUMBLER_THUMBNAIL_FLAVOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUMBLER_TYPE_THUMBNAIL_FLAVOR, TumblerThumbnailFlavor)) +#define TUMBLER_THUMBNAIL_FLAVOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUMBLER_TYPE_THUMBNAIL_FLAVOR, TumblerThumbnailFlavorClass)) +#define TUMBLER_IS_THUMBNAIL_FLAVOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUMBLER_TYPE_THUMBNAIL_FLAVOR)) +#define TUMBLER_IS_THUMBNAIL_FLAVOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUMBLER_TYPE_THUMBNAIL_FLAVOR) +#define TUMBLER_THUMBNAIL_FLAVOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUMBLER_TYPE_THUMBNAIL_FLAVOR, TumblerThumbnailFlavorClass)) + +typedef struct _TumblerThumbnailFlavorPrivate TumblerThumbnailFlavorPrivate; +typedef struct _TumblerThumbnailFlavorClass TumblerThumbnailFlavorClass; +typedef struct _TumblerThumbnailFlavor TumblerThumbnailFlavor; + +GType tumbler_thumbnail_flavor_get_type (void) G_GNUC_CONST; + +TumblerThumbnailFlavor *tumbler_thumbnail_flavor_new (const gchar *name, + gint width, + gint height) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +TumblerThumbnailFlavor *tumbler_thumbnail_flavor_new_normal (void) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +TumblerThumbnailFlavor *tumbler_thumbnail_flavor_new_large (void) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +const gchar *tumbler_thumbnail_flavor_get_name (TumblerThumbnailFlavor *flavor); +void tumbler_thumbnail_flavor_get_size (TumblerThumbnailFlavor *flavor, + gint *width, + gint *height); + +G_END_DECLS + +#endif /* !__TUMBLER_THUMBNAIL_FLAVOR_H__ */ diff --git a/tumbler/tumbler-thumbnail.c b/tumbler/tumbler-thumbnail.c index ecefc51..b8b497a 100644 --- a/tumbler/tumbler-thumbnail.c +++ b/tumbler/tumbler-thumbnail.c @@ -77,13 +77,12 @@ tumbler_thumbnail_class_init (TumblerThumbnailIface *klass) G_PARAM_CONSTRUCT_ONLY)); g_object_interface_install_property (klass, - g_param_spec_enum ("flavor", - "flavor", - "flavor", - TUMBLER_TYPE_THUMBNAIL_FLAVOR, - TUMBLER_THUMBNAIL_FLAVOR_INVALID, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); + g_param_spec_object ("flavor", + "flavor", + "flavor", + TUMBLER_TYPE_THUMBNAIL_FLAVOR, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); } @@ -168,62 +167,13 @@ tumbler_thumbnail_get_cache (TumblerThumbnail *thumbnail) -TumblerThumbnailFlavor +TumblerThumbnailFlavor * tumbler_thumbnail_get_flavor (TumblerThumbnail *thumbnail) { - TumblerThumbnailFlavor flavor; + TumblerThumbnailFlavor *flavor; - g_return_val_if_fail (TUMBLER_IS_THUMBNAIL (thumbnail), TUMBLER_THUMBNAIL_FLAVOR_INVALID); + g_return_val_if_fail (TUMBLER_IS_THUMBNAIL (thumbnail), NULL); g_object_get (thumbnail, "flavor", &flavor, NULL); return flavor; } - - - -TumblerThumbnailFlavor * -tumbler_thumbnail_get_flavors (void) -{ - static TumblerThumbnailFlavor flavors[] = - { -#ifdef ENABLE_NORMAL_THUMBNAILS - TUMBLER_THUMBNAIL_FLAVOR_NORMAL, -#endif -#ifdef ENABLE_LARGE_THUMBNAILS - TUMBLER_THUMBNAIL_FLAVOR_LARGE, -#endif -#ifdef ENABLE_CROPPED_THUMBNAILS - TUMBLER_THUMBNAIL_FLAVOR_CROPPED, -#endif - TUMBLER_THUMBNAIL_FLAVOR_INVALID, /* this always has to come last */ - }; - - return flavors; -} - - - -void -tumbler_thumbnail_flavor_get_size (TumblerThumbnailFlavor flavor, - gint *width, - gint *height) -{ - switch (flavor) - { - case TUMBLER_THUMBNAIL_FLAVOR_NORMAL: - *width = 128; - *height = 128; - break; - case TUMBLER_THUMBNAIL_FLAVOR_LARGE: - *width = 256; - *height = 256; - break; - case TUMBLER_THUMBNAIL_FLAVOR_CROPPED: - *width = 124; - *height = 124; - break; - default: - g_assert_not_reached (); - break; - } -} diff --git a/tumbler/tumbler-thumbnail.h b/tumbler/tumbler-thumbnail.h index ed72b8f..965c467 100644 --- a/tumbler/tumbler-thumbnail.h +++ b/tumbler/tumbler-thumbnail.h @@ -28,7 +28,7 @@ #include <gio/gio.h> #include <tumbler/tumbler-enum-types.h> -#include <tumbler/tumbler-cache.h> +#include <tumbler/tumbler-thumbnail-flavor.h> G_BEGIN_DECLS @@ -95,13 +95,7 @@ gboolean tumbler_thumbnail_save_file (TumblerThumbnail guint64 mtime, GCancellable *cancellable, GError **error); -TumblerCache *tumbler_thumbnail_get_cache (TumblerThumbnail *thumbnail); -TumblerThumbnailFlavor tumbler_thumbnail_get_flavor (TumblerThumbnail *thumbnail); - -TumblerThumbnailFlavor *tumbler_thumbnail_get_flavors (void); -void tumbler_thumbnail_flavor_get_size (TumblerThumbnailFlavor flavor, - gint *width, - gint *height); +TumblerThumbnailFlavor *tumbler_thumbnail_get_flavor (TumblerThumbnail *thumbnail); G_END_DECLS diff --git a/tumbler/tumbler-thumbnailer.c b/tumbler/tumbler-thumbnailer.c index 980db15..588cfa2 100644 --- a/tumbler/tumbler-thumbnailer.c +++ b/tumbler/tumbler-thumbnailer.c @@ -23,6 +23,7 @@ #endif #include <tumbler/tumbler-marshal.h> +#include <tumbler/tumbler-file-info.h> #include <tumbler/tumbler-thumbnailer.h> @@ -136,22 +137,17 @@ tumbler_thumbnailer_class_init (TumblerThumbnailerIface *klass) void -tumbler_thumbnailer_create (TumblerThumbnailer *thumbnailer, - GCancellable *cancellable, - const gchar *uri, - const gchar *mime_hint, - const gchar *flavor) +tumbler_thumbnailer_create (TumblerThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info) { 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_IS_FILE_INFO (info)); g_return_if_fail (TUMBLER_THUMBNAILER_GET_IFACE (thumbnailer)->create != NULL); return (*TUMBLER_THUMBNAILER_GET_IFACE (thumbnailer)->create) (thumbnailer, cancellable, - uri, - mime_hint, - flavor); + info); } @@ -197,14 +193,14 @@ tumbler_thumbnailer_get_uri_schemes (TumblerThumbnailer *thumbnailer) TumblerThumbnailer ** tumbler_thumbnailer_array_copy (TumblerThumbnailer **thumbnailers, - gint length) + guint length) { TumblerThumbnailer **copy; - gint n; + guint n; g_return_val_if_fail (thumbnailers != NULL, NULL); - copy = g_new0 (TumblerThumbnailer *, length+1); + copy = g_new0 (TumblerThumbnailer *, length + 1); for (n = 0; n < length; ++n) if (thumbnailers[n] != NULL) @@ -219,9 +215,9 @@ tumbler_thumbnailer_array_copy (TumblerThumbnailer **thumbnailers, void tumbler_thumbnailer_array_free (TumblerThumbnailer **thumbnailers, - gint length) + guint length) { - gint n; + guint n; for (n = 0; thumbnailers != NULL && n < length; ++n) if (thumbnailers[n] != NULL) diff --git a/tumbler/tumbler-thumbnailer.h b/tumbler/tumbler-thumbnailer.h index 89f780b..9194fe4 100644 --- a/tumbler/tumbler-thumbnailer.h +++ b/tumbler/tumbler-thumbnailer.h @@ -28,6 +28,8 @@ #include <glib-object.h> #include <gio/gio.h> +#include <tumbler/tumbler-file-info.h> + G_BEGIN_DECLS #define TUMBLER_TYPE_THUMBNAILER (tumbler_thumbnailer_get_type ()) @@ -52,29 +54,25 @@ struct _TumblerThumbnailerIface void (*unregister) (TumblerThumbnailer *thumbnailer); /* virtual methods */ - void (*create) (TumblerThumbnailer *thumbnailer, - GCancellable *cancellable, - const gchar *uri, - const gchar *mime_hint, - const gchar *flavor); + void (*create) (TumblerThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info); }; GType tumbler_thumbnailer_get_type (void) G_GNUC_CONST; -void tumbler_thumbnailer_create (TumblerThumbnailer *thumbnailer, - GCancellable *cancellable, - const gchar *uri, - const gchar *mime_hint, - const gchar *flavor); +void tumbler_thumbnailer_create (TumblerThumbnailer *thumbnailer, + GCancellable *cancellable, + TumblerFileInfo *info); GStrv tumbler_thumbnailer_get_hash_keys (TumblerThumbnailer *thumbnailer); GStrv tumbler_thumbnailer_get_mime_types (TumblerThumbnailer *thumbnailer); GStrv tumbler_thumbnailer_get_uri_schemes (TumblerThumbnailer *thumbnailer); TumblerThumbnailer **tumbler_thumbnailer_array_copy (TumblerThumbnailer **thumbnailers, - gint length); + guint length); void tumbler_thumbnailer_array_free (TumblerThumbnailer **thumbnailers, - gint length); + guint length); G_END_DECLS diff --git a/tumbler/tumbler.h b/tumbler/tumbler.h index 3f086bf..5bff523 100644 --- a/tumbler/tumbler.h +++ b/tumbler/tumbler.h @@ -34,9 +34,10 @@ #include <tumbler/tumbler-marshal.h> #include <tumbler/tumbler-provider-factory.h> #include <tumbler/tumbler-provider-plugin.h> +#include <tumbler/tumbler-thumbnail-flavor.h> +#include <tumbler/tumbler-thumbnail.h> #include <tumbler/tumbler-thumbnailer-provider.h> #include <tumbler/tumbler-thumbnailer.h> -#include <tumbler/tumbler-thumbnail.h> #include <tumbler/tumbler-util.h> #undef TUMBLER_INSIDE_TUMBLER_H |