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
|
From a2ed9f88c16a8b8be504c1a0b9c7a93b8b65415f Mon Sep 17 00:00:00 2001
From: Kai Uwe Broulik <kde@privat.broulik.de>
Date: Tue, 22 Apr 2025 15:45:00 +0200
Subject: [PATCH] applets/trash: Use KIO CommandLauncherJob to open trash
QDesktopServices::openUrl (through Qt.openUrlExternally) requests a
token from the focus window. When trash is clicked in a panel, the panel
doesn't have focus, resulting in no token being created.
KProcessRunner used by KIO CommandLauncherJob as a fallback takes
whatever first window in qApp making activation work.
While at it, also use KNotificationJobUiDelegate for proper error
reporting in case opening trash fails.
BUG: 499936
---
applets/trash/package/contents/ui/main.qml | 2 +-
applets/trash/plugin/CMakeLists.txt | 1 +
applets/trash/plugin/trash.cpp | 10 ++++++++++
applets/trash/plugin/trash.h | 1 +
4 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/applets/trash/package/contents/ui/main.qml b/applets/trash/package/contents/ui/main.qml
index 35cd5786e7..773afcd897 100644
--- a/applets/trash/package/contents/ui/main.qml
+++ b/applets/trash/package/contents/ui/main.qml
@@ -46,7 +46,7 @@ PlasmoidItem {
return iconName;
}
- Plasmoid.onActivated: Qt.openUrlExternally("trash:/")
+ Plasmoid.onActivated: TrashPrivate.Trash.openTrash()
Keys.onPressed: {
switch (event.key) {
diff --git a/applets/trash/plugin/CMakeLists.txt b/applets/trash/plugin/CMakeLists.txt
index 9cf08dd7e1..88c8c3d01d 100644
--- a/applets/trash/plugin/CMakeLists.txt
+++ b/applets/trash/plugin/CMakeLists.txt
@@ -12,6 +12,7 @@ target_link_libraries(trashplugin PRIVATE
KF6::KIOWidgets
KF6::CoreAddons # KSharedDataCache required by KImageCache in GuiAddons
KF6::GuiAddons
+ KF6::Notifications
Qt::DBus
)
diff --git a/applets/trash/plugin/trash.cpp b/applets/trash/plugin/trash.cpp
index e40d84560d..0725ae0d8f 100644
--- a/applets/trash/plugin/trash.cpp
+++ b/applets/trash/plugin/trash.cpp
@@ -9,13 +9,23 @@
#include <QApplication>
#include <QFileInfo>
+#include <KNotificationJobUiDelegate>
+
#include <KIO/DeleteOrTrashJob>
+#include <KIO/OpenUrlJob>
Trash::Trash(QObject *parent)
: QObject(parent)
{
}
+void Trash::openTrash()
+{
+ auto *job = new KIO::OpenUrlJob(QUrl(QStringLiteral("trash:/")));
+ job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled));
+ job->start();
+}
+
void Trash::trashUrls(const QList<QUrl> &urls)
{
using Iface = KIO::AskUserActionInterface;
diff --git a/applets/trash/plugin/trash.h b/applets/trash/plugin/trash.h
index 1014f9dcdf..c2010d4aba 100644
--- a/applets/trash/plugin/trash.h
+++ b/applets/trash/plugin/trash.h
@@ -20,6 +20,7 @@ public:
explicit Trash(QObject *parent = nullptr);
~Trash() override = default;
+ Q_INVOKABLE void openTrash();
Q_INVOKABLE void trashUrls(const QList<QUrl> &urls);
Q_INVOKABLE void emptyTrash();
Q_INVOKABLE bool canBeTrashed(const QUrl &url) const;
--
GitLab
|