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