Don't show rounded corners
[harmattan/cameraplus] / qml / RecordingPage.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 "data.js" as Data
28
29 // TODO: on error ?
30 // TODO: resources lost?
31 // TODO: closing camera in the middle of recording will hang camera
32 // TODO: optional resources?
33
34 CameraPage {
35         id: page
36         modesVisible: false
37
38         Component.onDestruction: videoMode.stopRecording();
39
40         onStatusChanged: {
41                 if (page.status == PageStatus.Active) {
42                         startRecording();
43                 }
44         }
45
46         function startRecording() {
47                 if (!pipelineManager.acquired || pipelineManager.hijacked) {
48                         showError(qsTr("Failed to acquire needed resources."));
49                         pageStack.pop(undefined, true);
50                         return;
51                 }
52
53                 metaData.setMetaData();
54
55                 if (!mountProtector.lock()) {
56                         showError(qsTr("Failed to lock images directory."));
57                         pageStack.pop(undefined, true);
58                         return;
59                 }
60
61                 var file = fileNaming.videoFileName();
62                 var tmpFile = fileNaming.temporaryVideoFileName();
63
64                 if (!videoMode.startRecording(file, tmpFile)) {
65                         showError(qsTr("Failed to record video. Please restart the camera."));
66                         pageStack.pop(undefined, true);
67                         mountProtector.unlock();
68                 }
69
70                 // TODO: sometimes this fails (fast stop after start).
71                 trackerStore.storeVideo(file);
72         }
73
74         function stopRecording() {
75                 mountProtector.unlock();
76                 pageStack.pop(undefined, true);
77         }
78
79         policyMode: CameraResources.Recording
80
81         controlsVisible: cam.running && videoMode.recording && !cameraMode.animationRunning && !previewAnimationRunning && !standbyWidget.visible
82
83         orientationLock: PageOrientation.LockLandscape
84
85         DisplayState {
86                 inhibitDim: true
87         }
88
89         onBatteryLow: {
90                 if (!checkBattery()) {
91                         page.stopRecording();
92                         showError(qsTr("Not enough battery to record video."));
93                 }
94         }
95
96         CaptureButton {
97                 id: recording
98                 anchors.right: parent.right
99                 anchors.rightMargin: 20
100                 anchors.verticalCenter: parent.verticalCenter
101                 iconSource: "image://theme/icon-m-camera-video-record"
102                 width: 75
103                 height: 75
104                 opacity: 0.5
105
106                 onClicked: page.stopRecording();
107                 visible: controlsVisible
108         }
109
110         Connections {
111                 target: Qt.application
112                 onActiveChanged: {
113                         if (!Qt.application.active) {
114                                 page.stopRecording();
115                         }
116                 }
117         }
118
119         VideoMode {
120                 id: videoMode
121                 camera: cam
122         }
123
124         VideoTorchButton {
125                 id: torch
126                 camera: cam
127                 visible: controlsVisible
128                 anchors.top: parent.top
129                 anchors.left: parent.left
130                 anchors.topMargin: 20
131                 anchors.leftMargin: 20
132                 opacity: 0.5
133         }
134
135         VideoEvCompButton {
136                 id: evComp
137                 visible: controlsVisible
138                 anchors.top: torch.bottom
139                 anchors.left: parent.left
140                 anchors.topMargin: 10
141                 anchors.leftMargin: 20
142         }
143
144         Rectangle {
145                 anchors.left: parent.left
146                 anchors.bottom: parent.bottom
147                 anchors.leftMargin: 20
148                 anchors.bottomMargin: 20
149
150                 visible: controlsVisible
151
152                 color: "black"
153                 opacity: 0.5
154                 width: 100
155                 height: 30
156
157                 Timer {
158                         id: recordingDuration
159
160                         property int duration: 0
161
162                         running: videoMode.recording
163                         interval: 1000
164                         repeat: true
165
166                         onTriggered: {
167                                 duration = duration + 1;
168                                 if (duration == 3600) {
169                                         page.stopRecording();
170                                         showError(qsTr("Maximum recording time reached."));
171                                 }
172                                 else if (!checkDiskSpace()) {
173                                         page.stopRecording();
174                                         showError(qsTr("Not enough space to continue recording."));
175                                 }
176                         }
177                 }
178
179                 Image {
180                         id: recordingIcon
181                         source: "image://theme/icon-m-camera-ongoing-recording"
182                         width: 20
183                         height: 20
184                         anchors.verticalCenter: parent.verticalCenter
185                         anchors.left: parent.left
186                         anchors.leftMargin: 5
187                         sourceSize.width: 20
188                         sourceSize.height: 20
189                 }
190
191                 Label {
192                         function formatDuration(dur) {
193                                 var secs = parseInt(recordingDuration.duration);
194                                 var minutes = Math.floor(secs / 60);
195                                 var seconds = secs - (minutes * 60);
196
197                                 var date = new Date();
198                                 date.setSeconds(seconds);
199                                 date.setMinutes(minutes);
200                                 return Qt.formatTime(date, "mm:ss");
201                         }
202
203                         id: durationLabel
204                         text: formatDuration(recordingDuration.duration);
205                         anchors.left: recordingIcon.right
206                         anchors.leftMargin: 5
207                 }
208         }
209 }