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>
29 #include <QWebElement>
34 static const int RECENT_STATIONS_MAX_COUNT = 10;
38 DataProvider::DataProvider(QObject *parent) :
40 accessManager(new QNetworkAccessManager(this))
44 void DataProvider::stationSchedule(const QString &station)
46 QNetworkRequest request;
47 Settings *settings = Settings::instance();
48 request.setUrl(settings->queryBaseUrl());
49 const QString queryString = "stazione=" + station;
50 const QByteArray query(queryString.toLocal8Bit());
51 stationQueryReply = accessManager->post(request, query);
52 connect(stationQueryReply, SIGNAL(finished()),
53 SLOT(onStationScheduleReady()));
54 settings->recentStations().push_front(station);
55 settings->recentStations().removeDuplicates();
56 if (settings->recentStations().count() > RECENT_STATIONS_MAX_COUNT) {
57 settings->recentStations().pop_back();
59 // TODO Implement busy indication...
62 void DataProvider::updateStation()
64 Settings *settings = Settings::instance();
66 qDebug() << "updating station data";
67 if (!settings->recentStations().isEmpty()) {
68 stationSchedule(settings->recentStations().front());
72 void DataProvider::onStationScheduleReady()
74 disconnect(stationQueryReply, SIGNAL(finished()),
75 this, SLOT(downloadFinished()));
76 // TODO implement parsing or data returning...
77 emit stationScheduleReady(stationQueryReply->readAll());
78 stationQueryReply->deleteLater();
79 stationQueryReply = 0;