Don't show the error unless page is Active
[harmattan/cameraplus] / qml / PostCapturePage.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 QtSparql 1.0
27 import CameraPlus 1.0
28
29 // QML QtGallery stuff is crap.
30 // Most of the ideas (and some code) for loading and displaying images are stolen from
31 // N9QmlPhotoPicker https://github.com/petrumotrescu/N9QmlPhotoPicker
32
33 // TODO: this is really basic.
34
35 CameraPage {
36         id: page
37
38         controlsVisible: false
39         policyMode: CameraResources.PostCapture
40         needsPipeline: true
41
42         onStatusChanged: {
43                 if (status == PageStatus.Active) {
44                         cam.stop();
45                 }
46         }
47
48         Connections {
49                 // Unlikely that we need this.
50                 target: cam
51                 onIdleChanged: {
52                         if (cam.idle && page.status == PageStatus.Active) {
53                                 cam.stop();
54                         }
55                 }
56         }
57
58         Rectangle {
59                 color: "black"
60                 anchors.fill: parent
61         }
62
63         PathView {
64                 id: view
65                 anchors.fill: parent
66
67                 path: Path {
68                         startX: -view.width
69                         startY: view.height / 2
70                         PathLine { x: view.width * 2; y: view.height / 2 }
71                 }
72
73                 flickDeceleration: 999999 // Insanely high value to prevent panning multiple images
74                 preferredHighlightBegin: 0.5
75                 preferredHighlightEnd: 0.5
76                 highlightRangeMode: PathView.StrictlyEnforceRange
77                 pathItemCount: 3
78
79                 model: SparqlListModel {
80                         // This is the exact query used by Harmattan gallery.
81                         // Gallery prints it as part of its debugging when
82                         // passing -output-level debug ;-)
83                         query: "SELECT nie:url(?urn) AS ?url nfo:fileName(?urn) AS ?filename ?created nie:mimeType(?urn) AS ?mimetype ( EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite . } ) AS ?favorite nfo:duration(?urn) AS ?duration ?urn \"false\"^^xsd:boolean AS ?isVirtual nfo:fileLastModified(?urn) as ?lastmod nfo:hasRegionOfInterest(?urn) as ?roi tracker:id(?urn) AS ?trackerid WHERE { ?urn rdf:type nfo:Visual ; tracker:available \"true\"^^xsd:boolean . OPTIONAL { ?urn nie:contentCreated ?created } . ?urn nfo:equipment \"urn:equipment:" + deviceInfo.manufacturer + ":" + deviceInfo.model + ":\" . } ORDER BY DESC (?created)"
84
85                         connection: SparqlConnection {
86                                 id: connection
87                                 driver: "QTRACKER_DIRECT"
88                                 onStatusChanged: checkStatus(status)
89
90                                 function checkStatus(status) {
91                                         if (status == SparqlConnection.Error) {
92                                                 console.log("Error = "+connection.errorString());
93                                         }
94                                 }
95                         }
96                 }
97
98                 delegate: Item {
99                         width: view.width
100                         height: view.height
101
102                         Label {
103                                 width: view.width - 10
104                                 height: view.height
105                                 anchors.centerIn: parent
106                                 visible: item.error && page.status == PageStatus.Active
107                                 text: qsTr("Failed to load preview");
108                                 verticalAlignment: Text.AlignVCenter
109                                 horizontalAlignment: Text.AlignHCenter
110                                 font.pixelSize: 32
111                         }
112
113                         QuillItem {
114                                 id: item
115                                 source: url
116                                 mimeType: mimetype
117                                 width: view.width - 10
118                                 height: view.height
119                                 anchors.centerIn: parent
120
121                                 MouseArea {
122                                         id: mouse
123                                         anchors.fill: parent
124                                         enabled: true
125                                         onClicked: toolBar.visible = !toolBar.visible
126                                 }
127                         }
128                 }
129         }
130
131         ToolBar {
132                 id: toolBar
133                 opacity: 0.8
134                 anchors.bottom: parent.bottom
135                 tools: ToolBarLayout {
136                         id: layout
137                         ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: { cam.start(); pageStack.pop(); } }
138                 }
139         }
140
141         Rectangle {
142                 // TODO: transitions
143                 id: rect
144                 anchors.top: parent.top
145                 height: toolBar.height
146                 width: parent.width
147                 color: "black"
148                 opacity: toolBar.opacity
149                 visible: toolBar.visible
150                 Row {
151                         anchors.fill: parent
152
153                         Label {
154
155                         }
156
157                         Label {
158
159                         }
160                 }
161         }
162 }