From d1ede5d14574fe06e49e2fa3054c4ece7aab9b38 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 21 Jul 2018 17:34:37 +0200 Subject: Working on themes --- src/io/resource.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'src/io/resource.cpp') diff --git a/src/io/resource.cpp b/src/io/resource.cpp index f8cf9fce4..127b92b76 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -213,7 +213,6 @@ Glib::ustring get_filename(Glib::ustring path, Glib::ustring filename) * * domain - Optional domain (overload), will check return domains if not. * type - The type of files, e.g. TEMPLATES - * path - Instead of Domain and Type, specify the path to get the files from. * extensions - A list of extensions to return, e.g. xml, svg * exclusions - A list of names to exclude e.g. default.xml */ @@ -225,6 +224,7 @@ std::vector get_filenames(Type type, std::vector ex get_filenames_from_path(ret, get_path_ustring(CREATE, type), extensions, exclusions); return ret; } + std::vector get_filenames(Domain domain, Type type, std::vector extensions, std::vector exclusions) { std::vector ret; @@ -238,10 +238,41 @@ std::vector get_filenames(Glib::ustring path, std::vector get_foldernames(Type type, std::vector exclusions) +{ + std::vector ret; + get_foldernames_from_path(ret, get_path_ustring(USER, type), exclusions); + get_foldernames_from_path(ret, get_path_ustring(SYSTEM, type), exclusions); + get_foldernames_from_path(ret, get_path_ustring(CREATE, type), exclusions); + return ret; +} + +std::vector get_foldernames(Domain domain, Type type, std::vector exclusions) +{ + std::vector ret; + get_foldernames_from_path(ret, get_path_ustring(domain, type), exclusions); + return ret; +} +std::vector get_foldernames(Glib::ustring path, std::vector exclusions) +{ + std::vector ret; + get_foldernames_from_path(ret, path, exclusions); + return ret; +} + + /* * Get all the files from a specific path and any sub-dirs, populating &files vector * - * &files - Output list to populate, will be opoulated with full paths + * &files - Output list to populate, will be poulated with full paths * path - The directory to parse, will add nothing if directory doesn't exist * extensions - Only add files with these extensions, they must be duplicated * exclusions - Exclude files that exactly match these names. @@ -280,6 +311,40 @@ void get_filenames_from_path(std::vector &files, Glib::ustring pa } } +/* + * Get all the files from a specific path and any sub-dirs, populating &files vector + * + * &folders - Output list to populate, will be poulated with full paths + * path - The directory to parse, will add nothing if directory doesn't exist + * exclusions - Exclude files that exactly match these names. + */ +void get_foldernames_from_path(std::vector &folders, Glib::ustring path, std::vector exclusions) +{ + if(!Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) { + return; + } + + Glib::Dir dir(path); + std::string file = dir.read_name(); + while (!file.empty()){ + // If not extensions are specified, don't reject ANY files. + bool reject = false; + + // Reject any file which matches the exclusions. + for (auto &exc: exclusions) { + reject |= Glib::str_has_prefix(file, exc); + } + + // Reject any filename which isn't a regular file + Glib::ustring filename = Glib::build_filename(path, file); + + if(Glib::file_test(filename, Glib::FILE_TEST_IS_DIR) && !reject) { + folders.push_back(filename); + } + file = dir.read_name(); + } +} + /** * Get, or guess, or decide the location where the preferences.xml -- cgit v1.2.3