From 674809b1d899386380bef44aa320265da4190788 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 7 May 2025 20:13:55 +0300 Subject: [PATCH] Fix future continuations to use correct contexts --- src/base/bittorrent/torrentcontenthandler.h | 3 +++ src/gui/properties/peerlistwidget.cpp | 8 ++------ src/gui/properties/peerlistwidget.h | 2 +- src/gui/properties/propertieswidget.cpp | 14 ++++---------- src/gui/torrentcontentmodel.cpp | 15 +++------------ src/gui/trackerlist/trackerlistmodel.cpp | 6 +----- 6 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/base/bittorrent/torrentcontenthandler.h b/src/base/bittorrent/torrentcontenthandler.h index 350db753e..d9030850b 100644 --- a/src/base/bittorrent/torrentcontenthandler.h +++ b/src/base/bittorrent/torrentcontenthandler.h @@ -40,6 +40,9 @@ namespace BitTorrent { class TorrentContentHandler : public QObject, public AbstractFileStorage { + Q_OBJECT + Q_DISABLE_COPY_MOVE(TorrentContentHandler) + public: using QObject::QObject; diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index a6c44d106..3ea883c7a 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -401,17 +401,13 @@ void PeerListWidget::saveSettings() const Preferences::instance()->setPeerListState(header()->saveState()); } -void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent) +void PeerListWidget::loadPeers(BitTorrent::Torrent *torrent) { if (!torrent) return; - using TorrentPtr = QPointer; - torrent->fetchPeerInfo().then(this, [this, torrent = TorrentPtr(torrent)](const QList &peers) + torrent->fetchPeerInfo().then(torrent, [this, torrent](const QList &peers) { - if (torrent != m_properties->getCurrentTorrent()) - return; - // Remove I2P peers since they will be completely reloaded. for (const QStandardItem *item : asConst(m_I2PPeerItems)) m_listModel->removeRow(item->row()); diff --git a/src/gui/properties/peerlistwidget.h b/src/gui/properties/peerlistwidget.h index 83e733829..946433494 100644 --- a/src/gui/properties/peerlistwidget.h +++ b/src/gui/properties/peerlistwidget.h @@ -82,7 +82,7 @@ public: explicit PeerListWidget(PropertiesWidget *parent); ~PeerListWidget() override; - void loadPeers(const BitTorrent::Torrent *torrent); + void loadPeers(BitTorrent::Torrent *torrent); void updatePeerHostNameResolutionState(); void updatePeerCountryResolutionState(); void clear(); diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 8a76e4663..d926a12e1 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -479,11 +479,9 @@ void PropertiesWidget::loadDynamicData() // Pieces availability showPiecesAvailability(true); - using TorrentPtr = QPointer; - m_torrent->fetchPieceAvailability().then(this, [this, torrent = TorrentPtr(m_torrent)](const QList &pieceAvailability) + m_torrent->fetchPieceAvailability().then(m_torrent, [this](const QList &pieceAvailability) { - if (torrent == m_torrent) - m_piecesAvailability->setAvailability(pieceAvailability); + m_piecesAvailability->setAvailability(pieceAvailability); }); m_ui->labelAverageAvailabilityVal->setText(Utils::String::fromDouble(m_torrent->distributedCopies(), 3)); @@ -497,7 +495,7 @@ void PropertiesWidget::loadDynamicData() qreal progress = m_torrent->progress() * 100.; m_ui->labelProgressVal->setText(Utils::String::fromDouble(progress, 1) + u'%'); - m_torrent->fetchDownloadingPieces().then(this, [this](const QBitArray &downloadingPieces) + m_torrent->fetchDownloadingPieces().then(m_torrent, [this](const QBitArray &downloadingPieces) { m_downloadedPieces->setProgress(m_torrent->pieces(), downloadingPieces); }); @@ -524,12 +522,8 @@ void PropertiesWidget::loadUrlSeeds() if (!m_torrent) return; - using TorrentPtr = QPointer; - m_torrent->fetchURLSeeds().then(this, [this, torrent = TorrentPtr(m_torrent)](const QList &urlSeeds) + m_torrent->fetchURLSeeds().then(m_torrent, [this](const QList &urlSeeds) { - if (torrent != m_torrent) - return; - m_ui->listWebSeeds->clear(); qDebug("Loading web seeds"); // Add url seeds diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index 32e44c16f..731129627 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -219,20 +219,11 @@ void TorrentContentModel::updateFilesAvailability() { Q_ASSERT(m_contentHandler && m_contentHandler->hasMetadata()); - using HandlerPtr = QPointer; - m_contentHandler->fetchAvailableFileFractions().then(this - , [this, handler = HandlerPtr(m_contentHandler)](const QList &availableFileFractions) + m_contentHandler->fetchAvailableFileFractions().then(m_contentHandler + , [this](const QList &availableFileFractions) { - if (handler != m_contentHandler) - return; - - Q_ASSERT(m_filesIndex.size() == availableFileFractions.size()); - // XXX: Why is this necessary? - if (m_filesIndex.size() != availableFileFractions.size()) [[unlikely]] - return; - for (int i = 0; i < m_filesIndex.size(); ++i) - m_filesIndex[i]->setAvailability(availableFileFractions[i]); + m_filesIndex[i]->setAvailability(availableFileFractions.value(i, 0)); // Update folders progress in the tree m_rootItem->recalculateProgress(); }); diff --git a/src/gui/trackerlist/trackerlistmodel.cpp b/src/gui/trackerlist/trackerlistmodel.cpp index b13b067b6..d6649e115 100644 --- a/src/gui/trackerlist/trackerlistmodel.cpp +++ b/src/gui/trackerlist/trackerlistmodel.cpp @@ -309,12 +309,8 @@ void TrackerListModel::populate() m_items->emplace_back(std::make_shared(u"** [PeX] **", privateTorrentMessage)); m_items->emplace_back(std::make_shared(u"** [LSD] **", privateTorrentMessage)); - using TorrentPtr = QPointer; - m_torrent->fetchPeerInfo().then(this, [this, torrent = TorrentPtr(m_torrent)](const QList &peers) + m_torrent->fetchPeerInfo().then(m_torrent, [this](const QList &peers) { - if (torrent != m_torrent) - return; - // XXX: libtorrent should provide this info... // Count peers from DHT, PeX, LSD uint seedsDHT = 0, seedsPeX = 0, seedsLSD = 0, peersDHT = 0, peersPeX = 0, peersLSD = 0;