X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=application%2Fdataprovider.cpp;h=44e4844b9f2ae2d1df4170337fbbb8e4b0e00b6b;hb=34fab52a2172a66c8bc5bc5f379dbeb57c865934;hp=9d05ea3c70fbcee78d08c0f00e398ed4ad0f0ce1;hpb=a14e76318d4f5f7df5de7d4196c1e9d622bc12d0;p=quandoparte diff --git a/application/dataprovider.cpp b/application/dataprovider.cpp index 9d05ea3..44e4844 100644 --- a/application/dataprovider.cpp +++ b/application/dataprovider.cpp @@ -28,9 +28,11 @@ Boston, MA 02110-1301, USA. #include #include #include +#if 0 #include #include #include +#endif // Constants static const int RECENT_STATIONS_MAX_COUNT = 10; @@ -48,22 +50,29 @@ DataProvider *DataProvider::instance() DataProvider::DataProvider(QObject *parent) : QObject(parent), - accessManager(new QNetworkAccessManager(this)) + accessManager(new QNetworkAccessManager(this)), + stationQueryReply(0) { } -void DataProvider::fetchStationSchedule(const QString &station) +void DataProvider::fetchStationSchedule(const QString &station, + const QString &stationCode) { QNetworkRequest request; Settings *settings = Settings::instance(); request.setUrl(settings->queryBaseUrl() + "stazione"); - - qDebug() << "fetching schedule for station" << station; - const QString queryString = "stazione=" + station; + qDebug() << "fetching schedule for station:" << station << "code:" << stationCode; + const QString queryString = + stationCode.isEmpty() ? "stazione=" + station : + "codiceStazione=" + stationCode; const QByteArray query(queryString.toLocal8Bit()); stationQueryReply = accessManager->post(request, query); + connect(stationQueryReply, SIGNAL(metaDataChanged()), + SLOT(onStationQueryMetadataChanged())); connect(stationQueryReply, SIGNAL(finished()), SLOT(onStationScheduleFetched())); + connect(stationQueryReply, SIGNAL(error(QNetworkReply::NetworkError)), + SLOT(onNetworkError(QNetworkReply::NetworkError))); QStringList recentStations = settings->recentStations(); recentStations.push_front(station); recentStations.removeDuplicates(); @@ -85,12 +94,30 @@ void DataProvider::updateStation() void DataProvider::onStationScheduleFetched() { - disconnect(stationQueryReply, SIGNAL(finished()), - this, SLOT(onStationScheduleFetched())); - - QString name = Settings::instance()->recentStations().front(); + disconnect(stationQueryReply); + QVariant httpStatus = stationQueryReply->attribute(QNetworkRequest::HttpStatusCodeAttribute); + if (httpStatus.isValid()) { + qDebug() << "Metadata changed, Http status is:" << httpStatus.toInt(); + } emit stationScheduleReady(stationQueryReply->readAll(), stationQueryReply->url()); stationQueryReply->deleteLater(); stationQueryReply = 0; } + +void DataProvider::onStationQueryMetadataChanged(void) +{ +} + +void DataProvider::onNetworkError(QNetworkReply::NetworkError errorCode) +{ + switch (errorCode) { + case QNetworkReply::NoError: + qDebug() << "No Network error" << errorCode; + break; + default: + qDebug() << "Network error" << errorCode; + emit error(); + break; + } +}