From 8dcf326576fdb30030a4609291ca732b491863f0 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Dec 2017 21:18:18 +0800 Subject: [PATCH] Add source field in Torrent creator. Closes #7965. This field is often used for cross-seeding between (private) trackers. --- src/base/bittorrent/torrentcreatorthread.cpp | 10 +++++++++- src/base/bittorrent/torrentcreatorthread.h | 1 + src/gui/torrentcreatordlg.cpp | 7 ++++++- src/gui/torrentcreatordlg.h | 1 + src/gui/torrentcreatordlg.ui | 10 ++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index d4ae79b41..aaec19324 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -124,6 +124,14 @@ void TorrentCreatorThread::run() if (isInterruptionRequested()) return; + libt::entry entry = newTorrent.generate(); + + // add source field + if (!m_params.source.isEmpty()) + entry["info"]["source"] = m_params.source.toStdString(); + + if (isInterruptionRequested()) return; + // create the torrent std::ofstream outfile( #ifdef _MSC_VER @@ -137,7 +145,7 @@ void TorrentCreatorThread::run() if (isInterruptionRequested()) return; - libt::bencode(std::ostream_iterator(outfile), newTorrent.generate()); + libt::bencode(std::ostream_iterator(outfile), entry); outfile.close(); emit updateProgress(100); diff --git a/src/base/bittorrent/torrentcreatorthread.h b/src/base/bittorrent/torrentcreatorthread.h index c7aef99fb..58785cfa2 100644 --- a/src/base/bittorrent/torrentcreatorthread.h +++ b/src/base/bittorrent/torrentcreatorthread.h @@ -43,6 +43,7 @@ namespace BitTorrent QString inputPath; QString savePath; QString comment; + QString source; QStringList trackers; QStringList urlSeeds; }; diff --git a/src/gui/torrentcreatordlg.cpp b/src/gui/torrentcreatordlg.cpp index b66801438..0d46da91a 100644 --- a/src/gui/torrentcreatordlg.cpp +++ b/src/gui/torrentcreatordlg.cpp @@ -60,6 +60,7 @@ TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent, const QString &defaultPath , m_storeWebSeedList(SETTINGS_KEY("WebSeedList")) , m_storeComments(SETTINGS_KEY("Comments")) , m_storeLastSavePath(SETTINGS_KEY("LastSavePath"), QDir::homePath()) + , m_storeSource(SETTINGS_KEY("Source")) { m_ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); @@ -165,9 +166,11 @@ void TorrentCreatorDlg::onCreateButtonClicked() .replace(QRegularExpression("\n\n[\n]+"), "\n\n").split('\n'); const QStringList urlSeeds = m_ui->URLSeedsList->toPlainText().split('\n', QString::SkipEmptyParts); const QString comment = m_ui->txtComment->toPlainText(); + const QString source = m_ui->lineEditSource->text(); // run the creator thread - m_creatorThread->create({ m_ui->checkPrivate->isChecked(), getPieceSize(), input, destination, comment, trackers, urlSeeds }); + m_creatorThread->create({ m_ui->checkPrivate->isChecked(), getPieceSize() + , input, destination, comment, source, trackers, urlSeeds }); } void TorrentCreatorDlg::handleCreationFailure(const QString &msg) @@ -241,6 +244,7 @@ void TorrentCreatorDlg::saveSettings() m_storeTrackerList = m_ui->trackersList->toPlainText(); m_storeWebSeedList = m_ui->URLSeedsList->toPlainText(); m_storeComments = m_ui->txtComment->toPlainText(); + m_storeSource = m_ui->lineEditSource->text(); m_storeDialogSize = size(); } @@ -258,6 +262,7 @@ void TorrentCreatorDlg::loadSettings() m_ui->trackersList->setPlainText(m_storeTrackerList); m_ui->URLSeedsList->setPlainText(m_storeWebSeedList); m_ui->txtComment->setPlainText(m_storeComments); + m_ui->lineEditSource->setText(m_storeSource); if (m_storeDialogSize.value().isValid()) resize(m_storeDialogSize); diff --git a/src/gui/torrentcreatordlg.h b/src/gui/torrentcreatordlg.h index f8235fe67..514dedf0c 100644 --- a/src/gui/torrentcreatordlg.h +++ b/src/gui/torrentcreatordlg.h @@ -85,6 +85,7 @@ private: CachedSettingValue m_storeWebSeedList; CachedSettingValue m_storeComments; CachedSettingValue m_storeLastSavePath; + CachedSettingValue m_storeSource; }; #endif diff --git a/src/gui/torrentcreatordlg.ui b/src/gui/torrentcreatordlg.ui index b7809e932..20d24a1b2 100644 --- a/src/gui/torrentcreatordlg.ui +++ b/src/gui/torrentcreatordlg.ui @@ -273,6 +273,16 @@ + + + + Source: + + + + + +