summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-08-06 19:39:35 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-13 11:49:32 -0700
commit63fa532b1520bb18eff98c10ff708834939d8e59 (patch)
treeaf14c8c0536668f4c6784059baf41fbfe4500dcc
parent8603a7d826a7bcf10dea0f93d564a609aae0050a (diff)
downloadsubsurface-63fa532b1520bb18eff98c10ff708834939d8e59.tar.gz
core: create qPrefLanguage from SettingsObjectWrapper
Update set/get functions to follow common name scheme: - get function have same name as in struct preferences - set function have set_<name> - signal function have <name>_changed one class one .h/.cpp is the C++ idiom. Having load/sync of each variable in 1 functions (in contrast to the distributed way SettingsObjectWrapper handles it) secures the same storage name is used. Having the set/get/load/sync functions grouped together makes it easier to get an overview. REMARK: this commit only defines the class, it is not active in production Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r--core/CMakeLists.txt1
-rw-r--r--core/settings/qPref.h1
-rw-r--r--core/settings/qPrefLanguage.cpp43
-rw-r--r--core/settings/qPrefLanguage.h69
-rw-r--r--core/settings/qPrefPrivate.h1
-rw-r--r--packaging/ios/Subsurface-mobile.pro2
6 files changed, 117 insertions, 0 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 9babe1931..7c2af9626 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -109,6 +109,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
settings/qPrefDiveComputer.cpp
settings/qPrefDivePlanner.cpp
settings/qPrefFacebook.cpp
+ settings/qPrefLanguage.cpp
settings/qPrefLocationService.cpp
settings/qPrefPrivate.cpp
settings/qPrefProxy.cpp
diff --git a/core/settings/qPref.h b/core/settings/qPref.h
index 89e0b0951..bb304f0d5 100644
--- a/core/settings/qPref.h
+++ b/core/settings/qPref.h
@@ -11,6 +11,7 @@
#include "qPrefDiveComputer.h"
#include "qPrefDivePlanner.h"
#include "qPrefFacebook.h"
+#include "qPrefLanguage.h"
#include "qPrefLocationService.h"
#include "qPrefProxy.h"
#include "qPrefTechnicalDetails.h"
diff --git a/core/settings/qPrefLanguage.cpp b/core/settings/qPrefLanguage.cpp
new file mode 100644
index 000000000..1ad31a73b
--- /dev/null
+++ b/core/settings/qPrefLanguage.cpp
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "qPref.h"
+#include "qPrefPrivate.h"
+
+static const QString group = QStringLiteral("Language");
+
+qPrefLanguage::qPrefLanguage(QObject *parent) : QObject(parent)
+{
+}
+
+qPrefLanguage *qPrefLanguage::instance()
+{
+ static qPrefLanguage *self = new qPrefLanguage;
+ return self;
+}
+
+void qPrefLanguage::loadSync(bool doSync)
+{
+ disk_date_format(doSync);
+ disk_date_format_override(doSync);
+ disk_date_format_short(doSync);
+ disk_language(doSync);
+ disk_lang_locale(doSync);
+ disk_time_format(doSync);
+ disk_time_format_override(doSync);
+ disk_use_system_language(doSync);
+}
+
+HANDLE_PREFERENCE_TXT(Language, "/date_format", date_format);
+
+HANDLE_PREFERENCE_BOOL(Language,"/date_format_override", date_format_override);
+
+HANDLE_PREFERENCE_TXT(Language, "/date_format_short", date_format_short);
+
+HANDLE_PREFERENCE_TXT_EXT(Language, "/UiLanguage", language, locale.);
+
+HANDLE_PREFERENCE_TXT_EXT(Language, "/UiLang_locale", lang_locale, locale.);
+
+HANDLE_PREFERENCE_TXT(Language, "/time_format", time_format);
+
+HANDLE_PREFERENCE_BOOL(Language, "/time_format_override", time_format_override);
+
+HANDLE_PREFERENCE_BOOL_EXT(Language, "/Use_system_language", use_system_language, locale.);
diff --git a/core/settings/qPrefLanguage.h b/core/settings/qPrefLanguage.h
new file mode 100644
index 000000000..d1d8b2b79
--- /dev/null
+++ b/core/settings/qPrefLanguage.h
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef QPREFLANGUAGE_H
+#define QPREFLANGUAGE_H
+#include "core/pref.h"
+
+#include <QObject>
+
+class qPrefLanguage : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString date_format READ date_format WRITE set_date_format NOTIFY date_format_changed);
+ Q_PROPERTY(bool date_format_override READ date_format_override WRITE set_date_format_override NOTIFY date_format_override_changed);
+ Q_PROPERTY(QString date_format_short READ date_format_short WRITE set_date_format_short NOTIFY date_format_short_changed);
+ Q_PROPERTY(QString language READ language WRITE set_language NOTIFY language_changed);
+ Q_PROPERTY(QString lang_locale READ lang_locale WRITE set_lang_locale NOTIFY lang_locale_changed);
+ Q_PROPERTY(QString time_format READ time_format WRITE set_time_format NOTIFY time_format_changed);
+ Q_PROPERTY(bool time_format_override READ time_format_override WRITE set_time_format_override NOTIFY time_format_override_changed);
+ Q_PROPERTY(bool use_system_language READ use_system_language WRITE set_use_system_language NOTIFY use_system_language_changed);
+
+public:
+ qPrefLanguage(QObject *parent = NULL);
+ static qPrefLanguage *instance();
+
+ // Load/Sync local settings (disk) and struct preference
+ void loadSync(bool doSync);
+ void load() { loadSync(false); }
+ void sync() { loadSync(true); }
+
+public:
+ const QString date_format() { return prefs.date_format; }
+ bool date_format_override() { return prefs.date_format_override; }
+ const QString date_format_short() { return prefs.date_format_short; }
+ const QString language() { return prefs.locale.language; }
+ const QString lang_locale() { return prefs.locale.lang_locale; }
+ const QString time_format() { return prefs.time_format; }
+ bool time_format_override() { return prefs.time_format_override; }
+ bool use_system_language() { return prefs.locale.use_system_language; }
+
+public slots:
+ void set_date_format(const QString& value);
+ void set_date_format_override(bool value);
+ void set_date_format_short(const QString& value);
+ void set_language(const QString& value);
+ void set_lang_locale(const QString& value);
+ void set_time_format(const QString& value);
+ void set_time_format_override(bool value);
+ void set_use_system_language(bool value);
+
+signals:
+ void date_format_changed(const QString& value);
+ void date_format_override_changed(bool value);
+ void date_format_short_changed(const QString& value);
+ void language_changed(const QString& value);
+ void lang_locale_changed(const QString& value);
+ void time_format_changed(const QString& value);
+ void time_format_override_changed(bool value);
+ void use_system_language_changed(bool value);
+
+private:
+ void disk_date_format(bool doSync);
+ void disk_date_format_override(bool doSync);
+ void disk_date_format_short(bool doSync);
+ void disk_language(bool doSync);
+ void disk_lang_locale(bool doSync);
+ void disk_time_format(bool doSync);
+ void disk_time_format_override(bool doSync);
+ void disk_use_system_language(bool doSync);
+};
+
+#endif
diff --git a/core/settings/qPrefPrivate.h b/core/settings/qPrefPrivate.h
index efaa5382c..5a34acdc8 100644
--- a/core/settings/qPrefPrivate.h
+++ b/core/settings/qPrefPrivate.h
@@ -20,6 +20,7 @@ public:
friend class qPrefDiveComputer;
friend class qPrefDivePlanner;
friend class qPrefFacebook;
+ friend class qPrefLanguage;
friend class qPrefLocationService;
friend class qPrefProxy;
friend class qPrefTechnicalDetails;
diff --git a/packaging/ios/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile.pro
index 4107def06..169d46849 100644
--- a/packaging/ios/Subsurface-mobile.pro
+++ b/packaging/ios/Subsurface-mobile.pro
@@ -84,6 +84,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \
../../core/settings/qPrefDiveComputer.cpp \
../../core/settings/qPrefDivePlanner.cpp \
../../core/settings/qPrefFacebook.cpp \
+ ../../core/settings/qPrefLanguage.cpp \
../../core/settings/qPrefLocationService.cpp \
../../core/settings/qPrefPrivate.cpp \
../../core/settings/qPrefProxy.cpp \
@@ -203,6 +204,7 @@ HEADERS += \
../../core/settings/qPrefDiveComputer.h \
../../core/settings/qPrefDivePlanner.h \
../../core/settings/qPrefFacebook.h \
+ ../../core/settings/qPrefLanguage.h \
../../core/settings/qPrefLocationService.h \
../../core/settings/qPrefPrivate.h \
../../core/settings/qPrefProxy.h \