Settings for aspect ration and resolution can now read from and save to the configuration
[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: resolutions and aspect ratios
32 // TODO: postcapture
33 // TODO: battery low state
34 // TODO: disk space
35 // TODO: flash not ready
36 // TODO: focus, caf, ...
37 // TODO: portrait/landscape
38 // TODO: record video in a hidden directory and then copy the video to avoid tracker indexing it.
39 // TODO: stop viewfinder in settings pages ?
40 // TODO: prevent going to mass storage while recording and capturing
41 // TODO: sounds
42 // TODO: grid lines, face tracking, ambr
43 // TODO: complete settings pages
44 // TODO: stop camera properly when we get closed.
45 // TODO: select primary/secondary camera.
46 // TODO: disable debug builds.
47 // TODO: a way to get buffers to the application
48 // TODO: fcam like functionality (precise control over capture parameters).
49
50 PageStackWindow {
51         id: root
52
53         property alias dimmer: camDimmer
54
55         showStatusBar: false
56
57         Component.onCompleted: {
58                 theme.inverted = true;
59                 if (settings.mode == 0) {
60                         openFile("ImagePage.qml");
61                 }
62                 else {
63                         openFile("VideoPage.qml");
64                 }
65         }
66
67         function showError(msg) {
68                 error.text = msg;
69                 error.show();
70         }
71
72         PositionSource {
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                 onAcquiredChanged: {
122                         if (resourcePolicy.acquired) {
123                                 // TODO:
124                         }
125                         else {
126                                 // TODO: We need a way to force a stop.
127                         }
128                 }
129         }
130
131         DeviceInfo {
132                 id: deviceInfo
133         }
134
135         FSMonitor {
136                 id: fileSystem
137         }
138
139         InfoBanner {
140                 id: error
141         }
142
143         Settings {
144                 id: settings
145         }
146
147         FileNaming {
148                 id: fileNaming
149                 imageSuffix: cam.imageSuffix
150                 videoSuffix: cam.videoSuffix
151         }
152
153         function replacePage(file) {
154                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
155         }
156
157         function openFile(file) {
158                 pageStack.push(Qt.resolvedUrl(file), {cam: cam});
159         }
160
161         platformStyle: PageStackWindowStyle {
162                 // TODO: Hack
163                 background: " "
164         }
165
166         ImageSettings {
167                 id: imageSettings
168                 camera: cam
169         }
170
171         Camera {
172 /*
173                 onDeviceIdChanged: {
174                         // TODO: is this needed ?
175                         if (platformWindow.active) {
176                                 cam.start();
177                         }
178                 }
179 */
180                 id: cam
181                 anchors.fill: parent
182
183                 onError: {
184                         console.log("Camera error (" + code + "): " + message + " " + debug);
185                         showError(qsTr("Camera error. Please restart the application."));
186                         cam.stop();
187                 }
188
189                 // TODO: hardcoding device id
190                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
191
192                 // TODO: Hack
193                 z: -1
194
195                 Rectangle {
196                         id: camDimmer
197                         z: 1
198                         anchors.fill: parent
199                         opacity: 0
200                         color: "black"
201                 }
202         }
203
204         Scene {
205                 id: sceneController
206                 camera: cam
207                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
208         }
209
210         ColorTone {
211                 id: colorToneController
212                 camera: cam
213                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
214         }
215
216         WhiteBalance {
217                 id: whiteBalanceController
218                 camera: cam
219                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
220         }
221
222         ModeController {
223                 id: cameraMode
224                 cam: cam
225                 dimmer: root.dimmer
226         }
227
228         Iso {
229                 id: iso
230                 camera: cam
231                 value: ready ? settings.imageIso : 0
232         }
233
234         Connections {
235                 target: cam
236                 onModeChanged: {
237                         if (cam.mode == Camera.VideoMode) {
238                                 replacePage("VideoPage.qml");
239                         }
240                         else {
241                                 replacePage("ImagePage.qml");
242                         }
243                 }
244         }
245 }