Debian Codegraph @

src/app/qml/content-hub/FileOpener.qml

raw
1 /*
2 * Copyright (C) 2014 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 */
18 import QtQuick 2.4
19 import Lomiri.Components 1.3
20
21 import Lomiri.Content 1.3
22
23 import "contenttyperesolver.js" as Resolver
24
25 Page {
26 id: root
27 title: i18n.tr("Open with")
28
29 property var activeTransfer
30
31 property string fileUrl
32 property bool share: false
33
34 Component.onCompleted: {
35 var contentType = Resolver.resolveContentType(fileUrl)
36 console.log("Resolved contenttype: " + contentType)
37 peerPicker.contentType = contentType
38 }
39
40 Component {
41 id: resultComponent
42 ContentItem {}
43 }
44
45 function __exportItemsWhenPossible(url) {
46 if (root.activeTransfer.state === ContentTransfer.InProgress)
47 {
48 root.activeTransfer.items = [ resultComponent.createObject(root, {"url": url}) ];
49 root.activeTransfer.state = ContentTransfer.Charged;
50 }
51 }
52 ContentPeerPicker {
53 id: peerPicker
54 showTitle: false
55
56 // Type of handler: Source, Destination, or Share
57 handler: root.share ? ContentHandler.Share : ContentHandler.Destination
58 contentType: ContentType.Pictures
59
60 onPeerSelected: {
61 root.activeTransfer = peer.request();
62 pageStack.pop();
63 __exportItemsWhenPossible(root.fileUrl)
64 }
65
66 onCancelPressed: {
67 pageStack.pop();
68 }
69 }
70
71 Connections {
72 target: root.activeTransfer
73 onStateChanged: {
74 console.log("curTransfer StateChanged: " + root.activeTransfer.state);
75 __exportItemsWhenPossible(root.fileUrl)
76 }
77 }
78 }