stationlistproxymodel.cpp \
settings.cpp \
dataprovider.cpp \
- stationschedule.cpp
+ stationschedulemodel.cpp
HEADERS += \
$$PLATFORM_HEADERS \
stationlistproxymodel.h \
settings.h \
dataprovider.h \
- stationschedule.h
+ stationschedulemodel.h
FORMS += \
settingsdialog.ui \
resources/harmattan/qml/PageHeader.qml \
resources/harmattan/qml/uiconstants.js \
resources/harmattan/qml/StationListPage.js \
- resources/harmattan/qml/AboutPage.qml
+ resources/harmattan/qml/AboutPage.qml \
+ resources/harmattan/qml/InfoBar.qml
unix {
isEmpty(PREFIX) {
#include "dataprovider.h"
#include "settings.h"
+#include "stationschedulemodel.h"
#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
+#include <QSharedPointer>
#include <QWebElement>
#include <QWebFrame>
#include <QWebPage>
// Class methods
+DataProvider *DataProvider::instance()
+{
+ static DataProvider *dataProvider = 0;
+
+ if (!dataProvider)
+ dataProvider = new DataProvider(0);
+ return dataProvider;
+}
+
DataProvider::DataProvider(QObject *parent) :
QObject(parent),
accessManager(new QNetworkAccessManager(this))
{
}
-void DataProvider::stationSchedule(const QString &station)
+void DataProvider::fetchStationSchedule(const QString &station)
{
QNetworkRequest request;
Settings *settings = Settings::instance();
const QByteArray query(queryString.toLocal8Bit());
stationQueryReply = accessManager->post(request, query);
connect(stationQueryReply, SIGNAL(finished()),
- SLOT(onStationScheduleReady()));
+ SLOT(onStationScheduleFetched()));
settings->recentStations().push_front(station);
settings->recentStations().removeDuplicates();
if (settings->recentStations().count() > RECENT_STATIONS_MAX_COUNT) {
settings->recentStations().pop_back();
}
- // TODO Implement busy indication...
}
void DataProvider::updateStation()
qDebug() << "updating station data";
if (!settings->recentStations().isEmpty()) {
- stationSchedule(settings->recentStations().front());
+ fetchStationSchedule(settings->recentStations().front());
}
}
-void DataProvider::onStationScheduleReady()
+void DataProvider::onStationScheduleFetched()
{
disconnect(stationQueryReply, SIGNAL(finished()),
- this, SLOT(onStationScheduleReady()));
- // TODO implement parsing or data returning...
- emit stationScheduleReady(QString::fromUtf8(stationQueryReply->readAll()),
- stationQueryReply->url());
+ this, SLOT(onStationScheduleFetched()));
+
+ QString name = Settings::instance()->recentStations().front();
+
+ emit stationScheduleReady(stationQueryReply->readAll(), stationQueryReply->url());
stationQueryReply->deleteLater();
stationQueryReply = 0;
}
#define DATAPROVIDER_H
#include <QObject>
+#include <QSharedPointer>
class QNetworkAccessManager;
class QNetworkReply;
class QUrl;
+class StationScheduleModel;
+
class DataProvider : public QObject
{
Q_OBJECT
public:
explicit DataProvider(QObject *parent = 0);
-
+ static DataProvider *instance();
signals:
- void stationScheduleReady(const QString &result, const QUrl &url);
+ void stationScheduleReady(const QByteArray &data, const QUrl &url);
public slots:
- void stationSchedule(const QString &station);
+ void fetchStationSchedule(const QString &station);
void updateStation();
private slots:
- void onStationScheduleReady(void);
+ void onStationScheduleFetched(void);
private:
QNetworkAccessManager *accessManager;
--- /dev/null
+/*
+
+Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+*/
+
+#include "stationschedulemodel.h"
+
+#include "dataprovider.h"
+
+#include <QDebug>
+
+StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent) :
+ QStringListModel(parent),
+ m_name(name)
+
+{
+}
+
+QString & StationScheduleModel::name()
+{
+ return m_name;
+}
+
+void StationScheduleModel::setName(const QString &name)
+{
+ m_name = name;
+ emit nameChanged();
+}
+
+void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUrl)
+{
+ Q_UNUSED(baseUrl);
+ qDebug() << "--- start of query result --- cut here ------";
+ qDebug() << htmlReply;
+ qDebug() << "--- end of query result ----- cut here ------";
+}
+
+void StationScheduleModel::fetch(const QString &name)
+{
+ DataProvider *provider = DataProvider::instance();
+
+ connect(provider, SIGNAL(stationScheduleReady(QByteArray,QUrl)),
+ this, SLOT(parse(QByteArray,QUrl)));
+ provider->fetchStationSchedule(name);
+ setName(name);
+}
--- /dev/null
+/*
+
+Copyright (C) 2011 mikelima
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef STATIONSCHEDULEMODEL_H
+#define STATIONSCHEDULEMODEL_H
+
+#include <QObject>
+#include <QStringListModel>
+#include <QUrl>
+
+class StationScheduleModel : public QStringListModel
+{
+ Q_OBJECT
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+
+public:
+ explicit StationScheduleModel(const QString &name = "", QObject *parent = 0);
+
+ QString &name();
+ void setName(const QString &name);
+
+signals:
+ void nameChanged();
+
+public slots:
+ void fetch(const QString &name);
+
+private slots:
+ void parse(const QByteArray &htmlReply, const QUrl &baseUrl);
+
+private:
+ QString m_name;
+};
+
+#endif // STATIONSCHEDULEMODEL_H
#include "dataprovider.h"
#include "stationlistmodel.h"
#include "stationlistproxymodel.h"
+#include "stationschedulemodel.h"
#include <QDebug>
#include <QDir>
/* 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");
QDeclarativeContext *context = this->rootContext();
/* objects to be made accessible to QML */