Battery low handling:
authorMohammed Sameer <msameer@foolab.org>
Sat, 6 Oct 2012 21:31:41 +0000 (00:31 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sat, 6 Oct 2012 21:31:41 +0000 (00:31 +0300)
1) Don't record video or capture images when battery is low
2) Stop video recording when we battery is low

qml/CameraPage.qml
qml/ImagePage.qml
qml/VideoPage.qml
qml/main.qml

index ba02bf9..e643b2f 100644 (file)
@@ -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();
+                        }
+                }
+        }
 }
index 5830fe2..67ccee0 100644 (file)
@@ -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;
index 83e4f76..9b861ba 100644 (file)
@@ -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) {
index 2fe92e8..eb388ca 100644 (file)
@@ -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, ...