Show favorite indicator for sailfish
[quandoparte] / application / view.cpp
index 5d9bab4..1236dcc 100644 (file)
@@ -24,19 +24,28 @@ Boston, MA 02110-1301, USA.
 #include "dataprovider.h"
 #include "stationlistmodel.h"
 #include "stationlistproxymodel.h"
+#include "stationschedulemodel.h"
 
+#include <QtGlobal>
+#include <QtConcurrentRun>
 #include <QDebug>
 #include <QDir>
 #include <QFile>
 #include <QModelIndex>
-#include <QtConcurrentRun>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
+#include <QtQuick/QtQuick>
+#else
 #include <QtDeclarative>
+#endif
 
 // search Paths seem to be broken in Harmattan?
 
-static QString trueFilePath(QString path)
+static QString trueFilePath(const QString &path)
 {
     qDebug() << "searching for" << path;
+#if USE_RESOURCES
+    return path;
+#else
     QString searchPathName = path.section(':', 0, 0);
     qDebug() << "path is" << searchPathName;
     QString fileName = path.section(':', 1, 1);
@@ -53,10 +62,16 @@ static QString trueFilePath(QString path)
     }
     qDebug() << "file not found";
     return QString();
+#endif
 }
 
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
+View::View(QWindow *parent) :
+    QQuickView(parent),
+#else
 View::View(QWidget *parent) :
     QDeclarativeView(parent),
+#endif
     stationListModel(new StationListModel(this)),
     stationListProxyModel(new StationListProxyModel(this))
 {
@@ -64,27 +79,30 @@ View::View(QWidget *parent) :
     future = QtConcurrent::run(
                 stationListModel, &StationListModel::load,
                 trueFilePath("stations:stations.qpl"));
-
     stationListProxyModel->setSourceModel(stationListModel);
 
     /* Types to be made accessible to QML */
     qRegisterMetaType<QModelIndex>("QModelIndex");
-    //qRegisterMetaType<StationListProxyModel::SortingMode>("SortingMode");
-    qmlRegisterType<DataProvider>("net.cirulla.quandoparte", 1, 0, "DataProvider");
     qmlRegisterType<Settings>("net.cirulla.quandoparte", 1, 0, "Settings");
     qmlRegisterType<StationListProxyModel>(
                 "net.cirulla.quandoparte", 1, 0, "StationListProxyModel");
+    qmlRegisterType<StationScheduleModel>(
+                "net.cirulla.quandoparte", 1, 0, "StationScheduleModel");
 
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
+    QQmlContext *context = this->rootContext();
+#else
     QDeclarativeContext *context = this->rootContext();
+#endif
     /* objects to be made accessible to QML */
     context->setContextProperty("settings", Settings::instance());
     context->setContextProperty("stationList", stationListModel);
     context->setContextProperty("stationListProxyModel", stationListProxyModel);
 
-    // This does not seem ot work in harmattan. As a workaround, change dir to
+    // This does not seem to work in harmattan. As a workaround, change dir to
     // the qml dir, then load the file.
     // m_view->setSource(QUrl::fromLocalFile("qml:main.qml"));
-    setSource(QUrl::fromLocalFile(trueFilePath("qml:main.qml")));
+    setSource(trueFilePath("qml:main.qml"));
 }
 
 View::~View()