Add an optional "Silent" flag for QgsTask, which hides the operating

system level success/fail notifications for that task
This commit is contained in:
Nyall Dawson 2022-04-11 11:00:02 +10:00
parent 4c3502bee2
commit 11d52c2cdb
3 changed files with 7 additions and 1 deletions

View File

@ -49,6 +49,7 @@ clean up and terminate at the earliest possible convenience.
CanCancel,
CancelWithoutPrompt,
Hidden,
Silent,
AllFlags,
};
typedef QFlags<QgsTask::Flag> Flags;

View File

@ -16417,7 +16417,11 @@ void QgisApp::onTaskCompleteShowNotify( long taskId, int status )
{
long long minTime = QgsSettings().value( QStringLiteral( "minTaskLengthForSystemNotification" ), 5, QgsSettings::App ).toLongLong() * 1000;
QgsTask *task = QgsApplication::taskManager()->task( taskId );
if ( task && !( task->flags() & QgsTask::Flag::Hidden ) && task->elapsedTime() >= minTime )
if ( task
&& !(
( task->flags() & QgsTask::Hidden )
|| ( task->flags() & QgsTask::Silent ) )
&& task->elapsedTime() >= minTime )
{
if ( status == QgsTask::Complete )
showSystemNotification( tr( "Task complete" ), task->description() );

View File

@ -74,6 +74,7 @@ class CORE_EXPORT QgsTask : public QObject
CanCancel = 1 << 1, //!< Task can be canceled
CancelWithoutPrompt = 1 << 2, //!< Task can be canceled without any users prompts, e.g. when closing a project or QGIS.
Hidden = 1 << 3, //!< Hide task from GUI (since QGIS 3.26)
Silent = 1 << 4, //!< Don't show task updates (such as completion/failure messages) as operating-system level notifications (since QGIS 3.26)
AllFlags = CanCancel, //!< Task supports all flags
};
Q_DECLARE_FLAGS( Flags, Flag )