style fix
[harmattan/cameraplus] / qml / main.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
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.
12  *
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.
17  *
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
21  */
22
23 import QtQuick 1.1
24 import com.nokia.meego 1.1
25 import com.nokia.extras 1.1
26 import QtCamera 1.0
27 import CameraPlus 1.0
28 import QtMobility.systeminfo 1.2
29 import QtMobility.location 1.2
30
31 // TODO: postcapture
32 // TODO: flash not ready (battery low or flash not ready message)
33 // TODO: portrait/landscape
34 // TODO: grid lines, face tracking
35 // TODO: select primary/secondary camera.
36 // TODO: disable debug builds.
37 // TODO: a way to get buffers to the application
38 // TODO: fcam like functionality (precise control over capture parameters).
39
40 PageStackWindow {
41         id: root
42
43         property alias dimmer: camDimmer
44
45         showStatusBar: false
46
47         Component.onCompleted: {
48                 theme.inverted = true;
49                 // TODO: hardcoding device id
50                 root.resetCamera(0, settings.mode);
51         }
52
53         function showError(msg) {
54                 error.text = msg;
55                 error.show();
56         }
57
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."));
61                 }
62         }
63
64         PositionSource {
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.
68                 id: positionSource
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);
74         }
75
76         MetaData {
77                 id: metaData
78                 camera: cam
79                 manufacturer: deviceInfo.manufacturer
80                 model: deviceInfo.model
81                 country: geocode.country
82                 city: geocode.city
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
96                 dateTimeEnabled: true
97         }
98
99         Orientation {
100                 id: orientation
101                 active: cam.running
102         }
103
104         Compass {
105                 id: compass
106                 active: cam.running
107         }
108
109         ReverseGeocode {
110                 id: geocode
111                 active: cam.running && settings.useGps && settings.useGeotags
112         }
113
114         PipelineManager {
115                 id: pipelineManager
116                 camera: cam
117         }
118
119         DeviceInfo {
120                 id: deviceInfo
121         }
122
123         FSMonitor {
124                 id: fileSystem
125         }
126
127         InfoBanner {
128                 id: error
129         }
130
131         Settings {
132                 id: settings
133         }
134
135         FileNaming {
136                 id: fileNaming
137                 imageSuffix: cam.imageSuffix
138                 videoSuffix: cam.videoSuffix
139         }
140
141         MountProtector {
142                 id: mountProtector
143                 path: fileNaming.path
144         }
145
146         function replacePage(file) {
147                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
148         }
149
150         function openFile(file) {
151                 pageStack.push(Qt.resolvedUrl(file), {cam: cam});
152         }
153
154         function openFileNow(file) {
155                 pageStack.push(Qt.resolvedUrl(file), {cam: cam}, true);
156         }
157
158         platformStyle: PageStackWindowStyle {
159                 cornersVisible: false
160                 background: ""
161                 backgroundColor: "transparent"
162         }
163
164         ImageSettings {
165                 id: imageSettings
166                 camera: cam
167                 function setImageResolution() {
168                         if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
169                                 showError(qsTr("Failed to set required resolution"));
170                         }
171                 }
172
173                 onReadyChanged: {
174                         if (ready) {
175                                 imageSettings.setImageResolution();
176                         }
177                 }
178         }
179
180         VideoSettings {
181                 id: videoSettings
182                 camera: cam
183
184                 function setVideoResolution() {
185                         if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
186                                 showError(qsTr("Failed to set required resolution"));
187                         }
188                 }
189
190                 onReadyChanged: {
191                         if (ready) {
192                                 videoSettings.setVideoResolution();
193                         }
194                 }
195         }
196
197         Connections {
198                 target: settings
199
200                 onImageAspectRatioChanged: {
201                         imageSettings.setImageResolution();
202                 }
203
204                 onImageResolutionChanged: {
205                         imageSettings.setImageResolution();
206                 }
207
208                 onVideoResolutionChanged: {
209                         videoSettings.setVideoResolution();
210                 }
211         }
212
213         Camera {
214                 id: cam
215                 anchors.fill: parent
216
217                 FocusReticle {
218                         id: focusReticle
219                         cam: cam
220                         visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
221                         cafStatus: cam ? cam.autoFocus.cafStatus : -1
222                         status: cam ? cam.autoFocus.status : -1
223                 }
224
225 /*
226                 onDeviceIdChanged: {
227                         // TODO: is this needed ?
228                         if (platformWindow.active) {
229                                 cam.start();
230                         }
231                 }
232 */
233                 onError: {
234                         if (pipelineManager.error) {
235                                 // Ignore any subsequent errors.
236                                 // Killing pulseaudio while recording will lead to an
237                                 // infinite supply of errors which will break the UI
238                                 // if we show a banner for each.
239                                 return;
240                         }
241
242                         pipelineManager.error = true;
243                         pageStack.currentPage.cameraError();
244                         console.log("Camera error (" + code + "): " + message + " " + debug);
245                         showError(qsTr("Camera error. Please restart the application."));
246
247                         // We cannot stop camera here. Seems there is a race condition somewhere
248                         // which leads to a freeze if we do so.
249                 }
250
251                 onRunningChanged: {
252                         if (!cam.running) {
253                                 mountProtector.unlock();
254                         }
255                 }
256
257                 Component.onDestruction: cam.stop();
258
259                 // We need to show viewfinder below pages.
260                 z: -1
261
262                 Rectangle {
263                         id: camDimmer
264                         z: 1
265                         anchors.fill: parent
266                         opacity: 0
267                         color: "black"
268                 }
269
270                 notifications: Sounds {
271                         id: sounds
272                         mute: !settings.soundEnabled
273                 }
274
275         }
276
277         Binding {
278                 target: cam.flash
279                 property: "value"
280                 when: cam.mode == Camera.ImageMode
281                 value: settings.imageFlashMode
282         }
283
284         Binding {
285                 target: settings
286                 property: "imageFlashMode"
287                 when: cam.mode == Camera.ImageMode
288                 value: cam.flash.value
289         }
290
291         Binding {
292                 target: cam.scene
293                 property: "value"
294                 when: cam.mode == Camera.VideoMode
295                 value: settings.videoSceneMode
296         }
297
298         Binding {
299                 target: cam.scene
300                 property: "value"
301                 when: cam.mode == Camera.ImageMode
302                 value: settings.imageSceneMode
303         }
304
305         Binding {
306                 target: cam.evComp
307                 property: "value"
308                 when: cam.mode == Camera.ImageMode
309                 value: settings.imageEvComp
310         }
311
312         Binding {
313                 target: cam.evComp
314                 property: "value"
315                 when: cam.mode == Camera.VideoMode
316                 value: settings.videoEvComp
317         }
318
319         Binding {
320                 target: settings
321                 property: "imageEvComp"
322                 when: cam.mode == Camera.ImageMode
323                 value: cam.evComp.value
324         }
325
326         Binding {
327                 target: settings
328                 property: "videoEvComp"
329                 when: cam.mode == Camera.VideoMode
330                 value: cam.evComp.value
331         }
332
333         Binding {
334                 target: cam.whiteBalance
335                 property: "value"
336                 when: cam.mode == Camera.ImageMode
337                 value: settings.imageWhiteBalance
338         }
339
340         Binding {
341                 target: cam.whiteBalance
342                 property: "value"
343                 when: cam.mode == Camera.VideoMode
344                 value: settings.videoWhiteBalance
345         }
346
347         Binding {
348                 target: cam.colorTone
349                 property: "value"
350                 when: cam.mode == Camera.ImageMode
351                 value: settings.imageColorFilter
352         }
353
354         Binding {
355                 target: cam.colorTone
356                 property: "value"
357                 when: cam.mode == Camera.VideoMode
358                 value: settings.videoColorFilter
359         }
360
361         Binding {
362                 target: cam.iso
363                 property: "value"
364                 when: cam.mode == Camera.ImageMode
365                 value: settings.imageIso
366         }
367
368         Binding {
369                 target: settings
370                 property: "imageIso"
371                 when: cam.mode == Camera.ImageMode
372                 value: cam.iso.value
373         }
374
375         Binding {
376                 target: cam.videoMute
377                 property: "enabled"
378                 value: settings.videoMuted
379         }
380
381         TrackerStore {
382                 id: trackerStore
383                 active: cam.running
384                 manufacturer: deviceInfo.manufacturer
385                 model: deviceInfo.model
386         }
387
388         ModeController {
389                 id: cameraMode
390                 cam: cam
391                 dimmer: root.dimmer
392         }
393
394         Connections {
395                 target: cam
396                 onModeChanged: {
397                         if (cam.mode == Camera.VideoMode) {
398                                 replacePage("VideoPage.qml");
399                         }
400                         else {
401                                 replacePage("ImagePage.qml");
402                         }
403                 }
404         }
405
406         Standby {
407                 policyLost: pipelineManager.state == "policyLost"
408                 show: !pageStack.currentPage || (pageStack.currentPage.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)
409         }
410 }