From a4693a467ff59b3ad73651f1cff861fdddc6dd4b Mon Sep 17 00:00:00 2001 From: dorian Date: Fri, 22 Jun 2018 15:33:16 +0200 Subject: [PATCH] Cookplan added --- android-sources/AndroidManifest.xml | 2 +- fannyapp.pro.user | 158 +++++++++++++++++++--------- headers/serverconn.h | 6 ++ qml/FoodPlanForm.qml | 28 +++++ qml/HomeForm.qml | 10 +- qml/MainPage.qml | 10 ++ qml/qml.qrc | 1 + source/serverconn.cpp | 98 ++++++++++++++++- 8 files changed, 252 insertions(+), 61 deletions(-) create mode 100644 qml/FoodPlanForm.qml diff --git a/android-sources/AndroidManifest.xml b/android-sources/AndroidManifest.xml index f1e88c4..e4fdc54 100644 --- a/android-sources/AndroidManifest.xml +++ b/android-sources/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/fannyapp.pro.user b/fannyapp.pro.user index 4a2a8e1..4f5b87a 100644 --- a/fannyapp.pro.user +++ b/fannyapp.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {736334c7-59b9-42fb-bb64-0bbe827a8b2c} + {21eb7c7e-fe37-4955-bdba-642d7341ba98} ProjectExplorer.Project.ActiveTarget @@ -59,14 +59,14 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.10.1 clang 64bit - Desktop Qt 5.10.1 clang 64bit - qt.qt5.5101.clang_64_kit - 2 + Android for armeabi-v7a (GCC 4.9, Qt 5.10.1 for Android armv7) + Android for armeabi-v7a (GCC 4.9, Qt 5.10.1 for Android armv7) + {c2d2fa4a-1656-4ab9-a542-92c96158a688} + 0 0 0 - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_10_1_clang_64bit-Debug + /home/dorian/Documents/builds/Qt/fanny-app/build-fannyapp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Debug true @@ -92,8 +92,24 @@ - 2 - Erstellen + + true + Copy application data + + Qt4ProjectManager.AndroidPackageInstallationStep + + + android-27 + + true + Build Android APK + + QmakeProjectManager.AndroidBuildApkStep + false + false + + 4 + Build ProjectExplorer.BuildSteps.Build @@ -112,7 +128,7 @@ 1 - Bereinigen + Clean ProjectExplorer.BuildSteps.Clean @@ -126,7 +142,7 @@ true - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_10_1_clang_64bit-Release + /home/dorian/Documents/builds/Qt/fanny-app/build-fannyapp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Release true @@ -152,8 +168,24 @@ - 2 - Erstellen + + true + Copy application data + + Qt4ProjectManager.AndroidPackageInstallationStep + + + android-27 + /home/dorian/Documents/gitlab/fanny-app/android_release.keystore + true + Build Android APK + + QmakeProjectManager.AndroidBuildApkStep + false + false + + 4 + Build ProjectExplorer.BuildSteps.Build @@ -172,7 +204,7 @@ 1 - Bereinigen + Clean ProjectExplorer.BuildSteps.Clean @@ -186,7 +218,7 @@ true - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_10_1_clang_64bit-Profile + /home/dorian/Documents/Fanny App/build-fannyapp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-Profile true @@ -212,8 +244,24 @@ - 2 - Erstellen + + true + Copy application data + + Qt4ProjectManager.AndroidPackageInstallationStep + + + android-27 + + true + Build Android APK + + QmakeProjectManager.AndroidBuildApkStep + false + false + + 4 + Build ProjectExplorer.BuildSteps.Build @@ -232,7 +280,7 @@ 1 - Bereinigen + Clean ProjectExplorer.BuildSteps.Clean @@ -248,18 +296,28 @@ 3 - 0 - Deployment + + true + Deploy to Android device + + Qt4ProjectManager.AndroidDeployQtStep + false + + 1 + Deploy ProjectExplorer.BuildSteps.Deploy 1 - Deployment-Konfiguration + Deploy to Android device - ProjectExplorer.DefaultDeployConfiguration + Qt4ProjectManager.AndroidDeployConfiguration2 1 - + + MWS0216A15001488 + 24 + false false @@ -300,17 +358,13 @@ 13 14 - 2 - + + + fannyapp - - Qt4ProjectManager.Qt4RunConfiguration:/Users/dorian/Documents/git/fanny-app/fannyapp.pro - true - - fannyapp.pro - false - - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_11_1_clang_64bit2-Debug/fannyapp.app/Contents/MacOS + fannyapp + Qt4ProjectManager.AndroidRunConfiguration:/home/dorian/Documents/gitlab/fanny-app/fannyapp.pro + fannyapp.pro 3768 false true @@ -324,14 +378,14 @@ ProjectExplorer.Project.Target.1 - Desktop Qt 5.11.1 clang 64bit2 - Desktop Qt 5.11.1 clang 64bit2 - qt.qt5.5111.clang_64_kit + Desktop Qt 5.10.1 GCC 64bit + Desktop Qt 5.10.1 GCC 64bit + qt.qt5.5101.gcc_64_kit 0 0 0 - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_11_1_clang_64bit2-Debug + /home/dorian/Documents/builds/Qt/fanny-app true @@ -358,7 +412,7 @@ 2 - Erstellen + Build ProjectExplorer.BuildSteps.Build @@ -377,7 +431,7 @@ 1 - Bereinigen + Clean ProjectExplorer.BuildSteps.Clean @@ -391,7 +445,7 @@ true - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_11_1_clang_64bit2-Release + /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_64bit-Release true @@ -402,7 +456,7 @@ false false - true + false true @@ -418,7 +472,7 @@ 2 - Erstellen + Build ProjectExplorer.BuildSteps.Build @@ -437,7 +491,7 @@ 1 - Bereinigen + Clean ProjectExplorer.BuildSteps.Clean @@ -451,7 +505,7 @@ true - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_11_1_clang_64bit2-Profile + /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_64bit-Profile true @@ -462,7 +516,7 @@ false true - true + false true @@ -478,7 +532,7 @@ 2 - Erstellen + Build ProjectExplorer.BuildSteps.Build @@ -497,7 +551,7 @@ 1 - Bereinigen + Clean ProjectExplorer.BuildSteps.Clean @@ -514,12 +568,12 @@ 0 - Deployment + Deploy ProjectExplorer.BuildSteps.Deploy 1 - Deployment-Konfiguration + Deploy Configuration ProjectExplorer.DefaultDeployConfiguration @@ -568,14 +622,14 @@ 2 fannyapp - - Qt4ProjectManager.Qt4RunConfiguration:/Users/dorian/Documents/git/fanny-app/fannyapp.pro + fannyapp2 + Qt4ProjectManager.Qt4RunConfiguration:/home/dorian/Documents/gitlab/fanny-app/fannyapp.pro true fannyapp.pro false - /Users/dorian/Documents/git/build-fannyapp-Desktop_Qt_5_11_1_clang_64bit2-Debug/fannyapp.app/Contents/MacOS + /home/dorian/Documents/builds/Qt/fanny-app 3768 false true diff --git a/headers/serverconn.h b/headers/serverconn.h index cb0579e..e524d7f 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -17,6 +17,11 @@ typedef struct strReturnData{ QString text; }ReturnData_t; +typedef struct Weekplan{ + QString Cookteam; + QString date; +}ReturnData_t; + class ServerConn : public QObject { Q_OBJECT @@ -35,6 +40,7 @@ public: Q_INVOKABLE QString getDay(QString day); Q_INVOKABLE int checkConn(); Q_INVOKABLE float getProgress(); + Q_INVOKABLE QString getFoodPlan(); ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData); signals: diff --git a/qml/FoodPlanForm.qml b/qml/FoodPlanForm.qml new file mode 100644 index 0000000..c565386 --- /dev/null +++ b/qml/FoodPlanForm.qml @@ -0,0 +1,28 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +Page { + anchors.fill: parent + + title: qsTr("Speiseplanplan") + + Label { + id: laWelcome + text: "Hier kannst du dir den Vertretungsplan des Fannys anschauen" + font.pixelSize: 20 + wrapMode: Label.Wrap + width: window.width / 1.2 + + anchors { + top: parent.top + } + } + Button { + id: butt + text: "load" + onClicked: { + var ret = _cppServerConn.getFoodPlan(); + laWelcome.text = ret + } + } +} diff --git a/qml/HomeForm.qml b/qml/HomeForm.qml index d56d3e6..30e8177 100644 --- a/qml/HomeForm.qml +++ b/qml/HomeForm.qml @@ -123,7 +123,6 @@ Page { anchors.centerIn: parent Label { id: progress - anchors.fill: parent anchors.centerIn: parent text: _cppServerConn.getProgress() } @@ -135,14 +134,17 @@ Page { onTriggered: { var ret = _cppServerConn.getProgress() console.log(ret) - progress.text = ret + "%" + progress.text = Math.round( ret * 100 ) + "%" + progressBar.value = ret } } } ProgressBar { - anchors.bottom: parent.bottom + id: progressBar + anchors.top: parent.top anchors.left: parent.left + anchors.right: parent.right + anchors.topMargin: busyDialog.height / 1.5 } } - } diff --git a/qml/MainPage.qml b/qml/MainPage.qml index b956d1d..3a5b7cc 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -43,6 +43,16 @@ Page { drawer.close() } } + + ItemDelegate { + text: qsTr("Speiseplan") + width: parent.width + onClicked: { + stackView.push("FoodPlanForm.qml") + drawer.close() + } + } + ItemDelegate { text: qsTr("abmelden") width: parent.width diff --git a/qml/qml.qrc b/qml/qml.qrc index 00fae0f..285067a 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -7,5 +7,6 @@ MainPage.qml AppToolBar.qml WebsitePage.qml + FoodPlanForm.qml diff --git a/source/serverconn.cpp b/source/serverconn.cpp index 0f348b7..dc4f269 100644 --- a/source/serverconn.cpp +++ b/source/serverconn.cpp @@ -100,7 +100,7 @@ QString ServerConn::getDay(QString day) connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateProgress(qint64, qint64))); - + this->progress = 0; QEventLoop loop; loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); loop.exec(); @@ -113,11 +113,14 @@ QString ServerConn::getDay(QString day) 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(); + this->progress = 1; + QDesktopServices::openUrl(QUrl::fromLocalFile(path + "/.fannyapp-tmp/" + day + ".pdf")); qDebug() << QString::fromUtf8(reply->readAll()); qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); @@ -168,10 +171,10 @@ void ServerConn::updateProgress(qint64 read, qint64 total) { int read_int = read; int total_int = total; - float percent = ((float)read_int / (float)total_int) * 100; - - percent = (int)percent; + float percent = ((float)read_int / (float)total_int); this->progress = percent; + percent = (int)percent; + // qDebug() << read << total << percent << "%"; } @@ -180,6 +183,93 @@ float ServerConn::getProgress() return(this->progress); } +QString ServerConn::getFoodPlan() +{ + ReturnData_t ret; //this is a custom type to store the returned data + // Call the webservice + + QNetworkRequest request(QUrl("http://www.treffpunkt-fanny.de/fuer-schueler-und-lehrer/speiseplan.html")); + request.setHeader(QNetworkRequest::ContentTypeHeader, + "application/x-www-form-urlencoded"); + + //set ssl configuration + //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()); + + //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.text = QString::fromUtf8(reply->readAll()); + ret.text.replace("\n",""); + ret.text.replace("\r",""); + ret.text.replace("\t",""); + + QStringList stringlist_0 = ret.text.split( "" ); + QString table1 = stringlist_0[1]; + QStringList stringlist_1 = table1.split( "
" ); + table1 = stringlist_1[0]; + + + table1.remove(0,71); + table1 = table1.left(table1.length() - 13); + //qDebug() << table1; + + QStringList table1list = table1.split(""); + + qDebug() << table1list; + qDebug() << " "; + for (int i = 1; i <=4; i ++){ + QString temp = table1list[i]; //store item temporarly to edit it + table1list[i] = temp.left(temp.length()-5); //remove "" at the and of the Item + temp = table1list[i]; + //table list[i] looks now like: + //Red Hot Chili Peppers + //
+ //26.06.2018 + //
Gulasch mit Kartoffeln + //
Pellkartoffeln mit Quark + //
Gemischter Salat + //
Eaton Mess ( Erdbeer-Nachtisch ) + + QStringList templist = temp.split(""); //split item at strong, to get the cookteam and the date + //qDebug() << templist << "\n"; + temp = ""; + for (int i = 0; i <=2; i ++){ + temp += templist[i]; //convert the list to a big string + } + temp.replace("
",""); + templist = temp.split("
"); + QStringList Weekplan[0][i]; + Weekplan[0][i][0] = templist[0]; //store the cookteam in the weeklist + Weekplan[0][i][1] = templist[1]; //store the date in the weeklist + + + } + + QString table2 = stringlist_0[2]; + QStringList stringlist_2 = table2.split( "" ); + table2 = stringlist_2[0]; + +// QString fulltable = "" + stringlist_1[0] + stringlist_2[0] + "
"; +// fulltable.replace("\n",""); +// fulltable.replace("\r",""); +// fulltable.replace("\t",""); +// qDebug() << fulltable; +// return(fulltable); + + + //qDebug() << ret.text; + return(""); +} + ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata) {