~renatofilho/messaging-app/fix-1417341-rtm

« back to all changes in this revision

Viewing changes to src/qml/PictureImport.qml

  • Committer: CI bot
  • Author(s): Bill Filler
  • Date: 2014-08-22 17:44:09 UTC
  • mfrom: (192.2.1 messaging-app)
  • Revision ID: ps-jenkins@lists.canonical.com-20140822174409-14v77jr1ctvzqzzq
sim presence and call grouping merge from trunk 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012-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 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.2
 
18
import Ubuntu.Components 1.1
 
19
import Ubuntu.Components.Popups 1.0 as Popups
 
20
import Ubuntu.Content 0.1 as ContentHub
 
21
 
 
22
Item {
 
23
    id: root
 
24
 
 
25
    property var importDialog: null
 
26
 
 
27
    signal pictureReceived(string pictureUrl)
 
28
 
 
29
    function requestNewPicture()
 
30
    {
 
31
        if (!root.importDialog) {
 
32
            root.importDialog = PopupUtils.open(contentHubDialog, root)
 
33
        } else {
 
34
            console.warn("Import dialog already running")
 
35
        }
 
36
    }
 
37
 
 
38
    Component {
 
39
        id: contentHubDialog
 
40
 
 
41
        Popups.PopupBase {
 
42
            id: dialogue
 
43
 
 
44
            property alias activeTransfer: signalConnections.target
 
45
 
 
46
 
 
47
            focus: true
 
48
 
 
49
            Rectangle {
 
50
                anchors.fill: parent
 
51
 
 
52
                ContentHub.ContentPeerPicker {
 
53
                    id: peerPicker
 
54
 
 
55
                    anchors.fill: parent
 
56
                    visible: dialogue.done
 
57
                    contentType: ContentHub.ContentType.Pictures
 
58
                    handler: ContentHub.ContentHandler.Source
 
59
 
 
60
                    onPeerSelected: {
 
61
                        peer.selectionType = ContentHub.ContentTransfer.Single
 
62
                        dialogue.activeTransfer = peer.request()
 
63
                    }
 
64
 
 
65
                    onCancelPressed: {
 
66
                        PopupUtils.close(root.importDialog)
 
67
                    }
 
68
                }
 
69
            }
 
70
 
 
71
            Connections {
 
72
                id: signalConnections
 
73
 
 
74
                target: dialogue.activeTransfer
 
75
                onStateChanged: {
 
76
                    var done = ((dialogue.activeTransfer.state === ContentHub.ContentTransfer.Charged) ||
 
77
                                (dialogue.activeTransfer.state === ContentHub.ContentTransfer.Aborted))
 
78
 
 
79
                    if (dialogue.activeTransfer.state === ContentHub.ContentTransfer.Charged) {
 
80
                        dialogue.hide()
 
81
                        if (dialogue.activeTransfer.items.length > 0) {
 
82
                            root.pictureReceived(dialogue.activeTransfer.items[0].url)
 
83
                        }
 
84
                    }
 
85
 
 
86
                    if (done) {
 
87
                        acceptTimer.restart()
 
88
                    }
 
89
                }
 
90
            }
 
91
 
 
92
            // WORKAROUND: Work around for application becoming insensitive to touch events
 
93
            // if the dialog is dismissed while the application is inactive.
 
94
            // Just listening for changes to Qt.application.active doesn't appear
 
95
            // to be enough to resolve this, so it seems that something else needs
 
96
            // to be happening first. As such there's a potential for a race
 
97
            // condition here, although as yet no problem has been encountered.
 
98
            Timer {
 
99
                id: acceptTimer
 
100
 
 
101
                interval: 100
 
102
                repeat: true
 
103
                running: false
 
104
                onTriggered: {
 
105
                   if(Qt.application.active) {
 
106
                       PopupUtils.close(root.importDialog)
 
107
                   }
 
108
                }
 
109
            }
 
110
 
 
111
            Component.onDestruction: root.importDialog = null
 
112
        }
 
113
    }
 
114
}