File indexing completed on 2025-02-09 05:31:53
0001 /* This file is part of the KDE project 0002 Copyright (C) 2007 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), Nokia Corporation 0010 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 0021 */ 0022 0023 #ifndef PHONON_QSETTINGSGROUP_P_H 0024 #define PHONON_QSETTINGSGROUP_P_H 0025 0026 #include <QSettings> 0027 #include <QString> 0028 #include <QVariant> 0029 0030 #ifndef QT_NO_PHONON_SETTINGSGROUP 0031 0032 0033 namespace Phonon 0034 { 0035 class QSettingsGroup 0036 { 0037 public: 0038 inline QSettingsGroup(QSettings *settings, const QString &name) 0039 : m_mutableSettings(settings), 0040 m_settings(settings), 0041 m_group(name + QLatin1Char('/')) 0042 { 0043 } 0044 0045 inline QSettingsGroup(const QSettings *settings, const QString &name) 0046 : m_mutableSettings(nullptr), 0047 m_settings(settings), 0048 m_group(name + QLatin1Char('/')) 0049 { 0050 } 0051 0052 template<typename T> 0053 inline T value(const QString &key, const T &def) const 0054 { 0055 return qvariant_cast<T>(value(key, QVariant::fromValue<T>(def))); 0056 } 0057 0058 inline QVariant value(const QString &key, const QVariant &def) const 0059 { 0060 return m_settings->value(m_group + key, def); 0061 } 0062 0063 template<typename T> 0064 inline void setValue(const QString &key, const T &value) 0065 { 0066 Q_ASSERT(m_mutableSettings); 0067 m_mutableSettings->setValue(m_group + key, QVariant::fromValue<T>(value)); 0068 } 0069 0070 inline void removeEntry(const QString &key) 0071 { 0072 Q_ASSERT(m_mutableSettings); 0073 m_mutableSettings->remove(m_group + key); 0074 } 0075 0076 inline bool hasKey(const QString &key) const 0077 { 0078 return m_settings->contains(m_group + key); 0079 } 0080 0081 private: 0082 QSettings *const m_mutableSettings; 0083 const QSettings *const m_settings; 0084 QString m_group; 0085 }; 0086 } // namespace Phonon 0087 0088 #endif //QT_NO_PHONON_SETTINGSGROUP 0089 0090 #endif // PHONON_QSETTINGSGROUP_P_H