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"
25 #include <QNetworkAccessManager>
26 #include <QNetworkReply>
27 #include <QNetworkRequest>
30 static const int RECENT_STATIONS_MAX_COUNT = 10;
32 DataProvider::DataProvider(QDeclarativeItem *parent) :
33 QDeclarativeItem(parent),
34 accessManager(new QNetworkAccessManager(this))
38 void DataProvider::queryStation(const QString &station)
40 QNetworkRequest request;
41 Settings *settings = Settings::instance();
42 request.setUrl(settings->queryBaseUrl());
43 const QString queryString = "stazione=" + station;
44 const QByteArray query(queryString.toLocal8Bit());
45 stationQueryReply = accessManager->post(request, query);
46 connect(stationQueryReply, SIGNAL(finished()),
47 this, SLOT(queryStationCompleted()));
48 settings->recentStations().push_front(station);
49 settings->recentStations().removeDuplicates();
50 if (settings->recentStations().count() > RECENT_STATIONS_MAX_COUNT) {
51 settings->recentStations().pop_back();
53 // TODO Implement busy indication...
56 void DataProvider::updateStation()
58 Settings *settings = Settings::instance();
60 qDebug() << "updating station data";
61 if (!settings->recentStations().isEmpty()) {
62 queryStation(settings->recentStations().front());
66 void DataProvider::queryStationCompleted()
68 disconnect(stationQueryReply, SIGNAL(finished()),
69 this, SLOT(downloadFinished()));
70 // TODO implement parsing or data returning...
71 stationQueryReply->deleteLater();
72 stationQueryReply = 0;