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