Reworked and fixed pipeline error handling.
[harmattan/cameraplus] / qml / CameraPage.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 com.nokia.meego 1.1
25 import QtCamera 1.0
26 import CameraPlus 1.0
27 import QtMobility.systeminfo 1.2
28
29 Page {
30         id: page
31
32         property bool needsPipeline: true
33         property int policyMode: CameraResources.None
34
35         property Camera cam: null
36         property bool controlsVisible: cam.running && !standby.visible
37         property bool zoomVisible: true
38         property bool modesVisible: true
39         property bool standbyVisible: true
40         property bool focusReticleVisible: true
41
42         property alias previewAnimationRunning: preview.animationRunning
43
44         signal batteryLow
45
46         function cameraError() {
47                 // Nothing
48         }
49
50         function policyLost() {
51                 // Nothing
52         }
53
54         onStatusChanged: {
55                 if (status == PageStatus.Active) {
56                         focusReticle.setRegionOfInterest();
57                 }
58         }
59
60         Rectangle {
61                 // TODO: fade out transition
62                 // TODO: there is a toolbar visible on the first startup
63                 id: standby
64                 color: "black"
65                 anchors.fill: parent
66                 visible: standbyVisible && page.status == PageStatus.Active && pipelineManager.showStandBy
67                 z: 2
68                 MouseArea {
69                         anchors.fill: parent
70                         enabled: parent.visible
71                 }
72
73                 Image {
74                         id: icon
75                         source: "image://theme/icon-l-camera-standby"
76                         anchors.centerIn: parent
77                 }
78
79                 Label {
80                         anchors.top: icon.bottom
81                         anchors.right: parent.right
82                         anchors.left: parent.left
83                         text: qsTr("Resources lost")
84                         color: "white"
85                         font.pixelSize: 36
86                         horizontalAlignment: Text.AlignHCenter
87                         visible: pipelineManager.state == "policyLost"
88                 }
89         }
90
91         function setPreview(image) {
92                 preview.setPreview(image);
93         }
94
95         ModeButton {
96                 anchors.bottom: parent.bottom
97                 anchors.right: parent.right
98                 anchors.rightMargin: 20
99                 anchors.bottomMargin: 20
100                 visible: controlsVisible && modesVisible
101         }
102
103         PreviewImage {
104                 id: preview
105         }
106
107         ZoomSlider {
108                 id: zoom
109                 camera: cam
110                 anchors.top: parent.top
111                 anchors.topMargin: 0
112                 anchors.horizontalCenter: parent.horizontalCenter
113                 visible: controlsVisible && zoomVisible
114         }
115
116         function checkDiskSpace() {
117                 return fileSystem.hasFreeSpace(fileNaming.path);
118         }
119
120         function checkBattery() {
121                 // We are fine if we are connected to the charger:
122                 if (batteryMonitor.chargingState == BatteryInfo.Charging) {
123                         return true;
124                 }
125
126                 // If we have enough battery then we are fine:
127                 if (batteryMonitor.batteryStatus > BatteryInfo.BatteryCritical) {
128                         return true;
129                 }
130
131                 return false;
132         }
133
134         BatteryInfo {
135                 id: batteryMonitor
136                 monitorChargingStateChanges: cam.running
137                 monitorBatteryStatusChanges: cam.running
138
139                 onChargingStateChanged: {
140                         if (!checkBattery()) {
141                                 parent.batteryLow();
142                         }
143                 }
144
145                 onBatteryStatusChanged:  {
146                         if (!checkBattery()) {
147                                 parent.batteryLow();
148                         }
149                 }
150         }
151 }