4 * This file is part of CameraPlus.
6 * Copyright (C) 2012 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
39 Component.onCompleted: {
40 theme.inverted = true;
41 // TODO: hardcoding device id
42 root.resetCamera(0, settings.mode);
45 function showError(msg) {
50 function resetCamera(deviceId, mode) {
51 if (!cam.reset(deviceId, mode)) {
52 showError(qsTr("Failed to set camera device and mode. Please restart the application."));
57 // NOTE: The source will not reset the position when we lose the signal.
58 // This shouldn't be a big problem as we are course enough.
59 // If we ever need street level updates then this will be an issue.
61 active: settings.useGps
62 // TODO: we cannot bind to cam.running because camera will stop
63 // when the connection dialog pops up and we end up with an infinite loop
64 // active: cam.running && settings.useGps
65 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
71 manufacturer: deviceInfo.manufacturer
72 model: deviceInfo.model
73 country: geocode.country
75 suburb: geocode.suburb
76 longitude: positionSource.position.coordinate.longitude
77 longitudeValid: positionSource.position.longitudeValid && settings.useGps
78 latitude: positionSource.position.coordinate.latitude
79 latitudeValid: positionSource.position.latitudeValid && settings.useGps
80 elevation: positionSource.position.coordinate.altitude
81 elevationValid: positionSource.position.altitudeValid && settings.useGps
82 orientation: orientation.orientation
83 artist: settings.creatorName
84 captureDirection: compass.direction
85 captureDirectionValid: compass.directionValid
86 horizontalError: positionSource.position.horizontalAccuracy
87 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
103 active: cam.running && settings.useGps && settings.useGeotags
129 imageSuffix: cam.imageSuffix
130 videoSuffix: cam.videoSuffix
135 path: fileNaming.path
143 if (!checkBattery()) {
144 pageStack.currentPage.batteryLow();
149 batteryMonitor.check();
153 batteryMonitor.check();
157 function replacePage(file) {
158 pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
161 function openFile(file) {
162 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer});
165 function openFileNow(file) {
166 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
169 function checkBattery() {
170 // We are fine if we are connected to the charger:
171 if (batteryMonitor.charging) {
175 // If we have enough battery then we are fine:
176 if (!batteryMonitor.critical) {
183 platformStyle: PageStackWindowStyle {
184 cornersVisible: false
186 backgroundColor: "transparent"
192 function setImageResolution() {
193 if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
194 showError(qsTr("Failed to set required resolution"));
200 imageSettings.setImageResolution();
209 function setVideoResolution() {
210 if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
211 showError(qsTr("Failed to set required resolution"));
217 videoSettings.setVideoResolution();
225 onImageAspectRatioChanged: {
226 imageSettings.setImageResolution();
229 onImageResolutionChanged: {
230 imageSettings.setImageResolution();
233 onVideoResolutionChanged: {
234 videoSettings.setVideoResolution();
242 onRoiChanged: roi.normalize = false;
247 width: cam.renderArea.width
248 height: cam.renderArea.height
249 visible: settings.gridEnabled
255 visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
256 cafStatus: cam ? cam.autoFocus.cafStatus : -1
257 status: cam ? cam.autoFocus.status : -1
261 if (pipelineManager.error) {
262 // Ignore any subsequent errors.
263 // Killing pulseaudio while recording will lead to an
264 // infinite supply of errors which will break the UI
265 // if we show a banner for each.
269 pipelineManager.error = true;
270 pageStack.currentPage.cameraError();
271 console.log("Camera error (" + code + "): " + message + " " + debug);
272 showError(qsTr("Camera error. Please restart the application."));
274 // We cannot stop camera here. Seems there is a race condition somewhere
275 // which leads to a freeze if we do so.
280 mountProtector.unlock();
284 Component.onDestruction: cam.stop();
286 // We need to show viewfinder below pages.
290 property bool dimmed: false
294 opacity: dimmed ? 1.0 : 0.0
296 Behavior on opacity {
297 PropertyAnimation { duration: 150 }
301 notifications: Sounds {
303 mute: !settings.soundEnabled
311 when: cam.mode == Camera.ImageMode
312 value: settings.imageFlashMode
317 property: "imageFlashMode"
318 when: cam.mode == Camera.ImageMode
319 value: cam.flash.value
325 when: cam.mode == Camera.VideoMode
326 value: settings.videoSceneMode
332 when: cam.mode == Camera.ImageMode
333 value: settings.imageSceneMode
339 when: cam.mode == Camera.ImageMode
340 value: settings.imageEvComp
346 when: cam.mode == Camera.VideoMode
347 value: settings.videoEvComp
352 property: "imageEvComp"
353 when: cam.mode == Camera.ImageMode
354 value: cam.evComp.value
359 property: "videoEvComp"
360 when: cam.mode == Camera.VideoMode
361 value: cam.evComp.value
365 target: cam.whiteBalance
367 when: cam.mode == Camera.ImageMode
368 value: settings.imageWhiteBalance
372 target: cam.whiteBalance
374 when: cam.mode == Camera.VideoMode
375 value: settings.videoWhiteBalance
379 target: cam.colorTone
381 when: cam.mode == Camera.ImageMode
382 value: settings.imageColorFilter
386 target: cam.colorTone
388 when: cam.mode == Camera.VideoMode
389 value: settings.videoColorFilter
395 when: cam.mode == Camera.ImageMode
396 value: settings.imageIso
402 when: cam.mode == Camera.ImageMode
407 target: cam.videoMute
409 value: settings.videoMuted
415 value: settings.faceDetectionEnabled && !focusReticle.pressed && !focusReticle.touchMode && cam.mode == Camera.ImageMode
422 manufacturer: deviceInfo.manufacturer
423 model: deviceInfo.model
435 if (cam.mode == Camera.VideoMode) {
436 replacePage("VideoPage.qml");
439 replacePage("ImagePage.qml");
445 policyLost: pipelineManager.state == "policyLost"
446 show: !pageStack.currentPage || (pageStack.currentPage.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)
451 active: Qt.application.active && pipelineManager.scaleAcquired