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 <QSettings> |
27 | #include <QString> |
28 | #include <QVariant> |
29 | |
30 | #ifndef QT_NO_PHONON_SETTINGSGROUP |
31 | |
32 | |
33 | namespace Phonon |
34 | { |
35 | class QSettingsGroup |
36 | { |
37 | public: |
38 | inline QSettingsGroup(QSettings *settings, const QString &name) |
39 | : m_mutableSettings(settings), |
40 | m_settings(settings), |
41 | m_group(name + QLatin1Char('/')) |
42 | { |
43 | } |
44 | |
45 | inline QSettingsGroup(const QSettings *settings, const QString &name) |
46 | : m_mutableSettings(nullptr), |
47 | m_settings(settings), |
48 | m_group(name + QLatin1Char('/')) |
49 | { |
50 | } |
51 | |
52 | template<typename T> |
53 | inline T value(const QString &key, const T &def) const |
54 | { |
55 | return qvariant_cast<T>(value(key, QVariant::fromValue<T>(def))); |
56 | } |
57 | |
58 | inline QVariant value(const QString &key, const QVariant &def) const |
59 | { |
60 | return m_settings->value(key: m_group + key, defaultValue: def); |
61 | } |
62 | |
63 | template<typename T> |
64 | inline void setValue(const QString &key, const T &value) |
65 | { |
66 | Q_ASSERT(m_mutableSettings); |
67 | m_mutableSettings->setValue(key: m_group + key, value: QVariant::fromValue<T>(value)); |
68 | } |
69 | |
70 | inline void removeEntry(const QString &key) |
71 | { |
72 | Q_ASSERT(m_mutableSettings); |
73 | m_mutableSettings->remove(key: m_group + key); |
74 | } |
75 | |
76 | inline bool hasKey(const QString &key) const |
77 | { |
78 | return m_settings->contains(key: m_group + key); |
79 | } |
80 | |
81 | private: |
82 | QSettings *const m_mutableSettings; |
83 | const QSettings *const m_settings; |
84 | QString m_group; |
85 | }; |
86 | } // namespace Phonon |
87 | |
88 | #endif //QT_NO_PHONON_SETTINGSGROUP |
89 | |
90 | #endif // PHONON_QSETTINGSGROUP_P_H |
91 | |