Exemplo n.º 1
0
void PluginManager::loadAllPlugins()
{
    kDebug();
    KSharedConfig::Ptr config = KGlobal::config();
    if ( config->hasGroup( QLatin1String( "Plugins" ) ) )
    {
        QMap<QString, bool> pluginsMap;

        QMap<QString, QString> entries = config->entryMap( QLatin1String( "Plugins" ) );
        QMap<QString, QString>::Iterator it;
        for ( it = entries.begin(); it != entries.end(); ++it )
        {
            QString key = it.key();
            if ( key.endsWith( QLatin1String( "Enabled" ) ) )
                pluginsMap.insert( key.left(key.length() - 7), (it.value() == QLatin1String( "true" )) );
        }

        QList<KPluginInfo> plugins = availablePlugins( QString::null );    //krazy:exclude=nullstrassign for old broken gcc
        QList<KPluginInfo>::ConstIterator it2 = plugins.constBegin();
        QList<KPluginInfo>::ConstIterator end = plugins.constEnd();
        for ( ; it2 != end; ++it2 )
        {
            if ( it2->category() == QLatin1String( "MicroBlogs" ) ||
                 it2->category() == QLatin1String( "Shorteners" ) )
                continue;

            QString pluginName = it2->pluginName();
            if ( pluginsMap.value( pluginName, it2->isPluginEnabledByDefault() ) )
            {
                if ( !plugin( pluginName ) )
                    _kpmp->pluginsToLoad.push( pluginName );
            }
            else
            {
                //This happens if the user unloaded plugins with the config plugin page.
                // No real need to be assync because the user usually unload few plugins
                // compared tto the number of plugin to load in a cold start. - Olivier
                if ( plugin( pluginName ) )
                    unloadPlugin( pluginName );
            }
        }
    }
    else
    {
        // we had no config, so we load any plugins that should be loaded by default.
        QList<KPluginInfo> plugins = availablePlugins( QString::null );    //krazy:exclude=nullstrassign for old broken gcc
        QList<KPluginInfo>::ConstIterator it = plugins.constBegin();
        QList<KPluginInfo>::ConstIterator end = plugins.constEnd();
        for ( ; it != end; ++it )
        {
            if ( it->category() == QLatin1String( "MicroBlogs" ) ||
                it->category() == QLatin1String( "Shorteners" ) )
                continue;
            if ( it->isPluginEnabledByDefault() )
                _kpmp->pluginsToLoad.push( it->pluginName() );
        }
    }
    // Schedule the plugins to load
    QTimer::singleShot( 0, this, SLOT( slotLoadNextPlugin() ) );
}
void PluginManager::slotLoadNextPlugin()
{
	if ( _kpmp->pluginsToLoad.isEmpty() )
	{
		if ( _kpmp->shutdownMode == PluginManagerPrivate::StartingUp )
		{
			_kpmp->shutdownMode = PluginManagerPrivate::Running;
			_kpmp->isAllPluginsLoaded = true;
			emit allPluginsLoaded();
		}
		return;
	}

	QString key = _kpmp->pluginsToLoad.pop();
	loadPluginInternal( key );

	// Schedule the next run unconditionally to avoid code duplication on the
	// allPluginsLoaded() signal's handling. This has the added benefit that
	// the signal is delayed one event loop, so the accounts are more likely
	// to be instantiated.
	QTimer::singleShot( 0, this, SLOT(slotLoadNextPlugin()) );
}
Exemplo n.º 3
0
Plugin * PluginManager::loadPlugin( const QString &_pluginId, PluginLoadMode mode /* = LoadSync */ )
{
    QString pluginId = _pluginId;

    // Try to find legacy code
    // FIXME: Find any cases causing this, remove them, and remove this too - Richard
    if ( pluginId.endsWith( QLatin1String( ".desktop" ) ) )
    {
        kWarning() << "Trying to use old-style API!" << endl << kBacktrace();
        pluginId = pluginId.remove( QRegExp( QLatin1String( ".desktop$" ) ) );
    }

    if ( mode == LoadSync )
    {
        return loadPluginInternal( pluginId );
    }
    else
    {
        _kpmp->pluginsToLoad.push( pluginId );
        QTimer::singleShot( 0, this, SLOT( slotLoadNextPlugin() ) );
        return 0L;
    }
}