summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-08-08 16:34:17 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-13 11:49:32 -0700
commit72d87364c018c61f2127b7293fff11b83e97b82c (patch)
treeb2d2eff7326964fddbb4a8fc82798d616ef69d0e
parent63fa532b1520bb18eff98c10ff708834939d8e59 (diff)
downloadsubsurface-72d87364c018c61f2127b7293fff11b83e97b82c.tar.gz
core: activate qPrefLanguage
remove Language from SettingsObjectWrapper and reference qPrefLanguage update files using SettingsObjectWrapper/Language to use qPrefLanguage this activated qPrefLanguage and removed the similar class from SettingsObjectWrapper. Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r--core/settings/qPref.cpp1
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp155
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h49
-rw-r--r--desktop-widgets/preferences/preferences_language.cpp18
-rw-r--r--subsurface-helper.cpp1
-rw-r--r--tests/testpreferences.cpp68
6 files changed, 49 insertions, 243 deletions
diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp
index 90aaa8fea..a74937921 100644
--- a/core/settings/qPref.cpp
+++ b/core/settings/qPref.cpp
@@ -20,6 +20,7 @@ void qPref::loadSync(bool doSync)
qPrefDiveComputer::instance()->loadSync(doSync);
qPrefDivePlanner::instance()->loadSync(doSync);
// qPrefFaceook does not use disk.
+ qPrefLanguage::instance()->loadSync(doSync);
qPrefLocationService::instance()->loadSync(doSync);
qPrefProxy::instance()->loadSync(doSync);
qPrefTechnicalDetails::instance()->loadSync(doSync);
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index 84ffc5a26..1fb770c56 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -390,148 +390,6 @@ void GeneralSettingsObjectWrapper::setFfmpegExecutable(const QString &value)
emit ffmpegExecutableChanged(value);
}
-LanguageSettingsObjectWrapper::LanguageSettingsObjectWrapper(QObject *parent) :
- QObject(parent)
-{
-}
-
-QString LanguageSettingsObjectWrapper::language() const
-{
- return prefs.locale.language;
-}
-
-QString LanguageSettingsObjectWrapper::timeFormat() const
-{
- return prefs.time_format;
-}
-
-QString LanguageSettingsObjectWrapper::dateFormat() const
-{
- return prefs.date_format;
-}
-
-QString LanguageSettingsObjectWrapper::dateFormatShort() const
-{
- return prefs.date_format_short;
-}
-
-bool LanguageSettingsObjectWrapper::timeFormatOverride() const
-{
- return prefs.time_format_override;
-}
-
-bool LanguageSettingsObjectWrapper::dateFormatOverride() const
-{
- return prefs.date_format_override;
-}
-
-bool LanguageSettingsObjectWrapper::useSystemLanguage() const
-{
- return prefs.locale.use_system_language;
-}
-
-QString LanguageSettingsObjectWrapper::langLocale() const
-{
- return prefs.locale.lang_locale;
-}
-
-void LanguageSettingsObjectWrapper::setUseSystemLanguage(bool value)
-{
- if (value == prefs.locale.use_system_language)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("UseSystemLanguage", value);
- prefs.locale.use_system_language = value;
- emit useSystemLanguageChanged(value);
-}
-
-void LanguageSettingsObjectWrapper::setLangLocale(const QString &value)
-{
- if (value == prefs.locale.lang_locale)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("UiLangLocale", value);
- free((void *)prefs.locale.lang_locale);
- prefs.locale.lang_locale = copy_qstring(value);
- emit langLocaleChanged(value);
-}
-
-void LanguageSettingsObjectWrapper::setLanguage(const QString& value)
-{
- if (value == prefs.locale.language)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("UiLanguage", value);
- free((void *)prefs.locale.language);
- prefs.locale.language = copy_qstring(value);
- emit languageChanged(value);
-}
-
-void LanguageSettingsObjectWrapper::setTimeFormat(const QString& value)
-{
- if (value == prefs.time_format)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("time_format", value);
- free((void *)prefs.time_format);
- prefs.time_format = copy_qstring(value);
- emit timeFormatChanged(value);
-}
-
-void LanguageSettingsObjectWrapper::setDateFormat(const QString& value)
-{
- if (value == prefs.date_format)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("date_format", value);
- free((void *)prefs.date_format);
- prefs.date_format = copy_qstring(value);
- emit dateFormatChanged(value);
-}
-
-void LanguageSettingsObjectWrapper::setDateFormatShort(const QString& value)
-{
- if (value == prefs.date_format_short)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("date_format_short", value);
- free((void *)prefs.date_format_short);
- prefs.date_format_short = copy_qstring(value);
- emit dateFormatShortChanged(value);
-}
-
-void LanguageSettingsObjectWrapper::setTimeFormatOverride(bool value)
-{
- if (value == prefs.time_format_override)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("time_format_override", value);
- prefs.time_format_override = value;
- emit timeFormatOverrideChanged(value);
-}
-
-void LanguageSettingsObjectWrapper::setDateFormatOverride(bool value)
-{
- if (value == prefs.date_format_override)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("date_format_override", value);
- prefs.date_format_override = value;
- emit dateFormatOverrideChanged(value);
-}
-
-
SettingsObjectWrapper::SettingsObjectWrapper(QObject* parent):
QObject(parent),
techDetails(new qPrefTechnicalDetails(this)),
@@ -544,7 +402,7 @@ QObject(parent),
unit_settings(new qPrefUnits(this)),
general_settings(new GeneralSettingsObjectWrapper(this)),
display_settings(new qPrefDisplay(this)),
- language_settings(new LanguageSettingsObjectWrapper(this)),
+ language_settings(new qPrefLanguage(this)),
animation_settings(new qPrefAnimations(this)),
location_settings(new qPrefLocationService(this)),
update_manager_settings(new qPrefUpdateManager(this)),
@@ -601,16 +459,7 @@ void SettingsObjectWrapper::load()
qPrefDiveComputer::instance()->load();
qPrefUpdateManager::instance()->load();
- s.beginGroup("Language");
- GET_BOOL("UseSystemLanguage", locale.use_system_language);
- GET_TXT("UiLanguage", locale.language);
- GET_TXT("UiLangLocale", locale.lang_locale);
- GET_TXT("time_format", time_format);
- GET_TXT("date_format", date_format);
- GET_TXT("date_format_short", date_format_short);
- GET_BOOL("time_format_override", time_format_override);
- GET_BOOL("date_format_override", date_format_override);
- s.endGroup();
+ qPrefLanguage::instance()->load();
}
void SettingsObjectWrapper::sync()
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index 3af79404e..2fe2a7b5a 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -138,51 +138,6 @@ private:
const QString group = QStringLiteral("GeneralSettings");
};
-class LanguageSettingsObjectWrapper : public QObject {
- Q_OBJECT
- Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)
- Q_PROPERTY(QString time_format READ timeFormat WRITE setTimeFormat NOTIFY timeFormatChanged)
- Q_PROPERTY(QString date_format READ dateFormat WRITE setDateFormat NOTIFY dateFormatChanged)
- Q_PROPERTY(QString date_format_short READ dateFormatShort WRITE setDateFormatShort NOTIFY dateFormatShortChanged)
- Q_PROPERTY(QString lang_locale READ langLocale WRITE setLangLocale NOTIFY langLocaleChanged)
- Q_PROPERTY(bool time_format_override READ timeFormatOverride WRITE setTimeFormatOverride NOTIFY timeFormatOverrideChanged)
- Q_PROPERTY(bool date_format_override READ dateFormatOverride WRITE setDateFormatOverride NOTIFY dateFormatOverrideChanged)
- Q_PROPERTY(bool use_system_language READ useSystemLanguage WRITE setUseSystemLanguage NOTIFY useSystemLanguageChanged)
-
-public:
- LanguageSettingsObjectWrapper(QObject *parent);
- QString language() const;
- QString langLocale() const;
- QString timeFormat() const;
- QString dateFormat() const;
- QString dateFormatShort() const;
- bool timeFormatOverride() const;
- bool dateFormatOverride() const;
- bool useSystemLanguage() const;
-
-public slots:
- void setLangLocale (const QString& value);
- void setLanguage (const QString& value);
- void setTimeFormat (const QString& value);
- void setDateFormat (const QString& value);
- void setDateFormatShort (const QString& value);
- void setTimeFormatOverride (bool value);
- void setDateFormatOverride (bool value);
- void setUseSystemLanguage (bool value);
-signals:
- void languageChanged(const QString& value);
- void langLocaleChanged(const QString& value);
- void timeFormatChanged(const QString& value);
- void dateFormatChanged(const QString& value);
- void dateFormatShortChanged(const QString& value);
- void timeFormatOverrideChanged(bool value);
- void dateFormatOverrideChanged(bool value);
- void useSystemLanguageChanged(bool value);
-
-private:
- const QString group = QStringLiteral("Language");
-};
-
class SettingsObjectWrapper : public QObject {
Q_OBJECT
@@ -196,7 +151,7 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(qPrefUnits* units MEMBER unit_settings CONSTANT)
Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_settings CONSTANT)
Q_PROPERTY(qPrefDisplay* display MEMBER display_settings CONSTANT)
- Q_PROPERTY(LanguageSettingsObjectWrapper* language MEMBER language_settings CONSTANT)
+ Q_PROPERTY(qPrefLanguage* language MEMBER language_settings CONSTANT)
Q_PROPERTY(qPrefAnimations* animation MEMBER animation_settings CONSTANT)
Q_PROPERTY(qPrefLocationService* Location MEMBER location_settings CONSTANT)
@@ -215,7 +170,7 @@ public:
qPrefUnits *unit_settings;
GeneralSettingsObjectWrapper *general_settings;
qPrefDisplay *display_settings;
- LanguageSettingsObjectWrapper *language_settings;
+ qPrefLanguage *language_settings;
qPrefAnimations *animation_settings;
qPrefLocationService *location_settings;
qPrefUpdateManager *update_manager_settings;
diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp
index e4a63ae9e..2bcd3422d 100644
--- a/desktop-widgets/preferences/preferences_language.cpp
+++ b/desktop-widgets/preferences/preferences_language.cpp
@@ -82,15 +82,15 @@ void PreferencesLanguage::syncSettings()
currentLocale = m->data(languages.first(),Qt::UserRole).toString();
- auto lang = SettingsObjectWrapper::instance()->language_settings;
- lang->setLanguage(currentText);
- lang->setLangLocale(currentLocale);
- lang->setUseSystemLanguage(ui->languageSystemDefault->isChecked());
- lang->setTimeFormatOverride(!ui->timeFormatSystemDefault->isChecked());
- lang->setDateFormatOverride(!ui->dateFormatSystemDefault->isChecked());
- lang->setTimeFormat(ui->timeFormatEntry->currentText());
- lang->setDateFormat(ui->dateFormatEntry->currentText());
- lang->setDateFormatShort(ui->shortDateFormatEntry->text());
+ auto lang = qPrefLanguage::instance();
+ lang->set_language(currentText);
+ lang->set_lang_locale(currentLocale);
+ lang->set_use_system_language(ui->languageSystemDefault->isChecked());
+ lang->set_time_format_override(!ui->timeFormatSystemDefault->isChecked());
+ lang->set_date_format_override(!ui->dateFormatSystemDefault->isChecked());
+ lang->set_time_format(ui->timeFormatEntry->currentText());
+ lang->set_date_format(ui->dateFormatEntry->currentText());
+ lang->set_date_format_short(ui->shortDateFormatEntry->text());
uiLanguage(NULL);
QString qDateTimeWeb = tr("These will be used as is. This might not be what you intended.\nSee http://doc.qt.io/qt-5/qdatetime.html#toString");
diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp
index 99480c3ac..10b7ccb49 100644
--- a/subsurface-helper.cpp
+++ b/subsurface-helper.cpp
@@ -162,6 +162,7 @@ void register_qml_types()
REGISTER_TYPE(qPrefDiveComputer, "SsrfDiveComputerPrefs");
REGISTER_TYPE(qPrefDivePlanner, "SsrfDivePlannerPrefs");
REGISTER_TYPE(qPrefFacebook, "SsrfFacebookPrefs");
+ REGISTER_TYPE(qPrefLanguage, "SsrfLanguagePrefs");
REGISTER_TYPE(qPrefLocationService, "SsrfLocationServicePrefs");
REGISTER_TYPE(qPrefProxy, "SsrfProxyPrefs");
REGISTER_TYPE(qPrefTechnicalDetails, "SsrfTechnicalDetailsPrefs");
diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index 0a4492c00..f7912d6c0 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -110,42 +110,42 @@ void TestPreferences::testPreferences()
TEST(general->pscrRatio(), 1);
TEST(general->useDefaultFile(), false);
- auto language = pref->language_settings;
- language->setLangLocale("en_US");
- language->setLanguage("en");
- language->setTimeFormat("hh:mm");
- language->setDateFormat("dd/mm/yy");
- language->setDateFormatShort("dd/mm");
- language->setTimeFormatOverride(false);
- language->setDateFormatOverride(false);
- language->setUseSystemLanguage(false);
-
- TEST(language->langLocale(), QStringLiteral("en_US"));
+ auto language = qPrefLanguage::instance();
+ language->set_lang_locale("en_US");
+ language->set_language("en");
+ language->set_time_format("hh:mm");
+ language->set_date_format("dd/mm/yy");
+ language->set_date_format_short("dd/mm");
+ language->set_time_format_override(false);
+ language->set_date_format_override(false);
+ language->set_use_system_language(false);
+
+ TEST(language->lang_locale(), QStringLiteral("en_US"));
TEST(language->language(), QStringLiteral("en"));
- TEST(language->timeFormat(), QStringLiteral("hh:mm"));
- TEST(language->dateFormat(), QStringLiteral("dd/mm/yy"));
- TEST(language->dateFormatShort(), QStringLiteral("dd/mm"));
- TEST(language->timeFormatOverride(), false);
- TEST(language->dateFormatOverride(), false);
- TEST(language->useSystemLanguage(), false);
-
- language->setLangLocale("en_EN");
- language->setLanguage("br");
- language->setTimeFormat("mm:hh");
- language->setDateFormat("yy/mm/dd");
- language->setDateFormatShort("dd/yy");
- language->setTimeFormatOverride(true);
- language->setDateFormatOverride(true);
- language->setUseSystemLanguage(true);
-
- TEST(language->langLocale(), QStringLiteral("en_EN"));
+ TEST(language->time_format(), QStringLiteral("hh:mm"));
+ TEST(language->date_format(), QStringLiteral("dd/mm/yy"));
+ TEST(language->date_format_short(), QStringLiteral("dd/mm"));
+ TEST(language->time_format_override(), false);
+ TEST(language->date_format_override(), false);
+ TEST(language->use_system_language(), false);
+
+ language->set_lang_locale("en_EN");
+ language->set_language("br");
+ language->set_time_format("mm:hh");
+ language->set_date_format("yy/mm/dd");
+ language->set_date_format_short("dd/yy");
+ language->set_time_format_override(true);
+ language->set_date_format_override(true);
+ language->set_use_system_language(true);
+
+ TEST(language->lang_locale(), QStringLiteral("en_EN"));
TEST(language->language(), QStringLiteral("br"));
- TEST(language->timeFormat(), QStringLiteral("mm:hh"));
- TEST(language->dateFormat(), QStringLiteral("yy/mm/dd"));
- TEST(language->dateFormatShort(), QStringLiteral("dd/yy"));
- TEST(language->timeFormatOverride(), true);
- TEST(language->dateFormatOverride(), true);
- TEST(language->useSystemLanguage(), true);
+ TEST(language->time_format(), QStringLiteral("mm:hh"));
+ TEST(language->date_format(), QStringLiteral("yy/mm/dd"));
+ TEST(language->date_format_short(), QStringLiteral("dd/yy"));
+ TEST(language->time_format_override(), true);
+ TEST(language->date_format_override(), true);
+ TEST(language->use_system_language(), true);
}
QTEST_MAIN(TestPreferences)