mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 05:27:15 +03:00
Add more download options to torrent search result right-click menu
PR #15654.
This commit is contained in:
parent
32698fe0be
commit
b29b7e0185
2 changed files with 21 additions and 11 deletions
|
@ -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)
|
|||
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)
|
|||
|
||||
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)
|
|||
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);
|
||||
|
|
|
@ -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:
|
|||
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…
Reference in a new issue