]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Don't session-restore invalid paths
authorNate Graham <nate@kde.org>
Tue, 13 Oct 2020 19:37:11 +0000 (13:37 -0600)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Fri, 23 Oct 2020 17:00:09 +0000 (17:00 +0000)
When session restore is populating the main window, it's unconditional;
you'll get whatever was there before. This can be a problem if any of
those things are now missing. For example, maybe you were browsing files
on a removable disk, then quit Dolphin, and finally removed the disk. The
next time you launch Dolphin again, it will try to show you the
view from the now-missing removable disk.

To prevent this, we now look at all the URLs in all of the view
containers that were created after session-restore has finished doing
its thing; if any of them are invalid local URLs, we change the URL to
the home folder instead to avoid showing the user a view with an invalid
location in it.

BUG: 427619
FIXED-IN: 20.12

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/main.cpp

index 2c91cd07a7a846b1d718cdf61f38736d0e54928c..f7ec5f511f9ad64d0ba28afbd380a360a5f681c5 100644 (file)
@@ -216,6 +216,20 @@ QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
     return viewContainers;
 }
 
+void DolphinMainWindow::setViewsWithInvalidPathsToHome()
+{
+    const QVector<DolphinViewContainer*> theViewContainers = viewContainers();
+    for (DolphinViewContainer *viewContainer : theViewContainers) {
+
+        // Only consider local dirs, not remote locations and abstract protocols
+        if (viewContainer->url().isLocalFile()) {
+            if (!QFileInfo::exists(viewContainer->url().toLocalFile())) {
+                viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
+            }
+        }
+    }
+}
+
 void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs, bool splitView)
 {
     m_tabWidget->openDirectories(dirs, splitView);
index 80d0f891a5459cfdd3c96dbeddb5de096073b79d..faf428c03357fdfc20026056a060bb00eb55889c 100644 (file)
@@ -102,6 +102,12 @@ public:
      */
     void setViewsToHomeIfMountPathOpen(const QString& mountPath);
 
+    /**
+     * Sets any of the window's view containers which are currently displaying
+     * invalid locations to the home path
+     */
+    void setViewsWithInvalidPathsToHome();
+
 public slots:
     /**
      * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
index 0a252bc775a2f7b5227d8bc8bf7ea504e8a88d50..9191127e527e8f20e8862b62b305b473952c62d7 100644 (file)
@@ -191,6 +191,10 @@ extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
                 if (startedWithURLs) {
                     mainWindow->openDirectories(urls, splitView);
                 }
+
+                // Now handle invalid locations in the set of active views to
+                // avoid issues like https://bugs.kde.org/show_bug.cgi?id=427619
+                mainWindow->setViewsWithInvalidPathsToHome();
             } else {
                 qCWarning(DolphinDebug) << "Unknown class " << className << " in session saved data!";
             }