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
23 changed files with 477 additions and 256 deletions

View File

@@ -147,6 +147,7 @@ BitTorrent::AddTorrentParams AddTorrentParamsWidget::addTorrentParams() const
addTorrentParams.ratioLimit = m_ui->torrentShareLimitsWidget->ratioLimit().value();
addTorrentParams.seedingTimeLimit = m_ui->torrentShareLimitsWidget->seedingTimeLimit().value();
addTorrentParams.inactiveSeedingTimeLimit = m_ui->torrentShareLimitsWidget->inactiveSeedingTimeLimit().value();
addTorrentParams.shareLimitAction = m_ui->torrentShareLimitsWidget->shareLimitAction().value();
return addTorrentParams;
}
@@ -272,6 +273,7 @@ void AddTorrentParamsWidget::populate()
m_ui->torrentShareLimitsWidget->setRatioLimit(m_addTorrentParams.ratioLimit);
m_ui->torrentShareLimitsWidget->setSeedingTimeLimit(m_addTorrentParams.seedingTimeLimit);
m_ui->torrentShareLimitsWidget->setInactiveSeedingTimeLimit(m_addTorrentParams.inactiveSeedingTimeLimit);
m_ui->torrentShareLimitsWidget->setShareLimitAction(m_addTorrentParams.shareLimitAction);
}
void AddTorrentParamsWidget::loadCustomSavePathOptions()

View File

@@ -1,7 +1,7 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2023-2024 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2024 Jonathan Ketchker
* Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@@ -45,6 +45,7 @@
#include <QTranslator>
#include "base/bittorrent/session.h"
#include "base/bittorrent/sharelimitaction.h"
#include "base/exceptions.h"
#include "base/global.h"
#include "base/net/portforwarder.h"
@@ -1110,14 +1111,14 @@ void OptionsDialog::loadBittorrentTabOptions()
}
m_ui->comboRatioLimitAct->setEnabled((session->globalMaxSeedingMinutes() >= 0) || (session->globalMaxRatio() >= 0.) || (session->globalMaxInactiveSeedingMinutes() >= 0));
const QHash<MaxRatioAction, int> actIndex =
const QHash<BitTorrent::ShareLimitAction, int> actIndex =
{
{Pause, 0},
{Remove, 1},
{DeleteFiles, 2},
{EnableSuperSeeding, 3}
{BitTorrent::ShareLimitAction::Stop, 0},
{BitTorrent::ShareLimitAction::Remove, 1},
{BitTorrent::ShareLimitAction::RemoveWithContent, 2},
{BitTorrent::ShareLimitAction::EnableSuperSeeding, 3}
};
m_ui->comboRatioLimitAct->setCurrentIndex(actIndex.value(session->maxRatioAction()));
m_ui->comboRatioLimitAct->setCurrentIndex(actIndex.value(session->shareLimitAction()));
m_ui->checkEnableAddTrackers->setChecked(session->isAddTrackersEnabled());
m_ui->textTrackers->setPlainText(session->additionalTrackers());
@@ -1181,14 +1182,14 @@ void OptionsDialog::saveBittorrentTabOptions() const
session->setGlobalMaxRatio(getMaxRatio());
session->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
session->setGlobalMaxInactiveSeedingMinutes(getMaxInactiveSeedingMinutes());
const QVector<MaxRatioAction> actIndex =
const QVector<BitTorrent::ShareLimitAction> actIndex =
{
Pause,
Remove,
DeleteFiles,
EnableSuperSeeding
BitTorrent::ShareLimitAction::Stop,
BitTorrent::ShareLimitAction::Remove,
BitTorrent::ShareLimitAction::RemoveWithContent,
BitTorrent::ShareLimitAction::EnableSuperSeeding
};
session->setMaxRatioAction(actIndex.value(m_ui->comboRatioLimitAct->currentIndex()));
session->setShareLimitAction(actIndex.value(m_ui->comboRatioLimitAct->currentIndex()));
session->setAddTrackersEnabled(m_ui->checkEnableAddTrackers->isChecked());
session->setAdditionalTrackers(m_ui->textTrackers->toPlainText());

View File

@@ -82,6 +82,7 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
bool allSameRatio = true;
bool allSameSeedingTime = true;
bool allSameInactiveSeedingTime = true;
bool allSameShareLimitAction = true;
bool allTorrentsArePrivate = true;
bool allSameDHT = true;
bool allSamePEX = true;
@@ -103,6 +104,7 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
const qreal firstTorrentRatio = torrents[0]->ratioLimit();
const int firstTorrentSeedingTime = torrents[0]->seedingTimeLimit();
const int firstTorrentInactiveSeedingTime = torrents[0]->inactiveSeedingTimeLimit();
const BitTorrent::ShareLimitAction firstTorrentShareLimitAction = torrents[0]->shareLimitAction();
const bool isFirstTorrentDHTDisabled = torrents[0]->isDHTDisabled();
const bool isFirstTorrentPEXDisabled = torrents[0]->isPEXDisabled();
@@ -160,6 +162,11 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
if (torrent->inactiveSeedingTimeLimit() != firstTorrentInactiveSeedingTime)
allSameInactiveSeedingTime = false;
}
if (allSameShareLimitAction)
{
if (torrent->shareLimitAction() != firstTorrentShareLimitAction)
allSameShareLimitAction = false;
}
if (allTorrentsArePrivate)
{
if (!torrent->isPrivate())
@@ -289,6 +296,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
m_ui->torrentShareLimitsWidget->setSeedingTimeLimit(firstTorrentSeedingTime);
if (allSameInactiveSeedingTime)
m_ui->torrentShareLimitsWidget->setInactiveSeedingTimeLimit(firstTorrentInactiveSeedingTime);
if (allSameShareLimitAction)
m_ui->torrentShareLimitsWidget->setShareLimitAction(firstTorrentShareLimitAction);
if (!allTorrentsArePrivate)
{
@@ -340,6 +349,7 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
.ratio = m_ui->torrentShareLimitsWidget->ratioLimit(),
.seedingTime = m_ui->torrentShareLimitsWidget->seedingTimeLimit(),
.inactiveSeedingTime = m_ui->torrentShareLimitsWidget->inactiveSeedingTimeLimit(),
.shareLimitAction = m_ui->torrentShareLimitsWidget->shareLimitAction(),
.upSpeedLimit = m_ui->spinUploadLimit->value(),
.downSpeedLimit = m_ui->spinDownloadLimit->value(),
.autoTMM = m_ui->checkAutoTMM->checkState(),
@@ -440,6 +450,12 @@ void TorrentOptionsDialog::accept()
torrent->setInactiveSeedingTimeLimit(inactiveSeedingTimeLimit.value());
}
if (const std::optional<BitTorrent::ShareLimitAction> shareLimitAction = m_ui->torrentShareLimitsWidget->shareLimitAction();
m_initialValues.shareLimitAction != shareLimitAction)
{
torrent->setShareLimitAction(shareLimitAction.value());
}
if (!torrent->isPrivate())
{
if (m_initialValues.disableDHT != m_ui->checkDisableDHT->checkState())

View File

@@ -35,6 +35,7 @@
#include <QDialog>
#include "base/bittorrent/sharelimitaction.h"
#include "base/path.h"
#include "base/settingvalue.h"
@@ -87,6 +88,7 @@ private:
std::optional<qreal> ratio;
std::optional<int> seedingTime;
std::optional<int> inactiveSeedingTime;
std::optional<BitTorrent::ShareLimitAction> shareLimitAction;
int upSpeedLimit;
int downSpeedLimit;
Qt::CheckState autoTMM;

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();

View File

@@ -32,6 +32,8 @@
#include <QWidget>
#include "base/bittorrent/sharelimitaction.h"
namespace Ui
{
class TorrentShareLimitsWidget;
@@ -49,12 +51,14 @@ public:
void setRatioLimit(qreal ratioLimit);
void setSeedingTimeLimit(int seedingTimeLimit);
void setInactiveSeedingTimeLimit(int inactiveSeedingTimeLimit);
void setShareLimitAction(BitTorrent::ShareLimitAction action);
void setDefaultLimits(qreal ratioLimit, int seedingTimeLimit, int inactiveSeedingTimeLimit);
std::optional<qreal> ratioLimit() const;
std::optional<int> seedingTimeLimit() const;
std::optional<int> inactiveSeedingTimeLimit() const;
std::optional<BitTorrent::ShareLimitAction> shareLimitAction() const;
private:
void refreshRatioLimitControls();

View File

@@ -6,47 +6,13 @@
<rect>
<x>0</x>
<y>0</y>
<width>365</width>
<height>106</height>
<width>445</width>
<height>132</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxRatioMode">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Unlimited</string>
</property>
</item>
<item>
<property name="text">
<string>Set to</string>
</property>
</item>
</widget>
</item>
<layout class="QGridLayout" name="limitsLayout">
<item row="2" column="1">
<widget class="QComboBox" name="comboBoxInactiveSeedingTimeMode">
<property name="currentIndex">
@@ -69,58 +35,6 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelSeedingTime">
<property name="text">
<string>Seeding time:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="spinBoxInactiveSeedingTimeValue">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string extracomment="minutes"> min</string>
</property>
<property name="maximum">
<number>9999999</number>
</property>
<property name="value">
<number>1440</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelInactiveSeedingTime">
<property name="text">
<string>Inactive seeding time:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxSeedingTimeMode">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Unlimited</string>
</property>
</item>
<item>
<property name="text">
<string>Set to</string>
</property>
</item>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinBoxSeedingTimeValue">
<property name="enabled">
@@ -137,6 +51,36 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelRatio">
<property name="text">
<string>Ratio:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelInactiveSeedingTime">
<property name="text">
<string>Inactive seeding time:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="spinBoxInactiveSeedingTimeValue">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string extracomment="minutes"> min</string>
</property>
<property name="maximum">
<number>9999999</number>
</property>
<property name="value">
<number>1440</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QDoubleSpinBox" name="spinBoxRatioValue">
<property name="enabled">
@@ -153,15 +97,115 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelRatio">
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxSeedingTimeMode">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Unlimited</string>
</property>
</item>
<item>
<property name="text">
<string>Set to</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxRatioMode">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Unlimited</string>
</property>
</item>
<item>
<property name="text">
<string>Set to</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelSeedingTime">
<property name="text">
<string>Ratio:</string>
<string>Seeding time:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="actionLayout">
<item>
<widget class="QLabel" name="labelAction">
<property name="text">
<string>Action when the limit is reached:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxAction">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Stop torrent</string>
</property>
</item>
<item>
<property name="text">
<string>Remove torrent</string>
</property>
</item>
<item>
<property name="text">
<string>Remove torrent and its content</string>
</property>
</item>
<item>
<property name="text">
<string>Enable super seeding for torrent</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="actionLayoutSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>