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