@@ -152,6 +152,48 @@ void QgsPluginRegistry::unloadAll()
152
152
}
153
153
154
154
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
+
155
197
156
198
void QgsPluginRegistry::loadPythonPlugin ( QString packageName )
157
199
{
@@ -160,22 +202,30 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )
160
202
QgsDebugMsg ( " Python is not enabled in QGIS." );
161
203
return ;
162
204
}
205
+
206
+ QSettings settings;
163
207
164
208
// is loaded already?
165
209
if ( ! isLoaded ( packageName ) )
166
210
{
211
+ // if plugin is not compatible, disable it
212
+ if ( ! isPythonPluginCompatible ( packageName ) )
213
+ {
214
+ settings.setValue ( " /PythonPlugins/" + packageName, false );
215
+ return ;
216
+ }
217
+
167
218
mPythonUtils ->loadPlugin ( packageName );
168
219
mPythonUtils ->startPlugin ( packageName );
169
220
170
221
// TODO: test success
171
-
222
+
172
223
QString pluginName = mPythonUtils ->getPluginMetadata ( packageName, " name" );
173
224
174
225
// add to plugin registry
175
226
addPlugin ( packageName, QgsPluginMetadata ( packageName, pluginName, NULL , true ) );
176
227
177
228
// add to settings
178
- QSettings settings;
179
229
settings.setValue ( " /PythonPlugins/" + packageName, true );
180
230
std::cout << " Loaded : " << pluginName.toLocal8Bit ().constData () << " (package: "
181
231
<< packageName.toLocal8Bit ().constData () << " )" << std::endl; // OK
@@ -364,3 +414,17 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
364
414
365
415
return true ;
366
416
}
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