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
30 // TODO: losing resources in the middle of recording will produce corrupted video
31 // TODO: closing camera in the middle of recording will hang camera
32 // TODO: optional resources?
38 function policyLost() {
42 Component.onDestruction: videoMode.stopRecording();
45 if (page.status == PageStatus.Active) {
50 function startRecording() {
51 if (!pipelineManager.acquired || pipelineManager.hijacked) {
52 showError(qsTr("Failed to acquire needed resources."));
53 pageStack.pop(undefined, true);
57 metaData.setMetaData();
59 if (!mountProtector.lock()) {
60 showError(qsTr("Failed to lock images directory."));
61 pageStack.pop(undefined, true);
65 var file = fileNaming.videoFileName();
66 var tmpFile = fileNaming.temporaryVideoFileName();
68 if (!videoMode.startRecording(file, tmpFile)) {
69 showError(qsTr("Failed to record video. Please restart the camera."));
70 pageStack.pop(undefined, true);
71 mountProtector.unlock();
74 // TODO: sometimes this fails (fast stop after start).
75 trackerStore.storeVideo(file);
78 function stopRecording() {
79 mountProtector.unlock();
80 pageStack.pop(undefined, true);
83 policyMode: CameraResources.Recording
85 controlsVisible: cam.running && videoMode.recording && !cameraMode.animationRunning && !previewAnimationRunning
87 orientationLock: PageOrientation.LockLandscape
94 if (!checkBattery()) {
96 showError(qsTr("Not enough battery to record video."));
102 anchors.right: parent.right
103 anchors.rightMargin: 20
104 anchors.verticalCenter: parent.verticalCenter
105 iconSource: "image://theme/icon-m-camera-video-record"
110 onClicked: page.stopRecording();
111 visible: controlsVisible
115 target: Qt.application
117 if (!Qt.application.active) {
118 page.stopRecording();
131 visible: controlsVisible
132 anchors.top: parent.top
133 anchors.left: parent.left
134 anchors.topMargin: 20
135 anchors.leftMargin: 20
141 visible: controlsVisible
142 anchors.top: torch.bottom
143 anchors.left: parent.left
144 anchors.topMargin: 10
145 anchors.leftMargin: 20
149 anchors.left: parent.left
150 anchors.bottom: parent.bottom
151 anchors.leftMargin: 20
152 anchors.bottomMargin: 20
154 visible: controlsVisible
162 id: recordingDuration
164 property int duration: 0
166 running: videoMode.recording
171 duration = duration + 1;
172 if (duration == 3600) {
173 page.stopRecording();
174 showError(qsTr("Maximum recording time reached."));
176 else if (!checkDiskSpace()) {
177 page.stopRecording();
178 showError(qsTr("Not enough space to continue recording."));
185 source: "image://theme/icon-m-camera-ongoing-recording"
188 anchors.verticalCenter: parent.verticalCenter
189 anchors.left: parent.left
190 anchors.leftMargin: 5
192 sourceSize.height: 20
196 function formatDuration(dur) {
197 var secs = parseInt(recordingDuration.duration);
198 var minutes = Math.floor(secs / 60);
199 var seconds = secs - (minutes * 60);
201 var date = new Date();
202 date.setSeconds(seconds);
203 date.setMinutes(minutes);
204 return Qt.formatTime(date, "mm:ss");
208 text: formatDuration(recordingDuration.duration);
209 anchors.left: recordingIcon.right
210 anchors.leftMargin: 5