diff options
| author | Méven Car <[email protected]> | 2022-11-29 18:16:59 +0000 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2022-11-29 18:16:59 +0000 |
| commit | a2c9c05de2dfabbb2bb614390c8e03023dad2bd1 (patch) | |
| tree | 5f34ae95e4cb0ea8ee95d3ee17c28b3cacd25ae9 /src/dolphinviewcontainer.cpp | |
| parent | de289800b22c654e8e3d8fbaea7bdb496a021b88 (diff) | |
Exit the deleted directory when it is removed
If current directory is a local file, try to find nearest dir ancestor and
open it. Display warning to the user.
Diffstat (limited to 'src/dolphinviewcontainer.cpp')
| -rw-r--r-- | src/dolphinviewcontainer.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
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, <filename>%1</filename> 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{}; +} |
