Browse Source

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

Patch edited by Christophe Dumez.
adaptive-webui-19844
Driim 12 years ago committed by Christophe Dumez
parent
commit
23ea811095
  1. 60
      src/preferences/options.ui
  2. 61
      src/preferences/options_imp.cpp
  3. 5
      src/preferences/options_imp.h
  4. 25
      src/preferences/preferences.h
  5. 41
      src/qtlibtorrent/qbtsession.cpp
  6. 10
      src/qtlibtorrent/qbtsession.h
  7. 4
      src/webui/prefjson.cpp

60
src/preferences/options.ui

@ -508,9 +508,9 @@ @@ -508,9 +508,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-373</y>
<width>486</width>
<height>952</height>
<height>1025</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -561,9 +561,6 @@ @@ -561,9 +561,6 @@
<string>Hard Disk</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
@ -818,6 +815,55 @@ @@ -818,6 +815,55 @@
</layout>
</widget>
</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>
</widget>
</item>
@ -969,7 +1015,7 @@ @@ -969,7 +1015,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>486</width>
<width>474</width>
<height>577</height>
</rect>
</property>
@ -1413,7 +1459,7 @@ @@ -1413,7 +1459,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>486</width>
<width>395</width>
<height>480</height>
</rect>
</property>

61
src/preferences/options_imp.cpp

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

5
src/preferences/options_imp.h

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

25
src/preferences/preferences.h

@ -276,18 +276,33 @@ public: @@ -276,18 +276,33 @@ public:
}
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 {
return value(QString::fromUtf8("Preferences/Downloads/TorrentExport"), QString()).toString();
QString getTorrentExportDir() const {
return value(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), QString()).toString();
}
void setExportDir(QString path) {
void setTorrentExportDir(QString path) {
path = path.trimmed();
if (path.isEmpty())
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 {

41
src/qtlibtorrent/qbtsession.cpp

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

10
src/qtlibtorrent/qbtsession.h

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

4
src/webui/prefjson.cpp

@ -63,7 +63,7 @@ QString prefjson::getPreferences() @@ -63,7 +63,7 @@ QString prefjson::getPreferences()
}
data.add("download_in_scan_dirs", var_list);
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_email", pref.getMailNotificationEmail());
data.add("mail_notification_smtp", pref.getMailNotificationSMTP());
@ -198,7 +198,7 @@ void prefjson::setPreferences(const QString& json) @@ -198,7 +198,7 @@ void prefjson::setPreferences(const QString& json)
}
}
if (m.contains("export_dir"))
pref.setExportDir(m["export_dir"].toString());
pref.setTorrentExportDir(m["export_dir"].toString());
if (m.contains("mail_notification_enabled"))
pref.setMailNotificationEnabled(m["mail_notification_enabled"].toBool());
if (m.contains("mail_notification_email"))

Loading…
Cancel
Save