1 /**************************************************************************************** 2 * Copyright (c) 2004-2013 Mark Kretschmann <kretschmann@kde.org> * 3 * * 4 * This program is free software; you can redistribute it and/or modify it under * 5 * the terms of the GNU General Public License as published by the Free Software * 6 * Foundation; either version 2 of the License, or (at your option) any later * 7 * version. * 8 * * 9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 12 * * 13 * You should have received a copy of the GNU General Public License along with * 14 * this program. If not, see <http://www.gnu.org/licenses/>. * 15 ****************************************************************************************/ 16 17 #ifndef AMAROK_PLUGINMANAGER_H 18 #define AMAROK_PLUGINMANAGER_H 19 20 #include "amarok_export.h" 21 22 #include <KPluginInfo> 23 #include <KPluginMetaData> 24 25 #include <QVector> 26 27 namespace Plugins { 28 29 class PluginFactory; 30 31 class AMAROK_EXPORT PluginManager : public QObject 32 { 33 Q_OBJECT 34 Q_PROPERTY( int pluginFrameworkVersion READ pluginFrameworkVersion ) 35 36 public: 37 /** Type of the plugin. 38 * 39 * Will be determined by the KPluginInfo::category 40 */ 41 enum Type 42 { 43 Collection = 1, ///< the plugin implements a CollectionFactory 44 Service = 2, ///< this is a service plugin 45 Importer = 3, ///< this plugin implements importer functionality 46 Storage = 4, ///< the plugin implements a StorageFactory 47 }; 48 Q_ENUM( Type ) 49 50 ~PluginManager() override; 51 52 static PluginManager *instance(); 53 54 /** Destroys the instance of the PluginManager. 55 * 56 * The order of the destruction is somewhat important. 57 * The PluginManager needs to be destroyed after all collections 58 * have been removed and before the CollectionManager, 59 * the ServicePluginManager and the StatSyncing::Controller are destroyed. 60 */ 61 static void destroy(); 62 static int pluginFrameworkVersion(); 63 64 /** 65 * Load any services that are configured to be loaded 66 */ 67 void init(); 68 69 /** Returns enabled plugin factories for the given plugin type. 70 * 71 * This function will only return factories for enabled plugins. 72 */ 73 QList<QSharedPointer<PluginFactory> > factories( Type type ) const; 74 75 KPluginInfo::List plugins( Type type ) const; 76 77 QVector<KPluginMetaData> enabledPlugins(Type type ) const; 78 79 /** Check if any services were disabled and needs to be removed, or any 80 * that are hidden needs to be enabled 81 * 82 * This function will call the sub plugin managers (like CollectionManager) 83 * setFactories function. 84 */ 85 void checkPluginEnabledStates(); 86 87 private: 88 /** Tries finding Amarok plugins */ 89 QVector<KPluginMetaData> findPlugins(); 90 91 /** Returns true if the plugin is enabled. 92 * This function will check the default enabled state, 93 * the Amarok configuration state and the primary collection. 94 * 95 * @returns true if the plugin is enabled. 96 */ 97 bool isPluginEnabled( const KPluginMetaData &plugin ) const; 98 99 /** Creates a factories for a plugin */ 100 QSharedPointer<PluginFactory> createFactory( const KPluginMetaData &pluginInfo ); 101 102 /// contains the names of all KPluginInfos that have factories created 103 QVector<KPluginMetaData> m_plugins; 104 QHash<Type, QList<KPluginMetaData> > m_pluginsByType; 105 QHash<Type, QList<QSharedPointer<PluginFactory> > > m_factoriesByType; 106 QHash<QString, QSharedPointer<PluginFactory>> m_factoryCreated; 107 108 static const int s_pluginFrameworkVersion; 109 static PluginManager *s_instance; 110 111 explicit PluginManager( QObject *parent = nullptr ); 112 }; 113 114 } // namespace Plugins 115 116 namespace The 117 { pluginManager()118 inline Plugins::PluginManager *pluginManager() { return Plugins::PluginManager::instance(); } 119 } 120 121 #endif /* AMAROK_PLUGINMANAGER_H */ 122