Added resource policy support (Still needs more testing) and refactored the pipeline...
[harmattan/cameraplus] / qml / PostCapturePage.qml
1 // -*- qml -*-
2 import QtQuick 1.1
3 import com.nokia.meego 1.1
4 import QtCamera 1.0
5 import QtSparql 1.0
6 import CameraPlus 1.0
7
8 // QML QtGallery stuff is crap.
9 // Most of the ideas (and some code) for loading and displaying images are stolen from
10 // N9QmlPhotoPicker https://github.com/petrumotrescu/N9QmlPhotoPicker
11
12 // TODO: this is really basic.
13
14 CameraPage {
15         id: page
16
17         controlsVisible: false
18         policyMode: CameraResources.PostCapture
19         needsPipeline: true
20
21         onStatusChanged: {
22                 if (status == PageStatus.Active) {
23                         cam.stop();
24                 }
25         }
26
27         Connections {
28                 // Unlikely that we need this.
29                 target: cam
30                 onIdleChanged: {
31                         if (cam.idle && page.status == PageStatus.Active) {
32                                 cam.stop();
33                         }
34                 }
35         }
36
37         Rectangle {
38                 color: "black"
39                 anchors.fill: parent
40         }
41
42         PathView {
43                 id: view
44                 anchors.fill: parent
45
46                 path: Path {
47                         startX: - view.width
48                         startY: view.height / 2
49                         PathLine { x: view.width * 2; y: view.height / 2 }
50                 }
51
52                 flickDeceleration: 999999 // Insanely high value to prevent panning multiple images
53                 preferredHighlightBegin: 0.5
54                 preferredHighlightEnd: 0.5
55                 highlightRangeMode: PathView.StrictlyEnforceRange
56                 pathItemCount: 3
57
58                 model: SparqlListModel {
59                         query: "SELECT nie:url(?urn) AS ?url tracker:id(?urn) AS ?trackerid nie:mimeType(?urn) AS ?mime WHERE { ?urn rdf:type nfo:Media .  ?urn nfo:equipment \"urn:equipment:" + deviceInfo.manufacturer + ":" + deviceInfo.model + ":\" ; tracker:available \"true\"^^xsd:boolean  OPTIONAL { ?urn nie:contentCreated ?created }   }  ORDER BY DESC (?created)"
60
61                         connection: SparqlConnection {
62                                 id: connection
63                                 driver: "QTRACKER_DIRECT"
64                                 onStatusChanged: checkStatus(status)
65
66                                 function checkStatus(status) {
67                                         if (status == SparqlConnection.Error) {
68                                                 console.log("Error = "+connection.errorString());
69                                         }
70                                 }
71                         }
72                 }
73
74                 // TODO: tap post capture and then immediately back and you can see the error
75                 // and the standby widget underneath it.
76                 delegate: Item {
77                         width: view.width
78                         height: view.height
79
80                         Label {
81                                 width: view.width - 10
82                                 height: view.height
83                                 anchors.centerIn: parent
84                                 visible: item.error
85                                 text: qsTr("Failed to load preview");
86                                 verticalAlignment: Text.AlignVCenter
87                                 horizontalAlignment: Text.AlignHCenter
88                                 font.pixelSize: 32
89                         }
90
91                         QuillItem {
92                                 id: item
93                                 source: url
94                                 mimeType: mime
95                                 width: view.width - 10
96                                 height: view.height
97                                 anchors.centerIn: parent
98                         }
99                 }
100         }
101
102         ToolBar {
103                 id: toolBar
104                 opacity: 0.8
105                 anchors.bottom: parent.bottom
106                 tools: ToolBarLayout {
107                         id: layout
108                         ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: { cam.start(); pageStack.pop(); } }
109                 }
110         }
111 }