From 86597ad03b0a50fce144250a503ed02f42050d75 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Wed, 17 Nov 2021 13:05:05 +0100 Subject: [PATCH] [Jobs] Support "transient" flag for job This is for jobs, such as "Loading archive" or "Examining..." which are purely informational and provide no meaningful action once finished. When this property is set, a job will not show a "Finished" notification when finished successfully. --- libnotificationmanager/job.cpp | 10 ++++++++++ libnotificationmanager/job.h | 3 +++ libnotificationmanager/job_p.cpp | 4 ++-- libnotificationmanager/job_p.h | 1 + libnotificationmanager/jobsmodel_p.cpp | 4 ++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libnotificationmanager/job.cpp b/libnotificationmanager/job.cpp index 88018d7fe..194538913 100644 --- a/libnotificationmanager/job.cpp +++ b/libnotificationmanager/job.cpp @@ -159,6 +159,16 @@ void Job::setKillable(bool killable) d->m_killable = killable; } +bool Job::transient() const +{ + return d->m_transient; +} + +void Job::setTransient(bool transient) +{ + d->m_transient = transient; +} + QUrl Job::destUrl() const { return d->m_destUrl; diff --git a/libnotificationmanager/job.h b/libnotificationmanager/job.h index 8e44c5e84..7e5437c17 100644 --- a/libnotificationmanager/job.h +++ b/libnotificationmanager/job.h @@ -167,6 +167,9 @@ public: // TODO remove and let only constructor do it? void setKillable(bool killable); + bool transient() const; + void setTransient(bool transient); + QUrl destUrl() const; qulonglong speed() const; diff --git a/libnotificationmanager/job_p.cpp b/libnotificationmanager/job_p.cpp index 9dbb86c0f..fd4b3bbe4 100644 --- a/libnotificationmanager/job_p.cpp +++ b/libnotificationmanager/job_p.cpp @@ -264,8 +264,8 @@ void JobPrivate::finish() // Unregister the dbus service since the client is done with it QDBusConnection::sessionBus().unregisterObject(m_objectPath.path()); - // When user canceled transfer, remove it without notice - if (m_error == KIO::ERR_USER_CANCELED) { + // When user canceled job or a transient job finished successfully, remove it without notice + if (m_error == KIO::ERR_USER_CANCELED || (!m_error && m_transient)) { emit closed(); return; } diff --git a/libnotificationmanager/job_p.h b/libnotificationmanager/job_p.h index d549d1b91..f8e8c685e 100644 --- a/libnotificationmanager/job_p.h +++ b/libnotificationmanager/job_p.h @@ -141,6 +141,7 @@ private: QString m_errorText; bool m_suspendable = false; bool m_killable = false; + bool m_transient = false; QUrl m_destUrl; diff --git a/libnotificationmanager/jobsmodel_p.cpp b/libnotificationmanager/jobsmodel_p.cpp index e27db3d70..34688bafd 100644 --- a/libnotificationmanager/jobsmodel_p.cpp +++ b/libnotificationmanager/jobsmodel_p.cpp @@ -312,6 +312,10 @@ QDBusObjectPath JobsModelPrivate::requestView(const QString &desktopEntry, int c job->d->delayedShow(500ms, JobPrivate::ShowCondition::OnTimeout); } + if (hints.value(QStringLiteral("transient")).toBool()) { + job->setTransient(true); + } + m_jobServices.insert(job, serviceName); m_serviceWatcher->addWatchedService(serviceName);