Use font.capitalization instead of the custom javascript function used and return...
[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 CameraPage {
29         id: page
30
31         controlsVisible: false
32         policyMode: CameraResources.None
33         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         }
133
134         GalleryHelper {
135                 id: gallery
136         }
137
138         Rectangle {
139                 color: "black"
140                 anchors.fill: parent
141         }
142
143         PathView {
144                 id: view
145                 anchors.fill: parent
146
147                 path: Path {
148                         startX: - view.width
149                         startY: view.height / 2
150                         PathLine { x: view.width * 2; y: view.height / 2 }
151                 }
152
153                 // Insanely high value to prevent panning multiple images
154                 flickDeceleration: 999999
155
156                 preferredHighlightBegin: 0.5
157                 preferredHighlightEnd: 0.5
158                 highlightRangeMode: PathView.StrictlyEnforceRange
159                 pathItemCount: 3
160
161                 model: PostCaptureModel {
162                         id: postCaptureModel
163                         manufacturer: deviceInfo.manufacturer
164                         model: deviceInfo.model
165                         onError: {
166                                 console.log("Error populating model " + msg);
167                                 showError(qsTr("Failed to load captures"));
168                         }
169                 }
170
171                 Label {
172                         // TODO: Hide this when we have no items
173                         text: qsTr("No captures available");
174                         anchors.centerIn: parent
175                         font.pixelSize: 36
176                         visible: currentItem == null
177                 }
178
179                 delegate: PostCaptureItem {
180                         width: view.width
181                         height: view.height
182                         onClicked: hideTimer.running = !hideTimer.running;
183                 }
184         }
185
186         function restartTimer() {
187                 hideTimer.running = true;
188         }
189
190         Timer {
191                 id: hideTimer
192                 running: false
193                 interval: 3000
194         }
195
196         CameraToolBar {
197                 id: toolBar
198                 expanded: true
199                 manualBack: true
200                 anchors.bottom: parent.bottom
201                 anchors.bottomMargin: show ? 20 : -1 * (height + 20)
202                 anchors.left: parent.left
203                 anchors.leftMargin: 20
204                 opacity: 0.8
205
206                 property bool show: deleteDialog.status == DialogStatus.Open || deleteDialog.status == DialogStatus.Opening || hideTimer.running || menu.status == DialogStatus.Open || menu.status == DialogStatus.Opening || (currentItem && currentItem.error)
207
208                 onClicked: pageStack.pop();
209
210                 Behavior on anchors.bottomMargin {
211                         PropertyAnimation { duration: 200; }
212                 }
213
214                 items: [
215                         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(); } },
216                         ToolIcon { iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"; onClicked: { shareCurrentItem(); page.restartTimer(); } },
217                         ToolIcon { iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"; onClicked: { deleteCurrentItem(); page.restartTimer(); } },
218                         ToolIcon { iconId: "icon-m-toolbar-view-menu-white"; onClicked: { menu.open(); page.restartTimer(); } }
219                 ]
220         }
221
222         Rectangle {
223                 opacity: toolBar.opacity
224                 anchors.top: parent.top
225                 anchors.topMargin: toolBar.show ? 20 : -1 * (height + 20)
226                 anchors.left: parent.left
227                 anchors.leftMargin: 20
228                 anchors.right: parent.right
229                 anchors.rightMargin: 20
230                 visible: toolBar.visible
231                 height: toolBar.height
232                 color: toolBar.color
233                 border.color: toolBar.border.color
234                 radius: toolBar.radius
235
236                 Behavior on anchors.topMargin {
237                         PropertyAnimation { duration: 200; }
238                 }
239
240                 Label {
241                         text: currentItem ? currentItem.itemData.title : ""
242                         anchors.top: parent.top
243                         anchors.bottom: parent.bottom
244                         anchors.left: parent.left
245                         anchors.leftMargin: 20
246                         font.bold: true
247                         verticalAlignment: Text.AlignVCenter
248                 }
249
250                 Label {
251                         text: currentItem ? currentItem.itemData.created : ""
252                         font.bold: true
253                         anchors.top: parent.top
254                         anchors.bottom: parent.bottom
255                         anchors.right: parent.right
256                         anchors.rightMargin: 20
257                         verticalAlignment: Text.AlignVCenter
258                 }
259         }
260 }