Stop video playback when we lose policy resources
[harmattan/cameraplus] / qml / PostCaptureItem.qml
index 3d63b4a..5e5b79e 100644 (file)
@@ -3,7 +3,7 @@
 /*!
  * This file is part of CameraPlus.
  *
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,31 +25,69 @@ import com.nokia.meego 1.1
 import CameraPlus 1.0
 
 Item {
-        id: item
-        property bool isImage: mimetype.toLowerCase().search("video") < 0
-        property bool error: false
+    id: postCaptureItem
+    property bool isVideo: itemData.type.search("nmm#Video") > 0
+    property alias error: image.error
+    property variant itemData: item
+    property bool playing: loader.source != ""
+    signal clicked
 
-        Label {
-                anchors.fill: parent
-                visible: image.error && page.status == PageStatus.Active
-                text: qsTr("Failed to load preview");
-                verticalAlignment: Text.AlignVCenter
-                horizontalAlignment: Text.AlignHCenter
-                font.pixelSize: 32
+    function startPlayback() {
+        loader.source = Qt.resolvedUrl("VideoPlayerPage.qml")
+        loader.item.source = itemData.url
+        if (!loader.item.play()) {
+            showError(qsTr("Error playing video. Please try again."))
+            loader.source = ""
+        }
+    }
+
+    function stopPlayback() {
+        if (loader.item) {
+            loader.item.stop()
         }
+    }
+
+    Loader {
+        id: loader
+        anchors.fill: parent
+    }
+
+    Connections {
+        target: loader.item
+        onFinished: loader.source = ""
+    }
 
-        QuillItem {
-                id: image
-                anchors.fill: parent
-                visible: page.status == PageStatus.Activating || page.status == PageStatus.Active
+    QuillItem {
+        id: image
+        width: parent.width - 10
+        height: parent.height
+        anchors.centerIn: parent
+        Component.onCompleted: initialize(itemData.url, itemData.mimetype)
+        visible: loader.source == ""
 
-                Component.onCompleted: initialize(url, mimetype);
+        Label {
+            anchors.fill: parent
+            visible: image.error
+            text: qsTr("Failed to load preview")
+            verticalAlignment: Text.AlignVCenter
+            horizontalAlignment: Text.AlignHCenter
+            font.pixelSize: 32
+        }
+
+        MouseArea {
+            id: mouse
+            anchors.fill: parent
+            enabled: true
+            onClicked: postCaptureItem.clicked()
+        }
 
-                MouseArea {
-                        id: mouse
-                        anchors.fill: parent
-                        enabled: true
-                        onClicked: toolBar.visible = !toolBar.visible
-                }
+        ToolIcon {
+            // TODO: this is overlapping with error.
+            id: playIcon
+            anchors.centerIn: parent
+            iconSource: "image://theme/icon-s-music-video-play"
+            visible: isVideo
+            onClicked: startPlayback()
         }
+    }
 }