From 26ff9150a2cf7bcb2699c1d5d02d81d4cb2322f9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 26 Jun 2019 10:52:13 +0800 Subject: [PATCH 1/4] Rename label in search widget --- src/gui/search/searchjobwidget.cpp | 2 +- src/gui/search/searchwidget.ui | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index a9c41b21c..7708e9465 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -382,7 +382,7 @@ void SearchJobWidget::contextMenuEvent(QContextMenuEvent *event) menu->addSeparator(); const QAction *openDescriptionAction = menu->addAction( - GuiIconProvider::instance()->getIcon("application-x-mswinurl"), tr("Go to description page")); + GuiIconProvider::instance()->getIcon("application-x-mswinurl"), tr("Open description page")); connect(openDescriptionAction, &QAction::triggered, this, &SearchJobWidget::openTorrentPages); const QAction *copyDescriptionAction = menu->addAction( diff --git a/src/gui/search/searchwidget.ui b/src/gui/search/searchwidget.ui index 3e8fda8b2..d908b683c 100644 --- a/src/gui/search/searchwidget.ui +++ b/src/gui/search/searchwidget.ui @@ -129,7 +129,7 @@ Click the "Search plugins..." button at the bottom right of the window false - Go to description page + Open description page From 4f5302adf89267ea56aadb5d7bee3d96890ecabf Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 26 Jun 2019 11:17:45 +0800 Subject: [PATCH 2/4] Add more copy field actions to search widget Closes #10250. --- src/gui/search/searchjobwidget.cpp | 52 ++++++++++++++++++++++-------- src/gui/search/searchjobwidget.h | 11 ++++--- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index 7708e9465..1af98b679 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -217,7 +217,7 @@ void SearchJobWidget::downloadTorrents() downloadTorrent(rowIndex); } -void SearchJobWidget::openTorrentPages() +void SearchJobWidget::openTorrentPages() const { const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()}; for (const QModelIndex &rowIndex : rows) { @@ -228,21 +228,35 @@ void SearchJobWidget::openTorrentPages() } } -void SearchJobWidget::copyTorrentURLs() +void SearchJobWidget::copyTorrentURLs() const +{ + copyField(SearchSortModel::DESC_LINK); +} + +void SearchJobWidget::copyTorrentDownloadLinks() const +{ + copyField(SearchSortModel::DL_LINK); +} + +void SearchJobWidget::copyTorrentNames() const +{ + copyField(SearchSortModel::NAME); +} + +void SearchJobWidget::copyField(const int column) const { const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()}; - QStringList urls; + QStringList list; + for (const QModelIndex &rowIndex : rows) { - const QString descrLink = m_proxyModel->data( - m_proxyModel->index(rowIndex.row(), SearchSortModel::DESC_LINK)).toString(); - if (!descrLink.isEmpty()) - urls << descrLink; + const QString field = m_proxyModel->data( + m_proxyModel->index(rowIndex.row(), column)).toString(); + if (!field.isEmpty()) + list << field; } - if (!urls.empty()) { - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(urls.join('\n')); - } + if (!list.empty()) + QApplication::clipboard()->setText(list.join('\n')); } void SearchJobWidget::setStatus(Status value) @@ -385,8 +399,20 @@ void SearchJobWidget::contextMenuEvent(QContextMenuEvent *event) GuiIconProvider::instance()->getIcon("application-x-mswinurl"), tr("Open description page")); connect(openDescriptionAction, &QAction::triggered, this, &SearchJobWidget::openTorrentPages); - const QAction *copyDescriptionAction = menu->addAction( - GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy description page URL")); + QMenu *copySubMenu = menu->addMenu( + GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy")); + + const QAction *copyNamesAction = copySubMenu->addAction( + GuiIconProvider::instance()->getIcon("edit-copy"), tr("Name")); + connect(copyNamesAction, &QAction::triggered, this, &SearchJobWidget::copyTorrentNames); + + const QAction *copyDownloadLinkAction = copySubMenu->addAction( + GuiIconProvider::instance()->getIcon("edit-copy"), tr("Download link")); + connect(copyDownloadLinkAction, &QAction::triggered + , this, &SearchJobWidget::copyTorrentDownloadLinks); + + const QAction *copyDescriptionAction = copySubMenu->addAction( + GuiIconProvider::instance()->getIcon("edit-copy"), tr("Description page URL")); connect(copyDescriptionAction, &QAction::triggered, this, &SearchJobWidget::copyTorrentURLs); menu->popup(event->globalPos()); diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index 673ecdb55..0f3853db3 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -82,10 +82,6 @@ public: void cancelSearch(); - void downloadTorrents(); - void openTorrentPages(); - void copyTorrentURLs(); - signals: void resultsCountUpdated(); void statusChanged(); @@ -114,6 +110,13 @@ private: QHeaderView *header() const; void setRowColor(int row, const QColor &color); + void downloadTorrents(); + void openTorrentPages() const; + void copyTorrentURLs() const; + void copyTorrentDownloadLinks() const; + void copyTorrentNames() const; + void copyField(int column) const; + static QString statusText(Status st); static CachedSettingValue &nameFilteringModeSetting(); From 5b9b5ce577f882fb58284ccfd3f1570f931dac6f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 26 Jun 2019 11:41:23 +0800 Subject: [PATCH 3/4] Remove buttons from search widget These buttons are replaced by right-click menu actions. --- src/gui/search/searchwidget.cpp | 40 --------------------------------- src/gui/search/searchwidget.h | 5 ----- src/gui/search/searchwidget.ui | 30 ------------------------- 3 files changed, 75 deletions(-) diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 3fac10a2c..15af96484 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -104,10 +104,7 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) #ifndef Q_OS_MAC // Icons m_ui->searchButton->setIcon(GuiIconProvider::instance()->getIcon("edit-find")); - m_ui->downloadButton->setIcon(GuiIconProvider::instance()->getIcon("download")); - m_ui->goToDescBtn->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl")); m_ui->pluginsButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network")); - m_ui->copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy")); #else // On macOS the icons overlap the text otherwise QSize iconSize = m_ui->tabWidget->iconSize(); @@ -217,26 +214,11 @@ SearchWidget::~SearchWidget() delete m_ui; } -void SearchWidget::updateButtons() -{ - if (m_currentSearchTab && (m_currentSearchTab->visibleResultsCount() > 0)) { - m_ui->downloadButton->setEnabled(true); - m_ui->goToDescBtn->setEnabled(true); - m_ui->copyURLBtn->setEnabled(true); - } - else { - m_ui->downloadButton->setEnabled(false); - m_ui->goToDescBtn->setEnabled(false); - m_ui->copyURLBtn->setEnabled(false); - } -} - void SearchWidget::tabChanged(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) ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex())); - updateButtons(); } void SearchWidget::selectMultipleBox(int index) @@ -324,7 +306,6 @@ void SearchWidget::on_searchButton_clicked() m_ui->tabWidget->addTab(newTab, tabName); m_ui->tabWidget->setCurrentWidget(newTab); - connect(newTab, &SearchJobWidget::resultsCountUpdated, this, &SearchWidget::resultsCountUpdated); connect(newTab, &SearchJobWidget::statusChanged, this, [this, newTab]() { tabStatusChanged(newTab); }); m_ui->searchButton->setText(tr("Stop")); @@ -332,11 +313,6 @@ void SearchWidget::on_searchButton_clicked() tabStatusChanged(newTab); } -void SearchWidget::resultsCountUpdated() -{ - updateButtons(); -} - void SearchWidget::tabStatusChanged(QWidget *tab) { const int tabIndex = m_ui->tabWidget->indexOf(tab); @@ -367,19 +343,3 @@ void SearchWidget::closeTab(int index) delete tab; } - -// Download selected items in search results list -void SearchWidget::on_downloadButton_clicked() -{ - m_allTabs.at(m_ui->tabWidget->currentIndex())->downloadTorrents(); -} - -void SearchWidget::on_goToDescBtn_clicked() -{ - m_allTabs.at(m_ui->tabWidget->currentIndex())->openTorrentPages(); -} - -void SearchWidget::on_copyURLBtn_clicked() -{ - m_allTabs.at(m_ui->tabWidget->currentIndex())->copyTorrentURLs(); -} diff --git a/src/gui/search/searchwidget.h b/src/gui/search/searchwidget.h index 46a8315a7..cbfbfe321 100644 --- a/src/gui/search/searchwidget.h +++ b/src/gui/search/searchwidget.h @@ -57,15 +57,11 @@ public: private slots: void on_searchButton_clicked(); - void on_downloadButton_clicked(); - void on_goToDescBtn_clicked(); - void on_copyURLBtn_clicked(); void on_pluginsButton_clicked(); private: void tabChanged(int index); void closeTab(int index); - void resultsCountUpdated(); void tabStatusChanged(QWidget *tab); void selectMultipleBox(int index); void toggleFocusBetweenLineEdits(); @@ -74,7 +70,6 @@ private: void fillPluginComboBox(); void selectActivePage(); void searchTextEdited(const QString &); - void updateButtons(); QString selectedCategory() const; QString selectedPlugin() const; diff --git a/src/gui/search/searchwidget.ui b/src/gui/search/searchwidget.ui index d908b683c..51029f8f6 100644 --- a/src/gui/search/searchwidget.ui +++ b/src/gui/search/searchwidget.ui @@ -113,36 +113,6 @@ Click the "Search plugins..." button at the bottom right of the window - - - - false - - - Download - - - - - - - false - - - Open description page - - - - - - - false - - - Copy description page URL - - - From da2bfd24575e151ebb0690e258867600070a55a3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 26 Jun 2019 11:54:44 +0800 Subject: [PATCH 4/4] Replace QList by QVector --- src/gui/search/searchwidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 15af96484..de3b29947 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "base/global.h" #include "base/search/searchpluginmanager.h" @@ -146,7 +147,7 @@ void SearchWidget::fillCatCombobox() m_ui->comboCategory->addItem(SearchPluginManager::categoryFullName("all"), QVariant("all")); using QStrPair = QPair; - QList tmpList; + QVector tmpList; for (const QString &cat : asConst(SearchPluginManager::instance()->getPluginCategories(selectedPlugin()))) tmpList << qMakePair(SearchPluginManager::categoryFullName(cat), cat); std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); }); @@ -168,7 +169,7 @@ void SearchWidget::fillPluginComboBox() m_ui->selectPlugin->addItem(tr("Select..."), QVariant("multi")); using QStrPair = QPair; - QList tmpList; + QVector tmpList; for (const QString &name : asConst(SearchPluginManager::instance()->enabledPlugins())) tmpList << qMakePair(SearchPluginManager::instance()->pluginFullName(name), name); std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );