Commit 0fee3a43 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Notifications] Unwatch job when it gets stopped

We watch the service owner so that when it dies without finishing the job we communicate an error to the user.
When the job is stopped, the job is "done" and we don't need to watch the service anymore.

Differential Revision: https://phabricator.kde.org/D21366
parent 5b63edb8
......@@ -288,6 +288,7 @@ QDBusObjectPath JobsModelPrivate::requestView(const QString &desktopEntry,
scheduleUpdate(job, Notifications::ClosableRole);
if (job->state() == Notifications::JobStateStopped) {
unwatchJob(job);
updateApplicationPercentage(job->desktopEntry());
emitJobUrlsChanged();
}
......@@ -374,14 +375,7 @@ void JobsModelPrivate::remove(Job *job)
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 @@ void JobsModelPrivate::updateApplicationPercentage(const QString &desktopEntry)
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<Job *> jobs = m_jobServices.keys(serviceName);
for (Job *job : jobs) {
// Mark all non-finished jobs as failed
......@@ -456,6 +460,8 @@ void JobsModelPrivate::onServiceUnregistered(const QString &serviceName)
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)
......
......@@ -80,6 +80,7 @@ public: // stuff used by public class
QVector<Job *> m_jobViews;
private:
void unwatchJob(Job *job);
void onServiceUnregistered(const QString &serviceName);
void updateApplicationPercentage(const QString &desktopEntry);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment