Skip to content
Permalink
Browse files
Allow loading only compatible plugins, i.e. plugins implementing qgis…
…MinimumVersion() metadata.

Incompatible plugins are disabled and can't be selected in plugin manager.

Example of new metadata: (plugin's __init__.py)

def qgisMinimumVersion():
  return "1.0"


git-svn-id: http://svn.osgeo.org/qgis/trunk@9652 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Nov 17, 2008
1 parent 22dfe17 commit f5e577c2e317eaaa8f359fadab1d3b1286ed5f8e
Showing with 82 additions and 9 deletions.
  1. +10 −7 src/app/qgspluginmanager.cpp
  2. +66 −2 src/app/qgspluginregistry.cpp
  3. +6 −0 src/app/qgspluginregistry.h
@@ -147,6 +147,11 @@ void QgsPluginManager::getPythonPluginDescriptions()
QString version = mPythonUtils->getPluginMetadata( packageName, "version" );

if ( pluginName == "???" || description == "???" || version == "???" ) continue;

bool isCompatible = QgsPluginRegistry::instance()->isPythonPluginCompatible( packageName );
QString compatibleString; // empty by default
if (!isCompatible)
compatibleString = " " + tr("[ incompatible ]");

// filtering will be done on the display role so give it name and desription
// user wont see this text since we are using a custome delegate
@@ -156,9 +161,11 @@ void QgsPluginManager::getPythonPluginDescriptions()
mypDetailItem->setData( packageName, PLUGIN_BASE_NAME_ROLE ); //for matching in registry later
mypDetailItem->setCheckable( false );
mypDetailItem->setEditable( false );
mypDetailItem->setEnabled( isCompatible );
// setData in the delegate with a variantised QgsDetailedItemData
QgsDetailedItemData myData;
myData.setTitle( pluginName + " (" + version + ")" );
myData.setTitle( pluginName + " (" + version + ")" + compatibleString );
myData.setEnabled( isCompatible );
myData.setDetail( description );
//myData.setIcon(pixmap); //todo use a python logo here
myData.setCheckable( true );
@@ -476,13 +483,9 @@ void QgsPluginManager::on_vwPlugins_clicked( const QModelIndex &theIndex )
QStandardItem* mypItem = mModelPlugins->itemFromIndex( realIndex );
QgsDetailedItemData myData =
qVariantValue<QgsDetailedItemData>( mypItem->data( PLUGIN_DATA_ROLE ) );
if ( myData.isChecked() )
if ( myData.isEnabled() )
{
myData.setChecked( false );
}
else
{
myData.setChecked( true );
myData.setChecked( ! myData.isChecked() );
}
QVariant myVariant = qVariantFromValue( myData );
mypItem->setData( myVariant, PLUGIN_DATA_ROLE );
@@ -152,6 +152,48 @@ void QgsPluginRegistry::unloadAll()
}


bool QgsPluginRegistry::checkQgisVersion(QString minVersion)
{
QStringList minVersionParts = minVersion.split('.');
// qgis version must be in form x.y.z or just x.y
if (minVersionParts.count() != 2 && minVersionParts.count() != 3)
return false;

int minVerMajor, minVerMinor, minVerBugfix=0;
bool ok;
minVerMajor = minVersionParts.at(0).toInt(&ok);
if (!ok) return false;
minVerMinor = minVersionParts.at(1).toInt(&ok);
if (!ok) return false;
if (minVersionParts.count() == 3)
{
minVerBugfix = minVersionParts.at(2).toInt(&ok);
if (!ok) return false;
}

// our qgis version - cut release name after version number
QString qgisVersion = QString(QGis::QGIS_VERSION).section( '-', 0, 0 );
QStringList qgisVersionParts = qgisVersion.split( "." );

int qgisMajor = qgisVersionParts.at( 0 ).toInt();
int qgisMinor = qgisVersionParts.at( 1 ).toInt();
int qgisBugfix= qgisVersionParts.at( 2 ).toInt();

// first check major version
if (minVerMajor > qgisMajor) return false;
if (minVerMajor < qgisMajor) return true;

// if same, check minor version
if (minVerMinor > qgisMinor) return false;
if (minVerMinor < qgisMinor) return true;

// if still same, check bugfix version
if (minVerBugfix > qgisBugfix) return false;

// looks like min version is the same as our version - that's fine
return true;
}


void QgsPluginRegistry::loadPythonPlugin( QString packageName )
{
@@ -160,22 +202,30 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )
QgsDebugMsg( "Python is not enabled in QGIS." );
return;
}

QSettings settings;

// is loaded already?
if ( ! isLoaded( packageName ) )
{
// if plugin is not compatible, disable it
if ( ! isPythonPluginCompatible( packageName ) )
{
settings.setValue( "/PythonPlugins/" + packageName, false );
return;
}

mPythonUtils->loadPlugin( packageName );
mPythonUtils->startPlugin( packageName );

// TODO: test success

QString pluginName = mPythonUtils->getPluginMetadata( packageName, "name" );

// add to plugin registry
addPlugin( packageName, QgsPluginMetadata( packageName, pluginName, NULL, true ) );

// add to settings
QSettings settings;
settings.setValue( "/PythonPlugins/" + packageName, true );
std::cout << "Loaded : " << pluginName.toLocal8Bit().constData() << " (package: "
<< packageName.toLocal8Bit().constData() << ")" << std::endl; // OK
@@ -364,3 +414,17 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )

return true;
}

bool QgsPluginRegistry::isPythonPluginCompatible( QString packageName )
{
QString minVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMinimumVersion" );
if (minVersion == "__error__" || !checkQgisVersion(minVersion))
{
//QMessageBox::information(mQgisInterface->mainWindow(),
// QObject::tr("Incompatible plugin"),
// QObject::tr("Plugin \"%1\" is not compatible with this version of Quantum GIS.\nIt will be disabled.").arg(pluginName));
//settings.setValue( "/PythonPlugins/" + packageName, false );
return false;
}
return true;
}
@@ -81,6 +81,9 @@ class QgsPluginRegistry
//! Load any plugins used in the last qgis session
void restoreSessionPlugins( QString thePluginDirString );

//! Check whether plugin is compatible with current version of QGIS
bool isPythonPluginCompatible( QString packageName );

protected:
//! protected constructor
QgsPluginRegistry();
@@ -90,6 +93,9 @@ class QgsPluginRegistry
//! Try to load and get metadata from Python plugin, return true on success
bool checkPythonPlugin( QString packageName );

//! Check current QGIS version against plugin's minimal requested QGIS version
bool checkQgisVersion(QString minVersion);

private:
static QgsPluginRegistry* _instance;
QMap<QString, QgsPluginMetadata> mPlugins;

0 comments on commit f5e577c

Please sign in to comment.