From 796332d63a32e6fdea83001f4a14c03a8b81228b Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Fri, 23 Feb 2024 09:45:53 +0000 Subject: [PATCH] Avoid searching for the knetattach service on startup The installed services might change while Dolphin is running, so it is better to only search when they are actually needed instead. The very first time such a search happens (e.g. after updating the system), is also somewhat slow, which could slow down the very first Dolphin startup. This commit might also produce a very slight general startup speed improvement. However, the measured change is within the margin of error. --- src/dolphinnavigatorswidgetaction.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dolphinnavigatorswidgetaction.cpp b/src/dolphinnavigatorswidgetaction.cpp index 865c493bcb..f45589dbb2 100644 --- a/src/dolphinnavigatorswidgetaction.cpp +++ b/src/dolphinnavigatorswidgetaction.cpp @@ -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; }