summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2016-01-22 15:39:40 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-24 21:26:35 -0800
commite7412b11b99a67c4beb8841f6bca763519553f9d (patch)
tree382b9639bae09bdb361f61a24471c9b364c9f22e
parentdf6eff917c351221c7c48557803f16ea5872f599 (diff)
downloadsubsurface-e7412b11b99a67c4beb8841f6bca763519553f9d.tar.gz
Added a GeneralSettingsWrapper
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp105
-rw-r--r--subsurface-core/subsurface-qt/SettingsObjectWrapper.h50
2 files changed, 148 insertions, 7 deletions
diff --git a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp
index ef48dfa59..4684b744a 100644
--- a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -1226,3 +1226,108 @@ void UnitsSettings::setUnitSystem(const QString& value)
emit unitSystemChanged(value);
// TODO: emit the other values here?
}
+
+GeneralSettingsObjectWrapper::GeneralSettingsObjectWrapper(QObject *parent) :
+ QObject(parent),
+ group(QStringLiteral("GeneralSettings"))
+{
+}
+
+QString GeneralSettingsObjectWrapper::defaultFilename() const
+{
+ return prefs.default_filename;
+}
+
+QString GeneralSettingsObjectWrapper::defaultCylinder() const
+{
+ return prefs.default_cylinder;
+}
+
+short GeneralSettingsObjectWrapper::defaultFileBehavior() const
+{
+ return prefs.default_file_behavior;
+}
+
+bool GeneralSettingsObjectWrapper::useDefaultFile() const
+{
+ return prefs.use_default_file;
+}
+
+int GeneralSettingsObjectWrapper::defaultSetPoint() const
+{
+ return prefs.defaultsetpoint;
+}
+
+int GeneralSettingsObjectWrapper::o2Consumption() const
+{
+ return prefs.o2consumption;
+}
+
+int GeneralSettingsObjectWrapper::pscrRatio() const
+{
+ return prefs.pscr_ratio;
+}
+
+void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value)
+{
+ QSettings s;
+ s.setValue("default_filename", value);
+ prefs.default_filename = copy_string(qPrintable(value));
+ emit defaultFilenameChanged(value);
+}
+
+void GeneralSettingsObjectWrapper::setDefaultCylinder(const QString& value)
+{
+ QSettings s;
+ s.setValue("default_cylinder", value);
+ prefs.default_cylinder = copy_string(qPrintable(value));
+ emit defaultCylinderChanged(value);
+}
+
+void GeneralSettingsObjectWrapper::setDefaultFileBehavior(short value)
+{
+ QSettings s;
+ s.setValue("default_file_behavior", value);
+ prefs.default_file_behavior = value.;
+ 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
+ if (QString(prefs.default_filename).isEmpty())
+ prefs.default_file_behavior = NO_DEFAULT_FILE;
+ else
+ prefs.default_file_behavior = LOCAL_DEFAULT_FILE;
+ }
+ emit defaultFileBehaviorChanged(value);
+}
+
+void GeneralSettingsObjectWrapper::setUseDefaultFile(bool value)
+{
+ QSettings s;
+ s.setValue("use_default_file", value);
+ prefs.use_default_file = value.;
+ emit useDefaultFileChanged(value);
+}
+
+void GeneralSettingsObjectWrapper::setDefaultSetPoint(int value)
+{
+ QSettings s;
+ s.setValue("defaultsetpoint", value);
+ prefs.defaultsetpoint = value.;
+ emit defaultSetPointChanged(value);
+}
+
+void GeneralSettingsObjectWrapper::setO2Consumption(int value)
+{
+ QSettings s;
+ s.setValue("o2consumption", value);
+ prefs.o2consumption = value.;
+ emit o2ConsumptionChanged(value);
+}
+
+void GeneralSettingsObjectWrapper::setPscrRatio(int value)
+{
+ QSettings s;
+ s.setValue("pscr_ratio", value);
+ prefs.pscr_ratio = value.;
+ emit pscrRatioChanged(value);
+}
diff --git a/subsurface-core/subsurface-qt/SettingsObjectWrapper.h b/subsurface-core/subsurface-qt/SettingsObjectWrapper.h
index c0d0cabd7..fd8cdac67 100644
--- a/subsurface-core/subsurface-qt/SettingsObjectWrapper.h
+++ b/subsurface-core/subsurface-qt/SettingsObjectWrapper.h
@@ -450,11 +450,51 @@ private:
QString group;
};
+class GeneralSettingsObjectWrapper : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged)
+ Q_PROPERTY(QString default_cylinder READ defaultCylinder WRITE setDefaultCylinder NOTIFY defaultCylinderChanged)
+ Q_PROPERTY(short default_file_behavior READ defaultFileBehavior WRITE setDefaultFileBehavior NOTIFY defaultFileBehaviorChanged)
+ Q_PROPERTY(bool use_default_file READ useDefaultFile WRITE setUseDefaultFile NOTIFY useDefaultFileChanged)
+ Q_PROPERTY(int defaultsetpoint READ defaultSetPoint WRITE setDefaultSetPoint NOTIFY defaultSetPointChanged)
+ Q_PROPERTY(int o2consumption READ o2Consumption WRITE setO2Consumption NOTIFY o2ConsumptionChanged)
+ Q_PROPERTY(int pscr_ratio READ pscrRatio WRITE setPscrRatio NOTIFY pscrRatioChanged)
+
+public:
+ GeneralSettingsObjectWrapper(QObject *parent);
+ QString defaultFilename() const;
+ QString defaultCylinder() const;
+ short defaultFileBehavior() const;
+ bool useDefaultFile() const;
+ int defaultSetPoint() const;
+ int o2Consumption() const;
+ int pscrRatio() const;
+
+public slots:
+ void setDefaultFilename (const QString& value);
+ void setDefaultCylinder (const QString& value);
+ void setDefaultFileBehavior (short value);
+ void setUseDefaultFile (bool value);
+ void setDefaultSetPoint (int value);
+ void setO2Consumption (int value);
+ void setPscrRatio (int value);
+
+signals:
+ void defaultFilenameChanged(const QString& value);
+ void defaultCylinderChanged(const QString& value);
+ void defaultFileBehaviorChanged(short value);
+ void useDefaultFileChanged(bool value);
+ void defaultSetPointChanged(int value);
+ void o2ConsumptionChanged(int value);
+ void pscrRatioChanged(int value);
+private:
+ QString group;
+
+};
+
class SettingsObjectWrapper : public QObject {
Q_OBJECT
Q_PROPERTY(QString divelist_font READ divelistFont WRITE setDivelistFont NOTIFY divelistFontChanged)
- Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged)
- Q_PROPERTY(QString default_cylinder READ defaultCylinder WRITE setDefaultCylinder NOTIFY defaultCylinderChanged)
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)
@@ -466,12 +506,7 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(short unit_system READ unitSystem WRITE setUnitSystem NOTIFY uintSystemChanged)
Q_PROPERTY(bool coordinates_traditional READ coordinatesTraditional WRITE setCoordinatesTraditional NOTIFY coordinatesTraditionalChanged)
Q_PROPERTY(short save_userid_local READ saveUserIdLocal WRITE setSaveUserIdLocal NOTIFY saveUserIdLocalChanged)
- Q_PROPERTY(int o2consumption READ o2Consumption WRITE setO2Consumption NOTIFY o2ConsumptionChanged)
- Q_PROPERTY(int pscr_ratio READ pscrRatio WRITE setPscrRatio NOTIFY pscrRatioChanged)
- Q_PROPERTY(int defaultsetpoint READ defaultSetPoint WRITE setDefaultSetPoint NOTIFY defaultSetPointChanged)
Q_PROPERTY(bool show_pictures_in_profile READ showPicturesInProfile WRITE setShowPicturesInProfile NOTIFY showPicturesInProfileChanged)
- Q_PROPERTY(bool use_default_file READ useDefaultFile WRITE setUseDefaultFile NOTIFY useDefaultFileChanged)
- Q_PROPERTY(short default_file_behavior READ defaultFileBehavior WRITE setDefaultFileBehavior NOTIFY defaultFileBehaviorChanged)
Q_PROPERTY(int time_threshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged)
Q_PROPERTY(int distance_threshold READ distanceThreshold WRITE setDistanceThreshold NOTIFY distanceThresholdChanged)
Q_PROPERTY(bool git_local_only READ gitLocalOnly WRITE setGitLocalOnly NOTIFY gitLocalOnlyChanged)
@@ -484,6 +519,7 @@ class SettingsObjectWrapper : public QObject {
CloudStorageSettings *cloud_storage;
DivePlannerSettings *planner_settings;
UnitsSettings *unit_settings;
+ GeneralSettingsObjectWrapper *general_settings;
public:
SettingsObjectWrapper(QObject *parent = NULL);
};