File indexing completed on 2024-05-19 04:55:51
0001 /** 0002 * \file kdesettings.h 0003 * Wrapper for KDE application settings. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 07 Apr 2013 0008 * 0009 * Copyright (C) 2013-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <QScopedPointer> 0030 #include <KSharedConfig> 0031 #include "isettings.h" 0032 0033 class KConfigGroup; 0034 0035 /** 0036 * Wrapper for KDE application settings. 0037 */ 0038 class KdeSettings : public ISettings { 0039 public: 0040 /** 0041 * Constructor. 0042 * @param config KDE settings 0043 * @param stateConfig state information 0044 */ 0045 explicit KdeSettings(KSharedConfigPtr config, KSharedConfigPtr stateConfig); 0046 0047 /** 0048 * Destructor. 0049 */ 0050 ~KdeSettings() override; 0051 0052 /** 0053 * Use settings subgroup. 0054 * @param prefix group name 0055 * @param forState true if this group stores state information 0056 */ 0057 void beginGroup(const QString& prefix, bool forState = false) override; 0058 0059 /** 0060 * Finnish using settings subgroup. 0061 */ 0062 void endGroup() override; 0063 0064 /** 0065 * Set value for setting. 0066 * @param key name of setting 0067 * @param value value for setting 0068 */ 0069 void setValue(const QString& key, const QVariant& value) override; 0070 0071 /** 0072 * Get value for setting. 0073 * @param key name of setting 0074 * @param defaultValue default value 0075 * @return value of setting as variant. 0076 */ 0077 QVariant value(const QString& key, 0078 const QVariant& defaultValue) const override; 0079 0080 /** 0081 * Remove setting. 0082 * @param key name of setting 0083 */ 0084 void remove(const QString& key) override; 0085 0086 /** 0087 * Check if setting exists. 0088 * @param key name of setting 0089 * @return true if setting exists. 0090 */ 0091 bool contains(const QString& key) const override; 0092 0093 /** 0094 * Write unsaved changes to permanent storage. 0095 */ 0096 void sync() override; 0097 0098 private: 0099 KSharedConfigPtr m_config; 0100 KSharedConfigPtr m_stateConfig; 0101 QScopedPointer<KConfigGroup> m_group; 0102 };