#include "filterbar/filterbar.h"
#include "global.h"
#include "search/dolphinsearchbox.h"
+#include "selectionmode/topbar.h"
#include "statusbar/dolphinstatusbar.h"
-#include "views/viewmodecontroller.h"
-#include "views/viewproperties.h"
#include "dolphin_detailsmodesettings.h"
-#ifdef HAVE_KACTIVITIES
+#include <KActionCollection>
+#if HAVE_KACTIVITIES
#include <KActivities/ResourceInstance>
#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 <QVBoxLayout>
-#include <QDesktopServices>
+#include <QRegularExpression>
+
+// An overview of the widgets contained by this ViewContainer
+struct LayoutStructure {
+ int searchBox = 0;
+ int messageWidget = 1;
+ int selectionModeTopBar = 2;
+ int view = 3;
+ int selectionModeBottomBar = 4;
+ int filterBar = 5;
+ int statusBar = 6;
+};
+constexpr LayoutStructure positionFor;
DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
QWidget(parent),
m_searchBox(nullptr),
m_searchModeEnabled(false),
m_messageWidget(nullptr),
+ m_selectionModeTopBar{nullptr},
m_view(nullptr),
m_filterBar(nullptr),
+ m_selectionModeBottomBar{nullptr},
m_statusBar(nullptr),
m_statusBarTimer(nullptr),
m_statusBarTimestamp(),
m_autoGrabFocus(true)
-#ifdef HAVE_KACTIVITIES
+#if HAVE_KACTIVITIES
, m_activityResourceInstance(nullptr)
#endif
{
hide();
- m_topLayout = new QVBoxLayout(this);
+ m_topLayout = new QGridLayout(this);
m_topLayout->setSpacing(0);
m_topLayout->setContentsMargins(0, 0, 0, 0);
connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished,
this, &DolphinViewContainer::delayedStatusBarUpdate);
- m_topLayout->addWidget(m_searchBox);
- m_topLayout->addWidget(m_messageWidget);
- m_topLayout->addWidget(m_view);
- m_topLayout->addWidget(m_filterBar);
- m_topLayout->addWidget(m_statusBar);
+ m_topLayout->addWidget(m_searchBox, positionFor.searchBox, 0);
+ m_topLayout->addWidget(m_messageWidget, positionFor.messageWidget, 0);
+ m_topLayout->addWidget(m_view, positionFor.view, 0);
+ m_topLayout->addWidget(m_filterBar, positionFor.filterBar, 0);
+ m_topLayout->addWidget(m_statusBar, positionFor.statusBar, 0);
setSearchModeEnabled(isSearchUrl(url));
connect(DetailsModeSettings::self(), &KCoreConfigSkeleton::configChanged, this, [=]() {
- if (view()->mode() == DolphinView::Mode::DetailsView) {
+ if (view()->viewMode() == DolphinView::Mode::DetailsView) {
view()->reload();
}
});
// Initialize kactivities resource instance
-#ifdef HAVE_KACTIVITIES
+#if HAVE_KACTIVITIES
m_activityResourceInstance = new KActivities::ResourceInstance(window()->winId(), url);
m_activityResourceInstance->setParent(this);
#endif
}
m_view->setActive(active);
-#ifdef HAVE_KACTIVITIES
+#if HAVE_KACTIVITIES
if (active) {
m_activityResourceInstance->notifyFocusedIn();
} else {
m_urlNavigatorConnected = nullptr;
}
+void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionMode::BottomBar::Contents bottomBarContents)
+{
+ const bool wasEnabled = m_view->selectionMode();
+ 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);
+ Q_EMIT selectionModeChanged(false);
+ return;
+ }
+
+ if (!m_selectionModeTopBar) {
+ // Changing the location will disable selection mode.
+ connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlChanged, this, [this]() {
+ setSelectionModeEnabled(false);
+ });
+
+ 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 SelectionMode::BottomBar(actionCollection, this);
+ connect(m_view, &DolphinView::selectionChanged, this, [this](const KFileItemList &selection) {
+ m_selectionModeBottomBar->slotSelectionChanged(selection, m_view->url());
+ });
+ connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::error, this, [this](const QString &errorMessage) {
+ showErrorMessage(errorMessage);
+ });
+ connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::selectionModeLeavingRequested, this, [this]() {
+ setSelectionModeEnabled(false);
+ });
+ m_topLayout->addWidget(m_selectionModeBottomBar, positionFor.selectionModeBottomBar, 0);
+ }
+ m_selectionModeBottomBar->resetContents(bottomBarContents);
+ if (bottomBarContents == SelectionMode::BottomBar::GeneralContents) {
+ m_selectionModeBottomBar->slotSelectionChanged(m_view->selectedItems(), m_view->url());
+ }
+
+ if (!wasEnabled) {
+ m_selectionModeTopBar->setVisible(true, WithAnimation);
+ m_selectionModeBottomBar->setVisible(true, WithAnimation);
+ Q_EMIT selectionModeChanged(true);
+ }
+}
+
+bool DolphinViewContainer::isSelectionModeEnabled() const
+{
+ const bool isEnabled = m_view->selectionMode();
+ 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() == 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() == SelectionMode::BottomBar::GeneralContents)));
+ return isEnabled;
+}
+
+void DolphinViewContainer::slotSplitTabDisabled()
+{
+ if (m_selectionModeBottomBar) {
+ m_selectionModeBottomBar->slotSplitTabDisabled();
+ }
+}
+
+
void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
{
if (msg.isEmpty()) {
m_urlNavigator->setLocationUrl(newUrl);
}
-#ifdef HAVE_KACTIVITIES
+#if HAVE_KACTIVITIES
m_activityResourceInstance->setUri(newUrl);
#endif
}
return;
}
- KIO::OpenUrlJob *job = new KIO::OpenUrlJob(item.targetUrl());
- job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoWarningHandlingEnabled, this));
+ KIO::OpenUrlJob *job = new KIO::OpenUrlJob(item.targetUrl(), item.mimetype());
+#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();