1
/*  This file is part of the KDE project
2
    Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
3
4
    This library is free software; you can redistribute it and/or
5
    modify it under the terms of the GNU Lesser General Public
6
    License as published by the Free Software Foundation; either
7
    version 2.1 of the License, or (at your option) version 3, or any
8
    later version accepted by the membership of KDE e.V. (or its
9
    successor approved by the membership of KDE e.V.), Nokia Corporation
10
    (or its successors, if any) and the KDE Free Qt Foundation, which shall
11
    act as a proxy defined in Section 6 of version 3 of the license.
12
13
    This library is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
    Lesser General Public License for more details.
17
18
    You should have received a copy of the GNU Lesser General Public
19
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
21
*/
22
23
#ifndef PHONON_QSETTINGSGROUP_P_H
24
#define PHONON_QSETTINGSGROUP_P_H
25
26
#include <QtCore/QSettings>
27
#include <QtCore/QString>
28
#include <QtCore/QVariant>
29
30
#ifndef QT_NO_PHONON_SETTINGSGROUP
31
32
QT_BEGIN_HEADER
33
QT_BEGIN_NAMESPACE
34
35
namespace Phonon
36
{
37
class QSettingsGroup
38
{
39
    public:
40
        inline QSettingsGroup(QSettings *settings, const QString &name)
41
            : m_mutableSettings(settings),
42
            m_settings(settings),
43
            m_group(name + QLatin1Char('/'))
44
        {
45
        }
46
47
        inline QSettingsGroup(const QSettings *settings, const QString &name)
48
            : m_mutableSettings(0),
49
            m_settings(settings),
50
            m_group(name + QLatin1Char('/'))
51
        {
52
        }
53
54
        template<typename T>
55
        inline T value(const QString &key, const T &def) const
56
        {
57
            return qvariant_cast<T>(value(key, QVariant::fromValue(def)));
58
        }
59
60
        inline QVariant value(const QString &key, const QVariant &def) const
61
        {
62
            return m_settings->value(m_group + key, def);
63
        }
64
65
        template<typename T>
66
        inline void setValue(const QString &key, const T &value)
67
        {
68
            Q_ASSERT(m_mutableSettings);
69
            m_mutableSettings->setValue(m_group + key, QVariant::fromValue(value));
70
        }
71
72
        inline void removeEntry(const QString &key)
73
        {
74
            Q_ASSERT(m_mutableSettings);
75
            m_mutableSettings->remove(m_group + key);
76
        }
77
78
        inline bool hasKey(const QString &key) const
79
        {
80
            return m_settings->contains(m_group + key);
81
        }
82
83
    private:
84
        QSettings *const m_mutableSettings;
85
        const QSettings *const m_settings;
86
        QString m_group;
87
};
88
} // namespace Phonon
89
90
QT_END_NAMESPACE
91
QT_END_HEADER
92
#endif //QT_NO_PHONON_SETTINGSGROUP
93
94
#endif // PHONON_QSETTINGSGROUP_P_H