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>
|
2016-03-09 03:31:05 +00:00
|
|
|
#include <QScreen>
|
QML UI: don't immediately save data after we make changes
Much as this felt like the prudent thing to do, it makes the UI painful
to use. In bad network conditions, with a large dive log, on a phone,
the save operation can take more than a minute - which is just completely
ludicrous.
So instead we mark the dive list changed when we make changes and wait
for the app to not be in the foreground. Once the OS tells us that we are
hidden (on the desktop that generally means we don't have focus, on a
mobile device it usually does mean that the app is not on the screen), we
check if there are data to be saved and do so.
There is of course a major problem with this logic. If the user switches
away from Subsurface-mobile but comes back fairly quickly (just reacting
to a notification or briefly checking something, changing a song,
something... then the app may still be non-responsive for quite a while.
So we need to do something about the time it takes us to save the git
tree locally, and then figure out if we can move at least some of the
network traffic to another thread.
And we need to make sure the user immediately notices that the app is not
crashed but is actually saving their data. But that's for another commit.
tl;dr: CAREFUL, don't kill Subsurface-mobile before it had time to save
your data or your changes may be gone. In typical use that shouldn't be
an issue, but it is something that we need to tell the user about.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 00:37:17 +00:00
|
|
|
#include <QElapsedTimer>
|
2015-06-04 10:29:50 +00:00
|
|
|
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/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-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)
|
2016-04-06 18:42:38 +00:00
|
|
|
Q_PROPERTY(credentialStatus_t oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged)
|
2016-04-04 00:00:49 +00:00
|
|
|
Q_PROPERTY(int accessingCloud READ accessingCloud WRITE setAccessingCloud NOTIFY accessingCloudChanged)
|
2016-04-04 01:33:40 +00:00
|
|
|
Q_PROPERTY(bool syncToCloud READ syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged)
|
2016-03-03 01:13:42 +00:00
|
|
|
|
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-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);
|
|
|
|
|
2016-04-06 18:42:38 +00:00
|
|
|
credentialStatus_t oldStatus() const;
|
|
|
|
void setOldStatus(const credentialStatus_t value);
|
|
|
|
|
2015-08-19 07:17:52 +00:00
|
|
|
QString logText() const;
|
|
|
|
void setLogText(const QString &logText);
|
|
|
|
|
2016-04-04 00:00:49 +00:00
|
|
|
int accessingCloud() const;
|
|
|
|
void setAccessingCloud(int status);
|
2016-03-03 01:13:42 +00:00
|
|
|
|
2016-04-04 01:33:40 +00:00
|
|
|
bool syncToCloud() const;
|
|
|
|
void setSyncToCloud(bool status);
|
|
|
|
|
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:
|
QML UI: don't immediately save data after we make changes
Much as this felt like the prudent thing to do, it makes the UI painful
to use. In bad network conditions, with a large dive log, on a phone,
the save operation can take more than a minute - which is just completely
ludicrous.
So instead we mark the dive list changed when we make changes and wait
for the app to not be in the foreground. Once the OS tells us that we are
hidden (on the desktop that generally means we don't have focus, on a
mobile device it usually does mean that the app is not on the screen), we
check if there are data to be saved and do so.
There is of course a major problem with this logic. If the user switches
away from Subsurface-mobile but comes back fairly quickly (just reacting
to a notification or briefly checking something, changing a song,
something... then the app may still be non-responsive for quite a while.
So we need to do something about the time it takes us to save the git
tree locally, and then figure out if we can move at least some of the
network traffic to another thread.
And we need to make sure the user immediately notices that the app is not
crashed but is actually saving their data. But that's for another commit.
tl;dr: CAREFUL, don't kill Subsurface-mobile before it had time to save
your data or your changes may be gone. In typical use that shouldn't be
an issue, but it is something that we need to tell the user about.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 00:37:17 +00:00
|
|
|
void applicationStateChanged(Qt::ApplicationState state);
|
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();
|
|
|
|
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-28 14:43:54 +00:00
|
|
|
void commitChanges(QString diveId, QString date, QString location,
|
|
|
|
QString gps, QString duration, QString depth,
|
|
|
|
QString airtemp, QString watertemp, QString suit,
|
|
|
|
QString buddy, QString diveMaster, QString weight, QString notes,
|
|
|
|
QString startpressure, QString endpressure, QString gasmix);
|
2016-04-06 18:47:12 +00:00
|
|
|
void saveChangesLocal();
|
2016-04-08 19:35:45 +00:00
|
|
|
void saveChangesCloud(bool forceRemoteSync);
|
2016-02-23 12:39:40 +00:00
|
|
|
void deleteDive(int id);
|
2016-02-29 14:53:26 +00:00
|
|
|
void undoDelete(int id);
|
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-03-02 12:41:36 +00:00
|
|
|
int getIndex(const QString& diveId);
|
2016-01-26 15:02:42 +00:00
|
|
|
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();
|
2016-03-09 03:31:05 +00:00
|
|
|
void screenChanged(QScreen *screen);
|
|
|
|
qreal lastDevicePixelRatio();
|
2016-03-27 04:31:41 +00:00
|
|
|
void appendTextToLog(const QString &newText);
|
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-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;
|
2016-02-29 14:53:26 +00:00
|
|
|
struct dive *deletedDive;
|
|
|
|
struct dive_trip *deletedTrip;
|
2016-04-04 00:00:49 +00:00
|
|
|
int m_accessingCloud;
|
2016-04-04 01:33:40 +00:00
|
|
|
bool m_syncToCloud;
|
2016-02-11 01:45:23 +00:00
|
|
|
credentialStatus_t m_credentialStatus;
|
2016-04-06 18:42:38 +00:00
|
|
|
credentialStatus_t m_oldStatus;
|
2016-03-09 03:31:05 +00:00
|
|
|
qreal m_lastDevicePixelRatio;
|
QML UI: don't immediately save data after we make changes
Much as this felt like the prudent thing to do, it makes the UI painful
to use. In bad network conditions, with a large dive log, on a phone,
the save operation can take more than a minute - which is just completely
ludicrous.
So instead we mark the dive list changed when we make changes and wait
for the app to not be in the foreground. Once the OS tells us that we are
hidden (on the desktop that generally means we don't have focus, on a
mobile device it usually does mean that the app is not on the screen), we
check if there are data to be saved and do so.
There is of course a major problem with this logic. If the user switches
away from Subsurface-mobile but comes back fairly quickly (just reacting
to a notification or briefly checking something, changing a song,
something... then the app may still be non-responsive for quite a while.
So we need to do something about the time it takes us to save the git
tree locally, and then figure out if we can move at least some of the
network traffic to another thread.
And we need to make sure the user immediately notices that the app is not
crashed but is actually saving their data. But that's for another commit.
tl;dr: CAREFUL, don't kill Subsurface-mobile before it had time to save
your data or your changes may be gone. In typical use that shouldn't be
an issue, but it is something that we need to tell the user about.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 00:37:17 +00:00
|
|
|
QElapsedTimer timer;
|
|
|
|
bool alreadySaving;
|
2016-02-11 01:45:23 +00:00
|
|
|
|
2015-06-04 10:29:50 +00:00
|
|
|
signals:
|
2015-07-10 07:47:26 +00:00
|
|
|
void cloudUserNameChanged();
|
|
|
|
void cloudPasswordChanged();
|
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();
|
2016-04-06 18:42:38 +00:00
|
|
|
void oldStatusChanged();
|
2016-03-03 01:13:42 +00:00
|
|
|
void accessingCloudChanged();
|
2016-04-04 01:33:40 +00:00
|
|
|
void syncToCloudChanged();
|
2016-03-09 03:31:05 +00:00
|
|
|
void sendScreenChanged(QScreen *screen);
|
2015-06-04 10:29:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|