From 5875d8bff3e7413eb5088a9e2283728c4d204e75 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Sat, 11 Jan 2025 09:53:40 +0300 Subject: [PATCH] Allow multiple simultaneous searches PR #22127. --- src/gui/mainwindow.cpp | 2 +- src/gui/search/searchwidget.cpp | 74 +++++++++++++++++++++------------ src/gui/search/searchwidget.h | 14 +++---- src/gui/search/searchwidget.ui | 7 ++++ 4 files changed, 62 insertions(+), 35 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 4bc4e9b508dd..1dc459fdb111 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -739,7 +739,7 @@ void MainWindow::displaySearchTab(bool enable) if (!m_searchWidget) { m_searchWidget = new SearchWidget(app(), this); - connect(m_searchWidget, &SearchWidget::activeSearchFinished, this, [this](const bool failed) + connect(m_searchWidget, &SearchWidget::searchFinished, this, [this](const bool failed) { if (app()->desktopIntegration()->isNotificationsEnabled() && (currentTabWidget() != m_searchWidget)) { diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 9ede5cf8cf10..6784a3240503 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -88,6 +88,8 @@ SearchWidget::SearchWidget(IGUIApplication *app, QWidget *parent) , m_ui {new Ui::SearchWidget()} { m_ui->setupUi(this); + + m_ui->stopButton->hide(); m_ui->tabWidget->tabBar()->installEventFilter(this); const QString searchPatternHint = u"

" @@ -134,6 +136,9 @@ SearchWidget::SearchWidget(IGUIApplication *app, QWidget *parent) // Fill in category combobox onPluginChanged(); + connect(m_ui->pluginsButton, &QPushButton::clicked, this, &SearchWidget::pluginsButtonClicked); + connect(m_ui->searchButton, &QPushButton::clicked, this, &SearchWidget::searchButtonClicked); + connect(m_ui->stopButton, &QPushButton::clicked, this, &SearchWidget::stopButtonClicked); connect(m_ui->lineEditSearchPattern, &LineEdit::returnPressed, m_ui->searchButton, &QPushButton::click); connect(m_ui->lineEditSearchPattern, &LineEdit::textEdited, this, &SearchWidget::searchTextEdited); connect(m_ui->selectPlugin, qOverload(&QComboBox::currentIndexChanged) @@ -268,13 +273,27 @@ void SearchWidget::tabChanged(const int index) m_currentSearchTab = (index >= 0) ? static_cast(m_ui->tabWidget->widget(index)) : nullptr; + + if (!m_isNewQueryString) + { + if (m_currentSearchTab && (m_currentSearchTab->status() == SearchJobWidget::Status::Ongoing)) + { + m_ui->searchButton->hide(); + m_ui->stopButton->show(); + } + else + { + m_ui->stopButton->hide(); + m_ui->searchButton->show(); + } + } } void SearchWidget::selectMultipleBox([[maybe_unused]] const int index) { const auto itemText = m_ui->selectPlugin->itemData(m_ui->selectPlugin->currentIndex()).toString(); if (itemText == u"multi") - on_pluginsButton_clicked(); + pluginsButtonClicked(); } void SearchWidget::toggleFocusBetweenLineEdits() @@ -299,9 +318,13 @@ void SearchWidget::showTabMenu(const int index) searchJobWidget->status() != SearchJobWidget::Status::Ongoing) { menu->addAction(tr("Refresh"), this, [this, searchJobWidget] { refreshTab(searchJobWidget); }); - menu->addSeparator(); + } + else + { + menu->addAction(tr("Stop"), this, [searchJobWidget] { searchJobWidget->cancelSearch(); }); } + menu->addSeparator(); menu->addAction(tr("Close tab"), this, [this, index] { closeTab(index); }); menu->addAction(tr("Close all tabs"), this, &SearchWidget::closeAllTabs); @@ -309,7 +332,7 @@ void SearchWidget::showTabMenu(const int index) menu->popup(QCursor::pos()); } -void SearchWidget::on_pluginsButton_clicked() +void SearchWidget::pluginsButtonClicked() { auto *dlg = new PluginSelectDialog(SearchPluginManager::instance(), this); dlg->setAttribute(Qt::WA_DeleteOnClose); @@ -329,18 +352,8 @@ void SearchWidget::giveFocusToSearchInput() } // Function called when we click on search button -void SearchWidget::on_searchButton_clicked() +void SearchWidget::searchButtonClicked() { - if (m_activeSearchTab) - { - m_activeSearchTab->cancelSearch(); - if (!m_isNewQueryString) - { - m_ui->searchButton->setText(tr("Search")); - return; - } - } - m_isNewQueryString = false; const QString pattern = m_ui->lineEditSearchPattern->text().trimmed(); @@ -372,33 +385,38 @@ void SearchWidget::on_searchButton_clicked() connect(newTab, &SearchJobWidget::statusChanged, this, [this, newTab]() { tabStatusChanged(newTab); }); - m_ui->searchButton->setText(tr("Stop")); - m_activeSearchTab = newTab; tabStatusChanged(newTab); } -void SearchWidget::tabStatusChanged(QWidget *tab) +void SearchWidget::stopButtonClicked() +{ + m_currentSearchTab->cancelSearch(); + m_ui->stopButton->hide(); + m_ui->searchButton->show(); +} + +void SearchWidget::tabStatusChanged(SearchJobWidget *tab) { const int tabIndex = m_ui->tabWidget->indexOf(tab); m_ui->tabWidget->setTabToolTip(tabIndex, tab->statusTip()); m_ui->tabWidget->setTabIcon(tabIndex, UIThemeManager::instance()->getIcon( statusIconName(static_cast(tab)->status()))); - if ((tab == m_activeSearchTab) && (m_activeSearchTab->status() != SearchJobWidget::Status::Ongoing)) + if (tab->status() != SearchJobWidget::Status::Ongoing) { - emit activeSearchFinished(m_activeSearchTab->status() == SearchJobWidget::Status::Error); + if (tab == m_currentSearchTab) + { + m_ui->stopButton->hide(); + m_ui->searchButton->show(); + } - m_activeSearchTab = nullptr; - m_ui->searchButton->setText(tr("Search")); + emit searchFinished(tab->status() == SearchJobWidget::Status::Error); } } void SearchWidget::closeTab(const int index) { const QWidget *tab = m_ui->tabWidget->widget(index); - if (tab == m_activeSearchTab) - m_ui->searchButton->setText(tr("Search")); - delete tab; } @@ -419,8 +437,10 @@ void SearchWidget::refreshTab(SearchJobWidget *searchJobWidget) // Re-launch search auto *searchHandler = SearchPluginManager::instance()->startSearch(searchJobWidget->searchPattern(), selectedCategory(), selectedPlugins()); searchJobWidget->assignSearchHandler(searchHandler); - if (!m_isNewQueryString) - m_ui->searchButton->setText(tr("Stop")); - m_activeSearchTab = searchJobWidget; + if (!m_isNewQueryString && (m_ui->tabWidget->currentWidget() == searchJobWidget)) + { + m_ui->searchButton->hide(); + m_ui->stopButton->show(); + } tabStatusChanged(searchJobWidget); } diff --git a/src/gui/search/searchwidget.h b/src/gui/search/searchwidget.h index d5bc59e940bb..8e076008bec2 100644 --- a/src/gui/search/searchwidget.h +++ b/src/gui/search/searchwidget.h @@ -57,16 +57,17 @@ class SearchWidget : public GUIApplicationComponent void giveFocusToSearchInput(); signals: - void activeSearchFinished(bool failed); - -private slots: - void on_searchButton_clicked(); - void on_pluginsButton_clicked(); + void searchFinished(bool failed); private: bool eventFilter(QObject *object, QEvent *event) override; + + void pluginsButtonClicked(); + void searchButtonClicked(); + void stopButtonClicked(); + void tabChanged(int index); - void tabStatusChanged(QWidget *tab); + void tabStatusChanged(SearchJobWidget *tab); void closeTab(int index); void closeAllTabs(); @@ -86,6 +87,5 @@ private slots: Ui::SearchWidget *m_ui = nullptr; QPointer m_currentSearchTab; // Selected tab - QPointer m_activeSearchTab; // Tab with running search bool m_isNewQueryString = false; }; diff --git a/src/gui/search/searchwidget.ui b/src/gui/search/searchwidget.ui index cc3f0e7f57d5..54442b20106c 100644 --- a/src/gui/search/searchwidget.ui +++ b/src/gui/search/searchwidget.ui @@ -52,6 +52,13 @@ + + + + Stop + + +