diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/uri.cpp | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/uri.cpp')
| -rw-r--r-- | src/uri.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/uri.cpp b/src/uri.cpp index de6a454ec..2eaf4ecc1 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -10,10 +10,17 @@ #include <glib.h> #include "uri.h" +#include <string> #include <glibmm/ustring.h> +#include <glibmm/miscutils.h> namespace Inkscape { +URI::URI() { + const gchar *in = ""; + _impl = Impl::create(xmlParseURI(in)); +} + URI::URI(const URI &uri) { uri._impl->reference(); _impl = uri._impl; @@ -133,6 +140,31 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException) filename = tmp.toNativeFilename(); return filename; } +/* + * Returns the absolute path to an existing file referenced in this URI, + * if the uri is data, the path is empty or the file doesn't exist, then + * an empty string is returned. + * + * Does not check if the returned path is the local document's path (local) + * and thus redundent. Caller is expected to check against the document's path. + */ +const std::string URI::getFullPath(std::string const base) const { + if (!_impl->getPath()) { + return ""; + } + std::string path = std::string(_impl->getPath()); + // Calculate the absolute path from an available base + if(!base.empty() && !path.empty() && path[0] != '/') { + path = Glib::build_filename(base, path); + } + // Check the existance of the file + if(! g_file_test(path.c_str(), G_FILE_TEST_EXISTS) + || g_file_test(path.c_str(), G_FILE_TEST_IS_DIR) ) { + path.clear(); + } + return path; +} + /* TODO !!! proper error handling */ gchar *URI::toNativeFilename() const throw(BadURIException) { |
