Silence g++/moc warnings
[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         Camera {
167 /*
168                 onDeviceIdChanged: {
169                         // TODO: is this needed ?
170                         if (platformWindow.active) {
171                                 cam.start();
172                         }
173                 }
174 */
175                 id: cam
176                 anchors.fill: parent
177
178                 onError: {
179                         console.log("Camera error (" + code + "): " + message + " " + debug);
180                         showError(qsTr("Camera error. Please restart the application."));
181                         cam.stop();
182                 }
183
184                 // TODO: hardcoding device id
185                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
186
187                 // TODO: Hack
188                 z: -1
189
190                 Rectangle {
191                         id: camDimmer
192                         z: 1
193                         anchors.fill: parent
194                         opacity: 0
195                         color: "black"
196                 }
197         }
198
199         Scene {
200                 id: sceneController
201                 camera: cam
202                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
203         }
204
205         ColorTone {
206                 id: colorToneController
207                 camera: cam
208                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
209         }
210
211         WhiteBalance {
212                 id: whiteBalanceController
213                 camera: cam
214                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
215         }
216
217         ModeController {
218                 id: cameraMode
219                 cam: cam
220                 dimmer: root.dimmer
221         }
222
223         Iso {
224                 id: iso
225                 camera: cam
226                 value: ready ? settings.imageIso : 0
227         }
228
229         Connections {
230                 target: cam
231                 onModeChanged: {
232                         if (cam.mode == Camera.VideoMode) {
233                                 replacePage("VideoPage.qml");
234                         }
235                         else {
236                                 replacePage("ImagePage.qml");
237                         }
238                 }
239         }
240 }