2 // Go to root using the optional operationType parameter
3 // @param operationType PageStackAction.Immediate or Animated, Animated is default)
4 function goToRoot(operationType
)
6 if (operationType
!== PageStackAction
.Immediate
&&
7 operationType
!== PageStackAction
.Animated
)
8 operationType
= PageStackAction
.Animated
;
10 // find the first page
11 var firstPage
= pageStack
.previousPage();
14 while (pageStack
.previousPage(firstPage
)) {
15 firstPage
= pageStack
.previousPage(firstPage
);
18 var start
= engine
.startDepth();
19 for (var up
= 0; up
< start
; up
++) {
20 firstPage
= pageStack
.nextPage(firstPage
);
24 pageStack
.pop(firstPage
, operationType
);
29 // find the first page
30 var firstPage
= pageStack
.previousPage();
33 while (pageStack
.previousPage(firstPage
)) {
34 firstPage
= pageStack
.previousPage(firstPage
);
37 var start
= engine
.startDepth() - 1;
38 for (var up
= 0; up
< start
; up
++) {
39 firstPage
= pageStack
.nextPage(firstPage
);
43 pageStack
.pop(firstPage
, PageStackAction
.Animated
);
46 function fileSelect(fullPath
)
48 // set the selected file
49 engine
.setSelectedFilename(fullPath
);
51 // find the first page
52 var firstPage
= pageStack
.previousPage();
55 while (pageStack
.previousPage(firstPage
)) {
56 firstPage
= pageStack
.previousPage(firstPage
);
59 var start
= engine
.startDepth() - 1;
60 for (var up
= 0; up
< start
; up
++) {
61 firstPage
= pageStack
.nextPage(firstPage
);
65 pageStack
.pop(firstPage
, PageStackAction
.Animated
);
68 // returns true if string s1 starts with string s2
69 function startsWith(s1
, s2
)
74 var start
= s1
.substring(0, s2
.length
);
78 function goToFolder(folder
)
80 // first, go to root so that the page stack has only one page
81 goToRoot(PageStackAction
.Immediate
);
83 // open the folders one by one
84 var dirs
= folder
.split("/");
86 for (var i
= 1; i
< dirs
.length
; ++i
) {
88 // animate the last push
89 var action
= (i
< dirs
.length
-1) ? PageStackAction
.Immediate
: PageStackAction
.Animated
;
90 pageStack
.push(Qt
.resolvedUrl("DirectoryPage.qml"), { dir
: path
}, action
);
94 // Goes to Home folder
97 goToFolder(engine
.homeFolder());
100 function goToInitial(folder
, filter
)
102 engine
.extensionFilter
= filter
;
104 // open the folders one by one
105 var dirs
= folder
.split("/");
107 for (var i
= 0; i
< dirs
.length
; ++i
) {
109 // animate the last push
110 var action
= (i
< dirs
.length
-1) ? PageStackAction
.Immediate
: PageStackAction
.Animated
;
111 pageStack
.push(Qt
.resolvedUrl("DirectoryPage.qml"), { dir
: path
}, action
);
115 function sdcardPath()
117 return "/run/user/100000/media/sdcard";
120 function androidSdcardPath()
122 return "/data/sdcard";
125 function formatPathForTitle(path
)
128 return "File Browser: /";
130 var i
= path
.lastIndexOf("/");
134 return path
.substring(i
+1)+"/";
137 // returns the text after the last / in a path
138 function lastPartOfPath(path
)
143 var i
= path
.lastIndexOf("/");
147 return path
.substring(i
+1);
150 function formatPathForSearch(path
)
155 var i
= path
.lastIndexOf("/");
159 return path
.substring(i
+1);
162 function unicodeArrow()
164 return "\u2192"; // unicode for arrow symbol
167 function unicodeBlackDownPointingTriangle()
169 return "\u25bc"; // unicode for down pointing triangle symbol
172 function folderFromFile(path
)
174 if ((path
=== "Select") || (path
=== ""))
175 path
= engine
.homeFolder() + "/.";
177 var i
= path
.lastIndexOf("/");
178 if ((i
< 0) || (i
>= (path
.length
- 1)))
181 return path
.substring(0, i
);