Don't show rounded corners
[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 Item {
28         id: handler
29
30         property bool showStandBy: state != "on"
31
32         property alias acquired: policy.acquired
33         property alias hijacked: policy.hijacked
34
35         property Camera camera: null
36         property Item currentPage: pageStack.currentPage
37
38         onCurrentPageChanged: {
39                 if (state == "on" || state == "policyLost") {
40                         startCamera();
41                 }
42         }
43
44         CameraResources {
45                 id: policy
46         }
47
48         function startCamera() {
49                 if (!policy.acquire(currentPage.policyMode)) {
50                         console.log("Failed to acquire policy resources");
51                         return;
52                 }
53
54                 if (!camera.start()) {
55                         showError(qsTr("Failed to start camera. Please restart the application."));
56                 }
57         }
58
59         function stopCamera() {
60                 camera.stop(false);
61                 policy.acquire(CameraResources.None);
62         }
63
64         function forceStopCamera() {
65                 // We don't release resources here so we can get them back
66                 // when they become available
67                 camera.stop(true);
68         }
69
70         state: "off"
71
72 //        onStateChanged: console.log("New state " + handler.state);
73
74         states: [
75         State {
76                 name: "on"
77                 when: Qt.application.active && currentPage && currentPage.needsPipeline && !policy.hijacked
78         },
79         State {
80                 name: "off"
81                 when: (!Qt.application.active && camera.idle) || (currentPage && !currentPage.needsPipeline)
82         },
83         State {
84                 name: "policyLost"
85                 when: policy.hijacked
86         },
87         State {
88                 name: "error"
89         }
90         ]
91
92         transitions: [
93         Transition {
94                 from: "on"
95                 to: "off"
96                 ScriptAction {
97                         script: stopCamera();
98                 }
99         },
100         Transition {
101                 from: "off"
102                 to: "on"
103                 ScriptAction {
104                         script: handler.startCamera();
105                 }
106         },
107
108         Transition {
109                 from: "on"
110                 to: "policyLost"
111                 ScriptAction {
112                         script: forceStopCamera();
113                 }
114         },
115
116         Transition {
117                 from: "policyLost"
118                 to: "off"
119                 ScriptAction {
120                         script: stopCamera();
121                 }
122         },
123         Transition {
124                 from: "policyLost"
125                 to: "on"
126                 ScriptAction {
127                         script: startCamera();
128                 }
129         }
130         ]
131 }