X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/38c34eeca315c7be58e65d4d3fb72aaf7b866719..aeb704851d3b33f88eb601d597c2b0743d4e08df:/src/dolphinnavigatorswidgetaction.cpp diff --git a/src/dolphinnavigatorswidgetaction.cpp b/src/dolphinnavigatorswidgetaction.cpp index 47a2a2303..f45589dbb 100644 --- a/src/dolphinnavigatorswidgetaction.cpp +++ b/src/dolphinnavigatorswidgetaction.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project - SPDX-FileCopyrightText: 2020 Felix Ernst + SPDX-FileCopyrightText: 2020 Felix Ernst SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ @@ -42,10 +42,10 @@ DolphinNavigatorsWidgetAction::DolphinNavigatorsWidgetAction(QWidget *parent) void DolphinNavigatorsWidgetAction::adjustSpacing() { - m_previousWindowWidth = parentWidget()->window()->width(); + m_previousWindowWidth = qobject_cast(parent())->window()->width(); auto viewGeometries = m_viewGeometriesHelper.viewGeometries(); const int widthOfSplitterPrimary = viewGeometries.globalXOfPrimary + viewGeometries.widthOfPrimary - viewGeometries.globalXOfNavigatorsWidget; - const QList splitterSizes = {widthOfSplitterPrimary, m_splitter->width() - widthOfSplitterPrimary}; + const QList splitterSizes = {widthOfSplitterPrimary, m_splitter->width() - widthOfSplitterPrimary - m_splitter->handleWidth()}; m_splitter->setSizes(splitterSizes); // primary side of m_splitter @@ -253,8 +253,8 @@ QPushButton *DolphinNavigatorsWidgetAction::newNetworkFolderButton(const Dolphin { auto networkFolderButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-add")), i18nc("@action:button", "Add Network Folder"), parent); networkFolderButton->setFlat(true); - KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("org.kde.knetattach")); - connect(networkFolderButton, &QPushButton::clicked, this, [networkFolderButton, service]() { + connect(networkFolderButton, &QPushButton::clicked, this, [networkFolderButton]() { + const KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("org.kde.knetattach")); auto *job = new KIO::ApplicationLauncherJob(service, networkFolderButton); auto *delegate = new KNotificationJobUiDelegate; delegate->setAutoErrorHandlingEnabled(true); @@ -262,8 +262,14 @@ QPushButton *DolphinNavigatorsWidgetAction::newNetworkFolderButton(const Dolphin job->start(); }); networkFolderButton->hide(); - connect(urlNavigator, &KUrlNavigator::urlChanged, this, [networkFolderButton, urlNavigator, service]() { - networkFolderButton->setVisible(service && urlNavigator->locationUrl().scheme() == QLatin1String("remote")); + connect(urlNavigator, &KUrlNavigator::urlChanged, this, [networkFolderButton, urlNavigator]() { + if (urlNavigator->locationUrl().scheme() == QLatin1String("remote")) { + // Looking up a service can be a bit slow, so we only do it now when it becomes necessary. + const KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("org.kde.knetattach")); + networkFolderButton->setVisible(service); + } else { + networkFolderButton->setVisible(false); + } }); return networkFolderButton; } @@ -298,7 +304,7 @@ DolphinNavigatorsWidgetAction::ViewGeometriesHelper::ViewGeometriesHelper(QWidge bool DolphinNavigatorsWidgetAction::ViewGeometriesHelper::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::Resize) { - if (m_navigatorsWidgetAction->parentWidget()->window()->width() != m_navigatorsWidgetAction->m_previousWindowWidth) { + if (qobject_cast(m_navigatorsWidgetAction->parent())->window()->width() != m_navigatorsWidgetAction->m_previousWindowWidth) { // The window is being resized which means not all widgets have gotten their new sizes yet. // Let's wait a bit so the sizes of the navigatorsWidget and the viewContainers have all // had a chance to be updated. @@ -357,3 +363,5 @@ DolphinNavigatorsWidgetAction::ViewGeometriesHelper::Geometries DolphinNavigator } return geometries; } + +#include "moc_dolphinnavigatorswidgetaction.cpp"