Browse Source

Merge pull request #17725 from Chocobo1/downloadsDone

Clean up 'recursive download' related code
adaptive-webui-19844
Chocobo1 2 years ago committed by GitHub
parent
commit
b28704a6ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      src/base/bittorrent/sessionimpl.cpp
  2. 6
      src/base/bittorrent/torrentimpl.cpp
  3. 8
      src/base/preferences.cpp
  4. 4
      src/base/preferences.h
  5. 30
      src/gui/mainwindow.cpp
  6. 2
      src/gui/mainwindow.h
  7. 4
      src/gui/optionsdialog.cpp

38
src/base/bittorrent/sessionimpl.cpp

@ -4549,31 +4549,18 @@ void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent)
LogMsg(tr("Torrent download finished. Torrent: \"%1\"").arg(torrent->name())); LogMsg(tr("Torrent download finished. Torrent: \"%1\"").arg(torrent->name()));
emit torrentFinished(torrent); emit torrentFinished(torrent);
qDebug("Checking if the torrent contains torrent files to download"); if (const Path exportPath = finishedTorrentExportDirectory(); !exportPath.isEmpty())
// Check if there are torrent files inside exportTorrentFile(torrent, exportPath);
// Check whether it contains .torrent files
for (const Path &torrentRelpath : asConst(torrent->filePaths())) for (const Path &torrentRelpath : asConst(torrent->filePaths()))
{ {
if (torrentRelpath.hasExtension(u".torrent"_qs)) if (torrentRelpath.hasExtension(u".torrent"_qs))
{ {
qDebug("Found possible recursive torrent download.");
const Path torrentFullpath = torrent->actualStorageLocation() / torrentRelpath;
qDebug("Full subtorrent path is %s", qUtf8Printable(torrentFullpath.toString()));
if (TorrentInfo::loadFromFile(torrentFullpath))
{
qDebug("emitting recursiveTorrentDownloadPossible()");
emit recursiveTorrentDownloadPossible(torrent); emit recursiveTorrentDownloadPossible(torrent);
break; break;
} }
else
{
qDebug("Caught error loading torrent");
LogMsg(tr("Unable to load torrent. File: \"%1\"").arg(torrentFullpath.toString()), Log::CRITICAL);
}
} }
}
if (!finishedTorrentExportDirectory().isEmpty())
exportTorrentFile(torrent, finishedTorrentExportDirectory());
if (!hasUnfinishedTorrents()) if (!hasUnfinishedTorrents())
emit allTorrentsFinished(); emit allTorrentsFinished();
@ -4859,25 +4846,32 @@ void SessionImpl::disableIPFilter()
void SessionImpl::recursiveTorrentDownload(const TorrentID &id) void SessionImpl::recursiveTorrentDownload(const TorrentID &id)
{ {
TorrentImpl *const torrent = m_torrents.value(id); const TorrentImpl *torrent = m_torrents.value(id);
if (!torrent) return; if (!torrent)
return;
for (const Path &torrentRelpath : asConst(torrent->filePaths())) for (const Path &torrentRelpath : asConst(torrent->filePaths()))
{ {
if (torrentRelpath.hasExtension(u".torrent"_qs)) if (torrentRelpath.hasExtension(u".torrent"_qs))
{ {
LogMsg(tr("Recursive download .torrent file within torrent. Source torrent: \"%1\". File: \"%2\"")
.arg(torrent->name(), torrentRelpath.toString()));
const Path torrentFullpath = torrent->savePath() / torrentRelpath; const Path torrentFullpath = torrent->savePath() / torrentRelpath;
LogMsg(tr("Recursive download .torrent file within torrent. Source torrent: \"%1\". File: \"%2\"")
.arg(torrent->name(), torrentFullpath.toString()));
AddTorrentParams params; AddTorrentParams params;
// Passing the save path along to the sub torrent file // Passing the save path along to the sub torrent file
params.savePath = torrent->savePath(); params.savePath = torrent->savePath();
const nonstd::expected<TorrentInfo, QString> loadResult = TorrentInfo::loadFromFile(torrentFullpath); const nonstd::expected<TorrentInfo, QString> loadResult = TorrentInfo::loadFromFile(torrentFullpath);
if (loadResult) if (loadResult)
{
addTorrent(loadResult.value(), params); addTorrent(loadResult.value(), params);
}
else else
LogMsg(tr("Failed to load torrent. Error: \"%1\"").arg(loadResult.error()), Log::WARNING); {
LogMsg(tr("Failed to load .torrent file within torrent. Source torrent: \"%1\". File: \"%2\". Error: \"%3\"")
.arg(torrent->name(), torrentFullpath.toString(), loadResult.error()), Log::WARNING);
}
} }
} }
} }

6
src/base/bittorrent/torrentimpl.cpp

@ -1772,10 +1772,10 @@ void TorrentImpl::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p)
void TorrentImpl::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p) void TorrentImpl::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p)
{ {
Q_UNUSED(p); Q_UNUSED(p);
qDebug("Got a torrent finished alert for \"%s\"", qUtf8Printable(name()));
qDebug("Torrent has seed status: %s", m_hasSeedStatus ? "yes" : "no");
m_hasMissingFiles = false; m_hasMissingFiles = false;
if (m_hasSeedStatus) return; if (m_hasSeedStatus)
return;
m_statusUpdatedTriggers.enqueue([this]() m_statusUpdatedTriggers.enqueue([this]()
{ {

8
src/base/preferences.cpp

@ -996,14 +996,14 @@ void Preferences::resolvePeerHostNames(const bool resolve)
setValue(u"Preferences/Connection/ResolvePeerHostNames"_qs, resolve); setValue(u"Preferences/Connection/ResolvePeerHostNames"_qs, resolve);
} }
bool Preferences::recursiveDownloadDisabled() const bool Preferences::isRecursiveDownloadEnabled() const
{ {
return value(u"Preferences/Advanced/DisableRecursiveDownload"_qs, false); return !value(u"Preferences/Advanced/DisableRecursiveDownload"_qs, false);
} }
void Preferences::disableRecursiveDownload(const bool disable) void Preferences::setRecursiveDownloadEnabled(const bool enable)
{ {
setValue(u"Preferences/Advanced/DisableRecursiveDownload"_qs, disable); setValue(u"Preferences/Advanced/DisableRecursiveDownload"_qs, !enable);
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

4
src/base/preferences.h

@ -281,8 +281,8 @@ public:
void resolvePeerCountries(bool resolve); void resolvePeerCountries(bool resolve);
bool resolvePeerHostNames() const; bool resolvePeerHostNames() const;
void resolvePeerHostNames(bool resolve); void resolvePeerHostNames(bool resolve);
bool recursiveDownloadDisabled() const; bool isRecursiveDownloadEnabled() const;
void disableRecursiveDownload(bool disable = true); void setRecursiveDownloadEnabled(bool enable);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
bool neverCheckFileAssoc() const; bool neverCheckFileAssoc() const;
void setNeverCheckFileAssoc(bool check = true); void setNeverCheckFileAssoc(bool check = true);

30
src/gui/mainwindow.cpp

@ -885,27 +885,33 @@ void MainWindow::displayExecutionLogTab()
// End of keyboard shortcuts slots // End of keyboard shortcuts slots
void MainWindow::askRecursiveTorrentDownloadConfirmation(BitTorrent::Torrent *const torrent) void MainWindow::askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent *torrent)
{ {
Preferences *const pref = Preferences::instance(); if (!Preferences::instance()->isRecursiveDownloadEnabled())
if (pref->recursiveDownloadDisabled()) return; return;
const auto torrentID = torrent->id(); const auto torrentID = torrent->id();
QMessageBox *confirmBox = new QMessageBox(QMessageBox::Question, tr("Recursive download confirmation") QMessageBox *confirmBox = new QMessageBox(QMessageBox::Question, tr("Recursive download confirmation")
, tr("The torrent '%1' contains torrent files, do you want to proceed with their download?").arg(torrent->name()) , tr("The torrent '%1' contains .torrent files, do you want to proceed with their downloads?").arg(torrent->name())
, QMessageBox::NoButton, this); , (QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll), this);
confirmBox->setAttribute(Qt::WA_DeleteOnClose); confirmBox->setAttribute(Qt::WA_DeleteOnClose);
const QPushButton *yes = confirmBox->addButton(tr("Yes"), QMessageBox::YesRole); const QAbstractButton *yesButton = confirmBox->button(QMessageBox::Yes);
/*QPushButton *no = */ confirmBox->addButton(tr("No"), QMessageBox::NoRole); QAbstractButton *neverButton = confirmBox->button(QMessageBox::NoToAll);
const QPushButton *never = confirmBox->addButton(tr("Never"), QMessageBox::NoRole); neverButton->setText(tr("Never"));
connect(confirmBox, &QMessageBox::buttonClicked, this, [torrentID, yes, never](const QAbstractButton *button)
connect(confirmBox, &QMessageBox::buttonClicked, this
, [torrentID, yesButton, neverButton](const QAbstractButton *button)
{
if (button == yesButton)
{ {
if (button == yes)
BitTorrent::Session::instance()->recursiveTorrentDownload(torrentID); BitTorrent::Session::instance()->recursiveTorrentDownload(torrentID);
if (button == never) }
Preferences::instance()->disableRecursiveDownload(); else if (button == neverButton)
{
Preferences::instance()->setRecursiveDownloadEnabled(false);
}
}); });
confirmBox->open(); confirmBox->open();
} }

2
src/gui/mainwindow.h

@ -130,7 +130,7 @@ private slots:
void reloadSessionStats(); void reloadSessionStats();
void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents); void reloadTorrentStats(const QVector<BitTorrent::Torrent *> &torrents);
void loadPreferences(); void loadPreferences();
void askRecursiveTorrentDownloadConfirmation(BitTorrent::Torrent *const torrent); void askRecursiveTorrentDownloadConfirmation(const BitTorrent::Torrent *torrent);
void optionsSaved(); void optionsSaved();
void toggleAlternativeSpeeds(); void toggleAlternativeSpeeds();

4
src/gui/optionsdialog.cpp

@ -546,7 +546,7 @@ void OptionsDialog::loadDownloadsTabOptions()
m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled()); m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled());
m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled()); m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled());
m_ui->checkRecursiveDownload->setChecked(!pref->recursiveDownloadDisabled()); m_ui->checkRecursiveDownload->setChecked(pref->isRecursiveDownloadEnabled());
m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault()); m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
m_ui->comboTorrentCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategoryChanged()); m_ui->comboTorrentCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategoryChanged());
@ -698,7 +698,7 @@ void OptionsDialog::saveDownloadsTabOptions() const
session->setPreallocationEnabled(preAllocateAllFiles()); session->setPreallocationEnabled(preAllocateAllFiles());
session->setAppendExtensionEnabled(m_ui->checkAppendqB->isChecked()); session->setAppendExtensionEnabled(m_ui->checkAppendqB->isChecked());
pref->disableRecursiveDownload(!m_ui->checkRecursiveDownload->isChecked()); pref->setRecursiveDownloadEnabled(m_ui->checkRecursiveDownload->isChecked());
session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0); session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0);
session->setDisableAutoTMMWhenCategoryChanged(m_ui->comboTorrentCategoryChanged->currentIndex() == 1); session->setDisableAutoTMMWhenCategoryChanged(m_ui->comboTorrentCategoryChanged->currentIndex() == 1);

Loading…
Cancel
Save