From 2aa30324422f2d53c191d0abc4e4243fd792e898 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 14 Jun 2017 21:20:41 -0400 Subject: Use user interface files for the user interface --- src/io/resource.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/io/resource.cpp') diff --git a/src/io/resource.cpp b/src/io/resource.cpp index 501eab03b..52ac884b1 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -19,15 +19,18 @@ #include // g_assert() #include "path-prefix.h" #include "inkscape.h" +#include "io/sys.h" #include "io/resource.h" +using Inkscape::IO::file_test; + namespace Inkscape { namespace IO { namespace Resource { -Util::ptr_shared get_path(Domain domain, Type type, char const *filename) +gchar *_get_path(Domain domain, Type type, char const *filename) { gchar *path=NULL; switch (domain) { @@ -71,7 +74,8 @@ Util::ptr_shared get_path(Domain domain, Type type, char const *filename) case PALETTES: name = "palettes"; break; case PATTERNS: name = "patterns"; break; case TEMPLATES: name = "templates"; break; - default: return get_path(SYSTEM, type, filename); + case UI: name = "ui"; break; + default: return _get_path(SYSTEM, type, filename); } path = Inkscape::Application::profile_path(name); } break; @@ -83,11 +87,39 @@ Util::ptr_shared get_path(Domain domain, Type type, char const *filename) path = temp; } + return path; +} + +Util::ptr_shared get_path(Domain domain, Type type, char const *filename) +{ + char *path = _get_path(domain, type, filename); Util::ptr_shared result=Util::share_string(path); g_free(path); return result; } +/* + * Same as get_path, but checks for file's existance and falls back + * from USER to SYSTEM modes. + */ +Util::ptr_shared get_filename(Type type, char const *filename) +{ + Util::ptr_shared result; + char *user_filename = _get_path(USER, type, filename); + char *sys_filename = _get_path(SYSTEM, type, filename); + + if (file_test(user_filename, G_FILE_TEST_EXISTS)) { + result = Util::share_string(user_filename); + } else if(file_test(sys_filename, G_FILE_TEST_EXISTS)) { + result = Util::share_string(sys_filename); + } else { + g_warning("Failed to load resource: %s", filename); + } + g_free(user_filename); + g_free(sys_filename); + return result; +} + } } -- cgit v1.2.3