[Xfce4-commits] <tumbler:jannis/specialized> Squashme: Further work on the specialized branch.
Jannis Pohlmann
noreply at xfce.org
Tue Nov 3 01:44:03 CET 2009
Updating branch refs/heads/jannis/specialized
to c1d47c7f047f518a9681010a6092934e39b1454b (commit)
from 3b122767d1785131ce61bfefd2421762119e42fe (commit)
commit c1d47c7f047f518a9681010a6092934e39b1454b
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Nov 3 01:41:21 2009 +0100
Squashme: Further work on the specialized branch.
Except for reacting on file change events, everything should work now.
The rest is coming tomorrow or on Wednesday.
tumblerd/tumbler-manager.c | 246 +++++++++++++++----------------------------
tumblerd/tumbler-registry.c | 107 +++++++++----------
tumblerd/tumbler-registry.h | 5 +
3 files changed, 137 insertions(+), 221 deletions(-)
diff --git a/tumblerd/tumbler-manager.c b/tumblerd/tumbler-manager.c
index 8f685de..615938a 100644
--- a/tumblerd/tumbler-manager.c
+++ b/tumblerd/tumbler-manager.c
@@ -32,6 +32,7 @@
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include <gio/gio.h>
@@ -110,7 +111,7 @@ struct _OverrideInfo
struct _ThumbnailerInfo
{
- gchar *basename;
+ gchar *base_name;
TumblerThumbnailer *thumbnailer;
gint dir_index;
};
@@ -450,18 +451,6 @@ tumbler_manager_update_overrides (TumblerManager *manager)
g_hash_table_iter_init (&hash_iter, manager->overrides);
while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &infos))
g_ptr_array_sort (infos, override_info_compare);
-
- const gchar *key;
- g_hash_table_iter_init (&hash_iter, manager->overrides);
- while (g_hash_table_iter_next (&hash_iter, (gpointer) &key, (gpointer) &infos))
- {
- guint n;
-
- g_debug ("override section: %s", key);
-
- for (n = 0; n < infos->len; ++n)
- g_debug (" %s", ((OverrideInfo *)g_ptr_array_index (infos, n))->name);
- }
}
@@ -480,7 +469,7 @@ thumbnailer_info_free (ThumbnailerInfo *info)
if (info == NULL)
return;
- g_free (info->basename);
+ g_free (info->base_name);
if (info->thumbnailer != NULL)
g_object_unref (info->thumbnailer);
g_slice_free (ThumbnailerInfo, info);
@@ -488,47 +477,13 @@ thumbnailer_info_free (ThumbnailerInfo *info)
-static gint
-thumbnailer_info_compare (gconstpointer a,
- gconstpointer b)
-{
- TumblerSpecializedThumbnailer *thumbnailer_a;
- TumblerSpecializedThumbnailer *thumbnailer_b;
- const ThumbnailerInfo *info_a = a;
- const ThumbnailerInfo *info_b = b;
- guint64 mtime_a;
- guint64 mtime_b;
-
- thumbnailer_a = TUMBLER_SPECIALIZED_THUMBNAILER (info_a->thumbnailer);
- thumbnailer_b = TUMBLER_SPECIALIZED_THUMBNAILER (info_b->thumbnailer);
-
- mtime_a = tumbler_specialized_thumbnailer_get_modified (thumbnailer_a);
- mtime_b = tumbler_specialized_thumbnailer_get_modified (thumbnailer_b);
-
- return CLAMP (mtime_a - mtime_b, -1, 1);
-}
-
-
-
-static void
-thumbnailer_info_array_free (gpointer pointer)
-{
- GPtrArray *infos = pointer;
-
- g_ptr_array_foreach (infos, (GFunc) thumbnailer_info_free, NULL);
- g_ptr_array_free (infos, TRUE);
-}
-
-
-
static void
tumbler_manager_load_thumbnailer_infos (TumblerManager *manager,
GFile *directory)
{
ThumbnailerInfo *info;
- GPtrArray *infos;
- struct stat stat;
- const gchar *basename;
+ struct stat file_stat;
+ const gchar *base_name;
GKeyFile *key_file;
GError *error = NULL;
GDir *dir;
@@ -538,7 +493,6 @@ tumbler_manager_load_thumbnailer_infos (TumblerManager *manager,
gchar *object_path;
gchar **uri_schemes;
gchar **mime_types;
- guint n;
g_return_if_fail (TUMBLER_IS_MANAGER (manager));
g_return_if_fail (G_IS_FILE (directory));
@@ -553,20 +507,20 @@ tumbler_manager_load_thumbnailer_infos (TumblerManager *manager,
return;
}
- for (basename = g_dir_read_name (dir);
- basename != NULL;
- basename = g_dir_read_name (dir))
+ for (base_name = g_dir_read_name (dir);
+ base_name != NULL;
+ base_name = g_dir_read_name (dir))
{
/* skip non-service files */
- if (!g_str_has_suffix (basename, ".service"))
+ if (!g_str_has_suffix (base_name, ".service"))
continue;
/* skip .service files if files with the same filename appeared in
* directories with higher priorities */
- if (g_hash_table_lookup (manager->thumbnailers, basename) != NULL)
+ if (g_hash_table_lookup (manager->thumbnailers, base_name) != NULL)
continue;
- filename = g_build_filename (dirname, basename, NULL);
+ filename = g_build_filename (dirname, base_name, NULL);
if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
@@ -638,7 +592,7 @@ tumbler_manager_load_thumbnailer_infos (TumblerManager *manager,
uri_schemes[1] = NULL;
}
- if (g_stat (filename, &stat) != 0)
+ if (g_stat (filename, &file_stat) != 0)
{
g_warning (_("Failed to determine last modified time of \"%s\""), filename);
@@ -653,15 +607,15 @@ tumbler_manager_load_thumbnailer_infos (TumblerManager *manager,
}
info = thumbnailer_info_new ();
- info->basename = g_strdup (basename);
+ info->base_name = g_strdup (base_name);
info->dir_index = g_list_index (manager->directories, directory);
info->thumbnailer =
tumbler_specialized_thumbnailer_new (manager->connection, name, object_path,
(const gchar *const *)uri_schemes,
(const gchar *const *)mime_types,
- stat.st_mtime);
+ file_stat.st_mtime);
- g_hash_table_insert (manager->thumbnailers, g_strdup (basename), info);
+ g_hash_table_insert (manager->thumbnailers, g_strdup (base_name), info);
g_strfreev (uri_schemes);
g_strfreev (mime_types);
@@ -678,16 +632,17 @@ tumbler_manager_load_thumbnailer_infos (TumblerManager *manager,
static void
tumbler_manager_update_thumbnailers (TumblerManager *manager)
{
- ThumbnailerInfo *thumbnailer_info;
- GHashTableIter thumbnailer_iter;
- GHashTableIter override_iter;
- OverrideInfo *override_info;
- const gchar *hash_key;
- const gchar *override_key;
- const gchar *name;
- GPtrArray *overrides;
- GList *iter;
- guint n;
+ TumblerThumbnailer *preferred;
+ ThumbnailerInfo *thumbnailer_info;
+ GHashTableIter thumbnailer_iter;
+ GHashTableIter override_iter;
+ OverrideInfo *override_info;
+ const gchar *hash_key;
+ const gchar *name;
+ const gchar *preferred_name;
+ GPtrArray *overrides;
+ GList *iter;
+ guint n;
g_return_if_fail (TUMBLER_IS_MANAGER (manager));
@@ -712,33 +667,57 @@ tumbler_manager_update_thumbnailers (TumblerManager *manager)
g_hash_table_iter_init (&thumbnailer_iter, manager->thumbnailers);
while (g_hash_table_iter_next (&thumbnailer_iter, NULL, (gpointer) &thumbnailer_info))
{
- override_key = NULL;
+ /* add the thumbnailer to the registry */
+ tumbler_registry_add (manager->registry, thumbnailer_info->thumbnailer);
+ /* get the name of the current thumbnailer */
name = tumbler_specialized_thumbnailer_get_name (
TUMBLER_SPECIALIZED_THUMBNAILER (thumbnailer_info->thumbnailer));
- g_debug ("thumbnailer: %s", name);
-
+ /* iterate over all override info arrays */
g_hash_table_iter_init (&override_iter, manager->overrides);
- while (override_key == NULL
- && g_hash_table_iter_next (&override_iter, (gpointer) &hash_key,
- (gpointer) &overrides))
+ while (g_hash_table_iter_next (&override_iter, (gpointer) &hash_key,
+ (gpointer) &overrides))
{
- for (n = 0; override_key == NULL && n < overrides->len; ++n)
+ /* get the current preferred thumbnailer for this URI/MIME pair */
+ preferred = tumbler_registry_get_preferred (manager->registry, hash_key);
+
+ /* determine its name */
+ if (preferred != NULL)
+ {
+ preferred_name = tumbler_specialized_thumbnailer_get_name (
+ TUMBLER_SPECIALIZED_THUMBNAILER (preferred));
+ }
+ else
+ {
+ preferred_name = NULL;
+ }
+
+ /* iterate over all infos in the current array */
+ for (n = 0; n < overrides->len; ++n)
{
override_info = g_ptr_array_index (overrides, n);
+ /* stop searching if the info matches the already preferred thumbnailer */
+ if (preferred_name != NULL
+ && g_strcmp0 (preferred_name, override_info->name) == 0)
+ {
+ break;
+ }
+
+ /* check if the info matches the current thumbnailer */
if (g_strcmp0 (name, override_info->name) == 0)
- override_key = hash_key;
+ {
+ /* make the current thumbnailer the preferred thumbnailer for the
+ * hash key */
+ tumbler_registry_set_preferred (manager->registry, hash_key,
+ thumbnailer_info->thumbnailer);
+ }
}
- }
- if (override_key != NULL)
- {
- g_debug (" overrides others in %s", override_key);
- }
- else
- {
+ /* release the preferred thumbnailer */
+ if (preferred != NULL)
+ g_object_unref (preferred);
}
}
}
@@ -750,7 +729,7 @@ tumbler_manager_load_thumbnailers (TumblerManager *manager)
{
const gchar *const *data_dirs;
GFileMonitor *monitor;
- GList *directories;
+ GList *directories = NULL;
GList *iter;
gchar *dirname;
guint n;
@@ -774,7 +753,7 @@ tumbler_manager_load_thumbnailers (TumblerManager *manager)
data_dirs = g_get_system_data_dirs ();
/* build $XDG_DATA_DIRS/thumbnailers dirnames and prepend them to the list */
- for (data_dirs, n = 0; data_dirs[n] != NULL; ++n)
+ for (n = 0; data_dirs[n] != NULL; ++n)
{
dirname = g_build_filename (data_dirs[n], "thumbnailers", NULL);
directories = g_list_prepend (directories, g_file_new_for_path (dirname));
@@ -797,6 +776,9 @@ tumbler_manager_load_thumbnailers (TumblerManager *manager)
/* update the thumbnailer cache */
tumbler_manager_update_thumbnailers (manager);
+ /* update the supported information */
+ tumbler_registry_update_supported (manager->registry);
+
/* monitor the directories for changes */
for (iter = g_list_last (manager->directories); iter != NULL; iter = iter->prev)
{
@@ -812,21 +794,6 @@ tumbler_manager_load_thumbnailers (TumblerManager *manager)
-static gint
-compare_files (gconstpointer a,
- gconstpointer b)
-{
- GFile *file_a = G_FILE (a);
- GFile *file_b = G_FILE (b);
-
- if (g_file_equal (file_a, file_b))
- return 0;
- else
- return -1;
-}
-
-
-
static void
tumbler_manager_directory_changed (TumblerManager *manager,
GFile *file,
@@ -835,9 +802,7 @@ tumbler_manager_directory_changed (TumblerManager *manager,
GFileMonitor *monitor)
{
GFileType type;
- GList *iter;
- gchar *basename;
- gint dir_index;
+ gchar *base_name;
g_return_if_fail (TUMBLER_IS_MANAGER (manager));
g_return_if_fail (G_IS_FILE (file));
@@ -847,79 +812,34 @@ tumbler_manager_directory_changed (TumblerManager *manager,
if (type == G_FILE_TYPE_REGULAR)
{
- basename = g_file_get_basename (file);
+ base_name = g_file_get_basename (file);
- if (g_strcmp0 (basename, "overrides") == 0)
+ if (g_strcmp0 (base_name, "overrides") == 0)
{
g_debug ("overrides file %s changed", g_file_get_path (file));
tumbler_manager_update_overrides (manager);
+
+ /* TODO recreate the preferred mapping of the registry */
}
- else if (g_str_has_suffix (basename, ".service"))
+ else if (g_str_has_suffix (base_name, ".service"))
{
if (event_type == G_FILE_MONITOR_EVENT_DELETED)
{
g_debug ("service file %s deleted", g_file_get_path (file));
- /* TODO
- * 1. lookup the ThumbnailerInfo for this file
- * 2. if the ThumbnailerInfo is active
- * i) remove its thumbnailer from the registry
- * ii) destroy the ThumbnailerInfo
- */
-
- /* ALL THIS IS WRONG */
+ /* TODO remove the thumbnailer from the registry */
+ /* TODO if the thumbnailer is preferred, determine which
+ * replaces it in the preferred mapping */
}
else if (event_type == G_FILE_MONITOR_EVENT_CREATED)
{
g_debug ("service file %s created", g_file_get_path (file));
- /* TODO
- * 1. parse the file into a ThumbnailerInfo
- * 2. add the ThumbnailerInfo to the correct GPtrArray
- * 3. sort the GPtrArray
- * 4. if the new ThumbnailerInfo is first in this array and
- * is not overridden:
- * i) remove the previous active thumbnailer with this name
- * from the registry
- * ii) unref the previous active thumbnailer and set the
- * object member of the corresponding ThumbnailerInfo to NULL
- * iii) create the thumbnailer for the new ThumbnailerInfo
- * iv) add the new thumbnailer to the registry
- * v) update the registry's supported cache
- */
-
- /* ALL THIS IS WRONG */
- }
- }
- }
- else if (type == G_FILE_TYPE_DIRECTORY)
- {
- iter = g_list_find_custom (manager->directories, file, compare_files);
-
- if (iter != NULL)
- {
- dir_index = g_list_position (manager->directories, iter);
-
- if (event_type == G_FILE_MONITOR_EVENT_DELETED)
- {
- g_debug ("dir %s at index %i deleted", g_file_get_path (file), dir_index);
-
- /* TODO remove overrides and thumbnailers for this dir_index */
- }
- else if (event_type == G_FILE_MONITOR_EVENT_CREATED)
- {
- g_debug ("dir %s at index %i deleted", g_file_get_path (file), dir_index);
-
- tumbler_manager_update_overrides (manager);
-
- /* TODO load thumbnailers from iter->data */
- }
- else if (event_type == G_FILE_MONITOR_EVENT_CHANGED)
- {
- g_debug ("dir %s at index %i changed", g_file_get_path (file), dir_index);
-
- /* TODO What to do? */
+ /* TODO load the thumbnailer */
+ /* TODO add the thumbnailer to the registry */
+ /* TODO check if it needs to replace anything else in the
+ * preferred mapping */
}
}
}
diff --git a/tumblerd/tumbler-registry.c b/tumblerd/tumbler-registry.c
index b4f28d9..5b216d0 100644
--- a/tumblerd/tumbler-registry.c
+++ b/tumblerd/tumbler-registry.c
@@ -32,23 +32,7 @@
-/* Property identifiers */
-enum
-{
- PROP_0,
-};
-
-
-
static void tumbler_registry_finalize (GObject *object);
-static void tumbler_registry_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void tumbler_registry_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
static void tumbler_registry_remove (const gchar *key,
GList **list,
TumblerThumbnailer *thumbnailer);
@@ -73,6 +57,7 @@ struct _TumblerRegistry
GObject __parent__;
GHashTable *thumbnailers;
+ GHashTable *preferred_thumbnailers;
GMutex *mutex;
gchar **uri_schemes;
@@ -92,8 +77,6 @@ tumbler_registry_class_init (TumblerRegistryClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = tumbler_registry_finalize;
- gobject_class->get_property = tumbler_registry_get_property;
- gobject_class->set_property = tumbler_registry_set_property;
}
@@ -104,6 +87,8 @@ tumbler_registry_init (TumblerRegistry *registry)
registry->mutex = g_mutex_new ();
registry->thumbnailers = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, tumbler_registry_list_free);
+ registry->preferred_thumbnailers = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_object_unref);
}
@@ -114,6 +99,7 @@ tumbler_registry_finalize (GObject *object)
TumblerRegistry *registry = TUMBLER_REGISTRY (object);
/* release all thumbnailers */
+ g_hash_table_unref (registry->preferred_thumbnailers);
g_hash_table_unref (registry->thumbnailers);
/* free the cached URI schemes and MIME types */
@@ -129,46 +115,6 @@ tumbler_registry_finalize (GObject *object)
static void
-tumbler_registry_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
-#if 0
- TumblerRegistry *registry = TUMBLER_REGISTRY (object);
-#endif
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-
-
-static void
-tumbler_registry_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
-#if 0
- TumblerRegistry *registry = TUMBLER_REGISTRY (object);
-#endif
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-
-
-static void
tumbler_registry_remove (const gchar *key,
GList **list,
TumblerThumbnailer *thumbnailer)
@@ -318,6 +264,10 @@ tumbler_registry_lookup (TumblerRegistry *registry,
g_return_val_if_fail (TUMBLER_IS_REGISTRY (registry), NULL);
g_return_val_if_fail (hash_key != NULL, NULL);
+ thumbnailer = g_hash_table_lookup (registry->preferred_thumbnailers, hash_key);
+ if (thumbnailer != NULL)
+ return g_object_ref (thumbnailer);
+
list = g_hash_table_lookup (registry->thumbnailers, hash_key);
if (list != NULL)
@@ -627,3 +577,44 @@ tumbler_registry_get_supported (TumblerRegistry *registry,
g_mutex_unlock (registry->mutex);
}
+
+
+
+TumblerThumbnailer *
+tumbler_registry_get_preferred (TumblerRegistry *registry,
+ const gchar *hash_key)
+{
+ TumblerThumbnailer *thumbnailer = NULL;
+
+ g_return_val_if_fail (TUMBLER_IS_REGISTRY (registry), NULL);
+ g_return_val_if_fail (hash_key != NULL && *hash_key != '\0', NULL);
+
+ g_mutex_lock (registry->mutex);
+ thumbnailer = g_hash_table_lookup (registry->preferred_thumbnailers, hash_key);
+ g_mutex_unlock (registry->mutex);
+
+ return thumbnailer;
+}
+
+
+
+void
+tumbler_registry_set_preferred (TumblerRegistry *registry,
+ const gchar *hash_key,
+ TumblerThumbnailer *thumbnailer)
+{
+ g_return_if_fail (TUMBLER_IS_REGISTRY (registry));
+ g_return_if_fail (hash_key != NULL && *hash_key != '\0');
+ g_return_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer));
+
+ g_mutex_lock (registry->mutex);
+
+ g_debug ("preferring %s for %s",
+ tumbler_specialized_thumbnailer_get_name (TUMBLER_SPECIALIZED_THUMBNAILER (thumbnailer)),
+ hash_key);
+
+ g_hash_table_insert (registry->preferred_thumbnailers,
+ g_strdup (hash_key), g_object_ref (thumbnailer));
+
+ g_mutex_unlock (registry->mutex);
+}
diff --git a/tumblerd/tumbler-registry.h b/tumblerd/tumbler-registry.h
index dcd3ad3..057ddfa 100644
--- a/tumblerd/tumbler-registry.h
+++ b/tumblerd/tumbler-registry.h
@@ -50,6 +50,11 @@ void tumbler_registry_update_supported (TumblerRegistry
void tumbler_registry_get_supported (TumblerRegistry *registry,
const gchar *const **uri_schemes,
const gchar *const **mime_types);
+TumblerThumbnailer *tumbler_registry_get_preferred (TumblerRegistry *registry,
+ const gchar *hash_key) G_GNUC_WARN_UNUSED_RESULT;
+void tumbler_registry_set_preferred (TumblerRegistry *registry,
+ const gchar *hash_key,
+ TumblerThumbnailer *thumbnailer);
G_END_DECLS
More information about the Xfce4-commits
mailing list