4 * This file is part of CameraPlus.
6 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
24 import com.nokia.meego 1.1
27 import QtMobility.systeminfo 1.2
32 property alias standbyWidget: standby
34 property bool needsPipeline: true
35 property int policyMode: CameraResources.None
37 property Camera cam: null
38 property bool controlsVisible: cam.running && !standby.visible
39 property bool zoomVisible: true
40 property bool modesVisible: true
44 property alias previewAnimationRunning: preview.animationRunning
48 function updatePolicy() {
49 if (!resourcePolicy.acquire(page.policyMode)) {
57 Component.onCompleted: {
58 if (Qt.application.active && needsPipeline) {
61 else if (!needsPipeline) {
67 if (Qt.application.active && status == PageStatus.Activating) {
73 if (status == PageStatus.Active && !page.needsPipeline) {
79 onPolicyModeChanged: {
80 if (Qt.application.active) {
85 function handlePipeline() {
86 var acquired = resourcePolicy.acquired;
89 showError(qsTr("Resources lost. Stopping camera."));
91 else if (!Qt.application.active && !acquired) {
93 showError(qsTr("Resources lost. Stopping camera."));
95 else if (!Qt.application.active) {
98 else if (acquired && page.needsPipeline && !cam.running) {
100 showError(qsTr("Failed to start camera. Please restart the application."));
106 target: resourcePolicy
107 onAcquiredChanged: handlePipeline();
111 target: Qt.application
113 if (!Qt.application.active) {
114 // This is a noop if camera is not
115 // idle so calling it will not hurt
117 resourcePolicy.acquire(CameraResources.None);
120 else if (page.needsPipeline) {
129 if (cam.idle && !Qt.application.active) {
131 resourcePolicy.acquire(CameraResources.None);
134 else if (cam.idle && !page.needsPipeline) {
142 // TODO: fade out transition
143 // TODO: there is a toolbar visible on the first startup
147 visible: page.status == PageStatus.Active && (!Qt.application.active || !cam.running || !resourcePolicy.acquired)
149 source: "image://theme/icon-l-camera-standby"
150 anchors.centerIn: parent
154 function setPreview(image) {
155 preview.setPreview(image);
159 anchors.bottom: parent.bottom
160 anchors.right: parent.right
161 anchors.rightMargin: 20
162 anchors.bottomMargin: 20
163 visible: controlsVisible && modesVisible
173 anchors.top: parent.top
175 anchors.horizontalCenter: parent.horizontalCenter
176 visible: controlsVisible && zoomVisible
179 function checkDiskSpace() {
180 return fileSystem.hasFreeSpace(fileNaming.path);
183 function checkBattery() {
184 // We are fine if we are connected to the charger:
185 if (batteryMonitor.chargingState == BatteryInfo.Charging) {
189 // If we have enough battery then we are fine:
190 if (batteryMonitor.batteryStatus > BatteryInfo.BatteryCritical) {
199 monitorChargingStateChanges: cam.running
200 monitorBatteryStatusChanges: cam.running
202 onChargingStateChanged: {
203 if (!checkBattery()) {
208 onBatteryStatusChanged: {
209 if (!checkBattery()) {