source: subsurface/mobile-widgets/qmlmanager.h @ 0a0c93e

Last change on this file since 0a0c93e was 0a0c93e, checked in by Dirk Hohndel <dirk@…>, 5 months ago

QML UI: add variable for libdc logfile

It seemed cleanest and easiest to have this in the QMLManager and
not in the DCDownload object.

Signed-off-by: Dirk Hohndel <dirk@…>

  • Property mode set to 100644
File size: 8.6 KB
Line 
1// SPDX-License-Identifier: GPL-2.0
2#ifndef QMLMANAGER_H
3#define QMLMANAGER_H
4
5#include <QObject>
6#include <QString>
7#include <QNetworkAccessManager>
8#include <QScreen>
9#include <QElapsedTimer>
10#include <QColor>
11
12#include "core/btdiscovery.h"
13#include "core/gpslocation.h"
14#include "core/downloadfromdcthread.h"
15#include "qt-models/divelistmodel.h"
16
17class QMLManager : public QObject {
18        Q_OBJECT
19        Q_ENUMS(credentialStatus_t)
20        Q_PROPERTY(QString cloudUserName READ cloudUserName WRITE setCloudUserName NOTIFY cloudUserNameChanged)
21        Q_PROPERTY(QString cloudPassword READ cloudPassword WRITE setCloudPassword NOTIFY cloudPasswordChanged)
22        Q_PROPERTY(QString cloudPin READ cloudPin WRITE setCloudPin NOTIFY cloudPinChanged)
23        Q_PROPERTY(QString logText READ logText WRITE setLogText NOTIFY logTextChanged)
24        Q_PROPERTY(bool locationServiceEnabled READ locationServiceEnabled WRITE setLocationServiceEnabled NOTIFY locationServiceEnabledChanged)
25        Q_PROPERTY(bool locationServiceAvailable READ locationServiceAvailable WRITE setLocationServiceAvailable NOTIFY locationServiceAvailableChanged)
26        Q_PROPERTY(int distanceThreshold READ distanceThreshold WRITE setDistanceThreshold NOTIFY distanceThresholdChanged)
27        Q_PROPERTY(int timeThreshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged)
28        Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
29        Q_PROPERTY(bool loadFromCloud READ loadFromCloud WRITE setLoadFromCloud NOTIFY loadFromCloudChanged)
30        Q_PROPERTY(QString startPageText READ startPageText WRITE setStartPageText NOTIFY startPageTextChanged)
31        Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged)
32        Q_PROPERTY(credentialStatus_t credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged)
33        Q_PROPERTY(credentialStatus_t oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged)
34        Q_PROPERTY(QString notificationText READ notificationText WRITE setNotificationText NOTIFY notificationTextChanged)
35        Q_PROPERTY(bool syncToCloud READ syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged)
36        Q_PROPERTY(int updateSelectedDive READ updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged)
37        Q_PROPERTY(int selectedDiveTimestamp READ selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged)
38        Q_PROPERTY(QStringList suitInit READ suitInit CONSTANT)
39        Q_PROPERTY(QStringList buddyInit READ buddyInit CONSTANT)
40        Q_PROPERTY(QStringList divemasterInit READ divemasterInit CONSTANT)
41        Q_PROPERTY(QStringList cylinderInit READ cylinderInit CONSTANT)
42        Q_PROPERTY(bool showPin READ showPin WRITE setShowPin NOTIFY showPinChanged)
43        Q_PROPERTY(QString progressMessage READ progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged)
44        Q_PROPERTY(bool libdcLog READ libdcLog WRITE setLibdcLog NOTIFY libdcLogChanged)
45
46public:
47        QMLManager();
48        ~QMLManager();
49
50        enum credentialStatus_t {
51                INCOMPLETE,
52                UNKNOWN,
53                INVALID,
54                VALID_EMAIL,
55                VALID,
56                NOCLOUD
57        };
58
59        static QMLManager *instance();
60
61        QString cloudUserName() const;
62        void setCloudUserName(const QString &cloudUserName);
63
64        QString cloudPassword() const;
65        void setCloudPassword(const QString &cloudPassword);
66
67        QString cloudPin() const;
68        void setCloudPin(const QString &cloudPin);
69
70        bool locationServiceEnabled() const;
71        void setLocationServiceEnabled(bool locationServiceEnable);
72
73        bool locationServiceAvailable() const;
74        void setLocationServiceAvailable(bool locationServiceAvailable);
75
76        bool verboseEnabled() const;
77        void setVerboseEnabled(bool verboseMode);
78
79        int distanceThreshold() const;
80        void setDistanceThreshold(int distance);
81
82        int timeThreshold() const;
83        void setTimeThreshold(int time);
84
85        QString theme() const;
86        void setTheme(QString theme);
87
88        bool loadFromCloud() const;
89        void setLoadFromCloud(bool done);
90        void syncLoadFromCloud();
91
92        QString startPageText() const;
93        void setStartPageText(const QString& text);
94
95        credentialStatus_t credentialStatus() const;
96        void setCredentialStatus(const credentialStatus_t value);
97
98        credentialStatus_t oldStatus() const;
99        void setOldStatus(const credentialStatus_t value);
100
101        QString logText() const;
102        void setLogText(const QString &logText);
103
104        QString notificationText() const;
105        void setNotificationText(QString text);
106
107        bool syncToCloud() const;
108        void setSyncToCloud(bool status);
109
110        int updateSelectedDive() const;
111        void setUpdateSelectedDive(int idx);
112
113        int selectedDiveTimestamp() const;
114        void setSelectedDiveTimestamp(int when);
115
116        QString progressMessage() const;
117        void setProgressMessage(QString text);
118
119        bool libdcLog() const;
120        void setLibdcLog(bool value);
121
122        typedef void (QMLManager::*execute_function_type)();
123        DiveListSortModel *dlSortModel;
124
125        QStringList suitInit() const;
126        QStringList buddyInit() const;
127        QStringList divemasterInit() const;
128        QStringList cylinderInit() const;
129        bool showPin() const;
130        void setShowPin(bool enable);
131        Q_INVOKABLE void setStatusbarColor(QColor color);
132#if defined(Q_OS_ANDROID)
133        void writeToAppLogFile(QString logText);
134#endif
135
136public slots:
137        void applicationStateChanged(Qt::ApplicationState state);
138        void savePreferences();
139        void saveCloudCredentials();
140        void checkCredentialsAndExecute(execute_function_type execute);
141        void tryRetrieveDataFromBackend();
142        void handleError(QNetworkReply::NetworkError nError);
143        void handleSslErrors(const QList<QSslError> &errors);
144        void retrieveUserid();
145        void loadDivesWithValidCredentials();
146        void provideAuth(QNetworkReply *reply, QAuthenticator *auth);
147        void commitChanges(QString diveId, QString date, QString location, QString gps,
148                           QString duration, QString depth, QString airtemp,
149                           QString watertemp, QString suit, QString buddy,
150                           QString diveMaster, QString weight, QString notes, QString startpressure,
151                           QString endpressure, QString gasmix, QString cylinder);
152        void changesNeedSaving();
153        void saveChangesLocal();
154        void saveChangesCloud(bool forceRemoteSync);
155        void deleteDive(int id);
156        bool undoDelete(int id);
157        QString addDive();
158        void addDiveAborted(int id);
159        void applyGpsData();
160        void sendGpsData();
161        void downloadGpsData();
162        void populateGpsData();
163        void clearGpsData();
164        void finishSetup();
165        void openLocalThenRemote(QString url);
166        void mergeLocalRepo();
167        QString getNumber(const QString& diveId);
168        QString getDate(const QString& diveId);
169        QString getCurrentPosition();
170        QString getVersion() const;
171        void deleteGpsFix(quint64 when);
172        void revertToNoCloudIfNeeded();
173        void consumeFinishedLoad(timestamp_t currentDiveTimestamp);
174        void refreshDiveList();
175        void screenChanged(QScreen *screen);
176        qreal lastDevicePixelRatio();
177        void setDevicePixelRatio(qreal dpr, QScreen *screen);
178        void appendTextToLog(const QString &newText);
179        void quit();
180        void hasLocationSourceChanged();
181
182private:
183        QString m_cloudUserName;
184        QString m_cloudPassword;
185        QString m_cloudPin;
186        QString m_ssrfGpsWebUserid;
187        QString m_startPageText;
188        QString m_logText;
189        bool m_locationServiceEnabled;
190        bool m_locationServiceAvailable;
191        bool m_verboseEnabled;
192        int m_distanceThreshold;
193        int m_timeThreshold;
194        GpsLocation *locationProvider;
195        bool m_loadFromCloud;
196        static QMLManager *m_instance;
197        QNetworkReply *reply;
198        QNetworkRequest request;
199        struct dive *deletedDive;
200        struct dive_trip *deletedTrip;
201        QString m_notificationText;
202        bool m_syncToCloud;
203        int m_updateSelectedDive;
204        int m_selectedDiveTimestamp;
205        credentialStatus_t m_credentialStatus;
206        credentialStatus_t m_oldStatus;
207        qreal m_lastDevicePixelRatio;
208        QElapsedTimer timer;
209        bool alreadySaving;
210        bool checkDate(DiveObjectHelper *myDive, struct dive * d, QString date);
211        bool checkLocation(DiveObjectHelper *myDive, struct dive *d, QString location, QString gps);
212        bool checkDuration(DiveObjectHelper *myDive, struct dive *d, QString duration);
213        bool checkDepth(DiveObjectHelper *myDive, struct dive *d, QString depth);
214        bool currentGitLocalOnly;
215        bool m_showPin;
216        DCDeviceData *m_device_data;
217        QString m_progressMessage;
218        bool m_libdcLog;
219#if defined(Q_OS_ANDROID)
220        QString appLogFileName;
221        QFile appLogFile;
222        bool appLogFileOpen;
223#endif
224
225signals:
226        void cloudUserNameChanged();
227        void cloudPasswordChanged();
228        void cloudPinChanged();
229        void locationServiceEnabledChanged();
230        void locationServiceAvailableChanged();
231        void verboseEnabledChanged();
232        void logTextChanged();
233        void timeThresholdChanged();
234        void themeChanged();
235        void distanceThresholdChanged();
236        void loadFromCloudChanged();
237        void startPageTextChanged();
238        void credentialStatusChanged();
239        void oldStatusChanged();
240        void notificationTextChanged();
241        void syncToCloudChanged();
242        void updateSelectedDiveChanged();
243        void selectedDiveTimestampChanged();
244        void showPinChanged();
245        void sendScreenChanged(QScreen *screen);
246        void progressMessageChanged();
247        void libdcLogChanged();
248};
249
250#endif
Note: See TracBrowser for help on using the repository browser.