ISO settings are now functional
[harmattan/cameraplus] / qml / main.qml
1 // -*- qml -*-
2 import QtQuick 1.1
3 import com.nokia.meego 1.1
4 import com.nokia.extras 1.1
5 import QtCamera 1.0
6 import CameraPlus 1.0
7 import QtMobility.systeminfo 1.2
8 import QtMobility.location 1.2
9
10 // TODO: resolutions and aspect ratios
11 // TODO: postcapture
12 // TODO: battery low state
13 // TODO: disk space
14 // TODO: flash not ready
15 // TODO: focus, caf, ...
16 // TODO: indicators
17 // TODO: portrait/landscape
18 // TODO: record video in a hidden directory and then copy the video to avoid tracker indexing it.
19 // TODO: stop viewfinder in settings pages ?
20 // TODO: prevent going to mass storage while recording and capturing
21 // TODO: sounds
22 // TODO: grid lines, face tracking, ambr
23 // TODO: complete settings pages
24 // TODO: stop camera properly when we get closed.
25 // TODO: select primary/secondary camera.
26 // TODO: disable debug builds.
27 // TODO: a way to get buffers to the application
28 // TODO: fcam like functionality (precise control over capture parameters).
29
30 PageStackWindow {
31         id: root
32
33         property alias dimmer: camDimmer
34
35         showStatusBar: false
36
37         Component.onCompleted: {
38                 theme.inverted = true;
39                 if (settings.mode == 0) {
40                         openFile("ImagePage.qml");
41                 }
42                 else {
43                         openFile("VideoPage.qml");
44                 }
45         }
46
47         function showError(msg) {
48                 error.text = msg;
49                 error.show();
50         }
51
52         PositionSource {
53                 id: positionSource
54                 active: cam.running && settings.useGps
55                 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
56         }
57
58         MetaData {
59                 id: metaData
60                 camera: cam
61                 manufacturer: deviceInfo.manufacturer
62                 model: deviceInfo.model
63                 country: geocode.country
64                 city: geocode.city
65                 suburb: geocode.suburb
66                 longitude: positionSource.position.coordinate.longitude
67                 longitudeValid: positionSource.position.longitudeValid && settings.useGps
68                 latitude: positionSource.position.coordinate.latitude
69                 latitudeValid: positionSource.position.latitudeValid && settings.useGps
70                 elevation: positionSource.position.coordinate.altitude
71                 elevationValid: positionSource.position.altitudeValid && settings.useGps
72                 orientation: orientation.orientation
73                 artist: settings.creatorName
74                 captureDirection: compass.direction
75                 captureDirectionValid: compass.directionValid
76                 horizontalError: positionSource.position.horizontalAccuracy
77                 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
78                 dateTimeEnabled: true
79         }
80
81         Orientation {
82                 id: orientation
83                 active: cam.running
84         }
85
86         Compass {
87                 id: compass
88                 active: cam.running
89         }
90
91         ReverseGeocode {
92                 id: geocode
93                 active: cam.running && settings.useGps && settings.useGeotags
94         }
95
96         CameraResources {
97                 id: resourcePolicy
98                 onAcquiredChanged: {
99                         if (resourcePolicy.acquired) {
100                                 // TODO:
101                         }
102                         else {
103                                 // TODO: We need a way to force a stop.
104                         }
105                 }
106         }
107
108         DeviceInfo {
109                 id: deviceInfo
110         }
111
112         FSMonitor {
113                 id: fileSystem
114         }
115
116         InfoBanner {
117                 id: error
118         }
119
120         Settings {
121                 id: settings
122         }
123
124         FileNaming {
125                 id: fileNaming
126                 imageSuffix: cam.imageSuffix
127                 videoSuffix: cam.videoSuffix
128         }
129
130         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
131         function replacePage(file) {
132                 var component = Qt.createComponent(file)
133
134                 if (component.status == Component.Ready) {
135                         pageStack.replace(component, {cam: cam}, true);
136                 }
137                 else {
138                         console.log("Error loading component:", component.errorString());
139                 }
140         }
141
142         function openFile(file) {
143                 var component = Qt.createComponent(file)
144
145                 if (component.status == Component.Ready) {
146                         pageStack.push(component, {cam: cam});
147                 }
148                 else {
149                         console.log("Error loading component:", component.errorString());
150                 }
151         }
152
153         platformStyle: PageStackWindowStyle {
154                 // TODO: Hack
155                 background: " "
156         }
157
158         Camera {
159 /*
160                 onDeviceIdChanged: {
161                         // TODO: is this needed ?
162                         if (platformWindow.active) {
163                                 cam.start();
164                         }
165                 }
166 */
167                 id: cam
168                 anchors.fill: parent
169
170                 onError: {
171                         console.log("Camera error (" + code + "): " + message + " " + debug);
172                         showError(qsTr("Camera error. Please restart the application."));
173                         cam.stop();
174                 }
175
176                 // TODO: hardcoding device id
177                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
178
179                 // TODO: Hack
180                 z: -1
181
182                 Rectangle {
183                         id: camDimmer
184                         z: 1
185                         anchors.fill: parent
186                         opacity: 0
187                         color: "black"
188                 }
189         }
190
191         Scene {
192                 id: sceneController
193                 camera: cam
194                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
195         }
196
197         ColorTone {
198                 id: colorToneController
199                 camera: cam
200                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
201         }
202
203         WhiteBalance {
204                 id: whiteBalanceController
205                 camera: cam
206                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
207         }
208
209         ModeController {
210                 id: cameraMode
211                 cam: cam
212                 dimmer: root.dimmer
213         }
214
215         Iso {
216                 id: iso
217                 camera: cam
218                 value: ready ? settings.imageIso : 0
219         }
220
221         Connections {
222                 target: cam
223                 onModeChanged: {
224                         if (cam.mode == Camera.VideoMode) {
225                                 replacePage("VideoPage.qml");
226                         }
227                         else {
228                                 replacePage("ImagePage.qml");
229                         }
230                 }
231         }
232 }