Add option to automatically remove .torrent files upon adding

Some browsers do not download files, intended for immediate opening,
into a temporary directory, and thus a regular download directories
accumulate those unneeded files.

The option allows qBittorrent to clean after itself and delete those
files whether they were succesfully added or not (user-selectable
policy).
This commit is contained in:
Eugene Shalygin 2016-04-07 16:58:30 +02:00
parent 35c51ad3b1
commit 6e73fa80b8
10 changed files with 391 additions and 49 deletions

View file

@ -45,6 +45,7 @@
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "base/torrentfileguard.h"
#include "base/unicodestrings.h"
#include "guiiconprovider.h"
#include "autoexpandabledialog.h"
@ -94,6 +95,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
connect(ui->browseButton, SIGNAL(clicked()), SLOT(browseButton_clicked()));
ui->defaultSavePathCheckBox->setVisible(false); // Default path is selected by default
ui->doNotDeleteTorrentCheckBox->setVisible(TorrentFileGuard::autoDeleteMode() != TorrentFileGuard::Never);
// Load categories
QStringList categories = session->categories();
std::sort(categories.begin(), categories.end(), Utils::String::naturalCompareCaseInsensitive);
@ -112,6 +115,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
loadState();
// Signal / slots
connect(ui->adv_button, SIGNAL(clicked(bool)), SLOT(showAdvancedSettings(bool)));
connect(ui->doNotDeleteTorrentCheckBox, SIGNAL(clicked(bool)), SLOT(doNotDeleteTorrentClicked(bool)));
editHotkey = new QShortcut(QKeySequence("F2"), ui->contentTreeView, 0, 0, Qt::WidgetShortcut);
connect(editHotkey, SIGNAL(activated()), SLOT(renameSelectedFile()));
connect(ui->contentTreeView, SIGNAL(doubleClicked(QModelIndex)), SLOT(renameSelectedFile()));
@ -221,6 +225,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString &torrentPath)
return false;
}
m_torrentGuard.reset(new TorrentFileGuard(m_filePath));
m_hash = m_torrentInfo.hash();
// Prevent showing the dialog if download is already present
@ -647,6 +652,7 @@ void AddNewTorrentDialog::accept()
else
BitTorrent::Session::instance()->addTorrent(m_torrentInfo, params);
m_torrentGuard->markAsAddedToSession();
QDialog::accept();
}
@ -795,3 +801,8 @@ void AddNewTorrentDialog::setCommentText(const QString &str) const
int height = lineHeight * lines;
ui->scrollArea->setMaximumHeight(height);
}
void AddNewTorrentDialog::doNotDeleteTorrentClicked(bool checked)
{
m_torrentGuard->setAutoRemove(!checked);
}