X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f510339f033658eae27f8400bf042b78b36f82f2..2cd3d58eec5695899c26ca66a631fb79867b6584:/src/search/dolphinsearchbox.cpp diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 9df417c4f..dfd733e5d 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -13,9 +13,10 @@ #include "dolphinquery.h" #include "config-dolphin.h" +#include #include -#include #include +#include #if HAVE_BALOO #include #include @@ -60,7 +61,9 @@ DolphinSearchBox::~DolphinSearchBox() void DolphinSearchBox::setText(const QString &text) { - m_searchInput->setText(text); + if (m_searchInput->text() != text) { + m_searchInput->setText(text); + } } QString DolphinSearchBox::text() const @@ -201,7 +204,7 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent *event) QWidget::keyReleaseEvent(event); if (event->key() == Qt::Key_Escape) { if (m_searchInput->text().isEmpty()) { - Q_EMIT closeRequest(); + emitCloseRequest(); } else { m_searchInput->clear(); } @@ -261,7 +264,9 @@ void DolphinSearchBox::slotConfigurationChanged() 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(); } @@ -270,6 +275,10 @@ void DolphinSearchBox::slotSearchTextChanged(const QString &text) void DolphinSearchBox::slotReturnPressed() { + if (m_searchInput->text().isEmpty()) { + return; + } + emitSearchRequest(); Q_EMIT focusViewRequest(); } @@ -387,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); @@ -421,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); @@ -443,10 +460,10 @@ void DolphinSearchBox::init() 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); } @@ -496,10 +513,7 @@ void DolphinSearchBox::updateFromQuery(const DolphinQuery &query) 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);