- finished up event filter
- started to move the login management from qml to cpp
This commit is contained in:
parent
4af8ba030e
commit
4271bec598
10 changed files with 153 additions and 104 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QtXml>
|
||||
#include <QTimer>
|
||||
|
||||
#include <QtNetwork>
|
||||
#include <QAuthenticator>
|
||||
|
@ -26,16 +27,28 @@ typedef struct strReturnData{
|
|||
class ServerConn : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString state READ getState WRITE setState NOTIFY stateChanged)
|
||||
|
||||
public:
|
||||
private:
|
||||
QString state;
|
||||
// can be: loggedIn ; notLoggedIn
|
||||
QString username;
|
||||
QString password;
|
||||
QNetworkAccessManager *networkManager;
|
||||
QNetworkAccessManager *refreshNetworkManager;
|
||||
QTimer *checkConnTimer;
|
||||
float progress;
|
||||
public:
|
||||
int authErrorCount;
|
||||
|
||||
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
|
||||
void updateProgress(qint64 read, qint64 total);
|
||||
|
||||
void setState(QString state);
|
||||
|
||||
public slots:
|
||||
explicit ServerConn(QObject *parent = nullptr);
|
||||
~ServerConn();
|
||||
|
||||
Q_INVOKABLE int login(QString username, QString password, bool permanent);
|
||||
Q_INVOKABLE int logout();
|
||||
Q_INVOKABLE QString getDay(QString day);
|
||||
|
@ -43,15 +56,16 @@ public:
|
|||
Q_INVOKABLE float getProgress();
|
||||
Q_INVOKABLE int getFoodPlan();
|
||||
Q_INVOKABLE int getEvents(QString day);
|
||||
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
|
||||
|
||||
Q_INVOKABLE QString getState();
|
||||
|
||||
signals:
|
||||
void stateChanged();
|
||||
|
||||
public:
|
||||
QList<QList<QString>> m_weekplan;
|
||||
QList<QStringList> m_events;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE void updateProgress(qint64 read, qint64 total);
|
||||
|
||||
};
|
||||
extern ServerConn * pGlobalServConn;
|
||||
|
|
|
@ -5,16 +5,18 @@ Item {
|
|||
id: infoArea
|
||||
|
||||
property int alertLevel: app.getErrorInfo(infoArea.errorCode)[0]
|
||||
// 0 - ok
|
||||
// 1 - info
|
||||
// 2 - error
|
||||
property int errorCode: -1
|
||||
property var excludedCodes: []
|
||||
|
||||
visible: !(excludedCodes.indexOf(errorCode) >= 0)
|
||||
|
||||
height: childrenRect.height
|
||||
|
||||
Rectangle {
|
||||
|
||||
// 0 - ok
|
||||
// 1 - info
|
||||
// 2 - error
|
||||
|
||||
radius: height * 0.5
|
||||
width: parent.width
|
||||
height: width
|
||||
|
@ -45,7 +47,14 @@ Item {
|
|||
top: parent.bottom
|
||||
margins: parent.height * 0.1
|
||||
}
|
||||
font.pixelSize: errorLongDescription.font.pixelSize * 2
|
||||
|
||||
width: app.width * 0.8
|
||||
|
||||
wrapMode: Label.Wrap
|
||||
|
||||
horizontalAlignment: Label.AlignHCenter
|
||||
|
||||
font.pixelSize: errorLongDescription.font.pixelSize * 1.8
|
||||
text: app.getErrorInfo(infoArea.errorCode)[1]
|
||||
}
|
||||
|
||||
|
@ -57,7 +66,7 @@ Item {
|
|||
margins: parent.height * 0.1
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
width: app.width * 0.8
|
||||
|
||||
wrapMode: Label.Wrap
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ ItemDelegate {
|
|||
leftMargin: 10
|
||||
}
|
||||
|
||||
width: parent.width - 10 - forwardIcon.width - 10
|
||||
width: parent.width * 0.9
|
||||
|
||||
wrapMode: Label.Wrap
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@ Page {
|
|||
|
||||
onOpened: {
|
||||
console.log("Filter Form opened")
|
||||
|
||||
var filters = _cppAppSettings.readFiltersQml()
|
||||
}
|
||||
|
||||
Dialog {
|
||||
|
@ -104,8 +102,14 @@ Page {
|
|||
id: delegate
|
||||
|
||||
width: contactView.width
|
||||
height: 0
|
||||
|
||||
Component.onCompleted: {
|
||||
delegate.height = 50
|
||||
}
|
||||
|
||||
text: grade + classLetter
|
||||
font.pixelSize: height * 0.4
|
||||
|
||||
Rectangle {
|
||||
|
||||
|
@ -121,6 +125,29 @@ Page {
|
|||
color: "lightgrey"
|
||||
}
|
||||
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
duration: 500
|
||||
easing.type: Easing.InOutQuad
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NumberAnimation {
|
||||
id: deleteAnimation
|
||||
target: delegate
|
||||
property: "height"
|
||||
duration: 500
|
||||
from: delegate.height
|
||||
to: 0
|
||||
easing.type: Easing.InOutQuad
|
||||
onRunningChanged: {
|
||||
if(!running){
|
||||
contactView.model.remove(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: deleteButton
|
||||
|
||||
|
@ -136,7 +163,7 @@ Page {
|
|||
scale: pressed ? 0.8:1
|
||||
|
||||
onClicked: {
|
||||
contactView.model.remove(index)
|
||||
deleteAnimation.start()
|
||||
}
|
||||
|
||||
background: Image {
|
||||
|
@ -185,38 +212,4 @@ Page {
|
|||
text: "+"
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ListView {
|
||||
function getModel() {
|
||||
// convert the filter list into an object
|
||||
var keys = Object.keys(_cppAppSettings.readFiltersQml());
|
||||
// get he lenght
|
||||
var len = keys.length
|
||||
// return the lenght
|
||||
return(len)
|
||||
}
|
||||
|
||||
function getDetails(index) {
|
||||
var ret = _cppAppSettings.readFiltersQml()[index]
|
||||
var details = ret.split("|")
|
||||
return(details)
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
filterList.model = filterList.getModel()
|
||||
}
|
||||
|
||||
id: filterList
|
||||
anchors.fill: parent
|
||||
property string title: qsTr("connections")
|
||||
property int delegateHeight: height*0.18
|
||||
model: getModel()
|
||||
delegate: ItemDelegate {
|
||||
width: parent.width
|
||||
height: filterList.delegateHeight
|
||||
text: filterList.getDetails(index)[0] + filterList.getDetails(index)[1]
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ Page {
|
|||
topMargin: parent.height/2 - height * 0.8
|
||||
}
|
||||
|
||||
excludedCodes: [200, 902]
|
||||
errorCode: status
|
||||
}
|
||||
}
|
||||
|
|
46
qml/main.qml
46
qml/main.qml
|
@ -1,6 +1,8 @@
|
|||
import QtQuick 2.9
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
import Backend 1.0
|
||||
|
||||
import "./Components"
|
||||
import "./Forms"
|
||||
import "./Pages"
|
||||
|
@ -21,7 +23,7 @@ ApplicationWindow {
|
|||
property bool initdone: false
|
||||
property bool firstinitdone: false
|
||||
|
||||
property string text_color: "black" //"#424753"
|
||||
property string text_color: "black" // "#424753"
|
||||
property string background_color: "white"
|
||||
property string toolbar_color: "#312f38"
|
||||
|
||||
|
@ -45,6 +47,10 @@ ApplicationWindow {
|
|||
}
|
||||
]
|
||||
|
||||
ServerConn {
|
||||
id: serverConn
|
||||
}
|
||||
|
||||
// onBeforeRendering: {
|
||||
// if(!firstinitdone){
|
||||
// var isinit = _cppAppSettings.loadSetting("permanent")
|
||||
|
@ -137,15 +143,8 @@ ApplicationWindow {
|
|||
}
|
||||
|
||||
function handleError(error_code){
|
||||
if(error_code === 200){
|
||||
app.is_error = false;
|
||||
app.error = "";
|
||||
}
|
||||
else if(error_code === 401){
|
||||
if(error_code === 401){
|
||||
console.warn("401")
|
||||
_cppAppSettings.writeSetting("permanent", 0)
|
||||
_cppAppSettings.writeSetting("username", "")
|
||||
_cppAppSettings.writeSetting("password", "")
|
||||
if(app.state !== "notLoggedIn"){
|
||||
console.log("switching to login page")
|
||||
app.state = "notLoggedIn"
|
||||
|
@ -153,31 +152,15 @@ ApplicationWindow {
|
|||
app.is_error = true;
|
||||
app.error = "Nicht angemeldet!!";
|
||||
}
|
||||
else if(error_code === 500){
|
||||
app.is_error = true;
|
||||
app.error = "Interner Server Fehler!";
|
||||
}
|
||||
else if(error_code === 0){
|
||||
app.is_error = true;
|
||||
app.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
|
||||
app.is_error = false;
|
||||
}
|
||||
else if(error_code === 111){
|
||||
app.is_error = true;
|
||||
app.error = "Unbekannter interner Fehler!";
|
||||
}
|
||||
else {
|
||||
app.is_error = true;
|
||||
app.error = "Unbekannter Fehler! ("+error_code+")";
|
||||
}
|
||||
}
|
||||
|
||||
function getErrorInfo(errorCode) {
|
||||
|
||||
var infoLevel
|
||||
// 0 - ok
|
||||
// 1 - info
|
||||
// 2 - error
|
||||
|
||||
var errorString
|
||||
var errorDescription
|
||||
|
||||
|
@ -207,6 +190,11 @@ ApplicationWindow {
|
|||
errorString = "Keine Daten"
|
||||
errorDescription = "Es liegen keine aktuellen Daten vor."
|
||||
break
|
||||
case 902:
|
||||
infoLevel = 1
|
||||
errorString = "Alte Daten"
|
||||
errorDescription = "Es konnte keine Verbindung zum Server hergestellt werden, aber es sind noch alte Daten gespeichert."
|
||||
break
|
||||
default:
|
||||
infoLevel = 2
|
||||
errorString = "Unerwarteter Fehler ("+errorCode+")"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
5b 1 Hei D --- Entfall
|
||||
b5b 1 Hei D --- Entfall
|
||||
5b 2 Fu D 114 Hei / Aufgaben, Arbeitsheft!
|
||||
5b 3 Oe M 114 Ei / Aufgaben
|
||||
5b 4 Rm M 114 Ei / Aufgaben
|
||||
|
|
|
@ -7,6 +7,8 @@ AppSettings::AppSettings(QObject* parent)
|
|||
{
|
||||
qDebug("+----- AppSettings konstruktor -----");
|
||||
|
||||
pGlobalAppSettings = this;
|
||||
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
qDebug() << "+----- Settings Path:" << path;
|
||||
|
||||
|
|
|
@ -22,10 +22,7 @@
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppSettings * pAppSettings = new AppSettings();
|
||||
pGlobalAppSettings = pAppSettings;
|
||||
ServerConn * pServerConn = new ServerConn();
|
||||
//pGlobalServConn = pServerConn;
|
||||
|
||||
// ServerConn * pServerConn = new ServerConn();
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
|
||||
|
@ -34,13 +31,14 @@ int main(int argc, char *argv[])
|
|||
qmlRegisterType<FoodPlanModel>("Backend", 1, 0, "FoodPlanModel");
|
||||
qmlRegisterType<EventModel>("Backend", 1, 0, "EventModel");
|
||||
qmlRegisterType<FilterModel>("Backend", 1, 0, "FilterModel");
|
||||
qmlRegisterType<ServerConn>("Backend", 1, 0, "ServerConn");
|
||||
|
||||
QQuickStyle::setStyle("Material");
|
||||
QQmlApplicationEngine engine;
|
||||
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||
QQmlContext *context = engine.rootContext();
|
||||
|
||||
context->setContextProperty("_cppServerConn", pServerConn);
|
||||
// context->setContextProperty("_cppServerConn", pServerConn);
|
||||
context->setContextProperty("_cppAppSettings", pAppSettings);
|
||||
if (engine.rootObjects().isEmpty())
|
||||
return -1;
|
||||
|
@ -48,7 +46,7 @@ int main(int argc, char *argv[])
|
|||
int ret;
|
||||
ret = app.exec();
|
||||
|
||||
delete pServerConn;
|
||||
// delete pServerConn;
|
||||
delete pAppSettings;
|
||||
return(ret);
|
||||
}
|
||||
|
|
|
@ -5,20 +5,17 @@ ServerConn * pGlobalServConn = nullptr;
|
|||
ServerConn::ServerConn(QObject *parent) : QObject(parent)
|
||||
{
|
||||
qDebug("serverconn konstruktor");
|
||||
pGlobalServConn = this;
|
||||
this->networkManager = new QNetworkAccessManager();
|
||||
this->refreshNetworkManager = new QNetworkAccessManager();
|
||||
pGlobalServConn = this;
|
||||
}
|
||||
|
||||
ServerConn::~ServerConn()
|
||||
{
|
||||
qDebug("serverconn destruktor");
|
||||
delete this->networkManager;
|
||||
delete this->refreshNetworkManager;
|
||||
this->checkConnTimer = new QTimer();
|
||||
this->checkConnTimer->setInterval(1000);
|
||||
this->checkConnTimer->setSingleShot(true);
|
||||
this->checkConnTimer->start();
|
||||
|
||||
connect(this->checkConnTimer, &QTimer::timeout, this, &ServerConn::checkConn);
|
||||
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
QDir dir(path + "/.fannyapp-tmp");
|
||||
dir.removeRecursively();
|
||||
}
|
||||
|
||||
int ServerConn::login(QString username, QString password, bool permanent)
|
||||
|
@ -170,11 +167,25 @@ int ServerConn::checkConn()
|
|||
QNetworkReply*reply = this->refreshNetworkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
||||
//QNetworkReply*reply = networkManager->get( request );
|
||||
|
||||
QTimer timer;
|
||||
timer.start(3000);
|
||||
|
||||
QEventLoop loop;
|
||||
loop.connect(this->refreshNetworkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
||||
loop.connect(&timer, SLOT(timeout()), SLOT(quit()));
|
||||
loop.exec();
|
||||
|
||||
int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
if(status_code == 401){
|
||||
authErrorCount ++;
|
||||
|
||||
if(authErrorCount > 3){
|
||||
logout();
|
||||
}
|
||||
}
|
||||
|
||||
this->checkConnTimer->start();
|
||||
return(status_code);
|
||||
}
|
||||
|
||||
|
@ -314,14 +325,20 @@ int ServerConn::getEvents(QString day){
|
|||
}
|
||||
|
||||
// if the event matches the filter
|
||||
foreach(QStringList filter, pGlobalAppSettings->readFilters()){
|
||||
// go through all filters and check if one of them matches the event
|
||||
QList<QStringList> filtersList = pGlobalAppSettings->readFilters();
|
||||
if(filtersList.isEmpty()){
|
||||
tmpEvents.append(dayList);
|
||||
}
|
||||
else {
|
||||
foreach(QStringList filter, filtersList){
|
||||
// go through all filters and check if one of them matches the event
|
||||
|
||||
if(dayList[0].contains(filter[0]) && dayList[0].contains(filter[1])){
|
||||
// append the dayList to the temporary event list
|
||||
tmpEvents.append(dayList);
|
||||
// terminate the loop
|
||||
break;
|
||||
if((dayList[0].contains(filter[0]) && dayList[0].contains(filter[1]))){
|
||||
// append the dayList to the temporary event list
|
||||
tmpEvents.append(dayList);
|
||||
// terminate the loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -492,6 +509,13 @@ int ServerConn::getFoodPlan()
|
|||
this->progress = 1;
|
||||
if(status_code != 200){
|
||||
// if the request didn't result in a success, return the error code
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
return(status_code.toInt());
|
||||
}
|
||||
|
||||
|
@ -712,3 +736,23 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
|
|||
//return the data
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
QString ServerConn::getState() {
|
||||
return(this->state);
|
||||
}
|
||||
|
||||
void ServerConn::setState(QString state) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
ServerConn::~ServerConn()
|
||||
{
|
||||
qDebug("serverconn destruktor");
|
||||
delete this->networkManager;
|
||||
delete this->refreshNetworkManager;
|
||||
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
QDir dir(path + "/.fannyapp-tmp");
|
||||
dir.removeRecursively();
|
||||
}
|
||||
|
|
Reference in a new issue