Skip to content

Commit 52bb2c0

Browse files
committed
[Plugin Manager] Fix inconsistent behaviour in --noplugins mode: don't try to load plugins, just enable/disable them in QSettings.
1 parent fa9b215 commit 52bb2c0

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

src/app/pluginmanager/qgspluginmanager.cpp

+46-12
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#endif
5353

5454

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

78+
// set internal variable
79+
mPluginsAreEnabled = pluginsAreEnabled;
80+
7881
// Init models
7982
mModelPlugins = new QStandardItemModel( 0, 1 );
8083
mModelProxy = new QgsPluginSortFilterProxyModel( this );
@@ -248,6 +251,31 @@ void QgsPluginManager::unloadPlugin( QString id )
248251

249252

250253

254+
void QgsPluginManager::savePluginState( QString id, bool state )
255+
{
256+
const QMap<QString, QString>* plugin = pluginMetadata( id );
257+
if ( ! plugin )
258+
{
259+
return;
260+
}
261+
262+
QSettings settings;
263+
if ( plugin->value( "pythonic" ) == "true" )
264+
{
265+
// Python plugin
266+
settings.setValue( "/PythonPlugins/" + id, state );
267+
}
268+
else
269+
{
270+
// C++ plugin
271+
// Trim "cpp:" prefix from cpp plugin id
272+
id = id.mid( 4 );
273+
settings.setValue( "/Plugins/" + id, state );
274+
}
275+
}
276+
277+
278+
251279
void QgsPluginManager::getCppPluginsMetadata()
252280
{
253281
QString sharedLibExtension;
@@ -493,7 +521,7 @@ void QgsPluginManager::reloadModelData()
493521
mypDetailItem->setCheckState( Qt::Unchecked );
494522
}
495523

496-
if ( isPluginLoaded( it->value( "id" ) ) )
524+
if ( isPluginEnabled( it->value( "id" ) ) )
497525
{
498526
mypDetailItem->setCheckState( Qt::Checked );
499527
}
@@ -535,10 +563,20 @@ void QgsPluginManager::reloadModelData()
535563
void QgsPluginManager::pluginItemChanged( QStandardItem * item )
536564
{
537565
QString id = item->data( PLUGIN_BASE_NAME_ROLE ).toString();
538-
if ( item->checkState() && ! isPluginLoaded( id ) )
566+
567+
if ( item->checkState() )
539568
{
540-
QgsDebugMsg( " Loading plugin: " + id );
541-
loadPlugin( id );
569+
if ( mPluginsAreEnabled && ! isPluginEnabled( id ))
570+
{
571+
QgsDebugMsg( " Loading plugin: " + id );
572+
loadPlugin( id );
573+
}
574+
else
575+
{
576+
// only enable the plugin, as we're in --noplugins mode
577+
QgsDebugMsg( " Enabling plugin: " + id );
578+
savePluginState( id, true );
579+
}
542580
}
543581
else if ( ! item->checkState() )
544582
{
@@ -1194,7 +1232,7 @@ void QgsPluginManager::on_ckbExperimental_toggled( bool state )
11941232
// PRIVATE METHODS ///////////////////////////////////////////////////////////////////
11951233

11961234

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

1244+
QSettings mySettings;
12061245
if ( plugin->value( "pythonic" ) != "true" )
12071246
{
1208-
// For C++ plugins, just check in the QgsPluginRegistry. If the plugin is broken, it was disabled quietly.
12091247
// Trim "cpp:" prefix from cpp plugin id
12101248
key = key.mid( 4 );
1211-
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
1212-
return pRegistry->isLoaded( key );
1249+
return ( mySettings.value( "/Plugins/" + key, QVariant( false ) ).toBool() );
12131250
}
12141251
else
12151252
{
1216-
// For Python plugins, check in QSettings if enabled rather than checking in QgsPluginRegistry if loaded.
1217-
// This will allow to turn off the plugin if broken.
1218-
QSettings mySettings;
12191253
return ( plugin->value( "installed" ) == "true" && mySettings.value( "/PythonPlugins/" + key, QVariant( false ) ).toBool() );
12201254
}
12211255
}

src/app/pluginmanager/qgspluginmanager.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
3838
{
3939
Q_OBJECT
4040
public:
41-
//! Constructor
42-
QgsPluginManager( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
41+
//! Constructor; set pluginsAreEnabled to false in --noplugins mode
42+
QgsPluginManager( QWidget *parent = 0, bool pluginsAreEnabled = true, Qt::WFlags fl = QgisGui::ModalDialogFlags );
4343

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

56+
//! Save plugin enabled/disabled state to QSettings
57+
void savePluginState( QString id, bool state );
58+
5659
//! Get metadata of C++ plugins
5760
void getCppPluginsMetadata();
5861

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

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

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

195198
QgsPythonUtils* mPythonUtils;
196199

200+
//! true by default; false in --noplugins mode
201+
bool mPluginsAreEnabled;
202+
197203
QMap<QString, QString> mTabDescriptions;
198204

199205
QMap< QString, QMap< QString, QString > > mPlugins;

src/app/qgisapp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
528528
activateDeactivateLayerRelatedActions( NULL );
529529

530530
// initialize the plugin manager
531-
mPluginManager = new QgsPluginManager( this );
531+
mPluginManager = new QgsPluginManager( this, restorePlugins );
532532

533533
addDockWidget( Qt::LeftDockWidgetArea, mUndoWidget );
534534
mUndoWidget->hide();

src/app/qgspluginregistry.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,16 @@ void QgsPluginRegistry::unloadPythonPlugin( QString packageName )
428428

429429
void QgsPluginRegistry::unloadCppPlugin( QString theFullPathName )
430430
{
431+
QSettings settings;
431432
QString baseName = QFileInfo( theFullPathName ).baseName();
432-
// first check to see if it's loaded
433+
settings.setValue( "/Plugins/" + baseName, false );
433434
if ( isLoaded( baseName ) )
434435
{
435436
QgisPlugin * pluginInstance = plugin( baseName );
436437
if ( pluginInstance )
437438
{
438439
pluginInstance->unload();
439440
}
440-
QSettings settings;
441-
settings.setValue( "/Plugins/" + baseName, false );
442441
// remove the plugin from the registry
443442
removePlugin( baseName );
444443
QgsDebugMsg( "Cpp plugin successfully unloaded: " + baseName );

0 commit comments

Comments
 (0)