Example #1
0
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)");
    }
}
Example #2
0
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();
}
Example #3
0
void loadMySqlDriver()
{
    QPluginLoader loader;
    loader.setFileName("/opt/qtsdk-2010.04/qt/plugins/sqldrivers/libqsqlmysql.so");
    qDebug()<<loader.load();
    qDebug()<<loader.errorString();
}
Example #4
0
int Global::documentType(const QUrl& document)
{
    QMimeType mime = QMimeDatabase{}.mimeTypeForUrl(document);

    QList<QPluginLoader*> plugins = KoJsonTrader::self()->query("Calligra/Part", mime.name());

    for (int i = 0; i < plugins.count(); i++) {
        QPluginLoader* loader = plugins.at(i);

        if(loader->fileName().contains("words")) {
            return DocumentType::TextDocument;
        } else if(loader->fileName().contains("sheets")) {
            return DocumentType::Spreadsheet;
        } else if(loader->fileName().contains("stage")) {
            return DocumentType::Presentation;
        }
    }

    // Since we don't actually have a Calligra plugin that handles these...
    if(staticTextTypes.contains(mime.name())) {
        return DocumentType::StaticTextDocument;
    }

    return DocumentType::Unknown;
}
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;
            }
      }
    }
}
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 ()
}
Example #7
0
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);
        }
Example #8
0
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;
}
Example #9
0
void PluginManager::scanPlugins(bool initialScan) {
    if (initialScan) {
        QFileInfoList list = _pluginPath.entryInfoList();
        for (QFileInfo info : list) {
            QPluginLoader* loader = new QPluginLoader(info.absoluteFilePath(), this);
            QJsonObject metaData = loader->metaData().value("MetaData").toObject();

            const QString name = metaData.value("name").toString("Unknown");
            const QString role = metaData.value("role").toString("Unknown");

            // Ensure IID is inserted.
            metaData.insert("IID", loader->metaData().value("IID"));

            AdamantPluginInfo* data = new AdamantPluginInfo;
            data->state = PluginState::Unknown;
            data->name = name;
            data->role = role;
            data->metaData = metaData;
            data->instance = nullptr;
            data->script = nullptr;
            data->loader = nullptr;
            data->file = info;
            data->lastModified = info.lastModified();
            _pluginsByRole.insertMulti(role, data);

            emit pluginDiscovered(name);

            loader->deleteLater();
        }
    }
}
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;
}
bool ComponentManager::unloadModelComponentInfoById(const QString& id)
{
  if(m_modelComponentInfoById.contains(id))
  {
    IModelComponentInfo* componentInfo = m_modelComponentInfoById[id];

    if (m_modelComponentInfoHash.contains(componentInfo))
    {
      QPluginLoader* plugin = m_modelComponentInfoHash[componentInfo];
      m_modelComponentInfoHash.remove(componentInfo);
      m_modelComponentInfoById.remove(id);

      emit modelComponentInfoUnloaded(componentInfo->id());
      emit postMessage("Model component library " + componentInfo->id() + " unloaded");

      plugin->unload();

      return true;
    }
    else
    {
      emit postMessage("Unable to unload model component library " + componentInfo->id());
      return false;
    }
  }
  else
  {
    return false;
  }
}
Example #12
0
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);
    }

}
/*!
    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;
}
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);
}
Example #15
0
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 {};
}
Example #16
0
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;
	}
CntUiExtensionFactory* CntExtensionManager::pluginAt( int index)
{
    loadExtensionPlugins();
    QPluginLoader* pluginLoader = mPlugins[index];
    QObject *plugin = pluginLoader->instance();
    if (plugin)
    {
        return qobject_cast<CntUiExtensionFactory*>(plugin);
    }
    return NULL;
}
Example #18
0
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;
        }
    }
Example #19
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
         }
     }
 }
Example #20
0
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();
        }
    }
Example #21
0
void plugin_factory::load_all()
{
	auto file_list = QDir(plugindir_).entryInfoList(
			QDir::Files | QDir::NoDotAndDotDot);
	for (auto const &info : file_list) {
		auto p = info.absoluteFilePath();
		QPluginLoader *ld;
		if ((ld = load_plugin(p)) != 0) {
			qDebug() << "Loaded plugin" << p;
			plugins_.insert(ld->metaData().value("IID").toString(), ld);
		} else
			qDebug() << p << "is not an acv plugin";
	}
}
//---------------------------------------------------------------
//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;
}
QVariant GameEngine::pluginList()
{
    QStringList list;
    QPluginLoader* loader;
    foreach (loader,m_pluginList) {
        QString s = loader->fileName();
        s = s.mid(s.lastIndexOf("/")+1);
        s = s.left(s.lastIndexOf("."));
        s = s.toUpper();
#ifdef Q_WS_MAEMO_5
        if (s.contains("LIB")) {
            s = s.right(s.length() - (s.indexOf("LIB")+3));
        }
#endif
        list.append(s);
    }
Example #24
0
void DefaultManager::dump_metadata(const QPluginLoader& loader) const
{
	const auto meta = loader.metaData();
	qDebug() << meta.value("MetaData").toObject().value("name");
	qDebug() << meta.value("MetaData").toObject().value("version");
	qDebug() << meta.value("MetaData").toObject().value("dependencies");
}
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();
        }
    }
}
Example #26
0
bool EditorManager::unloadPlugin(QString const &pluginName)
{
	QPluginLoader *loader = mLoaders[mPluginFileName[pluginName]];
	if (loader != NULL) {
		mLoaders.remove(mPluginFileName[pluginName]);
		mPluginIface.remove(pluginName);
		mPluginFileName.remove(pluginName);
		mPluginsLoaded.removeAll(pluginName);
		if (!loader->unload()) {
			QMessageBox::warning(NULL, tr("error"), tr("Plugin unloading failed: ") + loader->errorString());
			delete loader;
			return false;
		}
		delete loader;
		return true;
	}
	return false;
}
QString PluginManagerImplementation::unloadPlugin(QString const &pluginName)
{
	QPluginLoader *loader = mLoaders[pluginName];

	if (loader) {
		mLoaders.remove(pluginName);

		if (!loader->unload()) {
			QString const error = loader->errorString();
			delete loader;
			return error;
		}

		delete loader;
		return QString();
	}

	return QString("Plugin was not found");
}
Example #28
0
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;
}
Example #29
0
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();
}
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()));
    }
}