- commented code

- added settingsForm basic grade filter for the events
This commit is contained in:
Dorian Zedler 2018-12-25 00:15:25 +01:00
parent 7f127b0feb
commit 6ad57a4661
9 changed files with 309 additions and 157 deletions

View file

@ -36,7 +36,7 @@ public:
public:
explicit ServerConn(QObject *parent = nullptr);
~ServerConn();
Q_INVOKABLE QString login(QString username, QString password, bool permanent);
Q_INVOKABLE int login(QString username, QString password, bool permanent);
Q_INVOKABLE int logout();
Q_INVOKABLE QString getDay(QString day);
Q_INVOKABLE int checkConn();

View file

@ -21,9 +21,6 @@ Page {
verticalCenter: parent.verticalCenter
}
// width: childrenRect.width
// height: childrenRect.height
property int buttonHeight: app.landscape() ? root.height * (0.5*0.8):buttonWidth
property int buttonWidth: app.landscape() ? buttonHeight:root.width * (0.5*0.8)
@ -144,6 +141,10 @@ Page {
width: smallMenu.buttonWidth
height: smallMenu.buttonHeight
onClicked: {
formStack.push(settingsForm)
}
}
FancyButton {
@ -177,11 +178,10 @@ Page {
}
onAccepted: {
_cppServerConn.logout()
app.state = "notLoggedInu"
app.state = "notLoggedIn"
}
}
}
}
}
}

View file

@ -0,0 +1,75 @@
import QtQuick 2.0
import QtQuick.Controls 2.4
Page {
id: root
title: "Einstellungen"
signal opened()
onOpened: {
console.log("Home Form opened")
}
Column {
id: settingsCol
anchors.fill: parent
ItemDelegate {
width: parent.width
height: 10 + shortDescription.height + 2 + longDescription.height + 10
Label {
id: shortDescription
anchors {
top: parent.top
left: parent.left
margins: 10
}
font.pixelSize: longDescription.font.pixelSize * 1.4
text: "Klassenstufe"
}
Label {
id: longDescription
anchors {
top: shortDescription.bottom
topMargin: 2
left: parent.left
leftMargin: 10
}
width: parent.width - 10 - gradeSelect.width
wrapMode: Label.Wrap
text: "Wähle deine Klassenstufe aus, um den Vertretungsplan zu sortieren"
}
SpinBox {
id: gradeSelect
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
}
from: 5
to: 12
stepSize: 1
value: _cppAppSettings.loadSetting("grade")
onValueChanged: {
_cppAppSettings.writeSetting("grade", value)
}
}
}
}
}

View file

@ -7,10 +7,6 @@ Page {
id: root
objectName: "LoginPage";
onHeightChanged: {
console.log(height)
}
header: AppToolBar {
Label {
text: "Anmeldung"
@ -210,31 +206,43 @@ Page {
}
function login(username, password, permanent){
// hide the keyboard
Qt.inputMethod.hide();
// open the busy dialog
busyDialog.open()
// disable the login button
loginButton.enabled = false
loginButton.text = "Loggin in.."
// change the text to "Anmelden.."
loginButton.text = "Anmelden.."
console.log(username, password, permanent)
// trigger the login fucntion of the cpp backend and store the return code
var ret = _cppServerConn.login(username, password, permanent);
// the request has finished
// close the busy dialog
busyDialog.close()
// enable the button
loginButton.enabled = true
loginButton.text = "Login"
if(ret === "OK"){
// change the text of the login button back to "Anmelden"
loginButton.text = "Anmelden"
// chekc if the login was successfull
if(ret === 200){
// if it was -> set the app to inited and set the state of the app to loggedIn
_cppAppSettings.writeSetting("init", 1);
app.is_error = false;
app.state = "loggedIn"
}
else{
if(_cppAppSettings.loadSetting("permanent") === "1"){
tiuname.text = _cppAppSettings.loadSetting("username")
tipasswd.text = _cppAppSettings.loadSetting("password")
// if it wasn't -> reset the stored credentinals
_cppAppSettings.writeSetting("permanent", "0")
_cppAppSettings.writeSetting("username", "")
_cppAppSettings.writeSetting("password", "")
// and set the error label to the error short description of the retuned error code
laStatus.text = app.getErrorInfo(ret)[1]
}
laStatus.text = ret
}
//root.qmlSignal(tiuname.text, tipasswd.text)
}
Dialog {
@ -242,14 +250,14 @@ Page {
modal: true
closePolicy: "NoAutoClose"
focus: true
title: "Please wait..."
title: "Bitte warten..."
x: (app.width - width) / 2
y: window.height / 6
y: (app.height - height) / 2
width: Math.min(window.width, window.height) / 3 * 2
height: 150
contentHeight: aboutColumn.height
contentHeight: contentColumn.height
Column {
id: aboutColumn
id: contentColumn
spacing: 20
RowLayout {
width: parent.width
@ -262,14 +270,11 @@ Page {
Label {
width: busyDialog.availableWidth
text: "logging in..."
text: "Anmelden..."
wrapMode: Label.Wrap
font.pixelSize: 12
}
}
}
}
}

View file

@ -56,6 +56,11 @@ Page {
}
}
Component {
id: settingsForm
SettingsForm {}
}
popEnter: Transition {
XAnimator {
from: (formStack.mirrored ? -1 : 1) * -formStack.width

View file

@ -88,7 +88,7 @@ ApplicationWindow {
else {
ret = _cppServerConn.checkConn()
handleError(ret)
app.handleError(ret)
}
}
else {
@ -187,6 +187,11 @@ ApplicationWindow {
errorString = "Keine Verbindung zum Server"
errorDescription = "Bitte überprüfe deine Internetverbindung und versuche es erneut."
break
case 401:
infoLevel = 2
errorString = "Ungültige Zugangsdaten"
errorDescription = "Der Server hat den Zugang verweigert, bitte überprüfe deine Zugangsdaten und versuche es erneut"
break
case 500:
infoLevel = 2
errorString = "Interner Server Fehler"

View file

@ -13,5 +13,6 @@
<file>Forms/LoadingForm.qml</file>
<file>Components/EventView.qml</file>
<file>Components/InfoArea.qml</file>
<file>Forms/SettingsForm.qml</file>
</qresource>
</RCC>

View file

@ -13,6 +13,9 @@ AppSettings::AppSettings(QObject* parent)
if(loadSetting("init") == "false"){
this->writeSetting("init", 0);
}
if(loadSetting("grade") == "false"){
this->writeSetting("grade", 5);
}
}
QString AppSettings::loadSetting(const QString &key)

View file

@ -21,63 +21,81 @@ ServerConn::~ServerConn()
dir.removeRecursively();
}
QString ServerConn::login(QString username, QString password, bool permanent)
int 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);
// qDebug() << ret.text;
// Create request
// Create network request
QNetworkRequest request;
request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/sheute.pdf" ) );
// call a non-existent file to be fast
request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/logintest" ) );
// Pack in credentials
QString concatenatedCredentials = username + ":" + password;
QByteArray data = concatenatedCredentials.toLocal8Bit().toBase64();
// pack the credentials into a string
QString credentialsString = username + ":" + password;
// convert it to a byte array
QByteArray data = credentialsString.toLocal8Bit().toBase64();
// put it into a string
QString headerData = "Basic " + data;
// and finally write it into the request header
request.setRawHeader( "Authorization", headerData.toLocal8Bit() );
QUrlQuery pdata;
//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 );
//QNetworkReply*reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
QNetworkReply*reply = networkManager->get( request );
// loop to wait until the request has finished before processing the data
QEventLoop loop;
// timer to cancel the request after 3 seconds
QTimer timer;
timer.setSingleShot(true);
// quit the loop when the request finised
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
// or the timer timed out
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
// start the timer
timer.start(2000);
// start the loop
loop.exec();
// get the status code from the request
int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if(status_code == 200){
// 404 is a success because a non existent file was called and not 401 was returned -> user data was correct
if(status_code == 404){
// store username and password in the class variables
this->username = username;
this->password = password;
if(permanent){
qDebug() << "permanent";
// if the user wants to say logged in, store the username and password to the settings file
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.");
// return success
return(200);
}
else {
QString ret = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toChar();
ret = ret + reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toChar();
return(ret);
// if not 404 was returned -> error -> return the return code
return(status_code);
}
}
int ServerConn::logout()
{
// reset the data stored in the class
this->username = "";
this->password = "";
// reset the data stored in the settings
pGlobalAppSettings->writeSetting("permanent", "0");
pGlobalAppSettings->writeSetting("username", "");
pGlobalAppSettings->writeSetting("password", "");
// return success
return(200);
}
@ -143,8 +161,7 @@ int ServerConn::checkConn()
request.setUrl( QUrl( "http://www.fanny-leicht.de/static15/http.intern/" ) );
// Pack in credentials
// Pack in credentials
//ZedlerDo:LxyJQB
// e.g. ZedlerDo:LxyJQB (yes, these do actually work ;)
QString concatenatedCredentials = this->username + ":" + this->password;
QByteArray data = concatenatedCredentials.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
@ -161,16 +178,15 @@ int ServerConn::checkConn()
int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
return(status_code);
}
void ServerConn::updateProgress(qint64 read, qint64 total)
{
int read_int = read;
int total_int = total;
float percent = ((float)read_int / (float)total_int);
int read_int = int(read);
int total_int = int(total);
float percent = (float(read_int) / float(total_int));
this->progress = percent;
percent = (int)percent;
percent = int(percent);
// qDebug() << read << total << percent << "%";
}
@ -222,51 +238,98 @@ int ServerConn::getEvents(QString day){
}
QString eventString = textFile->readAll();
// separate all lines into a list
QStringList events = eventString.split("\n");
// a line (one element of the list) looks like this:
// class hour replace subject room to text
// 8a 1-2 Ei Ch --- Entfall KEINE KA
// [ ] <-- at least two spaces
// to OR text can be blank
// temporary list to store the events for the given day
QList<QStringList> tmpEvents;
// 8a 1-2 Ei Ch --- Entfall KEINE KA
// go through the list and process every single row
foreach(QString event, events){
// value to count spaces between text
int spaceCount = 0;
// temporary list to store the data of one day
QStringList dayList;
// temporary dtring to store the data of one block
QString tmpString;
// processing works like:
// go through the line char by char
for(int i = 0;i < event.length(); i++){
// store the char temporarly
QCharRef tmpChar = event[i];
// check if the char is a space
if(tmpChar == " "){
// if so, increase the spaceCount by one
spaceCount ++;
}
else {
// if not -> new block or part of a block started
// could be : 8a 1 - 2 OR 8a 1 - 2
// here->| OR here->|
// in the first case, the space counter is higer than one
// in the second case, the space counter is exactly one
if(spaceCount == 1){
// -> append a space to the temp string
tmpString.append(" ");
}
// reset the space counter
spaceCount = 0;
// append the current character
tmpString.append(tmpChar);
}
// check if the soace count is 2
if(spaceCount == 2){
// if so -> break between two blocks
// could be: 8a 1 - 2 OR 8a 1 - 2
// here ->|
// -> append the current tmpString to the dayList
dayList.append(tmpString);
// and clear the tmpString
tmpString = "";
}
qDebug() << "char= " << tmpChar << " string= " << tmpString << " list= " << dayList;
}
// append the remaining tmpString to the dayList
dayList.append(tmpString);
// fill up the dayList with blanks until it reaches the defined length
while (dayList.length() < 7) {
dayList.append("");
}
// if the event matches the filter
if(dayList[0].contains(pGlobalAppSettings->loadSetting("grade"))){
// append the dayList to the temporary event list
tmpEvents.append(dayList);
}
}
// store the new events into the class variable
this->m_events = tmpEvents;
qDebug() << tmpEvents;
/*
// return success
return(200);
/*
qDebug() << "reading xml file";
QFile * xmlFile = new QFile(":/samplehtml/Download File.xml");
if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -285,7 +348,7 @@ int ServerConn::getEvents(QString day){
int currTop = 0;
/*
<text top="530" left="3" width="20" height="17" font="1">8a</text>
<text top="530" left="55" width="36" height="17" font="1">1 - 2</text>
<text top="530" left="123" width="16" height="17" font="4"><i>Ei</i></text>
@ -294,20 +357,20 @@ int ServerConn::getEvents(QString day){
<text top="530" left="275" width="50" height="17" font="1">Entfall</text>
<text top="530" left="391" width="83" height="17" font="1">KEINE KA</text>
<text top="194" left="3" width="62" height="17" font="1">5abc 1</text>
<text top="194" left="102" width="27" height="17" font="4"><i>We</i></text>
<text top="194" left="157" width="25" height="17" font="4"><i>KR</i></text>
<text top="194" left="209" width="18" height="17" font="1">---</text>
<text top="194" left="251" width="50" height="17" font="1">Entfall</text>
<text top="194" left="3" width="62" height="17" font="1">5abc 1</text>
<text top="194" left="102" width="27" height="17" font="4"><i>We</i></text>
<text top="194" left="157" width="25" height="17" font="4"><i>KR</i></text>
<text top="194" left="209" width="18" height="17" font="1">---</text>
<text top="194" left="251" width="50" height="17" font="1">Entfall</text>
#define eventXmlPosGrade 3
#define eventXmlPosHour 55
#define eventXmlPosReplace 123
#define eventXmlPosSubject 178
#define eventXmlPosRoom 233
#define eventXmlPosTo 275
#define eventXmlPosText 391
#define eventXmlPosGrade 3
#define eventXmlPosHour 55
#define eventXmlPosReplace 123
#define eventXmlPosSubject 178
#define eventXmlPosRoom 233
#define eventXmlPosTo 275
#define eventXmlPosText 391
QList<int> eventXmlPositions = {eventXmlPosGrade,eventXmlPosHour,eventXmlPosReplace,eventXmlPosSubject,eventXmlPosRoom,eventXmlPosTo,eventXmlPosText};
qDebug() << "start xml parsing";
@ -384,11 +447,6 @@ int ServerConn::getEvents(QString day){
xmlFile->close();
*/
foreach(QList<QString>day, this->m_events){
qDebug() << day;
}
return(200);
}
int ServerConn::getFoodPlan()