Implemented PostCaptureModel using QtSparql:
[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 CameraPlus 1.0
27
28 // TODO: losing resources while playback won't show an error
29 // TODO: favorites
30 // TODO: mass storage mode interaction
31
32 CameraPage {
33         id: page
34
35         controlsVisible: false
36         policyMode: CameraResources.PostCapture
37         needsPipeline: false
38         standbyVisible: !Qt.application.active
39
40         property Item currentItem: null
41         property bool available: currentItem ? currentItem.itemData.available : false
42
43         Component.onCompleted: postCaptureModel.reload();
44
45         function launchGallery() {
46                 if (!gallery.launch()) {
47                         showError(qsTr("Failed to launch gallery"));
48                 }
49         }
50
51         function showInGallery() {
52                 if (!available) {
53                         return;
54                 }
55
56                 if (!gallery.show(currentItem.itemUrl)) {
57                         showError(qsTr("Failed to launch gallery"));
58                 }
59         }
60
61         Menu {
62                 id: menu
63                 MenuLayout {
64                         MenuItem {text: qsTr("Captures in gallery"); onClicked: launchGallery(); }
65                         MenuItem {text: qsTr("View in gallery"); enabled: available; onClicked: showInGallery(); }
66                 }
67         }
68
69         function deleteCurrentItem() {
70                 if (!available) {
71                         return;
72                 }
73
74                 deleteDialog.message = currentItem.itemData.fileName;
75                 deleteDialog.open();
76         }
77
78         QueryDialog {
79                 id: deleteDialog
80                 titleText: qsTr("Delete item?");
81                 acceptButtonText: qsTr("Yes");
82                 rejectButtonText: qsTr("No");
83                 onAccepted: {
84                         if (!remove.remove(currentItem.itemData.url)) {
85                                 showError(qsTr("Failed to delete item"));
86                         }
87                         else {
88                                 postCaptureModel.remove(currentItem.itemData);
89                         }
90                 }
91
92                 DeleteHelper {
93                         id: remove
94                 }
95         }
96
97         function shareCurrentItem() {
98                 if (!available) {
99                         return;
100                 }
101
102                 if (!share.share(currentItem.itemData.url)) {
103                                 showError(qsTr("Failed to launch share service"));
104                 }
105         }
106
107         ShareHelper {
108                 id: share
109         }
110
111         GalleryHelper {
112                 id: gallery
113         }
114
115         Rectangle {
116                 color: "black"
117                 anchors.fill: parent
118         }
119
120         PathView {
121                 id: view
122                 anchors.fill: parent
123
124                 path: Path {
125                         startX: - view.width
126                         startY: view.height / 2
127                         PathLine { x: view.width * 2; y: view.height / 2 }
128                 }
129
130                 flickDeceleration: 999999 // Insanely high value to prevent panning multiple images
131                 preferredHighlightBegin: 0.5
132                 preferredHighlightEnd: 0.5
133                 highlightRangeMode: PathView.StrictlyEnforceRange
134                 pathItemCount: 3
135
136                 model: PostCaptureModel {
137                         id: postCaptureModel
138                         manufacturer: deviceInfo.manufacturer
139                         model: deviceInfo.model
140                         onError: {
141                                 console.log("Error populating model " + msg);
142                                 showError(qsTr("Failed to load captures"));
143                         }
144                 }
145
146                 Label {
147                         // TODO: Hide this when we have no items
148                         text: qsTr("No captures available");
149                         anchors.centerIn: parent
150                         font.pixelSize: 36
151                         visible: currentItem == null
152                 }
153
154                 delegate: PostCaptureItem {
155                         width: view.width - 10
156                         height: view.height
157                 }
158         }
159
160         ToolBar {
161                 id: toolBar
162                 opacity: 0.8
163                 anchors.bottom: parent.bottom
164                 tools: ToolBarLayout {
165                         id: layout
166                         ToolIcon { iconId: "icon-m-toolbar-back-white"; onClicked: { pageStack.pop(); } }
167                         ToolIcon { iconId: available ? "icon-m-toolbar-favorite-mark-white" : "icon-m-toolbar-favorite-mark-dimmed-white"}
168                         ToolIcon { iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"; onClicked: shareCurrentItem(); }
169                         ToolIcon { iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"; onClicked: deleteCurrentItem(); }
170                         ToolIcon { iconId: "icon-m-toolbar-view-menu-white"; onClicked: menu.open(); }
171                 }
172         }
173
174         ToolBar {
175                 opacity: toolBar.opacity
176                 anchors.top: parent.top
177                 visible: toolBar.visible
178
179                 tools: ToolBarLayout {
180                         Label {
181                                 text: currentItem ? currentItem.itemData.title : ""
182                                 anchors.top: parent.top
183                                 anchors.bottom: parent.bottom
184                                 anchors.left: parent.left
185                                 font.bold: true
186                                 verticalAlignment: Text.AlignVCenter
187                         }
188
189                         Label {
190                                 text: currentItem ? currentItem.itemData.created : ""
191                                 font.bold: true
192                                 anchors.top: parent.top
193                                 anchors.bottom: parent.bottom
194                                 anchors.right: parent.right
195                                 verticalAlignment: Text.AlignVCenter
196                         }
197                 }
198         }
199 }