/
ssuvariables_p.h
79 lines (72 loc) · 3 KB
1
/**
2
* @file ssuvariables_p.h
3
4
5
6
7
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/
8
9
#ifndef _SSUVARIABLES_P_H
#define _SSUVARIABLES_P_H
10
11
12
13
#include <QObject>
#include <QHash>
14
15
#include "ssusettings.h"
16
17
18
19
20
21
class SsuVariables: public QObject {
Q_OBJECT
public:
SsuVariables();
/**
22
23
24
25
26
* Return a default variable section, if exists, or an empty string.
*
* To identify the default section the section name gets split at '-', and
* the first token (or second token for "var-" sections) replaced with
* "default". You should therefore avoid "-" in section names.
27
*/
28
static QString defaultSection(SsuSettings *settings, QString section);
29
30
31
/**
* Resolve a whole string, containing several variables. Variables inside variables are allowed
*/
32
static QString resolveString(QString pattern, QHash<QString, QString> *variables, int recursionDepth=0);
33
34
35
/**
* Resolve variables; variable can be passed as %(var) or var
*/
36
37
38
39
40
41
42
43
44
45
46
47
48
static QString resolveVariable(QString variable, QHash<QString, QString> *variables);
/**
* Set the settings object to use
*/
void setSettings(SsuSettings *settings);
/*
* Return the settings object used
*/
SsuSettings *settings();
/**
* Return a variable from the given variable section. 'var'- is automatically
* prepended to the section name if not specified already. Recursive search
* through several variable sections (specified in the section) is supported,
49
* returned will be the last occurence of the variable.
50
51
52
53
*/
QVariant variable(QString section, const QString &key);
static QVariant variable(SsuSettings *settings, QString section, const QString &key);
/**
54
55
56
57
58
59
60
61
62
63
64
* Return the requested variable section, recursively looking up all variable
* sections referenced inside with the 'variable' keyword. 'var-' is automatically
* prepended to the section names of included variable sections, but not for
* the parent section.
*
* Variables starting with _ are treated as local variables and are ignored.
* The special key 'local' may contain a section-specific stringlist with
* additional keys which should be treated local.
*
* This function tries to identify a default configuration section, and merges
* the default section with the requested section.
65
66
*/
void variableSection(QString section, QHash<QString, QString> *storageHash);
67
68
static void variableSection(SsuSettings *settings, QString section,
QHash<QString, QString> *storageHash);
69
70
private:
71
72
73
74
75
static void readSection(SsuSettings *settings, QString section,
QHash<QString, QString> *storageHash, int recursionDepth,
bool logOverride=true);
static QVariant readVariable(SsuSettings *settings, QString section, const QString &key,
int recursionDepth, bool logOverride=true);
76
SsuSettings *m_settings;
77
78
79
};
#endif