Added resource policy support (Still needs more testing) and refactored the pipeline...
[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
9 // TODO: metadata creator name, gps, geotags
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 postcapture and settings pages ?
20 // TODO: resource policy
21 // TODO: prevent going to mass storage while recording and capturing
22 // TODO: sounds
23 // TODO: grid lines, face tracking
24 // TODO: complete settings pages
25 // TODO: stop camera properly when we get closed.
26 // TODO: select primary/secondary camera.
27 // TODO: disable debug builds.
28 // TODO: seems start gets called when we are shutting down
29 // TODO: seems start gets called twice when we are starting up if screen is locked or dimmed ?!
30
31 PageStackWindow {
32         id: root
33
34         property alias dimmer: camDimmer
35
36         showStatusBar: false
37
38         Component.onCompleted: {
39                 theme.inverted = true;
40                 if (settings.mode == 0) {
41                         openFile("ImagePage.qml");
42                 }
43                 else {
44                         openFile("VideoPage.qml");
45                 }
46         }
47
48         function showError(msg) {
49                 error.text = msg;
50                 error.show();
51         }
52
53         CameraResources {
54                 id: resourcePolicy
55                 onAcquiredChanged: {
56                         if (resourcePolicy.acquired) {
57                                 // TODO:
58                         }
59                         else {
60                                 // TODO: We need a way to force a stop.
61                         }
62                 }
63         }
64
65         DeviceInfo {
66                 id: deviceInfo
67         }
68
69         FSMonitor {
70                 id: fileSystem
71         }
72
73         InfoBanner {
74                 id: error
75         }
76
77         Settings {
78                 id: settings
79         }
80
81         FileNaming {
82                 id: fileNaming
83                 imageSuffix: cam.imageSuffix
84                 videoSuffix: cam.videoSuffix
85         }
86
87         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
88         function replacePage(file) {
89                 var component = Qt.createComponent(file)
90
91                 if (component.status == Component.Ready) {
92                         pageStack.replace(component, {cam: cam}, true);
93                 }
94                 else {
95                         console.log("Error loading component:", component.errorString());
96                 }
97         }
98
99         function openFile(file) {
100                 var component = Qt.createComponent(file)
101
102                 if (component.status == Component.Ready) {
103                         pageStack.push(component, {cam: cam});
104                 }
105                 else {
106                         console.log("Error loading component:", component.errorString());
107                 }
108         }
109
110         platformStyle: PageStackWindowStyle {
111                 // TODO: Hack
112                 background: " "
113         }
114
115         Camera {
116 /*
117                 onDeviceIdChanged: {
118                         // TODO: is this needed ?
119                         if (platformWindow.active) {
120                                 cam.start();
121                         }
122                 }
123 */
124                 id: cam
125                 anchors.fill: parent
126
127                 // TODO: hardcoding device id
128                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
129
130                 // TODO: Hack
131                 z: -1
132
133                 Rectangle {
134                         id: camDimmer
135                         z: 1
136                         anchors.fill: parent
137                         opacity: 0
138                         color: "black"
139                 }
140         }
141
142         Scene {
143                 id: sceneController
144                 camera: cam
145                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
146         }
147
148         ColorTone {
149                 id: colorToneController
150                 camera: cam
151                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
152         }
153
154         WhiteBalance {
155                 id: whiteBalanceController
156                 camera: cam
157                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
158         }
159
160         ModeController {
161                 id: cameraMode
162                 cam: cam
163                 dimmer: root.dimmer
164         }
165
166         Connections {
167                 target: cam
168                 onModeChanged: {
169                         if (cam.mode == Camera.VideoMode) {
170                                 replacePage("VideoPage.qml");
171                         }
172                         else {
173                                 replacePage("ImagePage.qml");
174                         }
175                 }
176         }
177 }