2018-06-21 16:41:02 +02:00
|
|
|
#include "headers/serverconn.h"
|
2018-06-21 08:47:09 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
ServerConn * pGlobalServConn = nullptr;
|
2018-06-21 18:36:46 +02:00
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
ServerConn::ServerConn(QObject *parent) : QObject(parent)
|
|
|
|
{
|
2018-12-25 20:34:53 +01:00
|
|
|
qDebug("+----- serverconn konstruktor -----+");
|
2018-12-25 19:30:42 +01:00
|
|
|
pGlobalServConn = this;
|
2018-06-21 08:47:09 +02:00
|
|
|
this->networkManager = new QNetworkAccessManager();
|
2018-06-21 16:41:02 +02:00
|
|
|
this->refreshNetworkManager = new QNetworkAccessManager();
|
2018-06-21 08:47:09 +02:00
|
|
|
|
2018-12-25 20:34:53 +01:00
|
|
|
// check login state
|
|
|
|
int perm = pGlobalAppSettings->loadSetting("permanent").toInt();
|
|
|
|
qDebug() << "+-- login state: " << perm;
|
|
|
|
|
|
|
|
if(perm == 1){
|
|
|
|
// permanent login
|
|
|
|
// restore login
|
|
|
|
this->username = pGlobalAppSettings->loadSetting("username");
|
|
|
|
this->password = pGlobalAppSettings->loadSetting("password");
|
|
|
|
|
|
|
|
this->setState("loggedIn");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this->setState("notLoggedIn");
|
|
|
|
}
|
|
|
|
|
2018-12-25 19:30:42 +01:00
|
|
|
this->checkConnTimer = new QTimer();
|
|
|
|
this->checkConnTimer->setInterval(1000);
|
|
|
|
this->checkConnTimer->setSingleShot(true);
|
2018-12-25 20:34:53 +01:00
|
|
|
connect(checkConnTimer, SIGNAL(timeout()), this, SLOT(checkConn()));
|
2018-12-25 19:30:42 +01:00
|
|
|
this->checkConnTimer->start();
|
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
}
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
int ServerConn::login(QString username, QString password, bool permanent)
|
2018-06-21 08:47:09 +02:00
|
|
|
{
|
2018-12-21 12:23:12 +01:00
|
|
|
// QUrlQuery pdata;
|
|
|
|
// ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/static15/http.intern/sheute.pdf"), pdata);
|
|
|
|
// qDebug() << ret.text;
|
2018-06-21 08:47:09 +02:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// Create network request
|
2018-12-21 12:23:12 +01:00
|
|
|
QNetworkRequest request;
|
2018-12-25 00:15:25 +01:00
|
|
|
// call a non-existent file to be fast
|
|
|
|
request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/logintest" ) );
|
|
|
|
|
|
|
|
// pack the credentials into a string
|
|
|
|
QString credentialsString = username + ":" + password;
|
|
|
|
// convert it to a byte array
|
|
|
|
QByteArray data = credentialsString.toLocal8Bit().toBase64();
|
|
|
|
// put it into a string
|
2018-12-21 12:23:12 +01:00
|
|
|
QString headerData = "Basic " + data;
|
2018-12-25 00:15:25 +01:00
|
|
|
// and finally write it into the request header
|
2018-12-21 12:23:12 +01:00
|
|
|
request.setRawHeader( "Authorization", headerData.toLocal8Bit() );
|
|
|
|
|
2018-12-25 15:16:24 +01:00
|
|
|
// Send GET request to fanny server
|
2018-12-25 00:15:25 +01:00
|
|
|
QNetworkReply*reply = networkManager->get( request );
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// loop to wait until the request has finished before processing the data
|
2018-12-21 12:23:12 +01:00
|
|
|
QEventLoop loop;
|
2018-12-25 00:15:25 +01:00
|
|
|
// timer to cancel the request after 3 seconds
|
|
|
|
QTimer timer;
|
|
|
|
timer.setSingleShot(true);
|
|
|
|
|
|
|
|
// quit the loop when the request finised
|
2018-12-21 12:23:12 +01:00
|
|
|
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
2018-12-25 00:15:25 +01:00
|
|
|
// or the timer timed out
|
|
|
|
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
|
|
|
// start the timer
|
|
|
|
timer.start(2000);
|
|
|
|
// start the loop
|
2018-12-21 12:23:12 +01:00
|
|
|
loop.exec();
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// get the status code from the request
|
2018-12-21 12:23:12 +01:00
|
|
|
int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// 404 is a success because a non existent file was called and not 401 was returned -> user data was correct
|
|
|
|
if(status_code == 404){
|
|
|
|
// store username and password in the class variables
|
2018-12-21 12:23:12 +01:00
|
|
|
this->username = username;
|
|
|
|
this->password = password;
|
2018-12-25 00:15:25 +01:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
if(permanent){
|
2018-12-25 00:15:25 +01:00
|
|
|
// if the user wants to say logged in, store the username and password to the settings file
|
2018-12-21 12:23:12 +01:00
|
|
|
pGlobalAppSettings->writeSetting("permanent", "1");
|
|
|
|
pGlobalAppSettings->writeSetting("username", username);
|
|
|
|
pGlobalAppSettings->writeSetting("password", password);
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
2018-12-25 00:15:25 +01:00
|
|
|
|
2018-12-25 20:34:53 +01:00
|
|
|
this->setState("loggedIn");
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// return success
|
|
|
|
return(200);
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-12-25 00:15:25 +01:00
|
|
|
// if not 404 was returned -> error -> return the return code
|
2018-12-25 20:34:53 +01:00
|
|
|
this->setState("notLoggedIn");
|
2018-12-25 00:15:25 +01:00
|
|
|
return(status_code);
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
2018-06-21 08:47:09 +02:00
|
|
|
}
|
|
|
|
|
2018-06-21 16:41:02 +02:00
|
|
|
int ServerConn::logout()
|
|
|
|
{
|
2018-12-25 00:15:25 +01:00
|
|
|
// reset the data stored in the class
|
2018-06-21 16:41:02 +02:00
|
|
|
this->username = "";
|
|
|
|
this->password = "";
|
2018-12-25 00:15:25 +01:00
|
|
|
// reset the data stored in the settings
|
2018-06-21 16:41:02 +02:00
|
|
|
pGlobalAppSettings->writeSetting("permanent", "0");
|
|
|
|
pGlobalAppSettings->writeSetting("username", "");
|
|
|
|
pGlobalAppSettings->writeSetting("password", "");
|
2018-12-25 20:34:53 +01:00
|
|
|
|
|
|
|
this->setState("notLoggedIn");
|
2018-12-25 00:15:25 +01:00
|
|
|
// return success
|
2018-06-21 17:56:36 +02:00
|
|
|
return(200);
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ServerConn::getDay(QString day)
|
|
|
|
{
|
2018-06-30 20:59:42 +02:00
|
|
|
this->progress = 0;
|
2018-06-21 16:41:02 +02:00
|
|
|
// Create request
|
2018-12-21 12:23:12 +01:00
|
|
|
QNetworkRequest request;
|
|
|
|
request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/" + day + ".pdf" ) );
|
|
|
|
|
|
|
|
// 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){
|
|
|
|
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
|
|
|
|
|
|
|
QDir dir;
|
|
|
|
dir.mkdir(path + "/.fannyapp-tmp");
|
|
|
|
QFile file(path + "/.fannyapp-tmp/" + day + ".pdf");
|
|
|
|
file.remove();
|
|
|
|
|
|
|
|
file.open(QIODevice::ReadWrite);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
|
|
|
QUrl url = QUrl::fromLocalFile(path + "/.fannyapp-tmp/" + day + ".pdf");
|
|
|
|
|
|
|
|
// QDesktopServices::openUrl(url);
|
2018-12-23 22:40:30 +01:00
|
|
|
return("OK_" + url.toString());
|
|
|
|
}
|
|
|
|
else if(status_code == 401){
|
|
|
|
return("Ungültige Benutzerdaten.");
|
|
|
|
}
|
|
|
|
else if(status_code == 0){
|
|
|
|
return("Keine Verbindung zum Server.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QString ret = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toChar();
|
|
|
|
ret = ret + " (" + reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toChar() + ")";
|
|
|
|
return(ret);
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
2018-12-23 22:40:30 +01:00
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-06-21 16:41:02 +02:00
|
|
|
int ServerConn::checkConn()
|
|
|
|
{
|
|
|
|
// Create request
|
2018-12-21 12:23:12 +01:00
|
|
|
QNetworkRequest request;
|
|
|
|
request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/" ) );
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
// Pack in credentials
|
2018-12-25 00:15:25 +01:00
|
|
|
// e.g. ZedlerDo:LxyJQB (yes, these do actually work ;)
|
2018-12-21 12:23:12 +01:00
|
|
|
QString concatenatedCredentials = this->username + ":" + this->password;
|
|
|
|
QByteArray data = concatenatedCredentials.toLocal8Bit().toBase64();
|
|
|
|
QString headerData = "Basic " + data;
|
|
|
|
request.setRawHeader( "Authorization", headerData.toLocal8Bit() );
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
QUrlQuery pdata;
|
|
|
|
// Send request and connect all possible signals
|
|
|
|
QNetworkReply*reply = this->refreshNetworkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
|
|
|
//QNetworkReply*reply = networkManager->get( request );
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-25 19:30:42 +01:00
|
|
|
QTimer timer;
|
|
|
|
timer.start(3000);
|
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
QEventLoop loop;
|
|
|
|
loop.connect(this->refreshNetworkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
2018-12-25 20:34:53 +01:00
|
|
|
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
2018-12-21 12:23:12 +01:00
|
|
|
loop.exec();
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
2018-12-25 19:30:42 +01:00
|
|
|
|
|
|
|
if(status_code == 401){
|
|
|
|
authErrorCount ++;
|
|
|
|
|
|
|
|
if(authErrorCount > 3){
|
|
|
|
logout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->checkConnTimer->start();
|
2018-12-21 12:23:12 +01:00
|
|
|
return(status_code);
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 09:36:20 +02:00
|
|
|
void ServerConn::updateProgress(qint64 read, qint64 total)
|
|
|
|
{
|
2018-12-25 00:15:25 +01:00
|
|
|
int read_int = int(read);
|
|
|
|
int total_int = int(total);
|
|
|
|
float percent = (float(read_int) / float(total_int));
|
2018-06-22 09:36:20 +02:00
|
|
|
this->progress = percent;
|
2018-12-25 00:15:25 +01:00
|
|
|
percent = int(percent);
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
// qDebug() << read << total << percent << "%";
|
2018-06-22 09:36:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float ServerConn::getProgress()
|
|
|
|
{
|
|
|
|
return(this->progress);
|
|
|
|
}
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-23 00:06:05 +01:00
|
|
|
int ServerConn::getEvents(QString day){
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-26 17:54:45 +01:00
|
|
|
|
2018-10-14 18:39:09 +02:00
|
|
|
this->progress = 0;
|
|
|
|
ReturnData_t ret; //this is a custom type to store the returned data
|
|
|
|
// Call the webservice
|
|
|
|
|
2018-12-23 00:06:05 +01:00
|
|
|
QNetworkRequest request(QUrl("http://api.itsblue.de/fanny/vertretung.php?uname=" + this->username + "&passwd=" + this->password + "&day=" + day + "&agree=true"));
|
2018-10-14 18:39:09 +02:00
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
2018-12-21 12:23:12 +01:00
|
|
|
"application/x-www-form-urlencoded");
|
2018-10-14 18:39:09 +02:00
|
|
|
|
|
|
|
//send a POST request with the given url and data to the server
|
|
|
|
QNetworkReply* reply;
|
|
|
|
|
|
|
|
QUrlQuery pdata;
|
|
|
|
reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
|
|
|
|
|
|
|
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
|
2018-12-21 12:23:12 +01:00
|
|
|
this, SLOT(updateProgress(qint64, qint64)));
|
2018-10-14 18:39:09 +02:00
|
|
|
//wait until the request has finished
|
|
|
|
QEventLoop loop;
|
|
|
|
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
//get the status code
|
|
|
|
QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
|
|
|
this->progress = 1;
|
|
|
|
if(status_code != 200){
|
2018-12-26 10:23:54 +01:00
|
|
|
// if the request didn't result in a success, return the error code
|
2018-10-14 18:39:09 +02:00
|
|
|
return(status_code.toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString eventString = reply->readAll();
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// qDebug() << "reading text file";
|
|
|
|
// QFile * textFile = new QFile(":/samplehtml/Download File.txt");
|
|
|
|
// if (!textFile->open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
// qDebug() << "Load XML File Problem Couldn't open xmlfile.xml to load settings for download";
|
|
|
|
// return 900;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// eventString = textFile->readAll();
|
|
|
|
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// separate all lines into a list
|
|
|
|
QStringList events = eventString.split("\n");
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// a line (one element of the list) looks like this:
|
2018-12-26 23:44:24 +01:00
|
|
|
// class hour replace subject room to text
|
|
|
|
// 8a 1-2 Ei Ch --- Entfall KEINE KA
|
|
|
|
// [ ] <-- at least two spaces between two blocks
|
2018-12-26 13:28:56 +01:00
|
|
|
// 'to' and 'text' can be blank
|
2018-12-26 10:37:14 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < events.length(); i++){
|
|
|
|
if(events[i] == ""){
|
|
|
|
events.removeAt(i);
|
|
|
|
}
|
|
|
|
}
|
2018-12-25 00:15:25 +01:00
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// all pages of the original Event document have a similar header that gets removed by this command
|
|
|
|
// (only the first one remains)
|
|
|
|
events.removeDuplicates();
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// temporary list to store the events for the given day
|
|
|
|
QList<QStringList> tmpEvents;
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// temporary list to store the header information
|
|
|
|
QStringList tmpEventHeader;
|
|
|
|
|
|
|
|
// get the filers list for later usage
|
|
|
|
QList<QStringList> filtersList = pGlobalAppSettings->readFilters();
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// go through the list and process every single row
|
2018-12-26 23:44:24 +01:00
|
|
|
for(int x = 0; x < events.length(); x++){
|
|
|
|
// store the event string
|
|
|
|
QString event = events[x];
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// value to count spaces between text
|
2018-12-24 21:37:32 +01:00
|
|
|
int spaceCount = 0;
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// temporary list to store the data of one day
|
2018-12-26 23:44:24 +01:00
|
|
|
QStringList eventList;
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// temporary dtring to store the data of one block
|
2018-12-24 21:37:32 +01:00
|
|
|
QString tmpString;
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// processing works like:
|
|
|
|
// go through the line char by char
|
2018-12-24 21:37:32 +01:00
|
|
|
for(int i = 0;i < event.length(); i++){
|
2018-12-25 00:15:25 +01:00
|
|
|
// store the char temporarly
|
2018-12-24 21:37:32 +01:00
|
|
|
QCharRef tmpChar = event[i];
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// check if the char is a space
|
2018-12-24 21:37:32 +01:00
|
|
|
if(tmpChar == " "){
|
2018-12-25 00:15:25 +01:00
|
|
|
// if so, increase the spaceCount by one
|
2018-12-24 21:37:32 +01:00
|
|
|
spaceCount ++;
|
|
|
|
}
|
|
|
|
else {
|
2018-12-25 00:15:25 +01:00
|
|
|
// if not -> new block or part of a block started
|
|
|
|
// could be : 8a 1 - 2 OR 8a 1 - 2
|
|
|
|
// here->| OR here->|
|
|
|
|
// in the first case, the space counter is higer than one
|
|
|
|
// in the second case, the space counter is exactly one
|
2018-12-24 21:37:32 +01:00
|
|
|
if(spaceCount == 1){
|
2018-12-25 00:15:25 +01:00
|
|
|
// -> append a space to the temp string
|
2018-12-24 21:37:32 +01:00
|
|
|
tmpString.append(" ");
|
|
|
|
}
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// reset the space counter
|
2018-12-24 21:37:32 +01:00
|
|
|
spaceCount = 0;
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// append the current character
|
2018-12-24 21:37:32 +01:00
|
|
|
tmpString.append(tmpChar);
|
|
|
|
}
|
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// check if the space count is 2
|
2018-12-24 21:37:32 +01:00
|
|
|
if(spaceCount == 2){
|
2018-12-25 00:15:25 +01:00
|
|
|
// if so -> break between two blocks
|
2018-12-26 23:44:24 +01:00
|
|
|
// could be: 8a 1 - 2
|
|
|
|
// here ->|
|
2018-12-25 00:15:25 +01:00
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// -> append the current tmpString to the eventList
|
|
|
|
eventList.append(tmpString);
|
2018-12-25 00:15:25 +01:00
|
|
|
|
|
|
|
// and clear the tmpString
|
2018-12-24 21:37:32 +01:00
|
|
|
tmpString = "";
|
|
|
|
}
|
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
//qDebug() << "char= " << tmpChar << " string= " << tmpString << " list= " << eventList;
|
2018-12-24 21:37:32 +01:00
|
|
|
}
|
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// append the remaining tmpString to the eventList
|
|
|
|
eventList.append(tmpString);
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// fill up the eventList with blanks until it reaches the defined length
|
|
|
|
while (eventList.length() < 7) {
|
|
|
|
eventList.append("");
|
2018-12-24 21:37:32 +01:00
|
|
|
}
|
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
if(x < 6){
|
|
|
|
// if the event is in the header
|
|
|
|
// the header could look like this:
|
|
|
|
//
|
|
|
|
// D-70563 FANNY-LEICHT-GYMN. Schuljahr 2018/19 - 1. Halbjahr Untis 2017
|
|
|
|
// STUTTGART, F.-LEICHT-STR. 13 gültig ab 10. September 2018 (13.12.2018 9:04)
|
|
|
|
//
|
|
|
|
//[Klasse 13.12. / Donnerstag Woche-A]
|
|
|
|
//{Ordnungsdienst: Klasse 10a}
|
|
|
|
//
|
|
|
|
// important data:
|
|
|
|
// () = date and time the document has been created
|
|
|
|
// [] = date the document is made for
|
|
|
|
// {} = class that has to clean up the scool :D
|
|
|
|
// (brackets are not present in the document)
|
|
|
|
|
|
|
|
// line 0 and 4 don't contain imporant information -> skip
|
|
|
|
|
|
|
|
if (x == 1) {
|
|
|
|
// the second line contains the creation date
|
|
|
|
// the creation date is the third block of the line
|
|
|
|
tmpEventHeader.append(eventList[2]);
|
|
|
|
}
|
|
|
|
else if (x == 2) {
|
|
|
|
// the third line contains the target date of the document
|
|
|
|
// the target date is the first block of the line
|
|
|
|
tmpEventHeader.append(eventList[0]);
|
|
|
|
}
|
|
|
|
else if (x == 3) {
|
|
|
|
// the third line contains the cleaning class
|
|
|
|
// the cleaning class is the first block of the line
|
|
|
|
tmpEventHeader.append(eventList[0]);
|
|
|
|
}
|
|
|
|
else if (x == 4) {
|
|
|
|
// if the fourth line is reached
|
|
|
|
// fill the event header
|
|
|
|
while (tmpEventHeader.length() < 7) {
|
|
|
|
tmpEventHeader.append("");
|
|
|
|
}
|
|
|
|
|
2018-12-27 11:06:26 +01:00
|
|
|
// check if the header is valid
|
|
|
|
// variable to count filled blocks
|
|
|
|
int blocksOK = 0;
|
|
|
|
foreach(QString block, tmpEventHeader){
|
|
|
|
if(block != ""){
|
|
|
|
blocksOK ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(blocksOK != 3) {
|
|
|
|
// if there are more or less than 3 filled blocks, the data is invalid
|
|
|
|
return(900);
|
|
|
|
}
|
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
// swap creation and target date
|
|
|
|
tmpEventHeader.swap(0,1);
|
|
|
|
|
|
|
|
// and append it to the events list
|
|
|
|
tmpEvents.append(tmpEventHeader);
|
|
|
|
}
|
|
|
|
else if (x == 5) {
|
|
|
|
// the fifth row contains the labels for the different filds
|
|
|
|
// -> append it to the events list
|
|
|
|
tmpEvents.append(eventList);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(filtersList.isEmpty()){
|
|
|
|
// if there are no filters append the event immideatly
|
|
|
|
tmpEvents.append(eventList);
|
2018-12-25 19:30:42 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-12-26 23:44:24 +01:00
|
|
|
// if there is at least one filter, check if the event matches it
|
2018-12-25 19:30:42 +01:00
|
|
|
foreach(QStringList filter, filtersList){
|
|
|
|
// go through all filters and check if one of them matches the event
|
|
|
|
|
2018-12-26 23:44:24 +01:00
|
|
|
if((eventList[0].contains(filter[0]) && eventList[0].contains(filter[1]))){
|
|
|
|
// append the eventList to the temporary event list
|
|
|
|
tmpEvents.append(eventList);
|
2018-12-25 19:30:42 +01:00
|
|
|
// terminate the loop
|
|
|
|
break;
|
|
|
|
}
|
2018-12-25 15:16:24 +01:00
|
|
|
}
|
2018-12-25 00:15:25 +01:00
|
|
|
}
|
2018-12-24 21:37:32 +01:00
|
|
|
}
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// store the new events into the class variable
|
2018-12-24 21:37:32 +01:00
|
|
|
this->m_events = tmpEvents;
|
|
|
|
qDebug() << tmpEvents;
|
|
|
|
|
2018-12-26 10:23:54 +01:00
|
|
|
// check if there is any valid data
|
2018-12-27 11:06:26 +01:00
|
|
|
if(this->m_events.length() < 3){
|
|
|
|
// remove the last (in this case the second) element, as it is unnecessary
|
|
|
|
m_events.takeLast();
|
|
|
|
// return no data
|
2018-12-26 10:23:54 +01:00
|
|
|
return(901);
|
|
|
|
}
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
// return success
|
|
|
|
return(200);
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
/*
|
|
|
|
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<QStringList> tmpEvents;
|
|
|
|
QStringList dayList;
|
|
|
|
while (dayList.length() < 7) {
|
|
|
|
dayList.append("");
|
|
|
|
}
|
|
|
|
|
|
|
|
int currTop = 0;
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-23 22:40:30 +01:00
|
|
|
<text top="530" left="3" width="20" height="17" font="1">8a</text>
|
|
|
|
<text top="530" left="55" width="36" height="17" font="1">1 - 2</text>
|
|
|
|
<text top="530" left="123" width="16" height="17" font="4"><i>Ei</i></text>
|
|
|
|
<text top="530" left="178" width="23" height="17" font="4"><i>Ch</i></text>
|
|
|
|
<text top="530" left="233" width="18" height="17" font="1">---</text>
|
|
|
|
<text top="530" left="275" width="50" height="17" font="1">Entfall</text>
|
|
|
|
<text top="530" left="391" width="83" height="17" font="1">KEINE KA</text>
|
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
<text top="194" left="3" width="62" height="17" font="1">5abc 1</text>
|
|
|
|
<text top="194" left="102" width="27" height="17" font="4"><i>We</i></text>
|
|
|
|
<text top="194" left="157" width="25" height="17" font="4"><i>KR</i></text>
|
|
|
|
<text top="194" left="209" width="18" height="17" font="1">---</text>
|
|
|
|
<text top="194" left="251" width="50" height="17" font="1">Entfall</text>
|
|
|
|
|
|
|
|
|
|
|
|
#define eventXmlPosGrade 3
|
|
|
|
#define eventXmlPosHour 55
|
|
|
|
#define eventXmlPosReplace 123
|
|
|
|
#define eventXmlPosSubject 178
|
|
|
|
#define eventXmlPosRoom 233
|
|
|
|
#define eventXmlPosTo 275
|
|
|
|
#define eventXmlPosText 391
|
|
|
|
|
|
|
|
QList<int> 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();
|
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
if(attributes.hasAttribute("top")){
|
|
|
|
// get the y-Position of the text
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
top = attributes.value("top").toInt();
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
if(abs(top - currTop) > 3){
|
|
|
|
// new line started
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
if(currTop > 175){
|
|
|
|
// if not header -> append
|
|
|
|
qDebug() << dayList;
|
|
|
|
tmpEvents.append(dayList);
|
|
|
|
}
|
2018-12-23 22:40:30 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
dayList.clear();
|
|
|
|
while (dayList.length() < 7) {
|
|
|
|
dayList.append("");
|
|
|
|
}
|
|
|
|
currTop = top;
|
2018-12-23 22:40:30 +01:00
|
|
|
}
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
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]);
|
|
|
|
}
|
2018-12-23 22:40:30 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-24 21:37:32 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
else {
|
|
|
|
qDebug() << " no left";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-12-24 21:37:32 +01:00
|
|
|
else {
|
2018-12-25 00:15:25 +01:00
|
|
|
qDebug() << " no top";
|
2018-12-24 21:37:32 +01:00
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 22:40:30 +01:00
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
this->m_events = tmpEvents;
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
if(xmlReader->hasError()) {
|
|
|
|
qDebug() << "xmlFile.xml Parse Error" << xmlReader->errorString();
|
|
|
|
//return(900);
|
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-12-25 00:15:25 +01:00
|
|
|
//close reader and flush file
|
|
|
|
xmlReader->clear();
|
|
|
|
xmlFile->close();
|
|
|
|
*/
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-10-14 18:39:09 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 00:15:18 +02:00
|
|
|
int ServerConn::getFoodPlan()
|
2018-06-22 15:33:16 +02:00
|
|
|
{
|
2018-12-24 21:37:32 +01:00
|
|
|
// set the progress to 0
|
2018-06-25 08:07:05 +02:00
|
|
|
this->progress = 0;
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// Call the webservice
|
2018-06-22 15:33:16 +02:00
|
|
|
QNetworkRequest request(QUrl("http://www.treffpunkt-fanny.de/fuer-schueler-und-lehrer/speiseplan.html"));
|
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
2018-12-21 12:23:12 +01:00
|
|
|
"application/x-www-form-urlencoded");
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-24 21:37:32 +01:00
|
|
|
// send a GET request to the treffpunkt fanny server
|
2018-06-22 15:33:16 +02:00
|
|
|
QNetworkReply* reply;
|
2018-12-24 21:37:32 +01:00
|
|
|
reply = this->networkManager->get(request);
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-24 21:37:32 +01:00
|
|
|
// update the progress during the request
|
2018-06-25 00:15:18 +02:00
|
|
|
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
|
2018-12-21 12:23:12 +01:00
|
|
|
this, SLOT(updateProgress(qint64, qint64)));
|
2018-12-23 21:07:10 +01:00
|
|
|
|
2018-12-24 21:37:32 +01:00
|
|
|
// loop to wait until the request has finished before processing the data
|
2018-06-22 15:33:16 +02:00
|
|
|
QEventLoop loop;
|
2018-12-24 21:37:32 +01:00
|
|
|
// timer to cancel the request after 3 seconds
|
2018-12-23 21:07:10 +01:00
|
|
|
QTimer timer;
|
|
|
|
timer.setSingleShot(true);
|
2018-12-24 21:37:32 +01:00
|
|
|
|
|
|
|
// quit the loop when the request finised
|
2018-06-22 15:33:16 +02:00
|
|
|
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
2018-12-24 21:37:32 +01:00
|
|
|
// or the timer timed out
|
|
|
|
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
|
|
|
// start the timer
|
2018-12-23 21:07:10 +01:00
|
|
|
timer.start(2000);
|
2018-12-24 21:37:32 +01:00
|
|
|
// start the loop
|
2018-06-22 15:33:16 +02:00
|
|
|
loop.exec();
|
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// get the status code
|
2018-06-22 15:33:16 +02:00
|
|
|
QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
2018-12-24 21:37:32 +01:00
|
|
|
// set the progress to 1
|
2018-06-25 08:07:05 +02:00
|
|
|
this->progress = 1;
|
2018-06-24 09:23:10 +02:00
|
|
|
if(status_code != 200){
|
2018-12-24 21:37:32 +01:00
|
|
|
// if the request didn't result in a success, return the error code
|
2018-12-25 19:30:42 +01:00
|
|
|
|
|
|
|
// if the request failed but there is still old data available
|
|
|
|
if(!this->m_weekplan.isEmpty()){
|
|
|
|
// set the status code to 902 (old data)
|
|
|
|
status_code = 902;
|
|
|
|
}
|
|
|
|
|
2018-06-25 00:15:18 +02:00
|
|
|
return(status_code.toInt());
|
2018-06-24 09:23:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// initialize the weekplan to store information to it
|
2018-06-24 21:56:40 +02:00
|
|
|
QList<QList<QString>> temp_weekplan;
|
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// m_weekplan is a list, that contains a list for each day, which contains: cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert.
|
|
|
|
|
|
|
|
// read the whole website
|
2018-12-23 21:12:33 +01:00
|
|
|
QString returnedData = QString::fromUtf8(reply->readAll());
|
2018-06-24 09:23:10 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// remove unnecessary stuff
|
2018-12-23 21:12:33 +01:00
|
|
|
returnedData.replace("\n","");
|
|
|
|
returnedData.replace("\r","");
|
|
|
|
returnedData.replace("\t","");
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// workaround for changing html syntax
|
2018-12-23 21:12:33 +01:00
|
|
|
returnedData.replace("style=\"width: 25%;\"", "width=\"25%\"");
|
2018-12-23 21:07:10 +01:00
|
|
|
|
|
|
|
// split the string at the beginning of the tables
|
2018-12-23 21:12:33 +01:00
|
|
|
QStringList documentList = returnedData.split( "<table class=\"speiseplan\">" );
|
2018-12-23 21:07:10 +01:00
|
|
|
|
|
|
|
// enshure that the data is valid
|
|
|
|
if(documentList.length() < 2){
|
|
|
|
return(900);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------- prepare the table of the first week ----------
|
|
|
|
QString table1 = documentList[1];
|
|
|
|
|
|
|
|
// enshure that the data is valid
|
|
|
|
if(table1.split( "</table>" ).length() < 1){
|
|
|
|
return(900);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove everything after "</table>"
|
|
|
|
table1 = table1.split( "</table>" )[0];
|
|
|
|
// remove "<tbody><tr style=\"border: 1px solid #999;\" align=\"center\" valign=\"top\">" at the beginning
|
|
|
|
table1.remove(0,71);
|
|
|
|
//remove "</tr></tbody>" at the end
|
|
|
|
table1 = table1.left(table1.length() - 13);
|
|
|
|
|
|
|
|
//split at the days to get a list of all days
|
|
|
|
QStringList table1list = table1.split("<td width=\"25%\">");
|
2018-06-24 09:23:10 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// enshure that the data is valid
|
|
|
|
if(table1list.length() < 5){
|
|
|
|
return(900);
|
|
|
|
}
|
|
|
|
|
|
|
|
//remove the first item, as it is empty
|
|
|
|
table1list.takeFirst();
|
2018-06-24 21:56:40 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//---------- prepare the table of the second week ----------
|
|
|
|
QString table2 = documentList[2];
|
|
|
|
|
|
|
|
// enshure that the data is valid
|
|
|
|
if(table2.split( "</table>" ).length() < 1){
|
|
|
|
return(900);
|
|
|
|
}
|
2018-06-24 21:56:40 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//remove everything after "</table>"
|
|
|
|
table2 = table2.split( "</table>" )[0];
|
|
|
|
//remove "<tbody><tr align=\"center\" valign=\"top\">" at the beginning
|
|
|
|
table2.remove(0,39);
|
|
|
|
//remove "</tr></tbody>" at the end
|
|
|
|
table2.remove(table2.length() - 13, table2.length());
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//split at the days to get a list of all days
|
|
|
|
QStringList table2list = table2.split("<td width=\"25%\">");
|
2018-09-23 17:55:05 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// enshure that the data is valid
|
|
|
|
if(table2list.length() < 5){
|
|
|
|
return(900);
|
|
|
|
}
|
2018-09-23 17:55:05 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//remove the first item, as it is empty
|
|
|
|
table2list.takeFirst();
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//---------- put both weeks into one big list ----------
|
|
|
|
QStringList weeklist = table1list + table2list;
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//---------- go through all days and split the day-string into the different types of information ----------
|
2018-10-14 18:39:09 +02:00
|
|
|
|
2018-06-24 09:23:10 +02:00
|
|
|
for (int i = 0; i <=7; i ++){
|
2018-12-23 21:07:10 +01:00
|
|
|
if(i > weeklist.length()){
|
|
|
|
// if the loop exceeds the length of the wweklist some kind of eror occured
|
|
|
|
return 900;
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
2018-06-24 09:23:10 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// store item temporarly to edit it
|
|
|
|
QString day = weeklist[i];
|
|
|
|
// remove "</td>" at the and of the Item
|
|
|
|
day = day.left(day.length()-5);
|
|
|
|
|
|
|
|
// table list[i] looks now like: | clould be:
|
|
|
|
// <strong>cookteam</strong> | <strong>Red Hot Chili Peppers</strong>
|
|
|
|
// <br /> | <br />
|
|
|
|
// <strong>date</strong> | <strong>26.06.2018</strong>
|
|
|
|
// <hr />mainDish | <hr />Gulasch mit Kartoffeln
|
|
|
|
// <hr />mainDishVeg | <hr />Pellkartoffeln mit Quark
|
|
|
|
// <hr />garnish | <hr />Gemischter Salat
|
|
|
|
// <hr />dessert</td> | <hr />Eaton Mess ( Erdbeer-Nachtisch )</td>
|
|
|
|
|
|
|
|
// split item at strong, to get the cookteam and the date
|
|
|
|
QStringList daylist = day.split("<strong>");
|
|
|
|
day = "";
|
|
|
|
|
|
|
|
// convert the list to a big string
|
|
|
|
for (int i = 0; i <= 2; i ++){
|
|
|
|
if(i <= daylist.length()){
|
|
|
|
day += daylist[i];
|
|
|
|
}
|
|
|
|
}
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
day.replace("<br />","");
|
|
|
|
daylist = day.split("</strong>");
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// store cookteam and date in the temp_weekplan
|
|
|
|
//temp_weekplan.append({daylist[0], daylist[1]});
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// store information in day
|
|
|
|
// (looks like: "<hr />MainDish<hr />MainDishVeg<hr />Garnish<hr />Dessert")
|
|
|
|
// (could be: "<hr />Gulasch mit Kartoffeln<hr />Pellkartoffeln mit Quark<hr />Gemischter Salat<hr />Eaton Mess ( Erdbeer-Nachtisch )")
|
|
|
|
day = daylist.takeLast();
|
|
|
|
// seperate the information
|
|
|
|
daylist.append(day.split("<hr />"));
|
|
|
|
// remove the item that is emplty from the list
|
|
|
|
daylist.removeAt(2);
|
2018-06-24 21:56:40 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//---------- check if the day is aleady over ----------
|
2018-10-14 18:39:09 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// get the datestring
|
|
|
|
QString dateString = daylist[1];
|
|
|
|
// convert it to a valid QDate
|
|
|
|
QDateTime date = QDateTime::fromString(dateString,"dd.MM.yyyy");
|
2018-06-24 21:56:40 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// get the current date and time
|
|
|
|
QDateTime currentDateTime = QDateTime::currentDateTimeUtc();
|
2018-06-22 15:33:16 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
// check if the given day is still in the future or today (then it is valid)
|
|
|
|
if(date.toTime_t() > currentDateTime.toTime_t() || date.date() == currentDateTime.date()){
|
|
|
|
// add the rest of the information to the temp_weekplan
|
|
|
|
qDebug() << "day valid:" << daylist;
|
2018-06-24 09:23:10 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
//---------- convert the date to a readable string ----------
|
|
|
|
QString readableDateString;
|
2018-06-24 21:56:40 +02:00
|
|
|
|
2018-12-23 21:07:10 +01:00
|
|
|
if(date.date() == currentDateTime.date()){
|
|
|
|
// the given day is today
|
|
|
|
readableDateString = "Heute";
|
|
|
|
}
|
|
|
|
else if (date.toTime_t() < ( currentDateTime.toTime_t() + ( 24 * 60 * 60 ))) {
|
|
|
|
// the given day is tomorrow
|
|
|
|
readableDateString = "Morgen";
|
2018-06-24 09:23:10 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-12-23 21:07:10 +01:00
|
|
|
readableDateString = date.toString("dddd, d.M.yy");
|
2018-06-24 09:23:10 +02:00
|
|
|
}
|
2018-12-23 21:07:10 +01:00
|
|
|
|
|
|
|
qDebug() << readableDateString;
|
|
|
|
|
|
|
|
// insert the redable tring into the daylist
|
|
|
|
daylist[1] = readableDateString;
|
|
|
|
|
|
|
|
// append the day to the weeklist
|
|
|
|
temp_weekplan.append({daylist[0], daylist[1], daylist[2], daylist[3], daylist[4], daylist[5]});
|
2018-06-24 09:23:10 +02:00
|
|
|
}
|
2018-12-23 21:07:10 +01:00
|
|
|
}
|
|
|
|
|
2018-12-23 21:12:33 +01:00
|
|
|
// write data to global foodplan
|
|
|
|
this->m_weekplan = temp_weekplan;
|
2018-12-23 21:07:10 +01:00
|
|
|
|
2018-12-23 21:12:33 +01:00
|
|
|
// check if there is any valid data
|
2018-12-23 21:07:10 +01:00
|
|
|
if(this->m_weekplan.isEmpty()){
|
2018-12-23 21:12:33 +01:00
|
|
|
// no data
|
2018-12-23 21:07:10 +01:00
|
|
|
return(901);
|
2018-06-24 09:23:10 +02:00
|
|
|
}
|
2018-12-23 21:07:10 +01:00
|
|
|
|
2018-12-23 21:12:33 +01:00
|
|
|
// success
|
2018-12-23 21:07:10 +01:00
|
|
|
return(200);
|
|
|
|
}
|
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
|
|
|
|
{
|
|
|
|
|
|
|
|
ReturnData_t ret; //this is a custom type to store the returned data
|
|
|
|
// Call the webservice
|
|
|
|
|
|
|
|
QNetworkRequest request(serviceUrl);
|
|
|
|
QAuthenticator authenticator;
|
|
|
|
authenticator.setUser("ZedlerDo");
|
|
|
|
authenticator.setPassword("LxyJQB");
|
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
2018-12-21 12:23:12 +01:00
|
|
|
"application/x-www-form-urlencoded");
|
2018-06-21 08:47:09 +02:00
|
|
|
|
|
|
|
//set ssl configuration
|
|
|
|
//send a POST request with the given url and data to the server
|
|
|
|
QNetworkReply* reply;
|
|
|
|
|
|
|
|
reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
|
|
|
|
|
|
|
//wait until the request has finished
|
|
|
|
QEventLoop loop;
|
|
|
|
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
//get the status code
|
|
|
|
QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
|
|
|
|
|
|
|
ret.status_code = status_code.toInt();
|
|
|
|
if(ret.status_code == 0){ //if tehstatus code is zero, the connecion to the server was not possible
|
|
|
|
ret.status_code = 444;
|
|
|
|
}
|
|
|
|
//get the full text response
|
|
|
|
ret.text = QString::fromUtf8(reply->readAll());
|
|
|
|
|
|
|
|
//return the data
|
|
|
|
return(ret);
|
|
|
|
}
|
2018-12-25 19:30:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
QString ServerConn::getState() {
|
|
|
|
return(this->state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServerConn::setState(QString state) {
|
|
|
|
this->state = state;
|
2018-12-25 20:34:53 +01:00
|
|
|
this->stateChanged(this->state);
|
2018-12-25 19:30:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ServerConn::~ServerConn()
|
|
|
|
{
|
|
|
|
qDebug("serverconn destruktor");
|
|
|
|
delete this->networkManager;
|
|
|
|
delete this->refreshNetworkManager;
|
|
|
|
|
|
|
|
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
|
|
|
QDir dir(path + "/.fannyapp-tmp");
|
|
|
|
dir.removeRecursively();
|
|
|
|
}
|