Replaced QtMobility BatteryInfo
[harmattan/cameraplus] / qml / main.qml
index 01fbfa2..63a18b6 100644 (file)
@@ -24,10 +24,14 @@ import QtQuick 1.1
 import com.nokia.meego 1.1
 import com.nokia.extras 1.1
 import QtCamera 1.0
-import CameraPlus 1.0
 import QtMobility.systeminfo 1.2
 import QtMobility.location 1.2
 
+// TODO: this has to be below QtMobility.systeminfo
+// We define an element called BatteryInfo which conflicts with the one defined by QtMobility
+// Thus we have to be the last so our element can be used instead of the one from QtMobility
+import CameraPlus 1.0
+
 // TODO: flash not ready (battery low or flash not ready message)
 // TODO: portrait/landscape
 // TODO: grid lines, face tracking
@@ -142,6 +146,25 @@ PageStackWindow {
                 path: fileNaming.path
         }
 
+        BatteryInfo {
+                id: batteryMonitor
+                active: cam.running
+
+                function check() {
+                        if (!checkBattery()) {
+                                pageStack.currentPage.batteryLow();
+                        }
+                }
+
+                onChargingChanged: {
+                        batteryMonitor.check();
+                }
+
+                onCriticalChanged: {
+                        batteryMonitor.check();
+                }
+        }
+
         function replacePage(file) {
                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
         }
@@ -154,6 +177,20 @@ PageStackWindow {
                 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
         }
 
+        function checkBattery() {
+                // We are fine if we are connected to the charger:
+                if (batteryMonitor.charging) {
+                        return true;
+                }
+
+                // If we have enough battery then we are fine:
+                if (!batteryMonitor.critical) {
+                        return true;
+                }
+
+                return false;
+        }
+
         platformStyle: PageStackWindowStyle {
                 cornersVisible: false
                 background: ""