Skip to content

Commit 150b373

Browse files
committedMay 21, 2020
Improve plugin watchdog message and UX
- Reword the message to clarify that it previously crashed QGIS, not necessarily on the last session. Also make the message shorter to fit into normal messagebar width - Add "Enable Plugin" button to the message, which clears the watchdog status for the plugin and immediately reloads it - Add "Ignore" button, which stops the message showing on subsequent startups. Otherwise the only way to clear this message is to manually go to plugin manager and enable/disable the plugin
1 parent 5cc0f09 commit 150b373

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed
 

‎src/app/qgspluginregistry.cpp

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgslogger.h"
3333
#include "qgsmessagelog.h"
3434
#include "qgsmessagebar.h"
35+
#include "qgsmessagebaritem.h"
3536
#include "qgsruntimeprofiler.h"
3637

3738
#ifdef WITH_BINDINGS
@@ -509,7 +510,40 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString &pluginDirString )
509510
QString baseName = QFileInfo( myFullPath ).baseName();
510511
if ( mySettings.value( QStringLiteral( "Plugins/watchDog/%1" ).arg( baseName ) ).isValid() )
511512
{
512-
mQgisInterface->messageBar()->pushWarning( QObject::tr( "Plugin %1" ).arg( baseName ), QObject::tr( "The plugin will be disabled because it crashed QGIS during last startup. Please report an issue and re-enable the plugin when the problem has been solved." ) );
513+
QToolButton *btnEnablePlugin = new QToolButton();
514+
btnEnablePlugin ->setText( QObject::tr( "Enable Plugin" ) );
515+
btnEnablePlugin ->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
516+
517+
QToolButton *btnIgnore = new QToolButton();
518+
btnIgnore->setText( QObject::tr( "Ignore" ) );
519+
btnIgnore->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
520+
521+
QgsMessageBarItem *watchdogMsg = new QgsMessageBarItem(
522+
QObject::tr( "Plugin %1" ).arg( baseName ),
523+
QObject::tr( "This plugin is disabled because it previously crashed QGIS." ),
524+
btnEnablePlugin,
525+
Qgis::Warning,
526+
0,
527+
mQgisInterface->messageBar() );
528+
watchdogMsg->layout()->addWidget( btnIgnore );
529+
530+
QObject::connect( btnEnablePlugin, &QToolButton::clicked, mQgisInterface->messageBar(), [ = ]()
531+
{
532+
QgsSettings settings;
533+
settings.setValue( "/Plugins/" + baseName, true );
534+
loadCppPlugin( myFullPath );
535+
settings.remove( QStringLiteral( "/Plugins/watchDog/%1" ).arg( baseName ) );
536+
mQgisInterface->messageBar()->popWidget( watchdogMsg );
537+
} );
538+
QObject::connect( btnIgnore, &QToolButton::clicked, mQgisInterface->messageBar(), [ = ]()
539+
{
540+
QgsSettings settings;
541+
settings.setValue( "/Plugins/" + baseName, false );
542+
settings.remove( "/Plugins/watchDog/" + baseName );
543+
mQgisInterface->messageBar()->popWidget( watchdogMsg );
544+
} );
545+
546+
mQgisInterface->messageBar()->pushItem( watchdogMsg );
513547
mySettings.setValue( "/Plugins/" + baseName, false );
514548
}
515549
if ( mySettings.value( "/Plugins/" + baseName ).toBool() )
@@ -565,7 +599,46 @@ void QgsPluginRegistry::restoreSessionPlugins( const QString &pluginDirString )
565599

566600
if ( mySettings.value( "/PythonPlugins/watchDog/" + packageName ).isValid() )
567601
{
568-
mQgisInterface->messageBar()->pushWarning( QObject::tr( "Plugin %1" ).arg( packageName ), QObject::tr( "The plugin will be disabled because it crashed QGIS during last startup. Please report an issue and re-enable the plugin when the problem has been solved." ) );
602+
QToolButton *btnEnablePlugin = new QToolButton();
603+
btnEnablePlugin->setText( QObject::tr( "Enable Plugin" ) );
604+
btnEnablePlugin->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
605+
606+
QToolButton *btnIgnore = new QToolButton();
607+
btnIgnore->setText( QObject::tr( "Ignore" ) );
608+
btnIgnore->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
609+
610+
QgsMessageBarItem *watchdogMsg = new QgsMessageBarItem(
611+
QObject::tr( "Plugin %1" ).arg( packageName ),
612+
QObject::tr( "This plugin is disabled because it previously crashed QGIS." ),
613+
btnEnablePlugin,
614+
Qgis::Warning,
615+
0,
616+
mQgisInterface->messageBar() );
617+
watchdogMsg->layout()->addWidget( btnIgnore );
618+
619+
QObject::connect( btnEnablePlugin, &QToolButton::clicked, mQgisInterface->messageBar(), [ = ]()
620+
{
621+
QgsSettings settings;
622+
settings.setValue( "/PythonPlugins/" + packageName, true );
623+
if ( checkPythonPlugin( packageName ) )
624+
{
625+
loadPythonPlugin( packageName );
626+
}
627+
settings.remove( "/PythonPlugins/watchDog/" + packageName );
628+
629+
mQgisInterface->messageBar()->popWidget( watchdogMsg );
630+
} );
631+
632+
QObject::connect( btnIgnore, &QToolButton::clicked, mQgisInterface->messageBar(), [ = ]()
633+
{
634+
QgsSettings settings;
635+
settings.setValue( "/PythonPlugins/" + packageName, false );
636+
settings.remove( "/PythonPlugins/watchDog/" + packageName );
637+
mQgisInterface->messageBar()->popWidget( watchdogMsg );
638+
} );
639+
640+
mQgisInterface->messageBar()->pushItem( watchdogMsg );
641+
569642
mySettings.setValue( "/PythonPlugins/" + packageName, false );
570643
}
571644
// check if the plugin was active on last session

0 commit comments

Comments
 (0)
Please sign in to comment.