]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Show home folder if needed after unmounting mounted disk
authorNate Graham <nate@kde.org>
Tue, 13 Oct 2020 17:51:59 +0000 (11:51 -0600)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Fri, 23 Oct 2020 17:00:09 +0000 (17:00 +0000)
Right now, when you unmount a device that any active view containers are
displaying, nothing in the view changes. As a result, it's possible to
try to navigate to files or folders in that view, which cannot be done
because the disk that the files or folders are located on has been
unmounted!

With this commit, we detect that case and switch the view containers
to show the home folder after the disk whose contents they are displaying
gets unmounted.

BUG: 158934
FIXED-IN: 20.12

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

index 8d4f50270b5c086b1ef23236bb54eecc3b28a1b3..2c91cd07a7a846b1d718cdf61f38736d0e54928c 100644 (file)
@@ -1271,6 +1271,10 @@ void DolphinMainWindow::updateWindowTitle()
 
 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
 {
+    connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
+        setViewsToHomeIfMountPathOpen(mountPath);
+    });
+
     if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
         m_tearDownFromPlacesRequested = true;
         m_terminalPanel->goHome();
@@ -1282,12 +1286,27 @@ void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mo
 
 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
 {
+    connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
+        setViewsToHomeIfMountPathOpen(mountPath);
+    });
+
     if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
         m_tearDownFromPlacesRequested = false;
         m_terminalPanel->goHome();
     }
 }
 
+void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString& mountPath)
+{
+    const QVector<DolphinViewContainer*> theViewContainers = viewContainers();
+    for (DolphinViewContainer *viewContainer : theViewContainers) {
+        if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
+            viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
+        }
+    }
+    disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
+}
+
 void DolphinMainWindow::setupActions()
 {
     // setup 'File' menu
index c03eb1be07fb56454bd35962e6fb12db25eed7d7..80d0f891a5459cfdd3c96dbeddb5de096073b79d 100644 (file)
@@ -92,7 +92,15 @@ public:
      */
     KNewFileMenu* newFileMenu() const;
 
-    void setTabsToHomeIfMountPathOpen(const QString& mountPath);
+    /**
+     * Switch the window's view containers' locations to display the home path
+     * for any which are currently displaying a location corresponding to or
+     * within mountPath.
+     *
+     * This typically done after unmounting a disk at mountPath to ensure that
+     * the window is not displaying an invalid location.
+     */
+    void setViewsToHomeIfMountPathOpen(const QString& mountPath);
 
 public slots:
     /**
index de858389bee5393fe5cdd5ab0ef88935268fc464..c9f1c8365560f5f9d8bcdf5372eeb436905d7d06 100644 (file)
@@ -473,6 +473,9 @@ void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error, const QVar
         } else {
             emit errorMessage(errorData.toString());
         }
+    } else {
+        // No error; it must have been unmounted successfully
+        emit storageTearDownSuccessful();
     }
     disconnect(m_deviceToTearDown, &Solid::StorageAccess::teardownDone,
                this, &PlacesItemModel::slotStorageTearDownDone);
index 91f017cecc4f870852284668a9d953ebec08316a..2b1f3bc14f67c2420c40fc23a0af7d5ba1f76308 100644 (file)
@@ -130,6 +130,7 @@ signals:
     void storageSetupDone(int index, bool success);
     void storageTearDownRequested(const QString& mountPath);
     void storageTearDownExternallyRequested(const QString& mountPath);
+    void storageTearDownSuccessful();
 
 protected:
     void onItemInserted(int index) override;
index 413d346b6e4840a025375d420d4fab5f9ae9c814..2e1d09e6b6cf3e3042faee7b61583fa09debc36f 100644 (file)
@@ -104,6 +104,8 @@ void PlacesPanel::showEvent(QShowEvent* event)
                 this, &PlacesPanel::storageTearDownRequested);
         connect(m_model, &PlacesItemModel::storageTearDownExternallyRequested,
                 this, &PlacesPanel::storageTearDownExternallyRequested);
+        connect(m_model, &PlacesItemModel::storageTearDownSuccessful,
+                this, &PlacesPanel::storageTearDownSuccessful);
 
         m_view = new PlacesView();
         m_view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>());
index 8ea4d0831f6be24120b2d9caa557611f1a8ac220..38bfa4c5324cefcc39264e7394e43ddd0c4647bc 100644 (file)
@@ -37,6 +37,7 @@ signals:
     void storageTearDownRequested(const QString& mountPath);
     void storageTearDownExternallyRequested(const QString& mountPath);
     void showHiddenEntriesChanged(bool shown);
+    void storageTearDownSuccessful();
 
 protected:
     bool urlChanged() override;