File indexing completed on 2024-05-05 04:48:32
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef STATSYNCING_IMPORTER_MANAGER_H 0018 #define STATSYNCING_IMPORTER_MANAGER_H 0019 0020 #include "statsyncing/ProviderFactory.h" 0021 0022 #include "amarok_export.h" 0023 0024 #include <KConfigGroup> 0025 #include <KPluginInfo> 0026 0027 0028 namespace StatSyncing 0029 { 0030 0031 class ImporterProvider; 0032 typedef QSharedPointer<ImporterProvider> ImporterProviderPtr; 0033 typedef QMap<QString, ProviderPtr> ProviderPtrMap; 0034 0035 /** 0036 * The ImporterManager class is a base class for every @see StatSyncing::ProviderFactory 0037 * derived importer provider factory, which in turn is derived from 0038 * Plugins::PluginFactory . 0039 * 0040 * For details about methods' purpose, and other methods that need to be implemented 0041 * in a concrete ImporterManager see StatSyncing::ProviderFactory documentation. 0042 */ 0043 class AMAROK_EXPORT ImporterManager : public ProviderFactory 0044 { 0045 Q_OBJECT 0046 0047 public: 0048 /** 0049 * Constructor. Sets the Plugins::PluginFactory m_type variable to type Importer 0050 */ 0051 ImporterManager(); 0052 0053 /** 0054 * Destructor. 0055 */ 0056 ~ImporterManager() override; 0057 0058 /** 0059 * Loads up saved configuration, for every retrieved config calls 0060 * createProvider( config ), and then registers created providers with 0061 * StatSyncing::Controller. This method is called by PluginManager. 0062 */ 0063 void init() override; 0064 0065 /** 0066 * Basic implementation for StatSyncing::ProviderFactory createConfigWidget() method, 0067 * used for configuring new providers. By default calls @see getConfigWidget with 0068 * empty config parameter. 0069 */ 0070 ProviderConfigWidget *createConfigWidget() override; 0071 0072 /** 0073 * Returns a configuration widget prepopulated with given config values. 0074 */ 0075 virtual ProviderConfigWidget *configWidget( const QVariantMap &config 0076 = QVariantMap() ) = 0; 0077 public Q_SLOTS: 0078 /** 0079 * Creates a new provider by calling newInstance and saves the config to the disk. 0080 * The created provider is registered with the StatSyncing::Controller 0081 * 0082 * This method can also be used to replace existing provider instances. 0083 */ 0084 ProviderPtr createProvider( const QVariantMap &config ) override; 0085 0086 protected: 0087 /** 0088 * Convenience method returning a config group for this manager. 0089 */ 0090 KConfigGroup managerConfig() const; 0091 0092 /** 0093 * Convenience method returning a config group for a given @param providerId . 0094 */ 0095 KConfigGroup providerConfig( const QString &providerId ) const; 0096 0097 /** 0098 * Overload of @see ImporterManager::providerConfig( const QString ) . 0099 */ 0100 KConfigGroup providerConfig( const ProviderPtr &provider ) const; 0101 0102 /** 0103 * Return a new provider instance. 0104 */ 0105 virtual ImporterProviderPtr newInstance( const QVariantMap &config ) = 0; 0106 0107 /** 0108 * A list of every provider associated with this ImporterManager instance. 0109 * After init() it's populated by loaded providers. 0110 */ 0111 ProviderPtrMap m_providers; 0112 0113 protected Q_SLOTS: 0114 /** 0115 * ProviderImporter listens to StatSyncing::Config's providerForgotten signal, and 0116 * unregisters and removes managed providers if they're forgotten. 0117 */ 0118 virtual void slotProviderForgotten( const QString &providerId ); 0119 }; 0120 0121 } // namespace StatSyncing 0122 0123 #endif // STATSYNCING_IMPORTER_MANAGER_H