diff options
author | jan Iversen <jani@apache.org> | 2018-08-12 17:57:45 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-08-14 09:09:06 -0700 |
commit | 4a7864444ba5c90e4113e704a593d0fc4e6207b8 (patch) | |
tree | d6d2caae40434e5cca59cbf2d448cbf0ada265fa /core/settings | |
parent | d5b087f01f89508f2e49c67a8d662662a93cf620 (diff) | |
download | subsurface-4a7864444ba5c90e4113e704a593d0fc4e6207b8.tar.gz |
core: create qPrefGeneral from SettingsObjectWrapper
Update set/get functions to follow common name scheme:
- get function have same name as in struct diveComputer
- 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>
Diffstat (limited to 'core/settings')
-rw-r--r-- | core/settings/qPref.h | 1 | ||||
-rw-r--r-- | core/settings/qPrefGeneral.cpp | 82 | ||||
-rw-r--r-- | core/settings/qPrefGeneral.h | 84 | ||||
-rw-r--r-- | core/settings/qPrefPrivate.h | 1 |
4 files changed, 168 insertions, 0 deletions
diff --git a/core/settings/qPref.h b/core/settings/qPref.h index 27610883e..805bf68c5 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 "qPrefGeneral.h" #include "qPrefGeocoding.h" #include "qPrefLanguage.h" #include "qPrefLocationService.h" diff --git a/core/settings/qPrefGeneral.cpp b/core/settings/qPrefGeneral.cpp new file mode 100644 index 000000000..4364ce731 --- /dev/null +++ b/core/settings/qPrefGeneral.cpp @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qPref.h" +#include "qPrefPrivate.h" + + +static const QString group = QStringLiteral("GeneralSettings"); + +qPrefGeneral::qPrefGeneral(QObject *parent) : QObject(parent) +{ +} +qPrefGeneral *qPrefGeneral::instance() +{ + static qPrefGeneral *self = new qPrefGeneral; + return self; +} + + +void qPrefGeneral::loadSync(bool doSync) +{ + disk_auto_recalculate_thumbnails(doSync); + disk_auto_recalculate_thumbnails(doSync); + disk_default_cylinder(doSync); + disk_default_filename(doSync); + disk_default_file_behavior(doSync); + disk_defaultsetpoint(doSync); + disk_extract_video_thumbnails(doSync); + disk_extract_video_thumbnails_position(doSync); + disk_ffmpeg_executable(doSync); + disk_o2consumption(doSync); + disk_pscr_ratio(doSync); + disk_use_default_file(doSync); +} + +HANDLE_PREFERENCE_BOOL(General, "/auto_recalculate_thumbnails", auto_recalculate_thumbnails); + +HANDLE_PREFERENCE_TXT(General, "/default_cylinder", default_cylinder); + +HANDLE_PREFERENCE_TXT(General, "default_filename", default_filename); + + +void qPrefGeneral::set_default_file_behavior(enum def_file_behavior value) +{ + if (value != prefs.default_file_behavior || + prefs.default_file_behavior != UNDEFINED_DEFAULT_FILE) { + + if (value == UNDEFINED_DEFAULT_FILE) { + // undefined, so check if there's a filename set and + // use that, otherwise go with no default file + prefs.default_file_behavior = QString(prefs.default_filename).isEmpty() ? NO_DEFAULT_FILE : LOCAL_DEFAULT_FILE; + } else { + prefs.default_file_behavior = value; + } + disk_default_file_behavior(true); + emit default_file_behavior_changed(value); + } +} +void qPrefGeneral::disk_default_file_behavior(bool doSync) +{ + if (doSync) { + qPrefPrivate::instance()->setting.setValue(group + "/default_file_behavior", prefs.default_file_behavior); + } else { + prefs.default_file_behavior = (enum def_file_behavior)qPrefPrivate::instance()->setting.value(group + "/default_file_behavior", default_prefs.default_file_behavior).toInt(); + if (prefs.default_file_behavior == UNDEFINED_DEFAULT_FILE) + // undefined, so check if there's a filename set and + // use that, otherwise go with no default file + prefs.default_file_behavior = QString(prefs.default_filename).isEmpty() ? NO_DEFAULT_FILE : LOCAL_DEFAULT_FILE; + } +} + +HANDLE_PREFERENCE_INT(General, "/defaultsetpoint", defaultsetpoint); + +HANDLE_PREFERENCE_BOOL(General, "/extract_video_thumbnails", extract_video_thumbnails); + +HANDLE_PREFERENCE_INT(General, "/extract_video_thumbnails_position", extract_video_thumbnails_position); + +HANDLE_PREFERENCE_TXT(General, "/ffmpeg_executable", ffmpeg_executable); + +HANDLE_PREFERENCE_INT(General, "/o2consumption", o2consumption); + +HANDLE_PREFERENCE_INT(General, "/pscr_ratio", pscr_ratio); + +HANDLE_PREFERENCE_BOOL(General, "/use_default_file", use_default_file); diff --git a/core/settings/qPrefGeneral.h b/core/settings/qPrefGeneral.h new file mode 100644 index 000000000..3263bb718 --- /dev/null +++ b/core/settings/qPrefGeneral.h @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef QPREFGENERAL_H +#define QPREFGENERAL_H +#include "core/pref.h" + +#include <QObject> + +class qPrefGeneral : public QObject { + Q_OBJECT + Q_PROPERTY(bool auto_recalculate_thumbnails READ auto_recalculate_thumbnails WRITE set_auto_recalculate_thumbnails NOTIFY auto_recalculate_thumbnails_changed); + Q_PROPERTY(QString default_cylinder READ default_cylinder WRITE set_default_cylinder NOTIFY default_cylinder_changed); + Q_PROPERTY(QString default_filename READ default_filename WRITE set_default_filename NOTIFY default_filename_changed); + Q_PROPERTY(enum def_file_behavior default_file_behavior READ default_file_behavior WRITE set_default_file_behavior NOTIFY default_file_behavior_changed); + Q_PROPERTY(int defaultsetpoint READ defaultsetpoint WRITE set_defaultsetpoint NOTIFY defaultsetpoint_changed); + Q_PROPERTY(bool extract_video_thumbnails READ extract_video_thumbnails WRITE set_extract_video_thumbnails NOTIFY extract_video_thumbnails_changed); + Q_PROPERTY(int extract_video_thumbnails_position READ extract_video_thumbnails_position WRITE set_extract_video_thumbnails_position NOTIFY extract_video_thumbnails_position_changed); + Q_PROPERTY(QString ffmpeg_executable READ ffmpeg_executable WRITE set_ffmpeg_executable NOTIFY ffmpeg_executable_changed); + Q_PROPERTY(int o2consumption READ o2consumption WRITE set_o2consumption NOTIFY o2consumption_changed); + Q_PROPERTY(int pscr_ratio READ pscr_ratio WRITE set_pscr_ratio NOTIFY pscr_ratio_changed); + Q_PROPERTY(bool use_default_file READ use_default_file WRITE set_use_default_file NOTIFY use_default_file_changed); + +public: + qPrefGeneral(QObject *parent = NULL); + static qPrefGeneral *instance(); + + // Load/Sync local settings (disk) and struct preference + void loadSync(bool doSync); + void load() { return loadSync(false); } + void sync() { return loadSync(true); } + +public: + bool auto_recalculate_thumbnails() { return prefs.auto_recalculate_thumbnails; } + QString default_cylinder() { return prefs.default_cylinder; } + QString default_filename() { return prefs.default_filename; } + enum def_file_behavior default_file_behavior() { return prefs.default_file_behavior; } + int defaultsetpoint() { return prefs.defaultsetpoint; } + bool extract_video_thumbnails() { return prefs.extract_video_thumbnails; } + int extract_video_thumbnails_position() { return prefs.extract_video_thumbnails_position; } + QString ffmpeg_executable() { return prefs.ffmpeg_executable; } + int o2consumption() { return prefs.o2consumption; } + int pscr_ratio() { return prefs.pscr_ratio; } + bool use_default_file() { return prefs.use_default_file; } + +public slots: + void set_auto_recalculate_thumbnails(bool value); + void set_default_cylinder(const QString& value); + void set_default_filename(const QString& value); + void set_default_file_behavior(enum def_file_behavior value); + void set_defaultsetpoint(int value); + void set_extract_video_thumbnails(bool value); + void set_extract_video_thumbnails_position(int value); + void set_ffmpeg_executable(const QString& value); + void set_o2consumption(int value); + void set_pscr_ratio(int value); + void set_use_default_file(bool value); + +signals: + void auto_recalculate_thumbnails_changed(bool value); + void default_cylinder_changed(const QString& value); + void default_filename_changed(const QString& value); + void default_file_behavior_changed(enum def_file_behavior value); + void defaultsetpoint_changed(int value); + void extract_video_thumbnails_changed(bool value); + void extract_video_thumbnails_position_changed(int value); + void ffmpeg_executable_changed(const QString& value); + void o2consumption_changed(int value); + void pscr_ratio_changed(int value); + void use_default_file_changed(bool value); + +private: + void disk_auto_recalculate_thumbnails(bool doSync); + void disk_default_cylinder(bool doSync); + void disk_default_filename(bool doSync); + void disk_default_file_behavior(bool doSync); + void disk_defaultsetpoint(bool doSync); + void disk_extract_video_thumbnails(bool doSync); + void disk_extract_video_thumbnails_position(bool doSync); + void disk_ffmpeg_executable(bool doSync); + void disk_o2consumption(bool doSync); + void disk_pscr_ratio(bool doSync); + void disk_use_default_file(bool doSync); +}; + +#endif diff --git a/core/settings/qPrefPrivate.h b/core/settings/qPrefPrivate.h index 291d07273..9d0849402 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 qPrefGeneral; friend class qPrefGeocoding; friend class qPrefLanguage; friend class qPrefLocationService; |