4 * This file is part of CameraPlus.
6 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
24 import com.nokia.meego 1.1
27 import "data.js" as Data
29 // TODO: losing resources in the middle of recording will produce corrupted video
30 // TODO: optional resources?
35 property bool error: false
37 policyMode: CameraResources.Recording
39 controlsVisible: cam.running && videoMode.recording && !cameraMode.animationRunning && !previewAnimationRunning && !error
41 orientationLock: PageOrientation.LockLandscape
43 function policyLost() {
47 function cameraError() {
52 Component.onDestruction: videoMode.stopRecording();
55 if (page.status == PageStatus.Active) {
60 function startRecording() {
61 if (!pipelineManager.acquired || pipelineManager.hijacked) {
62 showError(qsTr("Failed to acquire needed resources."));
63 pageStack.pop(undefined, true);
67 metaData.setMetaData();
69 if (!mountProtector.lock()) {
70 showError(qsTr("Failed to lock images directory."));
71 pageStack.pop(undefined, true);
75 var file = fileNaming.videoFileName();
76 var tmpFile = fileNaming.temporaryVideoFileName();
78 if (!videoMode.startRecording(file, tmpFile)) {
79 showError(qsTr("Failed to record video. Please restart the camera."));
80 pageStack.pop(undefined, true);
81 mountProtector.unlock();
84 // TODO: sometimes this fails (fast stop after start).
85 trackerStore.storeVideo(file);
88 function stopRecording() {
89 mountProtector.unlock();
90 // Something is fishy here but if there is an error
91 // and we use immediate mode then the page never gets destroyed.
92 pageStack.pop(undefined, error ? false : true);
100 if (!checkBattery()) {
101 page.stopRecording();
102 showError(qsTr("Not enough battery to record video."));
108 anchors.right: parent.right
109 anchors.rightMargin: 20
110 anchors.verticalCenter: parent.verticalCenter
111 iconSource: "image://theme/icon-m-camera-video-record"
116 onClicked: page.stopRecording();
117 visible: controlsVisible
121 target: Qt.application
123 if (!Qt.application.active) {
124 page.stopRecording();
137 visible: controlsVisible
138 anchors.top: parent.top
139 anchors.left: parent.left
140 anchors.topMargin: 20
141 anchors.leftMargin: 20
147 visible: controlsVisible
148 anchors.top: torch.bottom
149 anchors.left: parent.left
150 anchors.topMargin: 10
151 anchors.leftMargin: 20
155 anchors.left: parent.left
156 anchors.bottom: parent.bottom
157 anchors.leftMargin: 20
158 anchors.bottomMargin: 20
160 visible: controlsVisible
168 id: recordingDuration
170 property int duration: 0
172 running: videoMode.recording
177 duration = duration + 1;
178 if (duration == 3600) {
179 page.stopRecording();
180 showError(qsTr("Maximum recording time reached."));
182 else if (!checkDiskSpace()) {
183 page.stopRecording();
184 showError(qsTr("Not enough space to continue recording."));
191 source: "image://theme/icon-m-camera-ongoing-recording"
194 anchors.verticalCenter: parent.verticalCenter
195 anchors.left: parent.left
196 anchors.leftMargin: 5
198 sourceSize.height: 20
202 function formatDuration(dur) {
203 var secs = parseInt(recordingDuration.duration);
204 var minutes = Math.floor(secs / 60);
205 var seconds = secs - (minutes * 60);
207 var date = new Date();
208 date.setSeconds(seconds);
209 date.setMinutes(minutes);
210 return Qt.formatTime(date, "mm:ss");
214 text: formatDuration(recordingDuration.duration);
215 anchors.left: recordingIcon.right
216 anchors.leftMargin: 5