19166c8f74767bfcdf6ef955d2209249fa0e29d9
[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: settings.useGps
55                 // TODO: we cannot bind to cam.running because camera will stop
56                 // when the connection dialog pops up and we end up with an infinite loop
57                 // active: cam.running && settings.useGps
58                 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
59         }
60
61         MetaData {
62                 id: metaData
63                 camera: cam
64                 manufacturer: deviceInfo.manufacturer
65                 model: deviceInfo.model
66                 country: geocode.country
67                 city: geocode.city
68                 suburb: geocode.suburb
69                 longitude: positionSource.position.coordinate.longitude
70                 longitudeValid: positionSource.position.longitudeValid && settings.useGps
71                 latitude: positionSource.position.coordinate.latitude
72                 latitudeValid: positionSource.position.latitudeValid && settings.useGps
73                 elevation: positionSource.position.coordinate.altitude
74                 elevationValid: positionSource.position.altitudeValid && settings.useGps
75                 orientation: orientation.orientation
76                 artist: settings.creatorName
77                 captureDirection: compass.direction
78                 captureDirectionValid: compass.directionValid
79                 horizontalError: positionSource.position.horizontalAccuracy
80                 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
81                 dateTimeEnabled: true
82         }
83
84         Orientation {
85                 id: orientation
86                 active: cam.running
87         }
88
89         Compass {
90                 id: compass
91                 active: cam.running
92         }
93
94         ReverseGeocode {
95                 id: geocode
96                 active: cam.running && settings.useGps && settings.useGeotags
97         }
98
99         CameraResources {
100                 id: resourcePolicy
101                 onAcquiredChanged: {
102                         if (resourcePolicy.acquired) {
103                                 // TODO:
104                         }
105                         else {
106                                 // TODO: We need a way to force a stop.
107                         }
108                 }
109         }
110
111         DeviceInfo {
112                 id: deviceInfo
113         }
114
115         FSMonitor {
116                 id: fileSystem
117         }
118
119         InfoBanner {
120                 id: error
121         }
122
123         Settings {
124                 id: settings
125         }
126
127         FileNaming {
128                 id: fileNaming
129                 imageSuffix: cam.imageSuffix
130                 videoSuffix: cam.videoSuffix
131         }
132
133         function replacePage(file) {
134                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
135         }
136
137         function openFile(file) {
138                 pageStack.push(Qt.resolvedUrl(file), {cam: cam});
139         }
140
141         platformStyle: PageStackWindowStyle {
142                 // TODO: Hack
143                 background: " "
144         }
145
146         Camera {
147 /*
148                 onDeviceIdChanged: {
149                         // TODO: is this needed ?
150                         if (platformWindow.active) {
151                                 cam.start();
152                         }
153                 }
154 */
155                 id: cam
156                 anchors.fill: parent
157
158                 onError: {
159                         console.log("Camera error (" + code + "): " + message + " " + debug);
160                         showError(qsTr("Camera error. Please restart the application."));
161                         cam.stop();
162                 }
163
164                 // TODO: hardcoding device id
165                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
166
167                 // TODO: Hack
168                 z: -1
169
170                 Rectangle {
171                         id: camDimmer
172                         z: 1
173                         anchors.fill: parent
174                         opacity: 0
175                         color: "black"
176                 }
177         }
178
179         Scene {
180                 id: sceneController
181                 camera: cam
182                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
183         }
184
185         ColorTone {
186                 id: colorToneController
187                 camera: cam
188                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
189         }
190
191         WhiteBalance {
192                 id: whiteBalanceController
193                 camera: cam
194                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
195         }
196
197         ModeController {
198                 id: cameraMode
199                 cam: cam
200                 dimmer: root.dimmer
201         }
202
203         Iso {
204                 id: iso
205                 camera: cam
206                 value: ready ? settings.imageIso : 0
207         }
208
209         Connections {
210                 target: cam
211                 onModeChanged: {
212                         if (cam.mode == Camera.VideoMode) {
213                                 replacePage("VideoPage.qml");
214                         }
215                         else {
216                                 replacePage("ImagePage.qml");
217                         }
218                 }
219         }
220 }