#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();
- request.setUrl(settings->queryBaseUrl());
+ request.setUrl(settings->queryBaseUrl() + "stazione");
+
+ qDebug() << "fetching schedule for station" << station;
const QString queryString = "stazione=" + station;
const QByteArray query(queryString.toLocal8Bit());
stationQueryReply = accessManager->post(request, query);
connect(stationQueryReply, SIGNAL(finished()),
- SLOT(onStationScheduleReady()));
- settings->recentStations().push_front(station);
- settings->recentStations().removeDuplicates();
- if (settings->recentStations().count() > RECENT_STATIONS_MAX_COUNT) {
- settings->recentStations().pop_back();
+ SLOT(onStationScheduleFetched()));
+ QStringList recentStations = settings->recentStations();
+ recentStations.push_front(station);
+ recentStations.removeDuplicates();
+ if (recentStations.count() > RECENT_STATIONS_MAX_COUNT) {
+ recentStations.pop_back();
}
- // TODO Implement busy indication...
+ settings->setRecentStations(recentStations);
}
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(downloadFinished()));
- // TODO implement parsing or data returning...
- emit stationScheduleReady(stationQueryReply->readAll());
+ this, SLOT(onStationScheduleFetched()));
+
+ QString name = Settings::instance()->recentStations().front();
+
+ emit stationScheduleReady(stationQueryReply->readAll(), stationQueryReply->url());
stationQueryReply->deleteLater();
stationQueryReply = 0;
}