Added a class to generate filenames for images and videos
[harmattan/cameraplus] / qml / main.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 // TODO: metadata creator name, gps, geotags
8 // TODO: resolutions and aspect ratios
9 // TODO: postcapture
10 // TODO: battery low state
11 // TODO: disk space
12 // TODO: flash not ready
13 // TODO: focus, caf, ...
14 // TODO: indicators
15 // TODO: portrait/landscape
16 // TODO: record in a hidden directory and then copy the video to avoid tracker indexing it.
17
18 PageStackWindow {
19         id: root
20
21         property alias dimmer: camDimmer
22
23         showStatusBar: false
24
25         Component.onCompleted: {
26                 theme.inverted = true;
27                 if (settings.mode == 0) {
28                         openFile("ImagePage.qml");
29                 }
30                 else {
31                         openFile("VideoPage.qml");
32                 }
33         }
34
35         Settings {
36                 id: settings
37         }
38
39         FileNaming {
40                 id: fileNaming
41                 imageSuffix: cam.imageSuffix
42                 videoSuffix: cam.videoSuffix
43         }
44
45         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
46         function replacePage(file) {
47                 var component = Qt.createComponent(file)
48
49                 if (component.status == Component.Ready) {
50                         pageStack.replace(component, {cam: cam}, true);
51                 }
52                 else {
53                         console.log("Error loading component:", component.errorString());
54                 }
55         }
56
57         function openFile(file) {
58                 var component = Qt.createComponent(file)
59
60                 if (component.status == Component.Ready) {
61                         pageStack.push(component, {cam: cam});
62                 }
63                 else {
64                         console.log("Error loading component:", component.errorString());
65                 }
66         }
67
68         platformStyle: PageStackWindowStyle {
69                 // TODO: Hack
70                 background: " "
71         }
72
73         Connections {
74                 target: platformWindow
75                 onActiveChanged: {
76                         if (platformWindow.active) {
77                                 cam.start();
78                         }
79                         else {
80                                 // This is a noop if camera is not idle so calling it will not hurt
81                                 cam.stop();
82                         }
83                 }
84         }
85
86         Camera {
87                 onIdleChanged: {
88                         if (idle && !platformWindow.active) {
89                                 stop();
90                         }
91                 }
92
93                 onDeviceIdChanged: {
94                         if (platformWindow.active) {
95                                 cam.start();
96                         }
97                 }
98
99                 id: cam
100                 anchors.fill: parent
101
102                 // TODO: hardcoding device id
103                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
104
105                 // TODO: Hack
106                 z: -1
107
108                 Rectangle {
109                         id: camDimmer
110                         z: 1
111                         anchors.fill: parent
112                         opacity: 0
113                         color: "black"
114                 }
115         }
116
117         Scene {
118                 id: sceneController
119                 camera: cam
120                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoSceneMode : settings.imageSceneMode : 0
121         }
122
123         ColorTone {
124                 id: colorToneController
125                 camera: cam
126                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoColorFilter : settings.imageColorFilter : 0
127         }
128
129         WhiteBalance {
130                 id: whiteBalanceController
131                 camera: cam
132                 value: ready ? camera.mode == Camera.VideoMode ? settings.videoWhiteBalance : settings.imageWhiteBalance : 0
133         }
134
135         ModeController {
136                 id: cameraMode
137                 cam: cam
138                 dimmer: root.dimmer
139         }
140
141         Connections {
142                 target: cam
143                 onModeChanged: {
144                         if (cam.mode == Camera.VideoMode) {
145                                 replacePage("VideoPage.qml");
146                         }
147                         else {
148                                 replacePage("ImagePage.qml");
149                         }
150                 }
151         }
152 }