mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 05:27:15 +03:00
Merge pull request #10852 from Chocobo1/menu
Improvements to search widget
This commit is contained in:
commit
cd654d61fd
5 changed files with 50 additions and 95 deletions
|
@ -217,7 +217,7 @@ void SearchJobWidget::downloadTorrents()
|
||||||
downloadTorrent(rowIndex);
|
downloadTorrent(rowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchJobWidget::openTorrentPages()
|
void SearchJobWidget::openTorrentPages() const
|
||||||
{
|
{
|
||||||
const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()};
|
const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()};
|
||||||
for (const QModelIndex &rowIndex : rows) {
|
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()};
|
const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()};
|
||||||
QStringList urls;
|
QStringList list;
|
||||||
|
|
||||||
for (const QModelIndex &rowIndex : rows) {
|
for (const QModelIndex &rowIndex : rows) {
|
||||||
const QString descrLink = m_proxyModel->data(
|
const QString field = m_proxyModel->data(
|
||||||
m_proxyModel->index(rowIndex.row(), SearchSortModel::DESC_LINK)).toString();
|
m_proxyModel->index(rowIndex.row(), column)).toString();
|
||||||
if (!descrLink.isEmpty())
|
if (!field.isEmpty())
|
||||||
urls << descrLink;
|
list << field;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!urls.empty()) {
|
if (!list.empty())
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QApplication::clipboard()->setText(list.join('\n'));
|
||||||
clipboard->setText(urls.join('\n'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchJobWidget::setStatus(Status value)
|
void SearchJobWidget::setStatus(Status value)
|
||||||
|
@ -382,11 +396,23 @@ void SearchJobWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
const QAction *openDescriptionAction = menu->addAction(
|
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);
|
connect(openDescriptionAction, &QAction::triggered, this, &SearchJobWidget::openTorrentPages);
|
||||||
|
|
||||||
const QAction *copyDescriptionAction = menu->addAction(
|
QMenu *copySubMenu = menu->addMenu(
|
||||||
GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy description page URL"));
|
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);
|
connect(copyDescriptionAction, &QAction::triggered, this, &SearchJobWidget::copyTorrentURLs);
|
||||||
|
|
||||||
menu->popup(event->globalPos());
|
menu->popup(event->globalPos());
|
||||||
|
|
|
@ -82,10 +82,6 @@ public:
|
||||||
|
|
||||||
void cancelSearch();
|
void cancelSearch();
|
||||||
|
|
||||||
void downloadTorrents();
|
|
||||||
void openTorrentPages();
|
|
||||||
void copyTorrentURLs();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void resultsCountUpdated();
|
void resultsCountUpdated();
|
||||||
void statusChanged();
|
void statusChanged();
|
||||||
|
@ -114,6 +110,13 @@ private:
|
||||||
QHeaderView *header() const;
|
QHeaderView *header() const;
|
||||||
void setRowColor(int row, const QColor &color);
|
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 QString statusText(Status st);
|
||||||
static CachedSettingValue<NameFilteringMode> &nameFilteringModeSetting();
|
static CachedSettingValue<NameFilteringMode> &nameFilteringModeSetting();
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/search/searchpluginmanager.h"
|
#include "base/search/searchpluginmanager.h"
|
||||||
|
@ -104,10 +105,7 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
// Icons
|
// Icons
|
||||||
m_ui->searchButton->setIcon(GuiIconProvider::instance()->getIcon("edit-find"));
|
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->pluginsButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network"));
|
||||||
m_ui->copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy"));
|
|
||||||
#else
|
#else
|
||||||
// On macOS the icons overlap the text otherwise
|
// On macOS the icons overlap the text otherwise
|
||||||
QSize iconSize = m_ui->tabWidget->iconSize();
|
QSize iconSize = m_ui->tabWidget->iconSize();
|
||||||
|
@ -149,7 +147,7 @@ void SearchWidget::fillCatCombobox()
|
||||||
m_ui->comboCategory->addItem(SearchPluginManager::categoryFullName("all"), QVariant("all"));
|
m_ui->comboCategory->addItem(SearchPluginManager::categoryFullName("all"), QVariant("all"));
|
||||||
|
|
||||||
using QStrPair = QPair<QString, QString>;
|
using QStrPair = QPair<QString, QString>;
|
||||||
QList<QStrPair> tmpList;
|
QVector<QStrPair> tmpList;
|
||||||
for (const QString &cat : asConst(SearchPluginManager::instance()->getPluginCategories(selectedPlugin())))
|
for (const QString &cat : asConst(SearchPluginManager::instance()->getPluginCategories(selectedPlugin())))
|
||||||
tmpList << qMakePair(SearchPluginManager::categoryFullName(cat), cat);
|
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); });
|
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
|
||||||
|
@ -171,7 +169,7 @@ void SearchWidget::fillPluginComboBox()
|
||||||
m_ui->selectPlugin->addItem(tr("Select..."), QVariant("multi"));
|
m_ui->selectPlugin->addItem(tr("Select..."), QVariant("multi"));
|
||||||
|
|
||||||
using QStrPair = QPair<QString, QString>;
|
using QStrPair = QPair<QString, QString>;
|
||||||
QList<QStrPair> tmpList;
|
QVector<QStrPair> tmpList;
|
||||||
for (const QString &name : asConst(SearchPluginManager::instance()->enabledPlugins()))
|
for (const QString &name : asConst(SearchPluginManager::instance()->enabledPlugins()))
|
||||||
tmpList << qMakePair(SearchPluginManager::instance()->pluginFullName(name), name);
|
tmpList << qMakePair(SearchPluginManager::instance()->pluginFullName(name), name);
|
||||||
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );
|
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );
|
||||||
|
@ -217,26 +215,11 @@ SearchWidget::~SearchWidget()
|
||||||
delete m_ui;
|
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)
|
void SearchWidget::tabChanged(int index)
|
||||||
{
|
{
|
||||||
// when we switch from a tab that is not empty to another that is empty
|
// when we switch from a tab that is not empty to another that is empty
|
||||||
// the download button doesn't have to be available
|
// the download button doesn't have to be available
|
||||||
m_currentSearchTab = ((index < 0) ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex()));
|
m_currentSearchTab = ((index < 0) ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex()));
|
||||||
updateButtons();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchWidget::selectMultipleBox(int index)
|
void SearchWidget::selectMultipleBox(int index)
|
||||||
|
@ -324,7 +307,6 @@ void SearchWidget::on_searchButton_clicked()
|
||||||
m_ui->tabWidget->addTab(newTab, tabName);
|
m_ui->tabWidget->addTab(newTab, tabName);
|
||||||
m_ui->tabWidget->setCurrentWidget(newTab);
|
m_ui->tabWidget->setCurrentWidget(newTab);
|
||||||
|
|
||||||
connect(newTab, &SearchJobWidget::resultsCountUpdated, this, &SearchWidget::resultsCountUpdated);
|
|
||||||
connect(newTab, &SearchJobWidget::statusChanged, this, [this, newTab]() { tabStatusChanged(newTab); });
|
connect(newTab, &SearchJobWidget::statusChanged, this, [this, newTab]() { tabStatusChanged(newTab); });
|
||||||
|
|
||||||
m_ui->searchButton->setText(tr("Stop"));
|
m_ui->searchButton->setText(tr("Stop"));
|
||||||
|
@ -332,11 +314,6 @@ void SearchWidget::on_searchButton_clicked()
|
||||||
tabStatusChanged(newTab);
|
tabStatusChanged(newTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchWidget::resultsCountUpdated()
|
|
||||||
{
|
|
||||||
updateButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchWidget::tabStatusChanged(QWidget *tab)
|
void SearchWidget::tabStatusChanged(QWidget *tab)
|
||||||
{
|
{
|
||||||
const int tabIndex = m_ui->tabWidget->indexOf(tab);
|
const int tabIndex = m_ui->tabWidget->indexOf(tab);
|
||||||
|
@ -367,19 +344,3 @@ void SearchWidget::closeTab(int index)
|
||||||
|
|
||||||
delete tab;
|
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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -57,15 +57,11 @@ public:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_searchButton_clicked();
|
void on_searchButton_clicked();
|
||||||
void on_downloadButton_clicked();
|
|
||||||
void on_goToDescBtn_clicked();
|
|
||||||
void on_copyURLBtn_clicked();
|
|
||||||
void on_pluginsButton_clicked();
|
void on_pluginsButton_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void tabChanged(int index);
|
void tabChanged(int index);
|
||||||
void closeTab(int index);
|
void closeTab(int index);
|
||||||
void resultsCountUpdated();
|
|
||||||
void tabStatusChanged(QWidget *tab);
|
void tabStatusChanged(QWidget *tab);
|
||||||
void selectMultipleBox(int index);
|
void selectMultipleBox(int index);
|
||||||
void toggleFocusBetweenLineEdits();
|
void toggleFocusBetweenLineEdits();
|
||||||
|
@ -74,7 +70,6 @@ private:
|
||||||
void fillPluginComboBox();
|
void fillPluginComboBox();
|
||||||
void selectActivePage();
|
void selectActivePage();
|
||||||
void searchTextEdited(const QString &);
|
void searchTextEdited(const QString &);
|
||||||
void updateButtons();
|
|
||||||
|
|
||||||
QString selectedCategory() const;
|
QString selectedCategory() const;
|
||||||
QString selectedPlugin() const;
|
QString selectedPlugin() const;
|
||||||
|
|
|
@ -113,36 +113,6 @@ Click the "Search plugins..." button at the bottom right of the window
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="layout2">
|
<layout class="QHBoxLayout" name="layout2">
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="downloadButton">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Download</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="goToDescBtn">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Go to description page</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="copyURLBtn">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Copy description page URL</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer name="spacer2">
|
<spacer name="spacer2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
Loading…
Reference in a new issue