Stop the pipeline if the camera becomes idle and our window is not active
[harmattan/cameraplus] / qml / main.qml
1 // -*- qml -*-
2 import QtQuick 1.1
3 import com.nokia.meego 1.1
4 import QtCamera 1.0
5 import CameraPlus 1.0
6
7 // TODO: metadata creator name, gps, geotags
8 // TODO: resolutions and aspect ratios
9 // TODO: postcapture
10 // TODO: file naming
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 in a hidden directory and then copy the video to avoid tracker indexing it.
18
19 PageStackWindow {
20         id: root
21
22         property alias dimmer: camDimmer
23
24         showStatusBar: false
25
26         Component.onCompleted: {
27                 theme.inverted = true;
28                 if (settings.mode == 0) {
29                         openFile("ImagePage.qml");
30                 }
31                 else {
32                         openFile("VideoPage.qml");
33                 }
34         }
35
36         Settings {
37                 id: settings
38         }
39
40         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
41         function replacePage(file) {
42                 var component = Qt.createComponent(file)
43
44                 if (component.status == Component.Ready) {
45                         pageStack.replace(component, {cam: cam}, true);
46                 }
47                 else {
48                         console.log("Error loading component:", component.errorString());
49                 }
50         }
51
52         function openFile(file) {
53                 var component = Qt.createComponent(file)
54
55                 if (component.status == Component.Ready) {
56                         pageStack.push(component, {cam: cam});
57                 }
58                 else {
59                         console.log("Error loading component:", component.errorString());
60                 }
61         }
62
63         platformStyle: PageStackWindowStyle {
64                 // TODO: Hack
65                 background: " "
66         }
67
68         Connections {
69                 target: platformWindow
70                 onActiveChanged: {
71                         if (platformWindow.active) {
72                                 cam.start();
73                         }
74                         else {
75                                 // This is a noop if camera is not idle so calling it will not hurt
76                                 cam.stop();
77                         }
78                 }
79         }
80
81         Camera {
82                 onIdleChanged: {
83                         if (idle && !platformWindow.active) {
84                                 stop();
85                         }
86                 }
87
88                 onDeviceIdChanged: {
89                         if (platformWindow.active) {
90                                 cam.start();
91                         }
92                 }
93
94                 id: cam
95                 anchors.fill: parent
96
97                 // TODO: hardcoding device id
98                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
99
100                 // TODO: Hack
101                 z: -1
102
103                 Rectangle {
104                         id: camDimmer
105                         z: 1
106                         anchors.fill: parent
107                         opacity: 0
108                         color: "black"
109                 }
110         }
111
112         Scene {
113                 id: sceneController
114                 camera: cam
115                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
116         }
117
118         ColorTone {
119                 id: colorToneController
120                 camera: cam
121                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
122         }
123
124         WhiteBalance {
125                 id: whiteBalanceController
126                 camera: cam
127                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
128         }
129
130         ModeController {
131                 id: cameraMode
132                 cam: cam
133                 dimmer: root.dimmer
134         }
135
136         Connections {
137                 target: cam
138                 onModeChanged: {
139                         if (cam.mode == Camera.VideoMode) {
140                                 replacePage("VideoPage.qml");
141                         }
142                         else {
143                                 replacePage("ImagePage.qml");
144                         }
145                 }
146         }
147 }