Skip to content
Permalink
Browse files
[Plugin Manager] Fix inconsistent behaviour in --noplugins mode: don'…
…t try to load plugins, just enable/disable them in QSettings.
  • Loading branch information
borysiasty committed Jun 27, 2013
1 parent fa9b215 commit 52bb2c0d285824d14fbe6fa9a087cbc5e6bae926
Showing with 59 additions and 20 deletions.
  1. +46 −12 src/app/pluginmanager/qgspluginmanager.cpp
  2. +10 −4 src/app/pluginmanager/qgspluginmanager.h
  3. +1 −1 src/app/qgisapp.cpp
  4. +2 −3 src/app/qgspluginregistry.cpp
@@ -52,7 +52,7 @@
#endif


QgsPluginManager::QgsPluginManager( QWidget * parent, Qt::WFlags fl )
QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt::WFlags fl )
: QgsOptionsDialogBase( "PluginManager", parent, fl )
{
// initialize pointer
@@ -75,6 +75,9 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, Qt::WFlags fl )
// load translated description strings from qgspluginmanager_texts
initTabDescriptions();

// set internal variable
mPluginsAreEnabled = pluginsAreEnabled;

// Init models
mModelPlugins = new QStandardItemModel( 0, 1 );
mModelProxy = new QgsPluginSortFilterProxyModel( this );
@@ -248,6 +251,31 @@ void QgsPluginManager::unloadPlugin( QString id )



void QgsPluginManager::savePluginState( QString id, bool state )
{
const QMap<QString, QString>* plugin = pluginMetadata( id );
if ( ! plugin )
{
return;
}

QSettings settings;
if ( plugin->value( "pythonic" ) == "true" )
{
// Python plugin
settings.setValue( "/PythonPlugins/" + id, state );
}
else
{
// C++ plugin
// Trim "cpp:" prefix from cpp plugin id
id = id.mid( 4 );
settings.setValue( "/Plugins/" + id, state );
}
}



void QgsPluginManager::getCppPluginsMetadata()
{
QString sharedLibExtension;
@@ -493,7 +521,7 @@ void QgsPluginManager::reloadModelData()
mypDetailItem->setCheckState( Qt::Unchecked );
}

if ( isPluginLoaded( it->value( "id" ) ) )
if ( isPluginEnabled( it->value( "id" ) ) )
{
mypDetailItem->setCheckState( Qt::Checked );
}
@@ -535,10 +563,20 @@ void QgsPluginManager::reloadModelData()
void QgsPluginManager::pluginItemChanged( QStandardItem * item )
{
QString id = item->data( PLUGIN_BASE_NAME_ROLE ).toString();
if ( item->checkState() && ! isPluginLoaded( id ) )

if ( item->checkState() )
{
QgsDebugMsg( " Loading plugin: " + id );
loadPlugin( id );
if ( mPluginsAreEnabled && ! isPluginEnabled( id ))
{
QgsDebugMsg( " Loading plugin: " + id );
loadPlugin( id );
}
else
{
// only enable the plugin, as we're in --noplugins mode
QgsDebugMsg( " Enabling plugin: " + id );
savePluginState( id, true );
}
}
else if ( ! item->checkState() )
{
@@ -1194,7 +1232,7 @@ void QgsPluginManager::on_ckbExperimental_toggled( bool state )
// PRIVATE METHODS ///////////////////////////////////////////////////////////////////


bool QgsPluginManager::isPluginLoaded( QString key )
bool QgsPluginManager::isPluginEnabled( QString key )
{
const QMap<QString, QString>* plugin = pluginMetadata( key );
if ( plugin->isEmpty() )
@@ -1203,19 +1241,15 @@ bool QgsPluginManager::isPluginLoaded( QString key )
return false;
}

QSettings mySettings;
if ( plugin->value( "pythonic" ) != "true" )
{
// For C++ plugins, just check in the QgsPluginRegistry. If the plugin is broken, it was disabled quietly.
// Trim "cpp:" prefix from cpp plugin id
key = key.mid( 4 );
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
return pRegistry->isLoaded( key );
return ( mySettings.value( "/Plugins/" + key, QVariant( false ) ).toBool() );
}
else
{
// For Python plugins, check in QSettings if enabled rather than checking in QgsPluginRegistry if loaded.
// This will allow to turn off the plugin if broken.
QSettings mySettings;
return ( plugin->value( "installed" ) == "true" && mySettings.value( "/PythonPlugins/" + key, QVariant( false ) ).toBool() );
}
}
@@ -38,8 +38,8 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
{
Q_OBJECT
public:
//! Constructor
QgsPluginManager( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
//! Constructor; set pluginsAreEnabled to false in --noplugins mode
QgsPluginManager( QWidget *parent = 0, bool pluginsAreEnabled = true, Qt::WFlags fl = QgisGui::ModalDialogFlags );

//! Destructor
~QgsPluginManager();
@@ -53,6 +53,9 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! Unload unselected plugin
void unloadPlugin( QString id );

//! Save plugin enabled/disabled state to QSettings
void savePluginState( QString id, bool state );

//! Get metadata of C++ plugins
void getCppPluginsMetadata();

@@ -167,8 +170,8 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! Load translated descriptions. Source strings implemented in external qgspluginmanager_texts.cpp
void initTabDescriptions();

//! Return true if given plugin is present in QgsPluginRegistry (c++ plugins) or is enabled in QSettings (Python plugins)
bool isPluginLoaded( QString key );
//! Return true if given plugin is enabled in QSettings
bool isPluginEnabled( QString key );

//! Return true if there are plugins available for download in the metadata registry
bool hasAvailablePlugins( );
@@ -194,6 +197,9 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag

QgsPythonUtils* mPythonUtils;

//! true by default; false in --noplugins mode
bool mPluginsAreEnabled;

QMap<QString, QString> mTabDescriptions;

QMap< QString, QMap< QString, QString > > mPlugins;
@@ -528,7 +528,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
activateDeactivateLayerRelatedActions( NULL );

// initialize the plugin manager
mPluginManager = new QgsPluginManager( this );
mPluginManager = new QgsPluginManager( this, restorePlugins );

addDockWidget( Qt::LeftDockWidgetArea, mUndoWidget );
mUndoWidget->hide();
@@ -428,17 +428,16 @@ void QgsPluginRegistry::unloadPythonPlugin( QString packageName )

void QgsPluginRegistry::unloadCppPlugin( QString theFullPathName )
{
QSettings settings;
QString baseName = QFileInfo( theFullPathName ).baseName();
// first check to see if it's loaded
settings.setValue( "/Plugins/" + baseName, false );
if ( isLoaded( baseName ) )
{
QgisPlugin * pluginInstance = plugin( baseName );
if ( pluginInstance )
{
pluginInstance->unload();
}
QSettings settings;
settings.setValue( "/Plugins/" + baseName, false );
// remove the plugin from the registry
removePlugin( baseName );
QgsDebugMsg( "Cpp plugin successfully unloaded: " + baseName );

0 comments on commit 52bb2c0

Please sign in to comment.