File indexing completed on 2024-05-19 04:55:54
0001 /** 0002 * \file configstore.h 0003 * Configuration storage. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 09 Jul 2011 0008 * 0009 * Copyright (C) 2011-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 <QObject> 0030 #include <QList> 0031 #include "kid3api.h" 0032 0033 class ISettings; 0034 class GeneralConfig; 0035 0036 /** 0037 * Configuration storage. 0038 */ 0039 class KID3_CORE_EXPORT ConfigStore : public QObject { 0040 public: 0041 /** 0042 * Constructor. 0043 * @param config application settings 0044 */ 0045 explicit ConfigStore(ISettings* config); 0046 0047 /** 0048 * Destructor. 0049 */ 0050 ~ConfigStore() override; 0051 0052 /** 0053 * Persist all added configurations. 0054 */ 0055 void writeToConfig(); 0056 0057 /** 0058 * Add a configuration. 0059 * The configuration will be read from the application settings. 0060 * 0061 * @param cfg configuration, ownership is taken 0062 * @return index of configuration. 0063 */ 0064 int addConfiguration(GeneralConfig* cfg); 0065 0066 /** 0067 * Access to configuration. 0068 * @param index index of configuration 0069 * @return configuration, 0 if not found. 0070 */ 0071 GeneralConfig* configuration(int index) const { 0072 return m_configurations.at(index); 0073 } 0074 0075 /** 0076 * Get a pointer to the application's config store instance. 0077 * @return config store, 0 if no instance has been allocated. 0078 */ 0079 static ConfigStore* instance() { return s_self; } 0080 0081 /** 0082 * Get the version number of the configuration which was read. 0083 * @return version number. 0084 */ 0085 static int getConfigVersion() { return s_configVersion; } 0086 0087 private: 0088 ISettings* m_config; 0089 QList<GeneralConfig*> m_configurations; 0090 static ConfigStore* s_self; 0091 static int s_configVersion; 0092 };