Browse Source

Add "Remove torrent and its files" option to share ratio limiting

adaptive-webui-19844
thalieht 5 years ago
parent
commit
07eb261991
  1. 45
      src/base/bittorrent/session.cpp
  2. 19
      src/base/bittorrent/session.h
  3. 18
      src/gui/optionsdialog.cpp
  4. 11
      src/gui/optionsdialog.ui
  5. 10
      src/gui/transferlistwidget.cpp
  6. 7
      src/webui/api/torrentscontroller.cpp
  7. 26
      src/webui/www/private/views/preferences.html

45
src/base/bittorrent/session.cpp

@ -1508,6 +1508,10 @@ void Session::processShareLimits() @@ -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() @@ -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) @@ -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) @@ -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) @@ -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);
@ -4007,7 +4018,7 @@ void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p) @@ -4007,7 +4018,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);
}

19
src/base/bittorrent/session.h

@ -59,11 +59,20 @@ class BandwidthScheduler; @@ -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
@ -413,7 +422,7 @@ namespace BitTorrent @@ -413,7 +422,7 @@ namespace BitTorrent
bool isKnownTorrent(const InfoHash &hash) const;
bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams());
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = 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);
@ -506,7 +515,7 @@ namespace BitTorrent @@ -506,7 +515,7 @@ namespace BitTorrent
{
QString name;
QString savePathToRemove;
bool requestedFileDeletion;
DeleteOption deleteOption;
};
explicit Session(QObject *parent = nullptr);

18
src/gui/optionsdialog.cpp

@ -747,7 +747,14 @@ void OptionsDialog::saveOptions() @@ -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() @@ -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

11
src/gui/optionsdialog.ui

@ -2485,17 +2485,22 @@ @@ -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>

10
src/gui/transferlistwidget.cpp

@ -371,8 +371,9 @@ void TransferListWidget::deleteSelectedTorrents(bool deleteLocalFiles) @@ -371,8 +371,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()
@ -388,8 +389,9 @@ void TransferListWidget::deleteVisibleTorrents() @@ -388,8 +389,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()

7
src/webui/api/torrentscontroller.cpp

@ -885,10 +885,11 @@ void TorrentsController::deleteAction() @@ -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);
});
}

26
src/webui/www/private/views/preferences.html

@ -577,9 +577,10 @@ @@ -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 @@ @@ -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…
Cancel
Save