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