Added resource policy support (Still needs more testing) and refactored the pipeline...
[harmattan/cameraplus] / qml / VideoPage.qml
1 // -*- qml -*-
2 import QtQuick 1.1
3 import com.nokia.meego 1.1
4 import QtCamera 1.0
5 import CameraPlus 1.0
6
7 CameraPage {
8         id: page
9
10         policyMode: CameraResources.Video
11
12         controlsVisible: recording.visible && cam.running && !standbyWidget.visible
13
14         orientationLock: PageOrientation.LockLandscape
15
16         DisplayState {
17                 inhibitDim: videoMode.recording
18         }
19
20         Button {
21                 id: recording
22                 anchors.right: parent.right
23                 anchors.rightMargin: 20
24                 anchors.verticalCenter: parent.verticalCenter
25                 iconSource: "image://theme/icon-m-camera-video-record"
26                 width: 75
27                 height: 75
28                 opacity: 0.5
29
30                 onClicked: {
31                         if (!fileSystem.available) {
32                                 showError(qsTr("Camera cannot record videos in mass storage mode."));
33                                 return;
34                         }
35
36                         // We only toggle the mode to video recording so
37                         // policy can acquire the needed resources
38
39                         if (policyMode == CameraResources.Video) {
40                                 policyMode = CameraResources.Recording;
41                         }
42                         else if (videoMode.recording) {
43                                 // We just ask to stop video.
44                                 videoMode.stopRecording();
45                         }
46                 }
47
48                 Connections {
49                         target: videoMode
50                         onRecordingChanged: {
51                                 if (!videoMode.recording) {
52                                         policyMode = CameraResources.Video;
53                                 }
54                         }
55                 }
56
57                 Connections {
58                         target: resourcePolicy
59                         onAcquiredChanged: {
60                                 if (resourcePolicy.acquired && policyMode == CameraResources.Recording) {
61                                         if (!videoMode.startRecording(fileNaming.videoFileName())) {
62                                                 showError(qsTr("Failed to record video. Please restart the camera."));
63                                                 policyMode = CameraResources.Video
64 }
65                                 }
66                         }
67                 }
68
69                 visible: (videoMode.recording || videoMode.canCapture) && !cameraMode.animationRunning && !previewAnimationRunning && !standbyWidget.visible
70         }
71
72         Connections {
73                 target: platformWindow
74                 onActiveChanged: {
75                         if (!platformWindow.active && videoMode.recording) {
76                                 videoMode.stopRecording();
77                         }
78                 }
79         }
80
81         VideoMode {
82                 id: videoMode
83                 camera: cam
84                 onPreviewAvailable: {
85                         if (!standbyWidget.visible) {
86                                 page.setPreview(preview);
87                         }
88                 }
89         }
90
91         VideoTorchButton {
92                 id: torch
93                 visible: controlsVisible
94                 anchors.top: parent.top
95                 anchors.left: parent.left
96                 anchors.topMargin: 20
97                 anchors.leftMargin: 20
98                 opacity: 0.5
99         }
100
101         VideoSceneButton {
102                 id: scene
103                 visible: controlsVisible && !videoMode.recording
104                 anchors.top: torch.bottom
105                 anchors.left: parent.left
106                 anchors.topMargin: 10
107                 anchors.leftMargin: 20
108         }
109
110         EvCompButton {
111                 id: evComp
112                 visible: controlsVisible
113                 anchors.top: scene.bottom
114                 anchors.left: parent.left
115                 anchors.topMargin: 10
116                 anchors.leftMargin: 20
117         }
118
119         Button {
120                 id: cameraRoll
121                 anchors.top: parent.top
122                 anchors.right: parent.right
123                 anchors.topMargin: 20
124                 anchors.rightMargin: 20
125                 width: 56
126                 height: 56
127
128                 opacity: 0.5
129                 iconSource: "image://theme/icon-m-camera-roll"
130                 onClicked: openFile("PostCapturePage.qml");
131                 visible: controlsVisible && !videoMode.recording
132         }
133 }