3 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
24 #include "dataprovider.h"
25 #include "stationlistmodel.h"
26 #include "stationlistproxymodel.h"
27 #include "stationschedulemodel.h"
30 #include <QtConcurrentRun>
34 #include <QModelIndex>
35 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
36 #include <QtQuick/QtQuick>
38 #include <QtDeclarative>
41 // search Paths seem to be broken in Harmattan?
43 static QString trueFilePath(const QString &path)
45 qDebug() << "searching for" << path;
49 QString searchPathName = path.section(':', 0, 0);
50 qDebug() << "path is" << searchPathName;
51 QString fileName = path.section(':', 1, 1);
52 qDebug() << "filename is" << fileName;
53 QStringList dirs = QDir::searchPaths(searchPathName);
54 foreach(QString dir, dirs) {
55 qDebug() << "searching in" << dir;
57 QString absoluteFileName = current.absoluteFilePath(fileName);
58 if (current.exists(fileName)) {
59 qDebug() << "found " << fileName << "in path" << absoluteFileName;
60 return absoluteFileName;
63 qDebug() << "file not found";
68 #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
69 View::View(QWindow *parent) :
72 View::View(QWidget *parent) :
73 QDeclarativeView(parent),
75 stationListModel(new StationListModel(this)),
76 stationListProxyModel(new StationListProxyModel(this))
79 future = QtConcurrent::run(
80 stationListModel, &StationListModel::load,
81 trueFilePath("stations:stations.qpl"));
82 stationListProxyModel->setSourceModel(stationListModel);
84 /* Types to be made accessible to QML */
85 qRegisterMetaType<QModelIndex>("QModelIndex");
86 qmlRegisterType<Settings>("net.cirulla.quandoparte", 1, 0, "Settings");
87 qmlRegisterType<StationListProxyModel>(
88 "net.cirulla.quandoparte", 1, 0, "StationListProxyModel");
89 qmlRegisterType<StationScheduleModel>(
90 "net.cirulla.quandoparte", 1, 0, "StationScheduleModel");
92 #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
93 QQmlContext *context = this->rootContext();
95 QDeclarativeContext *context = this->rootContext();
97 /* objects to be made accessible to QML */
98 context->setContextProperty("settings", Settings::instance());
99 context->setContextProperty("stationList", stationListModel);
100 context->setContextProperty("stationListProxyModel", stationListProxyModel);
102 // This does not seem to work in harmattan. As a workaround, change dir to
103 // the qml dir, then load the file.
104 // m_view->setSource(QUrl::fromLocalFile("qml:main.qml"));
105 setSource(trueFilePath("qml:main.qml"));
110 future.waitForFinished();