Allow torrents to override default share limit action

PR #20528.
This commit is contained in:
Vladimir Golovnev 2024-03-12 14:08:59 +03:00 committed by GitHub
parent 773cb1e55d
commit d5e41bf679
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 477 additions and 256 deletions

View file

@ -40,6 +40,16 @@ namespace
UnlimitedModeIndex,
AssignedModeIndex
};
enum ShareLimitActionIndex
{
UninitializedActionIndex = -1,
DefaultActionIndex,
StopActionIndex,
RemoveActionIndex,
RemoveWithContentActionIndex,
SuperSeedingActionIndex
};
}
TorrentShareLimitsWidget::TorrentShareLimitsWidget(QWidget *parent)
@ -119,6 +129,29 @@ void TorrentShareLimitsWidget::setInactiveSeedingTimeLimit(const int inactiveSee
}
}
void TorrentShareLimitsWidget::setShareLimitAction(const BitTorrent::ShareLimitAction action)
{
switch (action)
{
case BitTorrent::ShareLimitAction::Default:
default:
m_ui->comboBoxAction->setCurrentIndex(DefaultActionIndex);
break;
case BitTorrent::ShareLimitAction::Stop:
m_ui->comboBoxAction->setCurrentIndex(StopActionIndex);
break;
case BitTorrent::ShareLimitAction::Remove:
m_ui->comboBoxAction->setCurrentIndex(RemoveActionIndex);
break;
case BitTorrent::ShareLimitAction::RemoveWithContent:
m_ui->comboBoxAction->setCurrentIndex(RemoveWithContentActionIndex);
break;
case BitTorrent::ShareLimitAction::EnableSuperSeeding:
m_ui->comboBoxAction->setCurrentIndex(SuperSeedingActionIndex);
break;
}
}
void TorrentShareLimitsWidget::setDefaultLimits(const qreal ratioLimit, const int seedingTimeLimit, const int inactiveSeedingTimeLimit)
{
if (m_defaultRatioLimit != ratioLimit)
@ -185,6 +218,25 @@ std::optional<int> TorrentShareLimitsWidget::inactiveSeedingTimeLimit() const
}
}
std::optional<BitTorrent::ShareLimitAction> TorrentShareLimitsWidget::shareLimitAction() const
{
switch (m_ui->comboBoxAction->currentIndex())
{
case DefaultActionIndex:
return BitTorrent::ShareLimitAction::Default;
case StopActionIndex:
return BitTorrent::ShareLimitAction::Stop;
case RemoveActionIndex:
return BitTorrent::ShareLimitAction::Remove;
case RemoveWithContentActionIndex:
return BitTorrent::ShareLimitAction::RemoveWithContent;
case SuperSeedingActionIndex:
return BitTorrent::ShareLimitAction::EnableSuperSeeding;
default:
return std::nullopt;
}
}
void TorrentShareLimitsWidget::refreshRatioLimitControls()
{
const auto index = m_ui->comboBoxRatioMode->currentIndex();