low space handling:
[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: record video in a hidden directory and then copy the video to avoid tracker indexing it.
36 // TODO: stop viewfinder in settings pages ?
37 // TODO: prevent going to mass storage while recording and capturing
38 // TODO: grid lines, face tracking, ambr
39 // TODO: complete settings pages
40 // TODO: stop camera properly when we get closed.
41 // TODO: select primary/secondary camera.
42 // TODO: disable debug builds.
43 // TODO: a way to get buffers to the application
44 // TODO: fcam like functionality (precise control over capture parameters).
45
46 PageStackWindow {
47         id: root
48
49         property alias dimmer: camDimmer
50
51         showStatusBar: false
52
53         Component.onCompleted: {
54                 theme.inverted = true;
55                 if (settings.mode == 0) {
56                         openFile("ImagePage.qml");
57                 }
58                 else {
59                         openFile("VideoPage.qml");
60                 }
61         }
62
63         function showError(msg) {
64                 error.text = msg;
65                 error.show();
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                 onAcquiredChanged: {
121                         if (resourcePolicy.acquired) {
122                                 // TODO:
123                         }
124                         else {
125                                 // TODO: We need a way to force a stop.
126                         }
127                 }
128         }
129
130         DeviceInfo {
131                 id: deviceInfo
132         }
133
134         FSMonitor {
135                 id: fileSystem
136         }
137
138         InfoBanner {
139                 id: error
140         }
141
142         Settings {
143                 id: settings
144         }
145
146         FileNaming {
147                 id: fileNaming
148                 imageSuffix: cam.imageSuffix
149                 videoSuffix: cam.videoSuffix
150         }
151
152         function replacePage(file) {
153                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
154         }
155
156         function openFile(file) {
157                 pageStack.push(Qt.resolvedUrl(file), {cam: cam});
158         }
159
160         platformStyle: PageStackWindowStyle {
161                 // TODO: Hack
162                 background: " "
163         }
164
165         ImageSettings {
166                 id: imageSettings
167                 camera: cam
168                 function setImageResolution() {
169                         if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
170                                 showError(qsTr("Failed to set required resolution"));
171                         }
172                 }
173
174                 onReadyChanged: {
175                         if (ready) {
176                                 imageSettings.setImageResolution();
177                         }
178                 }
179         }
180
181         VideoSettings {
182                 id: videoSettings
183                 camera: cam
184
185                 function setVideoResolution() {
186                         if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
187                                 showError(qsTr("Failed to set required resolution"));
188                         }
189                 }
190
191                 onReadyChanged: {
192                         if (ready) {
193                                 videoSettings.setVideoResolution();
194                         }
195                 }
196         }
197
198         Connections {
199                 target: settings
200
201                 onImageAspectRatioChanged: {
202                         imageSettings.setImageResolution();
203                 }
204
205                 onImageResolutionChanged: {
206                         imageSettings.setImageResolution();
207                 }
208
209                 onVideoResolutionChanged: {
210                         videoSettings.setVideoResolution();
211                 }
212         }
213
214         Camera {
215 /*
216                 onDeviceIdChanged: {
217                         // TODO: is this needed ?
218                         if (platformWindow.active) {
219                                 cam.start();
220                         }
221                 }
222 */
223                 id: cam
224                 anchors.fill: parent
225
226                 onError: {
227                         console.log("Camera error (" + code + "): " + message + " " + debug);
228                         showError(qsTr("Camera error. Please restart the application."));
229                         cam.stop();
230                 }
231
232                 // TODO: hardcoding device id
233                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
234                 Component.onDestruction: {
235                 console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
236                 }
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         Scene {
256                 id: sceneController
257                 camera: cam
258                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
259         }
260
261         ColorTone {
262                 id: colorToneController
263                 camera: cam
264                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
265         }
266
267         WhiteBalance {
268                 id: whiteBalanceController
269                 camera: cam
270                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
271         }
272
273         ModeController {
274                 id: cameraMode
275                 cam: cam
276                 dimmer: root.dimmer
277         }
278
279         Iso {
280                 id: iso
281                 camera: cam
282                 value: ready ? settings.imageIso : 0
283         }
284
285         Connections {
286                 target: cam
287                 onModeChanged: {
288                         if (cam.mode == Camera.VideoMode) {
289                                 replacePage("VideoPage.qml");
290                         }
291                         else {
292                                 replacePage("ImagePage.qml");
293                         }
294                 }
295         }
296 }