-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathoptions.h
More file actions
83 lines (79 loc) · 3.36 KB
/
options.h
File metadata and controls
83 lines (79 loc) · 3.36 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef OPTIONS_H
#define OPTIONS_H
#include <QObject>
#include <QVariant>
#include <QByteArray>
#include <QDomDocument>
#include "utilsexport.h"
class UTILS_EXPORT OptionsNode
{
friend class Options;
public:
OptionsNode();
OptionsNode(const OptionsNode &ANode);
~OptionsNode();
bool isNull() const;
QString path() const;
QString name() const;
QString nspace() const;
OptionsNode parent() const;
QList<QString> parentNSpaces() const;
QList<QString> childNames() const;
QList<QString> childNSpaces(const QString &AName) const;
bool isChildNode(const OptionsNode &ANode) const;
QString childPath(const OptionsNode &ANode) const;
void removeChilds(const QString &AName = QString::null, const QString &ANSpace = QString::null) const;
OptionsNode node(const QString &APath, const QString &ANSpace = QString::null) const;
bool hasValue(const QString &APath = QString::null, const QString &ANSpace = QString::null) const;
QVariant value(const QString &APath = QString::null, const QString &ANSpace = QString::null) const;
void setValue(const QVariant &AValue, const QString &APath = QString::null, const QString &ANSpace = QString::null);
public:
bool operator==(const OptionsNode &AOther) const;
bool operator!=(const OptionsNode &AOther) const;
OptionsNode &operator=(const OptionsNode &AOther);
public:
static const OptionsNode null;
private:
OptionsNode(const QDomElement &ANode);
struct OptionsNodeData;
OptionsNodeData *d;
};
class UTILS_EXPORT Options :
public QObject
{
Q_OBJECT
friend class OptionsNode;
public:
static Options *instance();
static bool isNull();
static QString filesPath();
static QByteArray cryptKey();
static QString cleanNSpaces(const QString &APath); // account[uid].name -> account.name
static bool hasNode(const QString &APath, const QString &ANSpace = QString::null);
static OptionsNode node(const QString &APath, const QString &ANSpace = QString::null); // ANSpace - account id
static QVariant fileValue(const QString &APath, const QString &ANSpace = QString::null);
static void setFileValue(const QVariant &AValue, const QString &APath, const QString &ANSpace = QString::null);
static void setOptions(QDomDocument AOptions, const QString &AFilesPath, const QByteArray &ACryptKey);
static QVariant defaultValue(const QString &APath);
static void setDefaultValue(const QString &APath, const QVariant &ADefault);
static QByteArray encrypt(const QVariant &AValue, const QByteArray &AKey = cryptKey());
static QVariant decrypt(const QByteArray &AData, const QByteArray &AKey = cryptKey());
static void exportNode(const QString &APath, QDomElement &AToElem);
static void importNode(const QString &APath, const QDomElement &AFromElem);
// global settings (using QSettings)
static void setGlobalValue(const QString &key, const QVariant &value);
static QVariant globalValue(const QString &key, const QVariant &defaultValue = QVariant());
static bool hasGlobalValue(const QString &key);
static void removeGlobalValue(const QString &key);
signals:
void optionsOpened();
void optionsClosed();
void optionsCreated(const OptionsNode &ANode);
void optionsChanged(const OptionsNode &ANode);
void optionsRemoved(const OptionsNode &ANode);
void defaultValueChanged(const QString &APath, const QVariant &ADefault);
private:
struct OptionsData;
static OptionsData *d;
};
#endif // OPTIONS_H