File indexing completed on 2024-05-19 04:55:56
0001 /** 0002 * \file kid3settings.cpp 0003 * Wrapper for Qt 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 #include "kid3settings.h" 0028 #include <QSettings> 0029 #include <QStringList> 0030 0031 namespace { 0032 0033 void copyOldSettings(QSettings* config) 0034 { 0035 if (!config->contains(QLatin1String("Tags/MarkTruncations"))) { 0036 // Configuration missing or not in current format 0037 if (QSettings oldSettings( 0038 QSettings::UserScope, QLatin1String("kid3.sourceforge.net"), 0039 QLatin1String("Kid3")); 0040 oldSettings.contains(QLatin1String("/kid3/General Options/ExportFormatIdx"))) { 0041 oldSettings.beginGroup(QLatin1String("/kid3")); 0042 const auto keys = oldSettings.allKeys(); 0043 for (const QString& key : keys) { 0044 QString newKey(key); 0045 newKey.replace(QLatin1String("Recent Files"), 0046 QLatin1String("RecentFiles")); 0047 config->setValue(newKey, oldSettings.value(key)); 0048 } 0049 qDebug("Copied old settings"); 0050 } 0051 } 0052 } 0053 0054 } 0055 0056 /** 0057 * Constructor. 0058 */ 0059 Kid3Settings::Kid3Settings(QSettings* config) : m_config(config) 0060 { 0061 copyOldSettings(m_config); 0062 migrateOldSettings(); 0063 } 0064 0065 /** 0066 * Use settings subgroup. 0067 * @param prefix group name 0068 * @param forState true if this group stores state information 0069 */ 0070 void Kid3Settings::beginGroup(const QString& prefix, bool forState) 0071 { 0072 Q_UNUSED(forState); 0073 m_config->beginGroup(prefix); 0074 } 0075 0076 /** 0077 * Finnish using settings subgroup. 0078 */ 0079 void Kid3Settings::endGroup() 0080 { 0081 m_config->endGroup(); 0082 } 0083 0084 /** 0085 * Set value for setting. 0086 * @param key name of setting 0087 * @param value value for setting 0088 */ 0089 void Kid3Settings::setValue(const QString& key, const QVariant& value) 0090 { 0091 m_config->setValue(key, value); 0092 } 0093 0094 /** 0095 * Get value for setting. 0096 * @param key name of setting 0097 * @param defaultValue default value 0098 * @return value of setting as variant. 0099 */ 0100 QVariant Kid3Settings::value(const QString& key, 0101 const QVariant& defaultValue) const 0102 { 0103 return m_config->value(key, defaultValue); 0104 } 0105 0106 /** 0107 * Remove setting. 0108 * @param key name of setting 0109 */ 0110 void Kid3Settings::remove(const QString& key) 0111 { 0112 m_config->remove(key); 0113 } 0114 0115 /** 0116 * Check if setting exists. 0117 * @param key name of setting 0118 * @return true if setting exists. 0119 */ 0120 bool Kid3Settings::contains(const QString& key) const 0121 { 0122 return m_config->contains(key); 0123 } 0124 0125 /** 0126 * Write unsaved changes to permanent storage. 0127 */ 0128 void Kid3Settings::sync() 0129 { 0130 m_config->sync(); 0131 }