Skip to content

Commit

Permalink
Add API to determine if a plugin is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 28, 2019
1 parent 86517c8 commit 388d605
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/python/qgspythonutils.h
Expand Up @@ -120,11 +120,19 @@ class PYTHON_EXPORT QgsPythonUtils
/**
* Returns TRUE if the plugin with matching name is loaded (active).
*
* \see isPluginEnabled()
* \see listActivePlugins()
* \see loadPlugin()
*/
virtual bool isPluginLoaded( const QString &packageName ) = 0;

/**
* Returns TRUE if the plugin is user enabled (i.e. installed and checked in the user's plugin configuration)
*
* \see isPluginLoaded()
*/
virtual bool isPluginEnabled( const QString &packageName ) const = 0;

/**
* Returns a list of active (loaded) plugins.
*
Expand Down Expand Up @@ -173,6 +181,7 @@ class PYTHON_EXPORT QgsPythonUtils
* Returns TRUE if the plugin was successfully unloaded.
*/
virtual bool unloadPlugin( const QString &packageName ) = 0;

};

#endif
6 changes: 6 additions & 0 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmessageoutput.h"
#include "qgssettings.h"

#include <QStringList>
#include <QDir>
Expand Down Expand Up @@ -635,6 +636,11 @@ bool QgsPythonUtilsImpl::unloadPlugin( const QString &packageName )
return ( output == QLatin1String( "True" ) );
}

bool QgsPythonUtilsImpl::isPluginEnabled( const QString &packageName ) const
{
return QgsSettings().value( "/PythonPlugins/" + packageName, QVariant( false ) ).toBool();
}

bool QgsPythonUtilsImpl::isPluginLoaded( const QString &packageName )
{
QString output;
Expand Down
1 change: 1 addition & 0 deletions src/python/qgspythonutilsimpl.h
Expand Up @@ -88,6 +88,7 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
QString getPluginMetadata( const QString &pluginName, const QString &function ) override;
bool canUninstallPlugin( const QString &packageName ) override;
bool unloadPlugin( const QString &packageName ) override;
bool isPluginEnabled( const QString &packageName ) const override;

protected:

Expand Down

0 comments on commit 388d605

Please sign in to comment.