2018-06-16 14:03:31 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef QPREFPRIVATE_H
|
|
|
|
#define QPREFPRIVATE_H
|
|
|
|
|
|
|
|
// Header used by all qPref<class> implementations to avoid duplicating code
|
2018-07-25 17:49:48 +00:00
|
|
|
#include "core/qthelper.h"
|
2018-07-18 18:58:13 +00:00
|
|
|
#include "qPref.h"
|
2018-07-25 17:49:48 +00:00
|
|
|
#include <QObject>
|
2018-06-16 14:03:31 +00:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2018-07-17 13:22:51 +00:00
|
|
|
// implementation class of the interface classes
|
|
|
|
class qPrefPrivate : public QObject {
|
2018-07-25 17:49:48 +00:00
|
|
|
Q_OBJECT
|
2018-07-17 13:22:51 +00:00
|
|
|
|
|
|
|
public:
|
2018-07-18 18:58:13 +00:00
|
|
|
friend class qPrefAnimations;
|
|
|
|
friend class qPrefCloudStorage;
|
|
|
|
friend class qPrefDisplay;
|
2018-07-15 16:15:40 +00:00
|
|
|
friend class qPrefDiveComputer;
|
2018-08-01 15:14:04 +00:00
|
|
|
friend class qPrefDivePlanner;
|
2018-07-23 13:10:40 +00:00
|
|
|
friend class qPrefFacebook;
|
2018-07-27 08:25:43 +00:00
|
|
|
friend class qPrefProxy;
|
2018-07-31 13:04:12 +00:00
|
|
|
friend class qPrefUnits;
|
2018-08-03 17:24:53 +00:00
|
|
|
friend class qPrefUpdateManager;
|
2018-07-18 18:58:13 +00:00
|
|
|
|
|
|
|
private:
|
2018-07-25 17:49:48 +00:00
|
|
|
static qPrefPrivate *instance();
|
2018-07-17 13:22:51 +00:00
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
|
2018-07-18 18:47:59 +00:00
|
|
|
// Helper functions
|
2018-07-25 17:49:48 +00:00
|
|
|
static void copy_txt(const char **name, const QString &string);
|
2018-07-18 18:47:59 +00:00
|
|
|
|
2018-07-25 17:49:48 +00:00
|
|
|
qPrefPrivate(QObject *parent = NULL);
|
2018-07-17 13:22:51 +00:00
|
|
|
};
|
|
|
|
|
2018-07-18 20:52:13 +00:00
|
|
|
|
|
|
|
//******* Macros to generate disk function
|
2018-07-25 17:49:48 +00:00
|
|
|
#define DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, usestruct) \
|
|
|
|
void qPref##usegroup::disk_##field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
|
|
|
|
else \
|
|
|
|
prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toBool(); \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define DISK_LOADSYNC_BOOL(usegroup, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, )
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, usestruct) \
|
|
|
|
void qPref##usegroup::disk_##field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
|
|
|
|
else \
|
|
|
|
prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toDouble(); \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define DISK_LOADSYNC_DOUBLE(usegroup, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, )
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, usestruct) \
|
|
|
|
void qPref##usegroup::disk_##field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
|
|
|
|
else \
|
|
|
|
prefs.usestruct field = (enum type)qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toInt(); \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define DISK_LOADSYNC_ENUM(usegroup, name, type, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, )
|
|
|
|
|
|
|
|
#define DISK_LOADSYNC_INT_EXT(usegroup, name, field, usestruct) \
|
|
|
|
void qPref##usegroup::disk_##field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
|
|
|
|
else \
|
|
|
|
prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toInt(); \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define DISK_LOADSYNC_INT(usegroup, name, field) \
|
2018-07-27 18:35:48 +00:00
|
|
|
DISK_LOADSYNC_INT_EXT(usegroup, name, field, )
|
2018-07-25 17:49:48 +00:00
|
|
|
|
|
|
|
#define DISK_LOADSYNC_INT_DEF_EXT(usegroup, name, field, defval, usestruct) \
|
|
|
|
void qPref##usegroup::disk_##field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
|
|
|
|
else \
|
|
|
|
prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, defval).toInt(); \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define DISK_LOADSYNC_INT_DEF(usegroup, name, field, defval) \
|
2018-07-25 17:49:48 +00:00
|
|
|
DISK_LOADSYNC_INT_DEF_EXT(usegroup, name, field, defval, )
|
|
|
|
|
2018-08-02 17:35:04 +00:00
|
|
|
#define DISK_LOADSYNC_STRUCT_EXT(usegroup, name, field, var, usestruct) \
|
|
|
|
void qPref##usegroup::disk_##field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field . var); \
|
|
|
|
else \
|
|
|
|
prefs.usestruct field . var = qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field . var).toInt(); \
|
|
|
|
}
|
|
|
|
#define DISK_LOADSYNC_STRUCT(usegroup, name, field, var) \
|
|
|
|
DISK_LOADSYNC_STRUCT_EXT(usegroup, name, field, var, )
|
|
|
|
|
2018-07-25 17:49:48 +00:00
|
|
|
#define DISK_LOADSYNC_TXT_EXT(usegroup, name, field, usestruct) \
|
|
|
|
void qPref##usegroup::disk_##field(bool doSync) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
|
|
|
|
else \
|
|
|
|
prefs.usestruct field = copy_qstring(qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toString()); \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define DISK_LOADSYNC_TXT(usegroup, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
DISK_LOADSYNC_TXT_EXT(usegroup, name, field, )
|
2018-06-16 14:03:31 +00:00
|
|
|
|
2018-07-02 07:25:20 +00:00
|
|
|
//******* Macros to generate set function
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_BOOL_EXT(usegroup, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
void qPref##usegroup::set_##field(bool value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.usestruct field) { \
|
|
|
|
prefs.usestruct field = value; \
|
|
|
|
disk_##field(true); \
|
|
|
|
emit field##_changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_BOOL(usegroup, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_BOOL_EXT(usegroup, field, )
|
2018-07-02 07:25:20 +00:00
|
|
|
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_DOUBLE_EXT(usegroup, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
void qPref##usegroup::set_##field(double value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.usestruct field) { \
|
|
|
|
prefs.usestruct field = value; \
|
|
|
|
disk_##field(true); \
|
|
|
|
emit field##_changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_DOUBLE(usegroup, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_DOUBLE_EXT(usegroup, field, )
|
2018-07-02 07:25:20 +00:00
|
|
|
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_ENUM_EXT(usegroup, type, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
void qPref##usegroup::set_##field(type value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.usestruct field) { \
|
|
|
|
prefs.usestruct field = value; \
|
|
|
|
disk_##field(true); \
|
|
|
|
emit field##_changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_ENUM(usegroup, type, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_ENUM_EXT(usegroup, type, field, )
|
2018-07-02 07:25:20 +00:00
|
|
|
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_INT_EXT(usegroup, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
void qPref##usegroup::set_##field(int value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.usestruct field) { \
|
|
|
|
prefs.usestruct field = value; \
|
|
|
|
disk_##field(true); \
|
|
|
|
emit field##_changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_INT(usegroup, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_INT_EXT(usegroup, field, )
|
|
|
|
|
2018-08-02 17:35:04 +00:00
|
|
|
#define SET_PREFERENCE_STRUCT_EXT(usegroup, type, field, var, usestruct) \
|
|
|
|
void qPref##usegroup::set_##field(type value) \
|
|
|
|
{ \
|
|
|
|
if (value. var != prefs.usestruct field . var) { \
|
|
|
|
prefs.usestruct field . var = value . var; \
|
|
|
|
disk_##field(true); \
|
|
|
|
emit field##_changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define SET_PREFERENCE_STRUCT(usegroup, type, field, var) \
|
|
|
|
SET_PREFERENCE_STRUCT_EXT(usegroup, type, field, var, )
|
|
|
|
|
2018-07-25 17:49:48 +00:00
|
|
|
#define SET_PREFERENCE_TXT_EXT(usegroup, field, usestruct) \
|
|
|
|
void qPref##usegroup::set_##field(const QString &value) \
|
|
|
|
{ \
|
|
|
|
if (value != prefs.usestruct field) { \
|
|
|
|
qPrefPrivate::instance()->copy_txt(&prefs.usestruct field, value); \
|
|
|
|
disk_##field(true); \
|
|
|
|
emit field##_changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
2018-07-22 13:30:07 +00:00
|
|
|
#define SET_PREFERENCE_TXT(usegroup, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_TXT_EXT(usegroup, field, )
|
2018-07-04 12:13:48 +00:00
|
|
|
|
|
|
|
//******* Macros to generate set/set/loadsync combined
|
2018-07-22 13:30:07 +00:00
|
|
|
#define HANDLE_PREFERENCE_BOOL_EXT(usegroup, name, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_BOOL_EXT(usegroup, field, usestruct); \
|
|
|
|
DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, usestruct);
|
2018-07-04 12:13:48 +00:00
|
|
|
#define HANDLE_PREFERENCE_BOOL(usegroup, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
HANDLE_PREFERENCE_BOOL_EXT(usegroup, name, field, )
|
2018-07-04 12:13:48 +00:00
|
|
|
|
2018-07-22 13:30:07 +00:00
|
|
|
#define HANDLE_PREFERENCE_DOUBLE_EXT(usegroup, name, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_DOUBLE_EXT(usegroup, field, usestruct); \
|
|
|
|
DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, usestruct);
|
2018-07-04 12:13:48 +00:00
|
|
|
#define HANDLE_PREFERENCE_DOUBLE(usegroup, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
HANDLE_PREFERENCE_DOUBLE_EXT(usegroup, name, field, )
|
2018-07-04 12:13:48 +00:00
|
|
|
|
2018-07-22 13:30:07 +00:00
|
|
|
#define HANDLE_PREFERENCE_ENUM_EXT(usegroup, type, name, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_ENUM_EXT(usegroup, type, field, usestruct); \
|
|
|
|
DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, usestruct);
|
2018-07-04 12:13:48 +00:00
|
|
|
#define HANDLE_PREFERENCE_ENUM(usegroup, type, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(usegroup, type, name, field, )
|
2018-07-04 12:13:48 +00:00
|
|
|
|
2018-07-22 13:30:07 +00:00
|
|
|
#define HANDLE_PREFERENCE_INT_EXT(usegroup, name, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_INT_EXT(usegroup, field, usestruct); \
|
|
|
|
DISK_LOADSYNC_INT_EXT(usegroup, name, field, usestruct);
|
2018-07-04 12:13:48 +00:00
|
|
|
#define HANDLE_PREFERENCE_INT(usegroup, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
HANDLE_PREFERENCE_INT_EXT(usegroup, name, field, )
|
2018-07-04 12:13:48 +00:00
|
|
|
|
2018-07-27 18:35:48 +00:00
|
|
|
#define HANDLE_PREFERENCE_INT_DEF_EXT(usegroup, name, field, defval, usestruct) \
|
|
|
|
SET_PREFERENCE_INT_EXT(usegroup, field, usestruct); \
|
|
|
|
DISK_LOADSYNC_INT_DEF_EXT(usegroup, name, field, defval, usestruct);
|
|
|
|
#define HANDLE_PREFERENCE_INT_DEF(usegroup, name, field, defval) \
|
|
|
|
HANDLE_PREFERENCE_INT_DEF_EXT(usegroup, name, field, defval, )
|
|
|
|
|
2018-08-02 17:35:04 +00:00
|
|
|
#define HANDLE_PREFERENCE_STRUCT_EXT(usegroup, type, name, field, var, usestruct) \
|
|
|
|
SET_PREFERENCE_STRUCT_EXT(usegroup, type, field, var, usestruct) \
|
|
|
|
DISK_LOADSYNC_STRUCT_EXT(usegroup, name, field, var, usestruct)
|
|
|
|
#define HANDLE_PREFERENCE_STRUCT(usegroup, type, name, field, var) \
|
|
|
|
HANDLE_PREFERENCE_STRUCT_EXT(usegroup, type, name, field, var, )
|
|
|
|
|
2018-07-22 13:30:07 +00:00
|
|
|
#define HANDLE_PREFERENCE_TXT_EXT(usegroup, name, field, usestruct) \
|
2018-07-25 17:49:48 +00:00
|
|
|
SET_PREFERENCE_TXT_EXT(usegroup, field, usestruct); \
|
|
|
|
DISK_LOADSYNC_TXT_EXT(usegroup, name, field, usestruct);
|
2018-07-04 12:13:48 +00:00
|
|
|
#define HANDLE_PREFERENCE_TXT(usegroup, name, field) \
|
2018-07-25 17:49:48 +00:00
|
|
|
HANDLE_PREFERENCE_TXT_EXT(usegroup, name, field, )
|
2018-07-04 12:13:48 +00:00
|
|
|
|
2018-06-16 14:03:31 +00:00
|
|
|
#endif
|