populate post capture model when page is current and clear it when we leave
authorMohammed Sameer <msameer@foolab.org>
Sun, 25 Aug 2013 11:31:50 +0000 (14:31 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sun, 25 Aug 2013 11:31:50 +0000 (14:31 +0300)
qml/PostCaptureView.qml
src/postcapturemodel.cpp
src/postcapturemodel.h

index 1e01688..a8a28a5 100644 (file)
@@ -35,6 +35,21 @@ Item {
         CameraResources.Player : settings.mode == Camera.VideoMode ? CameraResources.Video :
         CameraResources.Image
 
+    property bool isCurrent: mainView.currentIndex == 2 && !mainView.moving
+    property bool inCameraMode: mainView.currentIndex == 1 && !mainView.moving
+
+    onIsCurrentChanged: {
+        if (isCurrent) {
+            postCaptureModel.reload()
+        }
+    }
+
+    onInCameraModeChanged: {
+        if (inCameraMode) {
+            postCaptureModel.clear()
+        }
+    }
+
     Connections {
         target: view.currentItem
         onPlayingChanged: {
@@ -76,30 +91,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
-                imagePath: platformSettings.imagePath
-                videoPath: platformSettings.videoPath
-
-                Component.onCompleted: reload()
-            }
-        }
+    PostCaptureModel {
+        id: postCaptureModel
+        imagePath: platformSettings.imagePath
+        videoPath: platformSettings.videoPath
     }
 
     Timer {
index 1f71a58..037d67c 100644 (file)
@@ -108,6 +108,16 @@ void PostCaptureModel::reload() {
   sort(0, Qt::DescendingOrder);
 }
 
+void PostCaptureModel::clear() {
+  if (m_model->rowCount(QModelIndex()) == 0) {
+    return;
+  }
+
+  m_data.clear();
+
+  m_model->setFiles(QStringList());
+}
+
 bool PostCaptureModel::lessThan(const QModelIndex& left, const QModelIndex& right) const {
   return info(sourceModel()->data(left, Qt::DisplayRole).toString()).created() <
     info(sourceModel()->data(right, Qt::DisplayRole).toString()).created();
index 411a9a9..2370214 100644 (file)
@@ -58,6 +58,7 @@ public:
 
 public slots:
   void reload();
+  void clear();
   void remove(const QUrl& file);
 
 signals: