2018-06-21 08:47:09 +02:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
import "./Components"
|
|
|
|
import "./Forms"
|
|
|
|
import "./Pages"
|
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
ApplicationWindow {
|
|
|
|
id: window
|
|
|
|
visible: true
|
2018-06-21 16:41:02 +02:00
|
|
|
width: 540
|
|
|
|
height: 960
|
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
Item {
|
|
|
|
id: app
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
property bool is_error
|
|
|
|
property string error
|
|
|
|
property bool initdone: false
|
|
|
|
property bool firstinitdone: false
|
|
|
|
|
|
|
|
property string text_color: "black" //"#424753"
|
|
|
|
property string background_color: "white"
|
|
|
|
property string toolbar_color: "#312f38"
|
|
|
|
|
2018-12-21 23:56:10 +01:00
|
|
|
state: "loggedIn"
|
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "notLoggedIn"
|
|
|
|
PropertyChanges {
|
|
|
|
target: mainStack
|
|
|
|
currPage: loginPage
|
2018-06-25 00:15:18 +02:00
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
},
|
2018-06-25 00:15:18 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
State {
|
|
|
|
name: "loggedIn"
|
|
|
|
PropertyChanges {
|
|
|
|
target: mainStack
|
|
|
|
currPage: mainPage
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
// onBeforeRendering: {
|
|
|
|
// if(!firstinitdone){
|
|
|
|
// var isinit = _cppAppSettings.loadSetting("permanent")
|
|
|
|
// console.log("getinit");
|
|
|
|
// console.log(isinit);
|
|
|
|
// if(isinit === "0"){
|
|
|
|
// stackView.push("qrc:/LoginPage.qml", {});
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// firstinitdone = true
|
|
|
|
// }
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
//runs only one time at applictaion lauch
|
|
|
|
property bool finished: true
|
|
|
|
id: initTimer
|
|
|
|
interval: 1;
|
|
|
|
running: true
|
|
|
|
repeat: false
|
|
|
|
onTriggered: {
|
|
|
|
var init = _cppAppSettings.loadSetting("init")
|
|
|
|
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"){
|
2018-12-21 23:56:10 +01:00
|
|
|
app.initdone = true
|
2018-12-21 12:23:12 +01:00
|
|
|
_cppAppSettings.writeSetting("init", 1);
|
|
|
|
if(app.state !== "loggedIn"){
|
|
|
|
app.state = "loggedIn"
|
|
|
|
}
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = false;
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else if(ret === "Keine Verbindung zum Server."){
|
|
|
|
handleError(0)
|
|
|
|
//initTimer.interval = 1000
|
|
|
|
finished = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
ret = _cppServerConn.checkConn()
|
|
|
|
handleError(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
app.initdone = false
|
|
|
|
if(app.state !== "notLoggedIn"){
|
|
|
|
app.state = "notLoggedIn"
|
|
|
|
}
|
2018-07-06 13:29:16 +02:00
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
app.initdone = true
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
Timer {
|
|
|
|
id: refreshTimer
|
|
|
|
interval: 1000;
|
2018-12-21 23:56:10 +01:00
|
|
|
running: app.initdone && app.state !== "notLoggedIn"
|
2018-12-21 12:23:12 +01:00
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
|
|
|
var ret = _cppServerConn.checkConn()
|
2018-12-21 23:56:10 +01:00
|
|
|
app.handleError(ret)
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
2018-06-21 08:47:09 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
StackView {
|
|
|
|
id: mainStack
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
property var currPage
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
onCurrPageChanged: {
|
|
|
|
mainStack.replace(currPage)
|
|
|
|
}
|
|
|
|
|
2018-12-21 23:56:10 +01:00
|
|
|
//initialItem: mainPage
|
2018-12-21 12:23:12 +01:00
|
|
|
|
|
|
|
Component {
|
|
|
|
id: loginPage
|
|
|
|
LoginPage {}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: mainPage
|
|
|
|
MainPage {}
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
|
|
|
|
function handleError(error_code){
|
|
|
|
if(error_code === 200){
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = false;
|
|
|
|
app.error = "";
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else if(error_code === 401){
|
|
|
|
console.warn("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("./Pages/LoginPage.qml");
|
|
|
|
}
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = true;
|
|
|
|
app.error = "Nicht angemeldet!!";
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else if(error_code === 500){
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = true;
|
|
|
|
app.error = "Interner Server Fehler!";
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else if(error_code === 0){
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = true;
|
|
|
|
app.error = "Keine Verbindung zum Server!";
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else if(error_code === 404){
|
|
|
|
//the testcon function calls a non existent file to be fast, so no error here
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = false;
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else if(error_code === 111){
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = true;
|
|
|
|
app.error = "Unbekannter interner Fehler!";
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-12-21 23:56:10 +01:00
|
|
|
app.is_error = true;
|
|
|
|
app.error = "Unbekannter Fehler! ("+error_code+")";
|
2018-12-21 12:23:12 +01:00
|
|
|
}
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
2018-06-21 08:47:09 +02:00
|
|
|
}
|