Use Qtm namespace for QtMobility.systeminfo to resolve the BatteryInfo conflict
[harmattan/cameraplus] / qml / main.qml
index 01fbfa2..d30139a 100644 (file)
@@ -25,7 +25,7 @@ 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.systeminfo 1.2 as Qtm
 import QtMobility.location 1.2
 
 // TODO: flash not ready (battery low or flash not ready message)
@@ -115,7 +115,7 @@ PageStackWindow {
                 camera: cam
         }
 
-        DeviceInfo {
+        Qtm.DeviceInfo {
                 id: deviceInfo
         }
 
@@ -142,6 +142,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 +173,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: ""