diff --git a/android-sources/AndroidManifest.xml b/android-sources/AndroidManifest.xml new file mode 100644 index 0000000..2411de1 --- /dev/null +++ b/android-sources/AndroidManifest.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android-sources/res/drawable-hdpi/icon.png b/android-sources/res/drawable-hdpi/icon.png new file mode 100644 index 0000000..859de5e Binary files /dev/null and b/android-sources/res/drawable-hdpi/icon.png differ diff --git a/android-sources/res/drawable-ldpi/icon.png b/android-sources/res/drawable-ldpi/icon.png new file mode 100644 index 0000000..859de5e Binary files /dev/null and b/android-sources/res/drawable-ldpi/icon.png differ diff --git a/android-sources/res/drawable-mdpi/icon.png b/android-sources/res/drawable-mdpi/icon.png new file mode 100644 index 0000000..859de5e Binary files /dev/null and b/android-sources/res/drawable-mdpi/icon.png differ diff --git a/android_release.keystore b/android_release.keystore new file mode 100644 index 0000000..f330509 Binary files /dev/null and b/android_release.keystore differ diff --git a/fannyapp.pro b/fannyapp.pro index 08b68ef..098b0fb 100644 --- a/fannyapp.pro +++ b/fannyapp.pro @@ -1,4 +1,4 @@ -QT += quick +QT += qml quick quickcontrols2 CONFIG += c++11 # The following define makes your compiler emit warnings if you use @@ -12,15 +12,21 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 +TEMPLATE = app +TARGET = fannyapp + SOURCES += \ source/serverconn.cpp \ - source/main.cpp + source/main.cpp \ + source/appsettings.cpp HEADERS += \ - headers/serverconn.h + headers/serverconn.h \ + headers/appsettings.h RESOURCES += \ - qml/qml.qrc + qml/qml.qrc \ + shared.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = @@ -33,4 +39,12 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target +android { + ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources +} + +DISTFILES += \ + favicon.png \ + android-sources/AndroidManifest.xml + diff --git a/fannyapp.pro.user b/fannyapp.pro.user index 159e2c5..efe6ce0 100644 --- a/fannyapp.pro.user +++ b/fannyapp.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 0 + 1 ProjectExplorer.Project.EditorSettings @@ -66,7 +66,7 @@ 0 0 - /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_64bit-Debug + /home/dorian/Documents/builds/Qt/fanny-app true @@ -310,7 +310,7 @@ fannyapp.pro false - /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_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-Release 3768 false true @@ -327,7 +327,7 @@ 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 + 1 0 0 @@ -407,7 +407,7 @@ true - /home/dorian/Documents/Fanny App/build-fannyapp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_10_1_for_Android_armv7-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 @@ -441,7 +441,7 @@ android-27 - + /home/dorian/Documents/gitlab/fanny-app/android_release.keystore true Build Android APK @@ -579,7 +579,10 @@ Qt4ProjectManager.AndroidDeployConfiguration2 1 - + + MWS0216A15001488 + 24 + false false @@ -625,8 +628,8 @@ fannyapp fannyapp - Qt4ProjectManager.AndroidRunConfiguration:/home/dorian/Documents/Fanny App/App/fannyapp.pro - ../../Fanny App/App/fannyapp.pro + Qt4ProjectManager.AndroidRunConfiguration:/home/dorian/Documents/gitlab/fanny-app/fannyapp.pro + fannyapp.pro 3768 false true diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000..859de5e Binary files /dev/null and b/favicon.png differ diff --git a/favicon.xcf b/favicon.xcf new file mode 100644 index 0000000..2b5b15b Binary files /dev/null and b/favicon.xcf differ diff --git a/graphics/Banner.png b/graphics/Banner.png new file mode 100644 index 0000000..75553f8 Binary files /dev/null and b/graphics/Banner.png differ diff --git a/graphics/FannyLogo.png b/graphics/FannyLogo.png new file mode 100644 index 0000000..f963950 Binary files /dev/null and b/graphics/FannyLogo.png differ diff --git a/graphics/Screenshot1.jpg b/graphics/Screenshot1.jpg new file mode 100644 index 0000000..abb123c Binary files /dev/null and b/graphics/Screenshot1.jpg differ diff --git a/graphics/Screenshot2.jpg b/graphics/Screenshot2.jpg new file mode 100644 index 0000000..f87d886 Binary files /dev/null and b/graphics/Screenshot2.jpg differ diff --git a/graphics/favicon.png b/graphics/favicon.png new file mode 100644 index 0000000..4ee3fc5 Binary files /dev/null and b/graphics/favicon.png differ diff --git a/graphics/favicon.xcf b/graphics/favicon.xcf new file mode 100644 index 0000000..2f48792 Binary files /dev/null and b/graphics/favicon.xcf differ diff --git a/graphics/icon.jpg b/graphics/icon.jpg new file mode 100644 index 0000000..aaf4da4 Binary files /dev/null and b/graphics/icon.jpg differ diff --git a/graphics/sheute.png b/graphics/sheute.png new file mode 100644 index 0000000..0b8f2aa Binary files /dev/null and b/graphics/sheute.png differ diff --git a/graphics/smorgen.png b/graphics/smorgen.png new file mode 100644 index 0000000..1212cc7 Binary files /dev/null and b/graphics/smorgen.png differ diff --git a/headers/appsettings.h b/headers/appsettings.h new file mode 100644 index 0000000..b5459ec --- /dev/null +++ b/headers/appsettings.h @@ -0,0 +1,26 @@ +#ifndef APPSETTINGS_H +#define APPSETTINGS_H + +#include +#include +#include + +class AppSettings : public QObject +{ + Q_OBJECT +public: + explicit AppSettings(QObject *parent = nullptr); + ~AppSettings(); + + Q_INVOKABLE QString loadSetting(const QString &key); + Q_INVOKABLE void writeSetting(const QString &key, const QVariant &variant); + + QSettings *settingsManager; + +signals: + +public slots: +}; +extern AppSettings * pGlobalAppSettings; + +#endif // APPSETTINGS_H diff --git a/headers/serverconn.h b/headers/serverconn.h index 143441c..3192f9f 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -2,8 +2,12 @@ #define SERVERCONN_H #include +#include #include #include +#include + +#include "headers/appsettings.h" typedef struct strReturnData{ int status_code; @@ -13,10 +17,20 @@ typedef struct strReturnData{ class ServerConn : public QObject { Q_OBJECT + public: + QString username; + QString password; QNetworkAccessManager *networkManager; + QNetworkAccessManager *refreshNetworkManager; +public: explicit ServerConn(QObject *parent = nullptr); - Q_INVOKABLE QString login(); + ~ServerConn(); + + Q_INVOKABLE QString login(QString username, QString password, bool permanent); + Q_INVOKABLE int logout(); + Q_INVOKABLE QString getDay(QString day); + Q_INVOKABLE int checkConn(); ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData); signals: diff --git a/qml/AppToolBar.qml b/qml/AppToolBar.qml new file mode 100644 index 0000000..fe3469b --- /dev/null +++ b/qml/AppToolBar.qml @@ -0,0 +1,28 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.1 +import QtQuick.Controls.Material 2.1 + +ToolBar { + property bool showErrorBar: true + Material.theme: Material.Light + Rectangle { + id: errorField + width: parent.width + height: 30 + visible: window.is_error & stackView.currentItem.objectName !== "LoginPage" & showErrorBar + anchors.top: parent.bottom + + + color: "red" + Text { + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + id: errorText + font.family: "Helvetica" + color: "White" + font.pointSize: 8 + + text: window.error + } + } +} diff --git a/qml/HomeForm.qml b/qml/HomeForm.qml index 8a16aa3..f7e87a3 100644 --- a/qml/HomeForm.qml +++ b/qml/HomeForm.qml @@ -2,15 +2,126 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 Page { - width: 600 - height: 400 + anchors.fill: parent - title: qsTr("Home") + title: qsTr("Vertretungsplan") Label { - text: qsTr("You are on the home page.") - anchors.centerIn: parent + id: laWelcome + text: "Hier kannst du dir den Vertretungsplan des Fannys anschuen" + font.pixelSize: 20 + wrapMode: Label.Wrap + width: window.width / 1.2 + + anchors { + top: parent.top + topMargin: window.height / 8 - laWelcome.height / 2 + horizontalCenter: parent.horizontalCenter + } } + Button { + id:buttToday + anchors { + left: parent.left + leftMargin: (window.width / 4) - (buttToday.width / 2) + verticalCenter: parent.verticalCenter + } + + onClicked: { + verificationDialog.day = "sheute" + verificationDialog.open() + } + background: Image { + id: sheuteImage + source: "qrc:/graphics/sheute.png" + } + } + + Button { + id: buttTomorrow + anchors { + right: parent.right + rightMargin: (window.width / 4) - (buttTomorrow.width / 2) + verticalCenter: parent.verticalCenter + } + + onClicked: { + verificationDialog.day = "smorgen" + verificationDialog.open() + } + background: Image { + id: smorgenImage + source: "qrc:/graphics/smorgen.png" + } + } + + Dialog { + property string day + id: verificationDialog + modal: true + focus: true + title: "Bedingung" + x: (window.width - width) / 2 + y: window.height / 6 + width: Math.min(window.width, window.height) / 3 * 2 + contentHeight: aboutColumn.height + standardButtons: Dialog.Ok | Dialog.Cancel + onAccepted: { + busyDialog.open() + text.visible = false + console.log("getting file of ", day) + var ret = _cppServerConn.getDay(day) + console.log(ret) + busyDialog.close() + text.visible = true + if(ret === "OK"){ + return + } + else if(ret === "Ungültige Benutzerdaten."){ + root.StackView.view.pop() + } + else { + error.text = ret + window.is_error = true + window.error = ret + error.visible = true + } + } + + Column { + id: aboutColumn + spacing: 20 + Label { + id: text + visible: true + width: verificationDialog.availableWidth + + + wrapMode: Label.Wrap + text: "Vertretungsplan, vertraulich, nur zum persönlichen Gebrauch, keine Speicherung!" + } + } + } + + Dialog { + id: busyDialog + modal: true + closePolicy: "NoAutoClose" + focus: true + //title: "Please wait..." + x: (window.width - width) / 2 + y: window.height / 6 + //width: Math.min(window.width, window.height) / 3 * 2 + height: contentHeight * 1.5 + width: contentWidth * 1.5 + contentHeight: busyIndicator.height + contentWidth: busyIndicator.width + BusyIndicator { + id: busyIndicator + visible: true + anchors.centerIn: parent + } + } } diff --git a/qml/LoginPage.qml b/qml/LoginPage.qml index dc42107..1dd7809 100644 --- a/qml/LoginPage.qml +++ b/qml/LoginPage.qml @@ -1,31 +1,143 @@ import QtQuick 2.0 +import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 Page { id: root anchors.fill: parent + objectName: "LoginPage"; + + header: AppToolBar { - Label { - text: qsTr("You are on login") - anchors.centerIn: parent } - BusyIndicator { - id: busyIndicator - visible: true - x: 40 - y: 49 + + Image { + id: bigLogo + source: "favicon.png" + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: window.height * 0.01 + height: window.height * 0.2 + fillMode: Image.PreserveAspectFit } - Button { - text: "main" - height: 30 - width: 50 - onClicked: { - var ret = _cppServerConn.login(); + ColumnLayout { + spacing: 40 + width: parent.width + anchors.fill: parent + anchors.topMargin: bigLogo.height + window.height * 0.01 + anchors.bottomMargin: window.height * 0.2 + + TextField { + id: tiuname + placeholderText: "Username" + anchors.horizontalCenter: parent.horizontalCenter + Keys.onReturnPressed: login(tiuname.text, tipasswd.text, cBperm.checked) + anchors.left: parent.left + anchors.margins: window.width * 0.05 + + } + + + TextField { + id: tipasswd + echoMode: TextInput.Password + placeholderText: "Password" + anchors.horizontalCenter: parent.horizontalCenter + Keys.onReturnPressed: login(tiuname.text, tipasswd.text, cBperm.checked) + anchors.left: parent.left + anchors.margins: window.width * 0.05 + } + + CheckDelegate { + id: cBperm + text: qsTr("Stay logged in") + checked: true + anchors.horizontalCenter: parent.horizontalCenter + } + + Button { + id: loginButton + objectName: "loginButton" + text: qsTr("Login") + enabled: tiuname.length > 0 & tipasswd.length > 0 + anchors.horizontalCenter: parent.horizontalCenter + anchors.left: parent.left + anchors.margins: window.width * 0.05 + onClicked: login(tiuname.text, tipasswd.text, cBperm.checked) + } + Label { + id: laStatus + text: qsTr("") + font.pixelSize: 20 + color: "red" + anchors.horizontalCenter: parent.horizontalCenter + } + } + + function login(username, password, permanent){ + Qt.inputMethod.hide(); + busyDialog.open() + loginButton.enabled = false + loginButton.text = "Loggin in.." + console.log(username, password, permanent) + var ret = _cppServerConn.login(username, password, permanent); + busyDialog.close() + loginButton.enabled = true + loginButton.text = "Login" + if(ret === "OK"){ + _cppAppSettings.writeSetting("init", 1); + window.is_error = false; root.StackView.view.push("MainPage.qml") } + else{ + if(_cppAppSettings.loadSetting("permanent") === "1"){ + tiuname.text = _cppAppSettings.loadSetting("username") + tipasswd.text = _cppAppSettings.loadSetting("password") + _cppAppSettings.writeSetting("permanent", "0") + _cppAppSettings.writeSetting("username", "") + _cppAppSettings.writeSetting("password", "") + } + laStatus.text = ret + } + //root.qmlSignal(tiuname.text, tipasswd.text) + } + + Dialog { + id: busyDialog + modal: true + closePolicy: "NoAutoClose" + focus: true + title: "Please wait..." + x: (window.width - width) / 2 + y: window.height / 6 + width: Math.min(window.width, window.height) / 3 * 2 + height: 150 + contentHeight: aboutColumn.height + Column { + id: aboutColumn + spacing: 20 + RowLayout { + width: parent.width + BusyIndicator { + id: busyIndicator + visible: true + x: 22 + y: 38 + } + + Label { + width: busyDialog.availableWidth + text: "logging in..." + wrapMode: Label.Wrap + font.pixelSize: 12 + } + } + } } + } diff --git a/qml/MainPage.qml b/qml/MainPage.qml index c20ef5d..b956d1d 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -4,14 +4,16 @@ import QtQuick.Controls 2.2 Page { id: root anchors.fill: parent - header: ToolBar { + header: AppToolBar { contentHeight: toolButton.implicitHeight ToolButton { id: toolButton - text: stackView.depth > 1 ? "\u25C0" : "\u2630" + text: stackView.depth > 1 ? "\u25C0" : "\u4E09" font.pixelSize: Qt.application.font.pixelSize * 1.6 + onClicked: { + console.log(toolButton.font.styleName) if (stackView.depth > 1) { stackView.pop() } else { @@ -33,21 +35,42 @@ Page { Column { anchors.fill: parent - ItemDelegate { - text: qsTr("page 1") + text: qsTr("Fanny Webseite") width: parent.width onClicked: { - stackView.push("Page1Form.qml") + stackView.push("WebsitePage.qml") drawer.close() } } ItemDelegate { - text: qsTr("Page 2") + text: qsTr("abmelden") width: parent.width onClicked: { - stackView.push("Page2Form.qml") - drawer.close() + confirmationDialog.open() + } + Dialog { + id: confirmationDialog + + x: (window.width - width) / 2 + y: (window.height - height) / 2 + parent: ApplicationWindow.overlay + + + modal: true + standardButtons: Dialog.Cancel | Dialog.Ok + Column { + spacing: 20 + anchors.fill: parent + Label { + text: "Möchtest du dich wirklich abmelden?" + } + } + onAccepted: { + _cppServerConn.logout() + drawer.close() + root.StackView.view.push("LoginPage.qml") + } } } } diff --git a/qml/Page1Form.qml b/qml/Page1Form.qml deleted file mode 100644 index a6e4058..0000000 --- a/qml/Page1Form.qml +++ /dev/null @@ -1,26 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.2 - -Page { - width: 600 - height: 400 - - objectName: "Page1"; - - property string title: "value" - - title: qsTr(title) - - Label { - text: qsTr("You are on Page 1.") - anchors.centerIn: parent - } - BusyIndicator { - id: busyIndicator - visible: true - x: 40 - y: 49 - } - - -} diff --git a/qml/Page2Form.qml b/qml/Page2Form.qml deleted file mode 100644 index dc7a430..0000000 --- a/qml/Page2Form.qml +++ /dev/null @@ -1,38 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.Universal 2.2 - -Page { - width: 600 - height: 400 - - title: qsTr("Page 2") - - Button { - id: butt - text: "test" - width: parent.width - height: 20 - - background: Rectangle{ - id: background - anchors.fill: parent - color: "lightblue" - } - - onReleased: { - background.color = "lightblue" - } - - onPressed: { - background.color = "red" - } - - anchors { - top: parent.top - left: parent.left - leftMargin: window.width / 2 - butt.width / 2 - topMargin: 200 - } - } -} diff --git a/qml/WebsitePage.qml b/qml/WebsitePage.qml new file mode 100644 index 0000000..beaa9b4 --- /dev/null +++ b/qml/WebsitePage.qml @@ -0,0 +1,46 @@ +import QtQuick 2.9 +import QtWebView 1.1 +import QtQuick.Controls 2.2 + +import QtWebView 1.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls.Styles 1.2 + +Page { + id:root + anchors.fill: parent + + objectName: "WebsitePage"; + + title: qsTr("Fanny Webseite") + ProgressBar { + id: progress + width: parent.width + anchors { + top: parent.top + } + //z: Qt.platform.os === "android" ? -1 : 1 + visible: webView.loadProgress < 100 + + value: webView.loadProgress == 100 ? 0 : webView.loadProgress / 100 + } + + WebView { + id: webView + anchors { + top: webView.loadProgress < 100 ? progress.bottom:parent.top + bottom: parent.bottom + left: parent.left + right: parent.right + } + + url: "http://www.fanny-leicht.de/j34" + onLoadingChanged: { + + if (loadRequest.errorString) + console.error(loadRequest.errorString); + } + } + + +} diff --git a/qml/main.qml b/qml/main.qml index 38ef350..06d577a 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -4,12 +4,91 @@ import QtQuick.Controls 2.2 ApplicationWindow { id: window visible: true - width: 640 - height: 480 + width: 540 + height: 960 + + property bool is_error + property string error + + Timer { + //runs only one time at applictaion lauch + id: initTimer + interval: 1; + running: true + repeat: false + onTriggered: { + var perm = _cppAppSettings.loadSetting("permanent") + console.log("checkoldlogin", perm); + if(perm === "1"){ + console.log("Perm") + var ret = _cppServerConn.login(_cppAppSettings.loadSetting("username"), _cppAppSettings.loadSetting("password"), true); + if(ret === "OK"){ + _cppAppSettings.writeSetting("init", 1); + window.is_error = false; + } + else { + ret = _cppServerConn.checkConn() + handleError(ret) + } + } + else { + stackView.push("qrc:/LoginPage.qml") + } + } + } + + Timer { + id: refreshTimer + interval: 1000; + running: true + repeat: true + onTriggered: { + var ret = _cppServerConn.checkConn() + handleError(ret) + } + } StackView { id: stackView - initialItem: "LoginPage.qml" + initialItem: "MainPage.qml" anchors.fill: parent } + + function handleError(error_code){ + if(error_code === 200){ + window.is_error = false; + window.error = ""; + } + else if(error_code === 401){ + _cppAppSettings.writeSetting("permanent", 0) + _cppAppSettings.writeSetting("username", "") + _cppAppSettings.writeSetting("password", "") + if(["LoginPage"].indexOf(stackView.currentItem.objectName) < 0){ + console.log("switching to login page") + stackView.push("qrc:/LoginPage.qml"); + } + window.is_error = true; + window.error = "Nicht angemeldet!!"; + } + else if(error_code === 500){ + window.is_error = true; + window.error = "Interner Server Fehler!"; + } + else if(error_code === 0){ + window.is_error = true; + window.error = "Keine Verbindung zum Server!"; + } + else if(error_code === 404){ + //the testcon function calls a non existent file to be fast, so no error here + window.is_error = false; + } + else if(error_code === 111){ + window.is_error = true; + window.error = "Unbekannter interner Fehler!"; + } + else { + window.is_error = true; + window.error = "Unbekannter Fehler! ("+error_code+")"; + } + } } diff --git a/qml/qml.qrc b/qml/qml.qrc index d0628c8..00fae0f 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -2,10 +2,10 @@ main.qml HomeForm.qml - Page1Form.qml - Page2Form.qml qtquickcontrols2.conf LoginPage.qml MainPage.qml + AppToolBar.qml + WebsitePage.qml diff --git a/shared.qrc b/shared.qrc new file mode 100644 index 0000000..e6c696a --- /dev/null +++ b/shared.qrc @@ -0,0 +1,7 @@ + + + favicon.png + graphics/sheute.png + graphics/smorgen.png + + diff --git a/source/appsettings.cpp b/source/appsettings.cpp new file mode 100644 index 0000000..eefda45 --- /dev/null +++ b/source/appsettings.cpp @@ -0,0 +1,37 @@ +#include "headers/appsettings.h" + +AppSettings * pGlobalAppSettings = NULL; + +AppSettings::AppSettings(QObject* parent) + :QObject(parent) +{ + QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + qDebug(path.toLatin1()); + this->settingsManager = new QSettings(path+"/fannyapp/settings.ini", QSettings::IniFormat); + + qDebug("AppSettings konstruktor"); + if(loadSetting("init") == "false"){ + this->writeSetting("init", 0); + } +} + +QString AppSettings::loadSetting(const QString &key) +{ + this->settingsManager->beginGroup("AppSettings"); + QString value = this->settingsManager->value(key , false).toString(); + this->settingsManager->endGroup(); + return(value); +} + +void AppSettings::writeSetting(const QString &key, const QVariant &variant) +{ + this->settingsManager->beginGroup("AppSettings"); + this->settingsManager->setValue(key , variant); + this->settingsManager->endGroup(); +} + +AppSettings::~AppSettings() +{ + delete settingsManager; +} + diff --git a/source/main.cpp b/source/main.cpp index 5949a06..370c017 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,26 +2,41 @@ #include #include #include +#include #include #include #include #include +#include +#include -#include "serverconn.h" +#include "headers/serverconn.h" +#include "headers/appsettings.h" int main(int argc, char *argv[]) { ServerConn * pServerConn = new ServerConn; + AppSettings * pAppSettings = new AppSettings(); + pGlobalAppSettings = pAppSettings; + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); + QQuickStyle::setStyle("Material"); + QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; engine.rootContext()->setContextProperty("_cppServerConn", pServerConn); + engine.rootContext()->setContextProperty("_cppAppSettings", pAppSettings); - return app.exec(); + int ret; + ret = app.exec(); + + delete pServerConn; + delete pAppSettings; + return(ret); } diff --git a/source/serverconn.cpp b/source/serverconn.cpp index 593fc2c..d5d6934 100644 --- a/source/serverconn.cpp +++ b/source/serverconn.cpp @@ -1,14 +1,25 @@ -#include "serverconn.h" +#include "headers/serverconn.h" ServerConn::ServerConn(QObject *parent) : QObject(parent) { qDebug("serverconn konstruktor"); this->networkManager = new QNetworkAccessManager(); - - + this->refreshNetworkManager = new QNetworkAccessManager(); } -QString ServerConn::login() +ServerConn::~ServerConn() +{ + qDebug("serverconn destruktor"); + delete this->networkManager; + delete this->refreshNetworkManager; + + QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + QDir dir(path + "/.fannyapp-tmp"); + dir.removeRecursively(); +} + + +QString ServerConn::login(QString username, QString password, bool permanent) { // QUrlQuery pdata; // ReturnData_t ret = this->senddata(QUrl("http://www.fanny-leicht.de/static15/http.intern/sheute.pdf"), pdata); @@ -19,16 +30,136 @@ QString ServerConn::login() request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/sheute.pdf" ) ); // Pack in credentials - QString concatenatedCredentials = "ZedlerDo:LxyJQB"; - QByteArray data = concatenatedCredentials.toLocal8Bit().toBase64(); - QString headerData = "Basic " + data; - request.setRawHeader( "Authorization", headerData.toLocal8Bit() ); + QString concatenatedCredentials = username + ":" + 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()); - qDebug() << QString::fromUtf8(reply->readAll()); + //QNetworkReply*reply = networkManager->get( request ); + + QEventLoop loop; + loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); + loop.exec(); + int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if(status_code == 200){ + this->username = username; + this->password = password; + if(permanent){ + pGlobalAppSettings->writeSetting("permanent", "1"); + pGlobalAppSettings->writeSetting("username", username); + pGlobalAppSettings->writeSetting("password", password); + } + return("OK"); + } + 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); + } } +int ServerConn::logout() +{ + this->username = ""; + this->password = ""; + pGlobalAppSettings->writeSetting("permanent", "0"); + pGlobalAppSettings->writeSetting("username", ""); + pGlobalAppSettings->writeSetting("password", ""); + +} + +QString ServerConn::getDay(QString day) +{ + qDebug("getting file of day"); + // Create request + QNetworkRequest request; + request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/" + day + ".pdf" ) ); + + // Pack in credentials + // 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 ); + + QEventLoop loop; + loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); + loop.exec(); + + int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if(status_code == 200){ + qDebug("OK"); + QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + QDir dir; + dir.mkdir(path + "/.fannyapp-tmp"); + QFile file(path + "/.fannyapp-tmp/" + day + ".pdf"); + + file.open(QIODevice::ReadWrite); + file.write(reply->readAll()); + file.close(); + + QDesktopServices::openUrl(QUrl::fromLocalFile(path + "/.fannyapp-tmp/" + day + ".pdf")); + qDebug() << QString::fromUtf8(reply->readAll()); + qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); + return("OK"); + } + 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); + } +} + +int ServerConn::checkConn() +{ + // Create request + QNetworkRequest request; + request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/" ) ); + + // Pack in credentials + // Pack in credentials + //ZedlerDo:LxyJQB + 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->refreshNetworkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8()); + //QNetworkReply*reply = networkManager->get( request ); + + QEventLoop loop; + loop.connect(this->refreshNetworkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); + loop.exec(); + + int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + return(status_code); + +} + + ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata) {