aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/settings/qPref.cpp1
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp75
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h29
-rw-r--r--desktop-widgets/updatemanager.cpp18
-rw-r--r--subsurface-helper.cpp1
-rw-r--r--tests/testpreferences.cpp26
6 files changed, 28 insertions, 122 deletions
diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp
index ede230236..c5f2e663c 100644
--- a/core/settings/qPref.cpp
+++ b/core/settings/qPref.cpp
@@ -22,6 +22,7 @@ void qPref::loadSync(bool doSync)
// qPrefFaceook does not use disk.
qPrefProxy::instance()->loadSync(doSync);
qPrefUnits::instance()->loadSync(doSync);
+ qPrefUpdateManager::instance()->loadSync(doSync);
}
const QString qPref::canonical_version() const
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index c31d3831b..16a354dda 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -8,71 +8,6 @@
#include "core/qthelper.h"
#include "core/prefs-macros.h"
-UpdateManagerSettings::UpdateManagerSettings(QObject *parent) : QObject(parent)
-{
-
-}
-
-bool UpdateManagerSettings::dontCheckForUpdates() const
-{
- return prefs.update_manager.dont_check_for_updates;
-}
-
-bool UpdateManagerSettings::dontCheckExists() const
-{
- return prefs.update_manager.dont_check_exists;
-}
-
-QString UpdateManagerSettings::lastVersionUsed() const
-{
- return prefs.update_manager.last_version_used;
-}
-
-QDate UpdateManagerSettings::nextCheck() const
-{
- return QDate::fromString(QString(prefs.update_manager.next_check), "dd/MM/yyyy");
-}
-
-void UpdateManagerSettings::setDontCheckForUpdates(bool value)
-{
- if (value == prefs.update_manager.dont_check_for_updates)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("DontCheckForUpdates", value);
- prefs.update_manager.dont_check_for_updates = value;
- prefs.update_manager.dont_check_exists = true;
- emit dontCheckForUpdatesChanged(value);
-}
-
-void UpdateManagerSettings::setLastVersionUsed(const QString& value)
-{
- if (value == prefs.update_manager.last_version_used)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("LastVersionUsed", value);
- free((void *)prefs.update_manager.last_version_used);
- prefs.update_manager.last_version_used = copy_qstring(value);
- emit lastVersionUsedChanged(value);
-}
-
-void UpdateManagerSettings::setNextCheck(const QDate& date)
-{
- if (date.toString() == prefs.update_manager.next_check)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("NextCheck", date);
- free((void *)prefs.update_manager.next_check);
- prefs.update_manager.next_check = copy_qstring(date.toString("dd/MM/yyyy"));
- emit nextCheckChanged(date);
-}
-
-
PartialPressureGasSettings::PartialPressureGasSettings(QObject* parent):
QObject(parent)
{
@@ -1112,7 +1047,7 @@ QObject(parent),
language_settings(new LanguageSettingsObjectWrapper(this)),
animation_settings(new qPrefAnimations(this)),
location_settings(new LocationServiceSettingsObjectWrapper(this)),
- update_manager_settings(new UpdateManagerSettings(this)),
+ update_manager_settings(new qPrefUpdateManager(this)),
dive_computer_settings(new qPrefDiveComputer(this))
{
}
@@ -1205,13 +1140,7 @@ void SettingsObjectWrapper::load()
qPrefDivePlanner::instance()->load();
qPrefDiveComputer::instance()->load();
-
- s.beginGroup("UpdateManager");
- prefs.update_manager.dont_check_exists = s.contains("DontCheckForUpdates");
- GET_BOOL("DontCheckForUpdates", update_manager.dont_check_for_updates);
- GET_TXT("LastVersionUsed", update_manager.last_version_used);
- prefs.update_manager.next_check = copy_qstring(s.value("NextCheck").toDate().toString("dd/MM/yyyy"));
- s.endGroup();
+ qPrefUpdateManager::instance()->load();
s.beginGroup("Language");
GET_BOOL("UseSystemLanguage", locale.use_system_language);
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index 54add731d..a648658f1 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -13,31 +13,6 @@
* and QWidget frontends. This class will be huge, since
* I need tons of properties, one for each option. */
-class UpdateManagerSettings : public QObject {
- Q_OBJECT
- Q_PROPERTY(bool dont_check_for_updates READ dontCheckForUpdates WRITE setDontCheckForUpdates NOTIFY dontCheckForUpdatesChanged)
- Q_PROPERTY(QString last_version_used READ lastVersionUsed WRITE setLastVersionUsed NOTIFY lastVersionUsedChanged)
- Q_PROPERTY(QDate next_check READ nextCheck WRITE nextCheckChanged)
-public:
- UpdateManagerSettings(QObject *parent);
- bool dontCheckForUpdates() const;
- bool dontCheckExists() const;
- QString lastVersionUsed() const;
- QDate nextCheck() const;
-
-public slots:
- void setDontCheckForUpdates(bool value);
- void setLastVersionUsed(const QString& value);
- void setNextCheck(const QDate& date);
-
-signals:
- void dontCheckForUpdatesChanged(bool value);
- void lastVersionUsedChanged(const QString& value);
- void nextCheckChanged(const QDate& date);
-private:
- const QString group = QStringLiteral("UpdateManager");
-};
-
/* Control the state of the Partial Pressure Graphs preferences */
class PartialPressureGasSettings : public QObject {
Q_OBJECT
@@ -366,7 +341,7 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(qPrefAnimations* animation MEMBER animation_settings CONSTANT)
Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT)
- Q_PROPERTY(UpdateManagerSettings* update MEMBER update_manager_settings CONSTANT)
+ Q_PROPERTY(qPrefUpdateManager* update MEMBER update_manager_settings CONSTANT)
Q_PROPERTY(qPrefDiveComputer* dive_computer MEMBER dive_computer_settings CONSTANT)
public:
static SettingsObjectWrapper *instance();
@@ -384,7 +359,7 @@ public:
LanguageSettingsObjectWrapper *language_settings;
qPrefAnimations *animation_settings;
LocationServiceSettingsObjectWrapper *location_settings;
- UpdateManagerSettings *update_manager_settings;
+ qPrefUpdateManager *update_manager_settings;
qPrefDiveComputer *dive_computer_settings;
void sync();
diff --git a/desktop-widgets/updatemanager.cpp b/desktop-widgets/updatemanager.cpp
index db4cd5ecc..ccf70a67c 100644
--- a/desktop-widgets/updatemanager.cpp
+++ b/desktop-widgets/updatemanager.cpp
@@ -14,17 +14,17 @@ UpdateManager::UpdateManager(QObject *parent) :
QObject(parent),
isAutomaticCheck(false)
{
- auto update_settings = SettingsObjectWrapper::instance()->update_manager_settings;
+ auto update_settings = qPrefUpdateManager::instance();
- if (update_settings->dontCheckForUpdates())
+ if (update_settings->dont_check_for_updates())
return;
- if (update_settings->lastVersionUsed() == subsurface_git_version() &&
- update_settings->nextCheck() > QDate::currentDate())
+ if (update_settings->last_version_used() == subsurface_git_version() &&
+ update_settings->next_check() > QDate::currentDate())
return;
- update_settings->setLastVersionUsed(subsurface_git_version());
- update_settings->setNextCheck(QDate::currentDate().addDays(14));
+ update_settings->set_last_version_used(subsurface_git_version());
+ update_settings->set_next_check(QDate::currentDate().addDays(14));
checkForUpdates(true);
}
@@ -108,8 +108,8 @@ void UpdateManager::requestReceived()
msgbox.exec();
}
if (isAutomaticCheck) {
- auto update_settings = SettingsObjectWrapper::instance()->update_manager_settings;
- if (!update_settings->dontCheckExists()) {
+ auto update_settings = qPrefUpdateManager::instance();
+ if (!update_settings->dont_check_exists()) {
// we allow an opt out of future checks
QMessageBox response(MainWindow::instance());
@@ -121,7 +121,7 @@ void UpdateManager::requestReceived()
response.setWindowTitle(tr("Automatic check for updates"));
response.setIcon(QMessageBox::Question);
response.setWindowModality(Qt::WindowModal);
- update_settings->setDontCheckForUpdates(response.exec() != QMessageBox::Accepted);
+ update_settings->set_dont_check_for_updates(response.exec() != QMessageBox::Accepted);
}
}
}
diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp
index 7b34aba1a..a089e7e00 100644
--- a/subsurface-helper.cpp
+++ b/subsurface-helper.cpp
@@ -164,6 +164,7 @@ void register_qml_types()
REGISTER_TYPE(qPrefFacebook, "SsrfFacebookPrefs");
REGISTER_TYPE(qPrefProxy, "SsrfProxyPrefs");
REGISTER_TYPE(qPrefUnits, "SsrfUnitPrefs");
+ REGISTER_TYPE(qPrefUpdateManager, "SsrfUpdateManagerPrefs");
#ifndef SUBSURFACE_TEST_DATA
#ifdef SUBSURFACE_MOBILE
diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index aae6ffe7d..59f7d064c 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -263,25 +263,25 @@ void TestPreferences::testPreferences()
TEST(location->timeThreshold(), 30);
TEST(location->distanceThreshold(), 40);
- auto update = pref->update_manager_settings;
+ auto update = qPrefUpdateManager::instance();
QDate date = QDate::currentDate();
- update->setDontCheckForUpdates(true);
- update->setLastVersionUsed("tomaz-1");
- update->setNextCheck(date);
+ update->set_dont_check_for_updates(true);
+ update->set_last_version_used("tomaz-1");
+ update->set_next_check(date);
- TEST(update->dontCheckForUpdates(), true);
- TEST(update->lastVersionUsed(), QStringLiteral("tomaz-1"));
- TEST(update->nextCheck(), date);
+ TEST(update->dont_check_for_updates(), true);
+ TEST(update->last_version_used(), QStringLiteral("tomaz-1"));
+ TEST(update->next_check(), date);
date = date.addDays(3);
- update->setDontCheckForUpdates(false);
- update->setLastVersionUsed("tomaz-2");
- update->setNextCheck(date);
+ update->set_dont_check_for_updates(false);
+ update->set_last_version_used("tomaz-2");
+ update->set_next_check(date);
- TEST(update->dontCheckForUpdates(), false);
- TEST(update->lastVersionUsed(), QStringLiteral("tomaz-2"));
- TEST(update->nextCheck(), date);
+ TEST(update->dont_check_for_updates(), false);
+ TEST(update->last_version_used(), QStringLiteral("tomaz-2"));
+ TEST(update->next_check(), date);
}
QTEST_MAIN(TestPreferences)