X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=blobdiff_plain;f=qml%2FPipelineManager.qml;h=0ef0a687d7f9da8fbd0acf709971c760613f9319;hp=47152e18ca191a6f77edbdcde696f0b0aec0e817;hb=0bcc5e36c09c707add18c70e2a95317d7db8b271;hpb=3ea1faf6136b4203d64982d8281ae30f6f2ef966 diff --git a/qml/PipelineManager.qml b/qml/PipelineManager.qml index 47152e1..0ef0a68 100644 --- a/qml/PipelineManager.qml +++ b/qml/PipelineManager.qml @@ -3,7 +3,7 @@ /*! * This file is part of CameraPlus. * - * Copyright (C) 2012 Mohammed Sameer + * Copyright (C) 2012-2013 Mohammed Sameer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,123 +20,134 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +import QtQuick 2.0 import QtCamera 1.0 import CameraPlus 1.0 -// TODO: cleanup debug output -// TODO: losing resources will freeze camera somehow. - Item { - id: handler + id: handler - property bool showStandBy: state != "on" + property bool showStandBy: state != "on" - property Camera camera: null - property Item currentPage: pageStack.currentPage + property alias acquired: policy.acquired + property alias hijacked: policy.hijacked + property alias scaleAcquired: policy.scaleAcquired - onCurrentPageChanged: { - if (state == "on") { - startCamera(); - } - } + property Camera camera: null + property Item currentItem + property bool error: false + property int currentPolicyMode: CameraResources.None - CameraResources { - id: policy + onCurrentItemChanged: { + if (state == "on" || state == "policyLost") { + startCamera() } - - function startCamera() { - console.log("start"); - if (!policy.acquire(currentPage.policyMode)) { - console.log("Failed to acquire policy resources"); - camera.stop(true); - return; - } - - if (!camera.start()) { - showError(qsTr("Failed to start camera. Please restart the application.")); - } + } + + Connections { + target: currentItem + onPolicyModeChanged: { + if (state == "on" || state == "policyLost") { + startCamera() + } } - - function stopCamera() { - console.log("stop"); - if (camera.stop(false)) { - console.log("stopped"); - } - else { - console.log("didn't stop"); - } - - policy.acquire(CameraResources.None); - console.log("acquired none"); + } + + CameraResources { + id: policy + } + + function startCamera() { + if (error) { + return + } else if ((currentPolicyMode == currentItem.policyMode) && camera.running) { + return + } else if (!policy.acquire(currentItem.policyMode)) { + console.log("Failed to acquire policy resources") + return + } else if (currentItem.policyMode == CameraResources.Player) { + currentPolicyMode = CameraResources.Player + camera.stop(true) + } else if (!camera.start()) { + showError(qsTr("Failed to start camera. Please restart the application.")) + } else { + currentPolicyMode = currentItem.policyMode } + } - function forceStopCamera() { - // We don't release resources here so we can get them back - // when they become available - console.log("force"); - camera.stop(true); + function stopCamera() { + if (camera.stop(false)) { + policy.acquire(CameraResources.None) + currentPolicyMode = CameraResources.None + error = false } + } - state: "off" + function forceStopCamera() { + // We don't release resources here so we can get them back + // when they become available + currentItem.policyLost() + camera.stop(true) + currentPolicyMode = CameraResources.None + error = false + } - onStateChanged: console.log("New state " + handler.state); + state: "off" - states: [ +// onStateChanged: console.log("New state " + handler.state); + + states: [ State { - name: "on" - when: Qt.application.active && currentPage && currentPage.needsPipeline && !policy.hijacked + name: "on" + when: Qt.application.active && currentItem && currentItem.policyMode != CameraResources.None && !policy.hijacked }, State { - name: "off" - when: (!Qt.application.active && camera.idle) || (currentPage && !currentPage.needsPipeline) + name: "off" + when: (!Qt.application.active && camera.idle) || (currentItem && currentItem.policyMode == CameraResources.None && camera.idle) }, State { - name: "policyLost" - when: policy.hijacked + name: "policyLost" + when: policy.hijacked }, State { - name: "error" + name: "error" } - ] + ] - transitions: [ + transitions: [ Transition { - from: "on" - to: "off" - ScriptAction { - script: stopCamera(); - } + to: "off" + ScriptAction { + script: stopCamera() + } }, Transition { - from: "off" - to: "on" - ScriptAction { - script: handler.startCamera(); - } + from: "off" + to: "on" + ScriptAction { + script: handler.startCamera() + } }, - Transition { - from: "on" - to: "policyLost" - ScriptAction { - script: forceStopCamera(); - } + from: "on" + to: "policyLost" + ScriptAction { + script: forceStopCamera() + } }, - Transition { - from: "policyLost" - to: "off" - ScriptAction { - script: stopCamera(); - } + from: "policyLost" + to: "off" + ScriptAction { + script: stopCamera() + } }, Transition { - from: "policyLost" - to: "on" - ScriptAction { - script: startCamera(); - } + from: "policyLost" + to: "on" + ScriptAction { + script: startCamera() + } } - ] + ] }