File indexing completed on 2024-05-05 04:48:33

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_PROVIDER_H
0018 #define STATSYNCING_IMPORTER_PROVIDER_H
0019 
0020 #include "statsyncing/Provider.h"
0021 
0022 #include "amarok_export.h"
0023 
0024 namespace StatSyncing
0025 {
0026 
0027 class ImporterManager;
0028 
0029 /**
0030  * The ImporterProvider class is a base class for every @see StatSyncing::Provider
0031  * derived statistic importer. It serves to reduce boilerplate by offering a common
0032  * implementation of some StatSyncing::Provider methods.
0033  *
0034  * For details about methods' purpose, and other methods that need to be implemented
0035  * in a concrete ImporterProvider, see StatSyncing::Provider documentation.
0036  */
0037 class AMAROK_EXPORT ImporterProvider : public Provider
0038 {
0039     Q_OBJECT
0040 
0041     /// Give ImporterManager access to config field in order to save and restore state.
0042     friend class ImporterManager;
0043 
0044 public:
0045     /**
0046      * The constructor stores @param config as a protected @see m_config variable, and
0047      * @param manager as @see m_manager. If config["uid"] isn't set, it's generated here.
0048      */
0049     ImporterProvider( const QVariantMap &config, ImporterManager *manager );
0050     ~ImporterProvider() override;
0051 
0052     /**
0053      * Provider's unique id which may be used as a key for configuration storage.
0054      * Returns m_config["uid"] by default.
0055      */
0056     QString id() const override;
0057 
0058     /**
0059      * Description of the provider. Returns m_importer->description() by default.
0060      */
0061     QString description() const override;
0062 
0063     /**
0064      * Provider's icon. Returns m_importer->icon() by default.
0065      */
0066     QIcon icon() const override;
0067 
0068     /**
0069      * Provider's name as displayed in Amarok's Metadata Configuration tab. Returns
0070      * m_config["name"] by default.
0071      */
0072     QString prettyName() const override;
0073 
0074     /**
0075      * Returns true if provider is configurable. Returns true by default.
0076      */
0077     bool isConfigurable() const override;
0078 
0079     /**
0080      * Returns configuration widget used to reconfigure this provider. By default
0081      * delegates to m_importer->getConfigWidget( m_config ).
0082      */
0083     ProviderConfigWidget *configWidget() override;
0084 
0085     /**
0086      * Reconfigures current provider. An ImporterManager subclass handles the
0087      * task, _recreating_ this provider with new configuration. Please note that
0088      * m_config["uid"] is not subject to reconfiguration.
0089      */
0090     void reconfigure( const QVariantMap &config ) override;
0091 
0092     /**
0093      * Determines if this provider should participate in statistics synchronization
0094      * by default. By default returns StatSyncing::Provider::NoByDefault .
0095      */
0096     Preference defaultPreference() override;
0097 
0098 Q_SIGNALS:
0099     void reconfigurationRequested( const QVariantMap &config );
0100 
0101 protected:
0102     /**
0103      * Configuration of this provider. It is saved and restored by an ImporterManager
0104      * subclass.
0105      */
0106     QVariantMap m_config;
0107     ImporterManager *m_manager;
0108 };
0109 
0110 } // namespace StatSyncing
0111 
0112 #endif // STATSYNCING_IMPORTER_PROVIDER_H