Dekko
ContentPickerDialog.qml
1 /* Copyright (C) 2014-2016 Dan Chapman <dpniel@ubuntu.com>
2 
3  This file is part of Dekko email client for Ubuntu Devices/
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License or (at your option) version 3
9 
10  This program 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  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 import QtQuick 2.4
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.0 as Popups
21 import Lomiri.Content 1.3
22 import Dekko.Lomiri.Constants 1.0
23 
24 Popups.PopupBase {
25  id: picker
26  z: 100
27 
28  property bool isExport: true
29 
30  // The url of the file to export, used to determine content type filter of peer picker
31  property string fileUrl
32 
33  property var activeTransfer
34  property var selectedItems
35  property string downloadFilePath
36 
37  signal complete();
38  signal filesImported(var files);
39 
40  Rectangle {
41  anchors.fill: parent
42 
43  ContentTransferHint {
44  anchors.fill: parent
45  activeTransfer: picker.activeTransfer
46  }
47 
48  ContentPeerPicker {
49  id: peerPicker
50  anchors.fill: parent
51  visible: true
52  contentType: isExport ? Content.resolveType(fileUrl) : ContentType.All
53  handler: isExport ? ContentHandler.Destination : ContentHandler.Source
54  onPeerSelected: {
55  peer.selectionType = (isExport ? ContentTransfer.Single : ContentTransfer.Multiple)
56  picker.activeTransfer = peer.request()
57  stateChangeConnection.target = picker.activeTransfer
58  }
59  onCancelPressed: {
60  PopupUtils.close(picker)
61  picker.complete();
62  }
63  }
64  }
65 
66  Connections {
67  id: stateChangeConnection
68  onStateChanged: {
69  if (isExport && picker.activeTransfer.state === ContentTransfer.InProgress) {
70  picker.activeTransfer.items = [transferComponent.createObject(dekko, {"url": fileUrl}) ]
71  picker.activeTransfer.state = ContentTransfer.Charged;
72  closeTimer.start();
73  } else if (!isExport && picker.activeTransfer.state === ContentTransfer.Charged){
74  picker.filesImported(picker.activeTransfer.items);
75  closeTimer.start();
76  }
77  }
78  }
79  Timer {
80  id: closeTimer
81  interval: 1000
82  repeat: false
83  onTriggered: {
84  PopupUtils.close(picker);
85  picker.complete();
86  }
87  }
88  Component {
89  id: transferComponent
90  ContentItem {}
91  }
92 }
Dekko
Definition: Dekko.qml:30
Dekko::Lomiri::Constants::ContentType
Definition: ContentType.qml:23