summaryrefslogtreecommitdiff
path: root/tumbler
diff options
context:
space:
mode:
authorNick Schermer <nick@xfce.org>2012-12-16 15:30:09 +0100
committerNick Schermer <nick@xfce.org>2012-12-27 11:28:27 +0100
commit8913e999caed579d62b0021f32db6dfef65ff7f4 (patch)
tree1315cca4400154e20ca4def7908ab7f0759b8544 /tumbler
parentf7a3eda07ec55d43f92dd2ebbe717cb5c1ddd81c (diff)
downloadtumbler-8913e999caed579d62b0021f32db6dfef65ff7f4.tar.gz
Add config file system to control thumbnailing plugin.
Settings that allow to change the plugin priority, max file size to act on, white-listed locations or completely disable them.
Diffstat (limited to 'tumbler')
-rw-r--r--tumbler/tumbler-abstract-thumbnailer.c48
-rw-r--r--tumbler/tumbler-provider-factory.c28
-rw-r--r--tumbler/tumbler-thumbnailer.c74
-rw-r--r--tumbler/tumbler-thumbnailer.h5
-rw-r--r--tumbler/tumbler-util.c55
-rw-r--r--tumbler/tumbler-util.h2
6 files changed, 209 insertions, 3 deletions
diff --git a/tumbler/tumbler-abstract-thumbnailer.c b/tumbler/tumbler-abstract-thumbnailer.c
index ea05c0f..0bb2649 100644
--- a/tumbler/tumbler-abstract-thumbnailer.c
+++ b/tumbler/tumbler-abstract-thumbnailer.c
@@ -42,6 +42,9 @@ enum
PROP_URI_SCHEMES,
PROP_MIME_TYPES,
PROP_HASH_KEYS,
+ PROP_PRIORITY,
+ PROP_MAX_FILE_SIZE,
+ PROP_LOCATIONS
};
@@ -68,6 +71,9 @@ struct _TumblerAbstractThumbnailerPrivate
gchar **hash_keys;
gchar **mime_types;
gchar **uri_schemes;
+ gint priority;
+ gint64 max_file_size;
+ GSList *locations;
};
@@ -97,6 +103,9 @@ tumbler_abstract_thumbnailer_class_init (TumblerAbstractThumbnailerClass *klass)
g_object_class_override_property (gobject_class, PROP_MIME_TYPES, "mime-types");
g_object_class_override_property (gobject_class, PROP_URI_SCHEMES, "uri-schemes");
g_object_class_override_property (gobject_class, PROP_HASH_KEYS, "hash-keys");
+ g_object_class_override_property (gobject_class, PROP_PRIORITY, "priority");
+ g_object_class_override_property (gobject_class, PROP_MAX_FILE_SIZE, "max-file-size");
+ g_object_class_override_property (gobject_class, PROP_LOCATIONS, "locations");
}
@@ -173,6 +182,9 @@ tumbler_abstract_thumbnailer_finalize (GObject *object)
g_strfreev (thumbnailer->priv->mime_types);
g_strfreev (thumbnailer->priv->uri_schemes);
+ g_slist_foreach (thumbnailer->priv->locations, (GFunc) g_object_unref, NULL);
+ g_slist_free (thumbnailer->priv->locations);
+
(*G_OBJECT_CLASS (tumbler_abstract_thumbnailer_parent_class)->finalize) (object);
}
@@ -185,18 +197,36 @@ tumbler_abstract_thumbnailer_get_property (GObject *object,
GParamSpec *pspec)
{
TumblerAbstractThumbnailer *thumbnailer = TUMBLER_ABSTRACT_THUMBNAILER (object);
+ GSList *dup;
switch (prop_id)
{
case PROP_MIME_TYPES:
g_value_set_pointer (value, g_strdupv (thumbnailer->priv->mime_types));
break;
+
case PROP_URI_SCHEMES:
g_value_set_pointer (value, g_strdupv (thumbnailer->priv->uri_schemes));
break;
+
case PROP_HASH_KEYS:
g_value_set_pointer (value, g_strdupv (thumbnailer->priv->hash_keys));
break;
+
+ case PROP_PRIORITY:
+ g_value_set_int (value, thumbnailer->priv->priority);
+ break;
+
+ case PROP_MAX_FILE_SIZE:
+ g_value_set_int64 (value, thumbnailer->priv->max_file_size);
+ break;
+
+ case PROP_LOCATIONS:
+ dup = g_slist_copy (thumbnailer->priv->locations);
+ g_slist_foreach (dup, (GFunc) g_object_ref, NULL);
+ g_value_set_pointer (value, dup);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -212,18 +242,36 @@ tumbler_abstract_thumbnailer_set_property (GObject *object,
GParamSpec *pspec)
{
TumblerAbstractThumbnailer *thumbnailer = TUMBLER_ABSTRACT_THUMBNAILER (object);
+ GSList *dup;
switch (prop_id)
{
case PROP_MIME_TYPES:
thumbnailer->priv->mime_types = g_strdupv (g_value_get_pointer (value));
break;
+
case PROP_URI_SCHEMES:
thumbnailer->priv->uri_schemes = g_strdupv (g_value_get_pointer (value));
break;
+
case PROP_HASH_KEYS:
thumbnailer->priv->hash_keys = g_strdupv (g_value_get_pointer (value));
break;
+
+ case PROP_PRIORITY:
+ thumbnailer->priv->priority = g_value_get_int (value);
+ break;
+
+ case PROP_MAX_FILE_SIZE:
+ thumbnailer->priv->max_file_size = g_value_get_int64 (value);
+ break;
+
+ case PROP_LOCATIONS:
+ dup = g_slist_copy (g_value_get_pointer (value));
+ g_slist_foreach (dup, (GFunc) g_object_ref, NULL);
+ thumbnailer->priv->locations = dup;
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
diff --git a/tumbler/tumbler-provider-factory.c b/tumbler/tumbler-provider-factory.c
index afa47e3..5c67147 100644
--- a/tumbler/tumbler-provider-factory.c
+++ b/tumbler/tumbler-provider-factory.c
@@ -22,11 +22,16 @@
#include <config.h>
#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
#include <glib.h>
#include <glib-object.h>
#include <tumbler/tumbler-provider-factory.h>
#include <tumbler/tumbler-provider-plugin.h>
+#include <tumbler/tumbler-util.h>
@@ -253,17 +258,34 @@ tumbler_provider_factory_get_providers (TumblerProviderFactory *factory,
GList *plugins;
GList *providers = NULL;
guint n;
+ const gchar *type_name;
+ gchar *name;
+ gboolean disabled;
+ GKeyFile *rc;
G_LOCK (factory_lock);
/* load available plugins */
plugins = tumbler_provider_factory_load_plugins (factory);
+ /* rc file */
+ rc = tumbler_util_get_settings ();
+
/* iterate over all provider infos */
for (n = 0; n < factory->provider_infos->len; ++n)
{
info = factory->provider_infos->pdata[n];
+ /* check if this plugin is disabled with the assumption
+ * the provider only provides 1 type */
+ type_name = g_type_name (info->type);
+ g_assert (g_str_has_suffix (type_name, "Provider"));
+ name = g_strndup (type_name, strlen (type_name) - 8);
+ disabled = g_key_file_get_boolean (rc, name, "Disabled", NULL);
+ g_free (name);
+ if (disabled)
+ continue;
+
/* check if the provider type implements the given type */
if (G_LIKELY (g_type_is_a (info->type, type)))
{
@@ -271,8 +293,8 @@ tumbler_provider_factory_get_providers (TumblerProviderFactory *factory,
if (info->provider == NULL)
info->provider = g_object_new (info->type, NULL);
- /* append the provider to the list */
- providers = g_list_append (providers, g_object_ref (info->provider));
+ /* add the provider to the list */
+ providers = g_list_prepend (providers, g_object_ref (info->provider));
}
}
@@ -281,6 +303,8 @@ tumbler_provider_factory_get_providers (TumblerProviderFactory *factory,
g_type_module_unuse (G_TYPE_MODULE (lp->data));
g_list_free (plugins);
+ g_key_file_free (rc);
+
G_UNLOCK (factory_lock);
return providers;
diff --git a/tumbler/tumbler-thumbnailer.c b/tumbler/tumbler-thumbnailer.c
index 4c4d928..14e2b71 100644
--- a/tumbler/tumbler-thumbnailer.c
+++ b/tumbler/tumbler-thumbnailer.c
@@ -94,7 +94,28 @@ tumbler_thumbnailer_class_init (TumblerThumbnailerIface *klass)
g_param_spec_pointer ("hash-keys",
"hash-keys",
"hash-keys",
- G_PARAM_READABLE));
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE));
+
+ g_object_interface_install_property (klass,
+ g_param_spec_int ("priority",
+ "priority",
+ "priority",
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE));
+
+ g_object_interface_install_property (klass,
+ g_param_spec_int64 ("max-file-size",
+ "max-file-size",
+ "max-file-size",
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+
+ g_object_interface_install_property (klass,
+ g_param_spec_pointer ("locations",
+ "locations",
+ "locations",
+ G_PARAM_READWRITE));
tumbler_thumbnailer_signals[SIGNAL_READY] =
g_signal_new ("ready",
@@ -191,6 +212,57 @@ tumbler_thumbnailer_get_uri_schemes (TumblerThumbnailer *thumbnailer)
+gint
+tumbler_thumbnailer_get_priority (TumblerThumbnailer *thumbnailer)
+{
+ gint priority;
+
+ g_return_val_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer), 0);
+
+ g_object_get (thumbnailer, "priority", &priority, NULL);
+ return priority;
+}
+
+
+
+gint64
+tumbler_thumbnailer_get_max_file_size (TumblerThumbnailer *thumbnailer)
+{
+ gint max_file_size;
+
+ g_return_val_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer), 0);
+
+ g_object_get (thumbnailer, "max-file-size", &max_file_size, NULL);
+ return max_file_size;
+}
+
+
+
+gboolean
+tumbler_thumbnailer_supports_location (TumblerThumbnailer *thumbnailer,
+ GFile *file)
+{
+ GSList *locations, *lp;
+ gboolean supported = FALSE;
+
+ /* we're cool if no locations are set */
+ g_object_get (thumbnailer, "locations", &locations, NULL);
+ if (locations == NULL)
+ return TRUE;
+
+ /*check if the prefix is supported */
+ for (lp = locations; !supported && lp != NULL; lp = lp->next)
+ if (g_file_has_prefix (file, G_FILE (lp->data)))
+ supported = TRUE;
+
+ g_slist_foreach (locations, (GFunc) g_object_unref, NULL);
+ g_slist_free (locations);
+
+ return supported;
+}
+
+
+
gboolean
tumbler_thumbnailer_supports_hash_key (TumblerThumbnailer *thumbnailer,
const gchar *hash_key)
diff --git a/tumbler/tumbler-thumbnailer.h b/tumbler/tumbler-thumbnailer.h
index 00abbbb..313e404 100644
--- a/tumbler/tumbler-thumbnailer.h
+++ b/tumbler/tumbler-thumbnailer.h
@@ -68,6 +68,11 @@ void tumbler_thumbnailer_create (TumblerThumbnailer
gchar **tumbler_thumbnailer_get_hash_keys (TumblerThumbnailer *thumbnailer);
gchar **tumbler_thumbnailer_get_mime_types (TumblerThumbnailer *thumbnailer);
gchar **tumbler_thumbnailer_get_uri_schemes (TumblerThumbnailer *thumbnailer);
+gint tumbler_thumbnailer_get_priority (TumblerThumbnailer *thumbnailer);
+gint64 tumbler_thumbnailer_get_max_file_size (TumblerThumbnailer *thumbnailer);
+
+gboolean tumbler_thumbnailer_supports_location (TumblerThumbnailer *thumbnailer,
+ GFile *file);
gboolean tumbler_thumbnailer_supports_hash_key (TumblerThumbnailer *thumbnailer,
const gchar *hash_key);
diff --git a/tumbler/tumbler-util.c b/tumbler/tumbler-util.c
index bb36be4..9d656d5 100644
--- a/tumbler/tumbler-util.c
+++ b/tumbler/tumbler-util.c
@@ -75,3 +75,58 @@ tumbler_util_get_supported_uri_schemes (void)
return uri_schemes;
}
+
+
+static gchar *
+tumbler_util_get_settings_filename (void)
+{
+ gchar *path;
+ const gchar filename[] = "tumbler" G_DIR_SEPARATOR_S "tumbler.rc";
+ const gchar * const *dirs;
+ guint n;
+
+ /* check user directory */
+ path = g_build_filename (g_get_user_config_dir (), filename, NULL);
+ if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
+ return path;
+ g_free (path);
+
+ dirs = g_get_system_config_dirs ();
+ if (G_UNLIKELY (dirs == NULL))
+ return FALSE;
+
+ /* look in system config dirs */
+ for (n = 0; dirs[n] != NULL; n++)
+ {
+ path = g_build_filename (dirs[n], filename, NULL);
+ if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
+ return path;
+ g_free (path);
+ }
+
+ return NULL;
+}
+
+
+
+GKeyFile *
+tumbler_util_get_settings (void)
+{
+ GKeyFile *settings;
+ GError *err = NULL;
+ gchar *filename;
+
+ settings = g_key_file_new ();
+ filename = tumbler_util_get_settings_filename ();
+
+ if (filename != NULL
+ && !g_key_file_load_from_file (settings, filename, 0, &err))
+ {
+ g_critical ("Unable to load settings from \"%s\": %s", filename, err->message);
+ g_error_free (err);
+ }
+
+ g_free (filename);
+
+ return settings;
+}
diff --git a/tumbler/tumbler-util.h b/tumbler/tumbler-util.h
index eeba4d1..b68db0a 100644
--- a/tumbler/tumbler-util.h
+++ b/tumbler/tumbler-util.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
gchar **tumbler_util_get_supported_uri_schemes (void) G_GNUC_MALLOC;
+GKeyFile *tumbler_util_get_settings (void) G_GNUC_MALLOC;
+
G_END_DECLS
#endif /* !__TUMBLER_UTIL_H__ */