diff options
-rw-r--r-- | core/pref.h | 1 | ||||
-rw-r--r-- | core/settings/qPrefCloudStorage.cpp | 3 | ||||
-rw-r--r-- | core/settings/qPrefCloudStorage.h | 5 | ||||
-rw-r--r-- | tests/testqPrefCloudStorage.cpp | 19 |
4 files changed, 28 insertions, 0 deletions
diff --git a/core/pref.h b/core/pref.h index 2e11efbe4..2fbe1762f 100644 --- a/core/pref.h +++ b/core/pref.h @@ -87,6 +87,7 @@ struct preferences { int animation_speed; // ********** CloudStorage ********** + bool cloud_auto_sync; const char *cloud_base_url; const char *cloud_git_url; const char *cloud_storage_email; diff --git a/core/settings/qPrefCloudStorage.cpp b/core/settings/qPrefCloudStorage.cpp index ef7605d97..8bbd91aec 100644 --- a/core/settings/qPrefCloudStorage.cpp +++ b/core/settings/qPrefCloudStorage.cpp @@ -16,6 +16,7 @@ qPrefCloudStorage *qPrefCloudStorage::instance() void qPrefCloudStorage::loadSync(bool doSync) { + disk_cloud_auto_sync(doSync); disk_cloud_base_url(doSync); disk_cloud_storage_email(doSync); disk_cloud_storage_email_encoded(doSync); @@ -26,6 +27,8 @@ void qPrefCloudStorage::loadSync(bool doSync) disk_save_password_local(doSync); } +HANDLE_PREFERENCE_BOOL(CloudStorage, "cloud_auto_sync", cloud_auto_sync); + void qPrefCloudStorage::set_cloud_base_url(const QString &value) { if (value != prefs.cloud_base_url) { diff --git a/core/settings/qPrefCloudStorage.h b/core/settings/qPrefCloudStorage.h index 631eaa670..841005b76 100644 --- a/core/settings/qPrefCloudStorage.h +++ b/core/settings/qPrefCloudStorage.h @@ -7,6 +7,7 @@ class qPrefCloudStorage : public QObject { Q_OBJECT + Q_PROPERTY(bool cloud_auto_sync READ cloud_auto_sync WRITE set_cloud_auto_sync NOTIFY cloud_auto_syncChanged); Q_PROPERTY(QString cloud_base_url READ cloud_base_url WRITE set_cloud_base_url NOTIFY cloud_base_urlChanged); Q_PROPERTY(QString cloud_git_url READ cloud_git_url); Q_PROPERTY(QString cloud_storage_email READ cloud_storage_email WRITE set_cloud_storage_email NOTIFY cloud_storage_emailChanged); @@ -36,6 +37,7 @@ public: }; Q_ENUM(cloud_status); + static bool cloud_auto_sync() { return prefs.cloud_auto_sync; } static QString cloud_base_url() { return prefs.cloud_base_url; } static QString cloud_git_url() { return prefs.cloud_git_url; } static QString cloud_storage_email() { return prefs.cloud_storage_email; } @@ -47,6 +49,7 @@ public: static bool save_password_local() { return prefs.save_password_local; } public slots: + static void set_cloud_auto_sync(bool value); static void set_cloud_base_url(const QString &value); static void set_cloud_storage_email(const QString &value); static void set_cloud_storage_email_encoded(const QString &value); @@ -57,6 +60,7 @@ public slots: static void set_save_password_local(bool value); signals: + void cloud_auto_syncChanged(bool value); void cloud_base_urlChanged(const QString &value); void cloud_storage_emailChanged(const QString &value); void cloud_storage_email_encodedChanged(const QString &value); @@ -68,6 +72,7 @@ signals: private: // functions to load/sync variable with disk + static void disk_cloud_auto_sync(bool doSync); static void disk_cloud_base_url(bool doSync); static void disk_cloud_storage_email(bool doSync); static void disk_cloud_storage_email_encoded(bool doSync); diff --git a/tests/testqPrefCloudStorage.cpp b/tests/testqPrefCloudStorage.cpp index f8f0fe00f..d4358349d 100644 --- a/tests/testqPrefCloudStorage.cpp +++ b/tests/testqPrefCloudStorage.cpp @@ -21,6 +21,7 @@ void TestQPrefCloudStorage::test_struct_get() auto tst = qPrefCloudStorage::instance(); + prefs.cloud_auto_sync = true; prefs.cloud_base_url = copy_qstring("new url"); prefs.cloud_git_url = copy_qstring("new again url"); prefs.cloud_storage_email = copy_qstring("myEmail"); @@ -31,6 +32,7 @@ void TestQPrefCloudStorage::test_struct_get() prefs.cloud_verification_status = qPrefCloudStorage::CS_NOCLOUD; prefs.save_password_local = true; + QCOMPARE(tst->cloud_auto_sync(), prefs.cloud_auto_sync); QCOMPARE(tst->cloud_base_url(), QString(prefs.cloud_base_url)); QCOMPARE(tst->cloud_git_url(), QString(prefs.cloud_git_url)); QCOMPARE(tst->cloud_storage_email(), QString(prefs.cloud_storage_email)); @@ -48,6 +50,7 @@ void TestQPrefCloudStorage::test_set_struct() auto tst = qPrefCloudStorage::instance(); + tst->set_cloud_auto_sync(false); tst->set_cloud_base_url("t2 base"); tst->set_cloud_storage_email("t2 email"); tst->set_cloud_storage_email_encoded("t2 email2"); @@ -57,6 +60,7 @@ void TestQPrefCloudStorage::test_set_struct() tst->set_cloud_verification_status(qPrefCloudStorage::CS_VERIFIED); tst->set_save_password_local(false); + QCOMPARE(prefs.cloud_auto_sync, false); QCOMPARE(QString(prefs.cloud_base_url), QString("t2 base")); QCOMPARE(QString(prefs.cloud_storage_email), QString("t2 email")); QCOMPARE(QString(prefs.cloud_storage_email_encoded), QString("t2 email2")); @@ -80,11 +84,13 @@ void TestQPrefCloudStorage::test_set_load_struct() tst->set_cloud_storage_email("t3 email"); tst->set_cloud_storage_email_encoded("t3 email2"); tst->set_save_password_local(true); + tst->set_cloud_auto_sync(true); tst->set_cloud_storage_password("t3 pass2"); tst->set_cloud_storage_pin("t3 pin"); tst->set_cloud_timeout(321); tst->set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD); + prefs.cloud_auto_sync = false; prefs.cloud_base_url = copy_qstring("error1"); prefs.cloud_git_url = copy_qstring("error1"); prefs.cloud_storage_email = copy_qstring("error1"); @@ -96,6 +102,7 @@ void TestQPrefCloudStorage::test_set_load_struct() prefs.save_password_local = false; tst->load(); + QCOMPARE(prefs.cloud_auto_sync, true); QCOMPARE(QString(prefs.cloud_base_url), QString("t3 base")); QCOMPARE(QString(prefs.cloud_storage_email), QString("t3 email")); QCOMPARE(QString(prefs.cloud_storage_email_encoded), QString("t3 email2")); @@ -119,6 +126,7 @@ void TestQPrefCloudStorage::test_struct_disk() prefs.cloud_storage_email = copy_qstring("t4 email"); prefs.cloud_storage_email_encoded = copy_qstring("t4 email2"); prefs.save_password_local = true; + prefs.cloud_auto_sync = true; prefs.cloud_storage_password = copy_qstring("t4 pass2"); prefs.cloud_storage_pin = copy_qstring("t4 pin"); prefs.cloud_timeout = 123; @@ -126,6 +134,7 @@ void TestQPrefCloudStorage::test_struct_disk() tst->sync(); + prefs.cloud_auto_sync = false; prefs.cloud_base_url = copy_qstring("error1"); prefs.cloud_git_url = copy_qstring("error1"); prefs.cloud_storage_email = copy_qstring("error1"); @@ -138,6 +147,7 @@ void TestQPrefCloudStorage::test_struct_disk() tst->load(); + QCOMPARE(prefs.cloud_auto_sync, true); QCOMPARE(QString(prefs.cloud_base_url), QString("t4 base")); QCOMPARE(QString(prefs.cloud_storage_email), QString("t4 email")); QCOMPARE(QString(prefs.cloud_storage_email_encoded), QString("t4 email2")); @@ -189,6 +199,11 @@ void TestQPrefCloudStorage::test_oldPreferences() cloud->set_cloud_storage_password("ABCABC"); TEST(cloud->cloud_storage_password(), QStringLiteral("ABCABC")); + cloud->set_cloud_auto_sync(true); + TEST(cloud->cloud_auto_sync(), true); + cloud->set_cloud_auto_sync(false); + TEST(cloud->cloud_auto_sync(), false); + cloud->set_save_password_local(true); TEST(cloud->save_password_local(), true); cloud->set_save_password_local(false); @@ -210,6 +225,7 @@ void TestQPrefCloudStorage::test_signals() QSignalSpy spy6(qPrefCloudStorage::instance(), SIGNAL(cloud_timeoutChanged(int))); QSignalSpy spy7(qPrefCloudStorage::instance(), SIGNAL(cloud_verification_statusChanged(int))); QSignalSpy spy9(qPrefCloudStorage::instance(), SIGNAL(save_password_localChanged(bool))); + QSignalSpy spy10(qPrefCloudStorage::instance(), SIGNAL(cloud_auto_syncChanged(bool))); qPrefCloudStorage::set_cloud_base_url("signal url"); qPrefCloudStorage::set_cloud_storage_email("signal myEmail"); @@ -219,6 +235,7 @@ void TestQPrefCloudStorage::test_signals() qPrefCloudStorage::set_cloud_timeout(11); qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_VERIFIED); qPrefCloudStorage::set_save_password_local(true); + qPrefCloudStorage::set_cloud_auto_sync(true); QCOMPARE(spy1.count(), 1); QCOMPARE(spy2.count(), 1); @@ -228,6 +245,7 @@ void TestQPrefCloudStorage::test_signals() QCOMPARE(spy6.count(), 1); QCOMPARE(spy7.count(), 1); QCOMPARE(spy9.count(), 1); + QCOMPARE(spy10.count(), 1); QVERIFY(spy1.takeFirst().at(0).toString() == "signal url"); QVERIFY(spy2.takeFirst().at(0).toString() == "signal myEmail"); @@ -237,6 +255,7 @@ void TestQPrefCloudStorage::test_signals() QVERIFY(spy6.takeFirst().at(0).toInt() == 11); QVERIFY(spy7.takeFirst().at(0).toInt() == qPrefCloudStorage::CS_VERIFIED); QVERIFY(spy9.takeFirst().at(0).toBool() == true); + QVERIFY(spy10.takeFirst().at(0).toBool() == true); } QTEST_MAIN(TestQPrefCloudStorage) |