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"
31 #include <QModelIndex>
32 #include <QtConcurrentRun>
33 #include <QtDeclarative>
35 // search Paths seem to be broken in Harmattan?
37 static QString trueFilePath(QString path)
39 qDebug() << "searching for" << path;
40 QString searchPathName = path.section(':', 0, 0);
41 qDebug() << "path is" << searchPathName;
42 QString fileName = path.section(':', 1, 1);
43 qDebug() << "filename is" << fileName;
44 QStringList dirs = QDir::searchPaths(searchPathName);
45 foreach(QString dir, dirs) {
46 qDebug() << "searching in" << dir;
48 QString absoluteFileName = current.absoluteFilePath(fileName);
49 if (current.exists(fileName)) {
50 qDebug() << "found " << fileName << "in path" << absoluteFileName;
51 return absoluteFileName;
54 qDebug() << "file not found";
58 View::View(QWidget *parent) :
59 QDeclarativeView(parent),
60 stationListModel(new StationListModel(this)),
61 stationListProxyModel(new StationListProxyModel(this))
64 future = QtConcurrent::run(
65 stationListModel, &StationListModel::load,
66 trueFilePath("stations:stations.qpl"));
68 stationListProxyModel->setSourceModel(stationListModel);
70 /* Types to be made accessible to QML */
71 qRegisterMetaType<QModelIndex>("QModelIndex");
72 //qRegisterMetaType<StationListProxyModel::SortingMode>("SortingMode");
73 qmlRegisterType<DataProvider>("net.cirulla.quandoparte", 1, 0, "DataProvider");
74 qmlRegisterType<Settings>("net.cirulla.quandoparte", 1, 0, "Settings");
75 qmlRegisterType<StationListProxyModel>(
76 "net.cirulla.quandoparte", 1, 0, "StationListProxyModel");
78 QDeclarativeContext *context = this->rootContext();
79 /* objects to be made accessible to QML */
80 context->setContextProperty("settings", Settings::instance());
81 context->setContextProperty("stationList", stationListModel);
82 context->setContextProperty("stationListProxyModel", stationListProxyModel);
84 // This does not seem ot work in harmattan. As a workaround, change dir to
85 // the qml dir, then load the file.
86 // m_view->setSource(QUrl::fromLocalFile("qml:main.qml"));
87 setSource(QUrl::fromLocalFile(trueFilePath("qml:main.qml")));
92 future.waitForFinished();