Use Qt.application.active instead of platformWindow.active
[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 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         CameraResources {
53                 id: resourcePolicy
54                 onAcquiredChanged: {
55                         if (resourcePolicy.acquired) {
56                                 // TODO:
57                         }
58                         else {
59                                 // TODO: We need a way to force a stop.
60                         }
61                 }
62         }
63
64         DeviceInfo {
65                 id: deviceInfo
66         }
67
68         FSMonitor {
69                 id: fileSystem
70         }
71
72         InfoBanner {
73                 id: error
74         }
75
76         Settings {
77                 id: settings
78         }
79
80         FileNaming {
81                 id: fileNaming
82                 imageSuffix: cam.imageSuffix
83                 videoSuffix: cam.videoSuffix
84         }
85
86         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
87         function replacePage(file) {
88                 var component = Qt.createComponent(file)
89
90                 if (component.status == Component.Ready) {
91                         pageStack.replace(component, {cam: cam}, true);
92                 }
93                 else {
94                         console.log("Error loading component:", component.errorString());
95                 }
96         }
97
98         function openFile(file) {
99                 var component = Qt.createComponent(file)
100
101                 if (component.status == Component.Ready) {
102                         pageStack.push(component, {cam: cam});
103                 }
104                 else {
105                         console.log("Error loading component:", component.errorString());
106                 }
107         }
108
109         platformStyle: PageStackWindowStyle {
110                 // TODO: Hack
111                 background: " "
112         }
113
114         Camera {
115 /*
116                 onDeviceIdChanged: {
117                         // TODO: is this needed ?
118                         if (platformWindow.active) {
119                                 cam.start();
120                         }
121                 }
122 */
123                 id: cam
124                 anchors.fill: parent
125
126                 onError: {
127                         console.log("Camera error (" + code + "): " + message + " " + debug);
128                         showError(qsTr("Camera error. Please restart the application."));
129                         cam.stop();
130                 }
131
132                 // TODO: hardcoding device id
133                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
134
135                 // TODO: Hack
136                 z: -1
137
138                 Rectangle {
139                         id: camDimmer
140                         z: 1
141                         anchors.fill: parent
142                         opacity: 0
143                         color: "black"
144                 }
145         }
146
147         Scene {
148                 id: sceneController
149                 camera: cam
150                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
151         }
152
153         ColorTone {
154                 id: colorToneController
155                 camera: cam
156                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
157         }
158
159         WhiteBalance {
160                 id: whiteBalanceController
161                 camera: cam
162                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
163         }
164
165         ModeController {
166                 id: cameraMode
167                 cam: cam
168                 dimmer: root.dimmer
169         }
170
171         Connections {
172                 target: cam
173                 onModeChanged: {
174                         if (cam.mode == Camera.VideoMode) {
175                                 replacePage("VideoPage.qml");
176                         }
177                         else {
178                                 replacePage("ImagePage.qml");
179                         }
180                 }
181         }
182 }