diff options
author | Gaël Bonithon <gael@xfce.org> | 2021-12-28 18:57:40 +0100 |
---|---|---|
committer | Gaël Bonithon <gael@xfce.org> | 2021-12-29 13:09:43 +0100 |
commit | cd30208a015032a17df7e5038be357ef5acc1de2 (patch) | |
tree | b8bdc6d61f1a67bce9479489f52b42151c8686e8 /tumbler | |
parent | a188f1c30f8e7c98373d620832933522ad29d14f (diff) | |
download | tumbler-cd30208a015032a17df7e5038be357ef5acc1de2.tar.gz |
Cleanup: Avoid code duplication
Diffstat (limited to 'tumbler')
-rw-r--r-- | tumbler/tumbler-util.c | 48 | ||||
-rw-r--r-- | tumbler/tumbler-util.h | 2 |
2 files changed, 50 insertions, 0 deletions
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, |