Commit 2d4d2ce9 authored by Felix Ernst's avatar Felix Ernst Committed by Elvis Angelaccio

Adress most of the second round of Angelaccio's review comments

This commit applies most suggestions which were made on the MR.
Most notably the DolphinUrlNavigator class is split up which leads to
the creation of a DolphinUrlNavigatorsController class.

Additionally some minor coding style and const correctness changes are
included.

The error value of cached integers is changed from -1 to INT_MIN
because situations could come up in which -1 would be a valid value.
parent 42023831
......@@ -210,6 +210,7 @@ set(dolphinstatic_SRCS
dolphintabpage.cpp
dolphintabwidget.cpp
dolphinurlnavigator.cpp
dolphinurlnavigatorscontroller.cpp
trash/dolphintrash.cpp
filterbar/filterbar.cpp
panels/places/placespanel.cpp
......
......@@ -14,8 +14,10 @@
#include "dolphinbookmarkhandler.h"
#include "dolphindockwidget.h"
#include "dolphincontextmenu.h"
#include "dolphinnavigatorswidgetaction.h"
#include "dolphinnewfilemenu.h"
#include "dolphinrecenttabsmenu.h"
#include "dolphinurlnavigatorscontroller.h"
#include "dolphinviewcontainer.h"
#include "dolphintabpage.h"
#include "middleclickactioneventfilter.h"
......@@ -31,7 +33,6 @@
#include "views/draganddrophelper.h"
#include "views/viewproperties.h"
#include "views/dolphinnewfilemenuobserver.h"
#include "dolphinnavigatorswidgetaction.h"
#include "dolphin_generalsettings.h"
#include <KActionCollection>
......@@ -106,8 +107,7 @@ DolphinMainWindow::DolphinMainWindow() :
m_placesPanel(nullptr),
m_tearDownFromPlacesRequested(false),
m_backAction(nullptr),
m_forwardAction(nullptr),
m_updateHistoryConnection{}
m_forwardAction(nullptr)
{
Q_INIT_RESOURCE(dolphin);
......@@ -210,7 +210,7 @@ DolphinMainWindow::~DolphinMainWindow()
{
}
QVector<DolphinViewContainer *> DolphinMainWindow::viewContainers() const
QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
{
QVector<DolphinViewContainer*> viewContainers;
......@@ -927,14 +927,14 @@ void DolphinMainWindow::goHome()
void DolphinMainWindow::goBackInNewTab()
{
KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
const KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
const int index = urlNavigator->historyIndex() + 1;
openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
}
void DolphinMainWindow::goForwardInNewTab()
{
KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
const KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
const int index = urlNavigator->historyIndex() - 1;
openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
}
......@@ -1066,7 +1066,8 @@ void DolphinMainWindow::editSettings()
const QUrl url = container->url();
DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, &DolphinUrlNavigator::slotReadSettings);
connect(settingsDialog, &DolphinSettingsDialog::settingsChanged,
&DolphinUrlNavigatorsController::slotReadSettings);
settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
settingsDialog->show();
m_settingsDialog = settingsDialog;
......@@ -1898,14 +1899,14 @@ void DolphinMainWindow::setupDockWidgets()
connect(this, &DolphinMainWindow::urlChanged,
m_placesPanel, &PlacesPanel::setUrl);
connect(placesDock, &DolphinDockWidget::visibilityChanged,
&DolphinUrlNavigator::slotPlacesPanelVisibilityChanged);
&DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
connect(this, &DolphinMainWindow::settingsChanged,
m_placesPanel, &PlacesPanel::readSettings);
connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
DolphinUrlNavigator::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
actionShowAllPlaces->setCheckable(true);
......@@ -2176,13 +2177,13 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigators")));
KUrlNavigator *navigator = m_tabWidget->currentTabPage()->primaryViewActive() ?
navigators->primaryUrlNavigator() :
navigators->secondaryUrlNavigator();
const KUrlNavigator *navigator = m_tabWidget->currentTabPage()->primaryViewActive() ?
navigators->primaryUrlNavigator() :
navigators->secondaryUrlNavigator();
connect(navigator, &KUrlNavigator::urlChanged,
this, &DolphinMainWindow::changeUrl);
QAction* editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
editableLocactionAction->setChecked(navigator->isUrlEditable());
connect(navigator, &KUrlNavigator::editableStateChanged,
this, &DolphinMainWindow::slotEditableStateChanged);
......
......@@ -18,18 +18,19 @@
#include <QPushButton>
#include <QSplitter>
#include <limits>
DolphinNavigatorsWidgetAction::DolphinNavigatorsWidgetAction(QWidget *parent) :
QWidgetAction{parent},
m_splitter{new QSplitter(Qt::Horizontal)},
m_adjustSpacingTimer{new QTimer(this)},
m_globalXOfPrimary{-1},
m_widthOfPrimary{-1},
m_globalXOfSecondary{-1},
m_widthOfSecondary{-1}
m_globalXOfSplitter{INT_MIN},
m_globalXOfPrimary{INT_MIN},
m_widthOfPrimary{INT_MIN},
m_globalXOfSecondary{INT_MIN},
m_widthOfSecondary{INT_MIN}
{
setText(i18nc(
"@action:inmenu When split view is enabled there are two otherwise one.",
"Url Navigator(s)"));
updateText();
setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
m_splitter->setChildrenCollapsible(false);
......@@ -76,12 +77,13 @@ void DolphinNavigatorsWidgetAction::createSecondaryUrlNavigator()
Q_ASSERT(m_splitter->count() == 1);
m_splitter->addWidget(createNavigatorWidget(Secondary));
Q_ASSERT(m_splitter->count() == 2);
updateText();
}
void DolphinNavigatorsWidgetAction::followViewContainerGeometry(
int globalXOfPrimary, int widthOfPrimary)
{
followViewContainersGeometry(globalXOfPrimary, widthOfPrimary, -1, -1);
followViewContainersGeometry(globalXOfPrimary, widthOfPrimary, INT_MIN, INT_MIN);
}
void DolphinNavigatorsWidgetAction::followViewContainersGeometry(
......@@ -99,7 +101,7 @@ void DolphinNavigatorsWidgetAction::followViewContainersGeometry(
DolphinUrlNavigator* DolphinNavigatorsWidgetAction::primaryUrlNavigator() const
{
Q_ASSERT(m_splitter);
return static_cast<DolphinUrlNavigator *>(m_splitter->widget(0)->findChild<KUrlNavigator *>());
return m_splitter->widget(0)->findChild<DolphinUrlNavigator *>();
}
DolphinUrlNavigator* DolphinNavigatorsWidgetAction::secondaryUrlNavigator() const
......@@ -108,7 +110,7 @@ DolphinUrlNavigator* DolphinNavigatorsWidgetAction::secondaryUrlNavigator() cons
if (m_splitter->count() < 2) {
return nullptr;
}
return static_cast<DolphinUrlNavigator *>(m_splitter->widget(1)->findChild<KUrlNavigator *>());
return m_splitter->widget(1)->findChild<DolphinUrlNavigator *>();
}
void DolphinNavigatorsWidgetAction::setSecondaryNavigatorVisible(bool visible)
......@@ -121,10 +123,14 @@ void DolphinNavigatorsWidgetAction::setSecondaryNavigatorVisible(bool visible)
// Fix an unlikely event of wrong trash button visibility.
emptyTrashButton(Secondary)->setVisible(false);
}
updateText();
}
void DolphinNavigatorsWidgetAction::adjustSpacing()
{
Q_ASSERT(m_globalXOfSplitter != INT_MIN);
Q_ASSERT(m_globalXOfPrimary != INT_MIN);
Q_ASSERT(m_widthOfPrimary != INT_MIN);
const int widthOfSplitterPrimary = m_globalXOfPrimary + m_widthOfPrimary - m_globalXOfSplitter;
const QList<int> splitterSizes = {widthOfSplitterPrimary,
m_splitter->width() - widthOfSplitterPrimary};
......@@ -156,8 +162,8 @@ void DolphinNavigatorsWidgetAction::adjustSpacing()
spacing(Primary, Trailing)->setFixedWidth(trailingSpacing);
// secondary side of m_splitter
if (m_globalXOfSecondary == -1) {
Q_ASSERT(m_widthOfSecondary == -1);
if (m_globalXOfSecondary == INT_MIN) {
Q_ASSERT(m_widthOfSecondary == INT_MIN);
return;
}
spacing(Primary, Trailing)->setFixedWidth(0);
......@@ -244,3 +250,10 @@ QWidget *DolphinNavigatorsWidgetAction::spacing(Side side, Position position) co
}
return m_splitter->widget(sideIndex)->layout()->itemAt(2)->widget();
}
void DolphinNavigatorsWidgetAction::updateText()
{
const int urlNavigatorsAmount = m_splitter->count() > 1 && m_splitter->widget(1)->isVisible() ?
2 : 1;
setText(i18ncp("@action:inmenu", "Url Navigator", "Url Navigators", urlNavigatorsAmount));
}
......@@ -38,14 +38,6 @@ class DolphinNavigatorsWidgetAction : public QWidgetAction
{
Q_OBJECT
/**
* In Left-to-right languages the Primary side will be the left one.
*/
enum Side {
Primary,
Secondary
};
public:
DolphinNavigatorsWidgetAction(QWidget *parent = nullptr);
......@@ -95,7 +87,7 @@ public:
*/
void setSecondaryNavigatorVisible(bool visible);
protected:
private:
/**
* Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers.
* This can only work nicely if up-to-date geometry of ViewContainers is cached so
......@@ -103,6 +95,13 @@ protected:
*/
void adjustSpacing();
/**
* In Left-to-right languages the Primary side will be the left one.
*/
enum Side {
Primary,
Secondary
};
/**
* Used to create the navigatorWidgets for both sides of the QSplitter.
*/
......@@ -133,6 +132,11 @@ protected:
*/
QWidget *spacing(Side side, Position position) const;
/**
* Sets this action's text depending on the amount of visible UrlNavigators.
*/
void updateText();
/**
* The defaultWidget() of this QWidgetAction.
*/
......
......@@ -8,7 +8,6 @@
#include "dolphin_generalsettings.h"
#include "dolphintabbar.h"
#include "dolphintabpage.h"
#include "dolphinviewcontainer.h"
#include <KConfigGroup>
......
......@@ -8,11 +8,11 @@
#define DOLPHIN_TAB_WIDGET_H
#include "dolphinnavigatorswidgetaction.h"
#include "dolphintabpage.h"
#include <QTabWidget>
#include <QUrl>
class DolphinTabPage;
class DolphinViewContainer;
class KConfigGroup;
......
......@@ -9,6 +9,7 @@
#include "dolphin_generalsettings.h"
#include "dolphinplacesmodelsingleton.h"
#include "dolphinurlnavigatorscontroller.h"
#include "global.h"
#include <KUrlComboBox>
......@@ -19,24 +20,17 @@
#include <QLineEdit>
DolphinUrlNavigator::DolphinUrlNavigator(QWidget *parent) :
KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), QUrl(), parent)
{
init();
}
DolphinUrlNavigator(QUrl(), parent)
{}
DolphinUrlNavigator::DolphinUrlNavigator(const QUrl &url, QWidget *parent) :
KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url, parent)
{
init();
}
void DolphinUrlNavigator::init()
{
const GeneralSettings* settings = GeneralSettings::self();
setUrlEditable(settings->editableUrl());
setShowFullPath(settings->showFullPath());
setHomeUrl(Dolphin::homeUrl());
setPlacesSelectorVisible(s_placesSelectorVisible);
setPlacesSelectorVisible(DolphinUrlNavigatorsController::placesSelectorVisible());
editor()->setCompletionMode(KCompletion::CompletionMode(settings->urlCompletionMode()));
setWhatsThis(xi18nc("@info:whatsthis location bar",
"<para>This describes the location of the files and folders "
......@@ -51,22 +45,21 @@ void DolphinUrlNavigator::init()
"<link url='help:/dolphin/location-bar.html'>click here</link>. "
"This will open the dedicated page in the Handbook.</para>"));
s_instances.push_front(this);
DolphinUrlNavigatorsController::registerDolphinUrlNavigator(this);
connect(this, &DolphinUrlNavigator::returnPressed,
this, &DolphinUrlNavigator::slotReturnPressed);
connect(editor(), &KUrlComboBox::completionModeChanged,
this, DolphinUrlNavigator::setCompletionMode);
DolphinUrlNavigatorsController::setCompletionMode);
}
DolphinUrlNavigator::~DolphinUrlNavigator()
{
s_instances.remove(this);
DolphinUrlNavigatorsController::unregisterDolphinUrlNavigator(this);
}
QSize DolphinUrlNavigator::sizeHint() const
{
// Change sizeHint() in KUrlNavigator instead.
if (isUrlEditable()) {
return editor()->lineEdit()->sizeHint();
}
......@@ -110,49 +103,9 @@ void DolphinUrlNavigator::setVisualState(const VisualState& visualState)
}
}
void DolphinUrlNavigator::slotReadSettings()
{
// The startup settings should (only) get applied if they have been
// modified by the user. Otherwise keep the (possibly) different current
// settings of the URL navigators and split view.
if (GeneralSettings::modifiedStartupSettings()) {
for (DolphinUrlNavigator *urlNavigator : s_instances) {
urlNavigator->setUrlEditable(GeneralSettings::editableUrl());
urlNavigator->setShowFullPath(GeneralSettings::showFullPath());
urlNavigator->setHomeUrl(Dolphin::homeUrl());
}
}
}
void DolphinUrlNavigator::slotReturnPressed()
{
if (!GeneralSettings::editableUrl()) {
setUrlEditable(false);
}
}
void DolphinUrlNavigator::slotPlacesPanelVisibilityChanged(bool visible)
{
// The places-selector from the URL navigator should only be shown
// if the places dock is invisible
s_placesSelectorVisible = !visible;
for (DolphinUrlNavigator *urlNavigator : s_instances) {
urlNavigator->setPlacesSelectorVisible(s_placesSelectorVisible);
}
}
void DolphinUrlNavigator::setCompletionMode(const KCompletion::CompletionMode completionMode)
{
if (completionMode != GeneralSettings::urlCompletionMode())
{
GeneralSettings::setUrlCompletionMode(completionMode);
for (const DolphinUrlNavigator *urlNavigator : s_instances)
{
urlNavigator->editor()->setCompletionMode(completionMode);
}
}
}
std::forward_list<DolphinUrlNavigator *> DolphinUrlNavigator::s_instances;
bool DolphinUrlNavigator::s_placesSelectorVisible = true;
......@@ -8,17 +8,12 @@
#ifndef DOLPHINURLNAVIGATOR_H
#define DOLPHINURLNAVIGATOR_H
#include <KCompletion>
#include <KUrlNavigator>
#include <forward_list>
class KToggleAction;
/**
* @brief Extends KUrlNavigator in a Dolphin-specific way
* @brief Extends KUrlNavigator in a Dolphin-specific way.
*
* Makes sure that Dolphin preferences, settings and settings changes are
* Makes sure that Dolphin preferences and settings are
* applied to all constructed DolphinUrlNavigators.
*
* @see KUrlNavigator
......@@ -42,12 +37,7 @@ public:
virtual ~DolphinUrlNavigator();
/**
* This method is needed so the DolphinNavigatorWidgetAction knows when there is not enough
* space to neatly align the UrlNavigator with the ViewContainers. Unfortunately KUrlNavigator
* does not have a useful sizeHint() currently. It would make more sense to change
* KUrlNavigator instead.
*/
// TODO: Fix KUrlNavigator::sizeHint() instead.
QSize sizeHint() const override;
/**
......@@ -73,39 +63,11 @@ public:
void setVisualState(const VisualState &visualState);
public slots:
/**
* Refreshes all DolphinUrlNavigators to get synchronized with the
* Dolphin settings if they were changed.
*/
static void slotReadSettings();
/**
* Switches to "breadcrumb" mode if the editable mode is not set to be
* preferred in the Dolphin settings.
*/
void slotReturnPressed();
static void slotPlacesPanelVisibilityChanged(bool visible);
protected:
/**
* Constructor-helper function
*/
void init();
protected slots:
/**
* Sets the completion mode for all DolphinUrlNavigators
* and saves it in settings.
*/
static void setCompletionMode(const KCompletion::CompletionMode completionMode);
protected:
/** Contains all currently constructed DolphinUrlNavigators */
static std::forward_list<DolphinUrlNavigator *> s_instances;
/** Caches the (negated) places panel visibility */
static bool s_placesSelectorVisible;
};
#endif // DOLPHINURLNAVIGATOR_H
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "dolphinurlnavigatorscontroller.h"
#include "dolphin_generalsettings.h"
#include "dolphinurlnavigator.h"
#include "global.h"
#include <KUrlComboBox>
void DolphinUrlNavigatorsController::slotReadSettings()
{
// The startup settings should (only) get applied if they have been
// modified by the user. Otherwise keep the (possibly) different current
// settings of the URL navigators and split view.
if (GeneralSettings::modifiedStartupSettings()) {
for (DolphinUrlNavigator *urlNavigator : s_instances) {
urlNavigator->setUrlEditable(GeneralSettings::editableUrl());
urlNavigator->setShowFullPath(GeneralSettings::showFullPath());
urlNavigator->setHomeUrl(Dolphin::homeUrl());
}
}
}
void DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(bool visible)
{
// The places-selector from the URL navigator should only be shown
// if the places dock is invisible
s_placesSelectorVisible = !visible;
for (DolphinUrlNavigator *urlNavigator : s_instances) {
urlNavigator->setPlacesSelectorVisible(s_placesSelectorVisible);
}
}
bool DolphinUrlNavigatorsController::placesSelectorVisible()
{
return s_placesSelectorVisible;
}
void DolphinUrlNavigatorsController::registerDolphinUrlNavigator(DolphinUrlNavigator *dolphinUrlNavigator)
{
s_instances.push_front(dolphinUrlNavigator);
}
void DolphinUrlNavigatorsController::unregisterDolphinUrlNavigator(DolphinUrlNavigator *dolphinUrlNavigator)
{
s_instances.remove(dolphinUrlNavigator);
}
void DolphinUrlNavigatorsController::setCompletionMode(const KCompletion::CompletionMode completionMode)
{
if (completionMode != GeneralSettings::urlCompletionMode()) {
GeneralSettings::setUrlCompletionMode(completionMode);
for (const DolphinUrlNavigator *urlNavigator : s_instances) {
urlNavigator->editor()->setCompletionMode(completionMode);
}
}
}
std::forward_list<DolphinUrlNavigator *> DolphinUrlNavigatorsController::s_instances;
bool DolphinUrlNavigatorsController::s_placesSelectorVisible = true;
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef DOLPHINURLNAVIGATORSCONTROLLER_H
#define DOLPHINURLNAVIGATORSCONTROLLER_H
#include <KCompletion>
#include <QObject>
#include <forward_list>
class DolphinUrlNavigator;
/**
* @brief A controller managing all DolphinUrlNavigators.
*
* This class is used to apply settings changes to all constructed DolphinUrlNavigators.
*
* @see DolphinUrlNavigator
*/
class DolphinUrlNavigatorsController : public QObject
{
Q_OBJECT
public:
DolphinUrlNavigatorsController() = delete;
public slots:
/**
* Refreshes all DolphinUrlNavigators to get synchronized with the
* Dolphin settings if they were changed.
*/
static void slotReadSettings();
static void slotPlacesPanelVisibilityChanged(bool visible);
private:
/**
* @return wether the places selector of DolphinUrlNavigators should be visible.
*/
static bool placesSelectorVisible();
/**
* Adds \p dolphinUrlNavigator to the list of DolphinUrlNavigators
* controlled by this class.
*/
static void registerDolphinUrlNavigator(DolphinUrlNavigator *dolphinUrlNavigator);
/**
* Removes \p dolphinUrlNavigator from the list of DolphinUrlNavigators
* controlled by this class.
*/
static void unregisterDolphinUrlNavigator(DolphinUrlNavigator *dolphinUrlNavigator);
private slots:
/**
* Sets the completion mode for all DolphinUrlNavigators and saves it in settings.
*/
static void setCompletionMode(const KCompletion::CompletionMode completionMode);
private:
/** Contains all currently constructed DolphinUrlNavigators */
static std::forward_list<DolphinUrlNavigator *> s_instances;
/** Caches the (negated) places panel visibility */
static bool s_placesSelectorVisible;
friend class DolphinUrlNavigator;
};
#endif // DOLPHINURLNAVIGATORSCONTROLLER_H
......@@ -53,8 +53,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
m_statusBar(nullptr),
m_statusBarTimer(nullptr),
m_statusBarTimestamp(),
m_autoGrabFocus(true),
m_urlNavigatorVisualState{}
m_autoGrabFocus(true)
#ifdef HAVE_KACTIVITIES
, m_activityResourceInstance(nullptr)
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment