]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Unmounting busy device doesn't tell who is blocking
authorDavid Hallas <david@davidhallas.dk>
Sat, 23 Mar 2019 08:16:17 +0000 (09:16 +0100)
committerDavid Hallas <david@davidhallas.dk>
Sun, 27 Oct 2019 05:52:25 +0000 (06:52 +0100)
Summary: Unmounting a busy device from the places panel doesn't tell which applications have open files blocking the unmount.

Test Plan:
Mount a USB stick using Dolphin
Open a file from the USB stick
Unmount the USB stick using Dolphin
Observe the new error message.

FEATURE: 189302

Reviewers: #dolphin, elvisangelaccio, ngraham, broulik, meven

Reviewed By: #dolphin, elvisangelaccio, meven

Subscribers: meven, davidedmundson, kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D19989

CMakeLists.txt
src/CMakeLists.txt
src/panels/places/placesitemmodel.cpp

index 90c1df10ef89ffc41d54d2679955ac9b05513a99..88ccca25618a9b20bf66b0ccdcf50c7b1d6c1927 100644 (file)
@@ -8,7 +8,7 @@ set (KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATI
 project(Dolphin VERSION ${KDE_APPLICATIONS_VERSION})
 
 set(QT_MIN_VERSION "5.11.0")
-set(KF5_MIN_VERSION "5.61.0")
+set(KF5_MIN_VERSION "5.63.0")
 
 # ECM setup
 find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED)
index 8bbb081cdddbc93e60e5dfe4f6ee35dc9956e128..14701a1f41169e7042e8ab46273f22a7e8ec3cb6 100644 (file)
@@ -274,6 +274,7 @@ add_library(dolphinstatic STATIC ${dolphinstatic_SRCS})
 target_include_directories(dolphinstatic SYSTEM PRIVATE ${PHONON_INCLUDES})
 target_link_libraries(dolphinstatic
     dolphinprivate
+    KF5::CoreAddons
     KF5::KCMUtils
     KF5::DBusAddons
     KF5::Notifications
index e8636942b83ac645e7309a9808379ae448ca1cf6..c0cef9315c9d17379dad3b403af4e25c6d94bbdf 100644 (file)
@@ -36,6 +36,8 @@
 #include <KUrlMimeData>
 #include <Solid/DeviceNotifier>
 #include <Solid/OpticalDrive>
+#include <KCoreAddons/KProcessList>
+#include <KCoreAddons/KListOpenFilesJob>
 
 #include <QAction>
 #include <QIcon>
@@ -474,7 +476,29 @@ void PlacesItemModel::updateItem(PlacesItem *item, const QModelIndex &index)
 void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error, const QVariant& errorData)
 {
     if (error && errorData.isValid()) {
-        emit errorMessage(errorData.toString());
+        if (error == Solid::ErrorType::DeviceBusy) {
+            KListOpenFilesJob* listOpenFilesJob = new KListOpenFilesJob(m_deviceToTearDown->filePath());
+            connect(listOpenFilesJob, &KIO::Job::result, this, [this, listOpenFilesJob](KJob*) {
+                const KProcessList::KProcessInfoList blockingProcesses = listOpenFilesJob->processInfoList();
+                QString errorString;
+                if (blockingProcesses.isEmpty()) {
+                    errorString = i18n("One or more files on this device are open within an application.");
+                } else {
+                    QStringList blockingApps;
+                    for (const auto& process : blockingProcesses) {
+                        blockingApps << process.name();
+                    }
+                    blockingApps.removeDuplicates();
+                    errorString = xi18np("One or more files on this device are opened in application <application>\"%2\"</application>.",
+                            "One or more files on this device are opened in following applications: <application>%2</application>.",
+                            blockingApps.count(), blockingApps.join(i18nc("separator in list of apps blocking device unmount", ", ")));
+                }
+                emit errorMessage(errorString);
+            });
+            listOpenFilesJob->start();
+        } else {
+            emit errorMessage(errorData.toString());
+        }
     }
     disconnect(m_deviceToTearDown, &Solid::StorageAccess::teardownDone,
                this, &PlacesItemModel::slotStorageTearDownDone);