summaryrefslogtreecommitdiffstats
path: root/src/io/resource.cpp
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-06-24 17:50:36 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-06-24 17:50:36 +0000
commitd71265c629a103d8c821fe85ccf71bd9c93baf47 (patch)
treec01fe4543cd48f64a8ca4b60e01e1bb5040922d9 /src/io/resource.cpp
parentWorking with powerclip and powermask (diff)
parentMerge branch 'ui-files-for-ui-xml' (diff)
downloadinkscape-d71265c629a103d8c821fe85ccf71bd9c93baf47.tar.gz
inkscape-d71265c629a103d8c821fe85ccf71bd9c93baf47.zip
Updating to master
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;
+}
+
}
}