]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/search/dolphinsearchbox.cpp
Port away from KMoreTools
[dolphin.git] / src / search / dolphinsearchbox.cpp
index a09f252937e7853451a4fac160646636d4fd217c..dfd733e5da2093eb5d496a91a0135275fb8d6a43 100644 (file)
 #include "dolphinquery.h"
 
 #include "config-dolphin.h"
+#include <KIO/ApplicationLauncherJob>
 #include <KLocalizedString>
-#include <KMoreToolsMenuFactory>
 #include <KSeparator>
+#include <KService>
 #if HAVE_BALOO
 #include <Baloo/IndexerConfig>
 #include <Baloo/Query>
@@ -265,9 +266,7 @@ void DolphinSearchBox::slotSearchTextChanged(const QString &text)
     if (text.isEmpty()) {
         // Restore URL when search box is cleared by closing and reopening the box.
         emitCloseRequest();
-        QTimer::singleShot(0, this, [this] {
-            Q_EMIT openRequest();
-        });
+        Q_EMIT openRequest();
     } else {
         m_startSearchTimer->start();
     }
@@ -397,18 +396,24 @@ void DolphinSearchBox::init()
     searchLocationGroup->addButton(m_fromHereButton);
     searchLocationGroup->addButton(m_everywhereButton);
 
-    auto moreSearchToolsButton = new QToolButton(this);
-    moreSearchToolsButton->setAutoRaise(true);
-    moreSearchToolsButton->setPopupMode(QToolButton::InstantPopup);
-    moreSearchToolsButton->setIcon(QIcon::fromTheme("arrow-down-double"));
-    moreSearchToolsButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
-    moreSearchToolsButton->setText(i18n("More Search Tools"));
-    moreSearchToolsButton->setMenu(new QMenu(this));
-    connect(moreSearchToolsButton->menu(), &QMenu::aboutToShow, moreSearchToolsButton->menu(), [this, moreSearchToolsButton]() {
-        m_menuFactory.reset(new KMoreToolsMenuFactory("dolphin/search-tools"));
-        moreSearchToolsButton->menu()->clear();
-        m_menuFactory->fillMenuFromGroupingNames(moreSearchToolsButton->menu(), {"files-find"}, this->m_searchPath);
-    });
+    KService::Ptr kfind = KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
+
+    QToolButton *kfindToolsButton = nullptr;
+    if (kfind) {
+        kfindToolsButton = new QToolButton(this);
+        kfindToolsButton->setAutoRaise(true);
+        kfindToolsButton->setPopupMode(QToolButton::InstantPopup);
+        kfindToolsButton->setIcon(QIcon::fromTheme("arrow-down-double"));
+        kfindToolsButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+        kfindToolsButton->setText(i18n("Open %1", kfind->name()));
+        kfindToolsButton->setIcon(QIcon::fromTheme(kfind->icon()));
+
+        connect(kfindToolsButton, &QToolButton::clicked, this, [this, kfind] {
+            auto *job = new KIO::ApplicationLauncherJob(kfind);
+            job->setUrls({m_searchPath});
+            job->start();
+        });
+    }
 
     // Create "Facets" widget
     m_facetsWidget = new DolphinFacetsWidget(this);
@@ -431,7 +436,9 @@ void DolphinSearchBox::init()
     optionsLayout->addWidget(m_fromHereButton);
     optionsLayout->addWidget(m_everywhereButton);
     optionsLayout->addWidget(new KSeparator(Qt::Vertical, this));
-    optionsLayout->addWidget(moreSearchToolsButton);
+    if (kfindToolsButton) {
+        optionsLayout->addWidget(kfindToolsButton);
+    }
     optionsLayout->addStretch(1);
 
     m_optionsScrollArea = new QScrollArea(this);