diff --git a/libnotificationmanager/jobsmodel_p.h b/libnotificationmanager/jobsmodel_p.h --- a/libnotificationmanager/jobsmodel_p.h +++ b/libnotificationmanager/jobsmodel_p.h @@ -80,6 +80,7 @@ QVector m_jobViews; private: + void unwatchJob(Job *job); void onServiceUnregistered(const QString &serviceName); void updateApplicationPercentage(const QString &desktopEntry); diff --git a/libnotificationmanager/jobsmodel_p.cpp b/libnotificationmanager/jobsmodel_p.cpp --- a/libnotificationmanager/jobsmodel_p.cpp +++ b/libnotificationmanager/jobsmodel_p.cpp @@ -288,6 +288,7 @@ scheduleUpdate(job, Notifications::ClosableRole); if (job->state() == Notifications::JobStateStopped) { + unwatchJob(job); updateApplicationPercentage(job->desktopEntry()); emitJobUrlsChanged(); } @@ -374,14 +375,7 @@ const QString desktopEntry = jobToBeRemoved->desktopEntry(); - const QString serviceName = m_jobServices.take(jobToBeRemoved); - // Check if there's any jobs left for this service, otherwise stop watching it - auto it = std::find_if(m_jobServices.constBegin(), m_jobServices.constEnd(), [&serviceName](const QString &item) { - return item == serviceName; - }); - if (it == m_jobServices.constEnd()) { - m_serviceWatcher->removeWatchedService(serviceName); - } + unwatchJob(jobToBeRemoved); delete jobToBeRemoved; if (activeRow > -1) { @@ -440,12 +434,22 @@ QDBusConnection::sessionBus().send(message); } +void JobsModelPrivate::unwatchJob(Job *job) +{ + const QString serviceName = m_jobServices.take(job); + // Check if there's any jobs left for this service, otherwise stop watching it + auto it = std::find_if(m_jobServices.constBegin(), m_jobServices.constEnd(), [&serviceName](const QString &item) { + return item == serviceName; + }); + if (it == m_jobServices.constEnd()) { + m_serviceWatcher->removeWatchedService(serviceName); + } +} + void JobsModelPrivate::onServiceUnregistered(const QString &serviceName) { qCDebug(NOTIFICATIONMANAGER) << "JobView service unregistered" << serviceName; - m_serviceWatcher->removeWatchedService(serviceName); - const QList jobs = m_jobServices.keys(serviceName); for (Job *job : jobs) { // Mark all non-finished jobs as failed @@ -456,6 +460,8 @@ job->setErrorText(i18n("Application closed unexpectedly.")); job->setState(Notifications::JobStateStopped); } + + Q_ASSERT(!m_serviceWatcher->watchedServices().contains(serviceName)); } void JobsModelPrivate::scheduleUpdate(Job *job, Notifications::Roles role)