Use font.capitalization instead of the custom javascript function used and return...
[harmattan/cameraplus] / qml / PostCapturePage.qml
index 0d1a337..5743ccf 100644 (file)
 import QtQuick 1.1
 import com.nokia.meego 1.1
 import QtCamera 1.0
-import QtSparql 1.0
 import CameraPlus 1.0
 
-// TODO: losing resources while playback won't show an error
-// TODO: show something if we have no files.
-// TODO: favorites
-// TODO: menu
 CameraPage {
         id: page
 
         controlsVisible: false
-        policyMode: CameraResources.PostCapture
-        needsPipeline: false
+        policyMode: CameraResources.None
         standbyVisible: !Qt.application.active
 
         property Item currentItem: null
-        property bool available: currentItem ? currentItem.itemAvailable : false
+        property bool available: currentItem ? currentItem.itemData.available : false
 
-        function parseDate(str) {
-                var parts = str.split('T');
-                var dates = parts[0].split('-');
-                var times = parts[1].split(':');
-                return new Date(dates[0], dates[1], dates[2], times[0], times[1], times[2]);
+        Component.onCompleted: postCaptureModel.reload();
+
+        function launchGallery() {
+                if (!gallery.launch()) {
+                        showError(qsTr("Failed to launch gallery"));
+                }
+        }
+
+        function showInGallery() {
+                if (!available) {
+                        return;
+                }
+
+                if (!gallery.show(currentItem.itemUrl)) {
+                        showError(qsTr("Failed to launch gallery"));
+                }
+        }
+
+        Menu {
+                id: menu
+                onStatusChanged: page.restartTimer();
+
+                MenuLayout {
+                        MenuItem {text: qsTr("Captures in gallery"); onClicked: launchGallery(); }
+                        MenuItem {text: qsTr("View in gallery"); enabled: available; onClicked: showInGallery(); }
+                }
         }
 
         function deleteCurrentItem() {
@@ -53,7 +68,7 @@ CameraPage {
                         return;
                 }
 
-                deleteDialog.message = currentItem.fileName;
+                deleteDialog.message = currentItem.itemData.fileName;
                 deleteDialog.open();
         }
 
@@ -62,11 +77,16 @@ CameraPage {
                 titleText: qsTr("Delete item?");
                 acceptButtonText: qsTr("Yes");
                 rejectButtonText: qsTr("No");
+
+                onStatusChanged: page.restartTimer();
+
                 onAccepted: {
-                        // TODO: Remove from model and move to next item
-                        if (!remove.remove(currentItem.itemUrl)) {
+                        if (!remove.remove(currentItem.itemData.url)) {
                                 showError(qsTr("Failed to delete item"));
                         }
+                        else {
+                                postCaptureModel.remove(currentItem.itemData);
+                        }
                 }
 
                 DeleteHelper {
@@ -79,15 +99,42 @@ CameraPage {
                         return;
                 }
 
-                if (!share.share(currentItem.itemUrl)) {
+                if (!share.share(currentItem.itemData.url)) {
                                 showError(qsTr("Failed to launch share service"));
                 }
         }
 
+        function addOrRemoveFavorite() {
+                if (!available) {
+                        return;
+                }
+
+                if (currentItem.itemData.favorite) {
+                        if (!trackerStore.removeFromFavorites(currentItem.itemData.url)) {
+                                showError(qsTr("Failed to remove favorite"));
+                        }
+                        else {
+                                currentItem.itemData.favorite = false;
+                        }
+                }
+                else {
+                        if (!trackerStore.addToFavorites(currentItem.itemData.url)) {
+                                showError(qsTr("Failed to add favorite"));
+                        }
+                        else {
+                                currentItem.itemData.favorite = true;
+                        }
+                }
+        }
+
         ShareHelper {
                 id: share
         }
 
+        GalleryHelper {
+                id: gallery
+        }
+
         Rectangle {
                 color: "black"
                 anchors.fill: parent
@@ -103,72 +150,111 @@ CameraPage {
                         PathLine { x: view.width * 2; y: view.height / 2 }
                 }
 
-                flickDeceleration: 999999 // Insanely high value to prevent panning multiple images
+                // Insanely high value to prevent panning multiple images
+                flickDeceleration: 999999
+
                 preferredHighlightBegin: 0.5
                 preferredHighlightEnd: 0.5
                 highlightRangeMode: PathView.StrictlyEnforceRange
                 pathItemCount: 3
 
-                model: SparqlListModel {
-                        query: 'SELECT rdf:type(?urn) AS ?type nie:url(?urn) AS ?url nie:contentCreated(?urn) AS ?created nie:title(?urn) AS ?title nfo:fileName(?urn) AS ?filename nie:mimeType(?urn) AS ?mimetype tracker:available(?urn) AS ?available nfo:fileLastModified(?urn) as ?lastmod tracker:id(?urn) AS ?trackerid  (EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite }) AS ?favorite WHERE { ?urn nfo:equipment "urn:equipment:' + deviceInfo.manufacturer + ':' + deviceInfo.model + ':" .  {?urn a nfo:Video} UNION {?urn a nfo:Image}} ORDER BY DESC(?created)'
-
-                        connection: SparqlConnection {
-                                id: connection
-                                driver: "QTRACKER_DIRECT"
-                                onStatusChanged: checkStatus(status)
-
-                                function checkStatus(status) {
-                                        if (status == SparqlConnection.Error) {
-                                                // TODO: report error
-                                                console.log("Error = " + connection.errorString());
-                                        }
-                                }
+                model: PostCaptureModel {
+                        id: postCaptureModel
+                        manufacturer: deviceInfo.manufacturer
+                        model: deviceInfo.model
+                        onError: {
+                                console.log("Error populating model " + msg);
+                                showError(qsTr("Failed to load captures"));
                         }
                 }
 
+                Label {
+                        // TODO: Hide this when we have no items
+                        text: qsTr("No captures available");
+                        anchors.centerIn: parent
+                        font.pixelSize: 36
+                        visible: currentItem == null
+                }
+
                 delegate: PostCaptureItem {
-                        width: view.width - 10
+                        width: view.width
                         height: view.height
+                        onClicked: hideTimer.running = !hideTimer.running;
                 }
         }
 
-        ToolBar {
+        function restartTimer() {
+                hideTimer.running = true;
+        }
+
+        Timer {
+                id: hideTimer
+                running: false
+                interval: 3000
+        }
+
+        CameraToolBar {
                 id: toolBar
-                opacity: 0.8
+                expanded: true
+                manualBack: true
                 anchors.bottom: parent.bottom
-                tools: ToolBarLayout {
-                        id: layout
-                        ToolIcon { iconId: "icon-m-toolbar-back-white"; onClicked: { pageStack.pop(); } }
-                        ToolIcon { iconId: available ? "icon-m-toolbar-favorite-mark-white" : "icon-m-toolbar-favorite-mark-dimmed-white"}
-                        ToolIcon { iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"; onClicked: shareCurrentItem(); }
-                        ToolIcon { iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"; onClicked: deleteCurrentItem(); }
-                        ToolIcon { iconId: "icon-m-toolbar-view-menu-white" }
+                anchors.bottomMargin: show ? 20 : -1 * (height + 20)
+                anchors.left: parent.left
+                anchors.leftMargin: 20
+                opacity: 0.8
+
+                property bool show: deleteDialog.status == DialogStatus.Open || deleteDialog.status == DialogStatus.Opening || hideTimer.running || menu.status == DialogStatus.Open || menu.status == DialogStatus.Opening || (currentItem && currentItem.error)
+
+                onClicked: pageStack.pop();
+
+                Behavior on anchors.bottomMargin {
+                        PropertyAnimation { duration: 200; }
                 }
+
+                items: [
+                        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(); } },
+                        ToolIcon { iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"; onClicked: { shareCurrentItem(); page.restartTimer(); } },
+                        ToolIcon { iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"; onClicked: { deleteCurrentItem(); page.restartTimer(); } },
+                        ToolIcon { iconId: "icon-m-toolbar-view-menu-white"; onClicked: { menu.open(); page.restartTimer(); } }
+                ]
         }
 
-        ToolBar {
+        Rectangle {
                 opacity: toolBar.opacity
                 anchors.top: parent.top
+                anchors.topMargin: toolBar.show ? 20 : -1 * (height + 20)
+                anchors.left: parent.left
+                anchors.leftMargin: 20
+                anchors.right: parent.right
+                anchors.rightMargin: 20
                 visible: toolBar.visible
+                height: toolBar.height
+                color: toolBar.color
+                border.color: toolBar.border.color
+                radius: toolBar.radius
 
-                tools: ToolBarLayout {
-                        Label {
-                                text: currentItem ? currentItem.itemTitle : ""
-                                anchors.top: parent.top
-                                anchors.bottom: parent.bottom
-                                anchors.left: parent.left
-                                font.bold: true
-                                verticalAlignment: Text.AlignVCenter
-                        }
+                Behavior on anchors.topMargin {
+                        PropertyAnimation { duration: 200; }
+                }
 
-                        Label {
-                                text: currentItem ? Qt.formatDateTime(parseDate(currentItem.creationDate)) : ""
-                                font.bold: true
-                                anchors.top: parent.top
-                                anchors.bottom: parent.bottom
-                                anchors.right: parent.right
-                                verticalAlignment: Text.AlignVCenter
-                        }
+                Label {
+                        text: currentItem ? currentItem.itemData.title : ""
+                        anchors.top: parent.top
+                        anchors.bottom: parent.bottom
+                        anchors.left: parent.left
+                        anchors.leftMargin: 20
+                        font.bold: true
+                        verticalAlignment: Text.AlignVCenter
+                }
+
+                Label {
+                        text: currentItem ? currentItem.itemData.created : ""
+                        font.bold: true
+                        anchors.top: parent.top
+                        anchors.bottom: parent.bottom
+                        anchors.right: parent.right
+                        anchors.rightMargin: 20
+                        verticalAlignment: Text.AlignVCenter
                 }
         }
 }