2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2015-06-10 21:27:11 +00:00
|
|
|
* This file Copyright (C) 2009-2015 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-09-07 21:19:10 +00:00
|
|
|
#include <array>
|
2020-06-23 21:11:16 +00:00
|
|
|
#include <bitset>
|
2019-11-06 23:31:41 +00:00
|
|
|
#include <ctime> // time_t
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
#include <vector>
|
2019-11-06 23:31:41 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QMetaType>
|
2020-05-19 23:42:17 +00:00
|
|
|
#include <QObject>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
2020-09-07 21:19:10 +00:00
|
|
|
#include <libtransmission/crypto-utils.h>
|
2012-12-22 20:35:19 +00:00
|
|
|
#include <libtransmission/quark.h>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-06-24 18:28:54 +00:00
|
|
|
#include "FaviconCache.h"
|
2020-11-02 01:13:32 +00:00
|
|
|
#include "IconCache.h"
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "Macros.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Speed.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-08 18:39:37 +00:00
|
|
|
#ifdef ERROR
|
2017-04-19 12:04:45 +00:00
|
|
|
#undef ERROR
|
2013-09-08 18:39:37 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
class QPixmap;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
|
|
|
class Prefs;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
struct tr_variant;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Peer
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool client_is_choked;
|
|
|
|
bool client_is_interested;
|
|
|
|
bool is_downloading_from;
|
|
|
|
bool is_encrypted;
|
|
|
|
bool is_incoming;
|
|
|
|
bool is_uploading_to;
|
|
|
|
bool peer_is_choked;
|
|
|
|
bool peer_is_interested;
|
2017-04-19 12:04:45 +00:00
|
|
|
QString address;
|
2020-05-27 21:53:12 +00:00
|
|
|
QString client_name;
|
|
|
|
QString flags;
|
2017-04-19 12:04:45 +00:00
|
|
|
int port;
|
2020-05-27 21:53:12 +00:00
|
|
|
Speed rate_to_client;
|
|
|
|
Speed rate_to_peer;
|
2017-04-19 12:04:45 +00:00
|
|
|
double progress;
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
using PeerList = std::vector<Peer>;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2010-04-03 14:23:29 +00:00
|
|
|
struct TrackerStat
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QPixmap getFavicon() const;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
bool has_announced;
|
|
|
|
bool has_scraped;
|
|
|
|
bool is_backup;
|
|
|
|
bool last_announce_succeeded;
|
|
|
|
bool last_announce_timed_out;
|
|
|
|
bool last_scrape_succeeded;
|
|
|
|
bool last_scrape_timed_out;
|
|
|
|
int announce_state;
|
|
|
|
int download_count;
|
2017-04-19 12:04:45 +00:00
|
|
|
int id;
|
2020-05-27 21:53:12 +00:00
|
|
|
int last_announce_peer_count;
|
|
|
|
int last_announce_start_time;
|
|
|
|
int last_announce_time;
|
|
|
|
int last_scrape_start_time;
|
|
|
|
int last_scrape_time;
|
|
|
|
int leecher_count;
|
|
|
|
int next_announce_time;
|
|
|
|
int next_scrape_time;
|
|
|
|
int scrape_state;
|
|
|
|
int seeder_count;
|
2017-04-19 12:04:45 +00:00
|
|
|
int tier;
|
2020-06-24 18:28:54 +00:00
|
|
|
FaviconCache::Key favicon_key;
|
2017-04-19 12:04:45 +00:00
|
|
|
QString announce;
|
2020-05-27 21:53:12 +00:00
|
|
|
QString last_announce_result;
|
|
|
|
QString last_scrape_result;
|
2010-04-03 14:23:29 +00:00
|
|
|
};
|
|
|
|
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
using TrackerStatsList = std::vector<TrackerStat>;
|
2010-04-03 14:23:29 +00:00
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
struct TorrentFile
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
bool wanted = true;
|
|
|
|
int index = -1;
|
|
|
|
int priority = 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
QString filename;
|
2020-05-19 23:42:17 +00:00
|
|
|
uint64_t size = 0;
|
|
|
|
uint64_t have = 0;
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
Qt 6 support (#2069)
* Bump minimum Qt version to 5.6
* Switch from QRegExp to QRegularExpression
While still available, QRegExp has been moved to Qt6::Core5Compat module
and is not part of Qt6::Core.
* Use qIsEffectiveTLD instead of QUrl::topLevelDomain
The latter is not part of Qt6::Core. The former is a private utility in
Qt6::Network; using it for now, until (and if) we switch to something
non-Qt-specific.
* Use QStyle::State_Horizontal state when drawing progress bars
Although available for a long time, this state either didn't apply to
progress bars before Qt 6, or was deduced based on bar size. With Qt 6,
failing to specify it results in bad rendering.
* Don't use QStringRef (and associated methods)
While still available, QStringRef has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core. Related method (e.g.
QString::midRef) have been removed in Qt 6.
* Use Qt::ItemIsAutoTristate instead of Qt::ItemIsTristate
The latter was deprecated and replaced with the former in Qt 5.6.
* Don't use QApplication::globalStrut
This property has been deprecated in Qt 5.15 and removed in Qt 6.
* Use QImage::fromHICON instead of QtWin::fromHICON
WinExtras module (providind the latter helper) has been removed in Qt 6.
* Use QStringDecoder instead of QTextCodec
While still available, QTextCodec has been moved to Qt6::Core5Compat
module and is not part of Qt6::Core.
* Don't forward-declare QStringList
Instead of being a standalone class, its definition has changed to
QList<QString> template specialization in Qt 6.
* Use explicit (since Qt 6) QFileInfo constructor
* Use QDateTime's {to,from}SecsSinceEpoch instead of {to,from}Time_t
The latter was deprecated in Qt 5.8 and removed in Qt 6.
* Don't use QFuture<>'s operator==
It has been removed in Qt 6. Since the original issue this code was
solving was caused by future reuse, just don't reuse futures and create
new finished ones when necessary.
* Use std::vector<> instead of QVector<>
The latter has been changed to a typedef for QList<>, which might not be
what one wants, and which also changed behavior a bit leading to
compilation errors.
* Don't use + for flags, cast to int explicitly
Operator+ for enum values has been deleted in Qt 6, so using operator|
instead. Then, there's no conversion from QFlags<> to QVariant, so need
to cast to int.
* Support Qt 6 in CMake and for MSI packaging
* Remove extra (empty) CMake variable use when constructing Qt target names
* Simplify logic in tr_qt_add_translation CMake helper
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-11-03 21:20:11 +00:00
|
|
|
using FileList = std::vector<TorrentFile>;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-09-07 21:19:10 +00:00
|
|
|
class TorrentHash
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::array<uint8_t, SHA_DIGEST_LENGTH> data_ = {};
|
|
|
|
|
|
|
|
public:
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentHash()
|
|
|
|
{
|
|
|
|
}
|
2020-09-07 21:19:10 +00:00
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
explicit TorrentHash(char const* str)
|
2020-09-07 21:19:10 +00:00
|
|
|
{
|
|
|
|
tr_hex_to_sha1(data_.data(), str);
|
|
|
|
}
|
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
explicit TorrentHash(QString const& str)
|
2020-09-07 21:19:10 +00:00
|
|
|
{
|
|
|
|
tr_hex_to_sha1(data_.data(), str.toUtf8().constData());
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
bool operator==(TorrentHash const& that) const
|
2020-09-07 21:19:10 +00:00
|
|
|
{
|
|
|
|
return data_ == that.data_;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
bool operator!=(TorrentHash const& that) const
|
2020-09-07 21:19:10 +00:00
|
|
|
{
|
|
|
|
return data_ != that.data_;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
bool operator<(TorrentHash const& that) const
|
2020-09-07 21:19:10 +00:00
|
|
|
{
|
|
|
|
return data_ < that.data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString toString() const
|
|
|
|
{
|
|
|
|
char str[SHA_DIGEST_LENGTH * 2 + 1];
|
|
|
|
tr_sha1_to_hex(str, data_.data());
|
|
|
|
return QString::fromUtf8(str, SHA_DIGEST_LENGTH * 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
class Torrent : public QObject
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2014-12-11 05:11:02 +00:00
|
|
|
Q_OBJECT
|
2020-08-11 18:11:55 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Torrent)
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2017-04-20 16:02:19 +00:00
|
|
|
Torrent(Prefs const&, int id);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
int getBandwidthPriority() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return bandwidth_priority_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int id() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return id_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
QString const& name() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return name_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 14:44:40 +00:00
|
|
|
bool hasName() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return !name_.isEmpty();
|
2019-11-09 14:44:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
QString const& creator() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return creator_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
QString const& comment() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return comment_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
QString const& getPath() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return download_dir_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString getError() const;
|
|
|
|
|
2020-09-07 21:19:10 +00:00
|
|
|
TorrentHash const& hash() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-09-07 21:19:10 +00:00
|
|
|
return hash_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasError() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return error_ != TR_STAT_OK;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isDone() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return leftUntilDone() == 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isSeed() const
|
|
|
|
{
|
|
|
|
return haveVerified() >= totalSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPrivate() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return is_private_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
bool getSeedRatio(double& setmeRatio) const;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
uint64_t haveVerified() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return have_verified_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t haveUnverified() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return have_unchecked_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t desiredAvailable() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return desired_available_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t haveTotal() const
|
|
|
|
{
|
|
|
|
return haveVerified() + haveUnverified();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t totalSize() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return total_size_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t sizeWhenDone() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return size_when_done_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t leftUntilDone() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return left_until_done_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t pieceSize() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return piece_size_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasMetadata() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return metadataPercentDone() >= 1.0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pieceCount() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return piece_count_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double ratio() const
|
|
|
|
{
|
2019-11-09 14:44:40 +00:00
|
|
|
auto const u = uploadedEver();
|
|
|
|
auto const d = downloadedEver();
|
|
|
|
auto const t = totalSize();
|
|
|
|
return double(u) / (d ? d : t);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double percentComplete() const
|
|
|
|
{
|
2017-05-01 09:55:29 +00:00
|
|
|
return totalSize() != 0 ? haveTotal() / static_cast<double>(totalSize()) : 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double percentDone() const
|
|
|
|
{
|
2019-11-09 14:44:40 +00:00
|
|
|
auto const l = leftUntilDone();
|
|
|
|
auto const s = sizeWhenDone();
|
2020-11-09 03:31:02 +00:00
|
|
|
return s ? static_cast<double>(s - l) / static_cast<double>(s) : 0.0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double metadataPercentDone() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return metadata_percent_complete_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t downloadedEver() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return downloaded_ever_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t uploadedEver() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return uploaded_ever_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t failedEver() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return failed_ever_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
int compareSeedRatio(Torrent const&) const;
|
|
|
|
int compareRatio(Torrent const&) const;
|
|
|
|
int compareETA(Torrent const&) const;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
bool hasETA() const
|
|
|
|
{
|
|
|
|
return getETA() >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getETA() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return eta_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 23:31:41 +00:00
|
|
|
time_t lastActivity() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return activity_date_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 23:31:41 +00:00
|
|
|
time_t lastStarted() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return start_date_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 23:31:41 +00:00
|
|
|
time_t dateAdded() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return added_date_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 23:31:41 +00:00
|
|
|
time_t dateCreated() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return date_created_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 20:34:11 +00:00
|
|
|
time_t dateEdited() const
|
|
|
|
{
|
|
|
|
return edit_date_;
|
|
|
|
}
|
|
|
|
|
2019-11-06 23:31:41 +00:00
|
|
|
time_t manualAnnounceTime() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return manual_announce_time_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 23:31:41 +00:00
|
|
|
bool canManualAnnounceAt(time_t t) const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2019-11-06 23:31:41 +00:00
|
|
|
return isReadyToTransfer() && (manualAnnounceTime() <= t);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int peersWeAreDownloadingFrom() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return peers_sending_to_us_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int webseedsWeAreDownloadingFrom() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return webseeds_sending_to_us_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int peersWeAreUploadingTo() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return peers_getting_from_us_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isUploading() const
|
|
|
|
{
|
|
|
|
return peersWeAreUploadingTo() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int connectedPeers() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return peers_connected_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int connectedPeersAndWebseeds() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return connectedPeers() + webseedsWeAreDownloadingFrom();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
Speed const& downloadSpeed() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return download_speed_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
Speed const& uploadSpeed() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return upload_speed_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double getVerifyProgress() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return recheck_progress_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 18:28:54 +00:00
|
|
|
bool includesTracker(FaviconCache::Key const& key) const;
|
|
|
|
|
|
|
|
FaviconCache::Keys const& trackerKeys() const
|
|
|
|
{
|
|
|
|
return tracker_keys_;
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
Speed uploadLimit() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return Speed::fromKBps(upload_limit_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Speed downloadLimit() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return Speed::fromKBps(download_limit_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool uploadIsLimited() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return upload_limited_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool downloadIsLimited() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return download_limited_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool honorsSessionLimits() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return honors_session_limits_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int peerLimit() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return peer_limit_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double seedRatioLimit() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return seed_ratio_limit_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tr_ratiolimit seedRatioMode() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return static_cast<tr_ratiolimit>(seed_ratio_mode_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int seedIdleLimit() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return seed_idle_limit_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tr_idlelimit seedIdleMode() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return static_cast<tr_idlelimit>(seed_idle_mode_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
TrackerStatsList const& trackerStats() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return tracker_stats_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
PeerList const& peers() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return peers_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
FileList const& files() const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return files_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int queuePosition() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return queue_position_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isStalled() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return is_stalled_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString activityString() const;
|
|
|
|
|
|
|
|
tr_torrent_activity getActivity() const
|
|
|
|
{
|
2020-05-19 23:42:17 +00:00
|
|
|
return static_cast<tr_torrent_activity>(status_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isFinished() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return is_finished_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPaused() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_STOPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWaitingToVerify() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_CHECK_WAIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isVerifying() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_CHECK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDownloading() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_DOWNLOAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWaitingToDownload() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_DOWNLOAD_WAIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSeeding() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_SEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWaitingToSeed() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_SEED_WAIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isReadyToTransfer() const
|
|
|
|
{
|
|
|
|
return getActivity() == TR_STATUS_DOWNLOAD || getActivity() == TR_STATUS_SEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isQueued() const
|
|
|
|
{
|
|
|
|
return isWaitingToDownload() || isWaitingToSeed();
|
|
|
|
}
|
|
|
|
|
2020-09-08 16:51:33 +00:00
|
|
|
QIcon getMimeTypeIcon() const;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-23 21:11:16 +00:00
|
|
|
enum Field
|
|
|
|
{
|
|
|
|
ACTIVITY_DATE,
|
|
|
|
ADDED_DATE,
|
|
|
|
BANDWIDTH_PRIORITY,
|
|
|
|
COMMENT,
|
|
|
|
CREATOR,
|
|
|
|
DATE_CREATED,
|
|
|
|
DESIRED_AVAILABLE,
|
|
|
|
DOWNLOADED_EVER,
|
|
|
|
DOWNLOAD_DIR,
|
|
|
|
DOWNLOAD_LIMIT,
|
|
|
|
DOWNLOAD_LIMITED,
|
|
|
|
DOWNLOAD_SPEED,
|
|
|
|
EDIT_DATE,
|
|
|
|
ERROR,
|
|
|
|
ERROR_STRING,
|
|
|
|
ETA,
|
|
|
|
FAILED_EVER,
|
2020-10-13 15:33:56 +00:00
|
|
|
FILE_COUNT,
|
2020-06-23 21:11:16 +00:00
|
|
|
FILES,
|
2020-09-07 21:19:10 +00:00
|
|
|
HASH,
|
2020-06-23 21:11:16 +00:00
|
|
|
HAVE_UNCHECKED,
|
|
|
|
HAVE_VERIFIED,
|
|
|
|
HONORS_SESSION_LIMITS,
|
|
|
|
ICON,
|
|
|
|
IS_FINISHED,
|
|
|
|
IS_PRIVATE,
|
|
|
|
IS_STALLED,
|
|
|
|
LEFT_UNTIL_DONE,
|
|
|
|
MANUAL_ANNOUNCE_TIME,
|
|
|
|
METADATA_PERCENT_COMPLETE,
|
|
|
|
NAME,
|
|
|
|
PEERS,
|
|
|
|
PEERS_CONNECTED,
|
|
|
|
PEERS_GETTING_FROM_US,
|
|
|
|
PEERS_SENDING_TO_US,
|
|
|
|
PEER_LIMIT,
|
|
|
|
PERCENT_DONE,
|
|
|
|
PIECE_COUNT,
|
|
|
|
PIECE_SIZE,
|
2020-10-13 15:33:56 +00:00
|
|
|
PRIMARY_MIME_TYPE,
|
2020-06-23 21:11:16 +00:00
|
|
|
QUEUE_POSITION,
|
|
|
|
RECHECK_PROGRESS,
|
|
|
|
SEED_IDLE_LIMIT,
|
|
|
|
SEED_IDLE_MODE,
|
|
|
|
SEED_RATIO_LIMIT,
|
|
|
|
SEED_RATIO_MODE,
|
|
|
|
SIZE_WHEN_DONE,
|
|
|
|
START_DATE,
|
|
|
|
STATUS,
|
|
|
|
TOTAL_SIZE,
|
|
|
|
TRACKER_STATS,
|
|
|
|
UPLOADED_EVER,
|
|
|
|
UPLOAD_LIMIT,
|
|
|
|
UPLOAD_LIMITED,
|
|
|
|
UPLOAD_SPEED,
|
|
|
|
WEBSEEDS_SENDING_TO_US,
|
|
|
|
|
|
|
|
N_FIELDS
|
|
|
|
};
|
|
|
|
using fields_t = std::bitset<N_FIELDS>;
|
|
|
|
|
|
|
|
fields_t update(tr_quark const* keys, tr_variant const* const* values, size_t n);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private:
|
2020-05-19 23:42:17 +00:00
|
|
|
int const id_;
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
bool download_limited_ = {};
|
|
|
|
bool honors_session_limits_ = {};
|
|
|
|
bool is_finished_ = {};
|
|
|
|
bool is_private_ = {};
|
|
|
|
bool is_stalled_ = {};
|
|
|
|
bool upload_limited_ = {};
|
|
|
|
|
|
|
|
time_t activity_date_ = {};
|
|
|
|
time_t added_date_ = {};
|
|
|
|
time_t date_created_ = {};
|
|
|
|
time_t edit_date_ = {};
|
|
|
|
time_t manual_announce_time_ = {};
|
|
|
|
time_t start_date_ = {};
|
|
|
|
|
|
|
|
int bandwidth_priority_ = {};
|
|
|
|
int download_limit_ = {};
|
2020-05-19 23:42:17 +00:00
|
|
|
int error_ = {};
|
|
|
|
int eta_ = {};
|
2020-05-27 21:53:12 +00:00
|
|
|
int peer_limit_ = {};
|
|
|
|
int peers_connected_ = {};
|
|
|
|
int peers_getting_from_us_ = {};
|
|
|
|
int peers_sending_to_us_ = {};
|
|
|
|
int piece_count_ = {};
|
|
|
|
int queue_position_ = {};
|
|
|
|
int seed_idle_limit_ = {};
|
|
|
|
int seed_idle_mode_ = {};
|
|
|
|
int seed_ratio_mode_ = {};
|
2020-05-19 23:42:17 +00:00
|
|
|
int status_ = {};
|
2020-05-27 21:53:12 +00:00
|
|
|
int upload_limit_ = {};
|
|
|
|
int webseeds_sending_to_us_ = {};
|
|
|
|
|
|
|
|
uint64_t desired_available_ = {};
|
|
|
|
uint64_t downloaded_ever_ = {};
|
|
|
|
uint64_t failed_ever_ = {};
|
2020-10-13 15:33:56 +00:00
|
|
|
uint64_t file_count_ = {};
|
2020-05-27 21:53:12 +00:00
|
|
|
uint64_t have_unchecked_ = {};
|
|
|
|
uint64_t have_verified_ = {};
|
|
|
|
uint64_t left_until_done_ = {};
|
|
|
|
uint64_t piece_size_ = {};
|
|
|
|
uint64_t size_when_done_ = {};
|
|
|
|
uint64_t total_size_ = {};
|
|
|
|
uint64_t uploaded_ever_ = {};
|
|
|
|
|
|
|
|
double metadata_percent_complete_ = {};
|
|
|
|
double percent_done_ = {};
|
|
|
|
double recheck_progress_ = {};
|
|
|
|
double seed_ratio_limit_ = {};
|
2020-05-19 23:42:17 +00:00
|
|
|
|
2020-10-13 15:33:56 +00:00
|
|
|
QString primary_mime_type_;
|
2020-05-19 23:42:17 +00:00
|
|
|
QString comment_;
|
|
|
|
QString creator_;
|
2020-05-27 21:53:12 +00:00
|
|
|
QString download_dir_;
|
|
|
|
QString error_string_;
|
2020-05-19 23:42:17 +00:00
|
|
|
QString name_;
|
|
|
|
|
2020-09-08 16:51:33 +00:00
|
|
|
// mutable because it's a lazy lookup
|
2020-11-02 01:13:32 +00:00
|
|
|
mutable QIcon icon_ = IconCache::get().fileIcon();
|
2020-05-19 23:42:17 +00:00
|
|
|
|
|
|
|
PeerList peers_;
|
|
|
|
FileList files_;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-24 18:28:54 +00:00
|
|
|
FaviconCache::Keys tracker_keys_;
|
2020-05-27 21:53:12 +00:00
|
|
|
TrackerStatsList tracker_stats_;
|
2019-11-12 01:37:05 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
Speed upload_speed_;
|
|
|
|
Speed download_speed_;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-19 23:42:17 +00:00
|
|
|
Prefs const& prefs_;
|
2020-09-07 21:19:10 +00:00
|
|
|
|
|
|
|
TorrentHash hash_;
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
Q_DECLARE_METATYPE(Torrent const*)
|