Replace maemo-meegotouch interfaces with DBus calls.
[harmattan/cameraplus] / qml / PostCapturePage.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 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 CameraPage {
29         id: page
30
31         controlsVisible: false
32         policyMode: CameraResources.None
33         activationData: ControlsActivationData {standbyVisible: !Qt.application.active}
34
35         property Item currentItem: null
36         property bool available: currentItem ? currentItem.itemData.available : false
37
38         Component.onCompleted: postCaptureModel.reload();
39
40         function launchGallery() {
41                 if (!gallery.launch()) {
42                         showError(qsTr("Failed to launch gallery"));
43                 }
44         }
45
46         function showInGallery() {
47                 if (!available) {
48                         return;
49                 }
50
51                 if (!gallery.show(currentItem.itemUrl)) {
52                         showError(qsTr("Failed to launch gallery"));
53                 }
54         }
55
56         Menu {
57                 id: menu
58                 onStatusChanged: page.restartTimer();
59
60                 MenuLayout {
61                         MenuItem {text: qsTr("Captures in gallery"); onClicked: launchGallery(); }
62                         MenuItem {text: qsTr("View in gallery"); enabled: available; onClicked: showInGallery(); }
63                 }
64         }
65
66         function deleteCurrentItem() {
67                 if (!available) {
68                         return;
69                 }
70
71                 deleteDialog.message = currentItem.itemData.fileName;
72                 deleteDialog.open();
73         }
74
75         QueryDialog {
76                 id: deleteDialog
77                 titleText: qsTr("Delete item?");
78                 acceptButtonText: qsTr("Yes");
79                 rejectButtonText: qsTr("No");
80
81                 onStatusChanged: page.restartTimer();
82
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         function addOrRemoveFavorite() {
108                 if (!available) {
109                         return;
110                 }
111
112                 if (currentItem.itemData.favorite) {
113                         if (!trackerStore.removeFromFavorites(currentItem.itemData.url)) {
114                                 showError(qsTr("Failed to remove favorite"));
115                         }
116                         else {
117                                 currentItem.itemData.favorite = false;
118                         }
119                 }
120                 else {
121                         if (!trackerStore.addToFavorites(currentItem.itemData.url)) {
122                                 showError(qsTr("Failed to add favorite"));
123                         }
124                         else {
125                                 currentItem.itemData.favorite = true;
126                         }
127                 }
128         }
129
130         ShareHelper {
131                 id: share
132                 settings: platformSettings
133         }
134
135         GalleryHelper {
136                 id: gallery
137                 settings: platformSettings
138         }
139
140         Rectangle {
141                 color: "black"
142                 anchors.fill: parent
143         }
144
145         PathView {
146                 id: view
147                 anchors.fill: parent
148
149                 path: Path {
150                         startX: - view.width
151                         startY: view.height / 2
152                         PathLine { x: view.width * 2; y: view.height / 2 }
153                 }
154
155                 // Insanely high value to prevent panning multiple images
156                 flickDeceleration: 999999
157
158                 preferredHighlightBegin: 0.5
159                 preferredHighlightEnd: 0.5
160                 highlightRangeMode: PathView.StrictlyEnforceRange
161                 pathItemCount: 3
162
163                 model: PostCaptureModel {
164                         id: postCaptureModel
165                         manufacturer: deviceInfo.manufacturer
166                         model: deviceInfo.model
167                         onError: {
168                                 console.log("Error populating model " + msg);
169                                 showError(qsTr("Failed to load captures"));
170                         }
171                 }
172
173                 Label {
174                         // TODO: Hide this when we have no items
175                         text: qsTr("No captures available");
176                         anchors.centerIn: parent
177                         font.pixelSize: 36
178                         visible: currentItem == null
179                 }
180
181                 delegate: PostCaptureItem {
182                         width: view.width
183                         height: view.height
184                         onClicked: hideTimer.running = !hideTimer.running;
185                 }
186         }
187
188         function restartTimer() {
189                 hideTimer.running = true;
190         }
191
192         Timer {
193                 id: hideTimer
194                 running: false
195                 interval: 3000
196         }
197
198         CameraToolBar {
199                 id: toolBar
200                 expanded: true
201                 manualBack: true
202                 anchors.bottom: parent.bottom
203                 anchors.bottomMargin: show ? 20 : -1 * (height + 20)
204                 anchors.left: parent.left
205                 anchors.leftMargin: 20
206                 opacity: 0.8
207
208                 property bool show: deleteDialog.status == DialogStatus.Open || deleteDialog.status == DialogStatus.Opening || hideTimer.running || menu.status == DialogStatus.Open || menu.status == DialogStatus.Opening || (currentItem && currentItem.error)
209
210                 onClicked: pageStack.pop();
211
212                 Behavior on anchors.bottomMargin {
213                         PropertyAnimation { duration: 200; }
214                 }
215
216                 items: [
217                         ToolIcon { iconId: !available ? "icon-m-toolbar-favorite-mark-dimmed-white" : currentItem.itemData.favorite ? "icon-m-toolbar-favorite-mark-white" : "icon-m-toolbar-favorite-unmark-white"; onClicked: { addOrRemoveFavorite(); page.restartTimer(); } },
218                         ToolIcon { iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"; onClicked: { shareCurrentItem(); page.restartTimer(); } },
219                         ToolIcon { iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"; onClicked: { deleteCurrentItem(); page.restartTimer(); } },
220                         ToolIcon { iconId: "icon-m-toolbar-view-menu-white"; onClicked: { menu.open(); page.restartTimer(); } }
221                 ]
222         }
223
224         Rectangle {
225                 opacity: toolBar.opacity
226                 anchors.top: parent.top
227                 anchors.topMargin: toolBar.show ? 20 : -1 * (height + 20)
228                 anchors.left: parent.left
229                 anchors.leftMargin: 20
230                 anchors.right: parent.right
231                 anchors.rightMargin: 20
232                 visible: toolBar.visible
233                 height: screen.isPortrait ? toolBar.height * 2 : toolBar.height
234                 color: toolBar.color
235                 border.color: toolBar.border.color
236                 radius: toolBar.radius
237
238                 Behavior on anchors.topMargin {
239                         PropertyAnimation { duration: 200; }
240                 }
241
242                 Flow {
243                         width: parent.width - 40
244                         x: 20
245                         height: parent.height
246
247                         Label {
248                                 text: currentItem ? currentItem.itemData.title : ""
249                                 width: parent.width / 2
250                                 height: parent.height
251                                 font.bold: true
252                                 verticalAlignment: Text.AlignVCenter
253                                 horizontalAlignment: Text.AlignLeft
254                         }
255
256                         Label {
257                                 text: currentItem ? currentItem.itemData.created : ""
258                                 width: parent.width / 2
259                                 height: parent.height
260                                 font.bold: true
261                                 verticalAlignment: Text.AlignVCenter
262                                 horizontalAlignment: Text.AlignRight
263                         }
264                 }
265         }
266 }