コード例 #1
0
ファイル: glwidget.cpp プロジェクト: EikaNN/FIB-G
void GLWidget::loadPlugins(const QStringList& list) {
    QStringList::ConstIterator it = list.constBegin();
    while(it != list.constEnd()) 
    {
        QString name = *it;
        QPluginLoader *loader = new QPluginLoader(name);
        if (! loader->load()) {
        	  qDebug() << "Could not load plugin " << name << "\n";
                qDebug() << loader->errorString() << "\n";

	        }
        if (loader->isLoaded()) 
        {
            qDebug() << "Loaded plugin: " << loader->fileName(); // << 	endl;
            QObject *plugin = loader->instance();
            if (plugin) 
            {
                plugins.push_back(loader); 
                BasicPlugin *plugin = qobject_cast<BasicPlugin *>(loader->instance());
                // initialize plugin
                if (plugin)
                {
                    plugin->setWidget(this);
                    plugin->setArgs(mainArgs);
                    plugin->onPluginLoad();
                    if (plugin->drawScene()) // overrides drawScene?
                        drawPlugin = plugin;
                }
            }
        }
        else 
        {
            qDebug() << "Load error: " << name << endl;
	        delete loader;
        }
        
        ++it;
    }

    // make sure all plugins know about the latest plugin that overrides drawScene
    for (unsigned int i=0; i<plugins.size(); ++i)
    {
        BasicPlugin *plugin = qobject_cast<BasicPlugin *>(plugins[i]->instance());
        if (plugin)
            plugin->setDrawPlugin(drawPlugin);
        else
        {
            qDebug() << "Error: the plugin must implement the BasicPlugin interface" << endl <<
            " Example: " << endl << 
            "   Q_INTERFACES(BasicPlugin)" << endl;
        }
    }

    resetCamera();
}
コード例 #2
0
ファイル: IMEManager.cpp プロジェクト: KyleMaas/luna-sysmgr
static QList<VirtualKeyboardFactory *> getVKBFactories()
{
    QList<VirtualKeyboardFactory *> list;
    QString path("/usr/lib/luna");
    qDebug() << "\033[1;33;45m" << Q_FUNC_INFO << "Searching for VKB plugins in" << path << "\033[0m";

    QDir plugindir = QDir(path);
    QStringList files = plugindir.entryList(QDir::Files);
    qDebug() << "\033[1;33;45m" << Q_FUNC_INFO << "Found" << files.count() << "files" << "\033[0m";

    QPluginLoader loader;
    QStringList::const_iterator it = files.constBegin();

    while (it != files.constEnd()) {
        qDebug() << "\033[1;33;40m" << Q_FUNC_INFO << "Checking" << (*it) << "\033[0m";
        loader.setFileName(plugindir.absoluteFilePath(*it));

        VirtualKeyboardFactory *factory =
            qobject_cast<VirtualKeyboardFactory *>(loader.instance());

        if (factory) {
            qDebug() << "\033[1;32;40m" << Q_FUNC_INFO << "Loaded plugin"
                     << (*it) << "successfully" << "\033[0m";
            list.append(factory);
        } else {
            qWarning() << "\033[1;31;40m" << Q_FUNC_INFO << "Failed to load"
                       << (*it) << "\n" << loader.errorString() << "\033[0m";

        }

        ++it;
    }

    return list;
}
コード例 #3
0
/*!
    Creates and returns a screensaver on the given token.
    \param token Identifies the screensaver to be created.
    \return The created state.
 */
Screensaver* ScreensaverFactoryPrivate::createScreensaver(const ScreensaverToken &token)
{
    QStringList pluginPaths;

    // check plugin dirs from root of different drives
    QFileInfoList drives = QDir::drives();
    for(int i=0; i < drives.count(); i++) {
        QFileInfo drive = drives.at(i);
        QString driveLetter = drive.absolutePath();
        QString path = driveLetter + mPluginDirectory;
        if (QDir(path).exists()) {
            pluginPaths << path;
        }
    }

    // check plugin dir relative to current dir
    if (QDir(mPluginDirectory).exists() && 
        !pluginPaths.contains(QDir(mPluginDirectory).absolutePath())) {
        pluginPaths << mPluginDirectory;
    }

    IScreensaverProvider *provider(0);
    QPluginLoader *loader = new QPluginLoader();
    QObject *plugin(0);

    for(int i=0; i < pluginPaths.count(); i++) {
        QString path = pluginPaths.at(i);
        QString fileName = QDir(path).absoluteFilePath(token.mLibrary);

        loader->setFileName(fileName);
        plugin = loader->instance();
        provider = qobject_cast<IScreensaverProvider*>(plugin);
        if (provider) {
            break;
        }
    }

    Screensaver *screensaver(0);

    if (provider) {
        screensaver = provider->createScreensaver(token);
        if (!screensaver) {
            qWarning() << "Screensaver creation failed.";
            qWarning() << token.mLibrary << "cannot provide" << token.mUri;
            loader->unload();
            delete loader;
        } else {
            // unload plugin once screensaver gets deleted
            ScreensaverPluginUnloader *unloader = new ScreensaverPluginUnloader(loader);
            unloader->connect(screensaver, SIGNAL(destroyed()), SLOT(deleteLater()));
        }
    } else {
        qDebug() << "Screensaver creation failed.";
        qWarning() << token.mLibrary << "- provider not found";
        loader->unload();
        delete loader;
    }

    return screensaver;
}
コード例 #4
0
ファイル: pluginmanager.cpp プロジェクト: AlexKlybik/kbe
void PluginManager::loadPlugin(QString const & path)
{
    qDebug() << "Load plugin: " << path;

    Q_ASSERT(mPluginLoaders.find(path) == mPluginLoaders.end());

    QPluginLoader * loader = new QPluginLoader(path, this);

    if (!loader->load())
    {
        qDebug() << loader->errorString();
        qDebug() << QString("Can't load plugin '%1'").arg(path);
    }

    // process instances
    PluginInterface *plugInterface = qobject_cast<PluginInterface*>(loader->instance());
    if (plugInterface != 0)
    {
        mPluginLoaders[path] = loader;
        processLoadPlugin(plugInterface);
    }else
    {
        delete loader;
        qDebug() << QString("There are no plugin interface in '%1'").arg(path);
    }

}
コード例 #5
0
HsWidget* HsWidgetFactoryPrivate::createWidget(const HsWidgetToken &token)
{
   QPluginLoader* loader = new QPluginLoader(token.mLibrary);
   QObject* plugin = loader->instance();
   IHsWidgetProvider* provider = qobject_cast<IHsWidgetProvider*>(plugin);
   HsWidget* widget(0);
   
   if (provider) {
       widget = provider->createWidget(token);
       
       if (!widget) {
          HSDEBUG("Widget creation failed.")
          loader->unload();
          delete loader;
       }
       else {
           HsPluginUnloader* p = new HsPluginUnloader(loader);
           p->connect(widget,SIGNAL(destroyed()),SLOT(deleteLater()));
       }
    }

   else {
        HSDEBUG("Widget creation failed - No provider.")
        loader->unload();
        delete loader;
   }

   
    return widget;
}
コード例 #6
0
ファイル: toolPluginManager.cpp プロジェクト: ASabina/qreal
ToolPluginManager::ToolPluginManager()
	: mCustomizer()
{
	mPluginsDir = QDir(qApp->applicationDirPath());

	while (!mPluginsDir.isRoot() && !mPluginsDir.entryList(QDir::Dirs).contains("plugins")) {
		mPluginsDir.cdUp();
	}

	mPluginsDir.cd("plugins");

	for (QString const &fileName : mPluginsDir.entryList(QDir::Files)) {
		// TODO: Free memory
		QPluginLoader *loader = new QPluginLoader(mPluginsDir.absoluteFilePath(fileName));
		QObject *plugin = loader->instance();

		if (plugin) {
			ToolPluginInterface *toolPlugin = qobject_cast<ToolPluginInterface *>(plugin);
			if (toolPlugin) {
				mPlugins << toolPlugin;
				mLoaders << loader;
			} else {
				// TODO: Does not work on linux. See editorManager.cpp for more details.
				// loader->unload();
				delete loader;
			}
		} else {
			loader->unload();
			delete loader;
		}
	}

	loadDefaultSettings();
	setHotKeyActions();
}
コード例 #7
0
void AbstractPluginLoader::loadPlugins(const QRegExp& fileRx, QVector<QString>* errors)
{
  Q_D(AbstractPluginLoader);
  const QDir pluginsFolder(this->loadingFolder());
  QStringList entries(pluginsFolder.entryList(QDir::Files));
  foreach (const QString& entry, entries) {
    if (fileRx.indexIn(entry) != -1 && ::isLibrary(entry)) {
      // Try to load the plugin
#ifdef DEBUG_ABSTRACT_PLUGIN_LOADER
      qDebug() << "try to load" << entry;
#endif // DEBUG_ABSTRACT_PLUGIN_LOADER
      QPluginLoader* pluginLoader = new QPluginLoader(pluginsFolder.absoluteFilePath(entry));
      QObject* plugin = pluginLoader->instance();
      // Is the plugin compatible ?
      if (this->isPluginCompatible(plugin)) {
        d->m_plugins.append(plugin);
        d->m_pluginLoaders.append(pluginLoader);
        d->m_pluginFilenames.insert(plugin, entry);
      }
      else {
#ifdef DEBUG_ABSTRACT_PLUGIN_LOADER
        qDebug() << "  not added";
#endif // DEBUG_ABSTRACT_PLUGIN_LOADER
        if (errors != NULL)
          //: %1 holds the path to a plugin (DLL)
          //: %2 holds an error description
          errors->append(QObject::tr("Failed to load plugin (maybe wrong interface) %1 : %2")
                         .arg(pluginLoader->fileName())
                         .arg(pluginLoader->errorString()));
        pluginLoader->unload();
        delete pluginLoader;
      } // end if (this->isPluginCompatible(plugin))
    } // end if (fileRx.indexIn(entry) != -1)
  } // end foreach ()
}
コード例 #8
0
AExtensionFactoryPrivate::AExtensionFactoryPrivate()
: QObject( qApp )
{
    QString extensionsDirName;
    AExtensionInterface *iface = 0;
    QObject *plugin = 0;
    QPluginLoader pluginLoader;

#ifdef Q_OS_WIN32
    extensionsDirName = qApp->applicationDirPath()+"/extensions";
#else
    extensionsDirName = "/usr/lib/ananas4/extensions";
#endif

    hash.clear();
    extensionKeys.clear();
    QDir extensionsDirectory( extensionsDirName );
    QStringList extensionFiles = extensionsDirectory.entryList( QDir::Files );
    QString fileName = extensionFiles.first();
    for (int i=0; i<extensionFiles.count(); i++){
      fileName = extensionFiles[i];
      pluginLoader.setFileName( extensionsDirectory.absoluteFilePath( fileName ) );
      plugin = pluginLoader.instance();
      if (plugin) {
            iface = qobject_cast<AExtensionInterface *>(plugin);
            if( iface ) {
                extensionKeys.append( iface->key());
                hash[ iface->key()] = iface;
            }
      }
    }
}
コード例 #9
0
ファイル: PluginConfigWidget.cpp プロジェクト: alex-games/a1
PluginConfigWidget::PluginConfigWidget(QHash<QString, QPluginLoader*> plugins,
        QWidget* parent) : QWidget(parent) {

    _plugins = plugins;
    //qDebug() << "* plugins for PluginConfigWidget:" << _plugins;

    QWidget* window = new QWidget();
    QStandardItemModel* model = new QStandardItemModel(window);
    QStandardItem* parentItem = model->invisibleRootItem();
        
    QStringList labels;
    labels << "Plugin" << "Description";
    model->setHorizontalHeaderLabels(labels);
    
    QPluginLoader* pl;
    foreach(pl, _plugins) {
        MClientPluginInterface* ip = 
                qobject_cast<MClientPluginInterface*>(pl->instance());

        if(!ip) continue;
        QList<QStandardItem*> itemList;
        QStandardItem* first = new QStandardItem(ip->longName());
        first->setData(ip->shortName(), Qt::UserRole);
        itemList.append(first);
        itemList.append(new QStandardItem(ip->description()));
        QStandardItem* item;
        foreach(item, itemList) {
            item->setEditable(false);
        }
コード例 #10
0
ファイル: suipluginmanager.cpp プロジェクト: asvitenkov/sui
void suiPluginManager::loadPlugin(const QString &fileName)
{
    qDebug() << "Load plugin: " << fileName;

    if (mPluginLoaders.find(fileName) != mPluginLoaders.end())
        SuiExcept(SuiExceptionDuplicateItem,
                  QString("Plugin '%1' already loaded").arg(fileName),
                  "void suiPluginManager::loadPlugin(const QString &fileName)");

    QPluginLoader *loader = new QPluginLoader(fileName, this);

    if (!loader->load())
    {
        qDebug() << loader->errorString();
        SuiExcept(SuiExceptionInternalError,
                  QString("Can't load plugin '%1'").arg(fileName),
                  "void suiPluginManager::loadPlugin(const QString &fileName)");
    }

    // process instances
    UiPluginInterface *plugInterface = qobject_cast<UiPluginInterface*>(loader->instance());
    if (plugInterface != 0)
    {
        mPluginLoaders[fileName] = loader;
        processLoadPlugin(plugInterface);
    }else
    {
        delete loader;
        SuiExcept(SuiExceptionInternalError,
                  QString("There are no plugin interface in '%1'").arg(fileName),
                  "void suiPluginManager::loadPlugin(const QString &fileName)");
    }
}
コード例 #11
0
ファイル: PluginManager.cpp プロジェクト: Sciss/i-score
ISCORE_LIB_BASE_EXPORT
std::pair<QString, iscore::Plugin_QtInterface*> PluginLoader::loadPlugin(
        const QString &fileName,
        const std::vector<iscore::Plugin_QtInterface*>& availablePlugins)
{
#if !defined(ISCORE_STATIC_QT)
    auto blacklist = pluginsBlacklist();
    QPluginLoader loader {fileName};

    if(QObject* plugin = loader.instance())
    {
        auto iscore_plugin = dynamic_cast<iscore::Plugin_QtInterface*>(plugin);
        if(!iscore_plugin)
        {
            qDebug() << "Warning: plugin"
                     << plugin->metaObject()->className()
                     << "is not an i-score plug-in.";
            return {};
        }

        // Check if the plugin is not already loaded
        auto plug_it =
                find_if(availablePlugins,
                        [&] (iscore::Plugin_QtInterface* obj)
        { return obj->key() == iscore_plugin->key(); });

        if(plug_it != availablePlugins.end())
        {
            qDebug() << "Warning: plugin"
                     << plugin->metaObject()->className()
                     << "was already loaded. Not reloading.";

            return std::make_pair(fileName, nullptr);
        }

        // Check if it is blacklisted
        if(blacklist.contains(fileName))
        {
            plugin->deleteLater();
            return std::make_pair(fileName, nullptr);
        }

        // We can load the plug-in
        return std::make_pair(fileName, iscore_plugin);
    }
    else
    {
        QString s = loader.errorString();
        if(!s.contains("Plugin verification data mismatch") && !s.contains("is not a Qt plugin"))
            qDebug() << "Error while loading" << fileName << ": " << loader.errorString();
        return {};
    }
#endif

    return {};
}
コード例 #12
0
ファイル: dataiom_gui.cpp プロジェクト: Vaa3D/vaa3d_tools
SelectPluginDlg::SelectPluginDlg(QWidget * parent, const V3DPluginCallback2 & _callback)
	: QDialog(parent)
{
	setMinimumWidth(500);
	parent = parent;
	callback = (V3DPluginCallback2 *) (&(_callback));
	
	QVBoxLayout * layout = new QVBoxLayout;
	
	//tree widget GUI
	pluginTreeWidget = new QTreeWidget();
	pluginTreeWidget->setColumnCount(1);
	pluginTreeWidget->header()->hide();
	pluginTreeWidget->setSortingEnabled(false);

	if (!setPluginRootPathAutomaticly())
		v3d_msg("You don't have any plugins on neuron utilities");
	QStringList fileList;
	getAllFiles(toolboxRootPath, fileList);
	root_path = toolboxRootPath;

	for (int i=0;i<fileList.size();i++)
	{
		QString file = fileList[i];
		QPluginLoader* loader = new QPluginLoader(file);
		if(!loader) 
		{
			cerr<<"unable to load plugin: "<<qPrintable(file)<<endl;
			continue;
		}

		QObject * plugin = loader->instance();

		if (plugin)
		{
			//lib - top level item
			QTreeWidgetItem *pluginItem = new QTreeWidgetItem(pluginTreeWidget);
			QString tmp = file.remove(0, root_path.size()+1);
			tmp.chop(file.section("/", -1).size()+1);
			pluginItem->setText(0, tmp);
			pluginTreeWidget->addTopLevelItem(pluginItem);
			name_table.insert(pluginItem,fileList[i]);

			QStringList menulist = v3d_getInterfaceMenuList(plugin);
			foreach(QString menu_name, menulist)
			{
				//menu - second level item
				QTreeWidgetItem * menuItem = new QTreeWidgetItem(pluginItem);
				menuItem->setText(0, menu_name);
			}
			
		}
		loader->unload();
		delete loader;
	}
コード例 #13
0
ファイル: global.cpp プロジェクト: LukasKoudela/agros2d
PluginInterface *Agros2D::loadPlugin(const QString &pluginName)
{
    QPluginLoader *loader = NULL;

#ifdef Q_WS_X11
    if (QFile::exists(QString("%1/libs/libagros2d_plugin_%2.so").arg(datadir()).arg(pluginName)))
        loader = new QPluginLoader(QString("%1/libs/libagros2d_plugin_%2.so").arg(datadir()).arg(pluginName));

    if (!loader)
    {
        if (QFile::exists(QString("/usr/local/lib/libagros2d_plugin_%1.so").arg(pluginName)))
            loader = new QPluginLoader(QString("/usr/local/lib/libagros2d_plugin_%1.so").arg(pluginName));
        else if (QFile::exists(QString("/usr/lib/libagros2d_plugin_%1.so").arg(pluginName)))
            loader = new QPluginLoader(QString("/usr/lib/libagros2d_plugin_%1.so").arg(pluginName));
    }
#endif

#ifdef Q_WS_WIN
    if (QFile::exists(QString("%1/libs/agros2d_plugin_%2.dll").arg(datadir()).arg(pluginName)))
        loader = new QPluginLoader(QString("%1/libs/agros2d_plugin_%2.dll").arg(datadir()).arg(pluginName));
#endif

    if (!loader)
    {
        throw AgrosPluginException(QObject::tr("Could not find 'agros2d_plugin_%1'").arg(pluginName));
    }

    if (!loader->load())
    {
        QString error = loader->errorString();
        delete loader;
        throw AgrosPluginException(QObject::tr("Could not load 'agros2d_plugin_%1' (%2)").arg(pluginName).arg(error));
    }

    assert(loader->instance());
    PluginInterface *plugin = qobject_cast<PluginInterface *>(loader->instance());

    // loader->unload();
    delete loader;

    return plugin;
}
コード例 #14
0
 void tryLoad(QPluginLoader &loader)
 {
     if (T *newInst = qobject_cast<T*>(loader.instance())) {
         if (!inst || inst->pluginPriority() < newInst->pluginPriority()) {
             inst = newInst;
             pl.unload(); //release any reference to a previous plugin instance
             pl.setFileName(loader.fileName());
             pl.load(); //Adds a ref to the library
         }
     }
 }
コード例 #15
0
ファイル: PluginManager.cpp プロジェクト: AndreiDuma/marble
void PluginManagerPrivate::loadPlugins()
{
    if (m_pluginsLoaded)
    {
        return;
    }

    QTime t;
    t.start();
    mDebug() << "Starting to load Plugins.";

    QStringList pluginFileNameList = MarbleDirs::pluginEntryList( "", QDir::Files );

    MarbleDirs::debug();

    Q_ASSERT( m_renderPluginTemplates.isEmpty() );
    Q_ASSERT( m_positionProviderPluginTemplates.isEmpty() );
    Q_ASSERT( m_searchRunnerPlugins.isEmpty() );
    Q_ASSERT( m_reverseGeocodingRunnerPlugins.isEmpty() );
    Q_ASSERT( m_routingRunnerPlugins.isEmpty() );
    Q_ASSERT( m_parsingRunnerPlugins.isEmpty() );

    foreach( const QString &fileName, pluginFileNameList ) {
        // mDebug() << fileName << " - " << MarbleDirs::pluginPath( fileName );
        QString const path = MarbleDirs::pluginPath( fileName );
        QPluginLoader* loader = new QPluginLoader( path );

        QObject * obj = loader->instance();

        if ( obj ) {
            bool isPlugin = appendPlugin<RenderPlugin, RenderPluginInterface>
                       ( obj, loader, m_renderPluginTemplates );
            isPlugin = isPlugin || appendPlugin<PositionProviderPlugin, PositionProviderPluginInterface>
                       ( obj, loader, m_positionProviderPluginTemplates );
            isPlugin = isPlugin || appendPlugin<SearchRunnerPlugin, SearchRunnerPlugin>
                       ( obj, loader, m_searchRunnerPlugins ); // intentionally T==U
            isPlugin = isPlugin || appendPlugin<ReverseGeocodingRunnerPlugin, ReverseGeocodingRunnerPlugin>
                       ( obj, loader, m_reverseGeocodingRunnerPlugins ); // intentionally T==U
            isPlugin = isPlugin || appendPlugin<RoutingRunnerPlugin, RoutingRunnerPlugin>
                       ( obj, loader, m_routingRunnerPlugins ); // intentionally T==U
            isPlugin = isPlugin || appendPlugin<ParseRunnerPlugin, ParseRunnerPlugin>
                       ( obj, loader, m_parsingRunnerPlugins ); // intentionally T==U
            if ( !isPlugin ) {
                qWarning() << "Ignoring the following plugin since it couldn't be loaded:" << path;
                mDebug() << "Plugin failure:" << path << "is a plugin, but it does not implement the "
                        << "right interfaces or it was compiled against an old version of Marble. Ignoring it.";
                delete loader;
            }
        } else {
            qWarning() << "Ignoring to load the following file since it doesn't look like a valid Marble plugin:" << path << endl
                       << "Reason:" << loader->errorString();
            delete loader;
        }
    }
コード例 #16
0
CntUiExtensionFactory* CntExtensionManager::pluginAt( int index)
{
    loadExtensionPlugins();
    QPluginLoader* pluginLoader = mPlugins[index];
    QObject *plugin = pluginLoader->instance();
    if (plugin)
    {
        return qobject_cast<CntUiExtensionFactory*>(plugin);
    }
    return NULL;
}
コード例 #17
0
ファイル: PluginManager.cpp プロジェクト: snowy97/marble
void PluginManagerPrivate::loadPlugins()
{
    if (m_pluginsLoaded)
    {
        return;
    }

    QTime t;
    t.start();
    mDebug() << "Starting to load Plugins.";

    QStringList pluginFileNameList = MarbleDirs::pluginEntryList( "", QDir::Files );

    MarbleDirs::debug();

    qDeleteAll( m_renderPluginTemplates );
    m_renderPluginTemplates.clear();

    qDeleteAll( m_networkPluginTemplates );
    m_networkPluginTemplates.clear();

    qDeleteAll( m_positionProviderPluginTemplates );
    m_positionProviderPluginTemplates.clear();

    // No need to delete runner plugins

    foreach( const QString &fileName, pluginFileNameList ) {
        // mDebug() << fileName << " - " << MarbleDirs::pluginPath( fileName );
        QString const path = MarbleDirs::pluginPath( fileName );
        QPluginLoader* loader = new QPluginLoader( path );

        QObject * obj = loader->instance();

        if ( obj ) {
            bool isPlugin = appendPlugin<RenderPlugin, RenderPluginInterface>
                       ( obj, loader, m_renderPluginTemplates );
            isPlugin = isPlugin || appendPlugin<NetworkPlugin, NetworkPluginInterface>
                       ( obj, loader, m_networkPluginTemplates );
            isPlugin = isPlugin || appendPlugin<PositionProviderPlugin, PositionProviderPluginInterface>
                       ( obj, loader, m_positionProviderPluginTemplates );
            isPlugin = isPlugin || appendPlugin<RunnerPlugin, RunnerPlugin>
                       ( obj, loader, m_runnerPlugins ); // intentionally T==U
            if ( !isPlugin ) {
                mDebug() << "Plugin failure:" << fileName << "is a plugin, but it does not implement the "
                        << "right interfaces or it was compiled against an old version of Marble. Ignoring it.";
                delete loader;
            }
        } else {
            mDebug() << "Plugin failure:" << fileName << "is not a valid Marble Plugin:"
                     << loader->errorString();
        }
    }
コード例 #18
0
ファイル: form_interface.cpp プロジェクト: LeiDai/agros2d
// read forms
void readCustomForms(QMenu *menu)
{
    QDir dir(datadir() + "/libs/");

    QStringList filter;
    filter << "*agros2d_forms_*";
    QStringList list = dir.entryList(filter);

    foreach (QString filename, list)
    {
        QString fn = QString("%1/%2").arg(dir.absolutePath()).arg(filename);
        if (QFile::exists(fn))
        {
            QPluginLoader *loader = new QPluginLoader(fn);

            if (!loader)
            {
                throw AgrosException(QObject::tr("Could not find '%1'").arg(fn));
            }


            if (!loader->load())
            {
                qDebug() << loader->errorString();
                delete loader;
                throw AgrosException(QObject::tr("Could not load '%1'. %2").arg(fn).arg(loader->errorString()));
            }

            assert(loader->instance());
            FormInterface *form = qobject_cast<FormInterface *>(loader->instance());
            delete loader;

            if (form)
            {
                qDebug() << QString("Form '%1' loaded.").arg(form->formId());
                menu->addAction(form->action());
            }
        }
    }
コード例 #19
0
void tst_QPluginLoader::reloadPlugin()
{
    QPluginLoader loader;
    loader.setFileName( sys_qualifiedLibraryName("theplugin"));     //a plugin
    loader.load(); // not recommended, instance() should do the job.
    PluginInterface *instance = qobject_cast<PluginInterface*>(loader.instance());
    QVERIFY(instance);
    QCOMPARE(instance->pluginName(), QLatin1String("Plugin ok"));

    QSignalSpy spy(loader.instance(), SIGNAL(destroyed()));
    QVERIFY(spy.isValid());
    QVERIFY(loader.unload());   // refcount reached 0, did really unload
    QCOMPARE(spy.count(), 1);

    // reload plugin
    QVERIFY(loader.load());
    QVERIFY(loader.isLoaded());

    PluginInterface *instance2 = qobject_cast<PluginInterface*>(loader.instance());
    QVERIFY(instance2);
    QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));

    QVERIFY(loader.unload());
}
コード例 #20
0
//---------------------------------------------------------------
//UniEditorPluginLoader::getUniEditorPlugin()
//@see header
//---------------------------------------------------------------
UniEditorPluginInterface* UniEditorPluginLoader::getUniEditorPlugin(
                                                                    ConvergedMessage::MessageType messageType)
{
#ifdef _DEBUG
    QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
    dir.cd("messaging\\editorplugins");
#else
    // plugins directory setting for HARDWARE IMAGE
    QDir dir("Z:\\resource\\qt\\plugins\\messaging\\editorplugins");
#endif

    QString pluginPath = dir.absolutePath();
#ifdef _DEBUG_TRACES_
    qDebug() << "Enter LoadPlugin path = " << pluginPath;
#endif

    // get the list of all plugins...
    QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Readable);
    QString filePath = QString();
    foreach (QFileInfo entry, entries)
        {
            if (messageType == ConvergedMessage::Sms && entry.fileName()
                    == SMS_PLUGIN)
            {
                filePath = entry.absoluteFilePath();
                break;
            }
            else if (messageType == ConvergedMessage::Mms && entry.fileName()
                    == MMS_PLUGIN)
            {
                filePath = entry.absoluteFilePath();
                break;
            }
        }

    if (!filePath.isEmpty())
    {
        QPluginLoader* loader = new QPluginLoader(filePath, this);
        UniEditorPluginInterface* editorPlugin = qobject_cast<
                UniEditorPluginInterface*> (loader->instance());
        if (editorPlugin)
        {
            mPluginLoaderList << loader;
            return editorPlugin;
        }
    }
    return NULL;
}
コード例 #21
0
void QAudioPluginLoader::load()
{
    if (!m_plugins.isEmpty())
        return;

    QStringList plugins = pluginList();
    for (int i=0; i < plugins.count(); i++) {
        QPluginLoader* loader = new QPluginLoader(plugins.at(i));
        QObject *o = loader->instance();
        if (o != 0 && o->qt_metacast(m_iid) != 0)
            m_plugins.append(loader);
        else {
            qWarning() << "QAudioPluginLoader: Failed to load plugin: "
                << plugins.at(i) << loader->errorString();
        }
    }
}
コード例 #22
0
 // 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()), "");
 }
コード例 #23
0
ファイル: pluginloader.cpp プロジェクト: KDE/akonadi
QObject *PluginLoader::createForName(const QString &name)
{
    if (!mPluginInfos.contains(name)) {
        qCWarning(AKONADICORE_LOG) << "plugin name \"" << name << "\" is unknown to the plugin loader." << endl;
        return 0;
    }

    PluginMetaData &info = mPluginInfos[name];

    //First try to load it staticly
    foreach (QObject *plugin, QPluginLoader::staticInstances()) {
        if (QLatin1String(plugin->metaObject()->className()) == info.className) {
            info.loaded = true;
            return plugin;
            break;
        }
    }

    if (!info.loaded) {
        QPluginLoader *loader = new QPluginLoader(info.library);
        if (loader->fileName().isEmpty()) {
            qCWarning(AKONADICORE_LOG) << loader->errorString();
            delete loader;
            return 0;
        }

        mPluginLoaders.insert(name, loader);
        info.loaded = true;
    }

    QPluginLoader *loader = mPluginLoaders.value(name);
    Q_ASSERT(loader);

    QObject *object = loader->instance();
    if (!object) {
        qCWarning(AKONADICORE_LOG) << "unable to load plugin" << info.library << "for plugin name" << name << ".";
        qCWarning(AKONADICORE_LOG) << "Error was:\"" << loader->errorString() << "\".";
        return 0;
    }

    return object;
}
コード例 #24
0
ファイル: editorManager.cpp プロジェクト: Esenin/qreal
bool EditorManager::loadPlugin(QString const &pluginName)
{
	QPluginLoader *loader = new QPluginLoader(mPluginsDir.absoluteFilePath(pluginName));
	loader->load();
	QObject *plugin = loader->instance();

	if (plugin) {
		EditorInterface *iEditor = qobject_cast<EditorInterface *>(plugin);
		if (iEditor) {
			mPluginsLoaded += iEditor->id();
			mPluginFileName.insert(iEditor->id(), pluginName);
			mPluginIface[iEditor->id()] = iEditor;
			mLoaders.insert(pluginName, loader);
			return true;
		}
	}

	QMessageBox::warning(NULL, tr("error"), tr("Plugin loading failed: ") + loader->errorString());
	loader->unload();
	delete loader;
	return false;
}
コード例 #25
0
bool CDbHandling::loadPlugin()
{
    if(dbInterface)
        return true;

    QSettings settings ( QCoreApplication::instance()->applicationDirPath() +"/horux.ini", QSettings::IniFormat );
    settings.beginGroup ( "SQL" );
    QString plugin = settings.value ( "plugins", "mysql" ).toString();
    if ( !settings.contains ( "plugins" ) ) settings.setValue ( "plugins", "mysql" );
    settings.endGroup();

    QDir pluginDirectory ( QCoreApplication::instance()->applicationDirPath() + "/plugins/db/" );


    QStringList filter;

#if defined(Q_OS_WIN)
    filter << plugin + "*";
#elif defined(Q_WS_X11) || defined(Q_WS_QWS)
    filter << "lib" + plugin + "*";
#endif

    if ( pluginDirectory.entryList ( filter ).count() >0 )
    {
        QString fileName = pluginDirectory.entryList ( filter ).first();

        QPluginLoader pluginLoader ( pluginDirectory.absoluteFilePath ( fileName ), this );
        QObject *plugin = pluginLoader.instance();

        if ( plugin )
        {
            dbInterface = qobject_cast<CDbInterface *> ( plugin );
            return true;
        }
    }

    return false;
}
コード例 #26
0
ファイル: editorManager.cpp プロジェクト: Esenin/qreal
EditorManager::EditorManager(QObject *parent) : QObject(parent)
{
	mPluginsDir = QDir(qApp->applicationDirPath());

	while (!mPluginsDir.isRoot() && !mPluginsDir.entryList(QDir::Dirs).contains("plugins")) {
		mPluginsDir.cdUp();
	}

	mPluginsDir.cd("plugins");

	foreach (QString const &fileName, mPluginsDir.entryList(QDir::Files)) {
		QPluginLoader *loader  = new QPluginLoader(mPluginsDir.absoluteFilePath(fileName));
		QObject *plugin = loader->instance();

		if (plugin) {
			EditorInterface *iEditor = qobject_cast<EditorInterface *>(plugin);
			if (iEditor) {
				mPluginsLoaded += iEditor->id();
				mPluginFileName.insert(iEditor->id(), fileName);
				mPluginIface[iEditor->id()] = iEditor;
				mLoaders.insert(fileName, loader);
			} else {
				// TODO: Just does not work under Linux. Seems to be memory corruption when
				// loading, unloading, and then loading .so file again.
				// To reproduce, uncomment this, build VisualInterpreter, and try to launch QReal.
				// With some tool plugins, like MetaEditorSupport or Exterminatus, works fine,
				// also works fine on Windows. Investigation required.
				// loader->unload();
				delete loader;
			}
		} else {
			qDebug() << "Plugin loading failed: " << loader->errorString();
			loader->unload();
			delete loader;
		}
	}
}
コード例 #27
0
QPair<QObject *, QString> PluginManagerImplementation::pluginLoadedByName(QString const &pluginName)
{
	QPluginLoader *loader = new QPluginLoader(mPluginsDir.absoluteFilePath(pluginName));
	loader->load();
	QObject *plugin = loader->instance();

	if (plugin) {
		mFileNameAndPlugin.insert(pluginName, plugin);
		return qMakePair(plugin, QString());
	}

	QString const loaderError = loader->errorString();

	// Unloading of plugins is currently (Qt 5.3) broken due to a bug in metatype system: calling Q_DECLARE_METATYPE
	// from plugin registers some data from plugin address space in Qt metatype system, which is not being updated
	// when plugin is unloaded and loaded again. Any subsequent calls to QVariant or other template classes/methods
	// which use metainformation will result in a crash. It is likely (but not verified) that qRegisterMetaType leads
	// to the same issue. Since we can not guarantee that plugin does not use Q_DECLARE_METATYPE or qRegisterMetaType
	// we shall not unload plugin at all, to be safe rather than sorry.
	//
	// But it seems also that metainformation gets deleted BEFORE plugins are unloaded on application exit, so we can
	// not call any metainformation-using code in destructors that get called on unloading. Since Qt classes themselves
	// are using such calls (QGraphicsViewScene, for example), random crashes on exit may be a symptom of this problem.
	//
	// EditorManager is an exception, because it really needs to unload editor plugins, to be able to load new versions
	// compiled by metaeditor. Editor plugins are generated, so we can guarantee to some extent that there will be no
	// metatype registrations.
	//
	// See:
	// http://stackoverflow.com/questions/19234703/using-q-declare-metatype-with-a-dll-that-may-be-loaded-multiple-times
	// (and http://qt-project.org/forums/viewthread/35587)
	// https://bugreports.qt-project.org/browse/QTBUG-32442

	delete loader;
	return qMakePair(nullptr, loaderError);
}
コード例 #28
0
ファイル: suipluginmanager.cpp プロジェクト: asvitenkov/sui
void suiPluginManager::unloadPlugin(const QString &fileName)
{
    qDebug() << "Unload plugin: " << fileName;

    if (mPluginLoaders.find(fileName) == mPluginLoaders.end())
        SuiExcept(SuiExceptionItemNotFound,
                  QString("Plugin '%1' doesn't loaded").arg(fileName),
                  "void suiPluginManager::unloadPlugin(const QString &fileName)");

    QMap<QString, QPluginLoader*>::iterator it = mPluginLoaders.find(fileName);
    QPluginLoader *loader = it.value();

    UiPluginInterface *plugInterface = qobject_cast<UiPluginInterface*>(loader->instance());
    if (!plugInterface) SuiExcept(SuiExceptionInternalError,
                                  QString("There are no plugin interface in '%1'").arg(fileName),
                                  "void suiPluginManager::unloadPlugin(const QString &fileName)");
    processUnloadPlugin(plugInterface);

    mPluginLoaders.erase(it);
    if (!loader->unload())  SuiExcept(SuiExceptionInternalError,
                                      QString("Can't unload plugin '%1'").arg(fileName),
                                      "void suiPluginManager::unloadPlugin(const QString &fileName)");
    delete loader;
}
コード例 #29
0
void tst_QPluginLoader::errorString()
{
#if defined(Q_OS_WINCE)
    // On WinCE we need an QCoreApplication object for current dir
    int argc = 0;
    QCoreApplication app(argc,0);
#endif
    const QString unknown(QLatin1String("Unknown error"));

    {
    QPluginLoader loader; // default constructed
    bool loaded = loader.load();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(loaded, false);
    QCOMPARE(loader.errorString(), unknown);

    QObject *obj = loader.instance();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(obj, static_cast<QObject*>(0));
    QCOMPARE(loader.errorString(), unknown);

    bool unloaded = loader.unload();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(unloaded, false);
    QCOMPARE(loader.errorString(), unknown);
    }
    {
    QPluginLoader loader( sys_qualifiedLibraryName("tst_qpluginloaderlib"));     //not a plugin
    bool loaded = loader.load();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(loaded, false);
    QVERIFY(loader.errorString() != unknown);

    QObject *obj = loader.instance();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(obj, static_cast<QObject*>(0));
    QVERIFY(loader.errorString() != unknown);

    bool unloaded = loader.unload();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(unloaded, false);
    QVERIFY(loader.errorString() != unknown);
    }

    {
    QPluginLoader loader( sys_qualifiedLibraryName("nosuchfile"));     //not a file
    bool loaded = loader.load();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(loaded, false);
    QVERIFY(loader.errorString() != unknown);

    QObject *obj = loader.instance();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(obj, static_cast<QObject*>(0));
    QVERIFY(loader.errorString() != unknown);

    bool unloaded = loader.unload();
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QCOMPARE(unloaded, false);
    QVERIFY(loader.errorString() != unknown);
    }

#if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined Q_OS_HPUX && !defined Q_OS_SYMBIAN && !defined Q_OS_QNX
    {
    QPluginLoader loader( sys_qualifiedLibraryName("almostplugin"));     //a plugin with unresolved symbols
    loader.setLoadHints(QLibrary::ResolveAllSymbolsHint);
    QCOMPARE(loader.load(), false);
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QVERIFY(loader.errorString() != unknown);

    QCOMPARE(loader.instance(), static_cast<QObject*>(0));
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QVERIFY(loader.errorString() != unknown);

    QCOMPARE(loader.unload(), false);
#ifdef SHOW_ERRORS
    qDebug() << loader.errorString();
#endif
    QVERIFY(loader.errorString() != unknown);
    }
#endif

    {
    QPluginLoader loader( sys_qualifiedLibraryName("theplugin"));     //a plugin
    QCOMPARE(loader.load(), true);
    QCOMPARE(loader.errorString(), unknown);

    QVERIFY(loader.instance() !=  static_cast<QObject*>(0));
    QCOMPARE(loader.errorString(), unknown);

    // Make sure that plugin really works
    PluginInterface* theplugin = qobject_cast<PluginInterface*>(loader.instance());
    QString pluginName = theplugin->pluginName();
    QCOMPARE(pluginName, QLatin1String("Plugin ok"));

    QCOMPARE(loader.unload(), true);
    QCOMPARE(loader.errorString(), unknown);
    }
}
コード例 #30
0
void QGeoSatelliteInfoSourcePrivate::loadDynamicPlugins(QHash<QString, QGeoPositionInfoSourceFactory *> &plugins)
{
    QStringList paths;
    paths << mobilityPlugins(QLatin1String("position"));

    QPluginLoader qpl;
    QString blockName;

    QSettings settings(QSettings::SystemScope, QLatin1String("Nokia"), QLatin1String("QtLocationPosAndSat"));
    QVariant value = settings.value("position.plugin.operator.whitelist");
    if (value.isValid()) {
        QStringList parts = value.toString().split(",");
        if (parts.size() == 4) {
            QFile file(parts.at(1));
            file.open(QIODevice::ReadOnly);

            QCryptographicHash hash(QCryptographicHash::Sha1);
            while (!file.atEnd()) {
                QByteArray data = file.read(4096);
                hash.addData(data);
            }
            file.close();

            QByteArray hexHash = hash.result().toHex();

            bool loadIt = true;
            if (QString::number(file.size()) != parts.at(3)) {
                qCritical("Position info plugin: bad plugin size for %s",
                          qPrintable(parts.at(1)));
                qWarning("Will fall back to platform default");
                loadIt = false;
            }

            if (hexHash != parts.at(2).toLatin1()) {
                qCritical("Position info plugin: bad plugin hash for %s",
                          qPrintable(parts.at(1)));
                qWarning("Will fall back to platform default");
                loadIt = false;
            }

            if (loadIt) {
                qpl.setFileName(parts.at(1));
                QGeoPositionInfoSourceFactory *f =
                        qobject_cast<QGeoPositionInfoSourceFactory*>(qpl.instance());

                if (f) {
                    QString name = f->sourceName();
                    if (name == parts.at(0)) {
                        plugins.insert(name, f);
                    } else {
                        qCritical("Position info plugin: bad plugin name for %s",
                                  qPrintable(parts.at(1)));
                        qWarning("Will fall back to platform default");
                    }
                }
            }

            // still set blockName to ensure the plugin doesn't load
            blockName = parts.at(1);
        } else {
            qWarning("Position plugin whitelist: invalid format -- should be key,filename,hash,size");
        }
    }

    for (int i = 0; i < paths.count(); ++i) {
        if (paths.at(i) != blockName) {
            qpl.setFileName(paths.at(i));

            QGeoPositionInfoSourceFactory *f =
                    qobject_cast<QGeoPositionInfoSourceFactory*>(qpl.instance());
            if (f) {
                QString name = f->sourceName();

    #if !defined QT_NO_DEBUG
                const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
                if (showDebug)
                    qDebug("Dynamic: found a service provider plugin with name %s", qPrintable(name));
    #endif
                plugins.insertMulti(name, f);
            }
        }
    }
}