#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>
void DolphinSearchBox::setText(const QString &text)
{
- m_searchInput->setText(text);
+ if (m_searchInput->text() != text) {
+ m_searchInput->setText(text);
+ }
}
QString DolphinSearchBox::text() const
QWidget::keyReleaseEvent(event);
if (event->key() == Qt::Key_Escape) {
if (m_searchInput->text().isEmpty()) {
- Q_EMIT closeRequest();
+ emitCloseRequest();
} else {
m_searchInput->clear();
}
void DolphinSearchBox::slotSearchTextChanged(const QString &text)
{
if (text.isEmpty()) {
- m_startSearchTimer->stop();
+ // Restore URL when search box is cleared by closing and reopening the box.
+ emitCloseRequest();
+ Q_EMIT openRequest();
} else {
m_startSearchTimer->start();
}
void DolphinSearchBox::slotReturnPressed()
{
+ if (m_searchInput->text().isEmpty()) {
+ return;
+ }
+
emitSearchRequest();
Q_EMIT focusViewRequest();
}
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);
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);
loadSettings();
// The searching should be started automatically after the user did not change
- // the text within one second
+ // the text for a while
m_startSearchTimer = new QTimer(this);
m_startSearchTimer->setSingleShot(true);
- m_startSearchTimer->setInterval(1000);
+ m_startSearchTimer->setInterval(500);
connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest);
}
setSearchPath(QUrl::fromLocalFile(QDir::homePath()));
}
- // If the input box has focus, do not update to avoid messing with user typing
- if (!m_searchInput->hasFocus()) {
- setText(query.text());
- }
+ setText(query.text());
if (query.hasContentSearch()) {
m_contentButton->setChecked(true);