Debian Codegraph @

qml/Components/PageHubImport.qml

raw
1 /*
2 * This file is part of the 2FA Manager App for Ubuntu Touch
3 * Copyright (C) 2019 Joan CiberSheep
4 *
5 * This App is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 *
10 * This App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 import QtQuick 2.9
21 import Lomiri.Components 1.3
22 import Lomiri.Content 1.3
23
24 Page {
25 id: importPage
26 objectName: "importHubPage"
27
28 property var activeTransfer
29 property bool allowMultipleFiles
30
31 signal accept(var files)
32 signal close()
33
34 header: HeaderBase {
35 title: i18n.tr("Import backup file from")
36
37 leadingActionBar.actions: Action {
38 iconName: "back"
39 text: i18n.tr("Back")
40
41 onTriggered: close();
42 }
43 }
44
45 Rectangle {
46 anchors.fill: parent
47 anchors.topMargin: importPage.header.height
48
49 ContentTransferHint {
50 anchors.fill: parent
51 activeTransfer: importPage.activeTransfer
52 }
53
54 ContentPeerPicker {
55 visible: importPage.visible
56 showTitle: false
57 contentType: ContentType.Documents
58 handler: ContentHandler.Source
59
60 onPeerSelected: {
61 peer.selectionType = importPage.allowMultipleFiles
62 ? ContentTransfer.Multiple
63 : ContentTransfer.Single;
64
65 importPage.activeTransfer = peer.request();
66 stateChangeConnection.target = importPage.activeTransfer;
67 }
68
69 onCancelPressed: {
70 close();
71 }
72 }
73 }
74
75 Connections {
76 id: stateChangeConnection
77 target: null
78
79 onStateChanged: {
80 var statesForDebug = ["Created","Initiated","InProgress","Charged","Collected","Aborted","Finalized","Downloading","Downloaded"]
81 console.log("DEBUG: activeTrasfer State is", statesForDebug[activeTransfer.state])
82
83 switch (activeTransfer.state) {
84 case ContentTransfer.Aborted:
85 console.log("Aborted")
86 break;
87 case ContentTransfer.Collected:
88 console.log("Finalize and close")
89 activeTransfer.finalize();
90 close();
91 break;
92 case ContentTransfer.Finalized:
93 console.log("Finalized")
94 break;
95 case ContentTransfer.InProgress:
96 console.log("InProgress")
97 break;
98 case ContentTransfer.Charged:
99 var selectedItems = []
100
101 for (var i in importPage.activeTransfer.items) {
102 //console.log("Move imported items",importPage.activeTransfer.items[i].move(backupPage.cachePath))
103 selectedItems.push(
104 String(importPage.activeTransfer.items[i].url) //Don't remove .replace("file://", "")
105 );
106 console.log("Charged. Items:",selectedItems[i])
107 }
108
109 accept(selectedItems);
110 break;
111 default:
112 console.log("Other state?",activeTransfer.state)
113 }
114 }
115 }
116 }