From: Mohammed Sameer Date: Sat, 6 Oct 2012 21:31:41 +0000 (+0300) Subject: Battery low handling: X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=104eced768ad67d62641401e5e626bf20da9bdbb Battery low handling: 1) Don't record video or capture images when battery is low 2) Stop video recording when we battery is low --- diff --git a/qml/CameraPage.qml b/qml/CameraPage.qml index ba02bf9..e643b2f 100644 --- a/qml/CameraPage.qml +++ b/qml/CameraPage.qml @@ -24,6 +24,7 @@ import QtQuick 1.1 import com.nokia.meego 1.1 import QtCamera 1.0 import CameraPlus 1.0 +import QtMobility.systeminfo 1.2 Page { id: page @@ -33,6 +34,8 @@ Page { property bool needsPipeline: true property int policyMode: CameraResources.None + signal batteryLow + Component.onCompleted: { if (Qt.application.active && needsPipeline) { resourcePolicy.acquire(page.policyMode); @@ -154,4 +157,36 @@ Page { anchors.horizontalCenter: parent.horizontalCenter visible: controlsVisible } + + function checkBattery() { + // We are fine if we are connected to the charger: + if (batteryMonitor.chargingState == BatteryInfo.Charging) { + return true; + } + + // If we have enough battery then we are fine: + if (batteryMonitor.batteryStatus > BatteryInfo.BatteryCritical) { + return true; + } + + return false; + } + + BatteryInfo { + id: batteryMonitor + monitorChargingStateChanges: cam.running + monitorBatteryStatusChanges: cam.running + + onChargingStateChanged: { + if (!checkBattery()) { + parent.batteryLow(); + } + } + + onBatteryStatusChanged: { + if (!checkBattery()) { + parent.batteryLow(); + } + } + } } diff --git a/qml/ImagePage.qml b/qml/ImagePage.qml index 5830fe2..67ccee0 100644 --- a/qml/ImagePage.qml +++ b/qml/ImagePage.qml @@ -44,6 +44,11 @@ CameraPage { height: 75 opacity: 0.5 onClicked: { + if (!checkBattery()) { + showError(qsTr("Not enough battery to capture images.")); + return; + } + if (!fileSystem.available) { showError(qsTr("Camera cannot capture images in mass storage mode.")); return; diff --git a/qml/VideoPage.qml b/qml/VideoPage.qml index 83e4f76..9b861ba 100644 --- a/qml/VideoPage.qml +++ b/qml/VideoPage.qml @@ -26,7 +26,6 @@ import QtCamera 1.0 import CameraPlus 1.0 import "data.js" as Data -// TODO: stop recording when battery low // TODO: stop recording when disk is low CameraPage { @@ -43,6 +42,17 @@ CameraPage { inhibitDim: videoMode.recording } + onBatteryLow: { + if (!videoMode.recording) { + return; + } + + if (!checkBattery()) { + videoMode.stopRecording(); + showError(qsTr("Not enough battery to record video.")); + } + } + Button { id: recording anchors.right: parent.right @@ -65,6 +75,11 @@ CameraPage { // policy can acquire the needed resources if (policyMode == CameraResources.Video) { + if (!checkBattery()) { + showError(qsTr("Not enough battery to record video.")); + return; + } + policyMode = CameraResources.Recording; } else if (videoMode.recording) { diff --git a/qml/main.qml b/qml/main.qml index 2fe92e8..eb388ca 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -29,7 +29,6 @@ import QtMobility.systeminfo 1.2 import QtMobility.location 1.2 // TODO: postcapture -// TODO: battery low state // TODO: disk space // TODO: flash not ready // TODO: focus, caf, ...