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() @@ -211,11 +211,11 @@ void SearchJobWidget::cancelSearch()
m_searchHandler->cancelSearch();
}
void SearchJobWidget::downloadTorrents()
void SearchJobWidget::downloadTorrents(const AddTorrentOption option)
{
const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()};
for (const QModelIndex &rowIndex : rows)
downloadTorrent(rowIndex);
downloadTorrent(rowIndex, option);
}
void SearchJobWidget::openTorrentPages() const
@ -271,7 +271,7 @@ void SearchJobWidget::setStatus(Status value) @@ -271,7 +271,7 @@ void SearchJobWidget::setStatus(Status value)
emit statusChanged();
}
void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex)
void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex, const AddTorrentOption option)
{
const QString torrentUrl = m_proxyModel->data(
m_proxyModel->index(rowIndex.row(), SearchSortModel::DL_LINK)).toString();
@ -280,22 +280,23 @@ void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex) @@ -280,22 +280,23 @@ void SearchJobWidget::downloadTorrent(const QModelIndex &rowIndex)
if (torrentUrl.startsWith("magnet:", Qt::CaseInsensitive))
{
addTorrentToSession(torrentUrl);
addTorrentToSession(torrentUrl, option);
}
else
{
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);
}
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 (AddNewTorrentDialog::isEnabled())
if ((option == AddTorrentOption::ShowDialog) || ((option == AddTorrentOption::Default) && AddNewTorrentDialog::isEnabled()))
AddNewTorrentDialog::show(source, this);
else
BitTorrent::Session::instance()->addTorrent(source);
@ -394,8 +395,10 @@ void SearchJobWidget::contextMenuEvent(QContextMenuEvent *event) @@ -394,8 +395,10 @@ void SearchJobWidget::contextMenuEvent(QContextMenuEvent *event)
auto *menu = new QMenu(this);
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")
, this, &SearchJobWidget::downloadTorrents);
, this, [this]() { downloadTorrents(AddTorrentOption::SkipDialog); });
menu->addSeparator();
menu->addAction(UIThemeManager::instance()->getIcon("application-x-mswinurl"), tr("Open description page")
, this, &SearchJobWidget::openTorrentPages);

13
src/gui/search/searchjobwidget.h

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

Loading…
Cancel
Save