Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to reuse existing search term #22148

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gui/search/searchjobwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ void SearchJobWidget::cancelSearch()
return;

m_searchHandler->cancelSearch();
setStatus(Status::Aborted);
}

void SearchJobWidget::downloadTorrents(const AddTorrentOption option)
Expand Down
102 changes: 64 additions & 38 deletions src/gui/search/searchwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,23 @@ SearchWidget::SearchWidget(IGUIApplication *app, QWidget *parent)
m_ui->tabWidget->setIconSize(iconSize);
#endif
connect(m_ui->tabWidget, &QTabWidget::tabCloseRequested, this, &SearchWidget::closeTab);
connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SearchWidget::tabChanged);
connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SearchWidget::currentTabChanged);

connect(m_ui->tabWidget, &QTabWidget::tabBarDoubleClicked, this, [this](const int tabIndex)
{
if (tabIndex < 0)
return;

// Reset current search pattern
auto *searchJobWidget = static_cast<SearchJobWidget *>(m_ui->tabWidget->widget(tabIndex));
const QString pattern = searchJobWidget->searchPattern();
if (pattern != m_ui->lineEditSearchPattern->text())
{
m_ui->lineEditSearchPattern->setText(pattern);
m_isNewQueryString = false;
adjustSearchButton();
}
});

const auto *searchManager = SearchPluginManager::instance();
const auto onPluginChanged = [this]()
Expand Down Expand Up @@ -162,16 +178,19 @@ bool SearchWidget::eventFilter(QObject *object, QEvent *event)

const auto *mouseEvent = static_cast<QMouseEvent *>(event);
const int tabIndex = m_ui->tabWidget->tabBar()->tabAt(mouseEvent->pos());
if ((mouseEvent->button() == Qt::MiddleButton) && (tabIndex >= 0))
{
closeTab(tabIndex);
return true;
}

if (mouseEvent->button() == Qt::RightButton)
if (tabIndex >= 0)
{
showTabMenu(tabIndex);
return true;
if (mouseEvent->button() == Qt::MiddleButton)
{
closeTab(tabIndex);
return true;
}

if (mouseEvent->button() == Qt::RightButton)
{
showTabMenu(tabIndex);
return true;
}
}

return false;
Expand Down Expand Up @@ -266,27 +285,21 @@ SearchWidget::~SearchWidget()
delete m_ui;
}

void SearchWidget::tabChanged(const int index)
void SearchWidget::currentTabChanged(const int index)
{
// when we switch from a tab that is not empty to another that is empty
// the download button doesn't have to be available
m_currentSearchTab = (index >= 0)
? static_cast<SearchJobWidget *>(m_ui->tabWidget->widget(index))
: nullptr;

if (!m_currentSearchTab)
m_isNewQueryString = true;

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();
}
}
m_ui->lineEditSearchPattern->setText(m_currentSearchTab->searchPattern());

adjustSearchButton();
}

void SearchWidget::selectMultipleBox([[maybe_unused]] const int index)
Expand All @@ -310,6 +323,27 @@ void SearchWidget::toggleFocusBetweenLineEdits()
}
}

void SearchWidget::adjustSearchButton()
{
if (!m_isNewQueryString
&& (m_currentSearchTab && (m_currentSearchTab->status() == SearchJobWidget::Status::Ongoing)))
{
if (m_ui->searchButton->isVisible())
{
m_ui->searchButton->hide();
m_ui->stopButton->show();
}
}
else
{
if (m_ui->stopButton->isVisible())
{
m_ui->stopButton->hide();
m_ui->searchButton->show();
}
}
}

void SearchWidget::showTabMenu(const int index)
{
QMenu *menu = new QMenu(this);
Expand Down Expand Up @@ -339,11 +373,13 @@ void SearchWidget::pluginsButtonClicked()
dlg->show();
}

void SearchWidget::searchTextEdited(const QString &)
void SearchWidget::searchTextEdited(const QString &text)
{
// Enable search button
m_ui->searchButton->setText(tr("Search"));
m_isNewQueryString = true;
if (m_currentSearchTab)
{
m_isNewQueryString = m_currentSearchTab->searchPattern() != text;
adjustSearchButton();
}
}

void SearchWidget::giveFocusToSearchInput()
Expand Down Expand Up @@ -391,8 +427,6 @@ void SearchWidget::searchButtonClicked()
void SearchWidget::stopButtonClicked()
{
m_currentSearchTab->cancelSearch();
m_ui->stopButton->hide();
m_ui->searchButton->show();
}

void SearchWidget::tabStatusChanged(SearchJobWidget *tab)
Expand All @@ -405,10 +439,7 @@ void SearchWidget::tabStatusChanged(SearchJobWidget *tab)
if (tab->status() != SearchJobWidget::Status::Ongoing)
{
if (tab == m_currentSearchTab)
{
m_ui->stopButton->hide();
m_ui->searchButton->show();
}
adjustSearchButton();

emit searchFinished(tab->status() == SearchJobWidget::Status::Error);
}
Expand Down Expand Up @@ -437,10 +468,5 @@ 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->tabWidget->currentWidget() == searchJobWidget))
{
m_ui->searchButton->hide();
m_ui->stopButton->show();
}
tabStatusChanged(searchJobWidget);
}
5 changes: 3 additions & 2 deletions src/gui/search/searchwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ class SearchWidget : public GUIApplicationComponent<QWidget>
void pluginsButtonClicked();
void searchButtonClicked();
void stopButtonClicked();
void searchTextEdited(const QString &text);
void currentTabChanged(int index);

void tabChanged(int index);
void tabStatusChanged(SearchJobWidget *tab);

void closeTab(int index);
Expand All @@ -76,11 +77,11 @@ class SearchWidget : public GUIApplicationComponent<QWidget>

void selectMultipleBox(int index);
void toggleFocusBetweenLineEdits();
void adjustSearchButton();

void fillCatCombobox();
void fillPluginComboBox();
void selectActivePage();
void searchTextEdited(const QString &);

QString selectedCategory() const;
QStringList selectedPlugins() const;
Expand Down
Loading