Browse Source

Split TorrentHandle interface and implementation

adaptive-webui-19844
Vladimir Golovnev (Glassez) 5 years ago
parent
commit
1132b84548
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 1
      src/app/application.cpp
  2. 2
      src/base/CMakeLists.txt
  3. 2
      src/base/base.pri
  4. 2
      src/base/bittorrent/peerinfo.cpp
  5. 139
      src/base/bittorrent/session.cpp
  6. 59
      src/base/bittorrent/session.h
  7. 2138
      src/base/bittorrent/torrenthandle.cpp
  8. 461
      src/base/bittorrent/torrenthandle.h
  9. 2147
      src/base/bittorrent/torrenthandleimpl.cpp
  10. 337
      src/base/bittorrent/torrenthandleimpl.h
  11. 1
      src/base/torrentfilter.cpp
  12. 1
      src/base/utils/fs.cpp
  13. 2
      src/gui/properties/piecesbar.cpp
  14. 1
      src/gui/properties/propertieswidget.cpp
  15. 3
      src/gui/transferlistfilterswidget.cpp
  16. 1
      src/gui/transferlistsortmodel.cpp
  17. 2
      src/gui/transferlistwidget.cpp
  18. 3
      src/webui/api/serialize/serialize_torrent.cpp
  19. 1
      src/webui/api/synccontroller.cpp

1
src/app/application.cpp

@ -61,6 +61,7 @@
#endif // Q_OS_MACOS #endif // Q_OS_MACOS
#endif #endif
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/exceptions.h" #include "base/exceptions.h"

2
src/base/CMakeLists.txt

@ -22,6 +22,7 @@ bittorrent/session.h
bittorrent/sessionstatus.h bittorrent/sessionstatus.h
bittorrent/torrentcreatorthread.h bittorrent/torrentcreatorthread.h
bittorrent/torrenthandle.h bittorrent/torrenthandle.h
bittorrent/torrenthandleimpl.h
bittorrent/torrentinfo.h bittorrent/torrentinfo.h
bittorrent/tracker.h bittorrent/tracker.h
bittorrent/trackerentry.h bittorrent/trackerentry.h
@ -100,6 +101,7 @@ bittorrent/private/statistics.cpp
bittorrent/session.cpp bittorrent/session.cpp
bittorrent/torrentcreatorthread.cpp bittorrent/torrentcreatorthread.cpp
bittorrent/torrenthandle.cpp bittorrent/torrenthandle.cpp
bittorrent/torrenthandleimpl.cpp
bittorrent/torrentinfo.cpp bittorrent/torrentinfo.cpp
bittorrent/tracker.cpp bittorrent/tracker.cpp
bittorrent/trackerentry.cpp bittorrent/trackerentry.cpp

2
src/base/base.pri

@ -21,6 +21,7 @@ HEADERS += \
$$PWD/bittorrent/sessionstatus.h \ $$PWD/bittorrent/sessionstatus.h \
$$PWD/bittorrent/torrentcreatorthread.h \ $$PWD/bittorrent/torrentcreatorthread.h \
$$PWD/bittorrent/torrenthandle.h \ $$PWD/bittorrent/torrenthandle.h \
$$PWD/bittorrent/torrenthandleimpl.h \
$$PWD/bittorrent/torrentinfo.h \ $$PWD/bittorrent/torrentinfo.h \
$$PWD/bittorrent/tracker.h \ $$PWD/bittorrent/tracker.h \
$$PWD/bittorrent/trackerentry.h \ $$PWD/bittorrent/trackerentry.h \
@ -99,6 +100,7 @@ SOURCES += \
$$PWD/bittorrent/session.cpp \ $$PWD/bittorrent/session.cpp \
$$PWD/bittorrent/torrentcreatorthread.cpp \ $$PWD/bittorrent/torrentcreatorthread.cpp \
$$PWD/bittorrent/torrenthandle.cpp \ $$PWD/bittorrent/torrenthandle.cpp \
$$PWD/bittorrent/torrenthandleimpl.cpp \
$$PWD/bittorrent/torrentinfo.cpp \ $$PWD/bittorrent/torrentinfo.cpp \
$$PWD/bittorrent/tracker.cpp \ $$PWD/bittorrent/tracker.cpp \
$$PWD/bittorrent/trackerentry.cpp \ $$PWD/bittorrent/trackerentry.cpp \

2
src/base/bittorrent/peerinfo.cpp

@ -28,6 +28,8 @@
#include "peerinfo.h" #include "peerinfo.h"
#include <libtorrent/version.hpp>
#include <QBitArray> #include <QBitArray>
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"

139
src/base/bittorrent/session.cpp

@ -101,7 +101,7 @@
#include "private/portforwarderimpl.h" #include "private/portforwarderimpl.h"
#include "private/resumedatasavingmanager.h" #include "private/resumedatasavingmanager.h"
#include "private/statistics.h" #include "private/statistics.h"
#include "torrenthandle.h" #include "torrenthandleimpl.h"
#include "tracker.h" #include "tracker.h"
#include "trackerentry.h" #include "trackerentry.h"
@ -660,7 +660,7 @@ void Session::setTempPathEnabled(const bool enabled)
{ {
if (enabled != isTempPathEnabled()) { if (enabled != isTempPathEnabled()) {
m_isTempPathEnabled = enabled; m_isTempPathEnabled = enabled;
for (TorrentHandle *const torrent : asConst(m_torrents)) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
torrent->handleTempPathChanged(); torrent->handleTempPathChanged();
} }
} }
@ -674,7 +674,7 @@ void Session::setAppendExtensionEnabled(const bool enabled)
{ {
if (isAppendExtensionEnabled() != enabled) { if (isAppendExtensionEnabled() != enabled) {
// append or remove .!qB extension for incomplete files // append or remove .!qB extension for incomplete files
for (TorrentHandle *const torrent : asConst(m_torrents)) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
torrent->handleAppendExtensionToggled(); torrent->handleAppendExtensionToggled();
m_isAppendExtensionEnabled = enabled; m_isAppendExtensionEnabled = enabled;
@ -825,12 +825,12 @@ bool Session::editCategory(const QString &name, const QString &savePath)
m_categories[name] = savePath; m_categories[name] = savePath;
m_storedCategories = map_cast(m_categories); m_storedCategories = map_cast(m_categories);
if (isDisableAutoTMMWhenCategorySavePathChanged()) { if (isDisableAutoTMMWhenCategorySavePathChanged()) {
for (TorrentHandle *const torrent : asConst(torrents())) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
if (torrent->category() == name) if (torrent->category() == name)
torrent->setAutoTMMEnabled(false); torrent->setAutoTMMEnabled(false);
} }
else { else {
for (TorrentHandle *const torrent : asConst(torrents())) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
if (torrent->category() == name) if (torrent->category() == name)
torrent->handleCategorySavePathChanged(); torrent->handleCategorySavePathChanged();
} }
@ -840,7 +840,7 @@ bool Session::editCategory(const QString &name, const QString &savePath)
bool Session::removeCategory(const QString &name) bool Session::removeCategory(const QString &name)
{ {
for (TorrentHandle *const torrent : asConst(torrents())) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
if (torrent->belongsToCategory(name)) if (torrent->belongsToCategory(name))
torrent->setCategory(""); torrent->setCategory("");
@ -927,7 +927,7 @@ bool Session::addTag(const QString &tag)
bool Session::removeTag(const QString &tag) bool Session::removeTag(const QString &tag)
{ {
if (m_tags.remove(tag)) { if (m_tags.remove(tag)) {
for (TorrentHandle *const torrent : asConst(torrents())) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
torrent->removeTag(tag); torrent->removeTag(tag);
m_storedTags = m_tags.values(); m_storedTags = m_tags.values();
emit tagRemoved(tag); emit tagRemoved(tag);
@ -1701,7 +1701,7 @@ void Session::processShareLimits()
{ {
qDebug("Processing share limits..."); qDebug("Processing share limits...");
for (TorrentHandle *const torrent : asConst(torrents())) { for (TorrentHandleImpl *const torrent : asConst(m_torrents)) {
if (torrent->isSeed() && !torrent->isForced()) { if (torrent->isSeed() && !torrent->isForced()) {
if (torrent->ratioLimit() != TorrentHandle::NO_RATIO_LIMIT) { if (torrent->ratioLimit() != TorrentHandle::NO_RATIO_LIMIT) {
const qreal ratio = torrent->realRatio(); const qreal ratio = torrent->realRatio();
@ -1793,7 +1793,7 @@ TorrentHandle *Session::findTorrent(const InfoHash &hash) const
bool Session::hasActiveTorrents() const bool Session::hasActiveTorrents() const
{ {
return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentHandle *torrent) return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentHandleImpl *torrent)
{ {
return TorrentFilter::ActiveTorrent.match(torrent); return TorrentFilter::ActiveTorrent.match(torrent);
}); });
@ -1801,7 +1801,7 @@ bool Session::hasActiveTorrents() const
bool Session::hasUnfinishedTorrents() const bool Session::hasUnfinishedTorrents() const
{ {
return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentHandle *torrent) return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentHandleImpl *torrent)
{ {
return (!torrent->isSeed() && !torrent->isPaused()); return (!torrent->isSeed() && !torrent->isPaused());
}); });
@ -1809,7 +1809,7 @@ bool Session::hasUnfinishedTorrents() const
bool Session::hasRunningSeed() const bool Session::hasRunningSeed() const
{ {
return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentHandle *torrent) return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentHandleImpl *torrent)
{ {
return (torrent->isSeed() && !torrent->isPaused()); return (torrent->isSeed() && !torrent->isPaused());
}); });
@ -1837,7 +1837,7 @@ void Session::banIP(const QString &ip)
// and from the disk, if the corresponding deleteOption is chosen // and from the disk, if the corresponding deleteOption is chosen
bool Session::deleteTorrent(const InfoHash &hash, const DeleteOption deleteOption) bool Session::deleteTorrent(const InfoHash &hash, const DeleteOption deleteOption)
{ {
TorrentHandle *const torrent = m_torrents.take(hash); TorrentHandleImpl *const torrent = m_torrents.take(hash);
if (!torrent) return false; if (!torrent) return false;
qDebug("Deleting torrent with hash: %s", qUtf8Printable(torrent->hash())); qDebug("Deleting torrent with hash: %s", qUtf8Printable(torrent->hash()));
@ -1922,21 +1922,21 @@ bool Session::cancelLoadMetadata(const InfoHash &hash)
void Session::increaseTorrentsQueuePos(const QVector<InfoHash> &hashes) void Session::increaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
{ {
using ElementType = std::pair<int, TorrentHandle *>; using ElementType = std::pair<int, TorrentHandleImpl *>;
std::priority_queue<ElementType std::priority_queue<ElementType
, std::vector<ElementType> , std::vector<ElementType>
, std::greater<ElementType>> torrentQueue; , std::greater<ElementType>> torrentQueue;
// Sort torrents by queue position // Sort torrents by queue position
for (const InfoHash &infoHash : hashes) { for (const InfoHash &infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash); TorrentHandleImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed()) if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent); torrentQueue.emplace(torrent->queuePosition(), torrent);
} }
// Increase torrents queue position (starting with the one in the highest queue position) // Increase torrents queue position (starting with the one in the highest queue position)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
const TorrentHandle *torrent = torrentQueue.top().second; const TorrentHandleImpl *torrent = torrentQueue.top().second;
torrentQueuePositionUp(torrent->nativeHandle()); torrentQueuePositionUp(torrent->nativeHandle());
torrentQueue.pop(); torrentQueue.pop();
} }
@ -1946,19 +1946,19 @@ void Session::increaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes) void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
{ {
using ElementType = std::pair<int, TorrentHandle *>; using ElementType = std::pair<int, TorrentHandleImpl *>;
std::priority_queue<ElementType> torrentQueue; std::priority_queue<ElementType> torrentQueue;
// Sort torrents by queue position // Sort torrents by queue position
for (const InfoHash &infoHash : hashes) { for (const InfoHash &infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash); TorrentHandleImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed()) if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent); torrentQueue.emplace(torrent->queuePosition(), torrent);
} }
// Decrease torrents queue position (starting with the one in the lowest queue position) // Decrease torrents queue position (starting with the one in the lowest queue position)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
const TorrentHandle *torrent = torrentQueue.top().second; const TorrentHandleImpl *torrent = torrentQueue.top().second;
torrentQueuePositionDown(torrent->nativeHandle()); torrentQueuePositionDown(torrent->nativeHandle());
torrentQueue.pop(); torrentQueue.pop();
} }
@ -1971,19 +1971,19 @@ void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes) void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes)
{ {
using ElementType = std::pair<int, TorrentHandle *>; using ElementType = std::pair<int, TorrentHandleImpl *>;
std::priority_queue<ElementType> torrentQueue; std::priority_queue<ElementType> torrentQueue;
// Sort torrents by queue position // Sort torrents by queue position
for (const InfoHash &infoHash : hashes) { for (const InfoHash &infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash); TorrentHandleImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed()) if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent); torrentQueue.emplace(torrent->queuePosition(), torrent);
} }
// Top torrents queue position (starting with the one in the lowest queue position) // Top torrents queue position (starting with the one in the lowest queue position)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
const TorrentHandle *torrent = torrentQueue.top().second; const TorrentHandleImpl *torrent = torrentQueue.top().second;
torrentQueuePositionTop(torrent->nativeHandle()); torrentQueuePositionTop(torrent->nativeHandle());
torrentQueue.pop(); torrentQueue.pop();
} }
@ -1993,21 +1993,21 @@ void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes)
void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes) void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes)
{ {
using ElementType = std::pair<int, TorrentHandle *>; using ElementType = std::pair<int, TorrentHandleImpl *>;
std::priority_queue<ElementType std::priority_queue<ElementType
, std::vector<ElementType> , std::vector<ElementType>
, std::greater<ElementType>> torrentQueue; , std::greater<ElementType>> torrentQueue;
// Sort torrents by queue position // Sort torrents by queue position
for (const InfoHash &infoHash : hashes) { for (const InfoHash &infoHash : hashes) {
TorrentHandle *const torrent = m_torrents.value(infoHash); TorrentHandleImpl *const torrent = m_torrents.value(infoHash);
if (torrent && !torrent->isSeed()) if (torrent && !torrent->isSeed())
torrentQueue.emplace(torrent->queuePosition(), torrent); torrentQueue.emplace(torrent->queuePosition(), torrent);
} }
// Bottom torrents queue position (starting with the one in the highest queue position) // Bottom torrents queue position (starting with the one in the highest queue position)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
const TorrentHandle *torrent = torrentQueue.top().second; const TorrentHandleImpl *torrent = torrentQueue.top().second;
torrentQueuePositionBottom(torrent->nativeHandle()); torrentQueuePositionBottom(torrent->nativeHandle());
torrentQueue.pop(); torrentQueue.pop();
} }
@ -2018,15 +2018,20 @@ void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes)
saveTorrentsQueue(); saveTorrentsQueue();
} }
void Session::handleTorrentSaveResumeDataRequested(const TorrentHandle *torrent) void Session::handleTorrentSaveResumeDataRequested(const TorrentHandleImpl *torrent)
{ {
qDebug("Saving resume data is requested for torrent '%s'...", qUtf8Printable(torrent->name())); qDebug("Saving resume data is requested for torrent '%s'...", qUtf8Printable(torrent->name()));
++m_numResumeData; ++m_numResumeData;
} }
QHash<InfoHash, TorrentHandle *> Session::torrents() const QVector<TorrentHandle *> Session::torrents() const
{ {
return m_torrents; QVector<TorrentHandle *> result;
result.reserve(m_torrents.size());
for (TorrentHandleImpl *torrent : asConst(m_torrents))
result << torrent;
return result;
} }
bool Session::addTorrent(const QString &source, const AddTorrentParams &params) bool Session::addTorrent(const QString &source, const AddTorrentParams &params)
@ -2327,7 +2332,7 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne
if (m_addingTorrents.contains(hash) || m_loadedMetadata.contains(hash)) if (m_addingTorrents.contains(hash) || m_loadedMetadata.contains(hash))
return false; return false;
TorrentHandle *const torrent = m_torrents.value(hash); TorrentHandleImpl *const torrent = m_torrents.value(hash);
if (torrent) { // a duplicate torrent is added if (torrent) { // a duplicate torrent is added
if (torrent->isPrivate() || (!fromMagnetUri && torrentInfo.isPrivate())) if (torrent->isPrivate() || (!fromMagnetUri && torrentInfo.isPrivate()))
return false; return false;
@ -2513,7 +2518,7 @@ bool Session::loadMetadata(const MagnetUri &magnetUri)
return true; return true;
} }
void Session::exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder) void Session::exportTorrentFile(const TorrentHandle *torrent, TorrentExportFolder folder)
{ {
Q_ASSERT(((folder == TorrentExportFolder::Regular) && !torrentExportDirectory().isEmpty()) || Q_ASSERT(((folder == TorrentExportFolder::Regular) && !torrentExportDirectory().isEmpty()) ||
((folder == TorrentExportFolder::Finished) && !finishedTorrentExportDirectory().isEmpty())); ((folder == TorrentExportFolder::Finished) && !finishedTorrentExportDirectory().isEmpty()));
@ -2539,7 +2544,7 @@ void Session::exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolde
void Session::generateResumeData(const bool final) void Session::generateResumeData(const bool final)
{ {
for (TorrentHandle *const torrent : asConst(m_torrents)) { for (TorrentHandleImpl *const torrent : asConst(m_torrents)) {
if (!torrent->isValid()) continue; if (!torrent->isValid()) continue;
if (!final && !torrent->needSaveResumeData()) continue; if (!final && !torrent->needSaveResumeData()) continue;
@ -2586,7 +2591,7 @@ void Session::saveTorrentsQueue()
{ {
// store hash in textual representation // store hash in textual representation
QMap<int, QString> queue; // Use QMap since it should be ordered by key QMap<int, QString> queue; // Use QMap since it should be ordered by key
for (const TorrentHandle *torrent : asConst(torrents())) { for (const TorrentHandleImpl *torrent : asConst(m_torrents)) {
// We require actual (non-cached) queue position here! // We require actual (non-cached) queue position here!
const int queuePos = LTUnderlyingType<LTQueuePosition> {torrent->nativeHandle().queue_position()}; const int queuePos = LTUnderlyingType<LTQueuePosition> {torrent->nativeHandle().queue_position()};
if (queuePos >= 0) if (queuePos >= 0)
@ -2627,10 +2632,10 @@ void Session::setDefaultSavePath(QString path)
m_defaultSavePath = path; m_defaultSavePath = path;
if (isDisableAutoTMMWhenDefaultSavePathChanged()) if (isDisableAutoTMMWhenDefaultSavePathChanged())
for (TorrentHandle *const torrent : asConst(torrents())) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
torrent->setAutoTMMEnabled(false); torrent->setAutoTMMEnabled(false);
else else
for (TorrentHandle *const torrent : asConst(torrents())) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
torrent->handleCategorySavePathChanged(); torrent->handleCategorySavePathChanged();
} }
@ -2641,7 +2646,7 @@ void Session::setTempPath(QString path)
m_tempPath = path; m_tempPath = path;
for (TorrentHandle *const torrent : asConst(m_torrents)) for (TorrentHandleImpl *const torrent : asConst(m_torrents))
torrent->handleTempPathChanged(); torrent->handleTempPathChanged();
} }
@ -3816,48 +3821,48 @@ void Session::updateSeedingLimitTimer()
} }
} }
void Session::handleTorrentShareLimitChanged(TorrentHandle *const torrent) void Session::handleTorrentShareLimitChanged(TorrentHandleImpl *const torrent)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
updateSeedingLimitTimer(); updateSeedingLimitTimer();
} }
void Session::handleTorrentNameChanged(TorrentHandle *const torrent) void Session::handleTorrentNameChanged(TorrentHandleImpl *const torrent)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
} }
void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent) void Session::handleTorrentSavePathChanged(TorrentHandleImpl *const torrent)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
emit torrentSavePathChanged(torrent); emit torrentSavePathChanged(torrent);
} }
void Session::handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory) void Session::handleTorrentCategoryChanged(TorrentHandleImpl *const torrent, const QString &oldCategory)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
emit torrentCategoryChanged(torrent, oldCategory); emit torrentCategoryChanged(torrent, oldCategory);
} }
void Session::handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag) void Session::handleTorrentTagAdded(TorrentHandleImpl *const torrent, const QString &tag)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
emit torrentTagAdded(torrent, tag); emit torrentTagAdded(torrent, tag);
} }
void Session::handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag) void Session::handleTorrentTagRemoved(TorrentHandleImpl *const torrent, const QString &tag)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
emit torrentTagRemoved(torrent, tag); emit torrentTagRemoved(torrent, tag);
} }
void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent) void Session::handleTorrentSavingModeChanged(TorrentHandleImpl *const torrent)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
emit torrentSavingModeChanged(torrent); emit torrentSavingModeChanged(torrent);
} }
void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers) void Session::handleTorrentTrackersAdded(TorrentHandleImpl *const torrent, const QVector<TrackerEntry> &newTrackers)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
@ -3869,7 +3874,7 @@ void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVe
emit trackersChanged(torrent); emit trackersChanged(torrent);
} }
void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers) void Session::handleTorrentTrackersRemoved(TorrentHandleImpl *const torrent, const QVector<TrackerEntry> &deletedTrackers)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
@ -3881,27 +3886,27 @@ void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const Q
emit trackersChanged(torrent); emit trackersChanged(torrent);
} }
void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent) void Session::handleTorrentTrackersChanged(TorrentHandleImpl *const torrent)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
emit trackersChanged(torrent); emit trackersChanged(torrent);
} }
void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QVector<QUrl> &newUrlSeeds) void Session::handleTorrentUrlSeedsAdded(TorrentHandleImpl *const torrent, const QVector<QUrl> &newUrlSeeds)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
for (const QUrl &newUrlSeed : newUrlSeeds) for (const QUrl &newUrlSeed : newUrlSeeds)
LogMsg(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name())); LogMsg(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name()));
} }
void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QVector<QUrl> &urlSeeds) void Session::handleTorrentUrlSeedsRemoved(TorrentHandleImpl *const torrent, const QVector<QUrl> &urlSeeds)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
for (const QUrl &urlSeed : urlSeeds) for (const QUrl &urlSeed : urlSeeds)
LogMsg(tr("URL seed '%1' was removed from torrent '%2'").arg(urlSeed.toString(), torrent->name())); LogMsg(tr("URL seed '%1' was removed from torrent '%2'").arg(urlSeed.toString(), torrent->name()));
} }
void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent) void Session::handleTorrentMetadataReceived(TorrentHandleImpl *const torrent)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
@ -3922,25 +3927,25 @@ void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent)
emit torrentMetadataLoaded(torrent); emit torrentMetadataLoaded(torrent);
} }
void Session::handleTorrentPaused(TorrentHandle *const torrent) void Session::handleTorrentPaused(TorrentHandleImpl *const torrent)
{ {
if (!torrent->hasError() && !torrent->hasMissingFiles()) if (!torrent->hasError() && !torrent->hasMissingFiles())
torrent->saveResumeData(); torrent->saveResumeData();
emit torrentPaused(torrent); emit torrentPaused(torrent);
} }
void Session::handleTorrentResumed(TorrentHandle *const torrent) void Session::handleTorrentResumed(TorrentHandleImpl *const torrent)
{ {
torrent->saveResumeData(); torrent->saveResumeData();
emit torrentResumed(torrent); emit torrentResumed(torrent);
} }
void Session::handleTorrentChecked(TorrentHandle *const torrent) void Session::handleTorrentChecked(TorrentHandleImpl *const torrent)
{ {
emit torrentFinishedChecking(torrent); emit torrentFinishedChecking(torrent);
} }
void Session::handleTorrentFinished(TorrentHandle *const torrent) void Session::handleTorrentFinished(TorrentHandleImpl *const torrent)
{ {
if (!torrent->hasError() && !torrent->hasMissingFiles()) if (!torrent->hasError() && !torrent->hasMissingFiles())
torrent->saveResumeData(); torrent->saveResumeData();
@ -3975,7 +3980,7 @@ void Session::handleTorrentFinished(TorrentHandle *const torrent)
emit allTorrentsFinished(); emit allTorrentsFinished();
} }
void Session::handleTorrentResumeDataReady(TorrentHandle *const torrent, const std::shared_ptr<lt::entry> &data) void Session::handleTorrentResumeDataReady(TorrentHandleImpl *const torrent, const std::shared_ptr<lt::entry> &data)
{ {
--m_numResumeData; --m_numResumeData;
@ -3992,23 +3997,23 @@ void Session::handleTorrentResumeDataReady(TorrentHandle *const torrent, const s
#endif #endif
} }
void Session::handleTorrentResumeDataFailed(TorrentHandle *const torrent) void Session::handleTorrentResumeDataFailed(TorrentHandleImpl *const torrent)
{ {
Q_UNUSED(torrent) Q_UNUSED(torrent)
--m_numResumeData; --m_numResumeData;
} }
void Session::handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl) void Session::handleTorrentTrackerReply(TorrentHandleImpl *const torrent, const QString &trackerUrl)
{ {
emit trackerSuccess(torrent, trackerUrl); emit trackerSuccess(torrent, trackerUrl);
} }
void Session::handleTorrentTrackerError(TorrentHandle *const torrent, const QString &trackerUrl) void Session::handleTorrentTrackerError(TorrentHandleImpl *const torrent, const QString &trackerUrl)
{ {
emit trackerError(torrent, trackerUrl); emit trackerError(torrent, trackerUrl);
} }
bool Session::addMoveTorrentStorageJob(TorrentHandle *torrent, const QString &newPath, const MoveStorageMode mode) bool Session::addMoveTorrentStorageJob(TorrentHandleImpl *torrent, const QString &newPath, const MoveStorageMode mode)
{ {
Q_ASSERT(torrent); Q_ASSERT(torrent);
@ -4081,14 +4086,14 @@ void Session::handleMoveTorrentStorageJobFinished(const QString &errorMessage)
} }
} }
void Session::handleTorrentTrackerWarning(TorrentHandle *const torrent, const QString &trackerUrl) void Session::handleTorrentTrackerWarning(TorrentHandleImpl *const torrent, const QString &trackerUrl)
{ {
emit trackerWarning(torrent, trackerUrl); emit trackerWarning(torrent, trackerUrl);
} }
bool Session::hasPerTorrentRatioLimit() const bool Session::hasPerTorrentRatioLimit() const
{ {
return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentHandle *torrent) return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentHandleImpl *torrent)
{ {
return (torrent->ratioLimit() >= 0); return (torrent->ratioLimit() >= 0);
}); });
@ -4096,7 +4101,7 @@ bool Session::hasPerTorrentRatioLimit() const
bool Session::hasPerTorrentSeedingTimeLimit() const bool Session::hasPerTorrentSeedingTimeLimit() const
{ {
return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentHandle *torrent) return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentHandleImpl *torrent)
{ {
return (torrent->seedingTimeLimit() >= 0); return (torrent->seedingTimeLimit() >= 0);
}); });
@ -4170,7 +4175,7 @@ void Session::disableIPFilter()
void Session::recursiveTorrentDownload(const InfoHash &hash) void Session::recursiveTorrentDownload(const InfoHash &hash)
{ {
TorrentHandle *const torrent = m_torrents.value(hash); TorrentHandleImpl *const torrent = m_torrents.value(hash);
if (!torrent) return; if (!torrent) return;
for (int i = 0; i < torrent->filesCount(); ++i) { for (int i = 0; i < torrent->filesCount(); ++i) {
@ -4480,7 +4485,7 @@ void Session::handleAlert(const lt::alert *a)
void Session::dispatchTorrentAlert(const lt::alert *a) void Session::dispatchTorrentAlert(const lt::alert *a)
{ {
TorrentHandle *const torrent = m_torrents.value(static_cast<const lt::torrent_alert*>(a)->handle.info_hash()); TorrentHandleImpl *const torrent = m_torrents.value(static_cast<const lt::torrent_alert*>(a)->handle.info_hash());
if (torrent) { if (torrent) {
torrent->handleAlert(a); torrent->handleAlert(a);
return; return;
@ -4500,7 +4505,7 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle)
const CreateTorrentParams params = m_addingTorrents.take(nativeHandle.info_hash()); const CreateTorrentParams params = m_addingTorrents.take(nativeHandle.info_hash());
TorrentHandle *const torrent = new TorrentHandle(this, nativeHandle, params); TorrentHandleImpl *const torrent = new TorrentHandleImpl(this, nativeHandle, params);
m_torrents.insert(torrent->hash(), torrent); m_torrents.insert(torrent->hash(), torrent);
const bool fromMagnetUri = !torrent->hasMetadata(); const bool fromMagnetUri = !torrent->hasMetadata();
@ -4644,7 +4649,7 @@ void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
void Session::handleFileErrorAlert(const lt::file_error_alert *p) void Session::handleFileErrorAlert(const lt::file_error_alert *p)
{ {
TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash()); TorrentHandleImpl *const torrent = m_torrents.value(p->handle.info_hash());
if (!torrent) if (!torrent)
return; return;
@ -4738,7 +4743,7 @@ void Session::handlePeerBanAlert(const lt::peer_ban_alert *p)
void Session::handleUrlSeedAlert(const lt::url_seed_alert *p) void Session::handleUrlSeedAlert(const lt::url_seed_alert *p)
{ {
const TorrentHandle *torrent = m_torrents.value(p->handle.info_hash()); const TorrentHandleImpl *torrent = m_torrents.value(p->handle.info_hash());
if (!torrent) if (!torrent)
return; return;
@ -4969,7 +4974,7 @@ void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p)
{ {
if (m_moveStorageQueue.isEmpty()) return; if (m_moveStorageQueue.isEmpty()) return;
const TorrentHandle *torrent = m_torrents.value(p->handle.info_hash()); const TorrentHandleImpl *torrent = m_torrents.value(p->handle.info_hash());
const MoveStorageJob &currentJob = m_moveStorageQueue.first(); const MoveStorageJob &currentJob = m_moveStorageQueue.first();
if (currentJob.torrent != torrent) return; if (currentJob.torrent != torrent) return;
@ -4981,7 +4986,7 @@ void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
{ {
if (m_moveStorageQueue.isEmpty()) return; if (m_moveStorageQueue.isEmpty()) return;
const TorrentHandle *torrent = m_torrents.value(p->handle.info_hash()); const TorrentHandleImpl *torrent = m_torrents.value(p->handle.info_hash());
const MoveStorageJob &currentJob = m_moveStorageQueue.first(); const MoveStorageJob &currentJob = m_moveStorageQueue.first();
if (currentJob.torrent != torrent) return; if (currentJob.torrent != torrent) return;
@ -4994,7 +4999,7 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
updatedTorrents.reserve(p->status.size()); updatedTorrents.reserve(p->status.size());
for (const lt::torrent_status &status : p->status) { for (const lt::torrent_status &status : p->status) {
TorrentHandle *const torrent = m_torrents.value(status.info_hash); TorrentHandleImpl *const torrent = m_torrents.value(status.info_hash);
if (!torrent) if (!torrent)
continue; continue;

59
src/base/bittorrent/session.h

@ -93,6 +93,7 @@ namespace BitTorrent
class InfoHash; class InfoHash;
class MagnetUri; class MagnetUri;
class TorrentHandle; class TorrentHandle;
class TorrentHandleImpl;
class Tracker; class Tracker;
class TrackerEntry; class TrackerEntry;
struct CreateTorrentParams; struct CreateTorrentParams;
@ -411,7 +412,7 @@ namespace BitTorrent
void startUpTorrents(); void startUpTorrents();
TorrentHandle *findTorrent(const InfoHash &hash) const; TorrentHandle *findTorrent(const InfoHash &hash) const;
QHash<InfoHash, TorrentHandle *> torrents() const; QVector<TorrentHandle *> torrents() const;
bool hasActiveTorrents() const; bool hasActiveTorrents() const;
bool hasUnfinishedTorrents() const; bool hasUnfinishedTorrents() const;
bool hasRunningSeed() const; bool hasRunningSeed() const;
@ -440,31 +441,31 @@ namespace BitTorrent
void bottomTorrentsQueuePos(const QVector<InfoHash> &hashes); void bottomTorrentsQueuePos(const QVector<InfoHash> &hashes);
// TorrentHandle interface // TorrentHandle interface
void handleTorrentSaveResumeDataRequested(const TorrentHandle *torrent); void handleTorrentSaveResumeDataRequested(const TorrentHandleImpl *torrent);
void handleTorrentShareLimitChanged(TorrentHandle *const torrent); void handleTorrentShareLimitChanged(TorrentHandleImpl *const torrent);
void handleTorrentNameChanged(TorrentHandle *const torrent); void handleTorrentNameChanged(TorrentHandleImpl *const torrent);
void handleTorrentSavePathChanged(TorrentHandle *const torrent); void handleTorrentSavePathChanged(TorrentHandleImpl *const torrent);
void handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory); void handleTorrentCategoryChanged(TorrentHandleImpl *const torrent, const QString &oldCategory);
void handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag); void handleTorrentTagAdded(TorrentHandleImpl *const torrent, const QString &tag);
void handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag); void handleTorrentTagRemoved(TorrentHandleImpl *const torrent, const QString &tag);
void handleTorrentSavingModeChanged(TorrentHandle *const torrent); void handleTorrentSavingModeChanged(TorrentHandleImpl *const torrent);
void handleTorrentMetadataReceived(TorrentHandle *const torrent); void handleTorrentMetadataReceived(TorrentHandleImpl *const torrent);
void handleTorrentPaused(TorrentHandle *const torrent); void handleTorrentPaused(TorrentHandleImpl *const torrent);
void handleTorrentResumed(TorrentHandle *const torrent); void handleTorrentResumed(TorrentHandleImpl *const torrent);
void handleTorrentChecked(TorrentHandle *const torrent); void handleTorrentChecked(TorrentHandleImpl *const torrent);
void handleTorrentFinished(TorrentHandle *const torrent); void handleTorrentFinished(TorrentHandleImpl *const torrent);
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers); void handleTorrentTrackersAdded(TorrentHandleImpl *const torrent, const QVector<TrackerEntry> &newTrackers);
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers); void handleTorrentTrackersRemoved(TorrentHandleImpl *const torrent, const QVector<TrackerEntry> &deletedTrackers);
void handleTorrentTrackersChanged(TorrentHandle *const torrent); void handleTorrentTrackersChanged(TorrentHandleImpl *const torrent);
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QVector<QUrl> &newUrlSeeds); void handleTorrentUrlSeedsAdded(TorrentHandleImpl *const torrent, const QVector<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QVector<QUrl> &urlSeeds); void handleTorrentUrlSeedsRemoved(TorrentHandleImpl *const torrent, const QVector<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentHandle *const torrent, const std::shared_ptr<lt::entry> &data); void handleTorrentResumeDataReady(TorrentHandleImpl *const torrent, const std::shared_ptr<lt::entry> &data);
void handleTorrentResumeDataFailed(TorrentHandle *const torrent); void handleTorrentResumeDataFailed(TorrentHandleImpl *const torrent);
void handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl); void handleTorrentTrackerReply(TorrentHandleImpl *const torrent, const QString &trackerUrl);
void handleTorrentTrackerWarning(TorrentHandle *const torrent, const QString &trackerUrl); void handleTorrentTrackerWarning(TorrentHandleImpl *const torrent, const QString &trackerUrl);
void handleTorrentTrackerError(TorrentHandle *const torrent, const QString &trackerUrl); void handleTorrentTrackerError(TorrentHandleImpl *const torrent, const QString &trackerUrl);
bool addMoveTorrentStorageJob(TorrentHandle *torrent, const QString &newPath, MoveStorageMode mode); bool addMoveTorrentStorageJob(TorrentHandleImpl *torrent, const QString &newPath, MoveStorageMode mode);
signals: signals:
void addTorrentFailed(const QString &error); void addTorrentFailed(const QString &error);
@ -521,7 +522,7 @@ namespace BitTorrent
private: private:
struct MoveStorageJob struct MoveStorageJob
{ {
TorrentHandle *torrent; TorrentHandleImpl *torrent;
QString path; QString path;
MoveStorageMode mode; MoveStorageMode mode;
}; };
@ -571,7 +572,7 @@ namespace BitTorrent
bool findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) const; bool findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) const;
void updateSeedingLimitTimer(); void updateSeedingLimitTimer();
void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular); void exportTorrentFile(const TorrentHandle *torrent, TorrentExportFolder folder = TorrentExportFolder::Regular);
void handleAlert(const lt::alert *a); void handleAlert(const lt::alert *a);
void dispatchTorrentAlert(const lt::alert *a); void dispatchTorrentAlert(const lt::alert *a);
@ -733,7 +734,7 @@ namespace BitTorrent
ResumeDataSavingManager *m_resumeDataSavingManager = nullptr; ResumeDataSavingManager *m_resumeDataSavingManager = nullptr;
QHash<InfoHash, TorrentInfo> m_loadedMetadata; QHash<InfoHash, TorrentInfo> m_loadedMetadata;
QHash<InfoHash, TorrentHandle *> m_torrents; QHash<InfoHash, TorrentHandleImpl *> m_torrents;
QHash<InfoHash, CreateTorrentParams> m_addingTorrents; QHash<InfoHash, CreateTorrentParams> m_addingTorrents;
QHash<QString, AddTorrentParams> m_downloadedTorrents; QHash<QString, AddTorrentParams> m_downloadedTorrents;
QHash<InfoHash, RemovingTorrentData> m_removingTorrents; QHash<InfoHash, RemovingTorrentData> m_removingTorrents;

2138
src/base/bittorrent/torrenthandle.cpp

File diff suppressed because it is too large Load Diff

461
src/base/bittorrent/torrenthandle.h

@ -27,84 +27,30 @@
* exception statement from your version. * exception statement from your version.
*/ */
#ifndef BITTORRENT_TORRENTHANDLE_H #pragma once
#define BITTORRENT_TORRENTHANDLE_H
#include <functional>
#include <libtorrent/fwd.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <libtorrent/torrent_status.hpp>
#include <QDateTime>
#include <QHash> #include <QHash>
#include <QObject> #include <QMetaType>
#include <QQueue>
#include <QSet> #include <QSet>
#include <QString> #include <QString>
#include <QVector> #include <QVector>
#include "private/speedmonitor.h"
#include "infohash.h"
#include "torrentinfo.h"
extern const QString QB_EXT;
class QBitArray; class QBitArray;
class QDateTime; class QDateTime;
class QStringList; class QStringList;
class QUrl; class QUrl;
extern const QString QB_EXT;
namespace BitTorrent namespace BitTorrent
{ {
enum class DownloadPriority; enum class DownloadPriority;
class InfoHash;
class PeerInfo; class PeerInfo;
class Session; class TorrentInfo;
class TrackerEntry; class TrackerEntry;
struct AddTorrentParams;
struct PeerAddress; struct PeerAddress;
struct CreateTorrentParams
{
bool restored; // is existing torrent job?
// for both new and restored torrents
QString name;
QString category;
QSet<QString> tags;
QString savePath;
bool disableTempPath;
bool sequential;
bool firstLastPiecePriority;
bool hasSeedStatus;
bool skipChecking;
bool hasRootFolder;
bool forced;
bool paused;
int uploadLimit;
int downloadLimit;
// for new torrents
QVector<DownloadPriority> filePriorities;
QDateTime addedTime;
// for restored torrents
qreal ratioLimit;
int seedingTimeLimit;
CreateTorrentParams();
explicit CreateTorrentParams(const AddTorrentParams &params);
};
struct TrackerInfo
{
QString lastMessage;
int numPeers = 0;
};
enum class MoveStorageMode
{
KeepExistingFiles,
Overwrite
};
enum class TorrentState enum class TorrentState
{ {
Unknown = -1, Unknown = -1,
@ -135,13 +81,16 @@ namespace BitTorrent
Error Error
}; };
struct TrackerInfo
{
QString lastMessage;
int numPeers = 0;
};
uint qHash(TorrentState key, uint seed); uint qHash(TorrentState key, uint seed);
class TorrentHandle : public QObject class TorrentHandle
{ {
Q_DISABLE_COPY(TorrentHandle)
Q_DECLARE_TR_FUNCTIONS(BitTorrent::TorrentHandle)
public: public:
static const qreal USE_GLOBAL_RATIO; static const qreal USE_GLOBAL_RATIO;
static const qreal NO_RATIO_LIMIT; static const qreal NO_RATIO_LIMIT;
@ -152,24 +101,21 @@ namespace BitTorrent
static const qreal MAX_RATIO; static const qreal MAX_RATIO;
static const int MAX_SEEDING_TIME; static const int MAX_SEEDING_TIME;
TorrentHandle(Session *session, const lt::torrent_handle &nativeHandle, virtual ~TorrentHandle() = default;
const CreateTorrentParams &params);
~TorrentHandle(); virtual InfoHash hash() const = 0;
virtual QString name() const = 0;
bool isValid() const; virtual QDateTime creationDate() const = 0;
InfoHash hash() const; virtual QString creator() const = 0;
QString name() const; virtual QString comment() const = 0;
QDateTime creationDate() const; virtual bool isPrivate() const = 0;
QString creator() const; virtual qlonglong totalSize() const = 0;
QString comment() const; virtual qlonglong wantedSize() const = 0;
bool isPrivate() const; virtual qlonglong completedSize() const = 0;
qlonglong totalSize() const; virtual qlonglong incompletedSize() const = 0;
qlonglong wantedSize() const; virtual qlonglong pieceLength() const = 0;
qlonglong completedSize() const; virtual qlonglong wastedSize() const = 0;
qlonglong incompletedSize() const; virtual QString currentTracker() const = 0;
qlonglong pieceLength() const;
qlonglong wastedSize() const;
QString currentTracker() const;
// 1. savePath() - the path where all the files and subfolders of torrent are stored (as always). // 1. savePath() - the path where all the files and subfolders of torrent are stored (as always).
// 2. rootPath() - absolute path of torrent file tree (save path + first item from 1st torrent file path). // 2. rootPath() - absolute path of torrent file tree (save path + first item from 1st torrent file path).
@ -214,237 +160,140 @@ namespace BitTorrent
// | B | /home/user/torrents/torrentB | /home/user/torrents/torrentB/subdir1/file1 | // | B | /home/user/torrents/torrentB | /home/user/torrents/torrentB/subdir1/file1 |
// | C | /home/user/torrents/file1 | /home/user/torrents/file1 | // | C | /home/user/torrents/file1 | /home/user/torrents/file1 |
QString savePath(bool actual = false) const; virtual QString savePath(bool actual = false) const = 0;
QString rootPath(bool actual = false) const; virtual QString rootPath(bool actual = false) const = 0;
QString contentPath(bool actual = false) const; virtual QString contentPath(bool actual = false) const = 0;
bool useTempPath() const; virtual bool useTempPath() const = 0;
bool isAutoTMMEnabled() const; virtual bool isAutoTMMEnabled() const = 0;
void setAutoTMMEnabled(bool enabled); virtual void setAutoTMMEnabled(bool enabled) = 0;
QString category() const; virtual QString category() const = 0;
bool belongsToCategory(const QString &category) const; virtual bool belongsToCategory(const QString &category) const = 0;
bool setCategory(const QString &category); virtual bool setCategory(const QString &category) = 0;
QSet<QString> tags() const; virtual QSet<QString> tags() const = 0;
bool hasTag(const QString &tag) const; virtual bool hasTag(const QString &tag) const = 0;
bool addTag(const QString &tag); virtual bool addTag(const QString &tag) = 0;
bool removeTag(const QString &tag); virtual bool removeTag(const QString &tag) = 0;
void removeAllTags(); virtual void removeAllTags() = 0;
bool hasRootFolder() const; virtual bool hasRootFolder() const = 0;
int filesCount() const; virtual int filesCount() const = 0;
int piecesCount() const; virtual int piecesCount() const = 0;
int piecesHave() const; virtual int piecesHave() const = 0;
qreal progress() const; virtual qreal progress() const = 0;
QDateTime addedTime() const; virtual QDateTime addedTime() const = 0;
qreal ratioLimit() const; virtual qreal ratioLimit() const = 0;
int seedingTimeLimit() const; virtual int seedingTimeLimit() const = 0;
QString filePath(int index) const; virtual QString filePath(int index) const = 0;
QString fileName(int index) const; virtual QString fileName(int index) const = 0;
qlonglong fileSize(int index) const; virtual qlonglong fileSize(int index) const = 0;
QStringList absoluteFilePaths() const; virtual QStringList absoluteFilePaths() const = 0;
QStringList absoluteFilePathsUnwanted() const; virtual QStringList absoluteFilePathsUnwanted() const = 0;
QVector<DownloadPriority> filePriorities() const; virtual QVector<DownloadPriority> filePriorities() const = 0;
TorrentInfo info() const; virtual TorrentInfo info() const = 0;
bool isSeed() const; virtual bool isSeed() const = 0;
bool isPaused() const; virtual bool isPaused() const = 0;
bool isResumed() const; virtual bool isResumed() const = 0;
bool isQueued() const; virtual bool isQueued() const = 0;
bool isForced() const; virtual bool isForced() const = 0;
bool isChecking() const; virtual bool isChecking() const = 0;
bool isDownloading() const; virtual bool isDownloading() const = 0;
bool isUploading() const; virtual bool isUploading() const = 0;
bool isCompleted() const; virtual bool isCompleted() const = 0;
bool isActive() const; virtual bool isActive() const = 0;
bool isInactive() const; virtual bool isInactive() const = 0;
bool isErrored() const; virtual bool isErrored() const = 0;
bool isSequentialDownload() const; virtual bool isSequentialDownload() const = 0;
bool hasFirstLastPiecePriority() const; virtual bool hasFirstLastPiecePriority() const = 0;
TorrentState state() const; virtual TorrentState state() const = 0;
bool hasMetadata() const; virtual bool hasMetadata() const = 0;
bool hasMissingFiles() const; virtual bool hasMissingFiles() const = 0;
bool hasError() const; virtual bool hasError() const = 0;
bool hasFilteredPieces() const; virtual bool hasFilteredPieces() const = 0;
int queuePosition() const; virtual int queuePosition() const = 0;
QVector<TrackerEntry> trackers() const; virtual QVector<TrackerEntry> trackers() const = 0;
QHash<QString, TrackerInfo> trackerInfos() const; virtual QHash<QString, TrackerInfo> trackerInfos() const = 0;
QVector<QUrl> urlSeeds() const; virtual QVector<QUrl> urlSeeds() const = 0;
QString error() const; virtual QString error() const = 0;
qlonglong totalDownload() const; virtual qlonglong totalDownload() const = 0;
qlonglong totalUpload() const; virtual qlonglong totalUpload() const = 0;
qlonglong activeTime() const; virtual qlonglong activeTime() const = 0;
qlonglong finishedTime() const; virtual qlonglong finishedTime() const = 0;
qlonglong seedingTime() const; virtual qlonglong seedingTime() const = 0;
qlonglong eta() const; virtual qlonglong eta() const = 0;
QVector<qreal> filesProgress() const; virtual QVector<qreal> filesProgress() const = 0;
int seedsCount() const; virtual int seedsCount() const = 0;
int peersCount() const; virtual int peersCount() const = 0;
int leechsCount() const; virtual int leechsCount() const = 0;
int totalSeedsCount() const; virtual int totalSeedsCount() const = 0;
int totalPeersCount() const; virtual int totalPeersCount() const = 0;
int totalLeechersCount() const; virtual int totalLeechersCount() const = 0;
int completeCount() const; virtual int completeCount() const = 0;
int incompleteCount() const; virtual int incompleteCount() const = 0;
QDateTime lastSeenComplete() const; virtual QDateTime lastSeenComplete() const = 0;
QDateTime completedTime() const; virtual QDateTime completedTime() const = 0;
qlonglong timeSinceUpload() const; virtual qlonglong timeSinceUpload() const = 0;
qlonglong timeSinceDownload() const; virtual qlonglong timeSinceDownload() const = 0;
qlonglong timeSinceActivity() const; virtual qlonglong timeSinceActivity() const = 0;
int downloadLimit() const; virtual int downloadLimit() const = 0;
int uploadLimit() const; virtual int uploadLimit() const = 0;
bool superSeeding() const; virtual bool superSeeding() const = 0;
QVector<PeerInfo> peers() const; virtual QVector<PeerInfo> peers() const = 0;
QBitArray pieces() const; virtual QBitArray pieces() const = 0;
QBitArray downloadingPieces() const; virtual QBitArray downloadingPieces() const = 0;
QVector<int> pieceAvailability() const; virtual QVector<int> pieceAvailability() const = 0;
qreal distributedCopies() const; virtual qreal distributedCopies() const = 0;
qreal maxRatio() const; virtual qreal maxRatio() const = 0;
int maxSeedingTime() const; virtual int maxSeedingTime() const = 0;
qreal realRatio() const; virtual qreal realRatio() const = 0;
int uploadPayloadRate() const; virtual int uploadPayloadRate() const = 0;
int downloadPayloadRate() const; virtual int downloadPayloadRate() const = 0;
qlonglong totalPayloadUpload() const; virtual qlonglong totalPayloadUpload() const = 0;
qlonglong totalPayloadDownload() const; virtual qlonglong totalPayloadDownload() const = 0;
int connectionsCount() const; virtual int connectionsCount() const = 0;
int connectionsLimit() const; virtual int connectionsLimit() const = 0;
qlonglong nextAnnounce() const; virtual qlonglong nextAnnounce() const = 0;
void setName(const QString &name);
void setSequentialDownload(bool enable);
void toggleSequentialDownload();
void setFirstLastPiecePriority(bool enabled);
void toggleFirstLastPiecePriority();
void pause();
void resume(bool forced = false);
void move(QString path);
void forceReannounce(int index = -1);
void forceDHTAnnounce();
void forceRecheck();
void renameFile(int index, const QString &name);
void prioritizeFiles(const QVector<DownloadPriority> &priorities);
void setRatioLimit(qreal limit);
void setSeedingTimeLimit(int limit);
void setUploadLimit(int limit);
void setDownloadLimit(int limit);
void setSuperSeeding(bool enable);
void flushCache() const;
void addTrackers(const QVector<TrackerEntry> &trackers);
void replaceTrackers(const QVector<TrackerEntry> &trackers);
void addUrlSeeds(const QVector<QUrl> &urlSeeds);
void removeUrlSeeds(const QVector<QUrl> &urlSeeds);
bool connectPeer(const PeerAddress &peerAddress);
QString toMagnetUri() const;
bool needSaveResumeData() const;
// Session interface
lt::torrent_handle nativeHandle() const;
void handleAlert(const lt::alert *a);
void handleStateUpdate(const lt::torrent_status &nativeStatus);
void handleTempPathChanged();
void handleCategorySavePathChanged();
void handleAppendExtensionToggled();
void saveResumeData();
void handleStorageMoved(const QString &newPath, const QString &errorMessage);
/** /**
* @brief fraction of file pieces that are available at least from one peer * @brief fraction of file pieces that are available at least from one peer
* *
* This is not the same as torrrent availability, it is just a fraction of pieces * This is not the same as torrrent availability, it is just a fraction of pieces
* that can be downloaded right now. It varies between 0 to 1. * that can be downloaded right now. It varies between 0 to 1.
*/ */
QVector<qreal> availableFileFractions() const; virtual QVector<qreal> availableFileFractions() const = 0;
private: virtual void setName(const QString &name) = 0;
typedef std::function<void ()> EventTrigger; virtual void setSequentialDownload(bool enable) = 0;
virtual void setFirstLastPiecePriority(bool enabled) = 0;
#if (LIBTORRENT_VERSION_NUM < 10200) virtual void pause() = 0;
using LTFileIndex = int; virtual void resume(bool forced = false) = 0;
#else virtual void move(QString path) = 0;
using LTFileIndex = lt::file_index_t; virtual void forceReannounce(int index = -1) = 0;
#endif virtual void forceDHTAnnounce() = 0;
virtual void forceRecheck() = 0;
void updateStatus(); virtual void renameFile(int index, const QString &name) = 0;
void updateStatus(const lt::torrent_status &nativeStatus); virtual void prioritizeFiles(const QVector<DownloadPriority> &priorities) = 0;
void updateState(); virtual void setRatioLimit(qreal limit) = 0;
void updateTorrentInfo(); virtual void setSeedingTimeLimit(int limit) = 0;
virtual void setUploadLimit(int limit) = 0;
void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p); virtual void setDownloadLimit(int limit) = 0;
void handleFileCompletedAlert(const lt::file_completed_alert *p); virtual void setSuperSeeding(bool enable) = 0;
void handleFileRenamedAlert(const lt::file_renamed_alert *p); virtual void flushCache() const = 0;
void handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p); virtual void addTrackers(const QVector<TrackerEntry> &trackers) = 0;
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p); virtual void replaceTrackers(const QVector<TrackerEntry> &trackers) = 0;
void handlePerformanceAlert(const lt::performance_alert *p) const; virtual void addUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
void handleSaveResumeDataAlert(const lt::save_resume_data_alert *p); virtual void removeUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
void handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p); virtual bool connectPeer(const PeerAddress &peerAddress) = 0;
void handleTorrentCheckedAlert(const lt::torrent_checked_alert *p);
void handleTorrentFinishedAlert(const lt::torrent_finished_alert *p); virtual QString createMagnetURI() const = 0;
void handleTorrentPausedAlert(const lt::torrent_paused_alert *p);
void handleTorrentResumedAlert(const lt::torrent_resumed_alert *p); void toggleSequentialDownload();
void handleTrackerErrorAlert(const lt::tracker_error_alert *p); void toggleFirstLastPiecePriority();
void handleTrackerReplyAlert(const lt::tracker_reply_alert *p);
void handleTrackerWarningAlert(const lt::tracker_warning_alert *p);
void resume_impl(bool forced);
bool isMoveInProgress() const;
QString actualStorageLocation() const;
bool isAutoManaged() const;
void setAutoManaged(bool enable);
void adjustActualSavePath();
void adjustActualSavePath_impl();
void move_impl(QString path, MoveStorageMode mode);
void moveStorage(const QString &newPath, MoveStorageMode mode);
void manageIncompleteFiles();
void setFirstLastPiecePriorityImpl(bool enabled, const QVector<DownloadPriority> &updatedFilePrio = {});
Session *const m_session;
lt::torrent_handle m_nativeHandle;
lt::torrent_status m_nativeStatus;
TorrentState m_state;
TorrentInfo m_torrentInfo;
SpeedMonitor m_speedMonitor;
InfoHash m_hash;
bool m_storageIsMoving = false;
// m_moveFinishedTriggers is activated only when the following conditions are met:
// all file rename jobs complete, all file move jobs complete
QQueue<EventTrigger> m_moveFinishedTriggers;
int m_renameCount;
// Until libtorrent provide an "old_name" field in `file_renamed_alert`
// we will rely on this workaround to remove empty leftover folders
QHash<LTFileIndex, QVector<QString>> m_oldPath;
bool m_useAutoTMM;
// Persistent data
QString m_name;
QString m_savePath;
QString m_category;
QSet<QString> m_tags;
bool m_hasSeedStatus;
qreal m_ratioLimit;
int m_seedingTimeLimit;
bool m_tempPathDisabled;
bool m_fastresumeDataRejected;
bool m_hasMissingFiles;
bool m_hasRootFolder;
bool m_needsToSetFirstLastPiecePriority;
QHash<QString, TrackerInfo> m_trackerInfos;
bool m_unchecked = false;
}; };
} }
Q_DECLARE_METATYPE(BitTorrent::TorrentState) Q_DECLARE_METATYPE(BitTorrent::TorrentState)
#endif // BITTORRENT_TORRENTHANDLE_H

2147
src/base/bittorrent/torrenthandleimpl.cpp

File diff suppressed because it is too large Load Diff

337
src/base/bittorrent/torrenthandleimpl.h

@ -0,0 +1,337 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
#include <functional>
#include <libtorrent/fwd.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <libtorrent/torrent_status.hpp>
#include <QDateTime>
#include <QHash>
#include <QObject>
#include <QQueue>
#include <QSet>
#include <QString>
#include <QVector>
#include "private/speedmonitor.h"
#include "infohash.h"
#include "torrenthandle.h"
#include "torrentinfo.h"
namespace BitTorrent
{
class Session;
struct AddTorrentParams;
struct CreateTorrentParams
{
bool restored = false; // is existing torrent job?
// for both new and restored torrents
QString name;
QString category;
QSet<QString> tags;
QString savePath;
bool disableTempPath = false;
bool sequential = false;
bool firstLastPiecePriority = false;
bool hasSeedStatus = false;
bool skipChecking = false;
bool hasRootFolder = true;
bool forced = false;
bool paused = false;
int uploadLimit = -1;
int downloadLimit = -1;
// for new torrents
QVector<DownloadPriority> filePriorities;
QDateTime addedTime;
// for restored torrents
qreal ratioLimit = TorrentHandle::USE_GLOBAL_RATIO;
int seedingTimeLimit = TorrentHandle::USE_GLOBAL_SEEDING_TIME;
CreateTorrentParams() = default;
explicit CreateTorrentParams(const AddTorrentParams &params);
};
enum class MoveStorageMode
{
KeepExistingFiles,
Overwrite
};
class TorrentHandleImpl final : public QObject, public TorrentHandle
{
Q_DISABLE_COPY(TorrentHandleImpl)
Q_DECLARE_TR_FUNCTIONS(BitTorrent::TorrentHandleImpl)
public:
TorrentHandleImpl(Session *session, const lt::torrent_handle &nativeHandle,
const CreateTorrentParams &params);
~TorrentHandleImpl() override;
bool isValid() const;
InfoHash hash() const override;
QString name() const override;
QDateTime creationDate() const override;
QString creator() const override;
QString comment() const override;
bool isPrivate() const override;
qlonglong totalSize() const override;
qlonglong wantedSize() const override;
qlonglong completedSize() const override;
qlonglong incompletedSize() const override;
qlonglong pieceLength() const override;
qlonglong wastedSize() const override;
QString currentTracker() const override;
QString savePath(bool actual = false) const override;
QString rootPath(bool actual = false) const override;
QString contentPath(bool actual = false) const override;
bool useTempPath() const override;
bool isAutoTMMEnabled() const override;
void setAutoTMMEnabled(bool enabled) override;
QString category() const override;
bool belongsToCategory(const QString &category) const override;
bool setCategory(const QString &category) override;
QSet<QString> tags() const override;
bool hasTag(const QString &tag) const override;
bool addTag(const QString &tag) override;
bool removeTag(const QString &tag) override;
void removeAllTags() override;
bool hasRootFolder() const override;
int filesCount() const override;
int piecesCount() const override;
int piecesHave() const override;
qreal progress() const override;
QDateTime addedTime() const override;
qreal ratioLimit() const override;
int seedingTimeLimit() const override;
QString filePath(int index) const override;
QString fileName(int index) const override;
qlonglong fileSize(int index) const override;
QStringList absoluteFilePaths() const override;
QStringList absoluteFilePathsUnwanted() const override;
QVector<DownloadPriority> filePriorities() const override;
TorrentInfo info() const override;
bool isSeed() const override;
bool isPaused() const override;
bool isResumed() const override;
bool isQueued() const override;
bool isForced() const override;
bool isChecking() const override;
bool isDownloading() const override;
bool isUploading() const override;
bool isCompleted() const override;
bool isActive() const override;
bool isInactive() const override;
bool isErrored() const override;
bool isSequentialDownload() const override;
bool hasFirstLastPiecePriority() const override;
TorrentState state() const override;
bool hasMetadata() const override;
bool hasMissingFiles() const override;
bool hasError() const override;
bool hasFilteredPieces() const override;
int queuePosition() const override;
QVector<TrackerEntry> trackers() const override;
QHash<QString, TrackerInfo> trackerInfos() const override;
QVector<QUrl> urlSeeds() const override;
QString error() const override;
qlonglong totalDownload() const override;
qlonglong totalUpload() const override;
qlonglong activeTime() const override;
qlonglong finishedTime() const override;
qlonglong seedingTime() const override;
qlonglong eta() const override;
QVector<qreal> filesProgress() const override;
int seedsCount() const override;
int peersCount() const override;
int leechsCount() const override;
int totalSeedsCount() const override;
int totalPeersCount() const override;
int totalLeechersCount() const override;
int completeCount() const override;
int incompleteCount() const override;
QDateTime lastSeenComplete() const override;
QDateTime completedTime() const override;
qlonglong timeSinceUpload() const override;
qlonglong timeSinceDownload() const override;
qlonglong timeSinceActivity() const override;
int downloadLimit() const override;
int uploadLimit() const override;
bool superSeeding() const override;
QVector<PeerInfo> peers() const override;
QBitArray pieces() const override;
QBitArray downloadingPieces() const override;
QVector<int> pieceAvailability() const override;
qreal distributedCopies() const override;
qreal maxRatio() const override;
int maxSeedingTime() const override;
qreal realRatio() const override;
int uploadPayloadRate() const override;
int downloadPayloadRate() const override;
qlonglong totalPayloadUpload() const override;
qlonglong totalPayloadDownload() const override;
int connectionsCount() const override;
int connectionsLimit() const override;
qlonglong nextAnnounce() const override;
QVector<qreal> availableFileFractions() const override;
void setName(const QString &name) override;
void setSequentialDownload(bool enable) override;
void setFirstLastPiecePriority(bool enabled) override;
void pause() override;
void resume(bool forced = false) override;
void move(QString path) override;
void forceReannounce(int index = -1) override;
void forceDHTAnnounce() override;
void forceRecheck() override;
void renameFile(int index, const QString &name) override;
void prioritizeFiles(const QVector<DownloadPriority> &priorities) override;
void setRatioLimit(qreal limit) override;
void setSeedingTimeLimit(int limit) override;
void setUploadLimit(int limit) override;
void setDownloadLimit(int limit) override;
void setSuperSeeding(bool enable) override;
void flushCache() const override;
void addTrackers(const QVector<TrackerEntry> &trackers) override;
void replaceTrackers(const QVector<TrackerEntry> &trackers) override;
void addUrlSeeds(const QVector<QUrl> &urlSeeds) override;
void removeUrlSeeds(const QVector<QUrl> &urlSeeds) override;
bool connectPeer(const PeerAddress &peerAddress) override;
QString createMagnetURI() const override;
bool needSaveResumeData() const;
// Session interface
lt::torrent_handle nativeHandle() const;
void handleAlert(const lt::alert *a);
void handleStateUpdate(const lt::torrent_status &nativeStatus);
void handleTempPathChanged();
void handleCategorySavePathChanged();
void handleAppendExtensionToggled();
void saveResumeData();
void handleStorageMoved(const QString &newPath, const QString &errorMessage);
private:
typedef std::function<void ()> EventTrigger;
#if (LIBTORRENT_VERSION_NUM < 10200)
using LTFileIndex = int;
#else
using LTFileIndex = lt::file_index_t;
#endif
void updateStatus();
void updateStatus(const lt::torrent_status &nativeStatus);
void updateState();
void updateTorrentInfo();
void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p);
void handleFileCompletedAlert(const lt::file_completed_alert *p);
void handleFileRenamedAlert(const lt::file_renamed_alert *p);
void handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p);
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p);
void handlePerformanceAlert(const lt::performance_alert *p) const;
void handleSaveResumeDataAlert(const lt::save_resume_data_alert *p);
void handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p);
void handleTorrentCheckedAlert(const lt::torrent_checked_alert *p);
void handleTorrentFinishedAlert(const lt::torrent_finished_alert *p);
void handleTorrentPausedAlert(const lt::torrent_paused_alert *p);
void handleTorrentResumedAlert(const lt::torrent_resumed_alert *p);
void handleTrackerErrorAlert(const lt::tracker_error_alert *p);
void handleTrackerReplyAlert(const lt::tracker_reply_alert *p);
void handleTrackerWarningAlert(const lt::tracker_warning_alert *p);
void resume_impl(bool forced);
bool isMoveInProgress() const;
QString actualStorageLocation() const;
bool isAutoManaged() const;
void setAutoManaged(bool enable);
void adjustActualSavePath();
void adjustActualSavePath_impl();
void move_impl(QString path, MoveStorageMode mode);
void moveStorage(const QString &newPath, MoveStorageMode mode);
void manageIncompleteFiles();
void setFirstLastPiecePriorityImpl(bool enabled, const QVector<DownloadPriority> &updatedFilePrio = {});
Session *const m_session;
lt::torrent_handle m_nativeHandle;
lt::torrent_status m_nativeStatus;
TorrentState m_state;
TorrentInfo m_torrentInfo;
SpeedMonitor m_speedMonitor;
InfoHash m_hash;
bool m_storageIsMoving = false;
// m_moveFinishedTriggers is activated only when the following conditions are met:
// all file rename jobs complete, all file move jobs complete
QQueue<EventTrigger> m_moveFinishedTriggers;
int m_renameCount;
// Until libtorrent provide an "old_name" field in `file_renamed_alert`
// we will rely on this workaround to remove empty leftover folders
QHash<LTFileIndex, QVector<QString>> m_oldPath;
bool m_useAutoTMM;
// Persistent data
QString m_name;
QString m_savePath;
QString m_category;
QSet<QString> m_tags;
bool m_hasSeedStatus;
qreal m_ratioLimit;
int m_seedingTimeLimit;
bool m_tempPathDisabled;
bool m_fastresumeDataRejected;
bool m_hasMissingFiles;
bool m_hasRootFolder;
bool m_needsToSetFirstLastPiecePriority;
QHash<QString, TrackerInfo> m_trackerInfos;
bool m_unchecked = false;
};
}

1
src/base/torrentfilter.cpp

@ -28,6 +28,7 @@
#include "torrentfilter.h" #include "torrentfilter.h"
#include "bittorrent/infohash.h"
#include "bittorrent/torrenthandle.h" #include "bittorrent/torrenthandle.h"
const QString TorrentFilter::AnyCategory; const QString TorrentFilter::AnyCategory;

1
src/base/utils/fs.cpp

@ -28,6 +28,7 @@
#include "fs.h" #include "fs.h"
#include <cerrno>
#include <cstring> #include <cstring>
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)

2
src/gui/properties/piecesbar.cpp

@ -37,7 +37,9 @@
#include <QTextStream> #include <QTextStream>
#include <QToolTip> #include <QToolTip>
#include "base/indexrange.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/torrentinfo.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
namespace namespace

1
src/gui/properties/propertieswidget.cpp

@ -43,6 +43,7 @@
#include <QUrl> #include <QUrl>
#include "base/bittorrent/downloadpriority.h" #include "base/bittorrent/downloadpriority.h"
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/preferences.h" #include "base/preferences.h"

3
src/gui/transferlistfilterswidget.cpp

@ -38,6 +38,7 @@
#include <QUrl> #include <QUrl>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/trackerentry.h" #include "base/bittorrent/trackerentry.h"
@ -223,7 +224,7 @@ void StatusFilterWidget::updateTorrentNumbers()
int nbStalledDownloading = 0; int nbStalledDownloading = 0;
int nbErrored = 0; int nbErrored = 0;
const QHash<BitTorrent::InfoHash, BitTorrent::TorrentHandle *> torrents = BitTorrent::Session::instance()->torrents(); const QVector<BitTorrent::TorrentHandle *> torrents = BitTorrent::Session::instance()->torrents();
for (const BitTorrent::TorrentHandle *torrent : torrents) { for (const BitTorrent::TorrentHandle *torrent : torrents) {
if (torrent->isDownloading()) if (torrent->isDownloading())
++nbDownloading; ++nbDownloading;

1
src/gui/transferlistsortmodel.cpp

@ -31,6 +31,7 @@
#include <QDateTime> #include <QDateTime>
#include <QStringList> #include <QStringList>
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/global.h" #include "base/global.h"
#include "base/types.h" #include "base/types.h"

2
src/gui/transferlistwidget.cpp

@ -652,7 +652,7 @@ void TransferListWidget::copySelectedMagnetURIs() const
{ {
QStringList magnetUris; QStringList magnetUris;
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
magnetUris << torrent->toMagnetUri(); magnetUris << torrent->createMagnetURI();
qApp->clipboard()->setText(magnetUris.join('\n')); qApp->clipboard()->setText(magnetUris.join('\n'));
} }

3
src/webui/api/serialize/serialize_torrent.cpp

@ -30,6 +30,7 @@
#include <QDateTime> #include <QDateTime>
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
@ -85,7 +86,7 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent)
QVariantMap ret = { QVariantMap ret = {
{KEY_TORRENT_HASH, QString(torrent.hash())}, {KEY_TORRENT_HASH, QString(torrent.hash())},
{KEY_TORRENT_NAME, torrent.name()}, {KEY_TORRENT_NAME, torrent.name()},
{KEY_TORRENT_MAGNET_URI, torrent.toMagnetUri()}, {KEY_TORRENT_MAGNET_URI, torrent.createMagnetURI()},
{KEY_TORRENT_SIZE, torrent.wantedSize()}, {KEY_TORRENT_SIZE, torrent.wantedSize()},
{KEY_TORRENT_PROGRESS, torrent.progress()}, {KEY_TORRENT_PROGRESS, torrent.progress()},
{KEY_TORRENT_DLSPEED, torrent.downloadPayloadRate()}, {KEY_TORRENT_DLSPEED, torrent.downloadPayloadRate()},

1
src/webui/api/synccontroller.cpp

@ -34,6 +34,7 @@
#include <QMetaObject> #include <QMetaObject>
#include <QThread> #include <QThread>
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/peeraddress.h" #include "base/bittorrent/peeraddress.h"
#include "base/bittorrent/peerinfo.h" #include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"

Loading…
Cancel
Save