*/
#include "app.h"
+#include "dataprovider.h"
#include "stationview.h"
#include "stationlistmodel.h"
#include "stationlistview.h"
App::App(QObject *parent) :
QObject(parent),
- accessManager(new QNetworkAccessManager(this)),
+ dataProvider(new DataProvider(this)),
checkingTimer(new QTimer(this)),
stationView(new StationView()),
stationListModel(new StationListModel(this)),
{
stationListModel->load("stations:stations.qpl");
- connect(stationListView, SIGNAL(stationSelected(const QString &)),
- SLOT(queryStation(const QString &)));
+ connect(dataProvider, SIGNAL(stationScheduleReady(QByteArray, QUrl)),
+ SLOT(downloadFinished(QByteArray)));
+
+ connect(stationListView, SIGNAL(stationSelected(QString)),
+ SLOT(queryStation(QString)));
connect(stationListView, SIGNAL(aboutTriggered()),
SLOT(showAboutDialog()));
if (settings->recentStations().isEmpty() || !settings->stationViewPreferred()) {
stationListView->show();
} else {
- queryStation(settings->recentStations().front());
+ updateStation();
}
}
delete stationView;
}
-void App::downloadFinished(void)
+void App::downloadFinished(const QByteArray &data)
{
- disconnect(stationQueryReply, SIGNAL(finished()),
- this, SLOT(downloadFinished()));
- stationView->updateView(stationQueryReply->readAll());
+ stationView->updateView(data);
stationListView->hide();
- stationQueryReply->deleteLater();
- stationQueryReply = 0;
#ifdef Q_WS_MAEMO_5
stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
#endif
void App::queryStation(const QString &station)
{
- QNetworkRequest request;
- Settings *settings = Settings::instance();
- request.setUrl(settings->queryBaseUrl());
- const QString queryString = "stazione=" + station;
- const QByteArray query(queryString.toLocal8Bit());
- stationQueryReply = accessManager->post(request, query);
- connect(stationQueryReply, SIGNAL(finished()),
- this, SLOT(downloadFinished()));
- settings->recentStations().push_front(station);
- settings->recentStations().removeDuplicates();
- if (settings->recentStations().count() > RECENT_STATIONS_MAX_COUNT) {
- settings->recentStations().pop_back();
- }
+ dataProvider->stationSchedule(station);
#ifdef Q_WS_MAEMO_5
stationListView->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
#endif
void App::updateStation()
{
- Settings *settings = Settings::instance();
-
- qDebug() << "updating station data";
- if (!settings->recentStations().isEmpty() && !stationListView->isVisible()) {
- queryStation(settings->recentStations().front());
+ if (!stationListView->isVisible()) {
+ dataProvider->updateStation();
}
}
void App::readSettings(void)
{
Settings *settings = Settings::instance();
- stationView->setBaseUrl(settings->queryBaseUrl());
+ stationView->setBaseUrl(settings->queryBaseUrl() + "stazione");
/*
I would use > 0 here, but people may have an old settings file with a 2