4 * This file is part of CameraPlus.
6 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 import com.nokia.meego 1.1
25 import com.nokia.extras 1.1
28 import QtMobility.location 1.2
30 // TODO: flash not ready (battery low or flash not ready message)
35 property alias dimmer: camDimmer
44 enabled: pageStack.busy
51 Component.onCompleted: {
52 platformSettings.init();
53 theme.inverted = true;
54 // TODO: hardcoding device id
55 root.resetCamera(0, settings.mode);
58 function showError(msg) {
63 function resetCamera(deviceId, mode) {
64 if (!cam.reset(deviceId, mode)) {
65 showError(qsTr("Failed to set camera device and mode. Please restart the application."));
70 // NOTE: The source will not reset the position when we lose the signal.
71 // This shouldn't be a big problem as we are course enough.
72 // If we ever need street level updates then this will be an issue.
74 active: settings.useGps
75 // TODO: we cannot bind to cam.running because camera will stop
76 // when the connection dialog pops up and we end up with an infinite loop
77 // active: cam.running && settings.useGps
78 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
84 manufacturer: deviceInfo.manufacturer
85 model: deviceInfo.model
86 country: geocode.country
88 suburb: geocode.suburb
89 longitude: positionSource.position.coordinate.longitude
90 longitudeValid: positionSource.position.longitudeValid && settings.useGps
91 latitude: positionSource.position.coordinate.latitude
92 latitudeValid: positionSource.position.latitudeValid && settings.useGps
93 elevation: positionSource.position.coordinate.altitude
94 elevationValid: positionSource.position.altitudeValid && settings.useGps
95 orientation: orientation.orientation
96 artist: settings.creatorName
97 captureDirection: compass.direction
98 captureDirectionValid: compass.directionValid
99 horizontalError: positionSource.position.horizontalAccuracy
100 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
101 dateTimeEnabled: true
116 active: cam.running && settings.useGps && settings.useGeotags
142 imageSuffix: cam.imageSuffix
143 videoSuffix: cam.videoSuffix
148 path: fileNaming.path
156 if (!checkBattery()) {
157 pageStack.currentPage.batteryLow();
162 batteryMonitor.check();
166 batteryMonitor.check();
170 function replacePage(file) {
171 pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
174 function openFile(file) {
175 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer});
178 function openFileNow(file) {
179 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
182 function checkBattery() {
183 // We are fine if we are connected to the charger:
184 if (batteryMonitor.charging) {
188 // If we have enough battery then we are fine:
189 if (!batteryMonitor.critical) {
199 function setImageResolution() {
200 if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
201 showError(qsTr("Failed to set required resolution"));
207 imageSettings.setImageResolution();
216 function setVideoResolution() {
217 if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
218 showError(qsTr("Failed to set required resolution"));
224 videoSettings.setVideoResolution();
232 onImageAspectRatioChanged: {
233 imageSettings.setImageResolution();
236 onImageResolutionChanged: {
237 imageSettings.setImageResolution();
240 onVideoResolutionChanged: {
241 videoSettings.setVideoResolution();
249 onRoiChanged: roi.normalize = false;
254 width: cam.renderArea.width
255 height: cam.renderArea.height
256 visible: settings.gridEnabled
262 visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
263 cafStatus: cam ? cam.autoFocus.cafStatus : -1
264 status: cam ? cam.autoFocus.status : -1
268 if (pipelineManager.error) {
269 // Ignore any subsequent errors.
270 // Killing pulseaudio while recording will lead to an
271 // infinite supply of errors which will break the UI
272 // if we show a banner for each.
276 pipelineManager.error = true;
277 pageStack.currentPage.cameraError();
278 console.log("Camera error (" + code + "): " + message + " " + debug);
279 showError(qsTr("Camera error. Please restart the application."));
281 // We cannot stop camera here. Seems there is a race condition somewhere
282 // which leads to a freeze if we do so.
287 mountProtector.unlock();
291 Component.onDestruction: cam.stop();
293 // We need to show viewfinder below pages.
297 property bool dimmed: false
301 opacity: dimmed ? 1.0 : 0.0
303 Behavior on opacity {
304 PropertyAnimation { duration: 150 }
308 notifications: Sounds {
310 mute: !settings.soundEnabled
318 when: cam.mode == Camera.ImageMode
319 value: settings.imageFlashMode
324 property: "imageFlashMode"
325 when: cam.mode == Camera.ImageMode
326 value: cam.flash.value
332 when: cam.mode == Camera.VideoMode
333 value: settings.videoSceneMode
339 when: cam.mode == Camera.ImageMode
340 value: settings.imageSceneMode
346 when: cam.mode == Camera.ImageMode
347 value: settings.imageEvComp
353 when: cam.mode == Camera.VideoMode
354 value: settings.videoEvComp
359 property: "imageEvComp"
360 when: cam.mode == Camera.ImageMode
361 value: cam.evComp.value
366 property: "videoEvComp"
367 when: cam.mode == Camera.VideoMode
368 value: cam.evComp.value
372 target: cam.whiteBalance
374 when: cam.mode == Camera.ImageMode
375 value: settings.imageWhiteBalance
379 target: cam.whiteBalance
381 when: cam.mode == Camera.VideoMode
382 value: settings.videoWhiteBalance
386 target: cam.colorTone
388 when: cam.mode == Camera.ImageMode
389 value: settings.imageColorFilter
393 target: cam.colorTone
395 when: cam.mode == Camera.VideoMode
396 value: settings.videoColorFilter
402 when: cam.mode == Camera.ImageMode
403 value: settings.imageIso
409 when: cam.mode == Camera.ImageMode
414 target: cam.videoMute
416 value: settings.videoMuted
422 value: settings.faceDetectionEnabled && !focusReticle.pressed && !focusReticle.touchMode && cam.mode == Camera.ImageMode
429 manufacturer: deviceInfo.manufacturer
430 model: deviceInfo.model
442 if (cam.mode == Camera.VideoMode) {
443 replacePage("VideoPage.qml");
446 replacePage("ImagePage.qml");
452 policyLost: pipelineManager.state == "policyLost"
453 show: !pageStack.currentPage || (pageStack.currentPage.activationData.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)
458 active: Qt.application.active && pipelineManager.scaleAcquired
459 repeat: !settings.zoomAsShutter