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.systeminfo 1.2 as Qtm
29 import QtMobility.location 1.2
31 // TODO: flash not ready (battery low or flash not ready message)
32 // TODO: portrait/landscape
33 // TODO: face tracking
34 // TODO: select primary/secondary camera.
35 // TODO: disable debug builds.
36 // TODO: a way to get buffers to the application
37 // TODO: fcam like functionality (precise control over capture parameters).
38 // TODO: timer, fast capture
43 property alias dimmer: camDimmer
47 Component.onCompleted: {
48 theme.inverted = true;
49 // TODO: hardcoding device id
50 root.resetCamera(0, settings.mode);
53 function showError(msg) {
58 function resetCamera(deviceId, mode) {
59 if (!cam.reset(deviceId, mode)) {
60 showError(qsTr("Failed to set camera device and mode. Please restart the application."));
65 // NOTE: The source will not reset the position when we lose the signal.
66 // This shouldn't be a big problem as we are course enough.
67 // If we ever need street level updates then this will be an issue.
69 active: settings.useGps
70 // TODO: we cannot bind to cam.running because camera will stop
71 // when the connection dialog pops up and we end up with an infinite loop
72 // active: cam.running && settings.useGps
73 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
79 manufacturer: deviceInfo.manufacturer
80 model: deviceInfo.model
81 country: geocode.country
83 suburb: geocode.suburb
84 longitude: positionSource.position.coordinate.longitude
85 longitudeValid: positionSource.position.longitudeValid && settings.useGps
86 latitude: positionSource.position.coordinate.latitude
87 latitudeValid: positionSource.position.latitudeValid && settings.useGps
88 elevation: positionSource.position.coordinate.altitude
89 elevationValid: positionSource.position.altitudeValid && settings.useGps
90 orientation: orientation.orientation
91 artist: settings.creatorName
92 captureDirection: compass.direction
93 captureDirectionValid: compass.directionValid
94 horizontalError: positionSource.position.horizontalAccuracy
95 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
111 active: cam.running && settings.useGps && settings.useGeotags
137 imageSuffix: cam.imageSuffix
138 videoSuffix: cam.videoSuffix
143 path: fileNaming.path
151 if (!checkBattery()) {
152 pageStack.currentPage.batteryLow();
157 batteryMonitor.check();
161 batteryMonitor.check();
165 function replacePage(file) {
166 pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
169 function openFile(file) {
170 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer});
173 function openFileNow(file) {
174 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
177 function checkBattery() {
178 // We are fine if we are connected to the charger:
179 if (batteryMonitor.charging) {
183 // If we have enough battery then we are fine:
184 if (!batteryMonitor.critical) {
191 platformStyle: PageStackWindowStyle {
192 cornersVisible: false
194 backgroundColor: "transparent"
200 function setImageResolution() {
201 if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
202 showError(qsTr("Failed to set required resolution"));
208 imageSettings.setImageResolution();
217 function setVideoResolution() {
218 if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
219 showError(qsTr("Failed to set required resolution"));
225 videoSettings.setVideoResolution();
233 onImageAspectRatioChanged: {
234 imageSettings.setImageResolution();
237 onImageResolutionChanged: {
238 imageSettings.setImageResolution();
241 onVideoResolutionChanged: {
242 videoSettings.setVideoResolution();
253 width: cam.renderArea.width
254 height: cam.renderArea.height
255 visible: settings.gridEnabled
261 visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
262 cafStatus: cam ? cam.autoFocus.cafStatus : -1
263 status: cam ? cam.autoFocus.status : -1
268 // TODO: is this needed ?
269 if (platformWindow.active) {
275 if (pipelineManager.error) {
276 // Ignore any subsequent errors.
277 // Killing pulseaudio while recording will lead to an
278 // infinite supply of errors which will break the UI
279 // if we show a banner for each.
283 pipelineManager.error = true;
284 pageStack.currentPage.cameraError();
285 console.log("Camera error (" + code + "): " + message + " " + debug);
286 showError(qsTr("Camera error. Please restart the application."));
288 // We cannot stop camera here. Seems there is a race condition somewhere
289 // which leads to a freeze if we do so.
294 mountProtector.unlock();
298 Component.onDestruction: cam.stop();
300 // We need to show viewfinder below pages.
304 property bool dimmed: false
308 opacity: dimmed ? 1.0 : 0.0
310 Behavior on opacity {
311 PropertyAnimation { duration: 150 }
315 notifications: Sounds {
317 mute: !settings.soundEnabled
325 when: cam.mode == Camera.ImageMode
326 value: settings.imageFlashMode
331 property: "imageFlashMode"
332 when: cam.mode == Camera.ImageMode
333 value: cam.flash.value
339 when: cam.mode == Camera.VideoMode
340 value: settings.videoSceneMode
346 when: cam.mode == Camera.ImageMode
347 value: settings.imageSceneMode
353 when: cam.mode == Camera.ImageMode
354 value: settings.imageEvComp
360 when: cam.mode == Camera.VideoMode
361 value: settings.videoEvComp
366 property: "imageEvComp"
367 when: cam.mode == Camera.ImageMode
368 value: cam.evComp.value
373 property: "videoEvComp"
374 when: cam.mode == Camera.VideoMode
375 value: cam.evComp.value
379 target: cam.whiteBalance
381 when: cam.mode == Camera.ImageMode
382 value: settings.imageWhiteBalance
386 target: cam.whiteBalance
388 when: cam.mode == Camera.VideoMode
389 value: settings.videoWhiteBalance
393 target: cam.colorTone
395 when: cam.mode == Camera.ImageMode
396 value: settings.imageColorFilter
400 target: cam.colorTone
402 when: cam.mode == Camera.VideoMode
403 value: settings.videoColorFilter
409 when: cam.mode == Camera.ImageMode
410 value: settings.imageIso
416 when: cam.mode == Camera.ImageMode
421 target: cam.videoMute
423 value: settings.videoMuted
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.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)