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

This commit is contained in:
thalieht 2019-09-18 19:26:01 +03:00
parent 19c70fd659
commit 07eb261991
7 changed files with 97 additions and 39 deletions

View file

@ -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);
@ -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);
}