add a mechanism to prevent a plugin to be loaded

for example, adding in the config file

plugin_blacklist=gocad_plugin|

will prevent the gocad to be loaded
This commit is contained in:
Sébastien Loriot 2012-10-17 16:18:07 +00:00
parent 39e37c53e4
commit b2afce039a
2 changed files with 30 additions and 5 deletions

View File

@ -290,6 +290,8 @@ MainWindow::MainWindow(QWidget* parent)
# endif
#endif
readSettings(); // Among other things, the column widths are stored.
// Load plugins, and re-enable actions that need it.
loadPlugins();
@ -299,7 +301,6 @@ MainWindow::MainWindow(QWidget* parent)
}
ui->menuDockWindows->removeAction(ui->dummyAction);
readSettings(); // Among other things, the column widths are stored.
#ifdef QT_SCRIPT_LIB
// evaluate_script("print(plugins);");
@ -417,14 +418,20 @@ void MainWindow::loadPlugins()
qPrintable(pluginsDir.absolutePath()));
Q_FOREACH (QString fileName, pluginsDir.entryList(QDir::Files)) {
if(fileName.contains("plugin") && QLibrary::isLibrary(fileName)) {
//set plugin name
QString name = fileName;
name.remove(QRegExp("^lib"));
name.remove(QRegExp("\\..*"));
//do not load it if it is in the blacklist
if ( plugin_blacklist.contains(name) ){
qDebug("### Ignoring plugin \"%s\".", qPrintable(fileName));
continue;
}
qDebug("### Loading \"%s\"...", qPrintable(fileName));
QPluginLoader loader;
loader.setFileName(pluginsDir.absoluteFilePath(fileName));
QObject *obj = loader.instance();
if(obj) {
QString name = fileName;
name.remove(QRegExp("^lib"));
name.remove(QRegExp("\\..*"));
obj->setObjectName(name);
initPlugin(obj);
initIOPlugin(obj);
@ -967,6 +974,11 @@ void MainWindow::readSettings()
QSettings settings;
// enable anti-aliasing
ui->actionAntiAliasing->setChecked(settings.value("antialiasing", false).toBool());
// read plugin blacklist
QString blacklist=settings.value("plugin_blacklist",QString()).toString();
Q_FOREACH(QString name, blacklist.split("|") ) {
if ( !name.isEmpty() ) plugin_blacklist.insert(name);
}
}
this->readState("MainWindow", Size|State);
}
@ -978,6 +990,16 @@ void MainWindow::writeSettings()
QSettings settings;
settings.setValue("antialiasing",
ui->actionAntiAliasing->isChecked());
//setting plugin blacklist
QString bl_value;
Q_FOREACH(QString name, plugin_blacklist)
{
//even after the last name we append a | but it does not matter as the reading
//takes this into account
bl_value.append(name).append('|');
}
if ( !bl_value.isEmpty() )
settings.setValue("plugin_blacklist",bl_value);
}
std::cerr << "Write setting... done.\n";
}

View File

@ -12,6 +12,7 @@
#include <QList>
#include <QFileInfo>
#include <QStringList>
#include <QSet>
class Scene;
class Viewer;
@ -19,7 +20,6 @@ class QTreeView;
class QMenu;
class Polyhedron_demo_io_plugin_interface;
class Polyhedron_demo_plugin_interface;
class Scene_item;
namespace Ui {
@ -152,6 +152,9 @@ protected:
private:
QString strippedName(const QString &fullFileName);
/// plugin black-list
QSet<QString> plugin_blacklist;
Scene* scene;
Viewer* viewer;
QTreeView* sceneView;