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.
22 #include "dataprovider.h"
26 #include <QNetworkAccessManager>
27 #include <QNetworkReply>
28 #include <QNetworkRequest>
31 static const int RECENT_STATIONS_MAX_COUNT = 10;
33 DataProvider::DataProvider(QObject *parent) :
35 accessManager(new QNetworkAccessManager(this))
39 void DataProvider::queryStation(const QString &station)
41 QNetworkRequest request;
42 Settings *settings = Settings::instance();
43 request.setUrl(settings->queryBaseUrl());
44 const QString queryString = "stazione=" + station;
45 const QByteArray query(queryString.toLocal8Bit());
46 stationQueryReply = accessManager->post(request, query);
47 connect(stationQueryReply, SIGNAL(finished()),
48 SLOT(onQueryStationReply()));
49 settings->recentStations().push_front(station);
50 settings->recentStations().removeDuplicates();
51 if (settings->recentStations().count() > RECENT_STATIONS_MAX_COUNT) {
52 settings->recentStations().pop_back();
54 // TODO Implement busy indication...
57 void DataProvider::updateStation()
59 Settings *settings = Settings::instance();
61 qDebug() << "updating station data";
62 if (!settings->recentStations().isEmpty()) {
63 queryStation(settings->recentStations().front());
67 void DataProvider::onQueryStationReply()
69 disconnect(stationQueryReply, SIGNAL(finished()),
70 this, SLOT(downloadFinished()));
71 // TODO implement parsing or data returning...
72 emit queryStationCompleted(stationQueryReply->readAll());
73 stationQueryReply->deleteLater();
74 stationQueryReply = 0;