2018-06-21 08:47:09 +02:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
|
|
|
|
ApplicationWindow {
|
|
|
|
id: window
|
|
|
|
visible: true
|
2018-06-21 16:41:02 +02:00
|
|
|
width: 540
|
|
|
|
height: 960
|
|
|
|
|
|
|
|
property bool is_error
|
|
|
|
property string error
|
2018-06-25 00:15:18 +02:00
|
|
|
property bool initdone: false
|
2018-06-25 08:07:05 +02:00
|
|
|
property bool firstinitdone: false
|
|
|
|
|
2018-06-27 20:26:02 +02:00
|
|
|
property string text_color: "black" //"#424753"
|
|
|
|
property string background_color: "white"
|
|
|
|
property string toolbar_color: "#312f38"
|
|
|
|
|
2018-07-06 13:29:16 +02:00
|
|
|
// onBeforeRendering: {
|
|
|
|
// if(!firstinitdone){
|
|
|
|
// var isinit = _cppAppSettings.loadSetting("init")
|
|
|
|
// console.log("getinit");
|
|
|
|
// console.log(isinit);
|
|
|
|
// if(isinit === "0"){
|
|
|
|
// stackView.push("qrc:/LoginPage.qml", {});
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// firstinitdone = true
|
|
|
|
// }
|
2018-06-21 16:41:02 +02:00
|
|
|
|
|
|
|
Timer {
|
|
|
|
//runs only one time at applictaion lauch
|
2018-06-25 08:07:05 +02:00
|
|
|
property bool finished: true
|
2018-06-21 16:41:02 +02:00
|
|
|
id: initTimer
|
2018-07-06 13:29:16 +02:00
|
|
|
interval: 1;
|
2018-06-25 08:07:05 +02:00
|
|
|
running: initdone === false
|
|
|
|
repeat: finished
|
2018-06-21 16:41:02 +02:00
|
|
|
onTriggered: {
|
2018-06-25 08:07:05 +02:00
|
|
|
finished = false
|
2018-06-25 00:15:18 +02:00
|
|
|
var init = _cppAppSettings.loadSetting("init")
|
|
|
|
|
2018-06-21 16:41:02 +02:00
|
|
|
var perm = _cppAppSettings.loadSetting("permanent")
|
2018-06-25 10:04:11 +02:00
|
|
|
console.log("checkoldlogin:", perm);
|
2018-06-21 16:41:02 +02:00
|
|
|
if(perm === "1"){
|
|
|
|
console.log("Perm")
|
|
|
|
var ret = _cppServerConn.login(_cppAppSettings.loadSetting("username"), _cppAppSettings.loadSetting("password"), true);
|
|
|
|
if(ret === "OK"){
|
2018-07-06 13:29:16 +02:00
|
|
|
initdone = true
|
2018-06-21 16:41:02 +02:00
|
|
|
_cppAppSettings.writeSetting("init", 1);
|
2018-06-25 08:07:05 +02:00
|
|
|
if(stackView.currentItem.objectName !== "MainPage"){
|
|
|
|
stackView.push("qrc:/MainPage.qml", {});
|
|
|
|
}
|
2018-06-21 16:41:02 +02:00
|
|
|
window.is_error = false;
|
|
|
|
}
|
2018-06-25 00:15:18 +02:00
|
|
|
else if(ret === "Keine Verbindung zum Server."){
|
|
|
|
handleError(0)
|
2018-06-25 08:07:05 +02:00
|
|
|
//initTimer.interval = 1000
|
|
|
|
finished = true
|
2018-06-25 00:15:18 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-21 16:41:02 +02:00
|
|
|
else {
|
|
|
|
ret = _cppServerConn.checkConn()
|
|
|
|
handleError(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-07-06 13:29:16 +02:00
|
|
|
initdone = false
|
|
|
|
if(stackView.currentItem.objectName !== "LoginPage"){
|
|
|
|
stackView.push("qrc:/LoginPage.qml")
|
|
|
|
}
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
2018-06-25 08:07:05 +02:00
|
|
|
finished = true
|
2018-06-25 00:15:18 +02:00
|
|
|
initdone = true
|
2018-06-21 16:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: refreshTimer
|
|
|
|
interval: 1000;
|
2018-06-25 00:15:18 +02:00
|
|
|
running: initdone
|
2018-06-21 16:41:02 +02:00
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
2018-07-06 13:29:16 +02:00
|
|
|
console.log("refresh")
|
2018-06-21 16:41:02 +02:00
|
|
|
var ret = _cppServerConn.checkConn()
|
|
|
|
handleError(ret)
|
|
|
|
}
|
|
|
|
}
|
2018-06-21 08:47:09 +02:00
|
|
|
|
|
|
|
StackView {
|
|
|
|
id: stackView
|
2018-06-21 16:41:02 +02:00
|
|
|
initialItem: "MainPage.qml"
|
2018-06-21 08:47:09 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
}
|
2018-06-21 16:41:02 +02:00
|
|
|
|
|
|
|
function handleError(error_code){
|
|
|
|
if(error_code === 200){
|
|
|
|
window.is_error = false;
|
|
|
|
window.error = "";
|
|
|
|
}
|
|
|
|
else if(error_code === 401){
|
2018-06-25 00:15:18 +02:00
|
|
|
console.warn("401")
|
2018-06-21 16:41:02 +02:00
|
|
|
_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+")";
|
|
|
|
}
|
|
|
|
}
|
2018-06-21 08:47:09 +02:00
|
|
|
}
|