- changed 'changed style' button to 'dark mode' switch

- fixed bug that made a 'no connection' error appear, even if there was a connection to the server
This commit is contained in:
Dorian Zedler 2019-03-13 20:07:54 +01:00
parent b16937a73c
commit 721da8c178
6 changed files with 113 additions and 17 deletions

View file

@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## unreleased
### Hinzugefügt
- Dunkler Modus
- ssl (https) Verschlüsselung
### Behoben
- Fehler, der dafür sorgte, dass fälschlicherweise 'keine Verbindung zum server' angezeigt wurde
### Geändert
- timeout auf 10 sekunden erhöht
## [1.0.1]
### Behoben
- Fehler, der dafür sorgte, dass die 'morgen' Taste immer den heutigen Vertretungsplan anzeigte

View file

@ -26,6 +26,7 @@ signals:
public slots:
QVariant getStyle();
Q_INVOKABLE void changeTheme();
Q_INVOKABLE void refreshTheme();
};
#endif // APPSTYLE_H

View file

@ -52,9 +52,7 @@ private:
// can be: loggedIn ; notLoggedIn
QString username;
QString password;
QNetworkAccessManager *networkManager;
QNetworkAccessManager *refreshNetworkManager;
QNetworkReply *networkReply;
QTimer *checkConnTimer;
int authErrorCount;

View file

@ -128,13 +128,85 @@ Page {
}
}
SettingsDelegate {
showForwardIcon: false
title: "Design ändern"
description: "Ändere das Design der App"
SwitchDelegate {
width: parent.width
onClicked: {
app.style.changeTheme()
height: 10 + shortDescription_.height + 2 + longDescription_.height + 10
checked: _cppAppSettings.loadSetting("theme") === "Dark"
onCheckedChanged: {
_cppAppSettings.writeSetting("theme", checked ? "Dark":"Light")
app.style.refreshTheme()
}
Label {
id: shortDescription_
anchors {
top: parent.top
left: parent.left
margins: 10
}
font.pixelSize: longDescription_.font.pixelSize * 1.4
text: "Dunkler Modus"
color: app.style.style.textColor
}
Label {
id: longDescription_
anchors {
top: shortDescription_.bottom
topMargin: 2
left: parent.left
leftMargin: 10
}
width: parent.width * 0.9
wrapMode: Label.Wrap
text: "Dunklen Modus aktivieren"
color: app.style.style.textColor
}
indicator: Rectangle {
property bool checked: parent.checked
property bool down: parent.down
property int set_height: parent.font.pixelSize * 1.4
implicitWidth: set_height * 1.84
implicitHeight: set_height
x: parent.width - width - parent.rightPadding
y: parent.height / 2 - height / 2
radius: implicitHeight * 0.5
color: parent.checked ? "#17a81a" : "transparent"
border.color: parent.checked ? "#17a81a" : "#cccccc"
Behavior on color{
ColorAnimation{
duration: 200
}
}
Rectangle {
x: parent.checked ? parent.width - width : 0
width: parent.height
height: parent.height
radius: height * 0.5
color: parent.down ? "#cccccc" : "#ffffff"
border.color: parent.checked ? (parent.down ? "#17a81a" : "#21be2b") : "#999999"
Behavior on x{
NumberAnimation {
property: "x"
duration: 200
easing.type: Easing.InOutQuad
}
}
}
}
}

View file

@ -108,3 +108,16 @@ void AppStyle::changeTheme() {
emit this->styleChanged();
}
void AppStyle::refreshTheme() {
QString currentThemeString = pGlobalAppSettings->loadSetting("theme");
if(currentThemeString == "Light"){
this->currentTheme = &this->lightTheme;
}
else if (currentThemeString == "Dark") {
this->currentTheme = &this->darkTheme;
}
emit this->styleChanged();
}

View file

@ -25,8 +25,6 @@ ServerConn::ServerConn(QObject *parent) : QObject(parent)
{
qDebug("+----- ServerConn konstruktor -----+");
pGlobalServConn = this;
this->networkManager = new QNetworkAccessManager();
this->refreshNetworkManager = new QNetworkAccessManager();
// check login state
int perm = pGlobalAppSettings->loadSetting("permanent").toInt();
@ -195,7 +193,7 @@ int ServerConn::getEvents(QString day)
int versionMajor = version.split(".")[0].toInt();
int versionMinor = version.split(".")[1].toInt();
int versionRevision = version.split(".")[2].toInt();
//int versionRevision = version.split(".")[2].toInt();
if(versionMajor > this->apiVersion[0] || versionMinor > this->apiVersion[1]){
return(904);
@ -362,6 +360,8 @@ int ServerConn::getFoodPlan()
ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
{
QNetworkAccessManager * networkManager = new QNetworkAccessManager();
ReturnData_t ret; //this is a custom type to store the return-data
// Create network request
@ -377,7 +377,7 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
QNetworkReply *reply;
reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
reply = networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
connect(reply, &QNetworkReply::sslErrors, this, [=](){ reply->ignoreSslErrors(); });
// loop to wait until the request has finished before processing the data
QEventLoop loop;
@ -386,11 +386,11 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
timer.setSingleShot(true);
// quit the loop when the request finised
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
loop.connect(networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
// or the timer timed out
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
// start the timer
timer.start(6000);
timer.start(10000);
// start the loop
loop.exec();
@ -405,6 +405,9 @@ ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)
// delete the reply object
delete reply;
// delete the newtwork access manager object
delete networkManager;
//return the data
return(ret);
}
@ -425,6 +428,4 @@ void ServerConn::setState(QString state) {
ServerConn::~ServerConn()
{
qDebug("+----- ServerConn destruktor -----+");
delete this->networkManager;
delete this->refreshNetworkManager;
}