diff --git a/src/base/addtorrentmanager.cpp b/src/base/addtorrentmanager.cpp index a4bfe8047..ce446a72b 100644 --- a/src/base/addtorrentmanager.cpp +++ b/src/base/addtorrentmanager.cpp @@ -195,11 +195,9 @@ void AddTorrentManager::setTorrentFileGuard(const QString &source, std::shared_p m_guardedTorrentFiles.emplace(source, std::move(torrentFileGuard)); } -void AddTorrentManager::releaseTorrentFileGuard(const QString &source) +std::shared_ptr AddTorrentManager::releaseTorrentFileGuard(const QString &source) { - auto torrentFileGuard = m_guardedTorrentFiles.take(source); - if (torrentFileGuard) - torrentFileGuard->setAutoRemove(false); + return m_guardedTorrentFiles.take(source); } bool AddTorrentManager::processTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr diff --git a/src/base/addtorrentmanager.h b/src/base/addtorrentmanager.h index 9f1f61039..0e2fc6f49 100644 --- a/src/base/addtorrentmanager.h +++ b/src/base/addtorrentmanager.h @@ -74,7 +74,7 @@ protected: void handleAddTorrentFailed(const QString &source, const QString &reason); void handleDuplicateTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr, BitTorrent::Torrent *existingTorrent); void setTorrentFileGuard(const QString &source, std::shared_ptr torrentFileGuard); - void releaseTorrentFileGuard(const QString &source); + std::shared_ptr releaseTorrentFileGuard(const QString &source); private: void onDownloadFinished(const Net::DownloadResult &result); diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 11b083c3e..7a048b218 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -821,6 +821,8 @@ void AddNewTorrentDialog::reject() if (!m_currentContext) [[unlikely]] return; + emit torrentRejected(m_currentContext->torrentDescr); + const BitTorrent::TorrentDescriptor &torrentDescr = m_currentContext->torrentDescr; const bool hasMetadata = torrentDescr.info().has_value(); if (!hasMetadata) diff --git a/src/gui/addnewtorrentdialog.h b/src/gui/addnewtorrentdialog.h index f81bd305b..bc530953b 100644 --- a/src/gui/addnewtorrentdialog.h +++ b/src/gui/addnewtorrentdialog.h @@ -66,6 +66,7 @@ public: signals: void torrentAccepted(const BitTorrent::TorrentDescriptor &torrentDescriptor, const BitTorrent::AddTorrentParams &addTorrentParams); + void torrentRejected(const BitTorrent::TorrentDescriptor &torrentDescriptor); private slots: void updateDiskSpaceLabel(); diff --git a/src/gui/guiaddtorrentmanager.cpp b/src/gui/guiaddtorrentmanager.cpp index c99d4afce..d600a4e17 100644 --- a/src/gui/guiaddtorrentmanager.cpp +++ b/src/gui/guiaddtorrentmanager.cpp @@ -235,15 +235,22 @@ bool GUIAddTorrentManager::processTorrent(const QString &source dlg->setAttribute(Qt::WA_DeleteOnClose); m_dialogs[infoHash] = dlg; connect(dlg, &AddNewTorrentDialog::torrentAccepted, this - , [this, source](const BitTorrent::TorrentDescriptor &torrentDescr, const BitTorrent::AddTorrentParams &addTorrentParams) - { - addTorrentToSession(source, torrentDescr, addTorrentParams); - }); - connect(dlg, &QDialog::finished, this, [this, source, infoHash, dlg] + , [this, source, dlg](const BitTorrent::TorrentDescriptor &torrentDescr, const BitTorrent::AddTorrentParams &addTorrentParams) { if (dlg->isDoNotDeleteTorrentChecked()) - releaseTorrentFileGuard(source); + { + if (auto torrentFileGuard = releaseTorrentFileGuard(source)) + torrentFileGuard->setAutoRemove(false); + } + addTorrentToSession(source, torrentDescr, addTorrentParams); + }); + connect(dlg, &AddNewTorrentDialog::torrentRejected, this, [this, source] + { + releaseTorrentFileGuard(source); + }); + connect(dlg, &QDialog::finished, this, [this, source, infoHash] + { m_dialogs.remove(infoHash); });