aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorConfuSomu2023-08-16 12:49:23 -0400
committerConfuSomu2023-08-16 14:38:17 -0400
commitc45f6501f501a65f753604bfd2341035ae12fd30 (patch)
tree3bb37bb6adae850ddb91baffa01a957576615e41 /src
parent52add29e0a380618a358fdbaddb612703d36eb90 (diff)
downloadActorViewer-c45f6501f501a65f753604bfd2341035ae12fd30.tar
ActorViewer-c45f6501f501a65f753604bfd2341035ae12fd30.tar.gz
ActorViewer-c45f6501f501a65f753604bfd2341035ae12fd30.zip
Make quick_read_setting() a templated method
This allows terser usage and removes the need for manually invoking QVariant's .value<T>() method.
Diffstat (limited to 'src')
-rw-r--r--src/activitypub/apactivity.cpp2
-rw-r--r--src/activitypub/appost.cpp2
-rw-r--r--src/activitypub/apquestion.cpp4
-rw-r--r--src/settings_interface.cpp5
-rw-r--r--src/settings_interface.h10
5 files changed, 13 insertions, 10 deletions
diff --git a/src/activitypub/apactivity.cpp b/src/activitypub/apactivity.cpp
index 3bc6444..6717731 100644
--- a/src/activitypub/apactivity.cpp
+++ b/src/activitypub/apactivity.cpp
@@ -42,7 +42,7 @@ QString APActivity::get_html_render(HtmlRenderDetails render_info) {
html.replace("{{object}}", object->get_html_render(render_info));
if (published.isValid())
html.replace("{{published}}", render_info.locale->toString(
- SettingsInterface::quick_read_setting("ui/timezone").value<AppSettingsTypes::Timezone>() ? published.toUTC() : published.toLocalTime()
+ SettingsInterface::quick_read_setting<AppSettingsTypes::Timezone>("ui/timezone") ? published.toUTC() : published.toLocalTime()
));
return html;
diff --git a/src/activitypub/appost.cpp b/src/activitypub/appost.cpp
index 24a01f5..87d6f08 100644
--- a/src/activitypub/appost.cpp
+++ b/src/activitypub/appost.cpp
@@ -47,7 +47,7 @@ QString APPost::get_html_render(HtmlRenderDetails render_info) {
if (published.isValid()) {
// Using QLocale::toString() is forward compatible with Qt 6 as QDateTime::toString() will not return anymore a string in the system locale.
html.replace("{{published}}", render_info.locale->toString(
- SettingsInterface::quick_read_setting("ui/timezone").value<AppSettingsTypes::Timezone>() ? published.toUTC() : published.toLocalTime()
+ SettingsInterface::quick_read_setting<AppSettingsTypes::Timezone>("ui/timezone") ? published.toUTC() : published.toLocalTime()
));
}
diff --git a/src/activitypub/apquestion.cpp b/src/activitypub/apquestion.cpp
index 06fde9e..9cdffd0 100644
--- a/src/activitypub/apquestion.cpp
+++ b/src/activitypub/apquestion.cpp
@@ -20,12 +20,12 @@ QString APQuestion::get_html_render(HtmlRenderDetails render_info) {
if (end_time.isValid()) {
html.replace("{{end-time}}", render_info.locale->toString(
- SettingsInterface::quick_read_setting("ui/timezone").value<AppSettingsTypes::Timezone>() ? end_time.toUTC() : end_time.toLocalTime()
+ SettingsInterface::quick_read_setting<AppSettingsTypes::Timezone>("ui/timezone") ? end_time.toUTC() : end_time.toLocalTime()
));
}
if (closed_time.isValid()) {
html.replace("{{closed-time}}", render_info.locale->toString(
- SettingsInterface::quick_read_setting("ui/timezone").value<AppSettingsTypes::Timezone>() ? closed_time.toUTC() : closed_time.toLocalTime()
+ SettingsInterface::quick_read_setting<AppSettingsTypes::Timezone>("ui/timezone") ? closed_time.toUTC() : closed_time.toLocalTime()
));
}
diff --git a/src/settings_interface.cpp b/src/settings_interface.cpp
index 17c5991..e14da92 100644
--- a/src/settings_interface.cpp
+++ b/src/settings_interface.cpp
@@ -19,11 +19,6 @@ const QVariant SettingsInterface::read_setting(const QString &key) {
return qt_settings.value(key, default_setting(key));
}
-const QVariant SettingsInterface::quick_read_setting(const QString &key) {
- static SettingsInterface settings;
- return settings.read_setting(key);
-}
-
// Write a new value for key. Isn't written to disk until you use SettingsInterface::commit().
void SettingsInterface::write_setting(const QString &key, const QVariant &value) {
if (not modified) modified = new QHash<QString, QVariant>;
diff --git a/src/settings_interface.h b/src/settings_interface.h
index e290125..09c309b 100644
--- a/src/settings_interface.h
+++ b/src/settings_interface.h
@@ -16,7 +16,8 @@ class SettingsInterface {
public:
~SettingsInterface();
const QVariant read_setting(const QString &key);
- static const QVariant quick_read_setting(const QString &key);
+ template<typename T>
+ static const T quick_read_setting(const QString &key);
void write_setting(const QString &key, const QVariant &value);
void clear_setting(const QString &key);
void clear_all();
@@ -33,3 +34,10 @@ private:
// List of keys to remove from the QSettings
QStringList must_clear;
};
+
+// Template code implementations have to be "seen" at the same time as the declaration
+template<typename T>
+const T SettingsInterface::quick_read_setting(const QString &key) {
+ static SettingsInterface settings;
+ return settings.read_setting(key).value<T>();
+}