void PluginLoaderThread::run()
{
    if (m_queue.empty() || m_targetThread == 0) {
        qCritical() << "Invalid plugin loading parameters";
        return;
    }

    while (!m_queue.isEmpty()) {
        QPluginLoader * loader = new QPluginLoader ();
        loader->setFileName (m_queue.takeFirst());
        loader->setLoadHints (QLibrary::ExportExternalSymbolsHint);

        if (loader->load()) {
            QMutexLocker locker(&m_mutex);
            if (!m_abort) {
                loader->moveToThread(m_targetThread);
                //loader->setParent(parent());
            }
            else {
                qDebug() << "Plugin loading aborted, exiting loader thread";
                delete loader;
                loader = 0;
                break;
            }
        }
        else {
            qCritical() << "Failed to load plugin:" << loader->errorString();
            delete loader;
            loader = 0;
        }

        Q_EMIT(pluginLoaded(loader, m_queue.isEmpty()));
    }
}
void tst_QPluginLoader::loadHints()
{
    QPluginLoader loader;
    QCOMPARE(loader.loadHints(), (QLibrary::LoadHints)0);   //Do not crash
    loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
    loader.setFileName( sys_qualifiedLibraryName("theplugin"));     //a plugin
    QCOMPARE(loader.loadHints(), QLibrary::ResolveAllSymbolsHint);
}
 // looking for dynamic plugins
 foreach(const QFileInfo & fileName, files)
 {
     emit log((int)LogDebug, MODULENAME, QString("Loading plugin: %1").arg(fileName.fileName()), "");
     QPluginLoader loader;
     loader.setLoadHints(QLibrary::ResolveAllSymbolsHint|QLibrary::ExportExternalSymbolsHint);
     loader.setFileName( fileName.absoluteFilePath());
     if (!loader.load())
     {
         qCritical() << loader.errorString();
         continue;
     }
     QObject *plugin = loader.instance();
     if (plugin && qobject_cast<PropertyInterface*>(plugin))
         m_plugins.push_back(qobject_cast<PropertyInterface*>(plugin));
     else
         emit log((int)LogWarning, MODULENAME, QString("It\'s not a PropertyEditor plugin: %1").arg(fileName.fileName()), "");
 }
示例#4
0
void PluginManager::loadAllPlugins(EnvisionManager& envisionManager)
{
	int lastCountLoaded = -1;

	// Holds the ids of plugins which are not yet loaded.
	QStringList plugins;
	for (auto p_meta : pluginMetaData)
		plugins.append(p_meta.id);

	QTextStream out(stdout);

	while ( lastCountLoaded != loadedPlugins.length() && loadedPlugins.length() < pluginMetaData.length() )
	{
		lastCountLoaded = loadedPlugins.length();

		for (int i = plugins.length() - 1; i >= 0; i--)
		{
			QList<PluginDependency> depList = idToMetaDataMap.value(plugins.at(i))->dependencies;

			bool allDependenciesLoaded = true;
			for (QList<PluginDependency>::iterator dep = depList.begin(); dep != depList.end(); dep++)
			{
				// Check if this dependency is already loaded
				if ( idToPluginLoaderMap.contains(dep->id) == false )
				{
					allDependenciesLoaded = false;
					break;
				}

				// Check if the version of the non-dependent plugin matches the version the current plugin depends on
				if ( !idToMetaDataMap.value(dep->id)->version.startsWith(dep->majorVersion + ".", Qt::CaseSensitive) )
					throw EnvisionException("Plugin " + plugins.at(i) + " depends on version " + dep->majorVersion
							+ " of " + dep->id + " but a different version is installed.");
			}

			if ( allDependenciesLoaded )
			{
				out << "Loading plug-in " << plugins.at(i) << "... " << endl;

				QPluginLoader* plugin = new QPluginLoader(pluginsDir.absoluteFilePath(getLibraryFileName(plugins.at(i))));
				plugin->setLoadHints(QLibrary::ExportExternalSymbolsHint);

				plugin->load();

				if ( plugin->isLoaded() == false )
					throw EnvisionException("Could not load plugin: " + plugin->errorString());

				EnvisionPlugin* p = qobject_cast<EnvisionPlugin*> (plugin->instance());
				p->initialize(envisionManager);

				out << plugins.at(i) << " loaded OK" << endl;

				loadedPlugins.append(plugin);
				idToPluginLoaderMap.insert(plugins.at(i), plugin);
				plugins.removeAt(i);
			}
		}
	}

	// Check if there are any plug-ins with unmet dependencies
	if (plugins.size() > 0)
	{
		out<< "Warning: The following plug-ins have not been loaded because their dependencies are not satisfied" << endl;
		for (int i = 0; i< plugins.size(); ++i) out << "  " << plugins.at(i) << endl;
	}
	else out << "All plug-ins loaded." << endl;
}
示例#5
0
 bool loadBinary() {
   loader->setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);
   return loader->load();
 }
/*!
 * This function will do the basic loading/unloading tests on the applet.
 */
void
Ft_AppletLoader::DoAppletTest (const char *soname, bool hasBrief)
{
    QPluginLoader loader;

    loader.setFileName (QString (APPLET_PATH) + QString (soname));
    loader.setLoadHints (QLibrary::ResolveAllSymbolsHint);

    /*
     * Getting the DcpAppletIf applet interface object. Checking if the applet
     * loaded, the type of the applet interface is right.
     */
    QVERIFY2 (loader.load (), qPrintable (loader.errorString ()));

    DcpAppletIf *applet = qobject_cast<DcpAppletIf *>(loader.instance ());

    QVERIFY (applet != 0);

    /*
     * Do initialization... in the same way how controlpanel doing:
     */
    applet->init ();

#ifndef TEST_NEW_TITLE_METHODS
    QVERIFY (! applet->title ().isEmpty ());
#endif

    /*
     * Checking if the applet brief is constructed.
     */
    DcpBrief *brief = applet->constructBrief ();
    if (hasBrief)
    {
        QVERIFY2(brief, 
		    "Error when creating brief widget");
#ifdef TEST_NEW_TITLE_METHODS
        /*
         * Checking if the applet has a non-empty title string.
         */
        QVERIFY (! brief->titleText ().isEmpty ());
#endif
    }
    else
        QVERIFY2(!brief, 
		    "This applet should not have a Brief");

    /*
     * Checking if the the main view (the applet widget) is constructed. FIXME:
     * We should call the getMainWidgetId here, but I'm not sure how it is done
     * after the refactoring.
     */
    DcpWidget *widget = applet->constructWidget (0);
    QVERIFY2 (widget, "Error when creating applet's main widget");

#ifdef TEST_NEW_TITLE_METHODS
    /*
     * Check if the applet widget has a non-empty title string.
     */
    QVERIFY (! widget->title ().isEmpty ());
#endif

    QTest::qWait (1000);

//    loader.unload ();
//    delete widget;
//    delete brief;
}
void TransferEnginePrivate::enabledPluginsCheck()
{
    Q_Q(TransferEngine);
    if (m_fileWatcherTimer->isActive()) {
        m_fileWatcherTimer->stop();
    }

    if (m_infoObjects.count() > 0) {
        qWarning() << Q_FUNC_INFO << "Already quering account info" << m_infoObjects.count();
        return;
    }

    // First clear old data
    m_enabledPlugins.clear();
    qDeleteAll(m_infoObjects);
    m_infoObjects.clear();

    QPluginLoader loader;
    loader.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);

    // Handle the case if all the plugins have been removed.
    QStringList plugins = pluginList();
    if (plugins.isEmpty()) {
        emit q->transferMethodListChanged();
        return;
    }

    // We have plugins
    Q_FOREACH(QString plugin, plugins) {
        loader.setFileName(plugin);
        TransferPluginInterface *interface =
                qobject_cast<TransferPluginInterface*>(loader.instance());

        if (interface && interface->enabled()) {

            TransferPluginInfo *info = interface->infoObject();
            if (!info) {
                qWarning() << Q_FUNC_INFO << "NULL Info object!";
                continue;
            }

            if (info->ready()) {
                if (info->info().count() > 0) {
                    m_enabledPlugins << info->info();
                } else {
                    // Plugin has nothing to provide, just ignore it
                    delete info;
                }
            } else {
                // These object will be cleaned in pluginInfoReady() slot.
                m_infoObjects << info;
                connect(info, SIGNAL(infoReady()), this, SLOT(pluginInfoReady()));
                connect(info, SIGNAL(infoError(QString)), this, SLOT(pluginInfoError(QString)));
                info->query();
            }
        }

        if (!interface) {
            qWarning() << Q_FUNC_INFO << loader.errorString();
        }
    }