From 689f2dd2aec22638f1fb30896b54194ce5cb2c73 Mon Sep 17 00:00:00 2001 From: dorian Date: Sun, 30 Dec 2018 20:56:26 +0100 Subject: [PATCH] the event data is now downloaded from the fanny-server --- android-sources/AndroidManifest.xml | 4 ++-- sources/serverconn.cpp | 31 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/android-sources/AndroidManifest.xml b/android-sources/AndroidManifest.xml index 62ae84b..76dbdbf 100644 --- a/android-sources/AndroidManifest.xml +++ b/android-sources/AndroidManifest.xml @@ -1,8 +1,8 @@ - + - + diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index 03ae240..a0729b0 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -227,7 +227,7 @@ float ServerConn::getProgress() int ServerConn::getEvents(QString day){ - +/* this->progress = 0; ReturnData_t ret; //this is a custom type to store the returned data // Call the webservice @@ -252,10 +252,37 @@ int ServerConn::getEvents(QString day){ //get the status code QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); this->progress = 1; + */ + + this->progress = 0; + // Create request + QNetworkRequest request; + request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/" + day + ".txt" ) ); + + // Pack in credentials + QString concatenatedCredentials = this->username + ":" + this->password; + QByteArray data = concatenatedCredentials.toLocal8Bit().toBase64(); + QString headerData = "Basic " + data; + request.setRawHeader( "Authorization", headerData.toLocal8Bit() ); + + QUrlQuery pdata; + // Send request and connect all possible signals + QNetworkReply*reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8()); + //QNetworkReply*reply = networkManager->get( request ); + + connect(reply, SIGNAL(downloadProgress(qint64, qint64)), + this, SLOT(updateProgress(qint64, qint64))); + QEventLoop loop; + loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); + loop.exec(); + + this->progress = 1; + int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if(status_code != 200){ // if the request didn't result in a success, clear the old events, as they are probaply incorrect and return the error code this->m_events.clear(); - return(status_code.toInt()); + return(status_code); } QString eventString = reply->readAll();