summaryrefslogtreecommitdiffstats
path: root/qt-mobile/qmlmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-mobile/qmlmanager.cpp')
-rw-r--r--qt-mobile/qmlmanager.cpp157
1 files changed, 119 insertions, 38 deletions
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index 6851ec079..301a02ce1 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -6,6 +6,7 @@
#include <QAuthenticator>
#include <QDesktopServices>
#include <QTextDocument>
+#include <QRegularExpression>
#include "qt-models/divelistmodel.h"
#include <gpslistmodel.h>
@@ -19,6 +20,9 @@
QMLManager *QMLManager::m_instance = NULL;
+#define RED_FONT QLatin1Literal("<font color=\"red\">")
+#define END_FONT QLatin1Literal("</font>")
+
static void appendTextToLogStandalone(const char *text)
{
QMLManager *self = QMLManager::instance();
@@ -42,10 +46,11 @@ extern "C" int gitProgressCB(int percent)
QMLManager::QMLManager() : m_locationServiceEnabled(false),
m_verboseEnabled(false),
- m_credentialStatus(UNKNOWN),
reply(0),
deletedDive(0),
- deletedTrip(0)
+ deletedTrip(0),
+ m_credentialStatus(UNKNOWN),
+ m_lastDevicePixelRatio(1.0)
{
m_instance = this;
appendTextToLog(getUserAgent());
@@ -98,7 +103,6 @@ void QMLManager::finishSetup()
// Initialize cloud credentials.
setCloudUserName(prefs.cloud_storage_email);
setCloudPassword(prefs.cloud_storage_password);
- setSaveCloudPassword(prefs.save_password_local);
// if the cloud credentials are valid, we should get the GPS Webservice ID as well
QString url;
if (!cloudUserName().isEmpty() &&
@@ -108,7 +112,7 @@ void QMLManager::finishSetup()
} else {
setCredentialStatus(INCOMPLETE);
appendTextToLog(QStringLiteral("no cloud credentials"));
- setStartPageText(tr("Please enter valid cloud credentials."));
+ setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
}
setDistanceThreshold(prefs.distance_threshold);
setTimeThreshold(prefs.time_threshold / 60);
@@ -144,28 +148,22 @@ void QMLManager::saveCloudCredentials()
bool cloudCredentialsChanged = false;
s.beginGroup("CloudStorage");
s.setValue("email", cloudUserName());
- s.setValue("save_password_local", saveCloudPassword());
- if (saveCloudPassword())
- s.setValue("password", cloudPassword());
+ s.setValue("password", cloudPassword());
s.sync();
if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUserName()))) {
free(prefs.cloud_storage_email);
prefs.cloud_storage_email = strdup(qPrintable(cloudUserName()));
cloudCredentialsChanged = true;
}
- if (saveCloudPassword() != prefs.save_password_local)
- prefs.save_password_local = saveCloudPassword();
cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()));
- if (saveCloudPassword()) {
- if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) {
- free(prefs.cloud_storage_password);
- prefs.cloud_storage_password = strdup(qPrintable(cloudPassword()));
- }
+ if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPassword()))) {
+ free(prefs.cloud_storage_password);
+ prefs.cloud_storage_password = strdup(qPrintable(cloudPassword()));
}
if (cloudUserName().isEmpty() || cloudPassword().isEmpty()) {
- setStartPageText(tr("Please enter valid cloud credentials."));
+ setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
} else if (cloudCredentialsChanged) {
free(prefs.userid);
prefs.userid = NULL;
@@ -209,6 +207,7 @@ void QMLManager::tryRetrieveDataFromBackend()
void QMLManager::loadDives()
{
+ setAccessingCloud(true);
checkCredentialsAndExecute(&QMLManager::loadDivesWithValidCredentials);
}
@@ -218,7 +217,7 @@ void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth)
auth->password() == QString(prefs.cloud_storage_password)) {
// OK, credentials have been tried and didn't work, so they are invalid
appendTextToLog("Cloud credentials are invalid");
- setStartPageText(tr("Cloud credentials are invalid"));
+ setStartPageText(RED_FONT + tr("Cloud credentials are invalid") + END_FONT);
setCredentialStatus(INVALID);
reply->disconnect();
reply->abort();
@@ -231,7 +230,7 @@ void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth)
void QMLManager::handleSslErrors(const QList<QSslError> &errors)
{
- setStartPageText(tr("Cannot open cloud storage: Error creating https connection"));
+ setStartPageText(RED_FONT + tr("Cannot open cloud storage: Error creating https connection") + END_FONT);
Q_FOREACH (QSslError e, errors) {
qDebug() << e.errorString();
}
@@ -244,7 +243,7 @@ void QMLManager::handleError(QNetworkReply::NetworkError nError)
{
QString errorString = reply->errorString();
qDebug() << "handleError" << nError << errorString;
- setStartPageText(tr("Cannot open cloud storage: %1").arg(errorString));
+ setStartPageText(RED_FONT + tr("Cannot open cloud storage: %1").arg(errorString) + END_FONT);
reply->abort();
reply->deleteLater();
setAccessingCloud(false);
@@ -253,7 +252,7 @@ void QMLManager::handleError(QNetworkReply::NetworkError nError)
void QMLManager::retrieveUserid()
{
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) {
- appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: ") + reply->readAll());
+ appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: %1").arg(QString(reply->readAll())));
setAccessingCloud(false);
return;
}
@@ -293,7 +292,7 @@ void QMLManager::loadDivesWithValidCredentials()
{
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) {
appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: ") + reply->readAll());
- setStartPageText(tr("Cannot connect to cloud storage"));
+ setStartPageText(RED_FONT + tr("Cannot connect to cloud storage") + END_FONT);
setAccessingCloud(false);
return;
}
@@ -305,7 +304,7 @@ void QMLManager::loadDivesWithValidCredentials()
if (getCloudURL(url)) {
QString errorString(get_error_string());
appendTextToLog(errorString);
- setStartPageText(tr("Cloud storage error: %1").arg(errorString));
+ setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT);
setAccessingCloud(false);
return;
}
@@ -331,7 +330,7 @@ void QMLManager::loadDivesWithValidCredentials()
report_error("failed to open file %s", fileNamePrt.data());
QString errorString(get_error_string());
appendTextToLog(errorString);
- setStartPageText(tr("Cloud storage error: %1").arg(errorString));
+ setStartPageText(RED_FONT + tr("Cloud storage error: %1").arg(errorString) + END_FONT);
return;
}
prefs.unit_system = informational_prefs.unit_system;
@@ -415,6 +414,76 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
date.replace(drop, "");
}
newDate = QDateTime::fromString(date, format);
+ if (!newDate.isValid()) {
+ qDebug() << "unable to parse date" << date << "with the given format" << format;
+ QRegularExpression isoDate("\\d+-\\d+-\\d+[^\\d]+\\d+:\\d+");
+ if (date.contains(isoDate)) {
+ newDate = QDateTime::fromString(date, "yyyy-M-d h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "yy-M-d h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression isoDateNoSecs("\\d+-\\d+-\\d+[^\\d]+\\d+");
+ if (date.contains(isoDateNoSecs)) {
+ newDate = QDateTime::fromString(date, "yyyy-M-d h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "yy-M-d h:m");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression usDate("\\d+/\\d+/\\d+[^\\d]+\\d+:\\d+:\\d+");
+ if (date.contains(usDate)) {
+ newDate = QDateTime::fromString(date, "M/d/yyyy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "M/d/yy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yyyy h:m:sap");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yy h:m:sap");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression usDateNoSecs("\\d+/\\d+/\\d+[^\\d]+\\d+:\\d+");
+ if (date.contains(usDateNoSecs)) {
+ newDate = QDateTime::fromString(date, "M/d/yyyy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "M/d/yy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yyyy h:map");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date.toLower(), "M/d/yy h:map");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression leDate("\\d+\\.\\d+\\.\\d+[^\\d]+\\d+:\\d+:\\d+");
+ if (date.contains(leDate)) {
+ newDate = QDateTime::fromString(date, "d.M.yyyy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "d.M.yy h:m:s");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ QRegularExpression leDateNoSecs("\\d+\\.\\d+\\.\\d+[^\\d]+\\d+:\\d+");
+ if (date.contains(leDateNoSecs)) {
+ newDate = QDateTime::fromString(date, "d.M.yyyy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ newDate = QDateTime::fromString(date, "d.M.yy h:m");
+ if (newDate.isValid())
+ goto parsed;
+ }
+ }
+parsed:
if (newDate.isValid()) {
// stupid Qt... two digit years are always 19xx - WTF???
// so if adding a hundred years gets you into something before a year from now...
@@ -422,6 +491,8 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
if (newDate.addYears(100) < QDateTime::currentDateTime().addYears(1))
newDate = newDate.addYears(100);
d->dc.when = d->when = newDate.toMSecsSinceEpoch() / 1000 + gettimezoneoffset(newDate.toMSecsSinceEpoch() / 1000);
+ } else {
+ qDebug() << "none of our parsing attempts worked for the date string";
}
}
struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
@@ -532,15 +603,17 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
diveChanged = true;
d->cylinder[0].start.mbar = parsePressureToMbar(startpressure);
d->cylinder[0].end.mbar = parsePressureToMbar(endpressure);
+ if (d->cylinder[0].end.mbar > d->cylinder[0].start.mbar)
+ d->cylinder[0].end.mbar = d->cylinder[0].start.mbar;
}
// gasmix for first cylinder
if (get_gas_string(d->cylinder[0].gasmix) != gasmix) {
int o2 = parseGasMixO2(gasmix);
int he = parseGasMixHE(gasmix);
// the QML code SHOULD only accept valid gas mixes, but just to make sure
- if (o2 >= 0 && o2 <= 100 &&
- he >= 0 && he <= 100 &&
- o2 + he <= 100) {
+ if (o2 >= 0 && o2 <= 1000 &&
+ he >= 0 && he <= 1000 &&
+ o2 + he <= 1000) {
diveChanged = true;
d->cylinder[0].gasmix.o2.permille = o2;
d->cylinder[0].gasmix.he.permille = he;
@@ -623,8 +696,8 @@ void QMLManager::saveChanges()
appendTextToLog(get_error_string());
return;
}
-
- setAccessingCloud(true);
+ if (prefs.git_local_only == false)
+ setAccessingCloud(true);
if (save_dives(fileName.toUtf8().data())) {
appendTextToLog(get_error_string());
setAccessingCloud(false);
@@ -772,16 +845,6 @@ void QMLManager::appendTextToLog(const QString &newText)
emit logTextChanged();
}
-bool QMLManager::saveCloudPassword() const
-{
- return m_saveCloudPassword;
-}
-
-void QMLManager::setSaveCloudPassword(bool saveCloudPassword)
-{
- m_saveCloudPassword = saveCloudPassword;
-}
-
bool QMLManager::locationServiceEnabled() const
{
return m_locationServiceEnabled;
@@ -824,7 +887,7 @@ QString QMLManager::cloudUserName() const
void QMLManager::setCloudUserName(const QString &cloudUserName)
{
- m_cloudUserName = cloudUserName;
+ m_cloudUserName = cloudUserName.toLower();
emit cloudUserNameChanged();
}
@@ -906,6 +969,13 @@ void QMLManager::showMap(const QString& location)
}
}
+#define MOBILEUSERMANUAL QUrl(QLatin1Literal("https://subsurface-divelog.org/documentation/subsurface-mobile-user-manual/"))
+
+void QMLManager::showUserManual()
+{
+ QDesktopServices::openUrl(MOBILEUSERMANUAL);
+}
+
// where in the QML dive list is that dive?
int QMLManager::getIndex(const QString &diveId)
{
@@ -953,3 +1023,14 @@ void QMLManager::setAccessingCloud(bool status)
m_accessingCloud = status;
emit accessingCloudChanged();
}
+
+qreal QMLManager::lastDevicePixelRatio()
+{
+ return m_lastDevicePixelRatio;
+}
+
+void QMLManager::screenChanged(QScreen *screen)
+{
+ m_lastDevicePixelRatio = screen->devicePixelRatio();
+ emit sendScreenChanged(screen);
+}