Added/Updated TODO items
[harmattan/cameraplus] / qml / PipelineManager.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 1.1
24 import QtCamera 1.0
25 import CameraPlus 1.0
26
27 // TODO: if a page doesn't need the pipeline then we will release its resources :(
28
29 Item {
30         id: handler
31
32         property bool showStandBy: state != "on"
33
34         property alias acquired: policy.acquired
35         property alias hijacked: policy.hijacked
36
37         property Camera camera: null
38         property Item currentPage: pageStack.currentPage
39
40         onCurrentPageChanged: {
41                 if (state == "on" || state == "policyLost") {
42                         startCamera();
43                 }
44         }
45
46         CameraResources {
47                 id: policy
48         }
49
50         function startCamera() {
51                 if (!policy.acquire(currentPage.policyMode)) {
52                         console.log("Failed to acquire policy resources");
53                         return;
54                 }
55
56                 if (!camera.start()) {
57                         showError(qsTr("Failed to start camera. Please restart the application."));
58                 }
59         }
60
61         function stopCamera() {
62                 if (camera.stop(false)) {
63                         policy.acquire(CameraResources.None);
64                 }
65         }
66
67         function forceStopCamera() {
68                 // We don't release resources here so we can get them back
69                 // when they become available
70                 pageStack.currentPage.policyLost();
71                 camera.stop(true);
72         }
73
74         state: "off"
75
76 //        onStateChanged: console.log("New state " + handler.state);
77
78         states: [
79         State {
80                 name: "on"
81                 when: Qt.application.active && currentPage && currentPage.needsPipeline && !policy.hijacked
82         },
83         State {
84                 name: "off"
85                 when: (!Qt.application.active && camera.idle) || (currentPage && !currentPage.needsPipeline)
86         },
87         State {
88                 name: "policyLost"
89                 when: policy.hijacked
90         },
91         State {
92                 name: "error"
93         }
94         ]
95
96         transitions: [
97         Transition {
98                 to: "off"
99                 ScriptAction {
100                         script: stopCamera();
101                 }
102         },
103         Transition {
104                 from: "off"
105                 to: "on"
106                 ScriptAction {
107                         script: handler.startCamera();
108                 }
109         },
110
111         Transition {
112                 from: "on"
113                 to: "policyLost"
114                 ScriptAction {
115                         script: forceStopCamera();
116                 }
117         },
118
119         Transition {
120                 from: "policyLost"
121                 to: "off"
122                 ScriptAction {
123                         script: stopCamera();
124                 }
125         },
126         Transition {
127                 from: "policyLost"
128                 to: "on"
129                 ScriptAction {
130                         script: startCamera();
131                 }
132         }
133         ]
134 }