2018-06-21 08:47:09 +02:00
|
|
|
#ifndef SERVERCONN_H
|
|
|
|
#define SERVERCONN_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2018-06-21 16:41:02 +02:00
|
|
|
#include <QDir>
|
2018-06-21 18:36:46 +02:00
|
|
|
#include <QUrl>
|
2018-12-21 12:23:12 +01:00
|
|
|
#include <QtXml>
|
2018-12-25 19:30:42 +01:00
|
|
|
#include <QTimer>
|
2018-12-21 12:23:12 +01:00
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
#include <QtNetwork>
|
|
|
|
#include <QAuthenticator>
|
2018-06-21 16:41:02 +02:00
|
|
|
#include <QDesktopServices>
|
2018-06-21 18:36:46 +02:00
|
|
|
#include <QXmlNamespaceSupport>
|
2018-06-21 16:41:02 +02:00
|
|
|
|
|
|
|
#include "headers/appsettings.h"
|
2018-06-21 08:47:09 +02:00
|
|
|
|
2018-12-21 12:23:12 +01:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
#include <QtAndroidExtras>
|
|
|
|
#endif
|
|
|
|
|
2018-06-21 18:36:46 +02:00
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
typedef struct strReturnData{
|
|
|
|
int status_code;
|
|
|
|
QString text;
|
|
|
|
}ReturnData_t;
|
|
|
|
|
|
|
|
class ServerConn : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-12-25 20:34:53 +01:00
|
|
|
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
|
2018-06-21 16:41:02 +02:00
|
|
|
|
2018-12-25 19:30:42 +01:00
|
|
|
private:
|
|
|
|
QString state;
|
|
|
|
// can be: loggedIn ; notLoggedIn
|
2018-06-21 16:41:02 +02:00
|
|
|
QString username;
|
|
|
|
QString password;
|
2018-06-21 08:47:09 +02:00
|
|
|
QNetworkAccessManager *networkManager;
|
2018-06-21 16:41:02 +02:00
|
|
|
QNetworkAccessManager *refreshNetworkManager;
|
2018-12-25 19:30:42 +01:00
|
|
|
QTimer *checkConnTimer;
|
2018-06-22 09:36:20 +02:00
|
|
|
float progress;
|
2018-12-25 19:30:42 +01:00
|
|
|
int authErrorCount;
|
|
|
|
|
|
|
|
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
|
2018-12-25 20:34:53 +01:00
|
|
|
|
|
|
|
private slots:
|
2018-12-25 19:30:42 +01:00
|
|
|
void updateProgress(qint64 read, qint64 total);
|
|
|
|
|
|
|
|
void setState(QString state);
|
|
|
|
|
2018-12-25 20:34:53 +01:00
|
|
|
public:
|
2018-06-21 08:47:09 +02:00
|
|
|
explicit ServerConn(QObject *parent = nullptr);
|
2018-06-21 16:41:02 +02:00
|
|
|
~ServerConn();
|
2018-12-25 19:30:42 +01:00
|
|
|
|
2018-12-25 20:34:53 +01:00
|
|
|
public slots:
|
2018-12-25 00:15:25 +01:00
|
|
|
Q_INVOKABLE int login(QString username, QString password, bool permanent);
|
2018-06-21 16:41:02 +02:00
|
|
|
Q_INVOKABLE int logout();
|
|
|
|
Q_INVOKABLE QString getDay(QString day);
|
|
|
|
Q_INVOKABLE int checkConn();
|
2018-06-22 09:36:20 +02:00
|
|
|
Q_INVOKABLE float getProgress();
|
2018-06-25 00:15:18 +02:00
|
|
|
Q_INVOKABLE int getFoodPlan();
|
2018-12-23 00:06:05 +01:00
|
|
|
Q_INVOKABLE int getEvents(QString day);
|
2018-06-21 08:47:09 +02:00
|
|
|
|
2018-12-25 19:30:42 +01:00
|
|
|
Q_INVOKABLE QString getState();
|
2018-12-23 21:07:10 +01:00
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
signals:
|
2018-12-25 20:34:53 +01:00
|
|
|
void stateChanged(QString newState);
|
2018-12-25 19:30:42 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
QList<QList<QString>> m_weekplan;
|
|
|
|
QList<QStringList> m_events;
|
2018-06-21 08:47:09 +02:00
|
|
|
|
2018-06-22 09:36:20 +02:00
|
|
|
|
2018-06-21 08:47:09 +02:00
|
|
|
};
|
2018-12-23 21:07:10 +01:00
|
|
|
extern ServerConn * pGlobalServConn;
|
2018-06-21 08:47:09 +02:00
|
|
|
|
|
|
|
#endif // SERVERCONN_H
|