[ui] add string <--> file representation convertors

* convenient methods to conform strings to Qt file reprensentation using the "file:/" protocol prefix
* use those methodes when manipulating files
This commit is contained in:
Yann Lanthony 2018-02-26 16:59:25 +01:00
parent 62726b4663
commit 2cdc83f06f
7 changed files with 38 additions and 6 deletions

View file

@ -22,3 +22,29 @@ function extension(path) {
function isFile(path) {
return extension(path) !== ""
}
/// Conform 'path' to the Qt file representation relying on "file:" protocol prefix
function stringToFile(path) {
// already containing the file protocol
if(path.startsWith("file:"))
return path
// network path
if(path.startsWith("//"))
return "file:" + path
// assumed local path
if(path.trim() == "")
return ""
return "file:/" + path
}
/// Remove any "file:" protocol prefix from 'path'
function fileToString(path)
{
// local path
if(path.startsWith("file:///"))
return path.replace("file:///", "")
// network path
else if(path.startsWith("file://"))
return path.replace("file://", "")
return path
}