diff options
author | Ken Moore <moorekou@gmail.com> | 2015-08-31 13:02:21 -0400 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2015-08-31 13:02:21 -0400 |
commit | 9fc9e5cf70adf1b2fd89752f3750c511fa7730df (patch) | |
tree | 988b4045a4140113bfdc58d3a97e88ce6714b8ee /libLumina | |
parent | Fix an issues with possible seg-faults when saving a *.desktop structure to f... (diff) | |
download | lumina-9fc9e5cf70adf1b2fd89752f3750c511fa7730df.tar.gz lumina-9fc9e5cf70adf1b2fd89752f3750c511fa7730df.tar.bz2 lumina-9fc9e5cf70adf1b2fd89752f3750c511fa7730df.zip |
Add a new "PathToAbsolute()" function to LuminaUtils for converting a possible relative path to an absolute path (for input path validation/checking).
Diffstat (limited to 'libLumina')
-rw-r--r-- | libLumina/LuminaUtils.cpp | 12 | ||||
-rw-r--r-- | libLumina/LuminaUtils.h | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index 63875172..ba3a8ef8 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -121,6 +121,18 @@ QStringList LUtils::listSubDirectories(QString dir, bool recursive){ return out; } +QString LUtils::PathToAbsolute(QString path){ + //Convert an input path to an absolute path (this does not check existance ot anything) + if(path.startsWith("/")){ return path; } //already an absolute path + if(path.startsWith("~")){ path = path.remove(1); path.prepend(QDir::homePath()); } + if(!path.startsWith("/")){ + //Must be a relative path + if(path.startsWith("./")){ path = path.remove(2); } + path.prepend( QDir::currentPath()+"/"); + } + return path; +} + QStringList LUtils::imageExtensions(){ //Note that all the image extensions are lowercase!! static QStringList imgExtensions; diff --git a/libLumina/LuminaUtils.h b/libLumina/LuminaUtils.h index b479e3ec..06552d1f 100644 --- a/libLumina/LuminaUtils.h +++ b/libLumina/LuminaUtils.h @@ -45,6 +45,9 @@ public: //List all the sub-directories of a parent dir (recursive) static QStringList listSubDirectories(QString dir, bool recursive = true); + //Convert an input file/dir path to an absolute file path + static QString PathToAbsolute(QString path); + //Get the list of all file extensions which Qt can read (lowercase) static QStringList imageExtensions(); |