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.
dolphintabpage.cpp
dolphintabwidget.cpp
dolphinurlnavigator.cpp
+ dolphinurlnavigatorscontroller.cpp
trash/dolphintrash.cpp
filterbar/filterbar.cpp
panels/places/placespanel.cpp
#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"
#include "views/draganddrophelper.h"
#include "views/viewproperties.h"
#include "views/dolphinnewfilemenuobserver.h"
-#include "dolphinnavigatorswidgetaction.h"
#include "dolphin_generalsettings.h"
#include <KActionCollection>
m_placesPanel(nullptr),
m_tearDownFromPlacesRequested(false),
m_backAction(nullptr),
- m_forwardAction(nullptr),
- m_updateHistoryConnection{}
+ m_forwardAction(nullptr)
{
Q_INIT_RESOURCE(dolphin);
{
}
-QVector<DolphinViewContainer *> DolphinMainWindow::viewContainers() const
+QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
{
QVector<DolphinViewContainer*> viewContainers;
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));
}
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;
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);
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);
#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);
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(
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
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)
// 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};
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);
}
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));
+}
{
Q_OBJECT
- /**
- * In Left-to-right languages the Primary side will be the left one.
- */
- enum Side {
- Primary,
- Secondary
- };
-
public:
DolphinNavigatorsWidgetAction(QWidget *parent = nullptr);
*/
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
*/
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.
*/
*/
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.
*/
#include "dolphin_generalsettings.h"
#include "dolphintabbar.h"
-#include "dolphintabpage.h"
#include "dolphinviewcontainer.h"
#include <KConfigGroup>
#define DOLPHIN_TAB_WIDGET_H
#include "dolphinnavigatorswidgetaction.h"
+#include "dolphintabpage.h"
#include <QTabWidget>
#include <QUrl>
-class DolphinTabPage;
class DolphinViewContainer;
class KConfigGroup;
#include "dolphin_generalsettings.h"
#include "dolphinplacesmodelsingleton.h"
+#include "dolphinurlnavigatorscontroller.h"
#include "global.h"
#include <KUrlComboBox>
#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 "
"<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();
}
}
}
-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;
#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
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;
/**
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
--- /dev/null
+/*
+ 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;
--- /dev/null
+/*
+ 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
m_statusBar(nullptr),
m_statusBarTimer(nullptr),
m_statusBarTimestamp(),
- m_autoGrabFocus(true),
- m_urlNavigatorVisualState{}
+ m_autoGrabFocus(true)
#ifdef HAVE_KACTIVITIES
, m_activityResourceInstance(nullptr)
#endif