Added resource policy support (Still needs more testing) and refactored the pipeline...
[harmattan/cameraplus] / qml / CameraPage.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 Page {
8         id: page
9
10         property alias standbyWidget: standby
11
12         property bool needsPipeline: true
13         property int policyMode: CameraResources.None
14
15         Component.onCompleted: {
16                 if (platformWindow.active && needsPipeline) {
17                         resourcePolicy.acquire(page.policyMode);
18                 }
19         }
20
21         onStatusChanged: {
22                 if (platformWindow.active && status == PageStatus.Activating) {
23                         resourcePolicy.acquire(page.policyMode);
24                 }
25         }
26 /*
27         onStatusChanged: {
28                 if (status == PageStatus.Active && !page.needsPipeline) {
29                         cam.stop();
30                 }
31         }
32 */
33
34         onPolicyModeChanged: {
35                 if (platformWindow.active) {
36                         resourcePolicy.acquire(page.policyMode);
37                 }
38         }
39
40         function handlePipeline() {
41                 if (!platformWindow.active) {
42                         // TODO: force if we lost resources ?
43                         cam.stop();
44                 }
45                 else if (resourcePolicy.acquired && page.needsPipeline && !cam.running) {
46                         // TODO: error
47                         cam.start();
48                 }
49                 else if (!resourcePolicy.acquired) {
50                         // TODO: force
51                         cam.stop();
52                 }
53         }
54
55         Connections {
56                 target: resourcePolicy
57                 onAcquiredChanged: handlePipeline();
58         }
59
60         Connections {
61                 target: platformWindow
62                 onActiveChanged: {
63                         if (!platformWindow.active) {
64                                 // This is a noop if camera is not
65                                 // idle so calling it will not hurt
66                                 if (cam.stop()) {
67                                         resourcePolicy.acquire(CameraResources.None);
68                                 }
69                         }
70                         else if (page.needsPipeline) {
71                                 resourcePolicy.acquire(page.policyMode);
72                         }
73                 }
74         }
75
76         Connections {
77                 target: cam
78                 onIdleChanged: {
79                         if (cam.idle && !platformWindow.active) {
80                                 cam.stop();
81                                 resourcePolicy.acquire(CameraResources.None);
82                         }
83 /*
84                         else if (cam.idle && !page.needsPipeline) {
85                                 cam.stop();
86                         }
87 */
88                 }
89         }
90
91         Rectangle {
92                 // TODO: color
93                 // TODO: fade out transition
94                 // TODO: there is a toolbar visible on the first startup
95                 id: standby
96                 color: "black"
97                 anchors.fill: parent
98                 visible: !platformWindow.active || !cam.running || !resourcePolicy.acquired
99                 Image {
100                         source: "image://theme/icon-l-camera-standby"
101                         anchors.centerIn: parent
102                 }
103         }
104
105         property Camera cam: null
106         property bool controlsVisible: cam.running && !standby.visible
107
108         anchors.fill: parent
109
110         property alias previewAnimationRunning: preview.animationRunning
111
112         function setPreview(image) {
113                 preview.setPreview(image);
114         }
115
116         ModeButton {
117                 anchors.bottom: parent.bottom
118                 anchors.right: parent.right
119                 anchors.rightMargin: 20
120                 anchors.bottomMargin: 20
121                 visible: controlsVisible
122         }
123
124         PreviewImage {
125                 id: preview
126         }
127
128         ZoomSlider {
129                 id: zoom
130                 camera: cam
131                 anchors.top: parent.top
132                 anchors.topMargin: 0
133                 anchors.horizontalCenter: parent.horizontalCenter
134                 visible: controlsVisible
135         }
136 }