Skip to content

Commit

Permalink
Check qgsMaximumVersion also when loading plugin to QgsPluginRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
borysiasty committed Jun 9, 2013
1 parent 094245e commit 5c50e2a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
12 changes: 12 additions & 0 deletions python/pyplugin_installer/version_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
49 changes: 40 additions & 9 deletions src/app/qgspluginregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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( "." );
Expand All @@ -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;
}

Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgspluginregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5c50e2a

Please sign in to comment.