Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/shell/plugincontroller.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
55 | 55 | | |||
56 | inline QString KEY_LoadMode() { return QStringLiteral("X-KDevelop-LoadMode"); } | 56 | inline QString KEY_LoadMode() { return QStringLiteral("X-KDevelop-LoadMode"); } | ||
57 | inline QString KEY_Category() { return QStringLiteral("X-KDevelop-Category"); } | 57 | inline QString KEY_Category() { return QStringLiteral("X-KDevelop-Category"); } | ||
58 | inline QString KEY_Mode() { return QStringLiteral("X-KDevelop-Mode"); } | 58 | inline QString KEY_Mode() { return QStringLiteral("X-KDevelop-Mode"); } | ||
59 | inline QString KEY_Version() { return QStringLiteral("X-KDevelop-Version"); } | 59 | inline QString KEY_Version() { return QStringLiteral("X-KDevelop-Version"); } | ||
60 | inline QString KEY_Interfaces() { return QStringLiteral("X-KDevelop-Interfaces"); } | 60 | inline QString KEY_Interfaces() { return QStringLiteral("X-KDevelop-Interfaces"); } | ||
61 | inline QString KEY_Required() { return QStringLiteral("X-KDevelop-IRequired"); } | 61 | inline QString KEY_Required() { return QStringLiteral("X-KDevelop-IRequired"); } | ||
62 | inline QString KEY_Optional() { return QStringLiteral("X-KDevelop-IOptional"); } | 62 | inline QString KEY_Optional() { return QStringLiteral("X-KDevelop-IOptional"); } | ||
63 | inline QString KEY_KPlugin() { return QStringLiteral("KPlugin"); } | ||||
64 | inline QString KEY_EnabledByDefault() { return QStringLiteral("EnabledByDefault"); } | ||||
63 | 65 | | |||
64 | inline QString KEY_Global() { return QStringLiteral("Global"); } | 66 | inline QString KEY_Global() { return QStringLiteral("Global"); } | ||
65 | inline QString KEY_Project() { return QStringLiteral("Project"); } | 67 | inline QString KEY_Project() { return QStringLiteral("Project"); } | ||
66 | inline QString KEY_Gui() { return QStringLiteral("GUI"); } | 68 | inline QString KEY_Gui() { return QStringLiteral("GUI"); } | ||
67 | inline QString KEY_AlwaysOn() { return QStringLiteral("AlwaysOn"); } | 69 | inline QString KEY_AlwaysOn() { return QStringLiteral("AlwaysOn"); } | ||
68 | inline QString KEY_UserSelectable() { return QStringLiteral("UserSelectable"); } | 70 | inline QString KEY_UserSelectable() { return QStringLiteral("UserSelectable"); } | ||
69 | 71 | | |||
70 | bool isUserSelectable( const KPluginMetaData& info ) | 72 | bool isUserSelectable( const KPluginMetaData& info ) | ||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Line(s) | 214 | { | |||
223 | } | 225 | } | ||
224 | } | 226 | } | ||
225 | 227 | | |||
226 | /** | 228 | /** | ||
227 | * Decide whether a plugin is enabled | 229 | * Decide whether a plugin is enabled | ||
228 | */ | 230 | */ | ||
229 | bool isEnabled(const KPluginMetaData& info) const | 231 | bool isEnabled(const KPluginMetaData& info) const | ||
230 | { | 232 | { | ||
233 | // first check black listing from environment | ||||
231 | static const QStringList disabledPlugins = QString::fromLatin1(qgetenv("KDEV_DISABLE_PLUGINS")).split(';'); | 234 | static const QStringList disabledPlugins = QString::fromLatin1(qgetenv("KDEV_DISABLE_PLUGINS")).split(';'); | ||
232 | if (disabledPlugins.contains(info.pluginId())) { | 235 | if (disabledPlugins.contains(info.pluginId())) { | ||
233 | return false; | 236 | return false; | ||
234 | } | 237 | } | ||
235 | 238 | | |||
236 | if (!isUserSelectable( info )) | 239 | if (!isUserSelectable( info )) | ||
237 | return true; | 240 | return true; | ||
238 | 241 | | |||
239 | // in case there's a user preference, prefer that | 242 | // read stored user preference | ||
240 | const KConfigGroup grp = Core::self()->activeSession()->config()->group( KEY_Plugins() ); | 243 | const KConfigGroup grp = Core::self()->activeSession()->config()->group( KEY_Plugins() ); | ||
241 | const QString pluginEnabledKey = info.pluginId() + KEY_Suffix_Enabled(); | 244 | const QString pluginEnabledKey = info.pluginId() + KEY_Suffix_Enabled(); | ||
242 | if (grp.hasKey(pluginEnabledKey)) { | 245 | if (grp.hasKey(pluginEnabledKey)) { | ||
243 | return grp.readEntry(pluginEnabledKey, true); | 246 | return grp.readEntry(pluginEnabledKey, true); | ||
244 | } | 247 | } | ||
245 | 248 | | |||
246 | // in all other cases: figure out if we want to load that plugin by default | | |||
247 | const auto defaultPlugins = ShellExtension::getInstance()->defaultPlugins(); | | |||
248 | const bool isDefaultPlugin = defaultPlugins.isEmpty() || defaultPlugins.contains(info.pluginId()); | | |||
249 | if (isDefaultPlugin) { | | |||
250 | return true; | | |||
251 | } | | |||
252 | | ||||
253 | if (!isGlobalPlugin( info )) { | | |||
254 | QJsonValue enabledByDefault = info.rawData()[QStringLiteral("KPlugin")].toObject()[QStringLiteral("EnabledByDefault")]; | | |||
255 | return enabledByDefault.isNull() || enabledByDefault.toBool(); //We consider plugins enabled until specified otherwise | | |||
256 | } | | |||
257 | | ||||
258 | return false; | 249 | return false; | ||
259 | } | 250 | } | ||
260 | 251 | | |||
261 | Core *core; | 252 | Core *core; | ||
262 | }; | 253 | }; | ||
263 | 254 | | |||
264 | PluginController::PluginController(Core *core) | 255 | PluginController::PluginController(Core *core) | ||
265 | : IPluginController(), d(new PluginControllerPrivate) | 256 | : IPluginController(), d(new PluginControllerPrivate) | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 316 | { | |||
341 | d->cleanupMode = PluginControllerPrivate::CleanupDone; | 332 | d->cleanupMode = PluginControllerPrivate::CleanupDone; | ||
342 | } | 333 | } | ||
343 | 334 | | |||
344 | IPlugin* PluginController::loadPlugin( const QString& pluginName ) | 335 | IPlugin* PluginController::loadPlugin( const QString& pluginName ) | ||
345 | { | 336 | { | ||
346 | return loadPluginInternal( pluginName ); | 337 | return loadPluginInternal( pluginName ); | ||
347 | } | 338 | } | ||
348 | 339 | | |||
349 | bool PluginController::isEnabled( const KPluginMetaData& info ) const | | |||
350 | { | | |||
351 | return d->isEnabled(info); | | |||
352 | } | | |||
353 | | ||||
354 | void PluginController::initialize() | 340 | void PluginController::initialize() | ||
355 | { | 341 | { | ||
356 | QElapsedTimer timer; | 342 | QElapsedTimer timer; | ||
357 | timer.start(); | 343 | timer.start(); | ||
358 | 344 | | |||
359 | QMap<QString, bool> pluginMap; | 345 | QMap<QString, bool> pluginMap; | ||
360 | if( ShellExtension::getInstance()->defaultPlugins().isEmpty() ) | 346 | if( ShellExtension::getInstance()->defaultPlugins().isEmpty() ) | ||
361 | { | 347 | { | ||
362 | foreach( const KPluginMetaData& pi, d->plugins ) | 348 | foreach( const KPluginMetaData& pi, d->plugins ) | ||
363 | { | 349 | { | ||
364 | pluginMap.insert( pi.pluginId(), true ); | 350 | QJsonValue enabledByDefaultValue = pi.rawData()[KEY_KPlugin()].toObject()[KEY_EnabledByDefault()]; | ||
351 | // plugins enabled until explicitly specified otherwise | ||||
352 | const bool enabledByDefault = (enabledByDefaultValue.isNull() || enabledByDefaultValue.toBool()); | ||||
353 | pluginMap.insert(pi.pluginId(), enabledByDefault); | ||||
365 | } | 354 | } | ||
366 | } else | 355 | } else | ||
367 | { | 356 | { | ||
368 | // Get the default from the ShellExtension | 357 | // Get the default from the ShellExtension | ||
369 | foreach( const QString& s, ShellExtension::getInstance()->defaultPlugins() ) | 358 | foreach( const QString& s, ShellExtension::getInstance()->defaultPlugins() ) | ||
370 | { | 359 | { | ||
371 | pluginMap.insert( s, true ); | 360 | pluginMap.insert( s, true ); | ||
372 | } | 361 | } | ||
Show All 9 Lines | 369 | { | |||
382 | if (key.endsWith(KEY_Suffix_Enabled())) { | 371 | if (key.endsWith(KEY_Suffix_Enabled())) { | ||
383 | const QString pluginid = key.left(key.length() - 7); | 372 | const QString pluginid = key.left(key.length() - 7); | ||
384 | const bool defValue = pluginMap.value( pluginid, false ); | 373 | const bool defValue = pluginMap.value( pluginid, false ); | ||
385 | const bool enabled = grp.readEntry(key, defValue); | 374 | const bool enabled = grp.readEntry(key, defValue); | ||
386 | pluginMap.insert( pluginid, enabled ); | 375 | pluginMap.insert( pluginid, enabled ); | ||
387 | } | 376 | } | ||
388 | } | 377 | } | ||
389 | 378 | | |||
390 | foreach( const KPluginMetaData& pi, d->plugins ) | 379 | // store current known set of enabled plugins | ||
391 | { | 380 | foreach (const KPluginMetaData& pi, d->plugins) { | ||
392 | if( isGlobalPlugin( pi ) ) | 381 | if (isUserSelectable(pi)) { | ||
393 | { | 382 | auto it = pluginMap.constFind(pi.pluginId()); | ||
394 | QMap<QString, bool>::const_iterator it = pluginMap.constFind( pi.pluginId() ); | 383 | if (it != pluginMap.constEnd() && (it.value())) { | ||
395 | if( it != pluginMap.constEnd() && ( it.value() || !isUserSelectable( pi ) ) ) | | |||
396 | { | | |||
397 | // Plugin is mentioned in pluginmap and the value is true, so try to load it | | |||
398 | loadPluginInternal( pi.pluginId() ); | | |||
399 | if(!grp.hasKey(pi.pluginId() + KEY_Suffix_Enabled())) { | | |||
400 | if( isUserSelectable( pi ) ) | | |||
401 | { | | |||
402 | // If plugin isn't listed yet, add it with true now | | |||
403 | grp.writeEntry(pi.pluginId() + KEY_Suffix_Enabled(), true); | 384 | grp.writeEntry(pi.pluginId() + KEY_Suffix_Enabled(), true); | ||
404 | } | 385 | } | ||
405 | } else if( grp.hasKey( pi.pluginId() + "Disabled" ) && !isUserSelectable( pi ) ) | 386 | } else { | ||
406 | { | 387 | // Backward compat: Remove any now-obsolete entries | ||
407 | // Remove now-obsolete entries | 388 | grp.deleteEntry(pi.pluginId() + QLatin1String("Disabled")); | ||
408 | grp.deleteEntry( pi.pluginId() + "Disabled" ); | | |||
409 | } | | |||
410 | } | | |||
411 | } | 389 | } | ||
412 | } | 390 | } | ||
413 | // Synchronize so we're writing out to the file. | 391 | // Synchronize so we're writing out to the file. | ||
414 | grp.sync(); | 392 | grp.sync(); | ||
415 | 393 | | |||
394 | // load global plugins | ||||
395 | foreach (const KPluginMetaData& pi, d->plugins) { | ||||
396 | if (isGlobalPlugin(pi)) { | ||||
397 | loadPluginInternal(pi.pluginId()); | ||||
398 | } | ||||
399 | } | ||||
400 | | ||||
416 | qCDebug(SHELL) << "Done loading plugins - took:" << timer.elapsed() << "ms"; | 401 | qCDebug(SHELL) << "Done loading plugins - took:" << timer.elapsed() << "ms"; | ||
417 | } | 402 | } | ||
418 | 403 | | |||
419 | QList<IPlugin *> PluginController::loadedPlugins() const | 404 | QList<IPlugin *> PluginController::loadedPlugins() const | ||
420 | { | 405 | { | ||
421 | return d->loadedPlugins.values(); | 406 | return d->loadedPlugins.values(); | ||
422 | } | 407 | } | ||
423 | 408 | | |||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 469 | if ( !info.isValid() ) { | |||
485 | qCWarning(SHELL) << "Unable to find a plugin named '" << pluginId << "'!" ; | 470 | qCWarning(SHELL) << "Unable to find a plugin named '" << pluginId << "'!" ; | ||
486 | return nullptr; | 471 | return nullptr; | ||
487 | } | 472 | } | ||
488 | 473 | | |||
489 | if ( IPlugin* plugin = d->loadedPlugins.value( info ) ) { | 474 | if ( IPlugin* plugin = d->loadedPlugins.value( info ) ) { | ||
490 | return plugin; | 475 | return plugin; | ||
491 | } | 476 | } | ||
492 | 477 | | |||
493 | if ( !isEnabled( info ) ) { | 478 | if (!d->isEnabled(info)) { | ||
494 | // Do not load disabled plugins | 479 | // Do not load disabled plugins | ||
495 | qCWarning(SHELL) << "Not loading plugin named" << pluginId << "because it has been disabled!"; | 480 | qCWarning(SHELL) << "Not loading plugin named" << pluginId << "because it has been disabled!"; | ||
496 | return nullptr; | 481 | return nullptr; | ||
497 | } | 482 | } | ||
498 | 483 | | |||
499 | if ( !hasMandatoryProperties( info ) ) { | 484 | if ( !hasMandatoryProperties( info ) ) { | ||
500 | qCWarning(SHELL) << "Unable to load plugin named" << pluginId << "because not all mandatory properties are set."; | 485 | qCWarning(SHELL) << "Unable to load plugin named" << pluginId << "because not all mandatory properties are set."; | ||
501 | return nullptr; | 486 | return nullptr; | ||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Line(s) | 737 | { | |||
755 | { | 740 | { | ||
756 | grp.writeEntry( info.pluginId() + KEY_Suffix_Enabled(), false ); | 741 | grp.writeEntry( info.pluginId() + KEY_Suffix_Enabled(), false ); | ||
757 | } | 742 | } | ||
758 | } else if( !loaded && enabled ) | 743 | } else if( !loaded && enabled ) | ||
759 | { | 744 | { | ||
760 | loadPluginInternal( info.pluginId() ); | 745 | loadPluginInternal( info.pluginId() ); | ||
761 | } | 746 | } | ||
762 | } | 747 | } | ||
748 | // TODO: what about project plugins? what about dependency plugins? | ||||
mwolff: yes, what about them? Sorry, but it's been a long time since I worked on this code. Can you… | |||||
763 | } | 749 | } | ||
764 | } | 750 | } | ||
765 | 751 | | |||
766 | void PluginController::resetToDefaults() | 752 | void PluginController::resetToDefaults() | ||
767 | { | 753 | { | ||
768 | KSharedConfigPtr cfg = Core::self()->activeSession()->config(); | 754 | KSharedConfigPtr cfg = Core::self()->activeSession()->config(); | ||
769 | cfg->deleteGroup( KEY_Plugins() ); | 755 | cfg->deleteGroup( KEY_Plugins() ); | ||
770 | cfg->sync(); | 756 | cfg->sync(); | ||
771 | KConfigGroup grp = cfg->group( KEY_Plugins() ); | 757 | KConfigGroup grp = cfg->group( KEY_Plugins() ); | ||
772 | QStringList plugins = ShellExtension::getInstance()->defaultPlugins(); | 758 | QStringList plugins = ShellExtension::getInstance()->defaultPlugins(); | ||
773 | if( plugins.isEmpty() ) | 759 | if( plugins.isEmpty() ) | ||
774 | { | 760 | { | ||
775 | foreach( const KPluginMetaData& info, d->plugins ) | 761 | foreach( const KPluginMetaData& info, d->plugins ) | ||
776 | { | 762 | { | ||
763 | if (!isUserSelectable(info)) { | ||||
764 | continue; | ||||
765 | } | ||||
766 | | ||||
767 | QJsonValue enabledByDefault = info.rawData()[KEY_KPlugin()].toObject()[KEY_EnabledByDefault()]; | ||||
768 | // plugins enabled until explicitly specified otherwise | ||||
769 | if (enabledByDefault.isNull() || enabledByDefault.toBool()) { | ||||
777 | plugins << info.pluginId(); | 770 | plugins << info.pluginId(); | ||
778 | } | 771 | } | ||
779 | } | 772 | } | ||
773 | } | ||||
780 | foreach( const QString& s, plugins ) | 774 | foreach( const QString& s, plugins ) | ||
781 | { | 775 | { | ||
782 | grp.writeEntry(s + KEY_Suffix_Enabled(), true); | 776 | grp.writeEntry(s + KEY_Suffix_Enabled(), true); | ||
783 | } | 777 | } | ||
784 | grp.sync(); | 778 | grp.sync(); | ||
785 | } | 779 | } | ||
786 | 780 | | |||
787 | } | 781 | } | ||
788 | 782 | |
yes, what about them? Sorry, but it's been a long time since I worked on this code. Can you elaborate the problems you are seeing?