Initial ui reimplementation. Still in its early phase.
[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
27 Item {
28     property bool pressed: view.currentItem ? view.currentItem.playing : false
29     property int policyMode: CameraResources.None
30     property bool available: view.currentItem ? view.currentItem.itemData.available : false
31
32     Component.onCompleted: postCaptureModel.reload()
33
34     ShareHelper {
35         id: share
36         settings: platformSettings
37     }
38
39     GalleryHelper {
40         id: gallery
41         settings: platformSettings
42     }
43
44     ListView {
45         id: view
46         anchors.fill: parent
47         snapMode: ListView.SnapOneItem
48         cacheBuffer: height * 3
49         model: postCaptureModel
50         highlightRangeMode: ListView.StrictlyEnforceRange
51
52         delegate: PostCaptureItem {
53             width: view.width
54             height: view.height
55             onClicked: hideTimer.running = !hideTimer.running
56         }
57
58         onFlickingChanged: {
59             if (flicking && hideTimer.running) {
60                 restartTimer()
61             }
62         }
63     }
64
65     PostCaptureModel {
66         // TODO: this should not be active all the time
67         id: postCaptureModel
68         manufacturer: deviceInfo.manufacturer
69         model: deviceInfo.model
70         onError: {
71             console.log("Error populating model " + msg)
72             showError(qsTr("Failed to load captures"))
73         }
74     }
75
76     Timer {
77         id: hideTimer
78         running: false
79         interval: 3000
80     }
81
82     CameraToolBar {
83         id: toolBar
84         expanded: true
85         manualBack: true
86         anchors.bottom: parent.bottom
87         anchors.bottomMargin: show ? 20 : -1 * (height + 20)
88         anchors.left: parent.left
89         anchors.leftMargin: 20
90         opacity: 0.8
91 // TODO: hide back button
92         property bool show: deleteDialog.status == DialogStatus.Open ||
93             deleteDialog.status == DialogStatus.Opening ||
94             hideTimer.running || menu.status == DialogStatus.Open ||
95             menu.status == DialogStatus.Opening ||
96             (view.currentItem && view.currentItem.error) && !view.currentItem.playing
97
98 // TODO:
99 //        onClicked: pageStack.pop()
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 }