Add missing capability.cpp
[harmattan/cameraplus] / qml / MainPage.qml
index 3b51009..811ba31 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 night mode
 
 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) {
@@ -186,7 +197,10 @@ CameraPage {
         camera: viewfinder.camera
 
         function setImageResolution() {
-            if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
+            var aspectRatio = settings.device == 1 ? settings.secondaryImageAspectRatio : settings.primaryImageAspectRatio
+            var resolution = settings.device == 1 ? settings.secondaryImageResolution : settings.primaryImageResolution
+
+            if (!imageSettings.setResolution(aspectRatio, resolution)) {
                 showError(qsTr("Failed to set required resolution"))
             }
         }
@@ -203,7 +217,10 @@ CameraPage {
         camera: viewfinder.camera
 
         function setVideoResolution() {
-            if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
+            var aspectRatio = settings.device == 1 ? settings.secondaryVideoAspectRatio : settings.primaryVideoAspectRatio
+            var resolution = settings.device == 1 ? settings.secondaryVideoResolution : settings.primaryVideoResolution
+
+            if (!videoSettings.setResolution(aspectRatio, resolution)) {
                 showError(qsTr("Failed to set required resolution"))
             }
         }
@@ -218,17 +235,15 @@ CameraPage {
     Connections {
         target: settings
 
-        onImageAspectRatioChanged: {
-            imageSettings.setImageResolution()
-        }
+        onPrimaryImageResolutionChanged: imageSettings.setImageResolution()
+        onPrimaryImageAspectRatioChanged: imageSettings.setImageResolution()
+        onSecondaryImageResolutionChanged: imageSettings.setImageResolution()
+        onSecondaryImageAspectRatioChanged: imageSettings.setImageResolution()
 
-        onImageResolutionChanged: {
-            imageSettings.setImageResolution()
-        }
-
-        onVideoResolutionChanged: {
-            videoSettings.setVideoResolution()
-        }
+        onPrimaryVideoResolutionChanged: videoSettings.setVideoResolution()
+        onPrimaryVideoAspectRatioChanged: videoSettings.setVideoResolution()
+        onSecondaryVideoResolutionChanged: videoSettings.setVideoResolution()
+        onSecondaryVideoAspectRatioChanged: videoSettings.setVideoResolution()
     }
 
     ModeController {