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
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QVariant>
|
2018-06-30 09:23:33 +00:00
|
|
|
#include <QObject>
|
2018-06-16 14:03:31 +00:00
|
|
|
#include "core/qthelper.h"
|
|
|
|
|
2018-07-17 13:22:51 +00:00
|
|
|
// implementation class of the interface classes
|
|
|
|
class qPrefPrivate : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
static qPrefPrivate *instance();
|
|
|
|
|
|
|
|
QSettings setting;
|
|
|
|
|
|
|
|
private:
|
|
|
|
qPrefPrivate(QObject *parent = NULL);
|
|
|
|
};
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
//****** Macros to be used in the set functions ******
|
2018-06-16 14:03:31 +00:00
|
|
|
#define COPY_TXT(name, string) \
|
|
|
|
{ \
|
|
|
|
free((void *)prefs.name); \
|
|
|
|
prefs.name = copy_qstring(string); \
|
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
//****** Macros to be used in the disk functions, which are special ******
|
|
|
|
#define LOADSYNC_BOOL(name, field) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
2018-06-30 09:23:33 +00:00
|
|
|
if (doSync) \
|
2018-07-17 13:22:51 +00:00
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-07-17 13:22:51 +00:00
|
|
|
prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toBool(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
#define LOADSYNC_DOUBLE(name, field) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-07-17 13:22:51 +00:00
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-07-17 13:22:51 +00:00
|
|
|
prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toDouble(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define LOADSYNC_ENUM(name, type, field) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-07-17 13:22:51 +00:00
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-07-17 13:22:51 +00:00
|
|
|
prefs.field = (enum type)qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toInt(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
#define LOADSYNC_INT(name, field) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
2018-06-30 09:23:33 +00:00
|
|
|
if (doSync) \
|
2018-07-17 13:22:51 +00:00
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-07-17 13:22:51 +00:00
|
|
|
prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toInt(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
#define LOADSYNC_INT_DEF(name, field, defval) \
|
2018-06-16 14:03:31 +00:00
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-07-17 13:22:51 +00:00
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-07-17 13:22:51 +00:00
|
|
|
prefs.field = qPrefPrivate::instance()->setting.value(group + name, defval).toInt(); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define LOADSYNC_TXT(name, field) \
|
|
|
|
{ \
|
|
|
|
if (doSync) \
|
2018-07-17 13:22:51 +00:00
|
|
|
qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
|
2018-06-16 14:03:31 +00:00
|
|
|
else \
|
2018-07-17 13:22:51 +00:00
|
|
|
prefs.field = copy_qstring(qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toString()); \
|
2018-06-16 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:23:33 +00:00
|
|
|
//******* Macros to generate disk function
|
2018-07-04 12:13:48 +00:00
|
|
|
#define DISK_LOADSYNC_BOOL(usegroup, name, field) \
|
|
|
|
void qPref ## usegroup::disk_ ## field(bool doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
{ \
|
|
|
|
LOADSYNC_BOOL(name, field); \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define DISK_LOADSYNC_DOUBLE(usegroup, name, field) \
|
|
|
|
void qPref ## usegroup::disk_ ## field(bool doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
{ \
|
|
|
|
LOADSYNC_DOUBLE(name, field); \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define DISK_LOADSYNC_ENUM(usegroup, name, type, field) \
|
|
|
|
void qPref ## usegroup::disk_ ## field(bool doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
{ \
|
|
|
|
LOADSYNC_ENUM(name, type, field); \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define DISK_LOADSYNC_INT(usegroup, name, field) \
|
|
|
|
void qPref ## usegroup::disk_ ## field(bool doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
{ \
|
2018-07-15 12:06:25 +00:00
|
|
|
LOADSYNC_INT(name, field); \
|
2018-06-30 09:23:33 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define DISK_LOADSYNC_INT_DEF(usegroup, name, field, defval) \
|
|
|
|
void qPref ## usegroup::disk_ ## field(bool doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
{ \
|
|
|
|
LOADSYNC_INT_DEF(name, field, defval); \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define DISK_LOADSYNC_TXT(usegroup, name, field) \
|
|
|
|
void qPref ## usegroup::disk_ ## field(bool doSync) \
|
2018-06-30 09:23:33 +00:00
|
|
|
{ \
|
|
|
|
LOADSYNC_TXT(name, field); \
|
|
|
|
}
|
2018-07-01 20:26:27 +00:00
|
|
|
|
|
|
|
//******* Macros to generate get function
|
2018-07-04 12:13:48 +00:00
|
|
|
#define GET_PREFERENCE_BOOL(usegroup, field) \
|
|
|
|
bool qPref ## usegroup::field () const \
|
2018-07-01 20:26:27 +00:00
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define GET_PREFERENCE_DOUBLE(usegroup, field) \
|
|
|
|
double qPref ## usegroup::field () const \
|
2018-07-01 20:26:27 +00:00
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define GET_PREFERENCE_ENUM(usegroup, type, field) \
|
|
|
|
struct type qPref ## usegroup:: ## field () const \
|
2018-07-01 20:26:27 +00:00
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define GET_PREFERENCE_INT(usegroup, field) \
|
|
|
|
int qPref ## usegroup::field () const \
|
2018-07-01 20:26:27 +00:00
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define GET_PREFERENCE_TXT(usegroup, field) \
|
|
|
|
const QString qPref ## usegroup::field () const \
|
2018-07-01 20:26:27 +00:00
|
|
|
{ \
|
|
|
|
return prefs.field; \
|
|
|
|
}
|
2018-07-02 07:25:20 +00:00
|
|
|
|
|
|
|
//******* Macros to generate set function
|
2018-07-04 12:13:48 +00:00
|
|
|
#define SET_PREFERENCE_BOOL(usegroup, field) \
|
|
|
|
void qPref ## usegroup::set_ ## field (bool value) \
|
2018-07-02 07:25:20 +00:00
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define SET_PREFERENCE_DOUBLE(usegroup, field) \
|
|
|
|
void qPref ## usegroup::set_ ## field (double value) \
|
2018-07-02 07:25:20 +00:00
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define SET_PREFERENCE_ENUM(usegroup, type, field) \
|
|
|
|
void qPref ## usegroup::set_ ## field (type value) \
|
2018-07-02 07:25:20 +00:00
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define SET_PREFERENCE_INT(usegroup, field) \
|
|
|
|
void qPref ## usegroup::set_ ## field (int value) \
|
2018-07-02 07:25:20 +00:00
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
prefs.field = value; \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:13:48 +00:00
|
|
|
#define SET_PREFERENCE_TXT(usegroup, field) \
|
|
|
|
void qPref ## usegroup::set_ ## field (const QString& value) \
|
2018-07-02 07:25:20 +00:00
|
|
|
{ \
|
|
|
|
if (value != prefs.field) { \
|
|
|
|
COPY_TXT(field, value); \
|
|
|
|
disk_ ## field(true); \
|
|
|
|
emit field ## _changed(value); \
|
|
|
|
} \
|
|
|
|
}
|
2018-07-04 12:13:48 +00:00
|
|
|
|
|
|
|
//******* Macros to generate set/set/loadsync combined
|
|
|
|
#define HANDLE_PREFERENCE_BOOL(usegroup, name, field) \
|
|
|
|
GET_PREFERENCE_BOOL(usegroup, field); \
|
|
|
|
SET_PREFERENCE_BOOL(usegroup, field); \
|
|
|
|
DISK_LOADSYNC_BOOL(usegroup, name, field);
|
|
|
|
|
|
|
|
#define HANDLE_PREFERENCE_DOUBLE(usegroup, name, field) \
|
|
|
|
GET_PREFERENCE_DOUBLE(usegroup, field); \
|
|
|
|
SET_PREFERENCE_DOUBLE(usegroup, field); \
|
|
|
|
DISK_LOADSYNC_DOUBLE(usegroup, name, field);
|
|
|
|
|
|
|
|
#define HANDLE_PREFERENCE_ENUM(usegroup, type, name, field) \
|
|
|
|
GET_PREFERENCE_ENUM(usegroup, type, field); \
|
|
|
|
SET_PREFERENCE_ENUM(usegroup, type, field); \
|
|
|
|
DISK_LOADSYNC_ENUM(usegroup, name, type, field);
|
|
|
|
|
|
|
|
#define HANDLE_PREFERENCE_INT(usegroup, name, field) \
|
|
|
|
GET_PREFERENCE_INT(usegroup, field); \
|
|
|
|
SET_PREFERENCE_INT(usegroup, field); \
|
|
|
|
DISK_LOADSYNC_INT(usegroup, name, field);
|
|
|
|
|
|
|
|
#define HANDLE_PREFERENCE_TXT(usegroup, name, field) \
|
|
|
|
GET_PREFERENCE_TXT(usegroup, field); \
|
|
|
|
SET_PREFERENCE_TXT(usegroup, field); \
|
|
|
|
DISK_LOADSYNC_TXT(usegroup, name, field);
|
|
|
|
|
2018-06-16 14:03:31 +00:00
|
|
|
#endif
|