]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Places Panel: Delegate open file error to KIO
authorKai Uwe Broulik <kde@privat.broulik.de>
Tue, 29 Nov 2022 10:22:19 +0000 (10:22 +0000)
committerFelix Ernst <felixernst@kde.org>
Tue, 29 Nov 2022 10:22:19 +0000 (10:22 +0000)
This functionality is now provided by `KFilePlacesModel` as long as
you tell it to do the teardown rather than calling into the device yourself.

src/panels/places/placespanel.cpp
src/panels/places/placespanel.h

index 69ed232b4b2c8b921511baa7fd8b9cde330936e3..de713774763b598cbe38fe3d83e1790ef48d514f 100644 (file)
@@ -21,7 +21,6 @@
 #include <KFilePlacesModel>
 #include <KIO/DropJob>
 #include <KIO/Job>
-#include <KListOpenFilesJob>
 #include <KLocalizedString>
 #include <KProtocolManager>
 
@@ -86,11 +85,12 @@ void PlacesPanel::setCustomContextMenuActions(const QList<QAction *> &actions)
 
 void PlacesPanel::proceedWithTearDown()
 {
-    Q_ASSERT(m_deviceToTearDown);
-
-    connect(m_deviceToTearDown, &Solid::StorageAccess::teardownDone,
-            this, &PlacesPanel::slotTearDownDone);
-    m_deviceToTearDown->teardown();
+    if (m_indexToTearDown.isValid()) {
+        auto *placesModel = static_cast<KFilePlacesModel *>(model());
+        placesModel->requestTeardown(m_indexToTearDown);
+    } else {
+        qWarning() << "Places entry to tear down is no longer valid";
+    }
 }
 
 void PlacesPanel::readSettings()
@@ -114,6 +114,7 @@ void PlacesPanel::showEvent(QShowEvent* event)
         setModel(placesModel);
 
         connect(placesModel, &KFilePlacesModel::errorMessage, this, &PlacesPanel::errorMessage);
+        connect(placesModel, &KFilePlacesModel::teardownDone, this, &PlacesPanel::slotTearDownDone);
 
         connect(placesModel, &QAbstractItemModel::rowsInserted, this, &PlacesPanel::slotRowsInserted);
         connect(placesModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &PlacesPanel::slotRowsAboutToBeRemoved);
@@ -212,7 +213,7 @@ void PlacesPanel::slotTearDownRequested(const QModelIndex &index)
         return;
     }
 
-    m_deviceToTearDown = storageAccess;
+    m_indexToTearDown = QPersistentModelIndex(index);
 
     // disconnect the Solid::StorageAccess::teardownRequested
     // to prevent emitting PlacesPanel::storageTearDownExternallyRequested
@@ -229,41 +230,17 @@ void PlacesPanel::slotTearDownRequestedExternally(const QString &udi)
     Q_EMIT storageTearDownExternallyRequested(storageAccess->filePath());
 }
 
-void PlacesPanel::slotTearDownDone(Solid::ErrorType error, const QVariant& errorData)
+void PlacesPanel::slotTearDownDone(const QModelIndex &index, Solid::ErrorType error, const QVariant &errorData)
 {
-    if (error && errorData.isValid()) {
-        if (error == Solid::ErrorType::UserCanceled) {
-            // No need to tell the user what they just did.
-        } else 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", ", ")));
-                }
-                Q_EMIT errorMessage(errorString);
-            });
-            listOpenFilesJob->start();
-        } else {
-            Q_EMIT errorMessage(errorData.toString());
+    Q_UNUSED(errorData); // All error handling is currently done in frameworks.
+
+    if (index == m_indexToTearDown) {
+        if (error == Solid::ErrorType::NoError) {
+            // No error; it must have been unmounted successfully
+            Q_EMIT storageTearDownSuccessful();
         }
-    } else {
-        // No error; it must have been unmounted successfully
-        Q_EMIT storageTearDownSuccessful();
+        m_indexToTearDown = QPersistentModelIndex();
     }
-    disconnect(m_deviceToTearDown, &Solid::StorageAccess::teardownDone,
-               this, &PlacesPanel::slotTearDownDone);
-    m_deviceToTearDown = nullptr;
 }
 
 void PlacesPanel::slotRowsInserted(const QModelIndex &parent, int first, int last)
index 6c37301ad6afb19fe7e7899495e89924291b50d4..ef213ab30068feb437c30c4a68bf7851722c11af 100644 (file)
@@ -62,7 +62,7 @@ private Q_SLOTS:
     void slotContextMenuAboutToShow(const QModelIndex &index, QMenu *menu);
     void slotTearDownRequested(const QModelIndex &index);
     void slotTearDownRequestedExternally(const QString &udi);
-    void slotTearDownDone(Solid::ErrorType error, const QVariant& errorData);
+    void slotTearDownDone(const QModelIndex &index, Solid::ErrorType error, const QVariant &errorData);
     void slotRowsInserted(const QModelIndex &parent, int first, int last);
     void slotRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
 
@@ -72,7 +72,7 @@ private:
     QUrl m_url; // only used for initial setUrl
     QList<QAction*> m_customContextMenuActions;
 
-    Solid::StorageAccess *m_deviceToTearDown = nullptr;
+    QPersistentModelIndex m_indexToTearDown;
 
     QAction *m_configureTrashAction;
     QAction *m_lockPanelsAction;