diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-07-01 23:31:49 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-07-01 23:31:49 +0000 |
| commit | 03bb87a0175289274132a0240628936fbccf6ca5 (patch) | |
| tree | 979519e873c0ceff7a6a8b0f53252a4a5ece1143 /src/io/resource.cpp | |
| parent | Improving CR feedback. thanks! (diff) | |
| parent | When running without installing, extensions will spawn correct Inkscape (diff) | |
| download | inkscape-03bb87a0175289274132a0240628936fbccf6ca5.tar.gz inkscape-03bb87a0175289274132a0240628936fbccf6ca5.zip | |
Merge https://gitlab.com/inkscape/inkscape into selectable-knots
Diffstat (limited to 'src/io/resource.cpp')
| -rw-r--r-- | src/io/resource.cpp | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/src/io/resource.cpp b/src/io/resource.cpp index 73dc7117e..6a388c1ac 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -20,6 +20,10 @@ #include "config.h" #endif +#include <glibmm/miscutils.h> +#include <glibmm/stringutils.h> +#include <glibmm/fileutils.h> + #include "path-prefix.h" #include "io/sys.h" #include "io/resource.h" @@ -57,7 +61,7 @@ gchar *_get_path(Domain domain, Type type, char const *filename) case THEMES: temp = INKSCAPE_THEMEDIR; break; case TUTORIALS: temp = INKSCAPE_TUTORIALSDIR; break; case UIS: temp = INKSCAPE_UIDIR; break; - default: g_assert_not_reached(); + default: temp = ""; } path = g_strdup(temp); } break; @@ -67,7 +71,7 @@ gchar *_get_path(Domain domain, Type type, char const *filename) case GRADIENTS: temp = CREATE_GRADIENTSDIR; break; case PALETTES: temp = CREATE_PALETTESDIR; break; case PATTERNS: temp = CREATE_PATTERNSDIR; break; - default: g_assert_not_reached(); + default: temp = ""; } path = g_strdup(temp); } break; @@ -96,7 +100,7 @@ gchar *_get_path(Domain domain, Type type, char const *filename) } break; } - if (filename) { + if (filename && path) { gchar *temp=g_build_filename(path, filename, NULL); g_free(path); path = temp; @@ -173,6 +177,63 @@ Glib::ustring get_filename(Type type, char const *filename, char const *locale) return result; } +/* + * Get's all the files in a given type, for all domain types. + * + * domain - Optional domain (overload), will check return domains if not. + * type - The type of files, e.g. TEMPLATES + * extentions - A list of extensions to return, e.g. xml, svg + * exclusions - A list of names to exclude e.g. default.xml + */ +std::vector<Glib::ustring> get_filenames(Type type, std::vector<const char *> extensions, std::vector<const char *> exclusions) +{ + std::vector<Glib::ustring> ret; + get_filenames_from_path(ret, get_path_ustring(USER, type), extensions, exclusions); + get_filenames_from_path(ret, get_path_ustring(SYSTEM, type), extensions, exclusions); + get_filenames_from_path(ret, get_path_ustring(CREATE, type), extensions, exclusions); + return ret; +} +std::vector<Glib::ustring> get_filenames(Domain domain, Type type, std::vector<const char *> extensions, std::vector<const char *> exclusions) +{ + std::vector<Glib::ustring> ret; + get_filenames_from_path(ret, get_path_ustring(domain, type), extensions, exclusions); + return ret; +} + +/* + * Get all the files from a specific path, populating &files vector + * + * &files - Output list to populate + * path - The directory to parse, will add nothing if directory doesn't exist + * extensions - Only add files with these extensions. + * exclusions - Exclude files that exactly match these names. + */ +void get_filenames_from_path(std::vector<Glib::ustring> &files, Glib::ustring path, std::vector<const char *> extensions, std::vector<const char *> 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()){ + bool reject = false; + for (auto &ext: extensions) { + reject |= !Glib::str_has_suffix(file, ext); + } + for (auto &exc: exclusions) { + reject |= Glib::str_has_prefix(file, exc); + } + Glib::ustring filename = Glib::build_filename(path, file); + reject |= !Glib::file_test(filename, Glib::FILE_TEST_IS_REGULAR); + if(!reject) { + files.push_back(filename); + } + file = dir.read_name(); + } +} + + /** * Get, or guess, or decide the location where the preferences.xml * file should be located. This also indicates where all other inkscape |
