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
27 import QtMobility.systeminfo 1.2
28 import QtMobility.location 1.2
30 // TODO: this has to be below QtMobility.systeminfo
31 // We define an element called BatteryInfo which conflicts with the one defined by QtMobility
32 // Thus we have to be the last so our element can be used instead of the one from QtMobility
35 // TODO: flash not ready (battery low or flash not ready message)
36 // TODO: portrait/landscape
37 // TODO: grid lines, face tracking
38 // TODO: select primary/secondary camera.
39 // TODO: disable debug builds.
40 // TODO: a way to get buffers to the application
41 // TODO: fcam like functionality (precise control over capture parameters).
46 property alias dimmer: camDimmer
50 Component.onCompleted: {
51 theme.inverted = true;
52 // TODO: hardcoding device id
53 root.resetCamera(0, settings.mode);
56 function showError(msg) {
61 function resetCamera(deviceId, mode) {
62 if (!cam.reset(deviceId, mode)) {
63 showError(qsTr("Failed to set camera device and mode. Please restart the application."));
68 // NOTE: The source will not reset the position when we lose the signal.
69 // This shouldn't be a big problem as we are course enough.
70 // If we ever need street level updates then this will be an issue.
72 active: settings.useGps
73 // TODO: we cannot bind to cam.running because camera will stop
74 // when the connection dialog pops up and we end up with an infinite loop
75 // active: cam.running && settings.useGps
76 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
82 manufacturer: deviceInfo.manufacturer
83 model: deviceInfo.model
84 country: geocode.country
86 suburb: geocode.suburb
87 longitude: positionSource.position.coordinate.longitude
88 longitudeValid: positionSource.position.longitudeValid && settings.useGps
89 latitude: positionSource.position.coordinate.latitude
90 latitudeValid: positionSource.position.latitudeValid && settings.useGps
91 elevation: positionSource.position.coordinate.altitude
92 elevationValid: positionSource.position.altitudeValid && settings.useGps
93 orientation: orientation.orientation
94 artist: settings.creatorName
95 captureDirection: compass.direction
96 captureDirectionValid: compass.directionValid
97 horizontalError: positionSource.position.horizontalAccuracy
98 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
114 active: cam.running && settings.useGps && settings.useGeotags
140 imageSuffix: cam.imageSuffix
141 videoSuffix: cam.videoSuffix
146 path: fileNaming.path
154 if (!checkBattery()) {
155 pageStack.currentPage.batteryLow();
160 batteryMonitor.check();
164 batteryMonitor.check();
168 function replacePage(file) {
169 pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
172 function openFile(file) {
173 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer});
176 function openFileNow(file) {
177 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
180 function checkBattery() {
181 // We are fine if we are connected to the charger:
182 if (batteryMonitor.charging) {
186 // If we have enough battery then we are fine:
187 if (!batteryMonitor.critical) {
194 platformStyle: PageStackWindowStyle {
195 cornersVisible: false
197 backgroundColor: "transparent"
203 function setImageResolution() {
204 if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
205 showError(qsTr("Failed to set required resolution"));
211 imageSettings.setImageResolution();
220 function setVideoResolution() {
221 if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
222 showError(qsTr("Failed to set required resolution"));
228 videoSettings.setVideoResolution();
236 onImageAspectRatioChanged: {
237 imageSettings.setImageResolution();
240 onImageResolutionChanged: {
241 imageSettings.setImageResolution();
244 onVideoResolutionChanged: {
245 videoSettings.setVideoResolution();
256 visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
257 cafStatus: cam ? cam.autoFocus.cafStatus : -1
258 status: cam ? cam.autoFocus.status : -1
263 // TODO: is this needed ?
264 if (platformWindow.active) {
270 if (pipelineManager.error) {
271 // Ignore any subsequent errors.
272 // Killing pulseaudio while recording will lead to an
273 // infinite supply of errors which will break the UI
274 // if we show a banner for each.
278 pipelineManager.error = true;
279 pageStack.currentPage.cameraError();
280 console.log("Camera error (" + code + "): " + message + " " + debug);
281 showError(qsTr("Camera error. Please restart the application."));
283 // We cannot stop camera here. Seems there is a race condition somewhere
284 // which leads to a freeze if we do so.
289 mountProtector.unlock();
293 Component.onDestruction: cam.stop();
295 // We need to show viewfinder below pages.
299 property bool dimmed: false
303 opacity: dimmed ? 1.0 : 0.0
305 Behavior on opacity {
306 PropertyAnimation { duration: 150 }
310 notifications: Sounds {
312 mute: !settings.soundEnabled
320 when: cam.mode == Camera.ImageMode
321 value: settings.imageFlashMode
326 property: "imageFlashMode"
327 when: cam.mode == Camera.ImageMode
328 value: cam.flash.value
334 when: cam.mode == Camera.VideoMode
335 value: settings.videoSceneMode
341 when: cam.mode == Camera.ImageMode
342 value: settings.imageSceneMode
348 when: cam.mode == Camera.ImageMode
349 value: settings.imageEvComp
355 when: cam.mode == Camera.VideoMode
356 value: settings.videoEvComp
361 property: "imageEvComp"
362 when: cam.mode == Camera.ImageMode
363 value: cam.evComp.value
368 property: "videoEvComp"
369 when: cam.mode == Camera.VideoMode
370 value: cam.evComp.value
374 target: cam.whiteBalance
376 when: cam.mode == Camera.ImageMode
377 value: settings.imageWhiteBalance
381 target: cam.whiteBalance
383 when: cam.mode == Camera.VideoMode
384 value: settings.videoWhiteBalance
388 target: cam.colorTone
390 when: cam.mode == Camera.ImageMode
391 value: settings.imageColorFilter
395 target: cam.colorTone
397 when: cam.mode == Camera.VideoMode
398 value: settings.videoColorFilter
404 when: cam.mode == Camera.ImageMode
405 value: settings.imageIso
411 when: cam.mode == Camera.ImageMode
416 target: cam.videoMute
418 value: settings.videoMuted
424 manufacturer: deviceInfo.manufacturer
425 model: deviceInfo.model
437 if (cam.mode == Camera.VideoMode) {
438 replacePage("VideoPage.qml");
441 replacePage("ImagePage.qml");
447 policyLost: pipelineManager.state == "policyLost"
448 show: !pageStack.currentPage || (pageStack.currentPage.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)