X-Git-Url: https://www.flypig.org.uk/git/?p=openvpnui.git;a=blobdiff_plain;f=qml%2Ffilebrowse%2Fpages%2Ffunctions.js;fp=qml%2Ffilebrowse%2Fpages%2Ffunctions.js;h=932ef7c91cd3a791b5f73bd2880403d32d4b426a;hp=0000000000000000000000000000000000000000;hb=e24363e314aca32e7bee952f02f517a04a8dc5f2;hpb=ee3968ffa08d4e0fcbad87765efa3aeb32ff0554 diff --git a/qml/filebrowse/pages/functions.js b/qml/filebrowse/pages/functions.js new file mode 100644 index 0000000..932ef7c --- /dev/null +++ b/qml/filebrowse/pages/functions.js @@ -0,0 +1,182 @@ + +// Go to root using the optional operationType parameter +// @param operationType PageStackAction.Immediate or Animated, Animated is default) +function goToRoot(operationType) +{ + if (operationType !== PageStackAction.Immediate && + operationType !== PageStackAction.Animated) + operationType = PageStackAction.Animated; + + // find the first page + var firstPage = pageStack.previousPage(); + if (!firstPage) + return; + while (pageStack.previousPage(firstPage)) { + firstPage = pageStack.previousPage(firstPage); + } + + var start = engine.startDepth(); + for (var up = 0; up < start; up++) { + firstPage = pageStack.nextPage(firstPage); + } + + // pop to first page + pageStack.pop(firstPage, operationType); +} + +function cancel() +{ + // find the first page + var firstPage = pageStack.previousPage(); + if (!firstPage) + return; + while (pageStack.previousPage(firstPage)) { + firstPage = pageStack.previousPage(firstPage); + } + + var start = engine.startDepth() - 1; + for (var up = 0; up < start; up++) { + firstPage = pageStack.nextPage(firstPage); + } + + // pop to first page + pageStack.pop(firstPage, PageStackAction.Animated); +} + +function fileSelect(fullPath) +{ + // set the selected file + engine.setSelectedFilename(fullPath); + + // find the first page + var firstPage = pageStack.previousPage(); + if (!firstPage) + return; + while (pageStack.previousPage(firstPage)) { + firstPage = pageStack.previousPage(firstPage); + } + + var start = engine.startDepth() - 1; + for (var up = 0; up < start; up++) { + firstPage = pageStack.nextPage(firstPage); + } + + // pop to first page + pageStack.pop(firstPage, PageStackAction.Animated); +} + +// returns true if string s1 starts with string s2 +function startsWith(s1, s2) +{ + if (!s1 || !s2) + return false; + + var start = s1.substring(0, s2.length); + return start === s2; +} + +function goToFolder(folder) +{ + // first, go to root so that the page stack has only one page + goToRoot(PageStackAction.Immediate); + + // open the folders one by one + var dirs = folder.split("/"); + var path = ""; + for (var i = 1; i < dirs.length; ++i) { + path += "/"+dirs[i]; + // animate the last push + var action = (i < dirs.length-1) ? PageStackAction.Immediate : PageStackAction.Animated; + pageStack.push(Qt.resolvedUrl("DirectoryPage.qml"), { dir: path }, action); + } +} + +// Goes to Home folder +function goToHome() +{ + goToFolder(engine.homeFolder()); +} + +function goToInitial(folder, filter) +{ + engine.extensionFilter = filter; + + // open the folders one by one + var dirs = folder.split("/"); + var path = ""; + for (var i = 0; i < dirs.length; ++i) { + path += "/"+dirs[i]; + // animate the last push + var action = (i < dirs.length-1) ? PageStackAction.Immediate : PageStackAction.Animated; + pageStack.push(Qt.resolvedUrl("DirectoryPage.qml"), { dir: path }, action); + } +} + +function sdcardPath() +{ + return "/run/user/100000/media/sdcard"; +} + +function androidSdcardPath() +{ + return "/data/sdcard"; +} + +function formatPathForTitle(path) +{ + if (path === "/") + return "File Browser: /"; + + var i = path.lastIndexOf("/"); + if (i < -1) + return path; + + return path.substring(i+1)+"/"; +} + +// returns the text after the last / in a path +function lastPartOfPath(path) +{ + if (path === "/") + return ""; + + var i = path.lastIndexOf("/"); + if (i < -1) + return path; + + return path.substring(i+1); +} + +function formatPathForSearch(path) +{ + if (path === "/") + return "root"; + + var i = path.lastIndexOf("/"); + if (i < -1) + return path; + + return path.substring(i+1); +} + +function unicodeArrow() +{ + return "\u2192"; // unicode for arrow symbol +} + +function unicodeBlackDownPointingTriangle() +{ + return "\u25bc"; // unicode for down pointing triangle symbol +} + +function folderFromFile(path) +{ + if ((path === "Select") || (path === "")) + path = engine.homeFolder() + "/."; + + var i = path.lastIndexOf("/"); + if ((i < 0) || (i >= (path.length - 1))) + return path; + + return path.substring(0, i); +}