From b731c758479498807faef01b7890166a303f8a63 Mon Sep 17 00:00:00 2001 From: dorian Date: Tue, 1 Jan 2019 15:21:25 +0100 Subject: [PATCH] some cleanup --- sources/serverconn.cpp | 129 ++--------------------------------------- 1 file changed, 4 insertions(+), 125 deletions(-) diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index f3b19c9..e25cadd 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -172,7 +172,6 @@ float ServerConn::getProgress() int ServerConn::getEvents(QString day){ - this->progress = 0; // Create request QNetworkRequest request; request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/" + day + ".txt" ) ); @@ -181,11 +180,10 @@ int ServerConn::getEvents(QString day){ QString concatenatedCredentials = this->username + ":" + this->password; QByteArray data = concatenatedCredentials.toLocal8Bit().toBase64(); QString headerData = "Basic " + data; - request.setRawHeader( "Authorization", headerData.toLocal8Bit() ); + request.setRawHeader("Authorization", headerData.toLocal8Bit()); - QUrlQuery pdata; - //QNetworkReply*reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8()); - QNetworkReply*reply = networkManager->get( request ); + // send the request + QNetworkReply*reply = networkManager->get(request); // loop to wait until the request has finished before processing the data QEventLoop loop; @@ -202,7 +200,7 @@ int ServerConn::getEvents(QString day){ // start the loop loop.exec(); - this->progress = 1; + // get the status code int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if(status_code != 200){ @@ -428,125 +426,6 @@ int ServerConn::getEvents(QString day){ // return success return(200); - - /* - qDebug() << "reading xml file"; - QFile * xmlFile = new QFile(":/samplehtml/Download File.xml"); - if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "Load XML File Problem Couldn't open xmlfile.xml to load settings for download"; - return 900; - } - - //QXmlStreamReader * xmlReader = new QXmlStreamReader(eventString); - QXmlStreamReader * xmlReader = new QXmlStreamReader(xmlFile); - //qDebug() << xmlFile->readAll(); - QList tmpEvents; - QStringList dayList; - while (dayList.length() < 7) { - dayList.append(""); - } - - int currTop = 0; - - - 8a - 1 - 2 - Ei - Ch - --- - Entfall - KEINE KA - - 5abc 1 - We - KR - --- - Entfall - - - #define eventXmlPosGrade 3 - #define eventXmlPosHour 55 - #define eventXmlPosReplace 123 - #define eventXmlPosSubject 178 - #define eventXmlPosRoom 233 - #define eventXmlPosTo 275 - #define eventXmlPosText 391 - - QList eventXmlPositions = {eventXmlPosGrade,eventXmlPosHour,eventXmlPosReplace,eventXmlPosSubject,eventXmlPosRoom,eventXmlPosTo,eventXmlPosText}; - qDebug() << "start xml parsing"; - //Parse the XML until we reach end of it - while(!xmlReader->atEnd()) { - if (xmlReader->readNextStartElement()) { - // read next element - - if (xmlReader->name().toString() == "text"){ - // text element found - QXmlStreamAttributes attributes = xmlReader->attributes(); - QString attribute_value; - int top; - - if(attributes.hasAttribute("font")){ - attribute_value = attributes.value("font").toString(); - } - - if(attributes.hasAttribute("top")){ - // get the y-Position of the text - - top = attributes.value("top").toInt(); - - if(abs(top - currTop) > 3){ - // new line started - - if(currTop > 175){ - // if not header -> append - qDebug() << dayList; - tmpEvents.append(dayList); - } - - dayList.clear(); - while (dayList.length() < 7) { - dayList.append(""); - } - currTop = top; - } - - if(attributes.hasAttribute("left")){ - int left = attributes.value("left").toInt(); - QString text = xmlReader->readElementText(QXmlStreamReader::IncludeChildElements); - qDebug() << text; - for(int i = 0;i<7;i++){ - //qDebug() << i << left << abs(left - eventXmlPositions[i]); - if(abs(left - eventXmlPositions[i]) < 30){ - dayList[i] = text; - //qDebug() << i << left << text << dayList << left << abs(left - eventXmlPositions[i]); - } - } - } - - else { - qDebug() << " no left"; - } - - } - else { - qDebug() << " no top"; - } - } - } - } - - this->m_events = tmpEvents; - - if(xmlReader->hasError()) { - qDebug() << "xmlFile.xml Parse Error" << xmlReader->errorString(); - //return(900); - } - - //close reader and flush file - xmlReader->clear(); - xmlFile->close(); - */ - } int ServerConn::getFoodPlan()