3 Copyright (C) 2011, 2013 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 "stationitem.h"
26 #include "stationscheduleitem.h"
27 #include "stationschedulemodel.h"
28 #include "stationlistproxymodel.h"
29 #include "stationlistmodel.h"
32 #include <QtConcurrentRun>
36 #include <QModelIndex>
37 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
38 #include <QtQuick/QtQuick>
40 #include <QtDeclarative>
43 // search Paths seem to be broken in Harmattan?
45 static QString trueFilePath(const QString &path)
47 qDebug() << "searching for" << path;
51 QString searchPathName = path.section(':', 0, 0);
52 qDebug() << "path is" << searchPathName;
53 QString fileName = path.section(':', 1, 1);
54 qDebug() << "filename is" << fileName;
55 QStringList dirs = QDir::searchPaths(searchPathName);
56 foreach(QString dir, dirs) {
57 qDebug() << "searching in" << dir;
59 QString absoluteFileName = current.absoluteFilePath(fileName);
60 if (current.exists(fileName)) {
61 qDebug() << "found " << fileName << "in path" << absoluteFileName;
62 return absoluteFileName;
65 qDebug() << "file not found";
70 Q_DECLARE_METATYPE(QList< QPersistentModelIndex >)
71 #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
72 Q_DECLARE_METATYPE(QAbstractItemModel::LayoutChangeHint)
75 #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
76 View::View(QWindow *parent) :
79 View::View(QWidget *parent) :
80 QDeclarativeView(parent),
82 stationListModel(new StationListModel(this)),
83 stationListProxyModel(new StationListProxyModel(this))
86 future = QtConcurrent::run(
87 stationListModel, &StationListModel::load,
88 trueFilePath("stations:stations.qpl"));
89 stationListProxyModel->setSourceModel(stationListModel);
91 /* Types to be made accessible to QML */
92 #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
93 qRegisterMetaType<QGeoCoordinate>("QGeoCoordinate");
94 qRegisterMetaType<QGeoPositionInfo>("QGeoPositionInfo");
95 qRegisterMetaType< QModelIndex >("QModelIndex");
96 qRegisterMetaType< QList< QPersistentModelIndex > >();
97 qRegisterMetaType< QAbstractItemModel::LayoutChangeHint>();
99 qmlRegisterType< StationListModel >(
100 "net.cirulla.quandoparte", 1, 0, "StationListModel");
101 qmlRegisterType< StationListProxyModel >(
102 "net.cirulla.quandoparte", 1, 0, "StationListProxyModel");
103 qmlRegisterType< StationScheduleModel >(
104 "net.cirulla.quandoparte", 1, 0, "StationScheduleModel");
106 #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
107 QQmlContext *context = this->rootContext();
109 QDeclarativeContext *context = this->rootContext();
111 /* objects to be made accessible to QML */
112 context->setContextProperty("settings", Settings::instance());
113 context->setContextProperty("stationList", stationListModel);
114 context->setContextProperty("stationListProxyModel", stationListProxyModel);
116 // This does not seem to work in harmattan. As a workaround, change dir to
117 // the qml dir, then load the file.
118 // m_view->setSource(QUrl::fromLocalFile("qml:main.qml"));
119 setSource(trueFilePath("qml:main.qml"));
124 future.waitForFinished();