Debian Codegraph @

src/qml/MediaImportDialog.qml

raw
1 /*
2 * Copyright (C) 2016 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 as published by
6 * the Free Software Foundation; version 3.
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
17 import QtQuick 2.4
18
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.3
21 import Lomiri.Content 1.3
22
23 PopupBase {
24 id: dialogue
25
26 property alias activeTransfer: signalConnections.target
27 signal mediaReceived(string url)
28 signal destruction()
29
30 parent: QuickUtils.rootItem(this)
31 focus: true
32
33 Rectangle {
34 anchors.fill: parent
35
36 ContentTransferHint {
37 anchors.fill: parent
38 activeTransfer: dialogue.activeTransfer
39 }
40
41 ContentPeerPicker {
42 id: peerPicker
43
44 anchors.fill: parent
45 contentType: ContentType.Videos | ContentType.Music
46 handler: ContentHandler.Source
47
48 onPeerSelected: {
49 console.log('onPeerSelected')
50 peer.selectionType = ContentTransfer.Single
51 dialogue.activeTransfer = peer.request()
52 }
53
54 onCancelPressed: {
55 PopupUtils.close(dialogue)
56 }
57 }
58 }
59
60 Connections {
61 id: signalConnections
62
63 onStateChanged: {
64 var done = ((dialogue.activeTransfer.state === ContentTransfer.Charged) ||
65 (dialogue.activeTransfer.state === ContentTransfer.Aborted))
66
67 if (dialogue.activeTransfer.state === ContentTransfer.Charged) {
68 if (dialogue.activeTransfer.items.length > 0) {
69 dialogue.mediaReceived(dialogue.activeTransfer.items[0].url)
70 }
71 }
72
73 if (done) {
74 acceptTimer.restart()
75 }
76 }
77 }
78
79 // WORKAROUND: Work around for application becoming insensitive to touch events
80 // if the dialog is dismissed while the application is inactive.
81 // Just listening for changes to Qt.application.active doesn't appear
82 // to be enough to resolve this, so it seems that something else needs
83 // to be happening first. As such there's a potential for a race
84 // condition here, although as yet no problem has been encountered.
85 Timer {
86 id: acceptTimer
87
88 interval: 100
89 repeat: true
90 running: false
91 onTriggered: {
92 if(Qt.application.state === Qt.ApplicationActive) {
93 PopupUtils.close(dialogue)
94 }
95 }
96 }
97
98 Component.onDestruction: dialogue.destruction()
99 }