X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/de289800b22c654e8e3d8fbaea7bdb496a021b88..a2c9c05de2dfabbb2bb614390c8e03023dad2bd1:/src/dolphinviewcontainer.cpp diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 0d2dcdafe..a38833481 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -172,6 +172,8 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : this, &DolphinViewContainer::slotHiddenFilesShownChanged); connect(m_view, &DolphinView::sortHiddenLastChanged, this, &DolphinViewContainer::slotSortHiddenLastChanged); + connect(m_view, &DolphinView::currentDirectoryRemoved, + this, &DolphinViewContainer::slotCurrentDirectoryRemoved); // Initialize status bar m_statusBar = new DolphinStatusBar(this); @@ -939,6 +941,19 @@ void DolphinViewContainer::slotSortHiddenLastChanged(bool hiddenLast) } } +void DolphinViewContainer::slotCurrentDirectoryRemoved() +{ + const QString location(url().toDisplayString(QUrl::PreferLocalFile)); + if (url().isLocalFile()) { + const QString dirPath = url().toLocalFile(); + const QString newPath = getNearestExistingAncestorOfPath(dirPath); + const QUrl newUrl = QUrl::fromLocalFile(newPath); + setUrl(newUrl); + } + + showMessage(xi18n("Current location changed, %1 is no longer accessible.", location), Warning); +} + void DolphinViewContainer::slotOpenUrlFinished(KJob *job) { if (job->error() && job->error() != KIO::ERR_USER_CANCELED) { @@ -967,3 +982,14 @@ void DolphinViewContainer::tryRestoreViewState() m_view->restoreState(stream); } } + +QString DolphinViewContainer::getNearestExistingAncestorOfPath(const QString& path) const +{ + QDir dir(path); + do { + dir.setPath(QDir::cleanPath(dir.filePath(QStringLiteral("..")))); + } + while (!dir.exists() && !dir.isRoot()); + + return dir.exists() ? dir.path() : QString{}; +}