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()
LogMsg(tr("'%1' reached the maximum ratio you set. Removed.").arg(torrent->name())); LogMsg(tr("'%1' reached the maximum ratio you set. Removed.").arg(torrent->name()));
deleteTorrent(torrent->hash()); 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()) { else if ((m_maxRatioAction == Pause) && !torrent->isPaused()) {
torrent->pause(); torrent->pause();
LogMsg(tr("'%1' reached the maximum ratio you set. Paused.").arg(torrent->name())); 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())); LogMsg(tr("'%1' reached the maximum seeding time you set. Removed.").arg(torrent->name()));
deleteTorrent(torrent->hash()); 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()) { else if ((m_maxRatioAction == Pause) && !torrent->isPaused()) {
torrent->pause(); torrent->pause();
LogMsg(tr("'%1' reached the maximum seeding time you set. Paused.").arg(torrent->name())); 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 // Delete a torrent from the session, given its hash
// deleteLocalFiles = true means that the torrent will be removed from the hard-drive too // and from the disk, if the corresponding deleteOption is chosen
bool Session::deleteTorrent(const QString &hash, const bool deleteLocalFiles) bool Session::deleteTorrent(const QString &hash, const DeleteOption deleteOption)
{ {
TorrentHandle *const torrent = m_torrents.take(hash); TorrentHandle *const torrent = m_torrents.take(hash);
if (!torrent) return false; if (!torrent) return false;
@ -1626,20 +1634,8 @@ bool Session::deleteTorrent(const QString &hash, const bool deleteLocalFiles)
emit torrentAboutToBeRemoved(torrent); emit torrentAboutToBeRemoved(torrent);
// Remove it from session // Remove it from session
if (deleteLocalFiles) { if (deleteOption == Torrent) {
const QString rootPath = torrent->rootPath(true); m_removingTorrents[torrent->hash()] = {torrent->name(), "", deleteOption};
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};
QStringList unwantedFiles; QStringList unwantedFiles;
if (torrent->hasMetadata()) if (torrent->hasMetadata())
unwantedFiles = torrent->absoluteFilePathsUnwanted(); unwantedFiles = torrent->absoluteFilePathsUnwanted();
@ -1653,6 +1649,21 @@ bool Session::deleteTorrent(const QString &hash, const bool deleteLocalFiles)
QDir().rmdir(parentFolder); 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 // Remove it from torrent resume directory
const QDir resumeDataDir(m_resumeFolderPath); const QDir resumeDataDir(m_resumeFolderPath);
@ -4007,7 +4018,7 @@ void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p)
if (m_removingTorrents.contains(infoHash)) { if (m_removingTorrents.contains(infoHash)) {
const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents[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)); LogMsg(tr("'%1' was removed from the transfer list.", "'xxx.avi' was removed...").arg(tmpRemovingTorrentData.name));
m_removingTorrents.remove(infoHash); m_removingTorrents.remove(infoHash);
} }

19
src/base/bittorrent/session.h

@ -59,11 +59,20 @@ class BandwidthScheduler;
class Statistics; class Statistics;
class ResumeDataSavingManager; class ResumeDataSavingManager;
// These values should remain unchanged when adding new items
// so as not to break the existing user settings.
enum MaxRatioAction enum MaxRatioAction
{ {
Pause, Pause = 0,
Remove, Remove = 1,
EnableSuperSeeding DeleteFiles = 3,
EnableSuperSeeding = 2
};
enum DeleteOption
{
Torrent,
TorrentAndFiles
}; };
enum TorrentExportFolder enum TorrentExportFolder
@ -413,7 +422,7 @@ namespace BitTorrent
bool isKnownTorrent(const InfoHash &hash) const; bool isKnownTorrent(const InfoHash &hash) const;
bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams()); bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams());
bool addTorrent(const TorrentInfo &torrentInfo, 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 loadMetadata(const MagnetUri &magnetUri);
bool cancelLoadMetadata(const InfoHash &hash); bool cancelLoadMetadata(const InfoHash &hash);
@ -506,7 +515,7 @@ namespace BitTorrent
{ {
QString name; QString name;
QString savePathToRemove; QString savePathToRemove;
bool requestedFileDeletion; DeleteOption deleteOption;
}; };
explicit Session(QObject *parent = nullptr); explicit Session(QObject *parent = nullptr);

18
src/gui/optionsdialog.cpp

@ -747,7 +747,14 @@ void OptionsDialog::saveOptions()
session->setAdditionalTrackers(m_ui->textTrackers->toPlainText()); session->setAdditionalTrackers(m_ui->textTrackers->toPlainText());
session->setGlobalMaxRatio(getMaxRatio()); session->setGlobalMaxRatio(getMaxRatio());
session->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes()); 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 // End Bittorrent preferences
// Misc preferences // Misc preferences
@ -1130,7 +1137,14 @@ void OptionsDialog::loadOptions()
m_ui->spinMaxSeedingMinutes->setEnabled(false); m_ui->spinMaxSeedingMinutes->setEnabled(false);
} }
m_ui->comboRatioLimitAct->setEnabled((session->globalMaxSeedingMinutes() >= 0) || (session->globalMaxRatio() >= 0.)); 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 // End Bittorrent preferences
// Web UI preferences // Web UI preferences

11
src/gui/optionsdialog.ui

@ -2485,17 +2485,22 @@
</property> </property>
<item> <item>
<property name="text"> <property name="text">
<string>Pause them</string> <string>Pause torrent</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>Remove them</string> <string>Remove torrent</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <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> </property>
</item> </item>
</widget> </widget>

10
src/gui/transferlistwidget.cpp

@ -371,8 +371,9 @@ void TransferListWidget::deleteSelectedTorrents(bool deleteLocalFiles)
if (Preferences::instance()->confirmTorrentDeletion() if (Preferences::instance()->confirmTorrentDeletion()
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name())) && !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
return; return;
for (BitTorrent::TorrentHandle *const torrent : torrents) const DeleteOption deleteOption = deleteLocalFiles ? TorrentAndFiles : Torrent;
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles); for (const BitTorrent::TorrentHandle *torrent : torrents)
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteOption);
} }
void TransferListWidget::deleteVisibleTorrents() void TransferListWidget::deleteVisibleTorrents()
@ -388,8 +389,9 @@ void TransferListWidget::deleteVisibleTorrents()
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name())) && !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
return; return;
for (BitTorrent::TorrentHandle *const torrent : asConst(torrents)) const DeleteOption deleteOption = deleteLocalFiles ? TorrentAndFiles : Torrent;
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles); for (const BitTorrent::TorrentHandle *torrent : asConst(torrents))
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteOption);
} }
void TransferListWidget::increaseQueuePosSelectedTorrents() void TransferListWidget::increaseQueuePosSelectedTorrents()

7
src/webui/api/torrentscontroller.cpp

@ -885,10 +885,11 @@ void TorrentsController::deleteAction()
checkParams({"hashes", "deleteFiles"}); checkParams({"hashes", "deleteFiles"});
const QStringList hashes {params()["hashes"].split('|')}; const QStringList hashes {params()["hashes"].split('|')};
const bool deleteFiles {parseBool(params()["deleteFiles"], false)}; const DeleteOption deleteOption = parseBool(params()["deleteFiles"], false)
applyToTorrents(hashes, [deleteFiles](BitTorrent::TorrentHandle *const torrent) ? 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 @@
</td> </td>
<td> <td>
<select id="max_ratio_act"> <select id="max_ratio_act">
<option value="0">QBT_TR(Pause them)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="0">QBT_TR(Pause torrent)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="1">QBT_TR(Remove them)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="1">QBT_TR(Remove torrent)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="2">QBT_TR(Enable super seeding for them)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> </select>
</td> </td>
</tr> </tr>
@ -1660,8 +1661,23 @@
$('max_seeding_time_value').setProperty('value', pref.max_seeding_time.toInt()); $('max_seeding_time_value').setProperty('value', pref.max_seeding_time.toInt());
else else
$('max_seeding_time_value').setProperty('value', 1440); $('max_seeding_time_value').setProperty('value', 1440);
const max_ratio_act = pref.max_ratio_act.toInt(); let maxRatioAct = 0;
$('max_ratio_act').getChildren('option')[max_ratio_act].setAttribute('selected', ''); 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(); updateMaxRatioTimeEnabled();
// Add trackers // Add trackers

Loading…
Cancel
Save