proximity sensor support implemented. Remove TODO
[harmattan/cameraplus] / qml / PostCaptureView.qml
index b0bf1d6..2dd6f29 100644 (file)
@@ -24,7 +24,6 @@ import QtQuick 2.0
 import CameraPlus 1.0
 import QtCamera 1.0
 
-// TODO: qrc:/qml/PostCaptureView.qml:104:5: QML CameraToolBar: Binding loop detected for property "height"
 Item {
     id: postCaptureView
 
@@ -33,7 +32,22 @@ Item {
     property int policyMode: view.currentItem && view.currentItem.playing ?
         CameraResources.Player : settings.mode == Camera.VideoMode ? CameraResources.Video :
         CameraResources.Image
-    property bool available: view.currentItem ? view.currentItem.itemData.available : false
+    property bool inhibitDim: pressed
+
+    property bool isCurrent: mainView.currentIndex == 2 && !mainView.moving
+    property bool inCameraMode: root.inCaptureMode && !mainView.moving
+
+    onIsCurrentChanged: {
+        if (isCurrent) {
+            postCaptureModel.reload()
+        }
+    }
+
+    onInCameraModeChanged: {
+        if (inCameraMode) {
+            postCaptureModel.clear()
+        }
+    }
 
     Connections {
         target: view.currentItem
@@ -76,33 +90,10 @@ Item {
         }
     }
 
-    property variant postCaptureModel: postCaptureModelLoader.item ?
-        postCaptureModelLoader.item.model : null
-    property bool loadModel: mainView.currentIndex == 2 && Qt.application.active
-
-    Loader {
-        id: postCaptureModelLoader
-        sourceComponent: loadModel ? postCaptureModelComponent : undefined
-    }
-
-    // We have to do it that way because Loader does not support non-visual elements.
-    Component {
-        id: postCaptureModelComponent
-
-        Item {
-            property alias model: postCaptureModel
-
-            PostCaptureModel {
-                id: postCaptureModel
-                manufacturer: deviceInfo.manufacturer
-                model: deviceInfo.model
-                Component.onCompleted: reload()
-                onError: {
-                    console.log("Error populating model " + msg)
-                    showError(qsTr("Failed to load captures"))
-                }
-            }
-        }
+    PostCaptureModel {
+        id: postCaptureModel
+        imagePath: platformSettings.imagePath
+        videoPath: platformSettings.videoPath
     }
 
     Timer {
@@ -116,32 +107,25 @@ Item {
         expanded: true
         hideBack: true
         anchors.bottom: parent.bottom
-        anchors.bottomMargin: show ? 20 : -1 * (height + 20)
+        anchors.bottomMargin: 20
         anchors.left: parent.left
         anchors.leftMargin: 20
         anchors.right: parent.right
         anchors.rightMargin: 20
-        opacity: 0.8
-
+        opacity: show ? 0.8 : 0.0
+        visible: opacity > 0
         property bool show: deleteDialog.isOpen || deleteDialog.isOpening ||
-            hideTimer.running || menu.isOpen || menu.isOpening ||
-            (view.currentItem && view.currentItem.error) && !view.currentItem.playing
+            hideTimer.running ||
+            (view.currentItem != null && view.currentItem.error) && !view.currentItem.playing
 
-        Behavior on anchors.bottomMargin {
+        Behavior on opacity {
             PropertyAnimation { duration: view.currentItem && view.currentItem.playing ? 0 : 200 }
         }
 
         tools: CameraToolBarTools {
             CameraToolIcon {
-                iconId: !available ? cameraTheme.favoriteDisabledIconId : view.currentItem.itemData.favorite ? cameraTheme.favoriteMarkIconId : cameraTheme.favoriteUnmarkIconId
-                onClicked: {
-                    addOrRemoveFavorite()
-                    restartTimer()
-                }
-            }
-
-            CameraToolIcon {
-                iconId: available ? cameraTheme.shareEnabledIconId : cameraTheme.shareDisabledIconId
+                iconSource: cameraTheme.shareIconId
+                enabled: view.currentItem != null
                 onClicked: {
                     shareCurrentItem()
                     restartTimer()
@@ -149,7 +133,8 @@ Item {
             }
 
             CameraToolIcon {
-                iconId: available ? cameraTheme.deleteEnabledIconId : cameraTheme.deleteDisabledIconId
+                iconSource: cameraTheme.deleteIconId
+                enabled: view.currentItem != null
                 onClicked: {
                     deleteCurrentItem()
                     restartTimer()
@@ -157,9 +142,9 @@ Item {
             }
 
             CameraToolIcon {
-                iconId: cameraTheme.menuIconId
+                iconSource: cameraTheme.galleryIconId
                 onClicked: {
-                    menu.open()
+                    launchGallery()
                     restartTimer()
                 }
             }
@@ -175,10 +160,10 @@ Item {
         onStatusChanged: restartTimer()
 
         onAccepted: {
-            if (!remove.remove(view.currentItem.itemData.url)) {
+            if (!remove.remove(view.currentItem.itemUrl)) {
                 showError(qsTr("Failed to delete item"))
             } else {
-                postCaptureModel.remove(view.currentItem.itemData);
+                view.model.remove(view.currentItem.itemUrl)
             }
         }
 
@@ -187,28 +172,10 @@ Item {
         }
     }
 
-    CameraMenu {
-        id: menu
-        onStatusChanged: restartTimer()
-
-        actions: [
-            CameraMenuAction {
-                text: qsTr("Captures in gallery")
-                onClicked: launchGallery()
-            },
-            CameraMenuAction {
-                // TODO: this is not working...
-                text: qsTr("View in gallery")
-                enabled: available
-                onClicked: showInGallery()
-            }
-        ]
-    }
-
     Rectangle {
         opacity: toolBar.opacity
         anchors.top: parent.top
-        anchors.topMargin: toolBar.show ? 20 : -1 * (height + 20)
+        anchors.topMargin: 20
         anchors.left: parent.left
         anchors.leftMargin: 20
         anchors.right: parent.right
@@ -219,17 +186,13 @@ Item {
         border.color: toolBar.border.color
         radius: toolBar.radius
 
-        Behavior on anchors.topMargin {
-            PropertyAnimation { duration: view.currentItem && view.currentItem.playing ? 0 : 200 }
-        }
-
         Flow {
             width: parent.width - 40
             x: 20
             height: parent.height
 
             CameraLabel {
-                text: view.currentItem ? view.currentItem.itemData.title : ""
+                text: view.currentItem ? view.currentItem.itemTitle : ""
                 width: parent.width / 2
                 height: parent.height
                 font.bold: true
@@ -238,7 +201,7 @@ Item {
             }
 
             CameraLabel {
-                text: view.currentItem ? view.currentItem.itemData.created : ""
+                text: view.currentItem ? view.currentItem.itemCreated : ""
                 width: parent.width / 2
                 height: parent.height
                 font.bold: true
@@ -254,55 +217,21 @@ Item {
         }
     }
 
-    function showInGallery() {
-        if (!available) {
-            return
-        }
-
-        if (!gallery.show(view.currentItem.itemUrl)) {
-            showError(qsTr("Failed to launch gallery"))
-        }
-    }
-
     function deleteCurrentItem() {
-        if (!available) {
+        if (view.currentItem == null) {
             return
         }
 
-        deleteDialog.message = view.currentItem.itemData.fileName
+        deleteDialog.message = view.currentItem.itemFileName
         deleteDialog.open()
     }
 
     function shareCurrentItem() {
-        if (!available) {
-            return
-        }
-
-        if (!share.share(view.currentItem.itemData.url)) {
+        if (view.currentItem != null && !share.share(view.currentItem.itemUrl)) {
             showError(qsTr("Failed to launch share service"))
         }
     }
 
-    function addOrRemoveFavorite() {
-        if (!available) {
-            return
-        }
-
-        if (view.currentItem.itemData.favorite) {
-            if (!trackerStore.removeFromFavorites(view.currentItem.itemData.url)) {
-                showError(qsTr("Failed to remove favorite"))
-            } else {
-                view.currentItem.itemData.favorite = false
-            }
-        } else {
-            if (!trackerStore.addToFavorites(view.currentItem.itemData.url)) {
-                showError(qsTr("Failed to add favorite"))
-            } else {
-                view.currentItem.itemData.favorite = true
-            }
-        }
-    }
-
     function restartTimer() {
         hideTimer.restart()
     }