@@ -152,6 +152,48 @@ void QgsPluginRegistry::unloadAll()
152152}
153153
154154
155+ bool QgsPluginRegistry::checkQgisVersion (QString minVersion)
156+ {
157+ QStringList minVersionParts = minVersion.split (' .' );
158+ // qgis version must be in form x.y.z or just x.y
159+ if (minVersionParts.count () != 2 && minVersionParts.count () != 3 )
160+ return false ;
161+
162+ int minVerMajor, minVerMinor, minVerBugfix=0 ;
163+ bool ok;
164+ minVerMajor = minVersionParts.at (0 ).toInt (&ok);
165+ if (!ok) return false ;
166+ minVerMinor = minVersionParts.at (1 ).toInt (&ok);
167+ if (!ok) return false ;
168+ if (minVersionParts.count () == 3 )
169+ {
170+ minVerBugfix = minVersionParts.at (2 ).toInt (&ok);
171+ if (!ok) return false ;
172+ }
173+
174+ // our qgis version - cut release name after version number
175+ QString qgisVersion = QString (QGis::QGIS_VERSION).section ( ' -' , 0 , 0 );
176+ QStringList qgisVersionParts = qgisVersion.split ( " ." );
177+
178+ int qgisMajor = qgisVersionParts.at ( 0 ).toInt ();
179+ int qgisMinor = qgisVersionParts.at ( 1 ).toInt ();
180+ int qgisBugfix= qgisVersionParts.at ( 2 ).toInt ();
181+
182+ // first check major version
183+ if (minVerMajor > qgisMajor) return false ;
184+ if (minVerMajor < qgisMajor) return true ;
185+
186+ // if same, check minor version
187+ if (minVerMinor > qgisMinor) return false ;
188+ if (minVerMinor < qgisMinor) return true ;
189+
190+ // if still same, check bugfix version
191+ if (minVerBugfix > qgisBugfix) return false ;
192+
193+ // looks like min version is the same as our version - that's fine
194+ return true ;
195+ }
196+
155197
156198void QgsPluginRegistry::loadPythonPlugin ( QString packageName )
157199{
@@ -160,22 +202,30 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )
160202 QgsDebugMsg ( " Python is not enabled in QGIS." );
161203 return ;
162204 }
205+
206+ QSettings settings;
163207
164208 // is loaded already?
165209 if ( ! isLoaded ( packageName ) )
166210 {
211+ // if plugin is not compatible, disable it
212+ if ( ! isPythonPluginCompatible ( packageName ) )
213+ {
214+ settings.setValue ( " /PythonPlugins/" + packageName, false );
215+ return ;
216+ }
217+
167218 mPythonUtils ->loadPlugin ( packageName );
168219 mPythonUtils ->startPlugin ( packageName );
169220
170221 // TODO: test success
171-
222+
172223 QString pluginName = mPythonUtils ->getPluginMetadata ( packageName, " name" );
173224
174225 // add to plugin registry
175226 addPlugin ( packageName, QgsPluginMetadata ( packageName, pluginName, NULL , true ) );
176227
177228 // add to settings
178- QSettings settings;
179229 settings.setValue ( " /PythonPlugins/" + packageName, true );
180230 std::cout << " Loaded : " << pluginName.toLocal8Bit ().constData () << " (package: "
181231 << packageName.toLocal8Bit ().constData () << " )" << std::endl; // OK
@@ -364,3 +414,17 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
364414
365415 return true ;
366416}
417+
418+ bool QgsPluginRegistry::isPythonPluginCompatible ( QString packageName )
419+ {
420+ QString minVersion = mPythonUtils ->getPluginMetadata ( packageName, " qgisMinimumVersion" );
421+ if (minVersion == " __error__" || !checkQgisVersion (minVersion))
422+ {
423+ // QMessageBox::information(mQgisInterface->mainWindow(),
424+ // QObject::tr("Incompatible plugin"),
425+ // QObject::tr("Plugin \"%1\" is not compatible with this version of Quantum GIS.\nIt will be disabled.").arg(pluginName));
426+ // settings.setValue( "/PythonPlugins/" + packageName, false );
427+ return false ;
428+ }
429+ return true ;
430+ }
0 commit comments