diff options
-rw-r--r-- | core/checkcloudconnection.cpp | 2 | ||||
-rw-r--r-- | core/git-access.c | 21 | ||||
-rw-r--r-- | core/git-access.h | 1 | ||||
-rw-r--r-- | core/pref.h | 1 | ||||
-rw-r--r-- | core/save-git.c | 2 | ||||
-rw-r--r-- | core/settings/qPrefCloudStorage.cpp | 3 | ||||
-rw-r--r-- | core/settings/qPrefCloudStorage.h | 5 | ||||
-rw-r--r-- | core/subsurfacestartup.c | 3 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 10 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 43 | ||||
-rw-r--r-- | tests/testqPrefCloudStorage.cpp | 15 |
11 files changed, 44 insertions, 62 deletions
diff --git a/core/checkcloudconnection.cpp b/core/checkcloudconnection.cpp index ce396ebf6..ffe2094f6 100644 --- a/core/checkcloudconnection.cpp +++ b/core/checkcloudconnection.cpp @@ -63,7 +63,7 @@ bool CheckCloudConnection::checkServer() } } git_storage_update_progress(qPrintable(tr("Cloud connection failed"))); - prefs.git_local_only = true; + git_local_only = true; if (verbose) qDebug() << "connection test to cloud server failed" << reply->error() << reply->errorString() << diff --git a/core/git-access.c b/core/git-access.c index 1fe71b80c..d71bed797 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -27,6 +27,15 @@ bool is_subsurface_cloud = false; +// the mobile app assumes that it shouldn't talk to the cloud +// the desktop app assumes that it should +#if defined(SUBSURFACE_MOBILE) +bool git_local_only = true; +#else +bool git_local_only = false; +#endif + + int (*update_progress_cb)(const char *) = NULL; static bool includes_string_caseinsensitive(const char *haystack, const char *needle) @@ -590,7 +599,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc char *proxy_string; git_config *conf; - if (prefs.git_local_only) { + if (git_local_only) { if (verbose) fprintf(stderr, "don't sync with remote - read from cache only\n"); return 0; @@ -650,7 +659,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc fprintf(stderr, "remote fetch failed (%s)\n", giterr_last() ? giterr_last()->message : "authentication failed"); // Since we failed to sync with online repository, enter offline mode - prefs.git_local_only = true; + git_local_only = true; error = 0; } else { error = check_remote_status(repo, origin, remote, branch, rt); @@ -676,7 +685,7 @@ static git_repository *update_local_repo(const char *localdir, const char *remot report_error("Unable to open git cache repository at %s: %s", localdir, giterr_last()->message); return NULL; } - if (!prefs.git_local_only) + if (!git_local_only) sync_with_remote(repo, remote, branch, rt); return repo; @@ -837,10 +846,10 @@ static struct git_repository *get_remote_repo(const char *localdir, const char * * remote cloud repo. */ git_repository *ret; - bool glo = prefs.git_local_only; - prefs.git_local_only = false; + bool glo = git_local_only; + git_local_only = false; ret = create_local_repo(localdir, remote, branch, rt); - prefs.git_local_only = glo; + git_local_only = glo; return ret; } diff --git a/core/git-access.h b/core/git-access.h index 77ff106a0..82927b87f 100644 --- a/core/git-access.h +++ b/core/git-access.h @@ -23,6 +23,7 @@ extern int git_load_dives(struct git_repository *, const char *); extern const char *get_sha(git_repository *repo, const char *branch); extern int do_git_save(git_repository *repo, const char *branch, const char *remote, bool select_only, bool create_empty); extern const char *saved_git_id; +extern bool git_local_only; extern void clear_git_id(void); extern void set_git_id(const struct git_oid *); extern enum remote_transport url_to_remote_transport(const char *remote); diff --git a/core/pref.h b/core/pref.h index 895006f7e..f66a463cc 100644 --- a/core/pref.h +++ b/core/pref.h @@ -96,7 +96,6 @@ struct preferences { const char *cloud_storage_pin; short cloud_timeout; short cloud_verification_status; - bool git_local_only; bool save_password_local; bool save_userid_local; const char *userid; diff --git a/core/save-git.c b/core/save-git.c index 2824b22ca..df5abf9e1 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -1271,7 +1271,7 @@ int do_git_save(git_repository *repo, const char *branch, const char *remote, bo return report_error("creating commit failed"); /* now sync the tree with the remote server */ - if (remote && !prefs.git_local_only) + if (remote && !git_local_only) return sync_with_remote(repo, remote, branch, url_to_remote_transport(remote)); return 0; } diff --git a/core/settings/qPrefCloudStorage.cpp b/core/settings/qPrefCloudStorage.cpp index dfb9c435b..4576de6fb 100644 --- a/core/settings/qPrefCloudStorage.cpp +++ b/core/settings/qPrefCloudStorage.cpp @@ -23,7 +23,6 @@ void qPrefCloudStorage::loadSync(bool doSync) disk_cloud_storage_pin(doSync); disk_cloud_timeout(doSync); disk_cloud_verification_status(doSync); - disk_git_local_only(doSync); disk_save_password_local(doSync); disk_save_userid_local(doSync); disk_userid(doSync); @@ -92,8 +91,6 @@ HANDLE_PREFERENCE_INT(CloudStorage, "timeout", cloud_timeout); HANDLE_PREFERENCE_INT(CloudStorage, "cloud_verification_status", cloud_verification_status); -HANDLE_PREFERENCE_BOOL(CloudStorage, "git_local_only", git_local_only); - HANDLE_PREFERENCE_BOOL(CloudStorage, "save_password_local", save_password_local); HANDLE_PREFERENCE_BOOL(CloudStorage, "save_userid_local", save_userid_local); diff --git a/core/settings/qPrefCloudStorage.h b/core/settings/qPrefCloudStorage.h index 91864afbc..f9a08372f 100644 --- a/core/settings/qPrefCloudStorage.h +++ b/core/settings/qPrefCloudStorage.h @@ -16,7 +16,6 @@ class qPrefCloudStorage : public QObject { Q_PROPERTY(QString cloud_storage_pin READ cloud_storage_pin WRITE set_cloud_storage_pin NOTIFY cloud_storage_pin_changed); Q_PROPERTY(int cloud_verification_status READ cloud_verification_status WRITE set_cloud_verification_status NOTIFY cloud_verification_status_changed); Q_PROPERTY(int cloud_timeout READ cloud_timeout WRITE set_cloud_timeout NOTIFY cloud_timeout_changed); - Q_PROPERTY(bool git_local_only READ git_local_only WRITE set_git_local_only NOTIFY git_local_only_changed); Q_PROPERTY(bool save_password_local READ save_password_local WRITE set_save_password_local NOTIFY save_password_local_changed); Q_PROPERTY(bool save_userid_local READ save_userid_local WRITE set_save_userid_local NOTIFY save_userid_local_changed); Q_PROPERTY(QString userid READ userid WRITE set_userid NOTIFY userid_changed); @@ -40,7 +39,6 @@ public: static QString cloud_storage_pin() { return prefs.cloud_storage_pin; } static int cloud_timeout() { return prefs.cloud_timeout; } static int cloud_verification_status() { return prefs.cloud_verification_status; } - static bool git_local_only() { return prefs.git_local_only; } static bool save_password_local() { return prefs.save_password_local; } static bool save_userid_local() { return prefs.save_userid_local; } static QString userid() { return prefs.userid; } @@ -54,7 +52,6 @@ public slots: static void set_cloud_storage_pin(const QString &value); static void set_cloud_timeout(int value); static void set_cloud_verification_status(int value); - static void set_git_local_only(bool value); static void set_save_password_local(bool value); static void set_save_userid_local(bool value); static void set_userid(const QString &value); @@ -68,7 +65,6 @@ signals: void cloud_storage_pin_changed(const QString &value); void cloud_timeout_changed(int value); void cloud_verification_status_changed(int value); - void git_local_only_changed(bool value); void save_password_local_changed(bool value); void save_userid_local_changed(bool value); void userid_changed(const QString &value); @@ -83,7 +79,6 @@ private: static void disk_cloud_storage_pin(bool doSync); static void disk_cloud_timeout(bool doSync); static void disk_cloud_verification_status(bool doSync); - static void disk_git_local_only(bool doSync); static void disk_save_password_local(bool doSync); static void disk_save_userid_local(bool doSync); static void disk_userid(bool doSync); diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c index f3f9e4bda..7e7ba0c9e 100644 --- a/core/subsurfacestartup.c +++ b/core/subsurfacestartup.c @@ -12,9 +12,6 @@ struct preferences prefs, git_prefs; struct preferences default_prefs = { .cloud_base_url = "https://cloud.subsurface-divelog.org/", -#if defined(SUBSURFACE_MOBILE) - .git_local_only = true, -#endif .units = SI_UNITS, .unit_system = METRIC, .coordinates_traditional = true, diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 0623af50b..9547afacf 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -660,7 +660,7 @@ void MainWindow::on_actionCloudstoragesave_triggered() void MainWindow::on_actionCloudOnline_triggered() { bool isOffline = !ui.actionCloudOnline->isChecked(); - if (isOffline == prefs.git_local_only) + if (isOffline == git_local_only) return; // Refuse to go online if there is an edit in progress @@ -673,7 +673,7 @@ void MainWindow::on_actionCloudOnline_triggered() return; } - prefs.git_local_only = isOffline; + git_local_only = isOffline; if (!isOffline) { // User requests to go online. Try to sync cloud storage if (unsaved_changes()) { @@ -689,7 +689,7 @@ void MainWindow::on_actionCloudOnline_triggered() // If there are no unsaved changes, let's just try to load the remote cloud on_actionCloudstorageopen_triggered(); } - if (prefs.git_local_only) + if (git_local_only) report_error(qPrintable(tr("Failure taking cloud storage online"))); } @@ -747,7 +747,7 @@ void MainWindow::updateCloudOnlineStatus() bool is_cloud = existing_filename && prefs.cloud_git_url && prefs.cloud_verification_status == qPref::CS_VERIFIED && strstr(existing_filename, prefs.cloud_git_url); ui.actionCloudOnline->setEnabled(is_cloud); - ui.actionCloudOnline->setChecked(is_cloud && !prefs.git_local_only); + ui.actionCloudOnline->setChecked(is_cloud && !git_local_only); } void MainWindow::setCurrentFile(const char *f) @@ -1729,7 +1729,7 @@ QString MainWindow::displayedFilename(QString fullFilename) if (fullFilename.contains(prefs.cloud_git_url)) { QString email = fileName.left(fileName.indexOf('[')); - if (prefs.git_local_only) + if (git_local_only) return tr("[local cache for] %1").arg(email); else return tr("[cloud storage for] %1").arg(email); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 44407c1e6..f5e7cff11 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -253,10 +253,10 @@ void QMLManager::openLocalThenRemote(QString url) clear_dive_file_data(); setNotificationText(tr("Open local dive data file")); QByteArray fileNamePrt = QFile::encodeName(url); - bool glo = prefs.git_local_only; - prefs.git_local_only = true; + bool glo = git_local_only; + git_local_only = true; int error = parse_file(fileNamePrt.data(), &dive_table); - prefs.git_local_only = glo; + git_local_only = glo; if (error) { appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); setNotificationText(tr("Opening local data file failed")); @@ -299,11 +299,11 @@ void QMLManager::openLocalThenRemote(QString url) } if (QMLPrefs::instance()->oldStatus() == qPref::CS_NOCLOUD) { // if we switch to credentials from CS_NOCLOUD, we take things online temporarily - prefs.git_local_only = false; + git_local_only = false; appendTextToLog(QStringLiteral("taking things online to be able to switch to cloud account")); } set_filename(fileNamePrt.data()); - if (prefs.git_local_only) { + if (git_local_only) { appendTextToLog(QStringLiteral("have cloud credentials, but user asked not to connect to network")); alreadySaving = false; } else { @@ -373,7 +373,7 @@ void QMLManager::finishSetup() // Initialize cloud credentials. QMLPrefs::instance()->setCloudUserName(qPrefCloudStorage::cloud_storage_email()); QMLPrefs::instance()->setCloudPassword(qPrefCloudStorage::cloud_storage_password()); - setSyncToCloud(!prefs.git_local_only); + setSyncToCloud(!git_local_only); QMLPrefs::instance()->setCredentialStatus((qPref::cloud_status) prefs.cloud_verification_status); // if the cloud credentials are valid, we should get the GPS Webservice ID as well QString url; @@ -505,8 +505,8 @@ void QMLManager::saveCloudCredentials() alreadySaving = true; // since we changed credentials, we need to try to connect to the cloud, regardless // of whether we're in offline mode or not, to make sure the repository is synced - currentGitLocalOnly = prefs.git_local_only; - prefs.git_local_only = false; + currentGitLocalOnly = git_local_only; + git_local_only = false; openLocalThenRemote(url); } else if (prefs.cloud_verification_status == qPref::CS_NEED_TO_VERIFY && !QMLPrefs::instance()->cloudPin().isEmpty()) { @@ -708,13 +708,13 @@ successful_exit: saveChangesLocal(); if (m_syncToCloud == false) { appendTextToLog(QStringLiteral("taking things back offline now that storage is synced")); - prefs.git_local_only = m_syncToCloud; + git_local_only = m_syncToCloud; } } // if we got here just for an initial connection to the cloud, reset to offline if (currentGitLocalOnly) { currentGitLocalOnly = false; - prefs.git_local_only = true; + git_local_only = true; } return; } @@ -724,7 +724,7 @@ void QMLManager::revertToNoCloudIfNeeded() if (currentGitLocalOnly) { // we tried to connect to the cloud for the first time and that failed currentGitLocalOnly = false; - prefs.git_local_only = true; + git_local_only = true; } if (QMLPrefs::instance()->oldStatus() == qPref::CS_NOCLOUD) { // we tried to switch to a cloud account and had previously used local data, @@ -734,7 +734,7 @@ void QMLManager::revertToNoCloudIfNeeded() // dives if (m_syncToCloud == false) { appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed")); - prefs.git_local_only = m_syncToCloud; + git_local_only = m_syncToCloud; } free((void *)prefs.cloud_storage_email); prefs.cloud_storage_email = NULL; @@ -1240,16 +1240,16 @@ void QMLManager::saveChangesLocal() return; } alreadySaving = true; - bool glo = prefs.git_local_only; - prefs.git_local_only = true; + bool glo = git_local_only; + git_local_only = true; if (save_dives(existing_filename)) { setNotificationText(consumeError()); set_filename(NULL); - prefs.git_local_only = glo; + git_local_only = glo; alreadySaving = false; return; } - prefs.git_local_only = glo; + git_local_only = glo; mark_divelist_changed(false); alreadySaving = false; } else { @@ -1272,7 +1272,7 @@ void QMLManager::saveChangesCloud(bool forceRemoteSync) saveChangesLocal(); // if the user asked not to push to the cloud we are done - if (prefs.git_local_only && !forceRemoteSync) + if (git_local_only && !forceRemoteSync) return; if (!m_loadFromCloud) { @@ -1280,12 +1280,12 @@ void QMLManager::saveChangesCloud(bool forceRemoteSync) return; } - bool glo = prefs.git_local_only; - prefs.git_local_only = false; + bool glo = git_local_only; + git_local_only = false; alreadySaving = true; loadDivesWithValidCredentials(); alreadySaving = false; - prefs.git_local_only = glo; + git_local_only = glo; } bool QMLManager::undoDelete(int id) @@ -1535,8 +1535,7 @@ void QMLManager::setNotificationText(QString text) void QMLManager::setSyncToCloud(bool status) { m_syncToCloud = status; - prefs.git_local_only = !status; - qPrefCloudStorage::set_git_local_only(prefs.git_local_only); + git_local_only = !status; emit syncToCloudChanged(); } diff --git a/tests/testqPrefCloudStorage.cpp b/tests/testqPrefCloudStorage.cpp index 2ca2bb81a..9d726ab47 100644 --- a/tests/testqPrefCloudStorage.cpp +++ b/tests/testqPrefCloudStorage.cpp @@ -29,7 +29,6 @@ void TestQPrefCloudStorage::test_struct_get() prefs.cloud_storage_pin = copy_qstring("a pin"); prefs.cloud_timeout = 117; prefs.cloud_verification_status = qPref::CS_NOCLOUD; - prefs.git_local_only = true; prefs.save_password_local = true; prefs.save_userid_local = true; prefs.userid = copy_qstring("my user"); @@ -43,7 +42,6 @@ void TestQPrefCloudStorage::test_struct_get() QCOMPARE(tst->cloud_storage_pin(), QString(prefs.cloud_storage_pin)); QCOMPARE(tst->cloud_timeout(), (int)prefs.cloud_timeout); QCOMPARE(tst->cloud_verification_status(), (int)prefs.cloud_verification_status); - QCOMPARE(tst->git_local_only(), prefs.git_local_only); QCOMPARE(tst->save_password_local(), prefs.save_password_local); QCOMPARE(tst->save_userid_local(), prefs.save_userid_local); QCOMPARE(tst->userid(), QString(prefs.userid)); @@ -63,7 +61,6 @@ void TestQPrefCloudStorage::test_set_struct() tst->set_cloud_storage_pin("t2 pin"); tst->set_cloud_timeout(123); tst->set_cloud_verification_status(qPref::CS_VERIFIED); - tst->set_git_local_only(false); tst->set_save_password_local(false); tst->set_save_userid_local(false); tst->set_userid("t2 user"); @@ -76,7 +73,6 @@ void TestQPrefCloudStorage::test_set_struct() QCOMPARE(QString(prefs.cloud_storage_pin), QString("t2 pin")); QCOMPARE((int)prefs.cloud_timeout, 123); QCOMPARE((int)prefs.cloud_verification_status, (int)qPref::CS_VERIFIED); - QCOMPARE(prefs.git_local_only, false); QCOMPARE(prefs.save_password_local, false); QCOMPARE(prefs.save_userid_local, false); QCOMPARE(QString(prefs.userid), QString("t2 user")); @@ -100,7 +96,6 @@ void TestQPrefCloudStorage::test_set_load_struct() tst->set_cloud_storage_pin("t3 pin"); tst->set_cloud_timeout(321); tst->set_cloud_verification_status(qPref::CS_NOCLOUD); - tst->set_git_local_only(true); tst->set_save_userid_local(true); tst->set_userid("t3 user"); @@ -113,7 +108,6 @@ void TestQPrefCloudStorage::test_set_load_struct() prefs.cloud_storage_pin = copy_qstring("error1"); prefs.cloud_timeout = 324; prefs.cloud_verification_status = qPref::CS_VERIFIED; - prefs.git_local_only = false; prefs.save_password_local = false; prefs.save_userid_local = false; prefs.userid = copy_qstring("error1"); @@ -126,7 +120,6 @@ void TestQPrefCloudStorage::test_set_load_struct() QCOMPARE(QString(prefs.cloud_storage_pin), QString("t3 pin")); QCOMPARE((int)prefs.cloud_timeout, 321); QCOMPARE((int)prefs.cloud_verification_status, (int)qPref::CS_NOCLOUD); - QCOMPARE(prefs.git_local_only, true); QCOMPARE(prefs.save_password_local, true); QCOMPARE(prefs.save_userid_local, true); QCOMPARE(QString(prefs.userid), QString("t3 user")); @@ -153,7 +146,6 @@ void TestQPrefCloudStorage::test_struct_disk() prefs.cloud_storage_pin = copy_qstring("t4 pin"); prefs.cloud_timeout = 123; prefs.cloud_verification_status = qPref::CS_VERIFIED; - prefs.git_local_only = true; prefs.save_userid_local = true; prefs.userid = copy_qstring("t4 user"); @@ -168,7 +160,6 @@ void TestQPrefCloudStorage::test_struct_disk() prefs.cloud_storage_pin = copy_qstring("error1"); prefs.cloud_timeout = 324; prefs.cloud_verification_status = qPref::CS_VERIFIED; - prefs.git_local_only = false; prefs.save_password_local = false; prefs.save_userid_local = false; prefs.userid = copy_qstring("error1"); @@ -182,7 +173,6 @@ void TestQPrefCloudStorage::test_struct_disk() QCOMPARE(QString(prefs.cloud_storage_pin), QString("t4 pin")); QCOMPARE((int)prefs.cloud_timeout, 123); QCOMPARE((int)prefs.cloud_verification_status, (int)qPref::CS_VERIFIED); - QCOMPARE(prefs.git_local_only, true); QCOMPARE(prefs.save_password_local, true); QCOMPARE(prefs.save_userid_local, true); QCOMPARE(QString(prefs.userid), QString("t4 user")); @@ -229,11 +219,6 @@ void TestQPrefCloudStorage::test_oldPreferences() cloud->set_cloud_storage_email("tomaz@gmail.com"); TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@gmail.com")); - cloud->set_git_local_only(true); - TEST(cloud->git_local_only(), true); - cloud->set_git_local_only(false); - TEST(cloud->git_local_only(), false); - // Why there's new password and password on the prefs? cloud->set_cloud_storage_newpassword("ABCD"); TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCD")); |