summaryrefslogtreecommitdiffstats
path: root/src/io/resource.cpp
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2017-06-15 01:20:41 +0000
committerMartin Owens <doctormo@gmail.com>2017-06-15 01:20:41 +0000
commit2aa30324422f2d53c191d0abc4e4243fd792e898 (patch)
treea912674b1bd059ddac7bfd44ec2e1849eb06176c /src/io/resource.cpp
parentMerge branch 'master' of gitlab.com:marcjeanmougin/inkscape (diff)
downloadinkscape-2aa30324422f2d53c191d0abc4e4243fd792e898.tar.gz
inkscape-2aa30324422f2d53c191d0abc4e4243fd792e898.zip
Use user interface files for the user interface
Diffstat (limited to 'src/io/resource.cpp')
-rw-r--r--src/io/resource.cpp36
1 files changed, 34 insertions, 2 deletions
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 <glib.h> // 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<char> 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<char> 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<char> get_path(Domain domain, Type type, char const *filename)
path = temp;
}
+ return path;
+}
+
+Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename)
+{
+ char *path = _get_path(domain, type, filename);
Util::ptr_shared<char> 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<char> get_filename(Type type, char const *filename)
+{
+ Util::ptr_shared<char> 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;
+}
+
}
}