1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*
* Copyright 2012 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.private.notifications 1.0
Column {
id: jobsRoot
width: parent.width
property alias count: jobs.count
ListModel {
id: jobs
}
PlasmaCore.DataSource {
id: jobsSource
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
}
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
}
var message = runningJobs[source]["label1"] ? runningJobs[source]["label1"] : runningJobs[source]["label0"]
var infoMessage = runningJobs[source]["infoMessage"]
if (!message && !infoMessage) {
return
}
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, failed to complete", "%1: Failed", infoMessage) : i18n("Job Failed")
}
var op = {
appIcon: runningJobs[source].appIconName,
appName: runningJobs[source].appName,
summary: summary,
body: errorText || message,
isPersistent: !!error, // we'll assume success to be the note-unworthy default, only be persistent in error case
urgency: 0,
configurable: false,
skipGrouping: true, // Bug 360156
actions: !error && UrlHelper.isUrlValid(message) ? ["jobUrl#" + message, i18n("Open...")] : []
}; // If the actionId contains "jobUrl#", it tries to open the "id" value (which is "message")
notifications.createNotification(op);
delete runningJobs[source]
}
onNewData: {
runningJobs[sourceName] = data
}
onDataChanged: {
var total = 0
for (var i = 0; i < sources.length; ++i) {
if (jobsSource.data[sources[i]] && jobsSource.data[sources[i]]["percentage"]) {
total += jobsSource.data[sources[i]]["percentage"]
}
}
total /= sources.length
notificationsApplet.globalProgress = total/100
}
Component.onCompleted: {
connectedSources = sources
}
}
Item {
visible: jobs.count > 3
PlasmaComponents.ProgressBar {
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
right: parent.right
}
minimumValue: 0
maximumValue: 100
value: notificationsApplet.globalProgress * 100
}
}
Repeater {
model: jobs
delegate: JobDelegate {}
}
}
|