Added a sounds component that implements the Notifications interface and is used to
[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: battery low state
33 // TODO: disk space
34 // TODO: flash not ready
35 // TODO: focus, caf, ...
36 // TODO: portrait/landscape
37 // TODO: record video in a hidden directory and then copy the video to avoid tracker indexing it.
38 // TODO: stop viewfinder in settings pages ?
39 // TODO: prevent going to mass storage while recording and capturing
40 // TODO: grid lines, face tracking, ambr
41 // TODO: complete settings pages
42 // TODO: stop camera properly when we get closed.
43 // TODO: select primary/secondary camera.
44 // TODO: disable debug builds.
45 // TODO: a way to get buffers to the application
46 // TODO: fcam like functionality (precise control over capture parameters).
47
48 PageStackWindow {
49         id: root
50
51         property alias dimmer: camDimmer
52
53         showStatusBar: false
54
55         Component.onCompleted: {
56                 theme.inverted = true;
57                 if (settings.mode == 0) {
58                         openFile("ImagePage.qml");
59                 }
60                 else {
61                         openFile("VideoPage.qml");
62                 }
63         }
64
65         function showError(msg) {
66                 error.text = msg;
67                 error.show();
68         }
69
70         PositionSource {
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                 onAcquiredChanged: {
120                         if (resourcePolicy.acquired) {
121                                 // TODO:
122                         }
123                         else {
124                                 // TODO: We need a way to force a stop.
125                         }
126                 }
127         }
128
129         DeviceInfo {
130                 id: deviceInfo
131         }
132
133         FSMonitor {
134                 id: fileSystem
135         }
136
137         InfoBanner {
138                 id: error
139         }
140
141         Settings {
142                 id: settings
143         }
144
145         FileNaming {
146                 id: fileNaming
147                 imageSuffix: cam.imageSuffix
148                 videoSuffix: cam.videoSuffix
149         }
150
151         function replacePage(file) {
152                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
153         }
154
155         function openFile(file) {
156                 pageStack.push(Qt.resolvedUrl(file), {cam: cam});
157         }
158
159         platformStyle: PageStackWindowStyle {
160                 // TODO: Hack
161                 background: " "
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 /*
215                 onDeviceIdChanged: {
216                         // TODO: is this needed ?
217                         if (platformWindow.active) {
218                                 cam.start();
219                         }
220                 }
221 */
222                 id: cam
223                 anchors.fill: parent
224
225                 onError: {
226                         console.log("Camera error (" + code + "): " + message + " " + debug);
227                         showError(qsTr("Camera error. Please restart the application."));
228                         cam.stop();
229                 }
230
231                 // TODO: hardcoding device id
232                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
233                 Component.onDestruction: {
234                 console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
235                 }
236
237                 // TODO: Hack
238                 z: -1
239
240                 Rectangle {
241                         id: camDimmer
242                         z: 1
243                         anchors.fill: parent
244                         opacity: 0
245                         color: "black"
246                 }
247
248                 notifications: Sounds {
249                         id: sounds
250                 }
251         }
252
253         Scene {
254                 id: sceneController
255                 camera: cam
256                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
257         }
258
259         ColorTone {
260                 id: colorToneController
261                 camera: cam
262                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
263         }
264
265         WhiteBalance {
266                 id: whiteBalanceController
267                 camera: cam
268                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
269         }
270
271         ModeController {
272                 id: cameraMode
273                 cam: cam
274                 dimmer: root.dimmer
275         }
276
277         Iso {
278                 id: iso
279                 camera: cam
280                 value: ready ? settings.imageIso : 0
281         }
282
283         Connections {
284                 target: cam
285                 onModeChanged: {
286                         if (cam.mode == Camera.VideoMode) {
287                                 replacePage("VideoPage.qml");
288                         }
289                         else {
290                                 replacePage("ImagePage.qml");
291                         }
292                 }
293         }
294 }