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
39 function updatePolicy() {
40 if (!resourcePolicy.acquire(page.policyMode)) {
48 Component.onCompleted: {
49 if (Qt.application.active && needsPipeline) {
55 if (Qt.application.active && status == PageStatus.Activating) {
61 if (status == PageStatus.Active && !page.needsPipeline) {
67 onPolicyModeChanged: {
68 if (Qt.application.active) {
73 function handlePipeline() {
74 var acquired = resourcePolicy.acquired;
77 showError(qsTr("Resources lost. Stopping camera."));
79 else if (!Qt.application.active && !acquired) {
81 showError(qsTr("Resources lost. Stopping camera."));
83 else if (!Qt.application.active) {
86 else if (acquired && page.needsPipeline && !cam.running) {
88 showError(qsTr("Failed to start camera. Please restart the application."));
94 target: resourcePolicy
95 onAcquiredChanged: handlePipeline();
99 target: Qt.application
101 if (!Qt.application.active) {
102 // This is a noop if camera is not
103 // idle so calling it will not hurt
105 resourcePolicy.acquire(CameraResources.None);
108 else if (page.needsPipeline) {
117 if (cam.idle && !Qt.application.active) {
119 resourcePolicy.acquire(CameraResources.None);
122 else if (cam.idle && !page.needsPipeline) {
130 // TODO: fade out transition
131 // TODO: there is a toolbar visible on the first startup
135 visible: page.status == PageStatus.Active && (!Qt.application.active || !cam.running || !resourcePolicy.acquired)
137 source: "image://theme/icon-l-camera-standby"
138 anchors.centerIn: parent
142 property Camera cam: null
143 property bool controlsVisible: cam.running && !standby.visible
147 property alias previewAnimationRunning: preview.animationRunning
149 function setPreview(image) {
150 preview.setPreview(image);
154 anchors.bottom: parent.bottom
155 anchors.right: parent.right
156 anchors.rightMargin: 20
157 anchors.bottomMargin: 20
158 visible: controlsVisible
168 anchors.top: parent.top
170 anchors.horizontalCenter: parent.horizontalCenter
171 visible: controlsVisible
174 function checkDiskSpace() {
175 return fileSystem.hasFreeSpace(fileNaming.path);
178 function checkBattery() {
179 // We are fine if we are connected to the charger:
180 if (batteryMonitor.chargingState == BatteryInfo.Charging) {
184 // If we have enough battery then we are fine:
185 if (batteryMonitor.batteryStatus > BatteryInfo.BatteryCritical) {
194 monitorChargingStateChanges: cam.running
195 monitorBatteryStatusChanges: cam.running
197 onChargingStateChanged: {
198 if (!checkBattery()) {
203 onBatteryStatusChanged: {
204 if (!checkBattery()) {