diff --git a/applets/notifications/package/contents/ui/Jobs.qml b/applets/notifications/package/contents/ui/Jobs.qml --- a/applets/notifications/package/contents/ui/Jobs.qml +++ b/applets/notifications/package/contents/ui/Jobs.qml @@ -61,30 +61,88 @@ return } - var error = runningJobs[source]["error"] - var errorText = runningJobs[source]["errorText"] + var job = runningJobs[source]; + + var error = job.error; + var errorText = job.errorText; // 1 = ERR_USER_CANCELED - don't show any notification at all if (error == 1) { delete runningJobs[source] return } - var message = runningJobs[source]["label1"] ? runningJobs[source]["label1"] : runningJobs[source]["label0"] - var infoMessage = runningJobs[source]["infoMessage"] + var message = job.label1 || job.label0 || ""; + var infoMessage = job.infoMessage; + if (!message && !infoMessage) { delete runningJobs[source] 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 body = message; + var actions = []; + var urls = []; + + if (!error && message && UrlHelper.isUrlValid(message)) { + var destUrl = job.destUrl; + + var filesCount = 0; + for (var i = 0; i < 3; ++i) { + var unit = job["totalUnit" + i]; + var amount = job["totalAmount" + i]; + if (unit === "files") { + filesCount = amount; + break; + } + } + + // If we can be sure it's a single valid file we can show a thumbnail + if (filesCount === 1) { + var url = message; + + var displaySource = url; + + var dotIndex = url.lastIndexOf("/"); + if (dotIndex > -1) { + displaySource = url.substr(dotIndex + 1); + } + + // destUrl is a URL so we want to strip the file:// for beauty + var displayDestUrl = (destUrl ? destUrl.toString() : ""); + if (displayDestUrl.indexOf("file:///") === 0) { + displayDestUrl = displayDestUrl.substr(7); // length of file:// + } + + if (displayDestUrl) { + body = i18nc("Copied, moved, or linked file named %1 to folder %2", "%1 to %2", displaySource, displayDestUrl); + } + + // KIO source/destination is pretty URL, so for it to be a proper URL we need to prepend file:// if neccessary + if (url[0] === "/") { + url = "file://" + url; + } + + urls.push(url); + // if there were multiple files, show the dest url instead + // which is a lot more useful than whatever random file that got processed last + } else if (filesCount > 1 && destUrl) { + body = i18ncp("Copied, moved, or linked %1 files to folder %2", "%1 file to %2", "%1 files to %2", filesCount, destUrl); + + urls.push(destUrl); + } else { + // otherwise use classic "open" button + actions.push("jobUrl#" + message, i18n("Open...")); + } + } + // notification body interprets HTML, so we need to manually escape the name - var body = (errorText || message || "").replace(/[&<>]/g, function (tag) { + body = body.replace(/[&<>]/g, function (tag) { return { '&': '&', '<': '<', @@ -101,8 +159,10 @@ 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") + // If the actionId contains "jobUrl#", it tries to open the "id" value (which is "message") + actions: actions, + urls: urls + }; notifications.createNotification(op); diff --git a/dataengines/notifications/notificationaction.cpp b/dataengines/notifications/notificationaction.cpp --- a/dataengines/notifications/notificationaction.cpp +++ b/dataengines/notifications/notificationaction.cpp @@ -66,6 +66,11 @@ hints.insert(QStringLiteral("x-kde-skipGrouping"), true); } + const QStringList urls = parameters().value(QStringLiteral("urls")).toStringList(); + if (!urls.isEmpty()) { + hints.insert(QStringLiteral("x-kde-urls"), urls); + } + int rv = m_engine->createNotification(parameters().value(QStringLiteral("appName")).toString(), parameters().value(QStringLiteral("appIcon")).toString(), parameters().value(QStringLiteral("summary")).toString(), diff --git a/dataengines/notifications/notifications.operations b/dataengines/notifications/notifications.operations --- a/dataengines/notifications/notifications.operations +++ b/dataengines/notifications/notifications.operations @@ -36,6 +36,9 @@ + + +