X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e464b58c33b27ea331225778c60ba3aa8b7fb1d5..628a2bbb64d08e5aff524b264847699a1f55a611:/src/dolphinviewcontainer.cpp diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index f38995603..a38833481 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -14,8 +14,6 @@ #include "search/dolphinsearchbox.h" #include "selectionmode/topbar.h" #include "statusbar/dolphinstatusbar.h" -#include "views/viewmodecontroller.h" -#include "views/viewproperties.h" #include "dolphin_detailsmodesettings.h" #include @@ -24,23 +22,25 @@ #endif #include #include -#include -#include +#include +#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0) +#include +#else #include +#endif +#include #include #include #include #include -#include +#include #include #include #include -#include -#include #include #include -#include +#include // An overview of the widgets contained by this ViewContainer struct LayoutStructure { @@ -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); @@ -761,7 +763,11 @@ void DolphinViewContainer::slotItemActivated(const KFileItem &item) } KIO::OpenUrlJob *job = new KIO::OpenUrlJob(item.targetUrl(), item.mimetype()); - job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoWarningHandlingEnabled, this)); +#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0) + job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); +#else + job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); +#endif job->setShowOpenOrExecuteDialog(true); connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished); job->start(); @@ -935,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) { @@ -963,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{}; +}