Ported ShareHelper to ShareUiInterface
[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 // TODO: losing resources while playback won't show an error
30 // TODO: show something if we have no files.
31 // TODO: favorites
32 // TODO: menu
33 CameraPage {
34         id: page
35
36         controlsVisible: false
37         policyMode: CameraResources.PostCapture
38         needsPipeline: false
39         standbyVisible: !Qt.application.active
40
41         property Item currentItem: null
42         property bool available: currentItem ? currentItem.itemAvailable : false
43
44         function parseDate(str) {
45                 var parts = str.split('T');
46                 var dates = parts[0].split('-');
47                 var times = parts[1].split(':');
48                 return new Date(dates[0], dates[1], dates[2], times[0], times[1], times[2]);
49         }
50
51         function deleteCurrentItem() {
52                 if (!available) {
53                         return;
54                 }
55
56                 deleteDialog.message = currentItem.fileName;
57                 deleteDialog.open();
58         }
59
60         QueryDialog {
61                 id: deleteDialog
62                 titleText: qsTr("Delete item?");
63                 acceptButtonText: qsTr("Yes");
64                 rejectButtonText: qsTr("No");
65                 onAccepted: {
66                         // TODO: Remove from model and move to next item
67                         if (!remove.remove(currentItem.itemUrl)) {
68                                 showError(qsTr("Failed to delete item"));
69                         }
70                 }
71
72                 DeleteHelper {
73                         id: remove
74                 }
75         }
76
77         function shareCurrentItem() {
78                 if (!available) {
79                         return;
80                 }
81
82                 if (!share.share(currentItem.itemUrl)) {
83                                 showError(qsTr("Failed to launch share service"));
84                 }
85         }
86
87         ShareHelper {
88                 id: share
89         }
90
91         Rectangle {
92                 color: "black"
93                 anchors.fill: parent
94         }
95
96         PathView {
97                 id: view
98                 anchors.fill: parent
99
100                 path: Path {
101                         startX: - view.width
102                         startY: view.height / 2
103                         PathLine { x: view.width * 2; y: view.height / 2 }
104                 }
105
106                 flickDeceleration: 999999 // Insanely high value to prevent panning multiple images
107                 preferredHighlightBegin: 0.5
108                 preferredHighlightEnd: 0.5
109                 highlightRangeMode: PathView.StrictlyEnforceRange
110                 pathItemCount: 3
111
112                 model: SparqlListModel {
113                         query: 'SELECT rdf:type(?urn) AS ?type nie:url(?urn) AS ?url nie:contentCreated(?urn) AS ?created nie:title(?urn) AS ?title nfo:fileName(?urn) AS ?filename nie:mimeType(?urn) AS ?mimetype tracker:available(?urn) AS ?available nfo:fileLastModified(?urn) as ?lastmod tracker:id(?urn) AS ?trackerid  (EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite }) AS ?favorite WHERE { ?urn nfo:equipment "urn:equipment:' + deviceInfo.manufacturer + ':' + deviceInfo.model + ':" .  {?urn a nfo:Video} UNION {?urn a nfo:Image}} ORDER BY DESC(?created)'
114
115                         connection: SparqlConnection {
116                                 id: connection
117                                 driver: "QTRACKER_DIRECT"
118                                 onStatusChanged: checkStatus(status)
119
120                                 function checkStatus(status) {
121                                         if (status == SparqlConnection.Error) {
122                                                 // TODO: report error
123                                                 console.log("Error = " + connection.errorString());
124                                         }
125                                 }
126                         }
127                 }
128
129                 delegate: PostCaptureItem {
130                         width: view.width - 10
131                         height: view.height
132                 }
133         }
134
135         ToolBar {
136                 id: toolBar
137                 opacity: 0.8
138                 anchors.bottom: parent.bottom
139                 tools: ToolBarLayout {
140                         id: layout
141                         ToolIcon { iconId: "icon-m-toolbar-back-white"; onClicked: { pageStack.pop(); } }
142                         ToolIcon { iconId: available ? "icon-m-toolbar-favorite-mark-white" : "icon-m-toolbar-favorite-mark-dimmed-white"}
143                         ToolIcon { iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"; onClicked: shareCurrentItem(); }
144                         ToolIcon { iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"; onClicked: deleteCurrentItem(); }
145                         ToolIcon { iconId: "icon-m-toolbar-view-menu-white" }
146                 }
147         }
148
149         ToolBar {
150                 opacity: toolBar.opacity
151                 anchors.top: parent.top
152                 visible: toolBar.visible
153
154                 tools: ToolBarLayout {
155                         Label {
156                                 text: currentItem ? currentItem.itemTitle : ""
157                                 anchors.top: parent.top
158                                 anchors.bottom: parent.bottom
159                                 anchors.left: parent.left
160                                 font.bold: true
161                                 verticalAlignment: Text.AlignVCenter
162                         }
163
164                         Label {
165                                 text: currentItem ? Qt.formatDateTime(parseDate(currentItem.creationDate)) : ""
166                                 font.bold: true
167                                 anchors.top: parent.top
168                                 anchors.bottom: parent.bottom
169                                 anchors.right: parent.right
170                                 verticalAlignment: Text.AlignVCenter
171                         }
172                 }
173         }
174 }