qBittorrent
serialize_torrent.cpp File Reference
#include "serialize_torrent.h"
#include <QDateTime>
#include <QVector>
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/torrent.h"
#include "base/bittorrent/trackerentry.h"
#include "base/tagset.h"
#include "base/utils/fs.h"
Include dependency graph for serialize_torrent.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{serialize_torrent.cpp}
 

Functions

QString anonymous_namespace{serialize_torrent.cpp}::torrentStateToString (const BitTorrent::TorrentState state)
 
QVariantMap serialize (const BitTorrent::Torrent &torrent)
 

Function Documentation

◆ serialize()

QVariantMap serialize ( const BitTorrent::Torrent torrent)

Definition at line 88 of file serialize_torrent.cpp.

89 {
90  const auto adjustQueuePosition = [](const int position) -> int
91  {
92  return (position < 0) ? 0 : (position + 1);
93  };
94 
95  const auto adjustRatio = [](const qreal ratio) -> qreal
96  {
97  return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
98  };
99 
100  const auto getLastActivityTime = [&torrent]() -> qlonglong
101  {
102  const qlonglong timeSinceActivity = torrent.timeSinceActivity();
103  return (timeSinceActivity < 0)
104  ? torrent.addedTime().toSecsSinceEpoch()
105  : (QDateTime::currentDateTime().toSecsSinceEpoch() - timeSinceActivity);
106  };
107 
108  return {
109  {KEY_TORRENT_ID, torrent.id().toString()},
110  {KEY_TORRENT_INFOHASHV1, torrent.infoHash().v1().toString()},
111  {KEY_TORRENT_INFOHASHV2, torrent.infoHash().v2().toString()},
112  {KEY_TORRENT_NAME, torrent.name()},
114  {KEY_TORRENT_SIZE, torrent.wantedSize()},
115  {KEY_TORRENT_PROGRESS, torrent.progress()},
118  {KEY_TORRENT_QUEUE_POSITION, adjustQueuePosition(torrent.queuePosition())},
119  {KEY_TORRENT_SEEDS, torrent.seedsCount()},
121  {KEY_TORRENT_LEECHS, torrent.leechsCount()},
123 
125  {KEY_TORRENT_ETA, torrent.eta()},
128 
129  {KEY_TORRENT_CATEGORY, torrent.category()},
130  {KEY_TORRENT_TAGS, torrent.tags().join(QLatin1String(", "))},
132  {KEY_TORRENT_FORCE_START, torrent.isForced()},
136  {KEY_TORRENT_ADDED_ON, torrent.addedTime().toSecsSinceEpoch()},
137  {KEY_TORRENT_COMPLETION_ON, torrent.completedTime().toSecsSinceEpoch()},
138  {KEY_TORRENT_TRACKER, torrent.currentTracker()},
139  {KEY_TORRENT_TRACKERS_COUNT, torrent.trackers().size()},
140  {KEY_TORRENT_DL_LIMIT, torrent.downloadLimit()},
141  {KEY_TORRENT_UP_LIMIT, torrent.uploadLimit()},
148  {KEY_TORRENT_MAX_RATIO, torrent.maxRatio()},
150  {KEY_TORRENT_RATIO, adjustRatio(torrent.realRatio())},
151  {KEY_TORRENT_RATIO_LIMIT, torrent.ratioLimit()},
153  {KEY_TORRENT_LAST_SEEN_COMPLETE_TIME, torrent.lastSeenComplete().toSecsSinceEpoch()},
155  {KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
157  {KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()},
159 
160  {KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
161  };
162 }
SHA1Hash v1() const
Definition: infohash.cpp:44
SHA256Hash v2() const
Definition: infohash.cpp:53
virtual qlonglong totalSize() const =0
virtual qreal distributedCopies() const =0
virtual int uploadPayloadRate() const =0
virtual int seedsCount() const =0
virtual int downloadLimit() const =0
TorrentID id() const
Definition: torrent.cpp:54
virtual TagSet tags() const =0
virtual qreal ratioLimit() const =0
virtual bool hasFirstLastPiecePriority() const =0
virtual QString createMagnetURI() const =0
virtual qlonglong totalUpload() const =0
virtual QString currentTracker() const =0
virtual int maxSeedingTime() const =0
virtual QString category() const =0
virtual qlonglong activeTime() const =0
virtual qlonglong totalPayloadDownload() const =0
virtual InfoHash infoHash() const =0
virtual qlonglong finishedTime() const =0
virtual int uploadLimit() const =0
qlonglong remainingSize() const
Definition: torrent.cpp:64
virtual bool superSeeding() const =0
virtual qlonglong completedSize() const =0
virtual int totalSeedsCount() const =0
virtual TorrentState state() const =0
virtual qlonglong totalDownload() const =0
virtual QString savePath() const =0
virtual qreal realRatio() const =0
virtual qreal maxRatio() const =0
virtual QString downloadPath() const =0
virtual int seedingTimeLimit() const =0
virtual int queuePosition() const =0
virtual QVector< TrackerEntry > trackers() const =0
virtual QDateTime addedTime() const =0
virtual bool isAutoTMMEnabled() const =0
virtual qlonglong totalPayloadUpload() const =0
virtual QDateTime completedTime() const =0
virtual QDateTime lastSeenComplete() const =0
virtual bool isForced() const =0
virtual int leechsCount() const =0
virtual qreal progress() const =0
virtual qlonglong timeSinceActivity() const =0
virtual qlonglong eta() const =0
virtual bool isSequentialDownload() const =0
static const qreal MAX_RATIO
Definition: torrent.h:110
virtual qlonglong wantedSize() const =0
virtual int downloadPayloadRate() const =0
virtual int totalLeechersCount() const =0
virtual QString name() const =0
virtual QString contentPath() const =0
QString toString() const
Definition: digest32.h:85
QString join(const QString &separator) const
Definition: orderedset.h:80
QString toNativePath(const QString &path)
Definition: fs.cpp:64
QString torrentStateToString(const BitTorrent::TorrentState state)
const char KEY_TORRENT_LAST_SEEN_COMPLETE_TIME[]
const char KEY_TORRENT_AMOUNT_UPLOADED[]
const char KEY_TORRENT_AMOUNT_DOWNLOADED[]
const char KEY_TORRENT_INFOHASHV1[]
const char KEY_TORRENT_AMOUNT_COMPLETED[]
const char KEY_TORRENT_AVAILABILITY[]
const char KEY_TORRENT_MAX_RATIO[]
const char KEY_TORRENT_AUTO_TORRENT_MANAGEMENT[]
const char KEY_TORRENT_SUPER_SEEDING[]
const char KEY_TORRENT_PROGRESS[]
const char KEY_TORRENT_INFOHASHV2[]
const char KEY_TORRENT_COMPLETION_ON[]
const char KEY_TORRENT_SEEDING_TIME_LIMIT[]
const char KEY_TORRENT_QUEUE_POSITION[]
const char KEY_TORRENT_TOTAL_SIZE[]
const char KEY_TORRENT_ADDED_ON[]
const char KEY_TORRENT_DL_LIMIT[]
const char KEY_TORRENT_TAGS[]
const char KEY_TORRENT_DOWNLOAD_PATH[]
const char KEY_TORRENT_NUM_COMPLETE[]
const char KEY_TORRENT_RATIO_LIMIT[]
const char KEY_TORRENT_TRACKERS_COUNT[]
const char KEY_TORRENT_FORCE_START[]
const char KEY_TORRENT_UP_LIMIT[]
const char KEY_TORRENT_LAST_ACTIVITY_TIME[]
const char KEY_TORRENT_STATE[]
const char KEY_TORRENT_SAVE_PATH[]
const char KEY_TORRENT_NUM_INCOMPLETE[]
const char KEY_TORRENT_ID[]
const char KEY_TORRENT_SEEDS[]
const char KEY_TORRENT_MAX_SEEDING_TIME[]
const char KEY_TORRENT_NAME[]
const char KEY_TORRENT_ETA[]
const char KEY_TORRENT_CATEGORY[]
const char KEY_TORRENT_SEEDING_TIME[]
const char KEY_TORRENT_DLSPEED[]
const char KEY_TORRENT_CONTENT_PATH[]
const char KEY_TORRENT_SEQUENTIAL_DOWNLOAD[]
const char KEY_TORRENT_RATIO[]
const char KEY_TORRENT_AMOUNT_LEFT[]
const char KEY_TORRENT_TRACKER[]
const char KEY_TORRENT_AMOUNT_UPLOADED_SESSION[]
const char KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION[]
const char KEY_TORRENT_TIME_ACTIVE[]
const char KEY_TORRENT_LEECHS[]
const char KEY_TORRENT_SIZE[]
const char KEY_TORRENT_UPSPEED[]
const char KEY_TORRENT_FIRST_LAST_PIECE_PRIO[]
const char KEY_TORRENT_MAGNET_URI[]

References BitTorrent::Torrent::activeTime(), BitTorrent::Torrent::addedTime(), BitTorrent::Torrent::category(), BitTorrent::Torrent::completedSize(), BitTorrent::Torrent::completedTime(), BitTorrent::Torrent::contentPath(), BitTorrent::Torrent::createMagnetURI(), BitTorrent::Torrent::currentTracker(), BitTorrent::Torrent::distributedCopies(), BitTorrent::Torrent::downloadLimit(), BitTorrent::Torrent::downloadPath(), BitTorrent::Torrent::downloadPayloadRate(), BitTorrent::Torrent::eta(), BitTorrent::Torrent::finishedTime(), BitTorrent::Torrent::hasFirstLastPiecePriority(), BitTorrent::Torrent::id(), BitTorrent::Torrent::infoHash(), BitTorrent::Torrent::isAutoTMMEnabled(), BitTorrent::Torrent::isForced(), BitTorrent::Torrent::isSequentialDownload(), OrderedSet< T, Compare >::join(), KEY_TORRENT_ADDED_ON, KEY_TORRENT_AMOUNT_COMPLETED, KEY_TORRENT_AMOUNT_DOWNLOADED, KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION, KEY_TORRENT_AMOUNT_LEFT, KEY_TORRENT_AMOUNT_UPLOADED, KEY_TORRENT_AMOUNT_UPLOADED_SESSION, KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, KEY_TORRENT_AVAILABILITY, KEY_TORRENT_CATEGORY, KEY_TORRENT_COMPLETION_ON, KEY_TORRENT_CONTENT_PATH, KEY_TORRENT_DL_LIMIT, KEY_TORRENT_DLSPEED, KEY_TORRENT_DOWNLOAD_PATH, KEY_TORRENT_ETA, KEY_TORRENT_FIRST_LAST_PIECE_PRIO, KEY_TORRENT_FORCE_START, KEY_TORRENT_ID, KEY_TORRENT_INFOHASHV1, KEY_TORRENT_INFOHASHV2, KEY_TORRENT_LAST_ACTIVITY_TIME, KEY_TORRENT_LAST_SEEN_COMPLETE_TIME, KEY_TORRENT_LEECHS, KEY_TORRENT_MAGNET_URI, KEY_TORRENT_MAX_RATIO, KEY_TORRENT_MAX_SEEDING_TIME, KEY_TORRENT_NAME, KEY_TORRENT_NUM_COMPLETE, KEY_TORRENT_NUM_INCOMPLETE, KEY_TORRENT_PROGRESS, KEY_TORRENT_QUEUE_POSITION, KEY_TORRENT_RATIO, KEY_TORRENT_RATIO_LIMIT, KEY_TORRENT_SAVE_PATH, KEY_TORRENT_SEEDING_TIME, KEY_TORRENT_SEEDING_TIME_LIMIT, KEY_TORRENT_SEEDS, KEY_TORRENT_SEQUENTIAL_DOWNLOAD, KEY_TORRENT_SIZE, KEY_TORRENT_STATE, KEY_TORRENT_SUPER_SEEDING, KEY_TORRENT_TAGS, KEY_TORRENT_TIME_ACTIVE, KEY_TORRENT_TOTAL_SIZE, KEY_TORRENT_TRACKER, KEY_TORRENT_TRACKERS_COUNT, KEY_TORRENT_UP_LIMIT, KEY_TORRENT_UPSPEED, BitTorrent::Torrent::lastSeenComplete(), BitTorrent::Torrent::leechsCount(), BitTorrent::Torrent::MAX_RATIO, BitTorrent::Torrent::maxRatio(), BitTorrent::Torrent::maxSeedingTime(), BitTorrent::Torrent::name(), BitTorrent::Torrent::progress(), BitTorrent::Torrent::queuePosition(), BitTorrent::Torrent::ratioLimit(), BitTorrent::Torrent::realRatio(), BitTorrent::Torrent::remainingSize(), BitTorrent::Torrent::savePath(), BitTorrent::Torrent::seedingTimeLimit(), BitTorrent::Torrent::seedsCount(), BitTorrent::Torrent::state(), BitTorrent::Torrent::superSeeding(), BitTorrent::Torrent::tags(), BitTorrent::Torrent::timeSinceActivity(), Utils::Fs::toNativePath(), anonymous_namespace{serialize_torrent.cpp}::torrentStateToString(), Digest32< N >::toString(), BitTorrent::Torrent::totalDownload(), BitTorrent::Torrent::totalLeechersCount(), BitTorrent::Torrent::totalPayloadDownload(), BitTorrent::Torrent::totalPayloadUpload(), BitTorrent::Torrent::totalSeedsCount(), BitTorrent::Torrent::totalSize(), BitTorrent::Torrent::totalUpload(), BitTorrent::Torrent::trackers(), BitTorrent::Torrent::uploadLimit(), BitTorrent::Torrent::uploadPayloadRate(), BitTorrent::InfoHash::v1(), BitTorrent::InfoHash::v2(), and BitTorrent::Torrent::wantedSize().

Referenced by TorrentsController::infoAction(), SyncController::maindataAction(), and anonymous_namespace{settingsstorage.cpp}::TransactionalSettings::write().

Here is the caller graph for this function: