Use Qtm namespace for QtMobility.systeminfo to resolve the BatteryInfo conflict
[harmattan/cameraplus] / qml / main.qml
index 6da3429..d30139a 100644 (file)
@@ -25,19 +25,16 @@ 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: postcapture
 // TODO: flash not ready (battery low or flash not ready message)
 // TODO: portrait/landscape
-// TODO: stop viewfinder in settings pages ?
-// TODO: grid lines, face tracking, ambr
+// TODO: grid lines, face tracking
 // TODO: select primary/secondary camera.
 // TODO: disable debug builds.
 // TODO: a way to get buffers to the application
 // TODO: fcam like functionality (precise control over capture parameters).
-// TODO: mute video sound
 
 PageStackWindow {
         id: root
@@ -118,7 +115,7 @@ PageStackWindow {
                 camera: cam
         }
 
-        DeviceInfo {
+        Qtm.DeviceInfo {
                 id: deviceInfo
         }
 
@@ -145,16 +142,49 @@ 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}, true);
+                pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
         }
 
         function openFile(file) {
-                pageStack.push(Qt.resolvedUrl(file), {cam: cam});
+                pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer});
         }
 
         function openFileNow(file) {
-                pageStack.push(Qt.resolvedUrl(file), {cam: cam}, true);
+                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 {
@@ -222,7 +252,7 @@ PageStackWindow {
                         visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
                         cafStatus: cam ? cam.autoFocus.cafStatus : -1
                         status: cam ? cam.autoFocus.status : -1
-        }
+                }
 
 /*
                 onDeviceIdChanged: {
@@ -233,10 +263,21 @@ PageStackWindow {
                 }
 */
                 onError: {
+                        if (pipelineManager.error) {
+                                // Ignore any subsequent errors.
+                                // Killing pulseaudio while recording will lead to an
+                                // infinite supply of errors which will break the UI
+                                // if we show a banner for each.
+                                return;
+                        }
+
+                        pipelineManager.error = true;
+                        pageStack.currentPage.cameraError();
                         console.log("Camera error (" + code + "): " + message + " " + debug);
                         showError(qsTr("Camera error. Please restart the application."));
-                        cam.stop();
-                        mountProtector.unlock();
+
+                        // We cannot stop camera here. Seems there is a race condition somewhere
+                        // which leads to a freeze if we do so.
                 }
 
                 onRunningChanged: {
@@ -251,11 +292,15 @@ PageStackWindow {
                 z: -1
 
                 Rectangle {
+                        property bool dimmed: false
                         id: camDimmer
                         z: 1
                         anchors.fill: parent
-                        opacity: 0
+                        opacity: dimmed ? 1.0 : 0.0
                         color: "black"
+                        Behavior on opacity {
+                                PropertyAnimation { duration: 150 }
+                        }
                 }
 
                 notifications: Sounds {
@@ -363,6 +408,12 @@ PageStackWindow {
                 value: cam.iso.value
         }
 
+        Binding {
+                target: cam.videoMute
+                property: "enabled"
+                value: settings.videoMuted
+        }
+
         TrackerStore {
                 id: trackerStore
                 active: cam.running
@@ -387,4 +438,9 @@ PageStackWindow {
                         }
                 }
         }
+
+        Standby {
+                policyLost: pipelineManager.state == "policyLost"
+                show: !pageStack.currentPage || (pageStack.currentPage.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)
+        }
 }