We will pretend that we have the same camera resources used by the overlay
[harmattan/cameraplus] / qml / PostCaptureView.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 CameraPlus 1.0
25 import com.nokia.meego 1.1
26 import QtCamera 1.0
27
28 Item {
29     property bool pressed: view.currentItem ? view.currentItem.playing : false
30     property int policyMode: settings.mode == Camera.VideoMode ? CameraResources.Video
31         : CameraResources.Image
32     property bool available: view.currentItem ? view.currentItem.itemData.available : false
33
34     Component.onCompleted: postCaptureModel.reload()
35
36     ShareHelper {
37         id: share
38         settings: platformSettings
39     }
40
41     GalleryHelper {
42         id: gallery
43         settings: platformSettings
44     }
45
46     ListView {
47         id: view
48         anchors.fill: parent
49         snapMode: ListView.SnapOneItem
50         cacheBuffer: height * 3
51         model: postCaptureModel
52         highlightRangeMode: ListView.StrictlyEnforceRange
53
54         delegate: PostCaptureItem {
55             width: view.width
56             height: view.height
57             onClicked: hideTimer.running = !hideTimer.running
58         }
59
60         onFlickingChanged: {
61             if (flicking && hideTimer.running) {
62                 restartTimer()
63             }
64         }
65     }
66
67     PostCaptureModel {
68         // TODO: this should not be active all the time
69         id: postCaptureModel
70         manufacturer: deviceInfo.manufacturer
71         model: deviceInfo.model
72         onError: {
73             console.log("Error populating model " + msg)
74             showError(qsTr("Failed to load captures"))
75         }
76     }
77
78     Timer {
79         id: hideTimer
80         running: false
81         interval: 3000
82     }
83
84     CameraToolBar {
85         id: toolBar
86         expanded: true
87         manualBack: true
88         anchors.bottom: parent.bottom
89         anchors.bottomMargin: show ? 20 : -1 * (height + 20)
90         anchors.left: parent.left
91         anchors.leftMargin: 20
92         opacity: 0.8
93 // TODO: hide back button
94         property bool show: deleteDialog.status == DialogStatus.Open ||
95             deleteDialog.status == DialogStatus.Opening ||
96             hideTimer.running || menu.status == DialogStatus.Open ||
97             menu.status == DialogStatus.Opening ||
98             (view.currentItem && view.currentItem.error) && !view.currentItem.playing
99
100 // TODO:
101 //        onClicked: pageStack.pop()
102
103         Behavior on anchors.bottomMargin {
104             PropertyAnimation { duration: 200; }
105         }
106
107         items: [
108             ToolIcon {
109                 iconId: !available ? "icon-m-toolbar-favorite-mark-dimmed-white" : view.currentItem.itemData.favorite ? "icon-m-toolbar-favorite-mark-white" : "icon-m-toolbar-favorite-unmark-white"
110                 onClicked: {
111                     addOrRemoveFavorite()
112                     restartTimer()
113                 }
114             },
115             ToolIcon {
116                 iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"
117                 onClicked: {
118                     shareCurrentItem()
119                     restartTimer()
120                 }
121             },
122             ToolIcon {
123                 iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"
124                 onClicked: {
125                     deleteCurrentItem()
126                     restartTimer()
127                 }
128             },
129             ToolIcon {
130                 iconId: "icon-m-toolbar-view-menu-white"
131                 onClicked: {
132                     menu.open()
133                     restartTimer()
134                 }
135             }
136         ]
137     }
138
139     QueryDialog {
140         id: deleteDialog
141         titleText: qsTr("Delete item?");
142         acceptButtonText: qsTr("Yes");
143         rejectButtonText: qsTr("No");
144
145         onStatusChanged: restartTimer()
146
147         onAccepted: {
148             if (!remove.remove(view.currentItem.itemData.url)) {
149                 showError(qsTr("Failed to delete item"))
150             } else {
151                 postCaptureModel.remove(view.currentItem.itemData);
152             }
153         }
154
155         DeleteHelper {
156             id: remove
157         }
158     }
159
160     Menu {
161         id: menu
162         onStatusChanged: restartTimer()
163
164         MenuLayout {
165             MenuItem {
166                 text: qsTr("Captures in gallery")
167                 onClicked: launchGallery()
168             }
169
170             MenuItem {
171                 text: qsTr("View in gallery")
172                 enabled: available
173                 onClicked: showInGallery()
174             }
175         }
176     }
177
178     Rectangle {
179         opacity: toolBar.opacity
180         anchors.top: parent.top
181         anchors.topMargin: toolBar.show ? 20 : -1 * (height + 20)
182         anchors.left: parent.left
183         anchors.leftMargin: 20
184         anchors.right: parent.right
185         anchors.rightMargin: 20
186         visible: toolBar.visible
187         height: screen.isPortrait ? toolBar.height * 2 : toolBar.height
188         color: toolBar.color
189         border.color: toolBar.border.color
190         radius: toolBar.radius
191
192         Behavior on anchors.topMargin {
193             PropertyAnimation { duration: 200; }
194         }
195
196         Flow {
197             width: parent.width - 40
198             x: 20
199             height: parent.height
200
201             Label {
202                 text: view.currentItem ? view.currentItem.itemData.title : ""
203                 width: parent.width / 2
204                 height: parent.height
205                 font.bold: true
206                 verticalAlignment: Text.AlignVCenter
207                 horizontalAlignment: Text.AlignLeft
208             }
209
210             Label {
211                 text: view.currentItem ? view.currentItem.itemData.created : ""
212                 width: parent.width / 2
213                 height: parent.height
214                 font.bold: true
215                 verticalAlignment: Text.AlignVCenter
216                 horizontalAlignment: Text.AlignRight
217             }
218         }
219     }
220
221     function launchGallery() {
222         if (!gallery.launch()) {
223             showError(qsTr("Failed to launch gallery"))
224         }
225     }
226
227     function showInGallery() {
228         if (!available) {
229             return
230         }
231
232         if (!gallery.show(view.currentItem.itemUrl)) {
233             showError(qsTr("Failed to launch gallery"))
234         }
235     }
236
237     function deleteCurrentItem() {
238         if (!available) {
239             return
240         }
241
242         deleteDialog.message = view.currentItem.itemData.fileName
243         deleteDialog.open()
244     }
245
246     function shareCurrentItem() {
247         if (!available) {
248             return
249         }
250
251         if (!share.share(view.currentItem.itemData.url)) {
252             showError(qsTr("Failed to launch share service"))
253         }
254     }
255
256     function addOrRemoveFavorite() {
257         if (!available) {
258             return
259         }
260
261         if (view.currentItem.itemData.favorite) {
262             if (!trackerStore.removeFromFavorites(view.currentItem.itemData.url)) {
263                 showError(qsTr("Failed to remove favorite"))
264             } else {
265                 view.currentItem.itemData.favorite = false
266             }
267         } else {
268             if (!trackerStore.addToFavorites(view.currentItem.itemData.url)) {
269                 showError(qsTr("Failed to add favorite"))
270             } else {
271                 view.currentItem.itemData.favorite = true
272             }
273         }
274     }
275
276     function restartTimer() {
277         hideTimer.restart()
278     }
279 }