Changeset View
Changeset View
Standalone View
Standalone View
src/PluginManager.cpp
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 64 | { | |||
---|---|---|---|---|---|
69 | PERF_LOG( "Initialising Plugin Manager" ) | 69 | PERF_LOG( "Initialising Plugin Manager" ) | ||
70 | init(); | 70 | init(); | ||
71 | PERF_LOG( "Initialised Plugin Manager" ) | 71 | PERF_LOG( "Initialised Plugin Manager" ) | ||
72 | } | 72 | } | ||
73 | 73 | | |||
74 | Plugins::PluginManager::~PluginManager() | 74 | Plugins::PluginManager::~PluginManager() | ||
75 | { | 75 | { | ||
76 | // tell the managers to get rid of their current factories | 76 | // tell the managers to get rid of their current factories | ||
77 | QList<Plugins::PluginFactory*> emptyFactories; | 77 | QList<QSharedPointer<Plugins::PluginFactory> > emptyFactories; | ||
78 | 78 | | |||
79 | StatSyncing::Controller *controller = Amarok::Components::statSyncingController(); | 79 | StatSyncing::Controller *controller = Amarok::Components::statSyncingController(); | ||
80 | if( controller ) | 80 | if( controller ) | ||
81 | controller->setFactories( emptyFactories ); | 81 | controller->setFactories( emptyFactories ); | ||
82 | ServicePluginManager::instance()->setFactories( emptyFactories ); | 82 | ServicePluginManager::instance()->setFactories( emptyFactories ); | ||
83 | CollectionManager::instance()->setFactories( emptyFactories ); | 83 | CollectionManager::instance()->setFactories( emptyFactories ); | ||
84 | StorageManager::instance()->setFactories( emptyFactories ); | 84 | StorageManager::instance()->setFactories( emptyFactories ); | ||
85 | } | 85 | } | ||
Show All 28 Lines | 110 | { | |||
114 | { | 114 | { | ||
115 | if( isPluginEnabled( plugin ) ) | 115 | if( isPluginEnabled( plugin ) ) | ||
116 | enabledList << plugin; | 116 | enabledList << plugin; | ||
117 | } | 117 | } | ||
118 | 118 | | |||
119 | return enabledList; | 119 | return enabledList; | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | QList<Plugins::PluginFactory*> | 122 | QList<QSharedPointer<Plugins::PluginFactory> > | ||
123 | Plugins::PluginManager::factories( Type type ) const | 123 | Plugins::PluginManager::factories( Type type ) const | ||
124 | { | 124 | { | ||
125 | return m_factoriesByType.value( type ); | 125 | return m_factoriesByType.value( type ); | ||
126 | } | 126 | } | ||
127 | 127 | | |||
128 | void | 128 | void | ||
129 | Plugins::PluginManager::checkPluginEnabledStates() | 129 | Plugins::PluginManager::checkPluginEnabledStates() | ||
130 | { | 130 | { | ||
Show All 19 Lines | 141 | { | |||
150 | // don't use QApplication::exit, as the eventloop may not have started yet | 150 | // don't use QApplication::exit, as the eventloop may not have started yet | ||
151 | std::exit( EXIT_SUCCESS ); | 151 | std::exit( EXIT_SUCCESS ); | ||
152 | } | 152 | } | ||
153 | 153 | | |||
154 | // sort the plugin infos by type | 154 | // sort the plugin infos by type | ||
155 | for( const auto &pluginInfo : m_plugins ) | 155 | for( const auto &pluginInfo : m_plugins ) | ||
156 | { | 156 | { | ||
157 | // create the factories and sort them by type | 157 | // create the factories and sort them by type | ||
158 | PluginFactory *factory = createFactory( pluginInfo ); | 158 | auto factory = createFactory( pluginInfo ); | ||
159 | 159 | | |||
160 | if( factory ) | 160 | if( factory ) | ||
161 | { | 161 | { | ||
162 | Type type; | 162 | Type type; | ||
163 | 163 | | |||
164 | if( qobject_cast<StorageFactory*>( factory ) ) | 164 | if( qobject_cast<StorageFactory*>( factory ) ) | ||
165 | type = Storage; | 165 | type = Storage; | ||
166 | else if( qobject_cast<Collections::CollectionFactory*>( factory ) ) | 166 | else if( qobject_cast<Collections::CollectionFactory*>( factory ) ) | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 229 | { | |||
260 | KPluginInfo info = KPluginInfo( plugin ); | 260 | KPluginInfo info = KPluginInfo( plugin ); | ||
261 | info.setConfig( Amarok::config( "Plugins" ) ); | 261 | info.setConfig( Amarok::config( "Plugins" ) ); | ||
262 | info.load(); | 262 | info.load(); | ||
263 | 263 | | |||
264 | return info.isPluginEnabled(); | 264 | return info.isPluginEnabled(); | ||
265 | } | 265 | } | ||
266 | 266 | | |||
267 | 267 | | |||
268 | Plugins::PluginFactory* | 268 | QSharedPointer<Plugins::PluginFactory> | ||
269 | Plugins::PluginManager::createFactory( const KPluginMetaData &pluginInfo ) | 269 | Plugins::PluginManager::createFactory( const KPluginMetaData &pluginInfo ) | ||
270 | { | 270 | { | ||
271 | debug() << "Creating factory for plugin:" << pluginInfo.pluginId(); | 271 | debug() << "Creating factory for plugin:" << pluginInfo.pluginId(); | ||
272 | 272 | | |||
273 | // check if we already created this factory | 273 | // check if we already created this factory | ||
274 | // note: old factories are not deleted. | 274 | // note: old factories are not deleted. | ||
275 | // We can't very well just destroy a factory being | 275 | // We can't very well just destroy a factory being | ||
276 | // currently used. | 276 | // currently used. | ||
277 | const QString name = pluginInfo.pluginId(); | 277 | const QString name = pluginInfo.pluginId(); | ||
278 | 278 | | |||
279 | if( m_factoryCreated.contains( name ) ) | 279 | if( m_factoryCreated.contains( name ) ) | ||
280 | return m_factoryCreated.value( name ); | 280 | return m_factoryCreated.value( name ); | ||
281 | 281 | | |||
282 | QPluginLoader loader( pluginInfo.fileName() ); | 282 | QPluginLoader loader( pluginInfo.fileName() ); | ||
283 | auto pluginFactory = qobject_cast<PluginFactory*>( loader.instance() ); | 283 | auto pointer = qobject_cast<PluginFactory*>( loader.instance() ); | ||
284 | auto pluginFactory = QSharedPointer<Plugins::PluginFactory>( pointer ); | ||||
284 | 285 | | |||
285 | if( !pluginFactory ) | 286 | if( !pluginFactory ) | ||
286 | { | 287 | { | ||
287 | warning() << QString( "Failed to get factory '%1' from QPluginLoader: %2" ) | 288 | warning() << QString( "Failed to get factory '%1' from QPluginLoader: %2" ) | ||
288 | .arg( name, loader.errorString() ); | 289 | .arg( name, loader.errorString() ); | ||
289 | return Q_NULLPTR; | 290 | return QSharedPointer<Plugins::PluginFactory>(); | ||
290 | } | 291 | } | ||
291 | 292 | | |||
292 | m_factoryCreated[ name ] = pluginFactory; | 293 | m_factoryCreated[ name ] = pluginFactory; | ||
293 | return pluginFactory; | 294 | return pluginFactory; | ||
294 | } | 295 | } | ||
295 | 296 | | |||
296 | 297 | | |||
297 | QVector<KPluginMetaData> | 298 | QVector<KPluginMetaData> | ||
Show All 24 Lines |