Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/jobsmodel_p.cpp
Show First 20 Lines • Show All 282 Lines • ▼ Show 20 Line(s) | 236 | { | |||
---|---|---|---|---|---|
283 | }); | 283 | }); | ||
284 | connect(job, &Job::stateChanged, this, [this, job] { | 284 | connect(job, &Job::stateChanged, this, [this, job] { | ||
285 | scheduleUpdate(job, Notifications::JobStateRole); | 285 | scheduleUpdate(job, Notifications::JobStateRole); | ||
286 | // Timeout and Closable depend on state, signal a change for those, too | 286 | // Timeout and Closable depend on state, signal a change for those, too | ||
287 | scheduleUpdate(job, Notifications::TimeoutRole); | 287 | scheduleUpdate(job, Notifications::TimeoutRole); | ||
288 | scheduleUpdate(job, Notifications::ClosableRole); | 288 | scheduleUpdate(job, Notifications::ClosableRole); | ||
289 | 289 | | |||
290 | if (job->state() == Notifications::JobStateStopped) { | 290 | if (job->state() == Notifications::JobStateStopped) { | ||
291 | unwatchJob(job); | ||||
291 | updateApplicationPercentage(job->desktopEntry()); | 292 | updateApplicationPercentage(job->desktopEntry()); | ||
292 | emitJobUrlsChanged(); | 293 | emitJobUrlsChanged(); | ||
293 | } | 294 | } | ||
294 | }); | 295 | }); | ||
295 | connect(job, &Job::percentageChanged, this, [this, job] { | 296 | connect(job, &Job::percentageChanged, this, [this, job] { | ||
296 | scheduleUpdate(job, Notifications::PercentageRole); | 297 | scheduleUpdate(job, Notifications::PercentageRole); | ||
297 | }); | 298 | }); | ||
298 | connect(job, &Job::errorChanged, this, [this, job] { | 299 | connect(job, &Job::errorChanged, this, [this, job] { | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 369 | } else if (pendingRow > -1) { | |||
369 | jobToBeRemoved = m_pendingJobViews.takeAt(pendingRow); | 370 | jobToBeRemoved = m_pendingJobViews.takeAt(pendingRow); | ||
370 | } | 371 | } | ||
371 | Q_ASSERT(jobToBeRemoved); | 372 | Q_ASSERT(jobToBeRemoved); | ||
372 | 373 | | |||
373 | m_pendingDirtyRoles.remove(jobToBeRemoved); | 374 | m_pendingDirtyRoles.remove(jobToBeRemoved); | ||
374 | 375 | | |||
375 | const QString desktopEntry = jobToBeRemoved->desktopEntry(); | 376 | const QString desktopEntry = jobToBeRemoved->desktopEntry(); | ||
376 | 377 | | |||
377 | const QString serviceName = m_jobServices.take(jobToBeRemoved); | 378 | unwatchJob(jobToBeRemoved); | ||
378 | // Check if there's any jobs left for this service, otherwise stop watching it | | |||
379 | auto it = std::find_if(m_jobServices.constBegin(), m_jobServices.constEnd(), [&serviceName](const QString &item) { | | |||
380 | return item == serviceName; | | |||
381 | }); | | |||
382 | if (it == m_jobServices.constEnd()) { | | |||
383 | m_serviceWatcher->removeWatchedService(serviceName); | | |||
384 | } | | |||
385 | 379 | | |||
386 | delete jobToBeRemoved; | 380 | delete jobToBeRemoved; | ||
387 | if (activeRow > -1) { | 381 | if (activeRow > -1) { | ||
388 | emit jobViewRemoved(activeRow); | 382 | emit jobViewRemoved(activeRow); | ||
389 | } | 383 | } | ||
390 | 384 | | |||
391 | updateApplicationPercentage(desktopEntry); | 385 | updateApplicationPercentage(desktopEntry); | ||
392 | } | 386 | } | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 397 | { | |||
435 | 429 | | |||
436 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/org/kde/notificationmanager/jobs"), | 430 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/org/kde/notificationmanager/jobs"), | ||
437 | QStringLiteral("com.canonical.Unity.LauncherEntry"), | 431 | QStringLiteral("com.canonical.Unity.LauncherEntry"), | ||
438 | QStringLiteral("Update")); | 432 | QStringLiteral("Update")); | ||
439 | message.setArguments({QStringLiteral("application://") + desktopEntry, properties}); | 433 | message.setArguments({QStringLiteral("application://") + desktopEntry, properties}); | ||
440 | QDBusConnection::sessionBus().send(message); | 434 | QDBusConnection::sessionBus().send(message); | ||
441 | } | 435 | } | ||
442 | 436 | | |||
437 | void JobsModelPrivate::unwatchJob(Job *job) | ||||
438 | { | ||||
439 | const QString serviceName = m_jobServices.take(job); | ||||
440 | // Check if there's any jobs left for this service, otherwise stop watching it | ||||
441 | auto it = std::find_if(m_jobServices.constBegin(), m_jobServices.constEnd(), [&serviceName](const QString &item) { | ||||
442 | return item == serviceName; | ||||
443 | }); | ||||
444 | if (it == m_jobServices.constEnd()) { | ||||
445 | m_serviceWatcher->removeWatchedService(serviceName); | ||||
446 | } | ||||
447 | } | ||||
448 | | ||||
443 | void JobsModelPrivate::onServiceUnregistered(const QString &serviceName) | 449 | void JobsModelPrivate::onServiceUnregistered(const QString &serviceName) | ||
444 | { | 450 | { | ||
445 | qCDebug(NOTIFICATIONMANAGER) << "JobView service unregistered" << serviceName; | 451 | qCDebug(NOTIFICATIONMANAGER) << "JobView service unregistered" << serviceName; | ||
446 | 452 | | |||
447 | m_serviceWatcher->removeWatchedService(serviceName); | | |||
448 | | ||||
449 | const QList<Job *> jobs = m_jobServices.keys(serviceName); | 453 | const QList<Job *> jobs = m_jobServices.keys(serviceName); | ||
450 | for (Job *job : jobs) { | 454 | for (Job *job : jobs) { | ||
451 | // Mark all non-finished jobs as failed | 455 | // Mark all non-finished jobs as failed | ||
452 | if (job->state() == Notifications::JobStateStopped) { | 456 | if (job->state() == Notifications::JobStateStopped) { | ||
453 | continue; | 457 | continue; | ||
454 | } | 458 | } | ||
455 | job->setError(KIO::ERR_OWNER_DIED); | 459 | job->setError(KIO::ERR_OWNER_DIED); | ||
456 | job->setErrorText(i18n("Application closed unexpectedly.")); | 460 | job->setErrorText(i18n("Application closed unexpectedly.")); | ||
457 | job->setState(Notifications::JobStateStopped); | 461 | job->setState(Notifications::JobStateStopped); | ||
458 | } | 462 | } | ||
463 | | ||||
464 | Q_ASSERT(!m_serviceWatcher->watchedServices().contains(serviceName)); | ||||
459 | } | 465 | } | ||
460 | 466 | | |||
461 | void JobsModelPrivate::scheduleUpdate(Job *job, Notifications::Roles role) | 467 | void JobsModelPrivate::scheduleUpdate(Job *job, Notifications::Roles role) | ||
462 | { | 468 | { | ||
463 | m_pendingDirtyRoles[job].append(role); | 469 | m_pendingDirtyRoles[job].append(role); | ||
464 | m_compressUpdatesTimer->start(); | 470 | m_compressUpdatesTimer->start(); | ||
465 | } | 471 | } |