mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-06 15:04:34 +08:00
Merge pull request #11241 from thalieht/delfolder
Add "Remove torrent and its files" option to share ratio limiting
This commit is contained in:
commit
975b44d05f
@ -1508,6 +1508,10 @@ void Session::processShareLimits()
|
||||
LogMsg(tr("'%1' reached the maximum ratio you set. Removed.").arg(torrent->name()));
|
||||
deleteTorrent(torrent->hash());
|
||||
}
|
||||
else if (m_maxRatioAction == DeleteFiles) {
|
||||
LogMsg(tr("'%1' reached the maximum ratio you set. Removed torrent and its files.").arg(torrent->name()));
|
||||
deleteTorrent(torrent->hash(), TorrentAndFiles);
|
||||
}
|
||||
else if ((m_maxRatioAction == Pause) && !torrent->isPaused()) {
|
||||
torrent->pause();
|
||||
LogMsg(tr("'%1' reached the maximum ratio you set. Paused.").arg(torrent->name()));
|
||||
@ -1535,6 +1539,10 @@ void Session::processShareLimits()
|
||||
LogMsg(tr("'%1' reached the maximum seeding time you set. Removed.").arg(torrent->name()));
|
||||
deleteTorrent(torrent->hash());
|
||||
}
|
||||
else if (m_maxRatioAction == DeleteFiles) {
|
||||
LogMsg(tr("'%1' reached the maximum seeding time you set. Removed torrent and its files.").arg(torrent->name()));
|
||||
deleteTorrent(torrent->hash(), TorrentAndFiles);
|
||||
}
|
||||
else if ((m_maxRatioAction == Pause) && !torrent->isPaused()) {
|
||||
torrent->pause();
|
||||
LogMsg(tr("'%1' reached the maximum seeding time you set. Paused.").arg(torrent->name()));
|
||||
@ -1616,8 +1624,8 @@ void Session::banIP(const QString &ip)
|
||||
}
|
||||
|
||||
// Delete a torrent from the session, given its hash
|
||||
// deleteLocalFiles = true means that the torrent will be removed from the hard-drive too
|
||||
bool Session::deleteTorrent(const QString &hash, const bool deleteLocalFiles)
|
||||
// and from the disk, if the corresponding deleteOption is chosen
|
||||
bool Session::deleteTorrent(const QString &hash, const DeleteOption deleteOption)
|
||||
{
|
||||
TorrentHandle *const torrent = m_torrents.take(hash);
|
||||
if (!torrent) return false;
|
||||
@ -1626,20 +1634,8 @@ bool Session::deleteTorrent(const QString &hash, const bool deleteLocalFiles)
|
||||
emit torrentAboutToBeRemoved(torrent);
|
||||
|
||||
// Remove it from session
|
||||
if (deleteLocalFiles) {
|
||||
const QString rootPath = torrent->rootPath(true);
|
||||
if (!rootPath.isEmpty())
|
||||
// torrent with root folder
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), rootPath, deleteLocalFiles};
|
||||
else if (torrent->useTempPath())
|
||||
// torrent without root folder still has it in its temporary save path
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), torrent->savePath(true), deleteLocalFiles};
|
||||
else
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), "", deleteLocalFiles};
|
||||
m_nativeSession->remove_torrent(torrent->nativeHandle(), lt::session::delete_files);
|
||||
}
|
||||
else {
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), "", deleteLocalFiles};
|
||||
if (deleteOption == Torrent) {
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), "", deleteOption};
|
||||
QStringList unwantedFiles;
|
||||
if (torrent->hasMetadata())
|
||||
unwantedFiles = torrent->absoluteFilePathsUnwanted();
|
||||
@ -1653,6 +1649,21 @@ bool Session::deleteTorrent(const QString &hash, const bool deleteLocalFiles)
|
||||
QDir().rmdir(parentFolder);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const QString rootPath = torrent->rootPath(true);
|
||||
if (!rootPath.isEmpty()) {
|
||||
// torrent with root folder
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), rootPath, deleteOption};
|
||||
}
|
||||
else if (torrent->useTempPath()) {
|
||||
// torrent without root folder still has it in its temporary save path
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), torrent->savePath(true), deleteOption};
|
||||
}
|
||||
else {
|
||||
m_removingTorrents[torrent->hash()] = {torrent->name(), "", deleteOption};
|
||||
}
|
||||
m_nativeSession->remove_torrent(torrent->nativeHandle(), lt::session::delete_files);
|
||||
}
|
||||
|
||||
// Remove it from torrent resume directory
|
||||
const QDir resumeDataDir(m_resumeFolderPath);
|
||||
@ -4002,7 +4013,7 @@ void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p)
|
||||
|
||||
if (m_removingTorrents.contains(infoHash)) {
|
||||
const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents[infoHash];
|
||||
if (!tmpRemovingTorrentData.requestedFileDeletion) {
|
||||
if (tmpRemovingTorrentData.deleteOption == Torrent) {
|
||||
LogMsg(tr("'%1' was removed from the transfer list.", "'xxx.avi' was removed...").arg(tmpRemovingTorrentData.name));
|
||||
m_removingTorrents.remove(infoHash);
|
||||
}
|
||||
|
@ -59,11 +59,20 @@ class BandwidthScheduler;
|
||||
class Statistics;
|
||||
class ResumeDataSavingManager;
|
||||
|
||||
// These values should remain unchanged when adding new items
|
||||
// so as not to break the existing user settings.
|
||||
enum MaxRatioAction
|
||||
{
|
||||
Pause,
|
||||
Remove,
|
||||
EnableSuperSeeding
|
||||
Pause = 0,
|
||||
Remove = 1,
|
||||
DeleteFiles = 3,
|
||||
EnableSuperSeeding = 2
|
||||
};
|
||||
|
||||
enum DeleteOption
|
||||
{
|
||||
Torrent,
|
||||
TorrentAndFiles
|
||||
};
|
||||
|
||||
enum TorrentExportFolder
|
||||
@ -400,7 +409,7 @@ namespace BitTorrent
|
||||
bool isKnownTorrent(const InfoHash &hash) const;
|
||||
bool addTorrent(const QString &source, const AddTorrentParams ¶ms = AddTorrentParams());
|
||||
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = AddTorrentParams());
|
||||
bool deleteTorrent(const QString &hash, bool deleteLocalFiles = false);
|
||||
bool deleteTorrent(const QString &hash, DeleteOption deleteOption = Torrent);
|
||||
bool loadMetadata(const MagnetUri &magnetUri);
|
||||
bool cancelLoadMetadata(const InfoHash &hash);
|
||||
|
||||
@ -492,7 +501,7 @@ namespace BitTorrent
|
||||
{
|
||||
QString name;
|
||||
QString savePathToRemove;
|
||||
bool requestedFileDeletion;
|
||||
DeleteOption deleteOption;
|
||||
};
|
||||
|
||||
explicit Session(QObject *parent = nullptr);
|
||||
|
@ -747,7 +747,14 @@ void OptionsDialog::saveOptions()
|
||||
session->setAdditionalTrackers(m_ui->textTrackers->toPlainText());
|
||||
session->setGlobalMaxRatio(getMaxRatio());
|
||||
session->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
|
||||
session->setMaxRatioAction(static_cast<MaxRatioAction>(m_ui->comboRatioLimitAct->currentIndex()));
|
||||
|
||||
const QVector<MaxRatioAction> actIndex = {
|
||||
Pause,
|
||||
Remove,
|
||||
DeleteFiles,
|
||||
EnableSuperSeeding
|
||||
};
|
||||
session->setMaxRatioAction(actIndex.value(m_ui->comboRatioLimitAct->currentIndex()));
|
||||
// End Bittorrent preferences
|
||||
|
||||
// Misc preferences
|
||||
@ -1130,7 +1137,14 @@ void OptionsDialog::loadOptions()
|
||||
m_ui->spinMaxSeedingMinutes->setEnabled(false);
|
||||
}
|
||||
m_ui->comboRatioLimitAct->setEnabled((session->globalMaxSeedingMinutes() >= 0) || (session->globalMaxRatio() >= 0.));
|
||||
m_ui->comboRatioLimitAct->setCurrentIndex(session->maxRatioAction());
|
||||
|
||||
const QHash<MaxRatioAction, int> actIndex = {
|
||||
{Pause, 0},
|
||||
{Remove, 1},
|
||||
{DeleteFiles, 2},
|
||||
{EnableSuperSeeding, 3}
|
||||
};
|
||||
m_ui->comboRatioLimitAct->setCurrentIndex(actIndex.value(session->maxRatioAction()));
|
||||
// End Bittorrent preferences
|
||||
|
||||
// Web UI preferences
|
||||
|
@ -2440,9 +2440,9 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="ratioBox">
|
||||
<widget class="QGroupBox" name="seedingLimitsBox">
|
||||
<property name="title">
|
||||
<string>Share Ratio Limiting</string>
|
||||
<string>Seeding Limits</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_91">
|
||||
<item row="2" column="1">
|
||||
@ -2464,7 +2464,7 @@
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="checkMaxSeedingMinutes">
|
||||
<property name="text">
|
||||
<string>Seed torrents until their seeding time reaches</string>
|
||||
<string>When seeding time reaches</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -2485,17 +2485,22 @@
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Pause them</string>
|
||||
<string>Pause torrent</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Remove them</string>
|
||||
<string>Remove torrent</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Enable super seeding for them</string>
|
||||
<string>Remove torrent and its files</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Enable super seeding for torrent</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
@ -2503,7 +2508,7 @@
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkMaxRatio">
|
||||
<property name="text">
|
||||
<string>Seed torrents until their ratio reaches</string>
|
||||
<string>When ratio reaches</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -373,8 +373,9 @@ void TransferListWidget::deleteSelectedTorrents(bool deleteLocalFiles)
|
||||
if (Preferences::instance()->confirmTorrentDeletion()
|
||||
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
|
||||
return;
|
||||
for (BitTorrent::TorrentHandle *const torrent : torrents)
|
||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles);
|
||||
const DeleteOption deleteOption = deleteLocalFiles ? TorrentAndFiles : Torrent;
|
||||
for (const BitTorrent::TorrentHandle *torrent : torrents)
|
||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteOption);
|
||||
}
|
||||
|
||||
void TransferListWidget::deleteVisibleTorrents()
|
||||
@ -390,8 +391,9 @@ void TransferListWidget::deleteVisibleTorrents()
|
||||
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
|
||||
return;
|
||||
|
||||
for (BitTorrent::TorrentHandle *const torrent : asConst(torrents))
|
||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles);
|
||||
const DeleteOption deleteOption = deleteLocalFiles ? TorrentAndFiles : Torrent;
|
||||
for (const BitTorrent::TorrentHandle *torrent : asConst(torrents))
|
||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteOption);
|
||||
}
|
||||
|
||||
void TransferListWidget::increaseQueuePosSelectedTorrents()
|
||||
|
@ -885,10 +885,11 @@ void TorrentsController::deleteAction()
|
||||
checkParams({"hashes", "deleteFiles"});
|
||||
|
||||
const QStringList hashes {params()["hashes"].split('|')};
|
||||
const bool deleteFiles {parseBool(params()["deleteFiles"], false)};
|
||||
applyToTorrents(hashes, [deleteFiles](BitTorrent::TorrentHandle *const torrent)
|
||||
const DeleteOption deleteOption = parseBool(params()["deleteFiles"], false)
|
||||
? TorrentAndFiles : Torrent;
|
||||
applyToTorrents(hashes, [deleteOption](const BitTorrent::TorrentHandle *torrent)
|
||||
{
|
||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteFiles);
|
||||
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteOption);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -552,12 +552,12 @@
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="settings">
|
||||
<legend>QBT_TR(Share Ratio Limiting)QBT_TR[CONTEXT=OptionsDialog]</legend>
|
||||
<legend>QBT_TR(Seeding Limits)QBT_TR[CONTEXT=OptionsDialog]</legend>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" id="max_ratio_checkbox" onclick="qBittorrent.Preferences.updateMaxRatioTimeEnabled();" />
|
||||
<label for="max_ratio_checkbox">QBT_TR(Seed torrents until their ratio reaches)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
<label for="max_ratio_checkbox">QBT_TR(When ratio reaches)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="max_ratio_value" style="width: 4em;" />
|
||||
@ -565,7 +565,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" id="max_seeding_time_checkbox" onclick="qBittorrent.Preferences.updateMaxRatioTimeEnabled();" />
|
||||
<label for="max_seeding_time_checkbox">QBT_TR(Seed torrents until their seeding time reaches)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
<label for="max_seeding_time_checkbox">QBT_TR(When seeding time reaches)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="max_seeding_time_value" style="width: 4em;" /> QBT_TR(minutes)QBT_TR[CONTEXT=OptionsDialog]
|
||||
@ -577,9 +577,10 @@
|
||||
</td>
|
||||
<td>
|
||||
<select id="max_ratio_act">
|
||||
<option value="0">QBT_TR(Pause them)QBT_TR[CONTEXT=OptionsDialog]</option>
|
||||
<option value="1">QBT_TR(Remove them)QBT_TR[CONTEXT=OptionsDialog]</option>
|
||||
<option value="2">QBT_TR(Enable super seeding for them)QBT_TR[CONTEXT=OptionsDialog]</option>
|
||||
<option value="0">QBT_TR(Pause torrent)QBT_TR[CONTEXT=OptionsDialog]</option>
|
||||
<option value="1">QBT_TR(Remove torrent)QBT_TR[CONTEXT=OptionsDialog]</option>
|
||||
<option value="3">QBT_TR(Remove torrent and its files)QBT_TR[CONTEXT=OptionsDialog]</option>
|
||||
<option value="2">QBT_TR(Enable super seeding for torrent)QBT_TR[CONTEXT=OptionsDialog]</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -1660,8 +1661,23 @@
|
||||
$('max_seeding_time_value').setProperty('value', pref.max_seeding_time.toInt());
|
||||
else
|
||||
$('max_seeding_time_value').setProperty('value', 1440);
|
||||
const max_ratio_act = pref.max_ratio_act.toInt();
|
||||
$('max_ratio_act').getChildren('option')[max_ratio_act].setAttribute('selected', '');
|
||||
let maxRatioAct = 0;
|
||||
switch (pref.max_ratio_act.toInt()) {
|
||||
case 0: // Pause
|
||||
default:
|
||||
maxRatioAct = 0;
|
||||
break;
|
||||
case 1: // Remove
|
||||
maxRatioAct = 1;
|
||||
break;
|
||||
case 2: // Enable super seeding
|
||||
maxRatioAct = 3;
|
||||
break;
|
||||
case 3: // Remove torrent and files
|
||||
maxRatioAct = 2;
|
||||
break;
|
||||
}
|
||||
$('max_ratio_act').getChildren('option')[maxRatioAct].setAttribute('selected', '');
|
||||
updateMaxRatioTimeEnabled();
|
||||
|
||||
// Add trackers
|
||||
|
Loading…
Reference in New Issue
Block a user