Capture button should not be visible if we use zoom for capturing and we have the...
[harmattan/cameraplus] / qml / RecordingPage.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 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 "data.js" as Data
28
29 // TODO: optional resources?
30
31 CameraPage {
32         id: page
33         modesVisible: false
34         property bool error: false
35
36         policyMode: CameraResources.Recording
37
38         controlsVisible: cam.running && videoMode.recording && !error
39
40         orientationLock: PageOrientation.LockLandscape
41
42         function policyLost() {
43                 page.stopRecording();
44         }
45
46         function cameraError() {
47                 error = true;
48                 page.stopRecording();
49         }
50
51         onStatusChanged: {
52                 if (page.status == PageStatus.Active) {
53                         startRecording();
54                 }
55         }
56
57         function startRecording() {
58                 if (!pipelineManager.acquired || pipelineManager.hijacked) {
59                         showError(qsTr("Failed to acquire needed resources."));
60                         pageStack.pop(undefined, true);
61                         return;
62                 }
63
64                 metaData.setMetaData();
65
66                 if (!mountProtector.lock()) {
67                         showError(qsTr("Failed to lock images directory."));
68                         pageStack.pop(undefined, true);
69                         return;
70                 }
71
72                 var file = fileNaming.videoFileName();
73                 var tmpFile = fileNaming.temporaryVideoFileName();
74
75                 if (!videoMode.startRecording(file, tmpFile)) {
76                         showError(qsTr("Failed to record video. Please restart the camera."));
77                         pageStack.pop(undefined, true);
78                         mountProtector.unlock();
79                 }
80
81                 trackerStore.storeVideo(file);
82         }
83
84         function stopRecording() {
85                 videoMode.stopRecording(true);
86                 mountProtector.unlock();
87                 // Something is fishy here but if there is an error
88                 // and we use immediate mode then the page never gets destroyed.
89                 pageStack.pop(undefined, error ? false : true);
90         }
91
92         DisplayState {
93                 inhibitDim: true
94         }
95
96         onBatteryLow: {
97                 if (!checkBattery()) {
98                         page.stopRecording();
99                         showError(qsTr("Not enough battery to record video."));
100                 }
101         }
102
103         CaptureButton {
104                 id: recording
105                 anchors.right: parent.right
106                 anchors.rightMargin: 20
107                 anchors.verticalCenter: parent.verticalCenter
108                 iconSource: "image://theme/icon-m-camera-video-record"
109                 width: 75
110                 height: 75
111                 opacity: 0.5
112
113                 onClicked: page.stopRecording();
114                 visible: controlsVisible && (!settings.zoomAsShutter && keys.active)
115         }
116
117         Connections {
118                 target: Qt.application
119                 onActiveChanged: {
120                         if (!Qt.application.active) {
121                                 page.stopRecording();
122                         }
123                 }
124         }
125
126         VideoMode {
127                 id: videoMode
128                 camera: cam
129         }
130
131         Rectangle {
132                 anchors.top: parent.top
133                 anchors.topMargin: 20
134                 anchors.left: parent.left
135                 anchors.leftMargin: 20
136                 width: 48
137                 height: col.height
138                 color: "black"
139                 border.color: "gray"
140                 radius: 20
141                 opacity: 0.5
142                 visible: controlsVisible
143
144                 Column {
145                         id: col
146                         width: parent.width
147                         spacing: 5
148
149                         Indicator {
150                                 id: resolutionIndicator
151                                 source: "image://theme/" + Data.videoIcon(settings.videoResolution);
152                         }
153
154                         Indicator {
155                                 id: wbIndicator
156                                 source: visible ? "image://theme/" + Data.wbIcon(settings.videoWhiteBalance) + "-screen" : ""
157                                 visible: settings.videoWhiteBalance != WhiteBalance.Auto
158                         }
159
160                         Indicator {
161                                 id: cfIndicator
162                                 source: "image://theme/" + Data.cfIcon(settings.videoColorFilter) + "-screen"
163                                 visible: settings.videoColorFilter != ColorTone.Normal
164                         }
165
166                         Indicator {
167                                 id: gpsIndicator
168                                 visible: settings.useGps
169                                 source: "image://theme/icon-m-camera-location"
170
171                                 PropertyAnimation on opacity  {
172                                         easing.type: Easing.OutSine
173                                         loops: Animation.Infinite
174                                         from: 0.2
175                                         to: 1.0
176                                         duration: 1000
177                                         running: settings.useGps && !positionSource.position.longitudeValid
178                                         alwaysRunToEnd: true
179                                 }
180                         }
181                 }
182         }
183
184         Rectangle {
185                 anchors.bottom: parent.bottom
186                 anchors.right: parent.right
187                 anchors.rightMargin: 20
188                 anchors.bottomMargin: 20
189
190                 visible: controlsVisible
191
192                 color: "black"
193                 opacity: 0.5
194                 width: 100
195                 height: 30
196
197                 Timer {
198                         id: recordingDuration
199
200                         property int duration: 0
201
202                         running: videoMode.recording
203                         interval: 1000
204                         repeat: true
205
206                         onTriggered: {
207                                 duration = duration + 1;
208                                 if (duration == 3600) {
209                                         page.stopRecording();
210                                         showError(qsTr("Maximum recording time reached."));
211                                 }
212                                 else if (!checkDiskSpace()) {
213                                         page.stopRecording();
214                                         showError(qsTr("Not enough space to continue recording."));
215                                 }
216                         }
217                 }
218
219                 Image {
220                         id: recordingIcon
221                         source: "image://theme/icon-m-camera-ongoing-recording"
222                         width: 20
223                         height: 20
224                         anchors.verticalCenter: parent.verticalCenter
225                         anchors.left: parent.left
226                         anchors.leftMargin: 5
227                         sourceSize.width: 20
228                         sourceSize.height: 20
229                 }
230
231                 Label {
232                         function formatDuration(dur) {
233                                 var secs = parseInt(recordingDuration.duration);
234                                 var minutes = Math.floor(secs / 60);
235                                 var seconds = secs - (minutes * 60);
236
237                                 var date = new Date();
238                                 date.setSeconds(seconds);
239                                 date.setMinutes(minutes);
240                                 return Qt.formatTime(date, "mm:ss");
241                         }
242
243                         id: durationLabel
244                         text: formatDuration(recordingDuration.duration);
245                         anchors.left: recordingIcon.right
246                         anchors.leftMargin: 5
247                 }
248         }
249
250         CameraToolBar {
251                 id: toolBar
252                 anchors.bottom: parent.bottom
253                 anchors.bottomMargin: 20
254                 anchors.left: parent.left
255                 anchors.leftMargin: 20
256                 opacity: 0.5
257                 targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
258                 visible: controlsVisible
259                 expanded: settings.showToolBar
260                 onExpandedChanged: settings.showToolBar = expanded;
261
262                 items: [
263                 VideoTorchButton {
264                         camera: cam
265                 },
266                 VideoEvCompButton {
267                         onClicked: toolBar.push(items);
268                 },
269                 VideoWhiteBalanceButton {
270                         onClicked: toolBar.push(items);
271                 },
272                 VideoColorFilterButton {
273                         onClicked: toolBar.push(items);
274                 },
275                 VideoMuteButton {
276                 },
277                 ToolIcon {
278                         iconSource: "image://theme/icon-m-toolbar-view-menu-white"
279                         onClicked: openFile("VideoSettingsPage.qml");
280                 }
281                 ]
282         }
283 }