source: subsurface/mobile-widgets/qmlmanager.h @ c59a740

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

Android: write appLog to file

The trick is to pick a path that is accessible from other applications.
In theory QStandardPaths::GenericDataLocation? should provide that.

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

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