1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-04 19:04:30 +00:00

Add setting to copy .torrent files for finished downloads (closes issue #22)

Patch edited by Christophe Dumez.
This commit is contained in:
Driim 2012-08-21 11:16:49 +04:00 committed by Christophe Dumez
parent dac0d67717
commit 23ea811095
7 changed files with 159 additions and 47 deletions

60
src/preferences/options.ui Normal file → Executable file
View File

@ -508,9 +508,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-373</y>
<width>486</width> <width>486</width>
<height>952</height> <height>1025</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -561,9 +561,6 @@
<string>Hard Disk</string> <string>Hard Disk</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_25"> <layout class="QVBoxLayout" name="verticalLayout_25">
<property name="bottomMargin">
<number>9</number>
</property>
<item> <item>
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">
@ -818,6 +815,55 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="checkExportDirFin">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="title">
<string>Copy .torrent files for finished downloads to:</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_13">
<property name="bottomMargin">
<number>9</number>
</property>
<item row="0" column="0">
<widget class="QLineEdit" name="textExportDirFin"/>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="browseExportDirFinButton">
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>25</width>
<height>27</height>
</size>
</property>
<property name="text">
<string notr="true">...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -969,7 +1015,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>486</width> <width>474</width>
<height>577</height> <height>577</height>
</rect> </rect>
</property> </property>
@ -1413,7 +1459,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>486</width> <width>395</width>
<height>480</height> <height>480</height>
</rect> </rect>
</property> </property>

61
src/preferences/options_imp.cpp Normal file → Executable file
View File

@ -161,7 +161,9 @@ options_imp::options_imp(QWidget *parent):
connect(checkAdditionDialog, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkAdditionDialog, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkStartPaused, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkStartPaused, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkExportDir, 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())); connect(textExportDir, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(textExportDirFin, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(actionTorrentDlOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(actionTorrentDlOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(actionTorrentFnOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(actionTorrentFnOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
@ -395,11 +397,14 @@ void options_imp::saveOptions() {
pref.addTorrentsInPause(addTorrentsInPause()); pref.addTorrentsInPause(addTorrentsInPause());
ScanFoldersModel::instance()->makePersistent(); ScanFoldersModel::instance()->makePersistent();
addedScanDirs.clear(); addedScanDirs.clear();
QString export_dir = getExportDir(); QString export_dir = getTorrentExportDir();
QString export_dir_fin = getFinishedTorrentExportDir();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
export_dir_fin.replace("\\", "/");
export_dir.replace("\\", "/"); export_dir.replace("\\", "/");
#endif #endif
pref.setExportDir(export_dir); pref.setTorrentExportDir(export_dir);
pref.setFinishedTorrentExportDir(export_dir_fin);
pref.setMailNotificationEnabled(groupMailNotification->isChecked()); pref.setMailNotificationEnabled(groupMailNotification->isChecked());
pref.setMailNotificationEmail(dest_email_txt->text()); pref.setMailNotificationEmail(dest_email_txt->text());
pref.setMailNotificationSMTP(smtp_server_txt->text()); pref.setMailNotificationSMTP(smtp_server_txt->text());
@ -569,7 +574,7 @@ void options_imp::loadOptions() {
checkAdditionDialog->setChecked(pref.useAdditionDialog()); checkAdditionDialog->setChecked(pref.useAdditionDialog());
checkStartPaused->setChecked(pref.addTorrentsInPause()); checkStartPaused->setChecked(pref.addTorrentsInPause());
strValue = pref.getExportDir(); strValue = pref.getTorrentExportDir();
if (strValue.isEmpty()) { if (strValue.isEmpty()) {
// Disable // Disable
checkExportDir->setChecked(false); checkExportDir->setChecked(false);
@ -581,6 +586,19 @@ void options_imp::loadOptions() {
#endif #endif
textExportDir->setText(strValue); textExportDir->setText(strValue);
} }
strValue = pref.getFinishedTorrentExportDir();
if (strValue.isEmpty()) {
// Disable
checkExportDirFin->setChecked(false);
} else {
// enable
checkExportDirFin->setChecked(true);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
strValue.replace("/", "\\");
#endif
textExportDirFin->setText(strValue);
}
groupMailNotification->setChecked(pref.isMailNotificationEnabled()); groupMailNotification->setChecked(pref.isMailNotificationEnabled());
dest_email_txt->setText(pref.getMailNotificationEmail()); dest_email_txt->setText(pref.getMailNotificationEmail());
smtp_server_txt->setText(pref.getMailNotificationSMTP()); smtp_server_txt->setText(pref.getMailNotificationSMTP());
@ -1016,12 +1034,18 @@ void options_imp::setLocale(const QString &localeStr) {
comboI18n->setCurrentIndex(index); comboI18n->setCurrentIndex(index);
} }
QString options_imp::getExportDir() const { QString options_imp::getTorrentExportDir() const {
if (checkExportDir->isChecked()) if (checkExportDir->isChecked())
return fsutils::expandPath(textExportDir->text()); return fsutils::expandPath(textExportDir->text());
return QString(); return QString();
} }
QString options_imp::getFinishedTorrentExportDir() const {
if (checkExportDirFin->isChecked())
return fsutils::expandPath(textExportDirFin->text());
return QString();
}
// Return action on double-click on a downloading torrent set in options // Return action on double-click on a downloading torrent set in options
int options_imp::getActionOnDblClOnTorrentDl() const { int options_imp::getActionOnDblClOnTorrentDl() const {
if (actionTorrentDlOnDblClBox->currentIndex() < 1) if (actionTorrentDlOnDblClBox->currentIndex() < 1)
@ -1075,21 +1099,28 @@ void options_imp::handleScanFolderViewSelectionChanged() {
removeScanFolderButton->setEnabled(!scanFoldersView->selectionModel()->selectedIndexes().isEmpty()); removeScanFolderButton->setEnabled(!scanFoldersView->selectionModel()->selectedIndexes().isEmpty());
} }
void options_imp::on_browseExportDirButton_clicked() { QString options_imp::askForExportDir(const QString& currentExportPath)
const QString export_path = fsutils::expandPath(textExportDir->text()); {
QDir exportDir(export_path); QDir currentExportDir(fsutils::expandPath(currentExportPath));
QString dir; QString dir;
if (!export_path.isEmpty() && exportDir.exists()) { if (!currentExportPath.isEmpty() && currentExportDir.exists()) {
dir = QFileDialog::getExistingDirectory(this, tr("Choose export directory"), exportDir.absolutePath()); dir = QFileDialog::getExistingDirectory(this, tr("Choose export directory"), currentExportDir.absolutePath());
} else { } else {
dir = QFileDialog::getExistingDirectory(this, tr("Choose export directory"), QDir::homePath()); dir = QFileDialog::getExistingDirectory(this, tr("Choose export directory"), QDir::homePath());
} }
if (!dir.isNull()) { return dir;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) }
dir.replace("/", "\\");
#endif void options_imp::on_browseExportDirButton_clicked() {
textExportDir->setText(dir); const QString newExportDir = askForExportDir(textExportDir->text());
} if (!newExportDir.isNull())
textExportDir->setText(fsutils::toDisplayPath(newExportDir));
}
void options_imp::on_browseExportDirFinButton_clicked() {
const QString newExportDir = askForExportDir(textExportDirFin->text());
if (!newExportDir.isNull())
textExportDirFin->setText(fsutils::toDisplayPath(newExportDir));
} }
void options_imp::on_browseFilterButton_clicked() { void options_imp::on_browseFilterButton_clicked() {

5
src/preferences/options_imp.h Normal file → Executable file
View File

@ -74,6 +74,7 @@ private slots:
void on_IpFilterRefreshBtn_clicked(); void on_IpFilterRefreshBtn_clicked();
void handleIPFilterParsed(bool error, int ruleCount); void handleIPFilterParsed(bool error, int ruleCount);
void on_browseExportDirButton_clicked(); void on_browseExportDirButton_clicked();
void on_browseExportDirFinButton_clicked();
void on_browseFilterButton_clicked(); void on_browseFilterButton_clicked();
void on_browseSaveDirButton_clicked(); void on_browseSaveDirButton_clicked();
void on_browseTempDirButton_clicked(); void on_browseTempDirButton_clicked();
@ -107,7 +108,9 @@ private:
bool preAllocateAllFiles() const; bool preAllocateAllFiles() const;
bool useAdditionDialog() const; bool useAdditionDialog() const;
bool addTorrentsInPause() const; bool addTorrentsInPause() const;
QString getExportDir() const; QString getTorrentExportDir() const;
QString getFinishedTorrentExportDir() const;
QString askForExportDir(const QString& currentExportPath);
int getActionOnDblClOnTorrentDl() const; int getActionOnDblClOnTorrentDl() const;
int getActionOnDblClOnTorrentFn() const; int getActionOnDblClOnTorrentFn() const;
// Connection options // Connection options

25
src/preferences/preferences.h Normal file → Executable file
View File

@ -276,18 +276,33 @@ public:
} }
bool isTorrentExportEnabled() const { bool isTorrentExportEnabled() const {
return !value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString().isEmpty(); return !value(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), QString()).toString().isEmpty();
} }
QString getExportDir() const { QString getTorrentExportDir() const {
return value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString(); return value(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), QString()).toString();
} }
void setExportDir(QString path) { void setTorrentExportDir(QString path) {
path = path.trimmed(); path = path.trimmed();
if (path.isEmpty()) if (path.isEmpty())
path = QString(); path = QString();
setValue(QString::fromUtf8("Preferences/Downloads/TorrentExport"), path); setValue(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), path);
}
bool isFinishedTorrentExportEnabled() const {
return !value(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), QString()).toString().isEmpty();
}
QString getFinishedTorrentExportDir() const {
return value(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), QString()).toString();
}
void setFinishedTorrentExportDir(QString path) {
path = path.trimmed();
if (path.isEmpty())
path = QString();
setValue(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), path);
} }
bool isMailNotificationEnabled() const { bool isMailNotificationEnabled() const {

41
src/qtlibtorrent/qbtsession.cpp Normal file → Executable file
View File

@ -104,7 +104,8 @@ QBtSession::QBtSession()
preAllocateAll(false), global_ratio_limit(-1), preAllocateAll(false), global_ratio_limit(-1),
LSDEnabled(false), LSDEnabled(false),
DHTEnabled(false), current_dht_port(0), queueingEnabled(false), DHTEnabled(false), current_dht_port(0), queueingEnabled(false),
torrentExport(false) m_torrentExportEnabled(false),
m_finishedTorrentExportEnabled(false)
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
, geoipDBLoaded(false), resolve_countries(false) , geoipDBLoaded(false), resolve_countries(false)
#endif #endif
@ -301,15 +302,19 @@ void QBtSession::configureSession() {
setAppendLabelToSavePath(pref.appendTorrentLabel()); setAppendLabelToSavePath(pref.appendTorrentLabel());
setAppendqBExtension(pref.useIncompleteFilesExtension()); setAppendqBExtension(pref.useIncompleteFilesExtension());
preAllocateAllFiles(pref.preAllocateAllFiles()); preAllocateAllFiles(pref.preAllocateAllFiles());
// * Export Dir // * Torrent export directory
const bool newTorrentExport = pref.isTorrentExportEnabled(); const bool torrentExportEnabled = pref.isTorrentExportEnabled();
if (torrentExport != newTorrentExport) { if (m_torrentExportEnabled != torrentExportEnabled) {
torrentExport = newTorrentExport; m_torrentExportEnabled = torrentExportEnabled;
if (torrentExport) { if (m_torrentExportEnabled) {
qDebug("Torrent export is enabled, exporting the current torrents"); qDebug("Torrent export is enabled, exporting the current torrents");
exportTorrentFiles(pref.getExportDir()); exportTorrentFiles(pref.getTorrentExportDir());
} }
} }
// * Finished Torrent export directory
const bool finishedTorrentExportEnabled = pref.isFinishedTorrentExportEnabled();
if (m_finishedTorrentExportEnabled != finishedTorrentExportEnabled)
m_finishedTorrentExportEnabled = finishedTorrentExportEnabled;
// Connection // Connection
// * Global download limit // * Global download limit
const bool alternative_speeds = pref.isAltBandwidthEnabled(); const bool alternative_speeds = pref.isAltBandwidthEnabled();
@ -884,7 +889,10 @@ void QBtSession::loadTorrentSettings(QTorrentHandle& h) {
#endif #endif
} }
QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool fromScanDir, const QString &filePath) { QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool fromScanDir, const QString &filePath)
{
Q_UNUSED(fromScanDir);
Q_UNUSED(filePath);
Preferences pref; Preferences pref;
QTorrentHandle h; QTorrentHandle h;
const QString hash(misc::magnetUriToHash(magnet_uri)); const QString hash(misc::magnetUriToHash(magnet_uri));
@ -1168,7 +1176,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
if (path != newFile) if (path != newFile)
QFile::copy(path, newFile); QFile::copy(path, newFile);
// Copy the torrent file to the export folder // Copy the torrent file to the export folder
if (torrentExport) if (m_torrentExportEnabled)
exportTorrentFile(h); exportTorrentFile(h);
} }
@ -1199,10 +1207,11 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
return h; return h;
} }
void QBtSession::exportTorrentFile(const QTorrentHandle &h) { void QBtSession::exportTorrentFile(const QTorrentHandle& h, TorrentExportFolder folder) {
Q_ASSERT(torrentExport); Q_ASSERT((folder == RegularTorrentExportFolder && m_torrentExportEnabled) ||
(folder == FinishedTorrentExportFolder && m_finishedTorrentExportEnabled));
QString torrent_path = QDir(fsutils::BTBackupLocation()).absoluteFilePath(h.hash()+".torrent"); QString torrent_path = QDir(fsutils::BTBackupLocation()).absoluteFilePath(h.hash()+".torrent");
QDir exportPath(Preferences().getExportDir()); QDir exportPath(folder == RegularTorrentExportFolder ? Preferences().getTorrentExportDir() : Preferences().getFinishedTorrentExportDir());
if (exportPath.exists() || exportPath.mkpath(exportPath.absolutePath())) { if (exportPath.exists() || exportPath.mkpath(exportPath.absolutePath())) {
QString new_torrent_path = exportPath.absoluteFilePath(h.name()+".torrent"); QString new_torrent_path = exportPath.absoluteFilePath(h.name()+".torrent");
if (QFile::exists(new_torrent_path) && fsutils::sameFiles(torrent_path, new_torrent_path)) { if (QFile::exists(new_torrent_path) && fsutils::sameFiles(torrent_path, new_torrent_path)) {
@ -1210,7 +1219,6 @@ void QBtSession::exportTorrentFile(const QTorrentHandle &h) {
new_torrent_path = exportPath.absoluteFilePath(h.name()+"-"+h.hash()+".torrent"); new_torrent_path = exportPath.absoluteFilePath(h.name()+"-"+h.hash()+".torrent");
} }
QFile::copy(torrent_path, new_torrent_path); QFile::copy(torrent_path, new_torrent_path);
//h.save_torrent_file(torrent_path);
} }
} }
@ -1364,7 +1372,7 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren
} }
void QBtSession::exportTorrentFiles(QString path) { void QBtSession::exportTorrentFiles(QString path) {
Q_ASSERT(torrentExport); Q_ASSERT(m_torrentExportEnabled);
QDir exportDir(path); QDir exportDir(path);
if (!exportDir.exists()) { if (!exportDir.exists()) {
if (!exportDir.mkpath(exportDir.absolutePath())) { if (!exportDir.mkpath(exportDir.absolutePath())) {
@ -2236,6 +2244,9 @@ void QBtSession::readAlerts() {
// AutoRun program // AutoRun program
if (pref.isAutoRunEnabled()) if (pref.isAutoRunEnabled())
autoRunExternalProgram(h, will_shutdown); autoRunExternalProgram(h, will_shutdown);
// Move .torrent file to another folder
if (pref.isFinishedTorrentExportEnabled())
exportTorrentFile(h, FinishedTorrentExportFolder);
// Mail notification // Mail notification
if (pref.isMailNotificationEnabled()) if (pref.isMailNotificationEnabled())
sendNotificationEmail(h); sendNotificationEmail(h);
@ -2366,7 +2377,7 @@ void QBtSession::readAlerts() {
if (!QFile::exists(torrentBackup.absoluteFilePath(h.hash()+QString(".torrent")))) if (!QFile::exists(torrentBackup.absoluteFilePath(h.hash()+QString(".torrent"))))
h.save_torrent_file(torrentBackup.absoluteFilePath(h.hash()+QString(".torrent"))); h.save_torrent_file(torrentBackup.absoluteFilePath(h.hash()+QString(".torrent")));
// Copy the torrent file to the export folder // Copy the torrent file to the export folder
if (torrentExport) if (m_torrentExportEnabled)
exportTorrentFile(h); exportTorrentFile(h);
// Append .!qB to incomplete files // Append .!qB to incomplete files
if (appendqBExtension) if (appendqBExtension)

10
src/qtlibtorrent/qbtsession.h Normal file → Executable file
View File

@ -63,6 +63,11 @@ class DNSUpdater;
const int MAX_LOG_MESSAGES = 100; const int MAX_LOG_MESSAGES = 100;
enum TorrentExportFolder {
RegularTorrentExportFolder,
FinishedTorrentExportFolder
};
class QBtSession : public QObject { class QBtSession : public QObject {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(QBtSession) Q_DISABLE_COPY(QBtSession)
@ -187,7 +192,7 @@ private slots:
void autoRunExternalProgram(const QTorrentHandle &h, bool async=true); void autoRunExternalProgram(const QTorrentHandle &h, bool async=true);
void cleanUpAutoRunProcess(int); void cleanUpAutoRunProcess(int);
void mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<libtorrent::torrent_info> t); void mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<libtorrent::torrent_info> t);
void exportTorrentFile(const QTorrentHandle &h); void exportTorrentFile(const QTorrentHandle &h, TorrentExportFolder folder = RegularTorrentExportFolder);
void initWebUi(); void initWebUi();
void handleIPFilterParsed(int ruleCount); void handleIPFilterParsed(int ruleCount);
void handleIPFilterError(); void handleIPFilterError();
@ -245,7 +250,8 @@ private:
bool PeXEnabled; bool PeXEnabled;
bool queueingEnabled; bool queueingEnabled;
bool appendLabelToSavePath; bool appendLabelToSavePath;
bool torrentExport; bool m_torrentExportEnabled;
bool m_finishedTorrentExportEnabled;
bool appendqBExtension; bool appendqBExtension;
QString defaultSavePath; QString defaultSavePath;
QString defaultTempPath; QString defaultTempPath;

View File

@ -63,7 +63,7 @@ QString prefjson::getPreferences()
} }
data.add("download_in_scan_dirs", var_list); data.add("download_in_scan_dirs", var_list);
data.add("export_dir_enabled", pref.isTorrentExportEnabled()); data.add("export_dir_enabled", pref.isTorrentExportEnabled());
data.add("export_dir", pref.getExportDir()); data.add("export_dir", pref.getTorrentExportDir());
data.add("mail_notification_enabled", pref.isMailNotificationEnabled()); data.add("mail_notification_enabled", pref.isMailNotificationEnabled());
data.add("mail_notification_email", pref.getMailNotificationEmail()); data.add("mail_notification_email", pref.getMailNotificationEmail());
data.add("mail_notification_smtp", pref.getMailNotificationSMTP()); data.add("mail_notification_smtp", pref.getMailNotificationSMTP());
@ -198,7 +198,7 @@ void prefjson::setPreferences(const QString& json)
} }
} }
if (m.contains("export_dir")) if (m.contains("export_dir"))
pref.setExportDir(m["export_dir"].toString()); pref.setTorrentExportDir(m["export_dir"].toString());
if (m.contains("mail_notification_enabled")) if (m.contains("mail_notification_enabled"))
pref.setMailNotificationEnabled(m["mail_notification_enabled"].toBool()); pref.setMailNotificationEnabled(m["mail_notification_enabled"].toBool());
if (m.contains("mail_notification_email")) if (m.contains("mail_notification_email"))