diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index 301f32e22..06f0a18e0 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -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); diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index 5e2adba54..ee6ce0b6c 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -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 &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;