summaryrefslogtreecommitdiff
path: root/tumbler
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis@xfce.org>2009-10-26 22:36:08 +0100
committerJannis Pohlmann <jannis@xfce.org>2009-10-26 22:36:08 +0100
commit7a1e43d0806ec976eb2872209affb3d8a0dad7d0 (patch)
treeb4dbedbee9a6c10e1a556b38ffa9f257963d409e /tumbler
parent8258763e662bc2345051f230f2afc4b6da699726 (diff)
downloadtumbler-7a1e43d0806ec976eb2872209affb3d8a0dad7d0.tar.gz
Switch to a plugin API that only allows one cache backend at a time.
Tumbler will now only check for the file $(libdir)/tumbler-1/plugins/cache/tumbler-cache-plugin.so which is supposed to link to the cache backend that is being used. If the XDG cache is built, tumbler-cache-plugin.so is set up to link to this plugin. The fact that we only have a singleton cache makes things much less ambiguous.
Diffstat (limited to 'tumbler')
-rw-r--r--tumbler/Makefile.am4
-rw-r--r--tumbler/tumbler-cache.c28
-rw-r--r--tumbler/tumbler-cache.h34
-rw-r--r--tumbler/tumbler-file-info.c84
-rw-r--r--tumbler/tumbler-provider-plugin.c4
-rw-r--r--tumbler/tumbler.h2
6 files changed, 82 insertions, 74 deletions
diff --git a/tumbler/Makefile.am b/tumbler/Makefile.am
index 3d32f4d..12f8d0b 100644
--- a/tumbler/Makefile.am
+++ b/tumbler/Makefile.am
@@ -30,7 +30,7 @@ libtumbler_built_sources = \
libtumbler_headers = \
tumbler-abstract-thumbnailer.h \
tumbler-cache.h \
- tumbler-cache-provider.h \
+ tumbler-cache-plugin.h \
tumbler-config.h \
tumbler-enum-types.h \
tumbler-error.h \
@@ -48,7 +48,7 @@ libtumbler_headers = \
libtumbler_sources = \
tumbler-abstract-thumbnailer.c \
tumbler-cache.c \
- tumbler-cache-provider.c \
+ tumbler-cache-plugin.c \
tumbler-config.c \
tumbler-enum-types.c \
tumbler-file-info.c \
diff --git a/tumbler/tumbler-cache.c b/tumbler/tumbler-cache.c
index d1232b1..cdb5156 100644
--- a/tumbler/tumbler-cache.c
+++ b/tumbler/tumbler-cache.c
@@ -25,6 +25,7 @@
#include <glib-object.h>
#include <tumbler/tumbler-cache.h>
+#include <tumbler/tumbler-cache-plugin.h>
@@ -54,6 +55,33 @@ tumbler_cache_get_type (void)
+TumblerCache *
+tumbler_cache_get_default (void)
+{
+ static TumblerCache *cache = NULL;
+ GTypeModule *plugin;
+
+ if (cache == NULL)
+ {
+ plugin = tumbler_cache_plugin_get_default ();
+
+ if (plugin != NULL)
+ {
+ cache = tumbler_cache_plugin_get_cache (TUMBLER_CACHE_PLUGIN (plugin));
+ g_object_add_weak_pointer (G_OBJECT (cache), (gpointer) &cache);
+ g_type_module_unuse (plugin);
+ }
+ }
+ else
+ {
+ g_object_ref (cache);
+ }
+
+ return cache;
+}
+
+
+
GList *
tumbler_cache_get_thumbnails (TumblerCache *cache,
const gchar *uri)
diff --git a/tumbler/tumbler-cache.h b/tumbler/tumbler-cache.h
index c1a1e42..7e42539 100644
--- a/tumbler/tumbler-cache.h
+++ b/tumbler/tumbler-cache.h
@@ -61,23 +61,25 @@ struct _TumblerCacheIface
const gchar *uri);
};
-GType tumbler_cache_get_type (void) G_GNUC_CONST;
+GType tumbler_cache_get_type (void) G_GNUC_CONST;
-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);
+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);
G_END_DECLS
diff --git a/tumbler/tumbler-file-info.c b/tumbler/tumbler-file-info.c
index 80b8d69..c2cbde8 100644
--- a/tumbler/tumbler-file-info.c
+++ b/tumbler/tumbler-file-info.c
@@ -193,15 +193,14 @@ tumbler_file_info_load (TumblerFileInfo *info,
GError **error)
{
TumblerProviderFactory *provider_factory;
- GFileInfo *file_info;
- GError *err = NULL;
- GFile *file;
- GList *caches;
- GList *cp;
- GList *lp;
- GList *providers;
- GList *thumbnails;
- GList *tp;
+ TumblerCache *cache;
+ GFileInfo *file_info;
+ GError *err = NULL;
+ GFile *file;
+ GList *cp;
+ GList *lp;
+ GList *thumbnails;
+ GList *tp;
g_return_val_if_fail (TUMBLER_IS_FILE_INFO (info), FALSE);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
@@ -237,57 +236,36 @@ tumbler_file_info_load (TumblerFileInfo *info,
g_list_free (info->thumbnails);
info->thumbnails = NULL;
- /* get the provider factory */
- provider_factory = tumbler_provider_factory_get_default ();
-
- /* query a list of cache providers */
- providers = tumbler_provider_factory_get_providers (provider_factory,
- TUMBLER_TYPE_CACHE_PROVIDER);
-
- /* iterate over all available cache providers */
- for (lp = providers; err == NULL && lp != NULL; lp = lp->next)
+ /* query the default cache implementation */
+ cache = tumbler_cache_get_default ();
+ if (cache != NULL)
{
- /* query a list of cache implementations from the current provider */
- caches = tumbler_cache_provider_get_caches (lp->data);
+ /* check if the file itself is a thumbnail */
+ 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);
+
+ /* 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);
- /* iterate over all available cache implementations */
- for (cp = caches; err == NULL && cp != NULL; cp = cp->next)
+ /* add all queried thumbnails to the list */
+ info->thumbnails = g_list_concat (info->thumbnails,
+ thumbnails);
+ }
+ else
{
- /* check if the file itself is a thumbnail */
- if (!tumbler_cache_is_thumbnail (cp->data, info->uri))
- {
- /* query thumbnail infos for this URI from the current cache */
- thumbnails = tumbler_cache_get_thumbnails (cp->data, info->uri);
-
- /* 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);
- }
- else
- {
- /* we don't allow the generation of thumbnails for thumbnails */
- g_set_error (&err, TUMBLER_ERROR, TUMBLER_ERROR_IS_THUMBNAIL,
- _("The file \"%s\" is a thumbnail itself"), info->uri);
- }
+ /* we don't allow the generation of thumbnails for thumbnails */
+ g_set_error (&err, TUMBLER_ERROR, TUMBLER_ERROR_IS_THUMBNAIL,
+ _("The file \"%s\" is a thumbnail itself"), info->uri);
}
- /* release cache references */
- g_list_foreach (caches, (GFunc) g_object_unref, NULL);
- g_list_free (caches);
+ /* release the cache */
+ g_object_unref (cache);
}
- /* release provider references */
- g_list_foreach (providers, (GFunc) g_object_unref, NULL);
- g_list_free (providers);
-
- /* release the provider factory */
- g_object_unref (provider_factory);
-
if (err != NULL)
{
/* propagate errors */
diff --git a/tumbler/tumbler-provider-plugin.c b/tumbler/tumbler-provider-plugin.c
index f22babd..5e759da 100644
--- a/tumbler/tumbler-provider-plugin.c
+++ b/tumbler/tumbler-provider-plugin.c
@@ -116,7 +116,7 @@ tumbler_provider_plugin_load (GTypeModule *type_module)
g_free (path);
/* check if the load operation was successful */
- if (G_UNLIKELY (plugin->library != NULL))
+ 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",
@@ -134,6 +134,7 @@ tumbler_provider_plugin_load (GTypeModule *type_module)
{
g_warning (_("Plugin \"%s\" lacks required symbols."), type_module->name);
g_module_close (plugin->library);
+ plugin->library = NULL;
return FALSE;
}
}
@@ -160,7 +161,6 @@ tumbler_provider_plugin_unload (GTypeModule *type_module)
plugin->library = NULL;
/* reset plugin state */
- plugin->library = NULL;
plugin->initialize = NULL;
plugin->shutdown = NULL;
plugin->get_types = NULL;
diff --git a/tumbler/tumbler.h b/tumbler/tumbler.h
index 98661a5..3f086bf 100644
--- a/tumbler/tumbler.h
+++ b/tumbler/tumbler.h
@@ -25,7 +25,7 @@
#include <tumbler/tumbler-abstract-thumbnailer.h>
#include <tumbler/tumbler-cache.h>
-#include <tumbler/tumbler-cache-provider.h>
+#include <tumbler/tumbler-cache-plugin.h>
#include <tumbler/tumbler-config.h>
#include <tumbler/tumbler-enum-types.h>
#include <tumbler/tumbler-error.h>