]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Update split action when settings change
[dolphin.git] / src / dolphinviewcontainer.cpp
index d45096d0b860ed7e081bf5ef1938b81ee609eca9..a388334819c9b40d11f13fba33cffd075fc71c29 100644 (file)
 #include "filterbar/filterbar.h"
 #include "global.h"
 #include "search/dolphinsearchbox.h"
-#include "selectionmode/selectionmodetopbar.h"
+#include "selectionmode/topbar.h"
 #include "statusbar/dolphinstatusbar.h"
-#include "views/viewmodecontroller.h"
-#include "views/viewproperties.h"
 #include "dolphin_detailsmodesettings.h"
 
 #include <KActionCollection>
 #endif
 #include <KFileItemActions>
 #include <KFilePlacesModel>
-#include <KIO/PreviewJob>
-#include <KIO/OpenUrlJob>
+#include <kio_version.h>
+#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
+#include <KIO/JobUiDelegateFactory>
+#else
 #include <KIO/JobUiDelegate>
+#endif
+#include <KIO/OpenUrlJob>
 #include <KLocalizedString>
 #include <KMessageWidget>
 #include <KProtocolManager>
 #include <KShell>
-#include <KUrlComboBox>
 
+#include <QDesktopServices>
 #include <QDropEvent>
 #include <QGridLayout>
 #include <QGuiApplication>
-#include <QLoggingCategory>
-#include <QMimeData>
 #include <QTimer>
 #include <QUrl>
-#include <QDesktopServices>
+#include <QRegularExpression>
 
 // 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);
@@ -373,19 +375,20 @@ void DolphinViewContainer::disconnectUrlNavigator()
     m_urlNavigatorConnected = nullptr;
 }
 
-void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionModeBottomBar::Contents bottomBarContents)
+void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionMode::BottomBar::Contents bottomBarContents)
 {
     const bool wasEnabled = m_view->selectionMode();
-    m_view->setSelectionMode(enabled);
+    m_view->setSelectionModeEnabled(enabled);
 
     if (!enabled) {
+        if (!wasEnabled) {
+            return; // nothing to do here
+        }
         Q_CHECK_PTR(m_selectionModeTopBar); // there is no point in disabling selectionMode when it wasn't even enabled once.
         Q_CHECK_PTR(m_selectionModeBottomBar);
         m_selectionModeTopBar->setVisible(false, WithAnimation);
         m_selectionModeBottomBar->setVisible(false, WithAnimation);
-        if (wasEnabled) {
-            Q_EMIT selectionModeChanged(false);
-        }
+        Q_EMIT selectionModeChanged(false);
         return;
     }
 
@@ -395,28 +398,28 @@ void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollecti
             setSelectionModeEnabled(false);
         });
 
-        m_selectionModeTopBar = new SelectionModeTopBar(this); // will be created hidden
-        connect(m_selectionModeTopBar, &SelectionModeTopBar::leaveSelectionModeRequested, this, [this]() {
+        m_selectionModeTopBar = new SelectionMode::TopBar(this); // will be created hidden
+        connect(m_selectionModeTopBar, &SelectionMode::TopBar::selectionModeLeavingRequested, this, [this]() {
             setSelectionModeEnabled(false);
         });
         m_topLayout->addWidget(m_selectionModeTopBar, positionFor.selectionModeTopBar, 0);
     }
 
     if (!m_selectionModeBottomBar) {
-        m_selectionModeBottomBar = new SelectionModeBottomBar(actionCollection, this);
+        m_selectionModeBottomBar = new SelectionMode::BottomBar(actionCollection, this);
         connect(m_view, &DolphinView::selectionChanged, this, [this](const KFileItemList &selection) {
             m_selectionModeBottomBar->slotSelectionChanged(selection, m_view->url());
         });
-        connect(m_selectionModeBottomBar, &SelectionModeBottomBar::error, this, [this](const QString &errorMessage) {
+        connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::error, this, [this](const QString &errorMessage) {
             showErrorMessage(errorMessage);
         });
-        connect(m_selectionModeBottomBar, &SelectionModeBottomBar::leaveSelectionModeRequested, this, [this]() {
+        connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::selectionModeLeavingRequested, this, [this]() {
             setSelectionModeEnabled(false);
         });
         m_topLayout->addWidget(m_selectionModeBottomBar, positionFor.selectionModeBottomBar, 0);
     }
     m_selectionModeBottomBar->resetContents(bottomBarContents);
-    if (bottomBarContents == SelectionModeBottomBar::GeneralContents) {
+    if (bottomBarContents == SelectionMode::BottomBar::GeneralContents) {
         m_selectionModeBottomBar->slotSelectionChanged(m_view->selectedItems(), m_view->url());
     }
 
@@ -433,12 +436,12 @@ bool DolphinViewContainer::isSelectionModeEnabled() const
     Q_ASSERT((!isEnabled
               // We can't assert that the bars are invisible only because the selection mode is disabled because the hide animation might still be playing.
               && (!m_selectionModeBottomBar || !m_selectionModeBottomBar->isEnabled() ||
-                  !m_selectionModeBottomBar->isVisible() || m_selectionModeBottomBar->contents() == SelectionModeBottomBar::PasteContents))
+                  !m_selectionModeBottomBar->isVisible() || m_selectionModeBottomBar->contents() == SelectionMode::BottomBar::PasteContents))
           || ( isEnabled
               && m_selectionModeTopBar && m_selectionModeTopBar->isVisible()
               // The bottom bar is either visible or was hidden because it has nothing to show in GeneralContents mode e.g. because no items are selected.
               && m_selectionModeBottomBar
-              && (m_selectionModeBottomBar->isVisible() || m_selectionModeBottomBar->contents() == SelectionModeBottomBar::GeneralContents)));
+              && (m_selectionModeBottomBar->isVisible() || m_selectionModeBottomBar->contents() == SelectionMode::BottomBar::GeneralContents)));
     return isEnabled;
 }
 
@@ -760,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();
@@ -934,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) {
@@ -962,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{};
+}