Change "metadata received" stop condition behavior

PR #20283.
Closes #20122.
This commit is contained in:
Vladimir Golovnev 2024-01-19 20:34:40 +03:00 committed by Vladimir Golovnev (Glassez)
parent e74b587420
commit acd9102dc2
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
4 changed files with 37 additions and 29 deletions

View file

@ -2807,6 +2807,14 @@ bool SessionImpl::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &so
if (hasMetadata) 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<TorrentInfo>(source); const TorrentInfo &torrentInfo = std::get<TorrentInfo>(source);
Q_ASSERT(addTorrentParams.filePaths.isEmpty() || (addTorrentParams.filePaths.size() == torrentInfo.filesCount())); Q_ASSERT(addTorrentParams.filePaths.isEmpty() || (addTorrentParams.filePaths.size() == torrentInfo.filesCount()));

View file

@ -356,18 +356,28 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
m_ui->downloadPath->setMaxVisibleItems(20); m_ui->downloadPath->setMaxVisibleItems(20);
m_ui->addToQueueTopCheckBox->setChecked(m_torrentParams.addToQueueTop.value_or(session->isAddTorrentToQueueTop())); 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( m_ui->stopConditionComboBox->setToolTip(
u"<html><body><p><b>" + tr("None") + u"</b> - " + tr("No stop condition is set.") + u"</p><p><b>" + u"<html><body><p><b>" + tr("None") + u"</b> - " + tr("No stop condition is set.") + u"</p><p><b>" +
tr("Metadata received") + u"</b> - " + tr("Torrent will stop after metadata is received.") + tr("Metadata received") + u"</b> - " + tr("Torrent will stop after metadata is received.") +
u" <em>" + tr("Torrents that have metadata initially aren't affected.") + u"</em></p><p><b>" + u" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u"</em></p><p><b>" +
tr("Files checked") + u"</b> - " + tr("Torrent will stop after files are initially checked.") + tr("Files checked") + u"</b> - " + tr("Torrent will stop after files are initially checked.") +
u" <em>" + tr("This will also download metadata if it wasn't there initially.") + u"</em></p></body></html>"); u" <em>" + tr("This will also download metadata if it wasn't there initially.") + u"</em></p></body></html>");
m_ui->stopConditionComboBox->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None)); m_ui->stopConditionComboBox->addItem(tr("None"), QVariant::fromValue(BitTorrent::Torrent::StopCondition::None));
m_ui->stopConditionComboBox->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived)); if (!hasMetadata())
m_ui->stopConditionComboBox->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked)); m_ui->stopConditionComboBox->addItem(tr("Metadata received"), QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived));
m_ui->stopConditionComboBox->setCurrentIndex(m_ui->stopConditionComboBox->findData( m_ui->stopConditionComboBox->addItem(tr("Files checked"), QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked));
QVariant::fromValue(m_torrentParams.stopCondition.value_or(session->torrentStopCondition())))); 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->stopConditionLabel->setEnabled(m_ui->startTorrentCheckBox->isChecked());
m_ui->stopConditionComboBox->setEnabled(m_ui->startTorrentCheckBox->isChecked()); m_ui->stopConditionComboBox->setEnabled(m_ui->startTorrentCheckBox->isChecked());
connect(m_ui->startTorrentCheckBox, &QCheckBox::toggled, this, [this](const bool checked) connect(m_ui->startTorrentCheckBox, &QCheckBox::toggled, this, [this](const bool checked)
@ -993,14 +1003,22 @@ void AddNewTorrentDialog::updateMetadata(const BitTorrent::TorrentInfo &metadata
// Good to go // Good to go
m_torrentInfo = metadata; m_torrentInfo = metadata;
setMetadataProgressIndicator(true, tr("Parsing metadata...")); setMetadataProgressIndicator(true, tr("Parsing metadata..."));
const auto stopCondition = m_ui->stopConditionComboBox->currentData().value<BitTorrent::Torrent::StopCondition>();
if (stopCondition == BitTorrent::Torrent::StopCondition::MetadataReceived)
m_ui->startTorrentCheckBox->setChecked(false);
// Update UI // Update UI
setupTreeview(); setupTreeview();
setMetadataProgressIndicator(false, tr("Metadata retrieval complete")); setMetadataProgressIndicator(false, tr("Metadata retrieval complete"));
if (const auto stopCondition = m_ui->stopConditionComboBox->currentData().value<BitTorrent::Torrent::StopCondition>()
; 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); m_ui->buttonSave->setVisible(true);
if (m_torrentInfo.infoHash().v2().isValid()) if (m_torrentInfo.infoHash().v2().isValid())
{ {

View file

@ -261,24 +261,6 @@
</item> </item>
<item> <item>
<widget class="QComboBox" name="stopConditionComboBox"> <widget class="QComboBox" name="stopConditionComboBox">
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Metadata received</string>
</property>
</item>
<item>
<property name="text">
<string>Files checked</string>
</property>
</item>
</widget> </widget>
</item> </item>
</layout> </layout>

View file

@ -516,7 +516,7 @@ void OptionsDialog::loadDownloadsTabOptions()
m_ui->stopConditionComboBox->setToolTip( m_ui->stopConditionComboBox->setToolTip(
u"<html><body><p><b>" + tr("None") + u"</b> - " + tr("No stop condition is set.") + u"</p><p><b>" + u"<html><body><p><b>" + tr("None") + u"</b> - " + tr("No stop condition is set.") + u"</p><p><b>" +
tr("Metadata received") + u"</b> - " + tr("Torrent will stop after metadata is received.") + tr("Metadata received") + u"</b> - " + tr("Torrent will stop after metadata is received.") +
u" <em>" + tr("Torrents that have metadata initially aren't affected.") + u"</em></p><p><b>" + u" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u"</em></p><p><b>" +
tr("Files checked") + u"</b> - " + tr("Torrent will stop after files are initially checked.") + tr("Files checked") + u"</b> - " + tr("Torrent will stop after files are initially checked.") +
u" <em>" + tr("This will also download metadata if it wasn't there initially.") + u"</em></p></body></html>"); u" <em>" + tr("This will also download metadata if it wasn't there initially.") + u"</em></p></body></html>");
m_ui->stopConditionComboBox->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None)); m_ui->stopConditionComboBox->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None));