From c3b914a7faed3a7c0195ae77b40204cbc8d31fe5 Mon Sep 17 00:00:00 2001 From: David Hallas Date: Sat, 23 Mar 2019 09:16:17 +0100 Subject: Unmounting busy device doesn't tell who is blocking 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 --- src/panels/places/placesitemmodel.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/panels') diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index e8636942b..c0cef9315 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include #include @@ -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 \"%2\".", + "One or more files on this device are opened in following applications: %2.", + 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); -- cgit v1.3