Load station list asynchronously
authorLuciano Montanaro <mikelima@cirulla.net>
Sun, 31 Jul 2011 13:02:10 +0000 (15:02 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Tue, 27 Dec 2011 22:16:49 +0000 (23:16 +0100)
application/view.cpp
application/view.h

index bfa8e74..245207f 100644 (file)
@@ -28,6 +28,7 @@ Boston, MA 02110-1301, USA.
 #include <QDebug>
 #include <QDir>
 #include <QFile>
+#include <QtConcurrentRun>
 #include <QtDeclarative>
 
 // search Paths seem to be broken in Harmattan?
@@ -59,7 +60,9 @@ View::View(QWidget *parent) :
     stationListProxyModel(new StationListProxyModel(this))
 {
     showFullScreen();
-    stationListModel->load(trueFilePath("stations:stations.qpl"));
+    future = QtConcurrent::run(
+                stationListModel, &StationListModel::load,
+                trueFilePath("stations:stations.qpl"));
 
     stationListProxyModel->setSourceModel(stationListModel);
 
@@ -79,5 +82,9 @@ View::View(QWidget *parent) :
     // the qml dir, then load the file.
     // m_view->setSource(QUrl::fromLocalFile("qml:main.qml"));
     setSource(QUrl::fromLocalFile(trueFilePath("qml:main.qml")));
+}
 
+View::~View()
+{
+    future.waitForFinished();
 }
index 7a98808..a91ce6e 100644 (file)
@@ -22,6 +22,7 @@ Boston, MA 02110-1301, USA.
 
 */
 
+#include <QFuture>
 #include <QDeclarativeView>
 
 class StationListModel;
@@ -32,14 +33,16 @@ class View : public QDeclarativeView
     Q_OBJECT
 public:
     explicit View(QWidget *parent = 0);
+    ~View();
 
 signals:
 
 public slots:
 
 private:
-   StationListModel *stationListModel;
-   StationListProxyModel *stationListProxyModel;
+    QFuture<void> future;
+    StationListModel *stationListModel;
+    StationListProxyModel *stationListProxyModel;
 };
 
 #endif // QP_VIEW_H