From bc5c47537f3bbb706b3fe7af66508f5ef2fadc6e Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 27 Apr 2015 20:09:14 +0200 Subject: [PATCH] Manually keep track of jobs sources DataSources source is a QStringList property which means changes within cannot be tracked causing all the job delegates to be destroyed and re-created when sourcesChanged is emitted. This is pretty wasteful and also causes the delegates to lose their state (eg. details expanded) REVIEW: 123502 BUG: 346673 FIXED-IN: 5.3.1 --- .../package/contents/ui/JobDelegate.qml | 11 ++++---- .../package/contents/ui/Jobs.qml | 27 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/applets/notifications/package/contents/ui/JobDelegate.qml b/applets/notifications/package/contents/ui/JobDelegate.qml index 67418893a..4717d49a8 100644 --- a/applets/notifications/package/contents/ui/JobDelegate.qml +++ b/applets/notifications/package/contents/ui/JobDelegate.qml @@ -42,7 +42,8 @@ Column { readonly property bool isSuspended: getData(jobsSource.data, "state", '') === "suspended" function getData(data, name, defaultValue) { - return data[modelData] ? (data[modelData][name] ? data[modelData][name] : defaultValue) : defaultValue; + var source = model.name + return data[source] ? (data[source][name] ? data[source][name] : defaultValue) : defaultValue; } PlasmaExtras.Heading { @@ -150,8 +151,8 @@ Column { maximumValue: 100 //percentage doesn't always exist, so doesn't get in the model value: getData(jobsSource.data, "percentage", 0) - indeterminate: plasmoid.expanded && jobsSource.data[modelData] - && typeof jobsSource.data[modelData]["percentage"] === "undefined" + indeterminate: plasmoid.expanded && jobsSource.data[model.name] + && typeof jobsSource.data[model.name]["percentage"] === "undefined" && !jobItem.isSuspended } @@ -165,7 +166,7 @@ Column { if (jobItem.isSuspended) { operationName = "resume" } - var service = jobsSource.serviceForSource(modelData) + var service = jobsSource.serviceForSource(model.name) var operation = service.operationDescription(operationName) service.startOperationCall(operation) } @@ -177,7 +178,7 @@ Column { visible: getData(jobsSource.data, "killable", 0) onClicked: { - var service = jobsSource.serviceForSource(modelData) + var service = jobsSource.serviceForSource(model.name) 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 6ecf36691..3307d38b9 100644 --- a/applets/notifications/package/contents/ui/Jobs.qml +++ b/applets/notifications/package/contents/ui/Jobs.qml @@ -28,21 +28,34 @@ Column { id: jobsRoot width: parent.width - property alias count: jobsRepeater.count + property alias count: jobs.count + + ListModel { + id: jobs + } PlasmaCore.DataSource { id: jobsSource - property variant runningJobs: ({}) + property var runningJobs: ({}) engine: "applicationjobs" interval: 0 onSourceAdded: { connectSource(source) + jobs.append({name: source}) } onSourceRemoved: { + // remove source from jobs model + for (var i = 0, len = jobs.count; i < len; ++i) { + if (jobs.get(i).name === source) { + jobs.remove(i) + break + } + } + if (!notifications) { return } @@ -84,9 +97,7 @@ Column { } onNewData: { - var jobs = runningJobs - jobs[sourceName] = data - runningJobs = jobs + runningJobs[sourceName] = data } onDataChanged: { @@ -107,7 +118,7 @@ Column { } Item { - visible: jobsRepeater.count > 3 + visible: jobs.count > 3 PlasmaComponents.ProgressBar { anchors { @@ -123,9 +134,7 @@ Column { } Repeater { - id: jobsRepeater - - model: jobsSource.sources + model: jobs delegate: JobDelegate {} } }