Reworked ModeButton to use a Switch
[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: losing resources while playback won't show an error
34
35 CameraPage {
36         id: page
37
38         controlsVisible: false
39         policyMode: CameraResources.PostCapture
40         needsPipeline: false
41         standbyVisible: !Qt.application.active
42
43         property Item currentItem: null
44
45         function parseDate(str) {
46                 var parts = str.split('T');
47                 var dates = parts[0].split('-');
48                 var times = parts[1].split(':');
49                 return new Date(dates[0], dates[1], dates[2], times[0], times[1], times[2]);
50         }
51
52         Rectangle {
53                 color: "black"
54                 anchors.fill: parent
55         }
56
57         PathView {
58                 id: view
59                 anchors.fill: parent
60
61                 path: Path {
62                         startX: - view.width
63                         startY: view.height / 2
64                         PathLine { x: view.width * 2; y: view.height / 2 }
65                 }
66
67                 flickDeceleration: 999999 // Insanely high value to prevent panning multiple images
68                 preferredHighlightBegin: 0.5
69                 preferredHighlightEnd: 0.5
70                 highlightRangeMode: PathView.StrictlyEnforceRange
71                 pathItemCount: 3
72
73                 model: SparqlListModel {
74                         query: "SELECT nie:url(?urn) AS ?url nie:title(?urn) AS ?title nfo:fileName(?urn) AS ?filename ?created nie:mimeType(?urn) AS ?mimetype ( EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite . } ) AS ?favorite nfo:fileLastModified(?urn) as ?lastmod 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)"
75
76                         connection: SparqlConnection {
77                                 id: connection
78                                 driver: "QTRACKER_DIRECT"
79                                 onStatusChanged: checkStatus(status)
80
81                                 function checkStatus(status) {
82                                         if (status == SparqlConnection.Error) {
83                                                 // TODO: report error
84                                                 console.log("Error = " + connection.errorString());
85                                         }
86                                 }
87                         }
88                 }
89
90                 delegate: PostCaptureItem {
91                         width: view.width - 10
92                         height: view.height
93                 }
94         }
95
96         ToolBar {
97                 id: toolBar
98                 opacity: 0.8
99                 anchors.bottom: parent.bottom
100                 tools: ToolBarLayout {
101                         id: layout
102                         ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: { pageStack.pop(); } }
103                 }
104         }
105
106         ToolBar {
107                 opacity: toolBar.opacity
108                 anchors.top: parent.top
109                 visible: toolBar.visible
110
111                 tools: ToolBarLayout {
112                         Label {
113                                 text: currentItem ? currentItem.itemTitle : ""
114                                 anchors.top: parent.top
115                                 anchors.bottom: parent.bottom
116                                 anchors.left: parent.left
117                                 font.bold: true
118                                 verticalAlignment: Text.AlignVCenter
119                         }
120
121                         Label {
122                                 text: currentItem ? Qt.formatDateTime(parseDate(currentItem.creationDate)) : ""
123                                 font.bold: true
124                                 anchors.top: parent.top
125                                 anchors.bottom: parent.bottom
126                                 anchors.right: parent.right
127                                 verticalAlignment: Text.AlignVCenter
128                         }
129                 }
130         }
131 }