fb484fb842b1d50fc7861aff9af1b3139e777600
[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
33 // TODO: focus, caf, ...
34 // TODO: portrait/landscape
35 // TODO: stop viewfinder in settings pages ?
36 // TODO: grid lines, face tracking, ambr
37 // TODO: complete settings pages
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).
42
43 PageStackWindow {
44         id: root
45
46         property alias dimmer: camDimmer
47
48         showStatusBar: false
49
50         Component.onCompleted: {
51                 theme.inverted = true;
52                 // TODO: hardcoding device id
53                 root.resetCamera(0, settings.mode);
54         }
55
56         function showError(msg) {
57                 error.text = msg;
58                 error.show();
59         }
60
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."));
64                 }
65         }
66
67         PositionSource {
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.
71                 id: positionSource
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);
77         }
78
79         MetaData {
80                 id: metaData
81                 camera: cam
82                 manufacturer: deviceInfo.manufacturer
83                 model: deviceInfo.model
84                 country: geocode.country
85                 city: geocode.city
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
99                 dateTimeEnabled: true
100         }
101
102         Orientation {
103                 id: orientation
104                 active: cam.running
105         }
106
107         Compass {
108                 id: compass
109                 active: cam.running
110         }
111
112         ReverseGeocode {
113                 id: geocode
114                 active: cam.running && settings.useGps && settings.useGeotags
115         }
116
117         CameraResources {
118                 id: resourcePolicy
119         }
120
121         DeviceInfo {
122                 id: deviceInfo
123         }
124
125         FSMonitor {
126                 id: fileSystem
127         }
128
129         InfoBanner {
130                 id: error
131         }
132
133         Settings {
134                 id: settings
135         }
136
137         FileNaming {
138                 id: fileNaming
139                 imageSuffix: cam.imageSuffix
140                 videoSuffix: cam.videoSuffix
141         }
142
143         MountProtector {
144                 id: mountProtector
145                 path: fileNaming.path
146         }
147
148         function replacePage(file) {
149                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
150         }
151
152         function openFile(file) {
153                 pageStack.push(Qt.resolvedUrl(file), {cam: cam});
154         }
155
156         platformStyle: PageStackWindowStyle {
157                 // TODO: Hack
158                 background: " "
159         }
160
161         ImageSettings {
162                 id: imageSettings
163                 camera: cam
164                 function setImageResolution() {
165                         if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
166                                 showError(qsTr("Failed to set required resolution"));
167                         }
168                 }
169
170                 onReadyChanged: {
171                         if (ready) {
172                                 imageSettings.setImageResolution();
173                         }
174                 }
175         }
176
177         VideoSettings {
178                 id: videoSettings
179                 camera: cam
180
181                 function setVideoResolution() {
182                         if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
183                                 showError(qsTr("Failed to set required resolution"));
184                         }
185                 }
186
187                 onReadyChanged: {
188                         if (ready) {
189                                 videoSettings.setVideoResolution();
190                         }
191                 }
192         }
193
194         Connections {
195                 target: settings
196
197                 onImageAspectRatioChanged: {
198                         imageSettings.setImageResolution();
199                 }
200
201                 onImageResolutionChanged: {
202                         imageSettings.setImageResolution();
203                 }
204
205                 onVideoResolutionChanged: {
206                         videoSettings.setVideoResolution();
207                 }
208         }
209
210         Camera {
211 /*
212                 onDeviceIdChanged: {
213                         // TODO: is this needed ?
214                         if (platformWindow.active) {
215                                 cam.start();
216                         }
217                 }
218 */
219                 id: cam
220                 anchors.fill: parent
221
222                 onError: {
223                         console.log("Camera error (" + code + "): " + message + " " + debug);
224                         showError(qsTr("Camera error. Please restart the application."));
225                         cam.stop();
226                         resourcePolicy.acquire(CameraResources.None);
227                         mountProtector.unlock();
228                 }
229
230                 onRunningChanged: {
231                         if (!cam.running) {
232                                 mountProtector.unlock();
233                         }
234                 }
235
236                 Component.onDestruction: cam.stop();
237
238                 // TODO: Hack
239                 z: -1
240
241                 Rectangle {
242                         id: camDimmer
243                         z: 1
244                         anchors.fill: parent
245                         opacity: 0
246                         color: "black"
247                 }
248
249                 notifications: Sounds {
250                         id: sounds
251                         mute: !settings.soundEnabled
252                 }
253
254         }
255
256         Binding {
257                 target: cam.flash
258                 property: "value"
259                 when: cam.mode == Camera.ImageMode
260                 value: settings.imageFlashMode
261         }
262
263         Binding {
264                 target: settings
265                 property: "imageFlashMode"
266                 when: cam.mode == Camera.ImageMode
267                 value: cam.flash.value
268         }
269
270         Binding {
271                 target: cam.scene
272                 property: "value"
273                 when: cam.mode == Camera.VideoMode
274                 value: settings.videoSceneMode
275         }
276
277         Binding {
278                 target: cam.scene
279                 property: "value"
280                 when: cam.mode == Camera.ImageMode
281                 value: settings.imageSceneMode
282         }
283
284         Binding {
285                 target: cam.evComp
286                 property: "value"
287                 when: cam.mode == Camera.ImageMode
288                 value: settings.imageEvComp
289         }
290
291         Binding {
292                 target: cam.evComp
293                 property: "value"
294                 when: cam.mode == Camera.VideoMode
295                 value: settings.videoEvComp
296         }
297
298         Binding {
299                 target: settings
300                 property: "imageEvComp"
301                 when: cam.mode == Camera.ImageMode
302                 value: cam.evComp.value
303         }
304
305         Binding {
306                 target: settings
307                 property: "videoEvComp"
308                 when: cam.mode == Camera.VideoMode
309                 value: cam.evComp.value
310         }
311
312         Binding {
313                 target: cam.whiteBalance
314                 property: "value"
315                 when: cam.mode == Camera.ImageMode
316                 value: settings.imageWhiteBalance
317         }
318
319         Binding {
320                 target: cam.whiteBalance
321                 property: "value"
322                 when: cam.mode == Camera.VideoMode
323                 value: settings.videoWhiteBalance
324         }
325
326         Binding {
327                 target: cam.colorTone
328                 property: "value"
329                 when: cam.mode == Camera.ImageMode
330                 value: settings.imageColorFilter
331         }
332
333         Binding {
334                 target: cam.colorTone
335                 property: "value"
336                 when: cam.mode == Camera.VideoMode
337                 value: settings.videoColorFilter
338         }
339
340         Binding {
341                 target: cam.iso
342                 property: "value"
343                 when: cam.mode == Camera.ImageMode
344                 value: settings.imageIso
345         }
346
347         Binding {
348                 target: settings
349                 property: "imageIso"
350                 when: cam.mode == Camera.ImageMode
351                 value: cam.iso.value
352         }
353
354         ModeController {
355                 id: cameraMode
356                 cam: cam
357                 dimmer: root.dimmer
358         }
359
360         Connections {
361                 target: cam
362                 onModeChanged: {
363                         if (cam.mode == Camera.VideoMode) {
364                                 replacePage("VideoPage.qml");
365                         }
366                         else {
367                                 replacePage("ImagePage.qml");
368                         }
369                 }
370         }
371 }