File fix-login-sound.patch of Package plasma5-workspace

From 608204765110724f420c978499411e46db1d086e Mon Sep 17 00:00:00 2001
From: Wolfgang Bauer <wbauer@tmo.at>
Date: Mon, 30 Apr 2018 13:42:54 +0200
Subject: [PATCH] [ksmserver] Use QUrl::fromUserInput to construct sound url

Since Phonon 4.9, this code fails to play a login sound if the sound
file is specified as absolute file path (without "file://"). The reason
is that QUrl() treats the parameter as Url (not as file path), and this
only accidentally worked with earlier Phonon versions but not any more.
This patch uses QUrl::fromUserInput() instead to create a QUrl from the
string in the settings file, which fixes the problem.

This is the same change as
https://phabricator.kde.org/R289:9db06adc8114163f401417064b07772139bc36bc
in knotifications.
A more detailed explanation of the problem can be found in
https://bugs.kde.org/show_bug.cgi?id=337276#c12 .

BUG: 392725
FIXED-IN: 5.12.5
Differential Revision: https://phabricator.kde.org/D12606
---
 ksmserver/startup.cpp | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/ksmserver/startup.cpp b/ksmserver/startup.cpp
index 8854c979..b9bb1e0d 100644
--- a/ksmserver/startup.cpp
+++ b/ksmserver/startup.cpp
@@ -115,14 +115,22 @@ class NotificationThread : public QThread
             return;
         }
 
-        QUrl soundURL = QUrl(soundFilename); // this CTOR accepts both absolute paths (/usr/share/sounds/blabla.ogg and blabla.ogg) w/o screwing the scheme
-        if (soundURL.isRelative() && !soundURL.toString().startsWith('/')) { // QUrl considers url.scheme.isEmpty() == url.isRelative()
-            soundURL = QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("sounds/") + soundFilename));
-
-            if (soundURL.isEmpty()) {
-                qWarning() << "Audio notification requested, but sound file from notifyrc file was not found, aborting audio notification";
-                return;
+        QUrl soundURL;
+        const auto dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
+        for (const QString &dataLocation: dataLocations) {
+            soundURL = QUrl::fromUserInput(soundFilename,
+                                           dataLocation + QStringLiteral("/sounds"),
+                                           QUrl::AssumeLocalFile);
+            if (soundURL.isLocalFile() && QFile::exists(soundURL.toLocalFile())) {
+                break;
+            } else if (!soundURL.isLocalFile() && soundURL.isValid()) {
+                break;
             }
+            soundURL.clear();
+        }
+        if (soundURL.isEmpty()) {
+            qWarning() << "Audio notification requested, but sound file from notifyrc file was not found, aborting audio notification";
+            return;
         }
 
         Phonon::MediaObject *m = new Phonon::MediaObject(&parent);
-- 
2.13.6

openSUSE Build Service is sponsored by