diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index fd598683f..09b013536 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -49,6 +49,11 @@ bool GpsLocation::hasInstance() return m_Instance != NULL; } +QSettings *GpsLocation::getSettings() +{ + return geoSettings; +} + GpsLocation::~GpsLocation() { m_Instance = NULL; @@ -404,6 +409,23 @@ void GpsLocation::deleteGpsFix(qint64 when) } #ifdef SUBSURFACE_MOBILE +extern "C" +const char *gpsGetString(int idx, const char **name) +{ + // check if we are supposed to store the data to the cloud and return + // the nth GPS fix, if it exists + if (!name || !prefs.store_gps_cloud || + !GpsLocation::hasInstance() || GpsLocation::instance()->getGpsNum() <= idx) + return NULL; + QSettings *geoSettings = GpsLocation::instance()->getSettings(); + QString text = QString("when %1 lat %2 lon %3").arg(geoSettings->value(QStringLiteral("gpsFix%1_time").arg(idx)).toString()) + .arg(geoSettings->value(QStringLiteral("gpsFix%1_lat").arg(idx)).toString()) + .arg(geoSettings->value(QStringLiteral("gpsFix%1_lon").arg(idx)).toString()); + QString fixName = geoSettings->value(QStringLiteral("gpsFix%1_name").arg(idx)).toString(); + *name = strdup(fixName.toUtf8().constData()); + return strdup(text.toUtf8().constData()); +} + void GpsLocation::clearGpsData() { m_trackers.clear(); diff --git a/core/gpslocation.h b/core/gpslocation.h index d376c5ec7..b3bc83791 100644 --- a/core/gpslocation.h +++ b/core/gpslocation.h @@ -37,7 +37,7 @@ public: int getGpsNum() const; bool hasLocationsSource(); QString currentPosition(); - + QSettings *getSettings(); QMap currentGPSInfo() const; private: diff --git a/core/pref.h b/core/pref.h index 344308549..e7916b4c0 100644 --- a/core/pref.h +++ b/core/pref.h @@ -138,6 +138,7 @@ struct preferences { // ********** LocationService ********** int time_threshold; int distance_threshold; + int store_gps_cloud; // ********** Network ********** bool proxy_auth; diff --git a/core/save-git.c b/core/save-git.c index ec594f131..f1e5395a4 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -916,6 +916,29 @@ static void save_divesites(git_repository *repo, struct dir *tree) } } +#if defined(SUBSURFACE_MOBILE) +// from gpslocation.cpp +extern const char *gpsGetString(int idx, const char **name); + +static void save_gps(git_repository *repo, struct dir *tree) +{ + struct membuffer b = { 0 }; + int i = 0; + const char *string; + const char *name = NULL; + do { + string = gpsGetString(i++, &name); + if (string) { + put_string(&b, string); + show_utf8(&b, " name ", name, "\n"); + free((void *)string); + free((void *)name); + } + } while (string != NULL); + blob_insert(repo, tree, &b, "02-Gps"); +} +#endif + static int create_git_tree(git_repository *repo, struct dir *root, bool select_only, bool cached_ok) { int i; @@ -927,6 +950,10 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o save_divesites(repo, root); +#if defined(SUBSURFACE_MOBILE) + save_gps(repo, root); +#endif + for (i = 0; i < trip_table.nr; ++i) trip_table.trips[i]->saved = 0; diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c index c5fb7b611..71c7b0e37 100644 --- a/core/subsurfacestartup.c +++ b/core/subsurfacestartup.c @@ -93,6 +93,7 @@ struct preferences default_prefs = { .vpmb_conservatism = 3, .distance_threshold = 100, .time_threshold = 300, + .store_gps_cloud = 0, #if defined(SUBSURFACE_MOBILE) .cloud_timeout = 10, #else diff --git a/mobile-widgets/qml/Settings.qml b/mobile-widgets/qml/Settings.qml index b7d5dd0d7..af998e205 100644 --- a/mobile-widgets/qml/Settings.qml +++ b/mobile-widgets/qml/Settings.qml @@ -618,17 +618,43 @@ TemplatePage { TemplateLabel { text: qsTr("Display Developer menu") Layout.fillWidth: true - //Layout.preferredWidth: gridWidth * 0.75 } SsrfSwitch { - id: developerButton checked: PrefDisplay.show_developer - //sLayout.preferredWidth: gridWidth * 0.25 onClicked: { PrefDisplay.show_developer = checked } } } + TemplateLine { + visible: sectionAdvanced.isExpanded + } + GridLayout { + id: gpsToCloud + visible: sectionAdvanced.isExpanded + width: parent.width + columns: 2 + TemplateLabel { + text: qsTr("GPS data") + font.pointSize: subsurfaceTheme.headingPointSize + font.weight: Font.Light + Layout.topMargin: Kirigami.Units.largeSpacing + Layout.bottomMargin: Kirigami.Units.largeSpacing / 2 + Layout.columnSpan: 2 + } + TemplateLabel { + text: qsTr("Store data to cloud") + Layout.fillWidth: true + } + SsrfSwitch { + checked: manager.storeGpsToCoud() + onClicked: { + manager.setStoreGpsToCloud(checked) + if (checked) + manager.saveChangesCloud(true) + } + } + } } } } diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 648532d7d..47bff213b 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -2266,3 +2266,16 @@ QString QMLManager::getSyncState() const return tr("(changes synced locally)"); return tr("(synced with cloud)"); } + +void QMLManager::setStoreGpsToCloud(int value) +{ + prefs.store_gps_cloud = value; + if (value) + // that's not really true, but this way the Gps section gets written + mark_divelist_changed(true); +} + +int QMLManager::storeGpsToCloud() +{ + return prefs.store_gps_cloud; +} diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 250493e79..16368df39 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -241,6 +241,8 @@ public slots: QString getProductVendorConnectionIdx(android_usb_serial_device_descriptor descriptor); #endif void divesChanged(const QVector &dives, DiveField field); + int storeGpsToCloud(); + void setStoreGpsToCloud(int value); private: BuddyCompletionModel buddyModel;