From 320331ae36ad2c762e8730b6b9e62aa685068896 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 13 Mar 2015 20:22:06 +0100 Subject: [PATCH] Don't show error notifications for jobs cancelled by user Modify applicationjobs dataengine so that "error" value now contains job's error code and "errorText" error message. This depends on commit 812d0b440e7f08e3acdd1c9bb95779bd871b75b3 to kjobwidgets. REVIEW: 122928 --- .../package/contents/ui/JobDelegate.qml | 1 - .../package/contents/ui/Jobs.qml | 17 +++++++---------- .../applicationjobs/kuiserverengine.cpp | 7 ++++++- dataengines/applicationjobs/kuiserverengine.h | 1 + kuiserver/jobview.cpp | 19 ++++++++++++++++--- kuiserver/jobview.h | 9 +++++++-- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/applets/notifications/package/contents/ui/JobDelegate.qml b/applets/notifications/package/contents/ui/JobDelegate.qml index d77290d68..f3f091d7a 100644 --- a/applets/notifications/package/contents/ui/JobDelegate.qml +++ b/applets/notifications/package/contents/ui/JobDelegate.qml @@ -174,7 +174,6 @@ Column { visible: getData(jobsSource.data, "killable", 0) onClicked: { - cancelledJobs.push(modelData) // register that it was user-cancelled var service = jobsSource.serviceForSource(modelData) var operation = service.operationDescription("stop") service.startOperationCall(operation) diff --git a/applets/notifications/package/contents/ui/Jobs.qml b/applets/notifications/package/contents/ui/Jobs.qml index e8a47487e..d421c6428 100644 --- a/applets/notifications/package/contents/ui/Jobs.qml +++ b/applets/notifications/package/contents/ui/Jobs.qml @@ -30,8 +30,6 @@ Column { property alias count: jobsRepeater.count - property var cancelledJobs: [] - PlasmaCore.DataSource { id: jobsSource @@ -49,9 +47,11 @@ Column { return } - var cancelledJobPos = cancelledJobs.indexOf(source) - if (cancelledJobPos > -1) { - cancelledJobs.splice(cancelledJobPos, 1) + var error = runningJobs[source]["error"] + var errorText = runningJobs[source]["errorText"] + + // 1 = ERR_USER_CANCELED - don't show any notification at all + if (error == 1) { return } @@ -61,13 +61,10 @@ Column { return } - var errorText = runningJobs[source]["error"]; - var error = errorText != "" - var summary = infoMessage ? i18nc("the job, which can be anything, has finished", "%1: Finished", infoMessage) : i18n("Job Finished") + if (error) { summary = infoMessage ? i18nc("the job, which can be anything, finished with error", "%1: Error", infoMessage) : i18n("Job Error") - message = errorText } notifications.addNotification({ @@ -75,7 +72,7 @@ Column { appIcon: runningJobs[source]["appIconName"], appName: runningJobs[source]["appName"], summary: summary, - body: message, + body: errorText || message, isPersistent: true, expireTimeout: 6000, urgency: 0, diff --git a/dataengines/applicationjobs/kuiserverengine.cpp b/dataengines/applicationjobs/kuiserverengine.cpp index e0b2cedba..93ef2d60b 100644 --- a/dataengines/applicationjobs/kuiserverengine.cpp +++ b/dataengines/applicationjobs/kuiserverengine.cpp @@ -89,7 +89,7 @@ void JobView::timerEvent(QTimerEvent *event) void JobView::terminate(const QString &errorMessage) { - setData("error", errorMessage); + setData(QStringLiteral("errorText"), errorMessage); QTimer::singleShot(0, this, SLOT(finished())); } @@ -128,6 +128,11 @@ void JobView::setSuspended(bool suspended) } } +void JobView::setError(uint errorCode) +{ + setData(QStringLiteral("error"), errorCode); +} + int JobView::unitId(const QString &unit) { int id = 0; diff --git a/dataengines/applicationjobs/kuiserverengine.h b/dataengines/applicationjobs/kuiserverengine.h index c03b0700d..a104e2235 100644 --- a/dataengines/applicationjobs/kuiserverengine.h +++ b/dataengines/applicationjobs/kuiserverengine.h @@ -95,6 +95,7 @@ public: void setCapabilities(int capabilities); void setPercent(uint percent); void setSuspended(bool suspended); + void setError(uint errorCode); //vestigal, required to implement this dbus interface void setDestUrl(const QDBusVariant &destUrl); diff --git a/kuiserver/jobview.cpp b/kuiserver/jobview.cpp index 4c76c5a0f..9bc2698fa 100644 --- a/kuiserver/jobview.cpp +++ b/kuiserver/jobview.cpp @@ -33,6 +33,7 @@ JobView::JobView(uint jobId, QObject *parent) : QObject(parent), m_capabilities(-1), m_percent(-1), + m_error(KJob::NoError), m_totalAmount(0), m_processAmount(0), m_jobId(jobId), @@ -57,10 +58,11 @@ void JobView::terminate(const QString &errorMessage) typedef QPair iFacePair; foreach(const iFacePair &pair, m_objectPaths) { qCDebug(KUISERVER) << "making async call of terminate for: " << pair.first; + pair.second->asyncCall(QLatin1String("setError"), m_error); pair.second->asyncCall(QLatin1String("terminate"), errorMessage); } - m_error = errorMessage; + m_errorText = errorMessage; if (m_currentPendingCalls < 1) { // if hit it means a job exists for *something* but can't be terminated properly @@ -285,11 +287,21 @@ int JobView::capabilities() const return m_capabilities; } -QString JobView::error() const +void JobView::setError(uint errorCode) +{ + m_error = errorCode; +} + +uint JobView::error() const { return m_error; } +QString JobView::errorText() const +{ + return m_errorText; +} + uint JobView::jobId() const { return m_jobId; @@ -415,7 +427,8 @@ void JobView::pendingCallFinished(RequestViewCallWatcher* watcher) // forcibly set the percent (should be 100). Since the job missed out on that too. client->asyncCall(QLatin1String("setPercent"), m_percent); - client->asyncCall(QLatin1String("terminate"), m_error); + client->asyncCall(QLatin1String("setError"), m_error); + client->asyncCall(QLatin1String("terminate"), m_errorText); if (m_currentPendingCalls < 1) { qCDebug(KUISERVER) << "no more async calls left pending..emitting finished so we can have ourselves deleted."; diff --git a/kuiserver/jobview.h b/kuiserver/jobview.h index b78ad149f..970322a32 100644 --- a/kuiserver/jobview.h +++ b/kuiserver/jobview.h @@ -98,7 +98,10 @@ public: void setCapabilities(int capabilities); int capabilities() const; - QString error() const; + void setError(uint errorCode); + uint error() const; + + QString errorText() const; uint state() const; @@ -201,7 +204,9 @@ private: QString m_infoMessage; ///< The information message to be shown - QString m_error; ///< The error message of the job, set when it's terminated + uint m_error; ///< The error code of the job, set when it's terminated + + QString m_errorText; ///< The error message of the job, set when it's terminated QString m_totalUnit; ///< The unit used in setTotalAmount