-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiqconfig.h
66 lines (54 loc) · 2 KB
/
iqconfig.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* This file is part of IQ Notifier.
*
* IQ Notifier is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* IQ Notifier is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IQ Notifier. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <QObject>
#include <QSettings>
#define IQ_CONF_VAR(VAR__, NAME__, DEFAULT__) \
static constexpr auto CONFIG_##VAR__ = NAME__; \
static constexpr auto CONFIG_##VAR__##_DEFAULT = DEFAULT__;
#define IQ_CONF_FACTOR(VAR__, NAME__, DEFAULT__) \
static constexpr auto CONFIG_##VAR__ = NAME__; \
static constexpr auto VAR__##_DEFAULT_FACTOR = DEFAULT__;
class IQConfig
{
public:
static QString applicationVersion();
static QString applicationName();
static QString configDir();
explicit IQConfig(const QString &category_,
const QString &fileName_ = "config");
QVariant value(const QString &key,
const QVariant &defaultValue = QVariant()) const;
void setValue(const QString &key, const QVariant &value);
private:
const QString category;
const QString fileName;
std::unique_ptr<QSettings> settings;
QString getConfigFileName() const;
bool copyConfigFileFromExample(const QString &destination) const;
bool copyThemesFromShare(const QString &destination) const;
};
struct IQConfigurable {
IQConfigurable() = delete;
const QString &name() const;
bool isEnabled() const;
protected:
explicit IQConfigurable(const QString &name);
const QString name_;
IQConfig config;
};