Debian Codegraph @

src/app/qml/ui/FolderListPage.qml

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Arto Jalkanen <[email protected]>
17 * Niklas Wenzel <[email protected]>
18 */
19 import QtQuick 2.4
20 import Lomiri.Components 1.3
21 import Lomiri.Components.Popups 1.3
22 import Lomiri.FileManager.folderlistmodel 1.0
23
24 import "../components"
25 import "../actions" as FMActions
26 import "../dialogs" as Dialogs
27 import "../backend" as Backend
28 import "../views" as Views
29 import "../tooltips" as Tooltips
30
31 // TODO: Review last position code, which is referenced in FolderListModel (backend), FolderDelegateActions, FolderIconView, FolderListView, FolderListPageDefaultHeader, (PlacesPage)
32
33 SidebarPageLayout {
34 id: folderListPage
35 objectName: "folderListPage"
36
37 property alias folderModel: pageModel
38 property string location: ""
39 property bool fileSelectorMode: false
40 property bool folderSelectorMode: false
41 property string tooltipMsg: ""
42
43 Backend.FolderListModel {
44 id: pageModel
45 primSelItem: ""
46 path: location.length > 0 ? location : places.locationHome
47
48 model.onlyAllowedPaths: !mainView.fullAccessGranted
49 model.onNeedsAuthentication: {
50 console.log("FolderListModel needsAuthentication() signal arrived")
51
52 var props = {
53 currentPath: urlPath,
54 currentUserName: user,
55 savePassword: mainView.sambaSavePassword
56 }
57
58 var popup = PopupUtils.open(Qt.resolvedUrl("../dialogs/NetAuthenticationDialog.qml"), mainView, props)
59
60 popup.savePasswordChanged.connect(function() {
61 mainView.sambaSavePassword = popup.savePassword
62 })
63
64 popup.ok.connect(function() {
65 pageModel.setPathWithAuthentication(popup.currentPath,
66 popup.currentUserName,
67 popup.currentPassword,
68 popup.savePassword)
69 })
70 }
71
72 model.onDownloadTemporaryComplete: {
73 var paths = filename.split("/")
74 var nameOnly = paths[paths.length -1]
75 console.log("onDownloadTemporaryComplete received filename="+filename + "name="+nameOnly)
76 openFromDisk(filename, nameOnly)
77 }
78
79 // Following properties are set from global settings, available in filemanager.qml
80 model.showHiddenFiles: globalSettings.showHidden
81 model.sortOrder: {
82 switch (globalSettings.sortOrder) {
83 case 0: return FolderListModel.SortAscending
84 case 1: return FolderListModel.SortDescending
85 }
86 }
87
88 model.sortBy: {
89 switch (globalSettings.sortBy) {
90 case 0: return FolderListModel.SortByName
91 case 1: return FolderListModel.SortByDate
92 case 2: return FolderListModel.SortBySize
93 }
94 }
95
96 onPathChanged: pageModel.model.selectionObject.clear()
97 }
98
99 sidebarWidth: globalSettings.sidebarWidth
100
101 Binding {
102 when: !sidebarResizing
103 target: globalSettings
104 property: "sidebarWidth"
105 value: folderListPage.sidebarWidth
106 }
107
108 sidebarActive: mainView.wideAspect
109 sidebarLoader.sourceComponent: PlacesPage {
110 anchors.fill: parent
111 folderModel: pageModel
112 }
113
114 mainLoader.sourceComponent: Page {
115 id: folderPage
116
117 readonly property bool narrowAspect: width <= units.gu(50)
118 readonly property var selectionManager: pageModel.model.selectionObject
119
120 header: FolderListPageDefaultHeader {
121 id: defaultHeader
122 fileOperationDialog: fileOperationDialogObj
123 folderPage: folderListPage
124 folderModel: pageModel
125 narrowAspect: folderPage.narrowAspect
126 selectionMode: folderPage.selectionMode
127 contentHubMode: mainView.isContentHub
128 importMode: mainView.importMode
129
130 leadingActions: {
131 if (selectionMode && !isContentHub) {
132 return actionsCollection.selectionLeadingActions
133 }
134
135 return actionsCollection.defaultLeadingActions
136 }
137
138 trailingActions: {
139 if (selectionMode) {
140 if (isContentHub) {
141 return actionsCollection.pickerModeTrailingActions
142 } else {
143 return actionsCollection.selectionTrailingActions
144 }
145 }
146
147 return actionsCollection.defaultTrailingActions
148 }
149
150 secondaryTrailingActions: actionsCollection.defaultHeaderSecondaryTrailingActions
151 extensionLeadingActions: actionsCollection.extensionLeadingActions
152 extensionTrailingActions: actionsCollection.extensionTrailingActions
153 }
154
155 // FIXME: Clearing selection (by cancel btn in the header, or changing the folder, should exit selection mode)
156 readonly property bool selectionMode: fileSelectorMode || folderSelectorMode
157
158 ActionsCollection {
159 id: actionsCollection
160
161 fileOperationDialog: fileOperationDialogObj
162 folderPage: folderListPage
163 folderModel: pageModel
164 selectionMode: folderPage.selectionMode
165 contentHubMode: mainView.isContentHub
166 importMode: mainView.importMode
167 narrowAspect: folderPage.narrowAspect
168 searchBarIsShown: defaultHeader.showSearchBar
169 openDefault: globalSettings.openDefault
170
171 onEnterSearch: defaultHeader.enterSearch()
172 }
173
174 Loader {
175 id: viewLoader
176 anchors.fill: parent
177 anchors.topMargin: folderPage.header.height
178 anchors.bottomMargin: bottomPanelStack.height
179
180
181 sourceComponent: {
182 if (globalSettings.viewMethod === 1) { // Grid
183 return folderIconView
184 } else {
185 return folderListView
186 }
187 }
188 }
189
190 BottomPanelStack {
191 id: bottomPanelStack
192
193 anchors {
194 left: parent.left
195 right: parent.right
196 bottom: parent.bottom
197 }
198
199 Tooltips.BottomTooltip {
200 id: bottomTooltip
201 message: tooltipMsg
202 visible: false
203 onMessageChanged: {
204 visible = true && tooltipMsg != ""
205 tooltipTimer.restart()
206 }
207 }
208 }
209
210 Rectangle {
211 anchors { bottom: bottomPanelStack.top; left: parent.left; right: parent.right; }
212 height: units.dp(1)
213 color: theme.palette.normal.base
214 visible: viewLoader.item.flickableItem.contentHeight > viewLoader.item.flickableItem.height
215 }
216
217 // *** VIEW COMPONENTS ***
218
219 Component {
220 id: folderIconView
221 Views.FolderIconView {
222 anchors.fill: parent
223 folderModel: pageModel
224 folderListPage: folderPage
225 fileOperationDialog: fileOperationDialogObj
226 openDefault: globalSettings.openDefault
227 header: pageModel.count > 0 && !folderModel.model.isCurAllowedPath && folderModel.model.onlyAllowedPaths
228 ? authReqHeader
229 : null
230 }
231 }
232
233 Component {
234 id: folderListView
235 Views.FolderListView {
236 anchors.fill: parent
237 folderModel: pageModel
238 folderListPage: folderPage
239 fileOperationDialog: fileOperationDialogObj
240 openDefault: globalSettings.openDefault
241 header: pageModel.count > 0 && !folderModel.model.isCurAllowedPath && folderModel.model.onlyAllowedPaths
242 ? authReqHeader
243 : null
244 }
245 }
246
247 FMActions.UnlockFullAccess {
248 id: authAction
249 onTriggered: {
250 console.log("Full access clicked")
251 authentication.authenticate()
252
253 authentication.authenticationSucceeded.connect(function() {
254 console.log("Authentication for full access succeeded!")
255 mainView.fullAccessGranted = true
256 })
257 }
258 }
259
260 Component {
261 id: authReqHeader
262 ListItem {
263 anchors { left: parent ? parent.left : undefined; right: parent ? parent.right : undefined }
264 divider.visible: false
265 height: layout.height
266 ListItemLayout {
267 id: layout
268 title.text: i18n.tr("Restricted access")
269 title.maximumLineCount: 2
270 title.wrapMode: Text.WordWrap
271
272 subtitle.text: i18n.tr("Authentication is required in order to see all the content of this folder.")
273 subtitle.maximumLineCount: Math.MAX_VALUE
274 subtitle.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
275 Button {
276 SlotsLayout.position: SlotsLayout.Last
277 color: theme.palette.normal.positive
278 action: authAction
279 }
280 }
281 }
282 }
283
284 Loader {
285 id: emptyStateLoader
286 anchors.fill: parent
287 active: !folderModel.busy
288 sourceComponent: {
289 if (folderModel.count == 0 && !folderModel.model.isCurAllowedPath && folderModel.model.onlyAllowedPaths)
290 return authEmptyState
291
292 if (folderModel.count == 0)
293 return noFilesEmptyState
294 }
295
296 ActivityIndicator {
297 anchors.centerIn: parent
298 running: folderModel.busy
299 }
300 }
301
302 Component {
303 id: noFilesEmptyState
304
305 Item {
306 anchors.fill: parent
307 EmptyState {
308 anchors.centerIn: parent
309 iconName: "document-open"
310 title: i18n.tr("No files")
311 subTitle: i18n.tr("This folder is empty.")
312 }
313 }
314 }
315
316 Component {
317 id: authEmptyState
318
319 Item {
320 anchors.fill: parent
•321 EmptyState {
322 anchors.centerIn: parent
323 iconName: "lock"
324 title: i18n.tr("Restricted access")
325 subTitle: i18n.tr("Authentication is required in order to see the content of this folder.")
326
327 controlComponent: Button {
328 width: units.gu(24)
329 action: authAction
330 }
331 }
332 }
333 }
334
335 // Errors from model
336 Connections {
337 target: pageModel.model
338 function onError(errorTitle, errorMessage) {
339 console.log("FolderListModel Error Title/Description", errorTitle, errorMessage)
340 error(i18n.tr("File operation error"), errorTitle + ": " + errorMessage)
341 }
342 }
343
344 Dialogs.FileOperationProgressDialog {
345 id: fileOperationDialogObj
346
347 page: folderPage
348 model: pageModel.model
349 }
350
351 function openFromDisk(fullpathname, name, share) {
352 console.log("openFromDisk():"+ fullpathname)
353 // Check if file is an archive. If yes, ask the user whether he wants to extract it
354 var archiveType = pageModel.getArchiveType(name)
355 if (archiveType === "") {
356 openLocalFile(fullpathname, share)
357 } else {
358 var props = {
359 "filePath" : fullpathname,
360 "fileName" : name,
361 "archiveType" : archiveType,
362 "folderListPage" : folderPage,
363 "folderModel": pageModel
364 }
365 PopupUtils.open(Qt.resolvedUrl("../dialogs/OpenArchiveDialog.qml"), mainView, props)
366 }
367
368 }
369
370 //High Level openFile() function
371 //remote files are saved as temporary files and then opened
372 // TODO: This is deprecated. Should be removed, with all the actions that actually uses it.
373 function openFile(model, share) {
374 if (model.isRemote) {
375 //download and open later when the signal downloadTemporaryComplete() arrives
376 pageModel.model.downloadAsTemporaryFile(model.index)
377 }
378 else {
379 openFromDisk(model.filePath, model.fileName, share)
380 }
381 }
382
383 Component.onCompleted: {
384 forceActiveFocus()
385 }
386
387 Timer {
388 id: tooltipTimer
389 repeat: true
390 interval: 2000
391 onTriggered: {
392 bottomTooltip.visible = false
393 }
394 }
395
396 MouseArea {
397 anchors.fill: parent
398 acceptedButtons: Qt.ForwardButton | Qt.BackButton
399
400 onClicked: {
401 if (mouse.button == Qt.BackButton) {
402 actionsCollection.goBackAction.trigger()
403 } else if (mouse.button == Qt.ForwardButton) {
404 actionsCollection.goForwardAction.trigger()
405 }
406 }
407 }
408 }
409 }