work around an issue with the connection dialog for now
[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         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
134         function replacePage(file) {
135                 var component = Qt.createComponent(file)
136
137                 if (component.status == Component.Ready) {
138                         pageStack.replace(component, {cam: cam}, true);
139                 }
140                 else {
141                         console.log("Error loading component:", component.errorString());
142                 }
143         }
144
145         function openFile(file) {
146                 var component = Qt.createComponent(file)
147
148                 if (component.status == Component.Ready) {
149                         pageStack.push(component, {cam: cam});
150                 }
151                 else {
152                         console.log("Error loading component:", component.errorString());
153                 }
154         }
155
156         platformStyle: PageStackWindowStyle {
157                 // TODO: Hack
158                 background: " "
159         }
160
161         Camera {
162 /*
163                 onDeviceIdChanged: {
164                         // TODO: is this needed ?
165                         if (platformWindow.active) {
166                                 cam.start();
167                         }
168                 }
169 */
170                 id: cam
171                 anchors.fill: parent
172
173                 onError: {
174                         console.log("Camera error (" + code + "): " + message + " " + debug);
175                         showError(qsTr("Camera error. Please restart the application."));
176                         cam.stop();
177                 }
178
179                 // TODO: hardcoding device id
180                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
181
182                 // TODO: Hack
183                 z: -1
184
185                 Rectangle {
186                         id: camDimmer
187                         z: 1
188                         anchors.fill: parent
189                         opacity: 0
190                         color: "black"
191                 }
192         }
193
194         Scene {
195                 id: sceneController
196                 camera: cam
197                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
198         }
199
200         ColorTone {
201                 id: colorToneController
202                 camera: cam
203                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
204         }
205
206         WhiteBalance {
207                 id: whiteBalanceController
208                 camera: cam
209                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
210         }
211
212         ModeController {
213                 id: cameraMode
214                 cam: cam
215                 dimmer: root.dimmer
216         }
217
218         Iso {
219                 id: iso
220                 camera: cam
221                 value: ready ? settings.imageIso : 0
222         }
223
224         Connections {
225                 target: cam
226                 onModeChanged: {
227                         if (cam.mode == Camera.VideoMode) {
228                                 replacePage("VideoPage.qml");
229                         }
230                         else {
231                                 replacePage("ImagePage.qml");
232                         }
233                 }
234         }
235 }