Added copyright headers and COPYING file.
[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: indicators
38 // TODO: portrait/landscape
39 // TODO: record video in a hidden directory and then copy the video to avoid tracker indexing it.
40 // TODO: stop viewfinder in settings pages ?
41 // TODO: prevent going to mass storage while recording and capturing
42 // TODO: sounds
43 // TODO: grid lines, face tracking, ambr
44 // TODO: complete settings pages
45 // TODO: stop camera properly when we get closed.
46 // TODO: select primary/secondary camera.
47 // TODO: disable debug builds.
48 // TODO: a way to get buffers to the application
49 // TODO: fcam like functionality (precise control over capture parameters).
50
51 PageStackWindow {
52         id: root
53
54         property alias dimmer: camDimmer
55
56         showStatusBar: false
57
58         Component.onCompleted: {
59                 theme.inverted = true;
60                 if (settings.mode == 0) {
61                         openFile("ImagePage.qml");
62                 }
63                 else {
64                         openFile("VideoPage.qml");
65                 }
66         }
67
68         function showError(msg) {
69                 error.text = msg;
70                 error.show();
71         }
72
73         PositionSource {
74                 id: positionSource
75                 active: settings.useGps
76                 // TODO: we cannot bind to cam.running because camera will stop
77                 // when the connection dialog pops up and we end up with an infinite loop
78                 // active: cam.running && settings.useGps
79                 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
80         }
81
82         MetaData {
83                 id: metaData
84                 camera: cam
85                 manufacturer: deviceInfo.manufacturer
86                 model: deviceInfo.model
87                 country: geocode.country
88                 city: geocode.city
89                 suburb: geocode.suburb
90                 longitude: positionSource.position.coordinate.longitude
91                 longitudeValid: positionSource.position.longitudeValid && settings.useGps
92                 latitude: positionSource.position.coordinate.latitude
93                 latitudeValid: positionSource.position.latitudeValid && settings.useGps
94                 elevation: positionSource.position.coordinate.altitude
95                 elevationValid: positionSource.position.altitudeValid && settings.useGps
96                 orientation: orientation.orientation
97                 artist: settings.creatorName
98                 captureDirection: compass.direction
99                 captureDirectionValid: compass.directionValid
100                 horizontalError: positionSource.position.horizontalAccuracy
101                 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
102                 dateTimeEnabled: true
103         }
104
105         Orientation {
106                 id: orientation
107                 active: cam.running
108         }
109
110         Compass {
111                 id: compass
112                 active: cam.running
113         }
114
115         ReverseGeocode {
116                 id: geocode
117                 active: cam.running && settings.useGps && settings.useGeotags
118         }
119
120         CameraResources {
121                 id: resourcePolicy
122                 onAcquiredChanged: {
123                         if (resourcePolicy.acquired) {
124                                 // TODO:
125                         }
126                         else {
127                                 // TODO: We need a way to force a stop.
128                         }
129                 }
130         }
131
132         DeviceInfo {
133                 id: deviceInfo
134         }
135
136         FSMonitor {
137                 id: fileSystem
138         }
139
140         InfoBanner {
141                 id: error
142         }
143
144         Settings {
145                 id: settings
146         }
147
148         FileNaming {
149                 id: fileNaming
150                 imageSuffix: cam.imageSuffix
151                 videoSuffix: cam.videoSuffix
152         }
153
154         function replacePage(file) {
155                 pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
156         }
157
158         function openFile(file) {
159                 pageStack.push(Qt.resolvedUrl(file), {cam: cam});
160         }
161
162         platformStyle: PageStackWindowStyle {
163                 // TODO: Hack
164                 background: " "
165         }
166
167         Camera {
168 /*
169                 onDeviceIdChanged: {
170                         // TODO: is this needed ?
171                         if (platformWindow.active) {
172                                 cam.start();
173                         }
174                 }
175 */
176                 id: cam
177                 anchors.fill: parent
178
179                 onError: {
180                         console.log("Camera error (" + code + "): " + message + " " + debug);
181                         showError(qsTr("Camera error. Please restart the application."));
182                         cam.stop();
183                 }
184
185                 // TODO: hardcoding device id
186                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
187
188                 // TODO: Hack
189                 z: -1
190
191                 Rectangle {
192                         id: camDimmer
193                         z: 1
194                         anchors.fill: parent
195                         opacity: 0
196                         color: "black"
197                 }
198         }
199
200         Scene {
201                 id: sceneController
202                 camera: cam
203                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
204         }
205
206         ColorTone {
207                 id: colorToneController
208                 camera: cam
209                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
210         }
211
212         WhiteBalance {
213                 id: whiteBalanceController
214                 camera: cam
215                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
216         }
217
218         ModeController {
219                 id: cameraMode
220                 cam: cam
221                 dimmer: root.dimmer
222         }
223
224         Iso {
225                 id: iso
226                 camera: cam
227                 value: ready ? settings.imageIso : 0
228         }
229
230         Connections {
231                 target: cam
232                 onModeChanged: {
233                         if (cam.mode == Camera.VideoMode) {
234                                 replacePage("VideoPage.qml");
235                         }
236                         else {
237                                 replacePage("ImagePage.qml");
238                         }
239                 }
240         }
241 }