| 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 avatarReceived(string avatarUrl) |
| 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.Pictures |
| 46 |
handler: ContentHandler.Source |
| 47 |
|
| 48 |
onPeerSelected: { |
| 49 |
peer.selectionType = ContentTransfer.Single |
| 50 |
dialogue.activeTransfer = peer.request() |
| 51 |
} |
| 52 |
|
| 53 |
onCancelPressed: { |
| 54 |
PopupUtils.close(dialogue) |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
Connections { |
| 60 |
id: signalConnections |
| 61 |
|
| 62 |
function onStateChanged() { |
| 63 |
var done = ((dialogue.activeTransfer.state === ContentTransfer.Charged) || |
| 64 |
(dialogue.activeTransfer.state === ContentTransfer.Aborted)) |
| 65 |
|
| 66 |
if (dialogue.activeTransfer.state === ContentTransfer.Charged) { |
| 67 |
if (dialogue.activeTransfer.items.length > 0) { |
| 68 |
dialogue.avatarReceived(dialogue.activeTransfer.items[0].url) |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
if (done) { |
| 73 |
acceptTimer.restart() |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// WORKAROUND: Work around for application becoming insensitive to touch events |
| 79 |
// if the dialog is dismissed while the application is inactive. |
| 80 |
// Just listening for changes to Qt.application.active doesn't appear |
| 81 |
// to be enough to resolve this, so it seems that something else needs |
| 82 |
// to be happening first. As such there's a potential for a race |
| 83 |
// condition here, although as yet no problem has been encountered. |
| 84 |
Timer { |
| 85 |
id: acceptTimer |
| 86 |
|
| 87 |
interval: 100 |
| 88 |
repeat: true |
| 89 |
running: false |
| 90 |
onTriggered: { |
| 91 |
if(Qt.application.state === Qt.ApplicationActive) { |
| 92 |
PopupUtils.close(dialogue) |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
Component.onDestruction: dialogue.destruction() |
| 98 |
} |