diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 2c91cd07a7..f7ec5f511f 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -216,6 +216,20 @@ QVector DolphinMainWindow::viewContainers() const return viewContainers; } +void DolphinMainWindow::setViewsWithInvalidPathsToHome() +{ + const QVector 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& dirs, bool splitView) { m_tabWidget->openDirectories(dirs, splitView); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 80d0f891a5..faf428c033 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -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, diff --git a/src/main.cpp b/src/main.cpp index 0a252bc775..9191127e52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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!"; }