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

View File

@@ -31,8 +31,9 @@
#ifndef ADDNEWTORRENTDIALOG_H
#define ADDNEWTORRENTDIALOG_H
#include <QShortcut>
#include <QDialog>
#include <QScopedPointer>
#include <QShortcut>
#include <QUrl>
#include "base/bittorrent/infohash.h"
@@ -49,6 +50,7 @@ namespace Ui
}
class TorrentContentFilterModel;
class TorrentFileGuard;
class PropListDelegate;
class AddNewTorrentDialog: public QDialog
@@ -79,6 +81,7 @@ private slots:
void handleDownloadFinished(const QString &url, const QString &filePath);
void savingModeChanged(bool enabled);
void categoryChanged(int index);
void doNotDeleteTorrentClicked(bool checked);
void accept() override;
void reject() override;
@@ -109,6 +112,7 @@ private:
QShortcut *editHotkey;
QByteArray m_headerState;
int m_oldIndex;
QScopedPointer<TorrentFileGuard> m_torrentGuard;
};
#endif // ADDNEWTORRENTDIALOG_H

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>414</width>
<height>590</height>
<height>661</height>
</rect>
</property>
<layout class="QVBoxLayout" name="AddNewTorrentDialogLayout">
@@ -95,6 +95,16 @@
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="doNotDeleteTorrentCheckBox">
<property name="toolTip">
<string>When checked, the .torrent file will not be deleted despite the settings at the &quot;Download&quot; page of the options dialog</string>
</property>
<property name="text">
<string>Do not delete .torrent file</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="never_show_cb">
<property name="text">
@@ -278,8 +288,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>301</width>
<height>73</height>
<width>308</width>
<height>74</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">

View File

@@ -113,9 +113,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-190</y>
<width>486</width>
<height>732</height>
<y>0</y>
<width>514</width>
<height>968</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
@@ -670,8 +670,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>487</width>
<height>1334</height>
<width>514</width>
<height>1537</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -719,6 +719,64 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="deleteTorrentBox">
<property name="toolTip">
<string>Should the .torrent file be deleted after adding it</string>
</property>
<property name="title">
<string>Delete .torrent files afterwards </string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<widget class="QCheckBox" name="deleteCancelledTorrentBox">
<property name="toolTip">
<string>Also delete .torrent files whose addition was cancelled</string>
</property>
<property name="text">
<string>Also when addition is cancelled</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="deleteTorrentWarningIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">&lt;&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="deleteTorrentWarningLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Warning! Data loss possible!</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
@@ -1364,8 +1422,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<height>658</height>
<width>457</width>
<height>713</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
@@ -1894,8 +1952,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>444</height>
<width>362</width>
<height>484</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -2281,8 +2339,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<height>527</height>
<width>587</width>
<height>578</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -2678,8 +2736,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>419</width>
<height>537</height>
<width>460</width>
<height>562</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
@@ -3130,12 +3188,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>544</x>
<y>172</y>
<x>604</x>
<y>205</y>
</hint>
<hint type="destinationlabel">
<x>603</x>
<y>171</y>
<x>677</x>
<y>206</y>
</hint>
</hints>
</connection>
@@ -3146,12 +3204,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>544</x>
<y>198</y>
<x>604</x>
<y>238</y>
</hint>
<hint type="destinationlabel">
<x>603</x>
<y>197</y>
<x>677</x>
<y>239</y>
</hint>
</hints>
</connection>
@@ -3162,12 +3220,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>544</x>
<y>250</y>
<x>604</x>
<y>304</y>
</hint>
<hint type="destinationlabel">
<x>603</x>
<y>249</y>
<x>677</x>
<y>305</y>
</hint>
</hints>
</connection>
@@ -3178,12 +3236,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>509</x>
<y>372</y>
<x>547</x>
<y>415</y>
</hint>
<hint type="destinationlabel">
<x>584</x>
<y>373</y>
<x>642</x>
<y>414</y>
</hint>
</hints>
</connection>
@@ -3194,12 +3252,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>509</x>
<y>372</y>
<x>547</x>
<y>415</y>
</hint>
<hint type="destinationlabel">
<x>721</x>
<y>373</y>
<x>815</x>
<y>413</y>
</hint>
</hints>
</connection>
@@ -3210,12 +3268,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>423</x>
<y>224</y>
<x>604</x>
<y>271</y>
</hint>
<hint type="destinationlabel">
<x>571</x>
<y>224</y>
<x>677</x>
<y>272</y>
</hint>
</hints>
</connection>
@@ -3226,12 +3284,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>398</x>
<y>292</y>
<x>395</x>
<y>203</y>
</hint>
<hint type="destinationlabel">
<x>477</x>
<y>292</y>
<x>496</x>
<y>204</y>
</hint>
</hints>
</connection>
@@ -3242,12 +3300,44 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>398</x>
<y>263</y>
<x>395</x>
<y>170</y>
</hint>
<hint type="destinationlabel">
<x>477</x>
<y>263</y>
<x>496</x>
<y>171</y>
</hint>
</hints>
</connection>
<connection>
<sender>deleteTorrentBox</sender>
<signal>toggled(bool)</signal>
<receiver>deleteTorrentWarningIcon</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>554</x>
<y>153</y>
</hint>
<hint type="destinationlabel">
<x>324</x>
<y>214</y>
</hint>
</hints>
</connection>
<connection>
<sender>deleteTorrentBox</sender>
<signal>toggled(bool)</signal>
<receiver>deleteTorrentWarningLabel</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>646</x>
<y>158</y>
</hint>
<hint type="destinationlabel">
<x>629</x>
<y>207</y>
</hint>
</hints>
</connection>

View File

@@ -49,6 +49,7 @@
#include "base/bittorrent/session.h"
#include "base/net/dnsupdater.h"
#include "base/unicodestrings.h"
#include "base/torrentfileguard.h"
#include "advancedsettings.h"
#include "guiiconprovider.h"
#include "scanfoldersdelegate.h"
@@ -88,6 +89,22 @@ options_imp::options_imp(QWidget *parent)
IpFilterRefreshBtn->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
deleteTorrentWarningIcon->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(16, 16));
deleteTorrentWarningIcon->hide();
deleteTorrentWarningLabel->hide();
deleteTorrentWarningLabel->setToolTip(QLatin1String("<html><body><p>") +
tr("By enabling these options, you can <strong>irrevocably lose</strong> your .torrent files!") +
QLatin1String("</p><p>") +
tr("When these options are enabled, qBittorent will <strong>delete</strong> .torrent files "
"after they were successfully (the first option) or not (the second option) added to its "
"download queue. This will be applied <strong>not only</strong> to the files opened via "
"&ldquo;Add torrent&rdquo; menu action but to those opened via <strong>file type association</strong> as well") +
QLatin1String("</p><p>") +
tr("If you enable the second option (&ldquo;Also when addition is cancelled&rdquo;) the "
".torrent file <strong>will be deleted</strong> even if you press &ldquo;<strong>Cancel</strong>&rdquo; in "
"the &ldquo;Add torrent&rdquo; dialog") +
QLatin1String("</p></body></html>"));
hsplitter->setCollapsible(0, false);
hsplitter->setCollapsible(1, false);
// Get apply button in button box
@@ -193,6 +210,8 @@ options_imp::options_imp(QWidget *parent)
connect(checkAdditionDialog, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkAdditionDialogFront, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkStartPaused, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(deleteTorrentBox, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(deleteCancelledTorrentBox, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkExportDir, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkExportDirFin, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(textExportDir, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
@@ -500,6 +519,9 @@ void options_imp::saveOptions()
pref->setAutoRunProgram(autoRun_txt->text().trimmed());
pref->setActionOnDblClOnTorrentDl(getActionOnDblClOnTorrentDl());
pref->setActionOnDblClOnTorrentFn(getActionOnDblClOnTorrentFn());
TorrentFileGuard::setautoDeleteMode(!deleteTorrentBox->isChecked() ? TorrentFileGuard::Never
: !deleteCancelledTorrentBox->isChecked() ? TorrentFileGuard::IfAdded
: TorrentFileGuard::Always);
// End Downloads preferences
// Connection preferences
@@ -676,6 +698,9 @@ void options_imp::loadOptions()
checkAdditionDialog->setChecked(AddNewTorrentDialog::isEnabled());
checkAdditionDialogFront->setChecked(AddNewTorrentDialog::isTopLevel());
checkStartPaused->setChecked(session->isAddTorrentPaused());
const TorrentFileGuard::AutoDeleteMode autoDeleteMode = TorrentFileGuard::autoDeleteMode();
deleteTorrentBox->setChecked(autoDeleteMode != TorrentFileGuard::Never);
deleteCancelledTorrentBox->setChecked(autoDeleteMode == TorrentFileGuard::Always);
textSavePath->setText(Utils::Fs::toNativePath(session->defaultSavePath()));
(session->isSubcategoriesEnabled() ? radioBtnEnableSubcategories : radioBtnDisableSubcategories)->setChecked(true);