Reset pipeline manager error and try to start camera device when device gets changed
[harmattan/cameraplus] / qml / MainPage.qml
index 3b51009..0f5c517 100644 (file)
@@ -25,6 +25,7 @@ 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
@@ -70,8 +71,7 @@ CameraPage {
 
     Component.onCompleted: {
         platformSettings.init()        
-        // TODO: hardcoding device id
-        root.resetCamera(0, settings.mode)
+        root.resetCamera(settings.device, settings.mode)
     }
 
     PlatformSettings {
@@ -80,6 +80,14 @@ CameraPage {
 
     Settings {
         id: settings
+        onDeviceChanged: {
+            // Reset pipeline manager error
+            pipelineManager.error = false
+
+            if (root.resetCamera(settings.device, settings.mode)) {
+                pipelineManager.startCamera()
+            }
+        }
     }
 
     PipelineManager {
@@ -91,7 +99,10 @@ 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
         }
+
+        return true
     }
 
     function showError(msg) {