]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
GIT_SILENT Sync po/docbooks with svn
[dolphin.git] / src / dolphinviewcontainer.cpp
index 0d2dcdafe53feac583c98dc9d620a583901816ce..10e88601867f2bdbadc5920d91eb406592336bc3 100644 (file)
@@ -125,7 +125,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
     // Initialize the main view
     m_view = new DolphinView(url, this);
     connect(m_view, &DolphinView::urlChanged,
-            m_filterBar, &FilterBar::slotUrlChanged);
+            m_filterBar, &FilterBar::clearIfUnlocked);
     connect(m_view, &DolphinView::urlChanged,
             m_messageWidget, &KMessageWidget::hide);
     // m_urlNavigator stays in sync with m_view's location changes and
@@ -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);
@@ -795,6 +797,11 @@ void DolphinViewContainer::closeFilterBar()
     Q_EMIT showFilterBarChanged(false);
 }
 
+void DolphinViewContainer::clearFilterBar()
+{
+    m_filterBar->clearIfUnlocked();
+}
+
 void DolphinViewContainer::setNameFilter(const QString& nameFilter)
 {
     m_view->hideToolTip(ToolTipManager::HideBehavior::Instantly);
@@ -939,6 +946,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 +987,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{};
+}