Browse Source

Add more download options to torrent search result right-click menu

PR #15654.
adaptive-webui-19844
a-sum-duma 3 years ago committed by GitHub
parent
commit
b29b7e0185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      src/gui/search/searchjobwidget.cpp
  2. 13
      src/gui/search/searchjobwidget.h

19
src/gui/search/searchjobwidget.cpp

@ -211,11 +211,11 @@ void SearchJobWidget::cancelSearch()
m_searchHandler->cancelSearch(); m_searchHandler->cancelSearch();
} }
void SearchJobWidget::downloadTorrents() void SearchJobWidget::downloadTorrents(const AddTorrentOption option)
{ {
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)
downloadTorrent(rowIndex); downloadTorrent(rowIndex, option);
} }
void SearchJobWidget::openTorrentPages() const void SearchJobWidget::openTorrentPages() const
@ -271,7 +271,7 @@ void SearchJobWidget::setStatus(Status value)
emit statusChanged(); emit statusChanged();
} }
void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex) void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex, const AddTorrentOption option)
{ {
const QString torrentUrl = m_proxyModel->data( const QString torrentUrl = m_proxyModel->data(
m_proxyModel->index(rowIndex.row(), SearchSortModel::DL_LINK)).toString(); m_proxyModel->index(rowIndex.row(), SearchSortModel::DL_LINK)).toString();
@ -280,22 +280,23 @@ void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex)
if (torrentUrl.startsWith("magnet:", Qt::CaseInsensitive)) if (torrentUrl.startsWith("magnet:", Qt::CaseInsensitive))
{ {
addTorrentToSession(torrentUrl); addTorrentToSession(torrentUrl, option);
} }
else else
{ {
SearchDownloadHandler *downloadHandler = m_searchHandler->manager()->downloadTorrent(siteUrl, torrentUrl); SearchDownloadHandler *downloadHandler = m_searchHandler->manager()->downloadTorrent(siteUrl, torrentUrl);
connect(downloadHandler, &SearchDownloadHandler::downloadFinished, this, &SearchJobWidget::addTorrentToSession); connect(downloadHandler, &SearchDownloadHandler::downloadFinished
, this, [this, option](const QString &source) { addTorrentToSession(source, option); });
connect(downloadHandler, &SearchDownloadHandler::downloadFinished, downloadHandler, &SearchDownloadHandler::deleteLater); connect(downloadHandler, &SearchDownloadHandler::downloadFinished, downloadHandler, &SearchDownloadHandler::deleteLater);
} }
setRowColor(rowIndex.row(), QApplication::palette().color(QPalette::LinkVisited)); setRowColor(rowIndex.row(), QApplication::palette().color(QPalette::LinkVisited));
} }
void SearchJobWidget::addTorrentToSession(const QString &source) void SearchJobWidget::addTorrentToSession(const QString &source, const AddTorrentOption option)
{ {
if (source.isEmpty()) return; if (source.isEmpty()) return;
if (AddNewTorrentDialog::isEnabled()) if ((option == AddTorrentOption::ShowDialog) || ((option == AddTorrentOption::Default) && AddNewTorrentDialog::isEnabled()))
AddNewTorrentDialog::show(source, this); AddNewTorrentDialog::show(source, this);
else else
BitTorrent::Session::instance()->addTorrent(source); BitTorrent::Session::instance()->addTorrent(source);
@ -394,8 +395,10 @@ void SearchJobWidget::contextMenuEvent(QContextMenuEvent *event)
auto *menu = new QMenu(this); auto *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addAction(UIThemeManager::instance()->getIcon("download"), tr("Open download window")
, this, [this]() { downloadTorrents(AddTorrentOption::ShowDialog); });
menu->addAction(UIThemeManager::instance()->getIcon("download"), tr("Download") menu->addAction(UIThemeManager::instance()->getIcon("download"), tr("Download")
, this, &SearchJobWidget::downloadTorrents); , this, [this]() { downloadTorrents(AddTorrentOption::SkipDialog); });
menu->addSeparator(); menu->addSeparator();
menu->addAction(UIThemeManager::instance()->getIcon("application-x-mswinurl"), tr("Open description page") menu->addAction(UIThemeManager::instance()->getIcon("application-x-mswinurl"), tr("Open description page")
, this, &SearchJobWidget::openTorrentPages); , this, &SearchJobWidget::openTorrentPages);

13
src/gui/search/searchjobwidget.h

@ -89,6 +89,13 @@ protected:
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
private: private:
enum class AddTorrentOption
{
Default,
ShowDialog,
SkipDialog,
};
void loadSettings(); void loadSettings();
void saveSettings() const; void saveSettings() const;
void updateFilter(); void updateFilter();
@ -102,14 +109,14 @@ private:
void appendSearchResults(const QVector<SearchResult> &results); void appendSearchResults(const QVector<SearchResult> &results);
void updateResultsCount(); void updateResultsCount();
void setStatus(Status value); void setStatus(Status value);
void downloadTorrent(const QModelIndex &rowIndex); void downloadTorrent(const QModelIndex &rowIndex, AddTorrentOption option = AddTorrentOption::Default);
void addTorrentToSession(const QString &source); void addTorrentToSession(const QString &source, AddTorrentOption option = AddTorrentOption::Default);
void fillFilterComboBoxes(); void fillFilterComboBoxes();
NameFilteringMode filteringMode() const; NameFilteringMode filteringMode() const;
QHeaderView *header() const; QHeaderView *header() const;
void setRowColor(int row, const QColor &color); void setRowColor(int row, const QColor &color);
void downloadTorrents(); void downloadTorrents(AddTorrentOption option = AddTorrentOption::Default);
void openTorrentPages() const; void openTorrentPages() const;
void copyTorrentURLs() const; void copyTorrentURLs() const;
void copyTorrentDownloadLinks() const; void copyTorrentDownloadLinks() const;

Loading…
Cancel
Save