Bump version to 0.9.0
[quandoparte] / application / app.cpp
index 278d420..26f0076 100644 (file)
@@ -20,6 +20,7 @@ Boston, MA 02110-1301, USA.
 */
 
 #include "app.h"
+#include "dataprovider.h"
 #include "stationview.h"
 #include "stationlistmodel.h"
 #include "stationlistview.h"
@@ -45,7 +46,7 @@ QTM_USE_NAMESPACE
 
 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)),
@@ -53,8 +54,11 @@ App::App(QObject *parent) :
 {
     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()));
@@ -79,7 +83,7 @@ App::App(QObject *parent) :
     if (settings->recentStations().isEmpty() || !settings->stationViewPreferred()) {
         stationListView->show();
     } else {
-        queryStation(settings->recentStations().front());
+        updateStation();
     }
 }
 
@@ -90,14 +94,10 @@ App::~App()
     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
@@ -105,19 +105,7 @@ void App::downloadFinished(void)
 
 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
@@ -125,11 +113,8 @@ void App::queryStation(const QString &station)
 
 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();
     }
 }
 
@@ -173,7 +158,7 @@ void App::showStationSelectView(void)
 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