Skip to content

Commit 62c4b42

Browse files
author
borysiasty
committed
[FEATURE] Applied patch #2541 - initial implementing the canBeUninstalled python plugin method
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13050 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3f77549 commit 62c4b42

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

python/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,22 @@ def startPlugin(packageName):
161161
return True
162162

163163

164+
def canUninstallPlugin(packageName):
165+
""" confirm that the plugin can be uninstalled """
166+
global plugins, active_plugins
167+
168+
if not plugins.has_key(packageName): return False
169+
if packageName not in active_plugins: return False
170+
171+
try:
172+
metadata = plugins[packageName]
173+
if "canBeUninstalled" not in dir(metadata):
174+
return True
175+
return bool(metadata.canBeUninstalled())
176+
except:
177+
return False
178+
179+
164180
def unloadPlugin(packageName):
165181
""" unload and delete plugin! """
166182
global plugins, active_plugins

src/app/qgspluginmanager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,12 @@ void QgsPluginManager::unload()
407407
{
408408
if ( mPythonUtils && mPythonUtils->isEnabled() )
409409
{
410-
mPythonUtils->unloadPlugin( baseName );
411-
//disable it to the qsettings file
412-
settings.setValue( "/PythonPlugins/" + baseName, false );
410+
if( mPythonUtils->canUninstallPlugin( baseName ) )
411+
{
412+
mPythonUtils->unloadPlugin( baseName );
413+
//disable it to the qsettings file
414+
settings.setValue( "/PythonPlugins/" + baseName, false );
415+
}
413416
}
414417
}
415418
else // C++ plugin

src/python/qgspythonutils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class PYTHON_EXPORT QgsPythonUtils
8181
//! @param function one of these strings: name, tpye, version, description
8282
virtual QString getPluginMetadata( QString pluginName, QString function ) = 0;
8383

84+
//! confirm that the plugin can be uninstalled
85+
virtual bool canUninstallPlugin( QString packageName ) = 0;
86+
8487
//! unload plugin
8588
virtual bool unloadPlugin( QString packageName ) = 0;
8689
};

src/python/qgspythonutilsimpl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,22 +406,26 @@ QString QgsPythonUtilsImpl::getPluginMetadata( QString pluginName, QString funct
406406
return res;
407407
}
408408

409-
410409
bool QgsPythonUtilsImpl::loadPlugin( QString packageName )
411410
{
412411
QString output;
413412
evalString( "qgis.utils.loadPlugin('" + packageName + "')", output );
414413
return ( output == "True" );
415414
}
416415

417-
418416
bool QgsPythonUtilsImpl::startPlugin( QString packageName )
419417
{
420418
QString output;
421419
evalString( "qgis.utils.startPlugin('" + packageName + "')", output );
422420
return ( output == "True" );
423421
}
424422

423+
bool QgsPythonUtilsImpl::canUninstallPlugin( QString packageName )
424+
{
425+
QString output;
426+
evalString( "qgis.utils.canUninstallPlugin('" + packageName + "')", output );
427+
return ( output == "True" );
428+
}
425429

426430
bool QgsPythonUtilsImpl::unloadPlugin( QString packageName )
427431
{

src/python/qgspythonutilsimpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
9898
//! @param function one of these strings: name, tpye, version, description
9999
QString getPluginMetadata( QString pluginName, QString function );
100100

101+
//! confirm it is safe to uninstall the plugin
102+
bool canUninstallPlugin( QString packageName );
103+
101104
//! unload plugin
102105
bool unloadPlugin( QString packageName );
103106

0 commit comments

Comments
 (0)