Stop video playback when we lose policy resources
[harmattan/cameraplus] / qml / PostCaptureItem.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 1.1
24 import com.nokia.meego 1.1
25 import CameraPlus 1.0
26
27 Item {
28     id: postCaptureItem
29     property bool isVideo: itemData.type.search("nmm#Video") > 0
30     property alias error: image.error
31     property variant itemData: item
32     property bool playing: loader.source != ""
33     signal clicked
34
35     function startPlayback() {
36         loader.source = Qt.resolvedUrl("VideoPlayerPage.qml")
37         loader.item.source = itemData.url
38         if (!loader.item.play()) {
39             showError(qsTr("Error playing video. Please try again."))
40             loader.source = ""
41         }
42     }
43
44     function stopPlayback() {
45         if (loader.item) {
46             loader.item.stop()
47         }
48     }
49
50     Loader {
51         id: loader
52         anchors.fill: parent
53     }
54
55     Connections {
56         target: loader.item
57         onFinished: loader.source = ""
58     }
59
60     QuillItem {
61         id: image
62         width: parent.width - 10
63         height: parent.height
64         anchors.centerIn: parent
65         Component.onCompleted: initialize(itemData.url, itemData.mimetype)
66         visible: loader.source == ""
67
68         Label {
69             anchors.fill: parent
70             visible: image.error
71             text: qsTr("Failed to load preview")
72             verticalAlignment: Text.AlignVCenter
73             horizontalAlignment: Text.AlignHCenter
74             font.pixelSize: 32
75         }
76
77         MouseArea {
78             id: mouse
79             anchors.fill: parent
80             enabled: true
81             onClicked: postCaptureItem.clicked()
82         }
83
84         ToolIcon {
85             // TODO: this is overlapping with error.
86             id: playIcon
87             anchors.centerIn: parent
88             iconSource: "image://theme/icon-s-music-video-play"
89             visible: isVideo
90             onClicked: startPlayback()
91         }
92     }
93 }