mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-28 23:44:32 +00:00
Merge pull request #10437 from Chocobo1/ngen
Migrate to update-to-date libtorrent functions
This commit is contained in:
commit
a3fee32b42
@ -65,7 +65,6 @@
|
|||||||
|
|
||||||
const QString QB_EXT {QStringLiteral(".!qB")};
|
const QString QB_EXT {QStringLiteral(".!qB")};
|
||||||
|
|
||||||
namespace libt = libtorrent;
|
|
||||||
using namespace BitTorrent;
|
using namespace BitTorrent;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -92,7 +91,7 @@ namespace
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
using ListType = libt::entry::list_type;
|
using ListType = lt::entry::list_type;
|
||||||
|
|
||||||
ListType setToEntryList(const QSet<QString> &input)
|
ListType setToEntryList(const QSet<QString> &input)
|
||||||
{
|
{
|
||||||
@ -366,12 +365,33 @@ QString TorrentHandle::nativeActualSavePath() const
|
|||||||
return QString::fromStdString(m_nativeStatus.save_path);
|
return QString::fromStdString(m_nativeStatus.save_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TorrentHandle::isAutoManaged() const
|
||||||
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
|
return m_nativeStatus.auto_managed;
|
||||||
|
#else
|
||||||
|
return (m_nativeStatus.flags & lt::torrent_flags::auto_managed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentHandle::setAutoManaged(const bool enable)
|
||||||
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
|
m_nativeHandle.auto_managed(enable);
|
||||||
|
#else
|
||||||
|
if (enable)
|
||||||
|
m_nativeHandle.set_flags(lt::torrent_flags::auto_managed);
|
||||||
|
else
|
||||||
|
m_nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
QList<TrackerEntry> TorrentHandle::trackers() const
|
QList<TrackerEntry> TorrentHandle::trackers() const
|
||||||
{
|
{
|
||||||
QList<TrackerEntry> entries;
|
QList<TrackerEntry> entries;
|
||||||
const std::vector<libt::announce_entry> announces = m_nativeHandle.trackers();
|
const std::vector<lt::announce_entry> announces = m_nativeHandle.trackers();
|
||||||
|
|
||||||
for (const libt::announce_entry &tracker : announces)
|
for (const lt::announce_entry &tracker : announces)
|
||||||
entries << tracker;
|
entries << tracker;
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
@ -399,7 +419,7 @@ void TorrentHandle::replaceTrackers(const QList<TrackerEntry> &trackers)
|
|||||||
QList<TrackerEntry> existingTrackers = this->trackers();
|
QList<TrackerEntry> existingTrackers = this->trackers();
|
||||||
QList<TrackerEntry> addedTrackers;
|
QList<TrackerEntry> addedTrackers;
|
||||||
|
|
||||||
std::vector<libt::announce_entry> announces;
|
std::vector<lt::announce_entry> announces;
|
||||||
for (const TrackerEntry &tracker : trackers) {
|
for (const TrackerEntry &tracker : trackers) {
|
||||||
announces.push_back(tracker.nativeEntry());
|
announces.push_back(tracker.nativeEntry());
|
||||||
if (!existingTrackers.contains(tracker))
|
if (!existingTrackers.contains(tracker))
|
||||||
@ -484,8 +504,8 @@ bool TorrentHandle::removeUrlSeed(const QUrl &urlSeed)
|
|||||||
|
|
||||||
bool TorrentHandle::connectPeer(const PeerAddress &peerAddress)
|
bool TorrentHandle::connectPeer(const PeerAddress &peerAddress)
|
||||||
{
|
{
|
||||||
libt::error_code ec;
|
lt::error_code ec;
|
||||||
const libt::address addr = libt::address::from_string(peerAddress.ip.toString().toStdString(), ec);
|
const lt::address addr = lt::address::from_string(peerAddress.ip.toString().toStdString(), ec);
|
||||||
if (ec) return false;
|
if (ec) return false;
|
||||||
|
|
||||||
const boost::asio::ip::tcp::endpoint ep(addr, peerAddress.port);
|
const boost::asio::ip::tcp::endpoint ep(addr, peerAddress.port);
|
||||||
@ -596,7 +616,7 @@ void TorrentHandle::removeAllTags()
|
|||||||
|
|
||||||
QDateTime TorrentHandle::addedTime() const
|
QDateTime TorrentHandle::addedTime() const
|
||||||
{
|
{
|
||||||
return QDateTime::fromTime_t(m_nativeStatus.added_time);
|
return QDateTime::fromSecsSinceEpoch(m_nativeStatus.added_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal TorrentHandle::ratioLimit() const
|
qreal TorrentHandle::ratioLimit() const
|
||||||
@ -643,11 +663,14 @@ QStringList TorrentHandle::absoluteFilePathsUnwanted() const
|
|||||||
if (!hasMetadata()) return {};
|
if (!hasMetadata()) return {};
|
||||||
|
|
||||||
const QDir saveDir(savePath(true));
|
const QDir saveDir(savePath(true));
|
||||||
QStringList res;
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
const std::vector<int> fp = m_nativeHandle.file_priorities();
|
const std::vector<LTDownloadPriority> fp = m_nativeHandle.file_priorities();
|
||||||
|
#else
|
||||||
|
const std::vector<LTDownloadPriority> fp = m_nativeHandle.get_file_priorities();
|
||||||
|
#endif
|
||||||
|
|
||||||
const int count = static_cast<int>(fp.size());
|
QStringList res;
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < static_cast<int>(fp.size()); ++i) {
|
||||||
if (fp[i] == 0) {
|
if (fp[i] == 0) {
|
||||||
const QString path = Utils::Fs::expandPathAbs(saveDir.absoluteFilePath(filePath(i)));
|
const QString path = Utils::Fs::expandPathAbs(saveDir.absoluteFilePath(filePath(i)));
|
||||||
if (path.contains(".unwanted"))
|
if (path.contains(".unwanted"))
|
||||||
@ -682,7 +705,12 @@ TorrentInfo TorrentHandle::info() const
|
|||||||
|
|
||||||
bool TorrentHandle::isPaused() const
|
bool TorrentHandle::isPaused() const
|
||||||
{
|
{
|
||||||
return (m_nativeStatus.paused && !m_nativeStatus.auto_managed);
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
|
return (m_nativeStatus.paused && !isAutoManaged());
|
||||||
|
#else
|
||||||
|
return ((m_nativeStatus.flags & lt::torrent_flags::paused)
|
||||||
|
&& !isAutoManaged());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandle::isResumed() const
|
bool TorrentHandle::isResumed() const
|
||||||
@ -692,13 +720,18 @@ bool TorrentHandle::isResumed() const
|
|||||||
|
|
||||||
bool TorrentHandle::isQueued() const
|
bool TorrentHandle::isQueued() const
|
||||||
{
|
{
|
||||||
return (m_nativeStatus.paused && m_nativeStatus.auto_managed);
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
|
return (m_nativeStatus.paused && isAutoManaged());
|
||||||
|
#else
|
||||||
|
return ((m_nativeStatus.flags & lt::torrent_flags::paused)
|
||||||
|
&& isAutoManaged());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandle::isChecking() const
|
bool TorrentHandle::isChecking() const
|
||||||
{
|
{
|
||||||
return ((m_nativeStatus.state == libt::torrent_status::checking_files)
|
return ((m_nativeStatus.state == lt::torrent_status::checking_files)
|
||||||
|| (m_nativeStatus.state == libt::torrent_status::checking_resume_data));
|
|| (m_nativeStatus.state == lt::torrent_status::checking_resume_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandle::isDownloading() const
|
bool TorrentHandle::isDownloading() const
|
||||||
@ -764,18 +797,27 @@ bool TorrentHandle::isSeed() const
|
|||||||
// May suffer from approximation problems
|
// May suffer from approximation problems
|
||||||
//return (progress() == 1.);
|
//return (progress() == 1.);
|
||||||
// This looks safe
|
// This looks safe
|
||||||
return ((m_nativeStatus.state == libt::torrent_status::finished)
|
return ((m_nativeStatus.state == lt::torrent_status::finished)
|
||||||
|| (m_nativeStatus.state == libt::torrent_status::seeding));
|
|| (m_nativeStatus.state == lt::torrent_status::seeding));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandle::isForced() const
|
bool TorrentHandle::isForced() const
|
||||||
{
|
{
|
||||||
return (!m_nativeStatus.paused && !m_nativeStatus.auto_managed);
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
|
return (!m_nativeStatus.paused && !isAutoManaged());
|
||||||
|
#else
|
||||||
|
return (!(m_nativeStatus.flags & lt::torrent_flags::paused)
|
||||||
|
&& !isAutoManaged());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandle::isSequentialDownload() const
|
bool TorrentHandle::isSequentialDownload() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return m_nativeStatus.sequential_download;
|
return m_nativeStatus.sequential_download;
|
||||||
|
#else
|
||||||
|
return (m_nativeStatus.flags & lt::torrent_flags::sequential_download);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandle::hasFirstLastPiecePriority() const
|
bool TorrentHandle::hasFirstLastPiecePriority() const
|
||||||
@ -783,7 +825,11 @@ bool TorrentHandle::hasFirstLastPiecePriority() const
|
|||||||
if (!hasMetadata())
|
if (!hasMetadata())
|
||||||
return m_needsToSetFirstLastPiecePriority;
|
return m_needsToSetFirstLastPiecePriority;
|
||||||
|
|
||||||
const std::vector<int> filePriorities = nativeHandle().file_priorities();
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
|
const std::vector<LTDownloadPriority> filePriorities = nativeHandle().file_priorities();
|
||||||
|
#else
|
||||||
|
const std::vector<LTDownloadPriority> filePriorities = nativeHandle().get_file_priorities();
|
||||||
|
#endif
|
||||||
for (int i = 0; i < static_cast<int>(filePriorities.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(filePriorities.size()); ++i) {
|
||||||
if (filePriorities[i] <= 0)
|
if (filePriorities[i] <= 0)
|
||||||
continue;
|
continue;
|
||||||
@ -804,7 +850,7 @@ TorrentState TorrentHandle::state() const
|
|||||||
|
|
||||||
void TorrentHandle::updateState()
|
void TorrentHandle::updateState()
|
||||||
{
|
{
|
||||||
if (m_nativeStatus.state == libt::torrent_status::checking_resume_data) {
|
if (m_nativeStatus.state == lt::torrent_status::checking_resume_data) {
|
||||||
m_state = TorrentState::CheckingResumeData;
|
m_state = TorrentState::CheckingResumeData;
|
||||||
}
|
}
|
||||||
else if (isMoveInProgress()) {
|
else if (isMoveInProgress()) {
|
||||||
@ -824,23 +870,23 @@ void TorrentHandle::updateState()
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
switch (m_nativeStatus.state) {
|
switch (m_nativeStatus.state) {
|
||||||
case libt::torrent_status::finished:
|
case lt::torrent_status::finished:
|
||||||
case libt::torrent_status::seeding:
|
case lt::torrent_status::seeding:
|
||||||
if (isForced())
|
if (isForced())
|
||||||
m_state = TorrentState::ForcedUploading;
|
m_state = TorrentState::ForcedUploading;
|
||||||
else
|
else
|
||||||
m_state = m_nativeStatus.upload_payload_rate > 0 ? TorrentState::Uploading : TorrentState::StalledUploading;
|
m_state = m_nativeStatus.upload_payload_rate > 0 ? TorrentState::Uploading : TorrentState::StalledUploading;
|
||||||
break;
|
break;
|
||||||
case libt::torrent_status::allocating:
|
case lt::torrent_status::allocating:
|
||||||
m_state = TorrentState::Allocating;
|
m_state = TorrentState::Allocating;
|
||||||
break;
|
break;
|
||||||
case libt::torrent_status::checking_files:
|
case lt::torrent_status::checking_files:
|
||||||
m_state = m_hasSeedStatus ? TorrentState::CheckingUploading : TorrentState::CheckingDownloading;
|
m_state = m_hasSeedStatus ? TorrentState::CheckingUploading : TorrentState::CheckingDownloading;
|
||||||
break;
|
break;
|
||||||
case libt::torrent_status::downloading_metadata:
|
case lt::torrent_status::downloading_metadata:
|
||||||
m_state = TorrentState::DownloadingMetadata;
|
m_state = TorrentState::DownloadingMetadata;
|
||||||
break;
|
break;
|
||||||
case libt::torrent_status::downloading:
|
case lt::torrent_status::downloading:
|
||||||
if (isForced())
|
if (isForced())
|
||||||
m_state = TorrentState::ForcedDownloading;
|
m_state = TorrentState::ForcedDownloading;
|
||||||
else
|
else
|
||||||
@ -866,7 +912,12 @@ bool TorrentHandle::hasMissingFiles() const
|
|||||||
|
|
||||||
bool TorrentHandle::hasError() const
|
bool TorrentHandle::hasError() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return (m_nativeStatus.paused && m_nativeStatus.errc);
|
return (m_nativeStatus.paused && m_nativeStatus.errc);
|
||||||
|
#else
|
||||||
|
return ((m_nativeStatus.flags & lt::torrent_flags::paused)
|
||||||
|
&& m_nativeStatus.errc);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentHandle::hasFilteredPieces() const
|
bool TorrentHandle::hasFilteredPieces() const
|
||||||
@ -904,19 +955,31 @@ qlonglong TorrentHandle::totalUpload() const
|
|||||||
return m_nativeStatus.all_time_upload;
|
return m_nativeStatus.all_time_upload;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::activeTime() const
|
qlonglong TorrentHandle::activeTime() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return m_nativeStatus.active_time;
|
return m_nativeStatus.active_time;
|
||||||
|
#else
|
||||||
|
return lt::total_seconds(m_nativeStatus.active_duration);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::finishedTime() const
|
qlonglong TorrentHandle::finishedTime() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return m_nativeStatus.finished_time;
|
return m_nativeStatus.finished_time;
|
||||||
|
#else
|
||||||
|
return lt::total_seconds(m_nativeStatus.finished_duration);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::seedingTime() const
|
qlonglong TorrentHandle::seedingTime() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return m_nativeStatus.seeding_time;
|
return m_nativeStatus.seeding_time;
|
||||||
|
#else
|
||||||
|
return lt::total_seconds(m_nativeStatus.seeding_duration);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
qulonglong TorrentHandle::eta() const
|
qulonglong TorrentHandle::eta() const
|
||||||
@ -960,7 +1023,7 @@ qulonglong TorrentHandle::eta() const
|
|||||||
QVector<qreal> TorrentHandle::filesProgress() const
|
QVector<qreal> TorrentHandle::filesProgress() const
|
||||||
{
|
{
|
||||||
std::vector<boost::int64_t> fp;
|
std::vector<boost::int64_t> fp;
|
||||||
m_nativeHandle.file_progress(fp, libt::torrent_handle::piece_granularity);
|
m_nativeHandle.file_progress(fp, lt::torrent_handle::piece_granularity);
|
||||||
|
|
||||||
const int count = static_cast<int>(fp.size());
|
const int count = static_cast<int>(fp.size());
|
||||||
QVector<qreal> result;
|
QVector<qreal> result;
|
||||||
@ -1022,7 +1085,7 @@ int TorrentHandle::incompleteCount() const
|
|||||||
QDateTime TorrentHandle::lastSeenComplete() const
|
QDateTime TorrentHandle::lastSeenComplete() const
|
||||||
{
|
{
|
||||||
if (m_nativeStatus.last_seen_complete > 0)
|
if (m_nativeStatus.last_seen_complete > 0)
|
||||||
return QDateTime::fromTime_t(m_nativeStatus.last_seen_complete);
|
return QDateTime::fromSecsSinceEpoch(m_nativeStatus.last_seen_complete);
|
||||||
else
|
else
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -1030,26 +1093,36 @@ QDateTime TorrentHandle::lastSeenComplete() const
|
|||||||
QDateTime TorrentHandle::completedTime() const
|
QDateTime TorrentHandle::completedTime() const
|
||||||
{
|
{
|
||||||
if (m_nativeStatus.completed_time > 0)
|
if (m_nativeStatus.completed_time > 0)
|
||||||
return QDateTime::fromTime_t(m_nativeStatus.completed_time);
|
return QDateTime::fromSecsSinceEpoch(m_nativeStatus.completed_time);
|
||||||
else
|
else
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::timeSinceUpload() const
|
qlonglong TorrentHandle::timeSinceUpload() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return m_nativeStatus.time_since_upload;
|
return m_nativeStatus.time_since_upload;
|
||||||
|
#else
|
||||||
|
return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_upload);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::timeSinceDownload() const
|
qlonglong TorrentHandle::timeSinceDownload() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return m_nativeStatus.time_since_download;
|
return m_nativeStatus.time_since_download;
|
||||||
|
#else
|
||||||
|
return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_download);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::timeSinceActivity() const
|
qlonglong TorrentHandle::timeSinceActivity() const
|
||||||
{
|
{
|
||||||
return ((m_nativeStatus.time_since_upload < 0) != (m_nativeStatus.time_since_download < 0))
|
const qlonglong upTime = timeSinceUpload();
|
||||||
? std::max(m_nativeStatus.time_since_upload, m_nativeStatus.time_since_download)
|
const qlonglong downTime = timeSinceDownload();
|
||||||
: std::min(m_nativeStatus.time_since_upload, m_nativeStatus.time_since_download);
|
return ((upTime < 0) != (downTime < 0))
|
||||||
|
? std::max(upTime, downTime)
|
||||||
|
: std::min(upTime, downTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::downloadLimit() const
|
int TorrentHandle::downloadLimit() const
|
||||||
@ -1064,17 +1137,21 @@ int TorrentHandle::uploadLimit() const
|
|||||||
|
|
||||||
bool TorrentHandle::superSeeding() const
|
bool TorrentHandle::superSeeding() const
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
return m_nativeStatus.super_seeding;
|
return m_nativeStatus.super_seeding;
|
||||||
|
#else
|
||||||
|
return (m_nativeStatus.flags & lt::torrent_flags::super_seeding);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<PeerInfo> TorrentHandle::peers() const
|
QList<PeerInfo> TorrentHandle::peers() const
|
||||||
{
|
{
|
||||||
QList<PeerInfo> peers;
|
QList<PeerInfo> peers;
|
||||||
std::vector<libt::peer_info> nativePeers;
|
std::vector<lt::peer_info> nativePeers;
|
||||||
|
|
||||||
m_nativeHandle.get_peer_info(nativePeers);
|
m_nativeHandle.get_peer_info(nativePeers);
|
||||||
|
|
||||||
for (const libt::peer_info &peer : nativePeers)
|
for (const lt::peer_info &peer : nativePeers)
|
||||||
peers << PeerInfo(this, peer);
|
peers << PeerInfo(this, peer);
|
||||||
|
|
||||||
return peers;
|
return peers;
|
||||||
@ -1094,11 +1171,11 @@ QBitArray TorrentHandle::downloadingPieces() const
|
|||||||
{
|
{
|
||||||
QBitArray result(piecesCount());
|
QBitArray result(piecesCount());
|
||||||
|
|
||||||
std::vector<libt::partial_piece_info> queue;
|
std::vector<lt::partial_piece_info> queue;
|
||||||
m_nativeHandle.get_download_queue(queue);
|
m_nativeHandle.get_download_queue(queue);
|
||||||
|
|
||||||
std::vector<libt::partial_piece_info>::const_iterator it = queue.begin();
|
std::vector<lt::partial_piece_info>::const_iterator it = queue.begin();
|
||||||
std::vector<libt::partial_piece_info>::const_iterator itend = queue.end();
|
std::vector<lt::partial_piece_info>::const_iterator itend = queue.end();
|
||||||
for (; it != itend; ++it)
|
for (; it != itend; ++it)
|
||||||
result.setBit(it->piece_index);
|
result.setBit(it->piece_index);
|
||||||
|
|
||||||
@ -1180,7 +1257,7 @@ int TorrentHandle::connectionsLimit() const
|
|||||||
|
|
||||||
qlonglong TorrentHandle::nextAnnounce() const
|
qlonglong TorrentHandle::nextAnnounce() const
|
||||||
{
|
{
|
||||||
return libt::duration_cast<libt::seconds>(m_nativeStatus.next_announce).count();
|
return lt::total_seconds(m_nativeStatus.next_announce);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::setName(const QString &name)
|
void TorrentHandle::setName(const QString &name)
|
||||||
@ -1258,17 +1335,30 @@ void TorrentHandle::forceRecheck()
|
|||||||
m_unchecked = false;
|
m_unchecked = false;
|
||||||
|
|
||||||
if (isPaused()) {
|
if (isPaused()) {
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
m_nativeHandle.stop_when_ready(true);
|
m_nativeHandle.stop_when_ready(true);
|
||||||
|
#else
|
||||||
|
m_nativeHandle.set_flags(lt::torrent_flags::stop_when_ready);
|
||||||
|
#endif
|
||||||
resume_impl(false);
|
resume_impl(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::setSequentialDownload(const bool b)
|
void TorrentHandle::setSequentialDownload(const bool enable)
|
||||||
{
|
{
|
||||||
if (b != isSequentialDownload()) {
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
m_nativeHandle.set_sequential_download(b);
|
m_nativeHandle.set_sequential_download(enable);
|
||||||
m_nativeStatus.sequential_download = b; // prevent return cached value
|
m_nativeStatus.sequential_download = enable; // prevent return cached value
|
||||||
|
#else
|
||||||
|
if (enable) {
|
||||||
|
m_nativeHandle.set_flags(lt::torrent_flags::sequential_download);
|
||||||
|
m_nativeStatus.flags |= lt::torrent_flags::sequential_download; // prevent return cached value
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
m_nativeHandle.unset_flags(lt::torrent_flags::sequential_download);
|
||||||
|
m_nativeStatus.flags &= ~lt::torrent_flags::sequential_download; // prevent return cached value
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::toggleSequentialDownload()
|
void TorrentHandle::toggleSequentialDownload()
|
||||||
@ -1333,7 +1423,7 @@ void TorrentHandle::pause()
|
|||||||
{
|
{
|
||||||
if (isPaused()) return;
|
if (isPaused()) return;
|
||||||
|
|
||||||
m_nativeHandle.auto_managed(false);
|
setAutoManaged(false);
|
||||||
m_nativeHandle.pause();
|
m_nativeHandle.pause();
|
||||||
|
|
||||||
// Libtorrent doesn't emit a torrent_paused_alert when the
|
// Libtorrent doesn't emit a torrent_paused_alert when the
|
||||||
@ -1358,7 +1448,7 @@ void TorrentHandle::resume_impl(bool forced)
|
|||||||
m_nativeHandle.force_recheck();
|
m_nativeHandle.force_recheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nativeHandle.auto_managed(!forced);
|
setAutoManaged(!forced);
|
||||||
m_nativeHandle.resume();
|
m_nativeHandle.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1375,8 +1465,13 @@ void TorrentHandle::moveStorage(const QString &newPath, bool overwrite)
|
|||||||
|
|
||||||
qDebug("move storage: %s to %s", qUtf8Printable(oldPath), qUtf8Printable(newPath));
|
qDebug("move storage: %s to %s", qUtf8Printable(oldPath), qUtf8Printable(newPath));
|
||||||
// Actually move the storage
|
// Actually move the storage
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
m_nativeHandle.move_storage(newPath.toUtf8().constData()
|
m_nativeHandle.move_storage(newPath.toUtf8().constData()
|
||||||
, (overwrite ? libt::always_replace_files : libt::dont_replace));
|
, (overwrite ? lt::always_replace_files : lt::dont_replace));
|
||||||
|
#else
|
||||||
|
m_nativeHandle.move_storage(newPath.toUtf8().constData()
|
||||||
|
, (overwrite ? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace));
|
||||||
|
#endif
|
||||||
m_moveStorageInfo.oldPath = oldPath;
|
m_moveStorageInfo.oldPath = oldPath;
|
||||||
m_moveStorageInfo.newPath = newPath;
|
m_moveStorageInfo.newPath = newPath;
|
||||||
updateState();
|
updateState();
|
||||||
@ -1394,14 +1489,14 @@ bool TorrentHandle::saveTorrentFile(const QString &path)
|
|||||||
{
|
{
|
||||||
if (!m_torrentInfo.isValid()) return false;
|
if (!m_torrentInfo.isValid()) return false;
|
||||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
const libt::create_torrent torrentCreator = libt::create_torrent(*(m_torrentInfo.nativeInfo()), true);
|
const lt::create_torrent torrentCreator = lt::create_torrent(*(m_torrentInfo.nativeInfo()), true);
|
||||||
#else
|
#else
|
||||||
const libt::create_torrent torrentCreator = libt::create_torrent(*(m_torrentInfo.nativeInfo()));
|
const lt::create_torrent torrentCreator = lt::create_torrent(*(m_torrentInfo.nativeInfo()));
|
||||||
#endif
|
#endif
|
||||||
const libt::entry torrentEntry = torrentCreator.generate();
|
const lt::entry torrentEntry = torrentCreator.generate();
|
||||||
|
|
||||||
QVector<char> out;
|
QVector<char> out;
|
||||||
libt::bencode(std::back_inserter(out), torrentEntry);
|
lt::bencode(std::back_inserter(out), torrentEntry);
|
||||||
QFile torrentFile(path);
|
QFile torrentFile(path);
|
||||||
if (!out.empty() && torrentFile.open(QIODevice::WriteOnly))
|
if (!out.empty() && torrentFile.open(QIODevice::WriteOnly))
|
||||||
return (torrentFile.write(&out[0], out.size()) == out.size());
|
return (torrentFile.write(&out[0], out.size()) == out.size());
|
||||||
@ -1409,7 +1504,7 @@ bool TorrentHandle::saveTorrentFile(const QString &path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::handleStateUpdate(const libt::torrent_status &nativeStatus)
|
void TorrentHandle::handleStateUpdate(const lt::torrent_status &nativeStatus)
|
||||||
{
|
{
|
||||||
updateStatus(nativeStatus);
|
updateStatus(nativeStatus);
|
||||||
}
|
}
|
||||||
@ -1629,7 +1724,7 @@ void TorrentHandle::handleSaveResumeDataFailedAlert(const libtorrent::save_resum
|
|||||||
{
|
{
|
||||||
// if torrent has no metadata we should save dummy fastresume data
|
// if torrent has no metadata we should save dummy fastresume data
|
||||||
// containing Magnet URI and qBittorrent own resume data only
|
// containing Magnet URI and qBittorrent own resume data only
|
||||||
if (p->error.value() == libt::errors::no_metadata)
|
if (p->error.value() == lt::errors::no_metadata)
|
||||||
handleSaveResumeDataAlert(nullptr);
|
handleSaveResumeDataAlert(nullptr);
|
||||||
else
|
else
|
||||||
m_session->handleTorrentResumeDataFailed(this);
|
m_session->handleTorrentResumeDataFailed(this);
|
||||||
@ -1637,7 +1732,7 @@ void TorrentHandle::handleSaveResumeDataFailedAlert(const libtorrent::save_resum
|
|||||||
|
|
||||||
void TorrentHandle::handleFastResumeRejectedAlert(const libtorrent::fastresume_rejected_alert *p)
|
void TorrentHandle::handleFastResumeRejectedAlert(const libtorrent::fastresume_rejected_alert *p)
|
||||||
{
|
{
|
||||||
if (p->error.value() == libt::errors::mismatching_file_size) {
|
if (p->error.value() == lt::errors::mismatching_file_size) {
|
||||||
// Mismatching file size (files were probably moved)
|
// Mismatching file size (files were probably moved)
|
||||||
m_hasMissingFiles = true;
|
m_hasMissingFiles = true;
|
||||||
LogMsg(tr("File sizes mismatch for torrent '%1', pausing it.").arg(name()), Log::CRITICAL);
|
LogMsg(tr("File sizes mismatch for torrent '%1', pausing it.").arg(name()), Log::CRITICAL);
|
||||||
@ -1708,12 +1803,12 @@ void TorrentHandle::handleFileCompletedAlert(const libtorrent::file_completed_al
|
|||||||
void TorrentHandle::handleStatsAlert(const libtorrent::stats_alert *p)
|
void TorrentHandle::handleStatsAlert(const libtorrent::stats_alert *p)
|
||||||
{
|
{
|
||||||
Q_ASSERT(p->interval >= 1000);
|
Q_ASSERT(p->interval >= 1000);
|
||||||
const SpeedSample transferred(p->transferred[libt::stats_alert::download_payload] * 1000LL / p->interval,
|
const SpeedSample transferred(p->transferred[lt::stats_alert::download_payload] * 1000LL / p->interval,
|
||||||
p->transferred[libt::stats_alert::upload_payload] * 1000LL / p->interval);
|
p->transferred[lt::stats_alert::upload_payload] * 1000LL / p->interval);
|
||||||
m_speedMonitor.addSample(transferred);
|
m_speedMonitor.addSample(transferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::handleMetadataReceivedAlert(const libt::metadata_received_alert *p)
|
void TorrentHandle::handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
|
||||||
{
|
{
|
||||||
Q_UNUSED(p);
|
Q_UNUSED(p);
|
||||||
qDebug("Metadata received for torrent %s.", qUtf8Printable(name()));
|
qDebug("Metadata received for torrent %s.", qUtf8Printable(name()));
|
||||||
@ -1762,56 +1857,56 @@ void TorrentHandle::handleAppendExtensionToggled()
|
|||||||
void TorrentHandle::handleAlert(const libtorrent::alert *a)
|
void TorrentHandle::handleAlert(const libtorrent::alert *a)
|
||||||
{
|
{
|
||||||
switch (a->type()) {
|
switch (a->type()) {
|
||||||
case libt::stats_alert::alert_type:
|
case lt::stats_alert::alert_type:
|
||||||
handleStatsAlert(static_cast<const libt::stats_alert*>(a));
|
handleStatsAlert(static_cast<const lt::stats_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::file_renamed_alert::alert_type:
|
case lt::file_renamed_alert::alert_type:
|
||||||
handleFileRenamedAlert(static_cast<const libt::file_renamed_alert*>(a));
|
handleFileRenamedAlert(static_cast<const lt::file_renamed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::file_rename_failed_alert::alert_type:
|
case lt::file_rename_failed_alert::alert_type:
|
||||||
handleFileRenameFailedAlert(static_cast<const libt::file_rename_failed_alert*>(a));
|
handleFileRenameFailedAlert(static_cast<const lt::file_rename_failed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::file_completed_alert::alert_type:
|
case lt::file_completed_alert::alert_type:
|
||||||
handleFileCompletedAlert(static_cast<const libt::file_completed_alert*>(a));
|
handleFileCompletedAlert(static_cast<const lt::file_completed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::torrent_finished_alert::alert_type:
|
case lt::torrent_finished_alert::alert_type:
|
||||||
handleTorrentFinishedAlert(static_cast<const libt::torrent_finished_alert*>(a));
|
handleTorrentFinishedAlert(static_cast<const lt::torrent_finished_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::save_resume_data_alert::alert_type:
|
case lt::save_resume_data_alert::alert_type:
|
||||||
handleSaveResumeDataAlert(static_cast<const libt::save_resume_data_alert*>(a));
|
handleSaveResumeDataAlert(static_cast<const lt::save_resume_data_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::save_resume_data_failed_alert::alert_type:
|
case lt::save_resume_data_failed_alert::alert_type:
|
||||||
handleSaveResumeDataFailedAlert(static_cast<const libt::save_resume_data_failed_alert*>(a));
|
handleSaveResumeDataFailedAlert(static_cast<const lt::save_resume_data_failed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::storage_moved_alert::alert_type:
|
case lt::storage_moved_alert::alert_type:
|
||||||
handleStorageMovedAlert(static_cast<const libt::storage_moved_alert*>(a));
|
handleStorageMovedAlert(static_cast<const lt::storage_moved_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::storage_moved_failed_alert::alert_type:
|
case lt::storage_moved_failed_alert::alert_type:
|
||||||
handleStorageMovedFailedAlert(static_cast<const libt::storage_moved_failed_alert*>(a));
|
handleStorageMovedFailedAlert(static_cast<const lt::storage_moved_failed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::torrent_paused_alert::alert_type:
|
case lt::torrent_paused_alert::alert_type:
|
||||||
handleTorrentPausedAlert(static_cast<const libt::torrent_paused_alert*>(a));
|
handleTorrentPausedAlert(static_cast<const lt::torrent_paused_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::torrent_resumed_alert::alert_type:
|
case lt::torrent_resumed_alert::alert_type:
|
||||||
handleTorrentResumedAlert(static_cast<const libt::torrent_resumed_alert*>(a));
|
handleTorrentResumedAlert(static_cast<const lt::torrent_resumed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::tracker_error_alert::alert_type:
|
case lt::tracker_error_alert::alert_type:
|
||||||
handleTrackerErrorAlert(static_cast<const libt::tracker_error_alert*>(a));
|
handleTrackerErrorAlert(static_cast<const lt::tracker_error_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::tracker_reply_alert::alert_type:
|
case lt::tracker_reply_alert::alert_type:
|
||||||
handleTrackerReplyAlert(static_cast<const libt::tracker_reply_alert*>(a));
|
handleTrackerReplyAlert(static_cast<const lt::tracker_reply_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::tracker_warning_alert::alert_type:
|
case lt::tracker_warning_alert::alert_type:
|
||||||
handleTrackerWarningAlert(static_cast<const libt::tracker_warning_alert*>(a));
|
handleTrackerWarningAlert(static_cast<const lt::tracker_warning_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::metadata_received_alert::alert_type:
|
case lt::metadata_received_alert::alert_type:
|
||||||
handleMetadataReceivedAlert(static_cast<const libt::metadata_received_alert*>(a));
|
handleMetadataReceivedAlert(static_cast<const lt::metadata_received_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::fastresume_rejected_alert::alert_type:
|
case lt::fastresume_rejected_alert::alert_type:
|
||||||
handleFastResumeRejectedAlert(static_cast<const libt::fastresume_rejected_alert*>(a));
|
handleFastResumeRejectedAlert(static_cast<const lt::fastresume_rejected_alert*>(a));
|
||||||
break;
|
break;
|
||||||
case libt::torrent_checked_alert::alert_type:
|
case lt::torrent_checked_alert::alert_type:
|
||||||
handleTorrentCheckedAlert(static_cast<const libt::torrent_checked_alert*>(a));
|
handleTorrentCheckedAlert(static_cast<const lt::torrent_checked_alert*>(a));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1950,7 +2045,14 @@ void TorrentHandle::setDownloadLimit(const int limit)
|
|||||||
|
|
||||||
void TorrentHandle::setSuperSeeding(const bool enable)
|
void TorrentHandle::setSuperSeeding(const bool enable)
|
||||||
{
|
{
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
m_nativeHandle.super_seeding(enable);
|
m_nativeHandle.super_seeding(enable);
|
||||||
|
#else
|
||||||
|
if (enable)
|
||||||
|
m_nativeHandle.set_flags(lt::torrent_flags::super_seeding);
|
||||||
|
else
|
||||||
|
m_nativeHandle.unset_flags(lt::torrent_flags::super_seeding);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::flushCache()
|
void TorrentHandle::flushCache()
|
||||||
@ -1960,7 +2062,7 @@ void TorrentHandle::flushCache()
|
|||||||
|
|
||||||
QString TorrentHandle::toMagnetUri() const
|
QString TorrentHandle::toMagnetUri() const
|
||||||
{
|
{
|
||||||
return QString::fromStdString(libt::make_magnet_uri(m_nativeHandle));
|
return QString::fromStdString(lt::make_magnet_uri(m_nativeHandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::prioritizeFiles(const QVector<DownloadPriority> &priorities)
|
void TorrentHandle::prioritizeFiles(const QVector<DownloadPriority> &priorities)
|
||||||
|
@ -266,9 +266,9 @@ namespace BitTorrent
|
|||||||
QString error() const;
|
QString error() const;
|
||||||
qlonglong totalDownload() const;
|
qlonglong totalDownload() const;
|
||||||
qlonglong totalUpload() const;
|
qlonglong totalUpload() const;
|
||||||
int activeTime() const;
|
qlonglong activeTime() const;
|
||||||
int finishedTime() const;
|
qlonglong finishedTime() const;
|
||||||
int seedingTime() const;
|
qlonglong seedingTime() const;
|
||||||
qulonglong eta() const;
|
qulonglong eta() const;
|
||||||
QVector<qreal> filesProgress() const;
|
QVector<qreal> filesProgress() const;
|
||||||
int seedsCount() const;
|
int seedsCount() const;
|
||||||
@ -281,9 +281,9 @@ namespace BitTorrent
|
|||||||
int incompleteCount() const;
|
int incompleteCount() const;
|
||||||
QDateTime lastSeenComplete() const;
|
QDateTime lastSeenComplete() const;
|
||||||
QDateTime completedTime() const;
|
QDateTime completedTime() const;
|
||||||
int timeSinceUpload() const;
|
qlonglong timeSinceUpload() const;
|
||||||
int timeSinceDownload() const;
|
qlonglong timeSinceDownload() const;
|
||||||
int timeSinceActivity() const;
|
qlonglong timeSinceActivity() const;
|
||||||
int downloadLimit() const;
|
int downloadLimit() const;
|
||||||
int uploadLimit() const;
|
int uploadLimit() const;
|
||||||
bool superSeeding() const;
|
bool superSeeding() const;
|
||||||
@ -304,7 +304,7 @@ namespace BitTorrent
|
|||||||
qlonglong nextAnnounce() const;
|
qlonglong nextAnnounce() const;
|
||||||
|
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
void setSequentialDownload(bool b);
|
void setSequentialDownload(bool enable);
|
||||||
void toggleSequentialDownload();
|
void toggleSequentialDownload();
|
||||||
void setFirstLastPiecePriority(bool enabled);
|
void setFirstLastPiecePriority(bool enabled);
|
||||||
void toggleFirstLastPiecePriority();
|
void toggleFirstLastPiecePriority();
|
||||||
@ -380,6 +380,8 @@ namespace BitTorrent
|
|||||||
void resume_impl(bool forced);
|
void resume_impl(bool forced);
|
||||||
bool isMoveInProgress() const;
|
bool isMoveInProgress() const;
|
||||||
QString nativeActualSavePath() const;
|
QString nativeActualSavePath() const;
|
||||||
|
bool isAutoManaged() const;
|
||||||
|
void setAutoManaged(bool enable);
|
||||||
|
|
||||||
void adjustActualSavePath();
|
void adjustActualSavePath();
|
||||||
void adjustActualSavePath_impl();
|
void adjustActualSavePath_impl();
|
||||||
|
@ -28,7 +28,10 @@
|
|||||||
|
|
||||||
#include "torrentinfo.h"
|
#include "torrentinfo.h"
|
||||||
|
|
||||||
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <libtorrent/error_code.hpp>
|
#include <libtorrent/error_code.hpp>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
@ -164,8 +167,14 @@ QString TorrentInfo::name() const
|
|||||||
QDateTime TorrentInfo::creationDate() const
|
QDateTime TorrentInfo::creationDate() const
|
||||||
{
|
{
|
||||||
if (!isValid()) return {};
|
if (!isValid()) return {};
|
||||||
const boost::optional<time_t> t = m_nativeInfo->creation_date();
|
|
||||||
return t ? QDateTime::fromTime_t(*t) : QDateTime();
|
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||||
|
const boost::optional<time_t> date = m_nativeInfo->creation_date();
|
||||||
|
return (date ? QDateTime::fromSecsSinceEpoch(*date) : QDateTime());
|
||||||
|
#else
|
||||||
|
const std::time_t date = m_nativeInfo->creation_date();
|
||||||
|
return ((date != 0) ? QDateTime::fromSecsSinceEpoch(date) : QDateTime());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TorrentInfo::creator() const
|
QString TorrentInfo::creator() const
|
||||||
|
@ -261,7 +261,7 @@ bool GeoIPDatabase::parseMetadata(const QVariantHash &metadata, QString &error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHECK_METADATA_REQ(build_epoch, ULongLong);
|
CHECK_METADATA_REQ(build_epoch, ULongLong);
|
||||||
m_buildEpoch = QDateTime::fromTime_t(metadata.value("build_epoch").toULongLong());
|
m_buildEpoch = QDateTime::fromSecsSinceEpoch(metadata.value("build_epoch").toULongLong());
|
||||||
|
|
||||||
CHECK_METADATA_OPT(languages, QVariantList);
|
CHECK_METADATA_OPT(languages, QVariantList);
|
||||||
CHECK_METADATA_OPT(description, QVariantHash);
|
CHECK_METADATA_OPT(description, QVariantHash);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user