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