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: grid lines, 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 visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
254 cafStatus: cam ? cam.autoFocus.cafStatus : -1
255 status: cam ? cam.autoFocus.status : -1
260 // TODO: is this needed ?
261 if (platformWindow.active) {
267 if (pipelineManager.error) {
268 // Ignore any subsequent errors.
269 // Killing pulseaudio while recording will lead to an
270 // infinite supply of errors which will break the UI
271 // if we show a banner for each.
275 pipelineManager.error = true;
276 pageStack.currentPage.cameraError();
277 console.log("Camera error (" + code + "): " + message + " " + debug);
278 showError(qsTr("Camera error. Please restart the application."));
280 // We cannot stop camera here. Seems there is a race condition somewhere
281 // which leads to a freeze if we do so.
286 mountProtector.unlock();
290 Component.onDestruction: cam.stop();
292 // We need to show viewfinder below pages.
296 property bool dimmed: false
300 opacity: dimmed ? 1.0 : 0.0
302 Behavior on opacity {
303 PropertyAnimation { duration: 150 }
307 notifications: Sounds {
309 mute: !settings.soundEnabled
317 when: cam.mode == Camera.ImageMode
318 value: settings.imageFlashMode
323 property: "imageFlashMode"
324 when: cam.mode == Camera.ImageMode
325 value: cam.flash.value
331 when: cam.mode == Camera.VideoMode
332 value: settings.videoSceneMode
338 when: cam.mode == Camera.ImageMode
339 value: settings.imageSceneMode
345 when: cam.mode == Camera.ImageMode
346 value: settings.imageEvComp
352 when: cam.mode == Camera.VideoMode
353 value: settings.videoEvComp
358 property: "imageEvComp"
359 when: cam.mode == Camera.ImageMode
360 value: cam.evComp.value
365 property: "videoEvComp"
366 when: cam.mode == Camera.VideoMode
367 value: cam.evComp.value
371 target: cam.whiteBalance
373 when: cam.mode == Camera.ImageMode
374 value: settings.imageWhiteBalance
378 target: cam.whiteBalance
380 when: cam.mode == Camera.VideoMode
381 value: settings.videoWhiteBalance
385 target: cam.colorTone
387 when: cam.mode == Camera.ImageMode
388 value: settings.imageColorFilter
392 target: cam.colorTone
394 when: cam.mode == Camera.VideoMode
395 value: settings.videoColorFilter
401 when: cam.mode == Camera.ImageMode
402 value: settings.imageIso
408 when: cam.mode == Camera.ImageMode
413 target: cam.videoMute
415 value: settings.videoMuted
421 manufacturer: deviceInfo.manufacturer
422 model: deviceInfo.model
434 if (cam.mode == Camera.VideoMode) {
435 replacePage("VideoPage.qml");
438 replacePage("ImagePage.qml");
444 policyLost: pipelineManager.state == "policyLost"
445 show: !pageStack.currentPage || (pageStack.currentPage.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)