diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 36825a283..5c7b10c44 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -194,11 +194,16 @@ add_library(qbt_base STATIC target_link_libraries(qbt_base PRIVATE - OpenSSL::Crypto OpenSSL::SSL + OpenSSL::Crypto + OpenSSL::SSL ZLIB::ZLIB PUBLIC LibtorrentRasterbar::torrent-rasterbar - Qt::Core Qt::Network Qt::Sql Qt::Xml + Qt::Core + Qt::CorePrivate + Qt::Network + Qt::Sql + Qt::Xml qbt_common_cfg ) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 730738dd2..7ef150c0a 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -2449,7 +2449,7 @@ bool SessionImpl::cancelDownloadMetadata(const TorrentID &id) // if magnet link was hybrid initially then it is indexed also by v1 info hash // so we need to remove both entries const auto altID = TorrentID::fromSHA1Hash(infoHash.v1()); - m_downloadedMetadata.remove((altID == downloadedMetadataIter.key()) ? id : altID); + m_downloadedMetadata.remove(altID); } #endif @@ -2807,6 +2807,14 @@ bool SessionImpl::addTorrent_impl(const std::variant &so if (hasMetadata) { + // Torrent that is being added with metadata is considered to be added as stopped + // if "metadata received" stop condition is set for it. + if (loadTorrentParams.stopCondition == Torrent::StopCondition::MetadataReceived) + { + loadTorrentParams.stopped = true; + loadTorrentParams.stopCondition = Torrent::StopCondition::None; + } + const TorrentInfo &torrentInfo = std::get(source); Q_ASSERT(addTorrentParams.filePaths.isEmpty() || (addTorrentParams.filePaths.size() == torrentInfo.filesCount())); diff --git a/src/base/utils/compare.h b/src/base/utils/compare.h index 53de6b73a..d424b974c 100644 --- a/src/base/utils/compare.h +++ b/src/base/utils/compare.h @@ -31,7 +31,14 @@ #include #include -#if !defined(Q_OS_WIN) && (!defined(Q_OS_UNIX) || defined(Q_OS_MACOS) || defined(QT_FEATURE_icu)) +// for QT_FEATURE_xxx, see: https://wiki.qt.io/Qt5_Build_System#How_to +#include + +// macOS and Windows support 'case sensitivity' and 'numeric mode' natively +// https://github.com/qt/qtbase/blob/6.0/src/corelib/CMakeLists.txt#L777-L793 +// https://github.com/qt/qtbase/blob/6.0/src/corelib/text/qcollator_macx.cpp#L74-L77 +// https://github.com/qt/qtbase/blob/6.0/src/corelib/text/qcollator_win.cpp#L72-L78 +#if ((QT_FEATURE_icu == 1) || defined(Q_OS_MACOS) || defined(Q_OS_WIN)) #define QBT_USE_QCOLLATOR #include #endif diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index b901538f1..2fe8ecafb 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -356,18 +356,28 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP m_ui->downloadPath->setMaxVisibleItems(20); m_ui->addToQueueTopCheckBox->setChecked(m_torrentParams.addToQueueTop.value_or(session->isAddTorrentToQueueTop())); - m_ui->startTorrentCheckBox->setChecked(!m_torrentParams.addPaused.value_or(session->isAddTorrentPaused())); + m_ui->stopConditionComboBox->setToolTip( u"

" + tr("None") + u" - " + tr("No stop condition is set.") + u"

" + tr("Metadata received") + u" - " + tr("Torrent will stop after metadata is received.") + - u" " + tr("Torrents that have metadata initially aren't affected.") + u"

" + + u" " + tr("Torrents that have metadata initially will be added as stopped.") + u"

" + tr("Files checked") + u" - " + tr("Torrent will stop after files are initially checked.") + u" " + tr("This will also download metadata if it wasn't there initially.") + u"

"); - m_ui->stopConditionComboBox->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None)); - m_ui->stopConditionComboBox->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived)); - m_ui->stopConditionComboBox->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked)); - m_ui->stopConditionComboBox->setCurrentIndex(m_ui->stopConditionComboBox->findData( - QVariant::fromValue(m_torrentParams.stopCondition.value_or(session->torrentStopCondition())))); + m_ui->stopConditionComboBox->addItem(tr("None"), QVariant::fromValue(BitTorrent::Torrent::StopCondition::None)); + if (!hasMetadata()) + m_ui->stopConditionComboBox->addItem(tr("Metadata received"), QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived)); + m_ui->stopConditionComboBox->addItem(tr("Files checked"), QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked)); + const auto stopCondition = m_torrentParams.stopCondition.value_or(session->torrentStopCondition()); + if (hasMetadata() && (stopCondition == BitTorrent::Torrent::StopCondition::MetadataReceived)) + { + m_ui->startTorrentCheckBox->setChecked(false); + m_ui->stopConditionComboBox->setCurrentIndex(m_ui->stopConditionComboBox->findData(QVariant::fromValue(BitTorrent::Torrent::StopCondition::None))); + } + else + { + m_ui->startTorrentCheckBox->setChecked(!m_torrentParams.addPaused.value_or(session->isAddTorrentPaused())); + m_ui->stopConditionComboBox->setCurrentIndex(m_ui->stopConditionComboBox->findData(QVariant::fromValue(stopCondition))); + } m_ui->stopConditionLabel->setEnabled(m_ui->startTorrentCheckBox->isChecked()); m_ui->stopConditionComboBox->setEnabled(m_ui->startTorrentCheckBox->isChecked()); connect(m_ui->startTorrentCheckBox, &QCheckBox::toggled, this, [this](const bool checked) @@ -991,14 +1001,22 @@ void AddNewTorrentDialog::updateMetadata(const BitTorrent::TorrentInfo &metadata // Good to go m_torrentInfo = metadata; setMetadataProgressIndicator(true, tr("Parsing metadata...")); - const auto stopCondition = m_ui->stopConditionComboBox->currentData().value(); - if (stopCondition == BitTorrent::Torrent::StopCondition::MetadataReceived) - m_ui->startTorrentCheckBox->setChecked(false); // Update UI setupTreeview(); setMetadataProgressIndicator(false, tr("Metadata retrieval complete")); + if (const auto stopCondition = m_ui->stopConditionComboBox->currentData().value() + ; stopCondition == BitTorrent::Torrent::StopCondition::MetadataReceived) + { + m_ui->startTorrentCheckBox->setChecked(false); + + const auto index = m_ui->stopConditionComboBox->currentIndex(); + m_ui->stopConditionComboBox->setCurrentIndex(m_ui->stopConditionComboBox->findData( + QVariant::fromValue(BitTorrent::Torrent::StopCondition::None))); + m_ui->stopConditionComboBox->removeItem(index); + } + m_ui->buttonSave->setVisible(true); if (m_torrentInfo.infoHash().v2().isValid()) { diff --git a/src/gui/addnewtorrentdialog.ui b/src/gui/addnewtorrentdialog.ui index 0c9a96e1f..9d2fc3e5f 100644 --- a/src/gui/addnewtorrentdialog.ui +++ b/src/gui/addnewtorrentdialog.ui @@ -261,24 +261,6 @@ - - 0 - - - - None - - - - - Metadata received - - - - - Files checked - - diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 0c20158f3..a9968cb56 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -516,7 +516,7 @@ void OptionsDialog::loadDownloadsTabOptions() m_ui->stopConditionComboBox->setToolTip( u"

" + tr("None") + u" - " + tr("No stop condition is set.") + u"

" + tr("Metadata received") + u" - " + tr("Torrent will stop after metadata is received.") + - u" " + tr("Torrents that have metadata initially aren't affected.") + u"

" + + u" " + tr("Torrents that have metadata initially will be added as stopped.") + u"

" + tr("Files checked") + u" - " + tr("Torrent will stop after files are initially checked.") + u" " + tr("This will also download metadata if it wasn't there initially.") + u"

"); m_ui->stopConditionComboBox->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None));