2015-06-04 13:29:50 +03:00
|
|
|
#ifndef QMLMANAGER_H
|
|
|
|
#define QMLMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2015-12-04 19:34:59 -08:00
|
|
|
#include <QNetworkAccessManager>
|
2015-06-04 13:29:50 +03:00
|
|
|
|
2015-11-18 18:30:55 -08:00
|
|
|
#include "gpslocation.h"
|
2015-11-11 12:34:56 -08:00
|
|
|
|
2016-01-11 06:14:45 -08:00
|
|
|
class QMLManager : public QObject {
|
2015-06-04 13:29:50 +03:00
|
|
|
Q_OBJECT
|
2015-07-10 10:47:26 +03:00
|
|
|
Q_PROPERTY(QString cloudUserName READ cloudUserName WRITE setCloudUserName NOTIFY cloudUserNameChanged)
|
|
|
|
Q_PROPERTY(QString cloudPassword READ cloudPassword WRITE setCloudPassword NOTIFY cloudPasswordChanged)
|
2015-07-21 11:57:10 +03:00
|
|
|
Q_PROPERTY(bool saveCloudPassword READ saveCloudPassword WRITE setSaveCloudPassword NOTIFY saveCloudPasswordChanged)
|
2015-08-19 10:17:52 +03:00
|
|
|
Q_PROPERTY(QString logText READ logText WRITE setLogText NOTIFY logTextChanged)
|
2015-11-11 12:34:56 -08:00
|
|
|
Q_PROPERTY(bool locationServiceEnabled READ locationServiceEnabled WRITE setLocationServiceEnabled NOTIFY locationServiceEnabledChanged)
|
2015-11-14 09:10:06 -08:00
|
|
|
Q_PROPERTY(int distanceThreshold READ distanceThreshold WRITE setDistanceThreshold NOTIFY distanceThresholdChanged)
|
|
|
|
Q_PROPERTY(int timeThreshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged)
|
2015-12-02 18:49:02 -08:00
|
|
|
Q_PROPERTY(bool loadFromCloud READ loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged)
|
2015-12-14 23:00:19 -08:00
|
|
|
Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged)
|
2015-12-19 18:41:10 -08:00
|
|
|
Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged)
|
2015-06-04 13:29:50 +03:00
|
|
|
public:
|
|
|
|
QMLManager();
|
|
|
|
~QMLManager();
|
|
|
|
|
2015-12-03 15:59:40 -08:00
|
|
|
static QMLManager *instance();
|
|
|
|
|
2015-07-10 10:47:26 +03:00
|
|
|
QString cloudUserName() const;
|
|
|
|
void setCloudUserName(const QString &cloudUserName);
|
|
|
|
|
|
|
|
QString cloudPassword() const;
|
|
|
|
void setCloudPassword(const QString &cloudPassword);
|
|
|
|
|
2015-07-21 11:57:10 +03:00
|
|
|
bool saveCloudPassword() const;
|
|
|
|
void setSaveCloudPassword(bool saveCloudPassword);
|
|
|
|
|
2015-11-11 12:34:56 -08:00
|
|
|
bool locationServiceEnabled() const;
|
|
|
|
void setLocationServiceEnabled(bool locationServiceEnable);
|
|
|
|
|
2015-12-19 18:41:10 -08:00
|
|
|
bool verboseEnabled() const;
|
|
|
|
void setVerboseEnabled(bool verboseMode);
|
|
|
|
|
2015-11-14 09:10:06 -08:00
|
|
|
int distanceThreshold() const;
|
|
|
|
void setDistanceThreshold(int distance);
|
|
|
|
|
|
|
|
int timeThreshold() const;
|
|
|
|
void setTimeThreshold(int time);
|
|
|
|
|
2015-12-02 18:49:02 -08:00
|
|
|
bool loadFromCloud() const;
|
|
|
|
void setLoadFromCloud(bool done);
|
|
|
|
|
2015-12-14 23:00:19 -08:00
|
|
|
QString startPageText() const;
|
|
|
|
void setStartPageText(QString text);
|
|
|
|
|
2015-08-19 10:17:52 +03:00
|
|
|
QString logText() const;
|
|
|
|
void setLogText(const QString &logText);
|
|
|
|
void appendTextToLog(const QString &newText);
|
|
|
|
|
2016-01-11 06:14:45 -08:00
|
|
|
typedef void (QMLManager::*execute_function_type)();
|
2015-12-04 19:34:59 -08:00
|
|
|
|
2015-06-04 13:29:50 +03:00
|
|
|
public slots:
|
2015-07-10 10:47:26 +03:00
|
|
|
void savePreferences();
|
2015-12-03 14:30:30 -08:00
|
|
|
void saveCloudCredentials();
|
2015-12-04 19:34:59 -08:00
|
|
|
void checkCredentialsAndExecute(execute_function_type execute);
|
|
|
|
void tryRetrieveDataFromBackend();
|
|
|
|
void handleError(QNetworkReply::NetworkError nError);
|
|
|
|
void handleSslErrors(const QList<QSslError> &errors);
|
|
|
|
void retrieveUserid();
|
2015-07-10 11:31:24 +03:00
|
|
|
void loadDives();
|
2015-12-04 19:34:59 -08:00
|
|
|
void loadDivesWithValidCredentials();
|
2015-12-14 23:00:19 -08:00
|
|
|
void loadDiveProgress(int percent);
|
2015-12-04 19:34:59 -08:00
|
|
|
void provideAuth(QNetworkReply *reply, QAuthenticator *auth);
|
2016-01-07 22:30:58 -08:00
|
|
|
QString commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth,
|
2016-01-11 06:14:45 -08:00
|
|
|
QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString notes);
|
2015-07-17 18:28:01 +03:00
|
|
|
void saveChanges();
|
2015-12-26 21:37:18 -08:00
|
|
|
QString addDive();
|
2015-11-12 20:23:00 -08:00
|
|
|
void applyGpsData();
|
2015-11-13 17:14:22 -08:00
|
|
|
void sendGpsData();
|
2016-01-07 21:37:36 -08:00
|
|
|
void downloadGpsData();
|
2016-01-07 21:40:15 -08:00
|
|
|
void populateGpsData();
|
2015-11-13 17:14:22 -08:00
|
|
|
void clearGpsData();
|
2015-12-04 19:34:59 -08:00
|
|
|
void finishSetup();
|
2015-12-26 13:22:50 -08:00
|
|
|
void showMap(QString location);
|
2015-12-26 20:02:23 -08:00
|
|
|
QString getNumber(QString diveId);
|
|
|
|
QString getDate(QString diveId);
|
2016-01-01 17:23:29 -08:00
|
|
|
QString getCurrentPosition();
|
2016-01-08 23:18:41 -08:00
|
|
|
void deleteGpsFix(quint64 when);
|
2016-01-10 19:34:21 -08:00
|
|
|
void refreshDiveList();
|
2015-11-11 12:34:56 -08:00
|
|
|
|
2015-06-04 13:29:50 +03:00
|
|
|
private:
|
2015-07-10 10:47:26 +03:00
|
|
|
QString m_cloudUserName;
|
|
|
|
QString m_cloudPassword;
|
2015-11-13 17:14:22 -08:00
|
|
|
QString m_ssrfGpsWebUserid;
|
2015-12-14 23:00:19 -08:00
|
|
|
QString m_startPageText;
|
2015-07-21 11:57:10 +03:00
|
|
|
bool m_saveCloudPassword;
|
2015-08-19 10:17:52 +03:00
|
|
|
QString m_logText;
|
2015-11-11 12:34:56 -08:00
|
|
|
bool m_locationServiceEnabled;
|
2015-12-19 18:41:10 -08:00
|
|
|
bool m_verboseEnabled;
|
2015-11-14 09:10:06 -08:00
|
|
|
int m_distanceThreshold;
|
|
|
|
int m_timeThreshold;
|
2015-11-11 12:34:56 -08:00
|
|
|
GpsLocation *locationProvider;
|
2015-12-02 18:49:02 -08:00
|
|
|
bool m_loadFromCloud;
|
2015-12-03 15:59:40 -08:00
|
|
|
static QMLManager *m_instance;
|
2015-12-04 19:34:59 -08:00
|
|
|
QNetworkReply *reply;
|
|
|
|
QNetworkRequest request;
|
|
|
|
QNetworkAccessManager *mgr;
|
2015-06-04 13:29:50 +03:00
|
|
|
|
|
|
|
signals:
|
2015-07-10 10:47:26 +03:00
|
|
|
void cloudUserNameChanged();
|
|
|
|
void cloudPasswordChanged();
|
2015-07-21 11:57:10 +03:00
|
|
|
void saveCloudPasswordChanged();
|
2015-11-11 12:34:56 -08:00
|
|
|
void locationServiceEnabledChanged();
|
2015-12-19 18:41:10 -08:00
|
|
|
void verboseEnabledChanged();
|
2015-08-19 10:17:52 +03:00
|
|
|
void logTextChanged();
|
2015-11-14 09:10:06 -08:00
|
|
|
void timeThresholdChanged();
|
|
|
|
void distanceThresholdChanged();
|
2015-12-02 18:49:02 -08:00
|
|
|
void loadFromCloudChanged();
|
2015-12-14 23:00:19 -08:00
|
|
|
void startPageTextChanged();
|
2015-06-04 13:29:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|