summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaël Bonithon <gael@xfce.org>2021-12-28 18:57:40 +0100
committerGaël Bonithon <gael@xfce.org>2021-12-29 13:09:43 +0100
commitcd30208a015032a17df7e5038be357ef5acc1de2 (patch)
treeb8bdc6d61f1a67bce9479489f52b42151c8686e8
parenta188f1c30f8e7c98373d620832933522ad29d14f (diff)
downloadtumbler-cd30208a015032a17df7e5038be357ef5acc1de2.tar.gz
Cleanup: Avoid code duplication
-rw-r--r--docs/reference/tumbler/tumbler-sections.txt1
-rw-r--r--plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c51
-rw-r--r--tumbler/tumbler-util.c48
-rw-r--r--tumbler/tumbler-util.h2
-rw-r--r--tumblerd/tumbler-manager.c51
5 files changed, 57 insertions, 96 deletions
diff --git a/docs/reference/tumbler/tumbler-sections.txt b/docs/reference/tumbler/tumbler-sections.txt
index 1d41b50..8378231 100644
--- a/docs/reference/tumbler/tumbler-sections.txt
+++ b/docs/reference/tumbler/tumbler-sections.txt
@@ -262,6 +262,7 @@ tumbler_util_dump_strv
tumbler_util_toggle_stderr
tumbler_util_get_supported_uri_schemes
tumbler_util_get_settings
+tumbler_util_get_thumbnailer_dirs
tumbler_util_guess_is_sparse
tumbler_util_size_prepared
tumbler_util_scale_pixbuf
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c
index 1b8ffe4..a7d7bea 100644
--- a/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c
+++ b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c
@@ -214,56 +214,11 @@ desktop_thumbnailer_get_thumbnailers_from_dir (GList *thumbnailers,
static GList *
desktop_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
{
- GHashTable *single_path;
- const gchar *const *data_dirs;
- gchar *dirname;
- GStrv uri_schemes;
- GList *iter;
- int n;
- GList *thumbnailers = NULL;
- GList *directories = NULL;
+ GList *directories, *iter, *thumbnailers = NULL;
+ GStrv uri_schemes;
uri_schemes = tumbler_util_get_supported_uri_schemes ();
-
- /* prepend $XDG_DATA_HOME/thumbnailers/ to the directory list */
- dirname = g_build_filename (g_get_user_data_dir (), "thumbnailers", NULL);
- directories = g_list_prepend (directories, g_file_new_for_path (dirname));
- g_free (dirname);
-
- /* build $XDG_DATA_DIRS/thumbnailers dirnames and prepend them to the list */
- data_dirs = g_get_system_data_dirs ();
-
- /* Create a ghash table to insert loaded directory path to avoid duplication */
- single_path = g_hash_table_new_full (g_file_hash,
- (GEqualFunc)g_file_equal,
- g_object_unref,
- NULL);
-
- for (n = 0; data_dirs[n] != NULL; ++n)
- {
- GFile *path;
-
- path = g_file_new_for_path(data_dirs[n]);
-
- if (!g_hash_table_lookup (single_path, path))
- {
- dirname = g_build_filename (data_dirs[n], "thumbnailers", NULL);
- directories = g_list_prepend (directories, g_file_new_for_path (dirname));
- g_hash_table_insert (single_path, path, path);
- g_free (dirname);
- }
- else
- {
- /* Free the path GFile object */
- g_object_unref(path);
- }
- }
- /* destroy the hash table used for loading single pathes */
- g_hash_table_destroy (single_path);
-
- /* reverse the directory list so that the directories with highest
- * priority come first */
- directories = g_list_reverse (directories);
+ directories = tumbler_util_get_thumbnailer_dirs ();
tumbler_util_dump_strv (G_LOG_DOMAIN, "Supported URI schemes",
(const gchar *const *) uri_schemes);
diff --git a/tumbler/tumbler-util.c b/tumbler/tumbler-util.c
index cfc1172..4e8f718 100644
--- a/tumbler/tumbler-util.c
+++ b/tumbler/tumbler-util.c
@@ -221,6 +221,54 @@ tumbler_util_get_settings (void)
}
+
+GList *
+tumbler_util_get_thumbnailer_dirs (void)
+{
+ GHashTable *single_path;
+ GFile *path;
+ GList *dirs = NULL;
+ const gchar *const *data_dirs;
+ gchar *dirname;
+ guint n;
+
+ /* prepend $XDG_DATA_HOME/thumbnailers/ to the directory list */
+ dirname = g_build_filename (g_get_user_data_dir (), "thumbnailers", NULL);
+ dirs = g_list_prepend (dirs, g_file_new_for_path (dirname));
+ g_free (dirname);
+
+ /* determine system data dirs */
+ data_dirs = g_get_system_data_dirs ();
+
+ /* create a ghash table to insert loaded directory path to avoid duplication */
+ single_path = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal);
+
+ /* build $XDG_DATA_DIRS/thumbnailers dirnames and prepend them to the list */
+ for (n = 0; data_dirs[n] != NULL; ++n)
+ {
+ dirname = g_build_filename (data_dirs[n], "thumbnailers", NULL);
+ path = g_file_new_for_path (dirname);
+
+ if (! g_hash_table_lookup (single_path, path))
+ {
+ g_hash_table_insert (single_path, path, path);
+ dirs = g_list_prepend (dirs, path);
+ }
+ else
+ g_object_unref (path);
+
+ g_free (dirname);
+ }
+
+ /* destroy the hash table used for loading single pathes */
+ g_hash_table_destroy (single_path);
+
+ /* reverse the directory list so that the dirs with highest priority come first */
+ return g_list_reverse (dirs);
+}
+
+
+
gboolean tumbler_util_guess_is_sparse (TumblerFileInfo *info)
{
gchar *filename;
diff --git a/tumbler/tumbler-util.h b/tumbler/tumbler-util.h
index 24c7d29..5f278db 100644
--- a/tumbler/tumbler-util.h
+++ b/tumbler/tumbler-util.h
@@ -40,6 +40,8 @@ gchar **tumbler_util_get_supported_uri_schemes (void) G_GNUC_MALLOC;
GKeyFile *tumbler_util_get_settings (void) G_GNUC_MALLOC;
+GList *tumbler_util_get_thumbnailer_dirs (void);
+
gboolean tumbler_util_guess_is_sparse (TumblerFileInfo *info);
void tumbler_util_size_prepared (GdkPixbufLoader *loader,
diff --git a/tumblerd/tumbler-manager.c b/tumblerd/tumbler-manager.c
index ef9a0e0..7a128a6 100644
--- a/tumblerd/tumbler-manager.c
+++ b/tumblerd/tumbler-manager.c
@@ -1213,13 +1213,8 @@ tumbler_manager_load_thumbnailers (TumblerManager *manager,
void
tumbler_manager_load (TumblerManager *manager)
{
- GHashTable *single_path;
- const gchar *const *data_dirs;
- GFileMonitor *monitor;
- GList *directories = NULL;
- GList *iter;
- gchar *dirname;
- guint n;
+ GFileMonitor *monitor;
+ GList *directories, *iter;
g_return_if_fail (TUMBLER_MANAGER (manager));
@@ -1231,47 +1226,7 @@ tumbler_manager_load (TumblerManager *manager)
tumbler_mutex_unlock (manager->mutex);
- /* prepend $XDG_DATA_HOME/thumbnailers/ to the directory list */
- dirname = g_build_filename (g_get_user_data_dir (), "thumbnailers", NULL);
- directories = g_list_prepend (directories, g_file_new_for_path (dirname));
- g_free (dirname);
-
- /* determine system data dirs */
- data_dirs = g_get_system_data_dirs ();
-
- /* Create a ghash table to insert loaded directory path to avoid duplication */
- single_path = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
-
- /* build $XDG_DATA_DIRS/thumbnailers dirnames and prepend them to the list */
- for (n = 0; data_dirs[n] != NULL; ++n)
- {
- GFile *path;
-
- path = g_file_new_for_path(data_dirs[n]);
-
- if (!g_hash_table_lookup (single_path, path))
- {
- /* Save it in the hash table so we can relocate it */
- /* path will be free automatically by g_hash_table_destroy */
- g_hash_table_insert (single_path, path, path);
-
- dirname = g_build_filename (data_dirs[n], "thumbnailers", NULL);
- directories = g_list_prepend (directories, g_file_new_for_path (dirname));
- g_free (dirname);
- }
- else
- {
- /* Free the path GFile object */
- g_object_unref(path);
- }
- }
-
- /* destroy the hash table used for loading single pathes */
- g_hash_table_destroy (single_path);
-
- /* reverse the directory list so that the directories with highest
- * priority come first */
- directories = g_list_reverse (directories);
+ directories = tumbler_util_get_thumbnailer_dirs ();
tumbler_mutex_lock (manager->mutex);