Convert TextSwitch to a platform specific component and rename it to CameraTextSwitch
[harmattan/cameraplus] / qml / MainPage.qml
index 997ce6e..e1b7fd7 100644 (file)
@@ -25,11 +25,13 @@ import QtCamera 1.0
 import CameraPlus 1.0
 
 // TODO: flash not ready (battery low or flash not ready message)
-// TODO: front camera
 
 CameraPage {
     id: root
 
+    property bool deviceChangeInProgress: false
+    property bool inCaptureMode: mainView.currentIndex == 1
+
     CameraTheme {
         id: cameraTheme
     }
@@ -80,7 +82,45 @@ CameraPage {
 
     Settings {
         id: settings
-        onDeviceChanged: root.resetCamera(settings.device, settings.mode)
+        onDeviceAboutToChange: {
+            root.deviceChangeInProgress = true
+        }
+
+        onDeviceChanged: {
+            viewfinder.cameraDeviceChanged()
+
+            // Reset pipeline manager error
+            pipelineManager.error = false
+
+            if (root.resetCamera(settings.device, settings.mode)) {
+                root.deviceChangeInProgress = false
+                pipelineManager.startCamera()
+            }
+        }
+
+        onImageAspectRatioChanged: {
+            if (!root.deviceChangeInProgress) {
+                imageSettings.setImageResolution()
+            }
+        }
+
+        onImageResolutionChanged: {
+            if (!root.deviceChangeInProgress) {
+                imageSettings.setImageResolution()
+            }
+        }
+
+        onVideoResolutionChanged: {
+            if (!root.deviceChangeInProgress) {
+                videoSettings.setVideoResolution()
+            }
+        }
+
+        onVideoAspectRatioChanged: {
+            if (!root.deviceChangeInProgress) {
+                videoSettings.setVideoResolution()
+            }
+        }
     }
 
     PipelineManager {
@@ -92,7 +132,17 @@ CameraPage {
     function resetCamera(deviceId, mode) {
         if (!viewfinder.camera.reset(deviceId, mode)) {
             showError(qsTr("Failed to set camera device and mode. Please restart the application."))
+            return false
+        }
+
+        if (mode == Camera.ImageMode) {
+            imageSettings.setImageResolution()
         }
+        else if (mode == Camera.VideoMode) {
+            videoSettings.setVideoResolution()
+        }
+
+        return true
     }
 
     function showError(msg) {
@@ -164,11 +214,14 @@ CameraPage {
         id: fileNaming
         imageSuffix: viewfinder.camera.imageSuffix
         videoSuffix: viewfinder.camera.videoSuffix
+        imagePath: platformSettings.imagePath
+        videoPath: platformSettings.videoPath
+        temporaryVideoPath: platformSettings.temporaryVideoPath
+        settings: settings
     }
 
     MountProtector {
         id: mountProtector
-        path: fileNaming.path
     }
 
     TrackerStore {
@@ -178,10 +231,6 @@ CameraPage {
         model: deviceInfo.model
     }
 
-    function checkDiskSpace() {
-        return fileSystem.hasFreeSpace(fileNaming.path)
-    }
-
     ImageSettings {
         id: imageSettings
         camera: viewfinder.camera
@@ -191,12 +240,6 @@ CameraPage {
                 showError(qsTr("Failed to set required resolution"))
             }
         }
-
-        onReadyChanged: {
-            if (ready) {
-                imageSettings.setImageResolution()
-            }
-        }
     }
 
     VideoSettings {
@@ -208,28 +251,6 @@ CameraPage {
                 showError(qsTr("Failed to set required resolution"))
             }
         }
-
-        onReadyChanged: {
-            if (ready) {
-                videoSettings.setVideoResolution()
-            }
-        }
-    }
-
-    Connections {
-        target: settings
-
-        onImageAspectRatioChanged: {
-            imageSettings.setImageResolution()
-        }
-
-        onImageResolutionChanged: {
-            imageSettings.setImageResolution()
-        }
-
-        onVideoResolutionChanged: {
-            videoSettings.setVideoResolution()
-        }
     }
 
     ModeController {
@@ -252,13 +273,19 @@ CameraPage {
 
     DeviceKeys {
         id: keys
-        active: Qt.application.active && pipelineManager.scaleAcquired
+        active: Qt.application.active && pipelineManager.scaleAcquired && root.inCaptureMode && !mainView.moving
         repeat: !settings.zoomAsShutter
     }
 
+    CameraProximitySensor {
+        id: proximitySensor
+        active: Qt.application.active && viewfinder.camera.running && settings.proximityAsShutter && root.inCaptureMode && !mainView.moving
+    }
+
+    // TODO:
     Standby {
         policyLost: pipelineManager.state == "policyLost"
         show: !Qt.application.active || pipelineManager.showStandBy ||
-            (mainView.currentIndex == 1 && !viewfinder.camera.running)
+            (inCaptureMode && !viewfinder.camera.running)
     }
 }