Skip to content
Permalink
Browse files

Check qgsMaximumVersion also when loading plugin to QgsPluginRegistry

  • Loading branch information
borysiasty committed Jun 9, 2013
1 parent 094245e commit 5c50e2a6c006cb1e7785d7ec770eb7aea9afd215
Showing with 55 additions and 11 deletions.
  1. +12 −0 python/pyplugin_installer/version_compare.py
  2. +40 −9 src/app/qgspluginregistry.cpp
  3. +3 −2 src/app/qgspluginregistry.h
@@ -124,6 +124,18 @@ def compareVersions(a,b):
# convert the strings to the lists
v1 = chopString(a)
v2 = chopString(b)

# !! ensure the version contains at least 3 segments. Fill to "x.y.z with "999" segments if needed.
# 999 must me unicode because of isnumeric method used.
if len(v1) == 2:
v1 += [u"999"]
elif len(v1) == 1:
v1 += [u"999",u"999"]
if len(v2) == 2:
v2 += [u"999"]
elif len(v2) == 1:
v2 += [u"999",u"999"]

# set the shorter string as a base
l = len(v1)
if l > len(v2):
@@ -184,10 +184,10 @@ void QgsPluginRegistry::unloadAll()
}


bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
bool QgsPluginRegistry::checkQgisVersion( QString minVersion, QString maxVersion )
{
// Parse qgisMinVersion. Must be in form x.y.z or just x.y
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;

@@ -206,6 +206,35 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
return false;
}

// Parse qgisMaxVersion. Must be in form x.y.z or just x.y
int maxVerMajor, maxVerMinor, maxVerBugfix = 0;
if ( maxVersion.isEmpty() || maxVersion == "__error__" )
{
maxVerMajor = minVerMajor;
maxVerMinor = 999;
maxVerBugfix = 999;
}
else
{
QStringList maxVersionParts = maxVersion.split( '.' );
if ( maxVersionParts.count() != 2 && maxVersionParts.count() != 3 )
return false;

bool ok;
maxVerMajor = maxVersionParts.at( 0 ).toInt( &ok );
if ( !ok )
return false;
maxVerMinor = maxVersionParts.at( 1 ).toInt( &ok );
if ( !ok )
return false;
if ( maxVersionParts.count() == 3 )
{
maxVerBugfix = maxVersionParts.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( "." );
@@ -215,21 +244,21 @@ bool QgsPluginRegistry::checkQgisVersion( QString minVersion )
int qgisBugfix = qgisVersionParts.at( 2 ).toInt();

// first check major version
if ( minVerMajor > qgisMajor )
if ( minVerMajor > qgisMajor || maxVerMajor < qgisMajor )
return false;
if ( minVerMajor < qgisMajor )
if ( minVerMajor < qgisMajor || maxVerMajor > qgisMajor )
return true;
// if same, check minor version
if ( minVerMinor > qgisMinor )
if ( minVerMinor > qgisMinor || maxVerMinor < qgisMinor )
return false;
if ( minVerMinor < qgisMinor )
if ( minVerMinor < qgisMinor || maxVerMinor > qgisMinor )
return true;

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

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

@@ -562,7 +591,9 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
bool QgsPluginRegistry::isPythonPluginCompatible( QString packageName )
{
QString minVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMinimumVersion" );
return minVersion != "__error__" && checkQgisVersion( minVersion );
// try to read qgisMaximumVersion. Note checkQgisVersion can cope with "__error__" value.
QString maxVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMaximumVersion" );
return minVersion != "__error__" && checkQgisVersion( minVersion, maxVersion );
}

QList<QgsPluginMetadata*> QgsPluginRegistry::pluginData()
@@ -102,8 +102,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 );
//! Check current QGIS version against requested minimal and optionally maximal QGIS version
//! if maxVersion not specified, the default value is assumed: floor(minVersion) + 0.999.999
bool checkQgisVersion( QString minVersion, QString maxVersion = "" );

private:
static QgsPluginRegistry* _instance;

0 comments on commit 5c50e2a

Please sign in to comment.
You can’t perform that action at this time.