Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
glassez committed Jul 19, 2024
1 parent 992648f commit 1164932
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/gui/guiaddtorrentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include "guiaddtorrentmanager.h"

#include <QFutureWatcher>
#include <QFuture>
#include <QScreen>

#include "base/bittorrent/session.h"
Expand Down Expand Up @@ -202,16 +202,12 @@ bool GUIAddTorrentManager::processTorrent(const QString &source, const BitTorren
return false;
}

QFuture<BitTorrent::TorrentInfo> downloadMetadataFuture;
if (!hasMetadata)
{
using FutureWatcher = QFutureWatcher<BitTorrent::TorrentInfo>;

auto *futureWatcher = new FutureWatcher(this);
connect(futureWatcher, &FutureWatcher::finished, this, [this, futureWatcher]
(downloadMetadataFuture = btSession()->downloadMetadata(torrentDescr))
.then(this, [this](const BitTorrent::TorrentInfo &torrentInfo)
{
futureWatcher->deleteLater();

const BitTorrent::TorrentInfo torrentInfo = futureWatcher->result();
Q_ASSERT(torrentInfo.isValid());
if (!torrentInfo.isValid()) [[unlikely]]
return;
Expand All @@ -222,7 +218,6 @@ bool GUIAddTorrentManager::processTorrent(const QString &source, const BitTorren
dialog->updateMetadata(torrentInfo);
}
});
futureWatcher->setFuture(btSession()->downloadMetadata(torrentDescr));
}

// By not setting a parent to the "AddNewTorrentDialog", all those dialogs
Expand All @@ -239,12 +234,16 @@ bool GUIAddTorrentManager::processTorrent(const QString &source, const BitTorren
{
addTorrentToSession(source, torrentDescr, addTorrentParams);
});
connect(dlg, &QDialog::finished, this, [this, source, infoHash, dlg]
connect(dlg, &QDialog::finished, this
, [this, source, infoHash, dlg, downloadMetadataFuture](const int result) mutable
{
if (dlg->isDoNotDeleteTorrentChecked())
releaseTorrentFileGuard(source);

m_dialogs.remove(infoHash);

if ((result == QDialog::Rejected) && !downloadMetadataFuture.isFinished())
downloadMetadataFuture.cancel();
});

adjustDialogGeometry(dlg, app()->mainWindow());
Expand Down

0 comments on commit 1164932

Please sign in to comment.