Move "torrent status report" functionality out of Session class

This commit is contained in:
Chocobo1
2019-09-18 15:28:43 +08:00
parent 9968eb53b2
commit 418164bee4
3 changed files with 41 additions and 49 deletions

View File

@@ -1796,11 +1796,6 @@ QHash<InfoHash, TorrentHandle *> Session::torrents() const
return m_torrents;
}
TorrentStatusReport Session::torrentStatusReport() const
{
return m_torrentStatusReport;
}
bool Session::addTorrent(const QString &source, const AddTorrentParams &params)
{
// `source`: .torrent file path/url or magnet uri
@@ -4404,26 +4399,6 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
updatedTorrents.push_back(torrent);
}
m_torrentStatusReport = TorrentStatusReport();
for (const TorrentHandle *torrent : asConst(m_torrents)) {
if (torrent->isDownloading())
++m_torrentStatusReport.nbDownloading;
if (torrent->isUploading())
++m_torrentStatusReport.nbSeeding;
if (torrent->isCompleted())
++m_torrentStatusReport.nbCompleted;
if (torrent->isPaused())
++m_torrentStatusReport.nbPaused;
if (torrent->isResumed())
++m_torrentStatusReport.nbResumed;
if (torrent->isActive())
++m_torrentStatusReport.nbActive;
if (torrent->isInactive())
++m_torrentStatusReport.nbInactive;
if (torrent->isErrored())
++m_torrentStatusReport.nbErrored;
}
emit torrentsUpdated(updatedTorrents);
}

View File

@@ -86,18 +86,6 @@ namespace BitTorrent
class TrackerEntry;
struct CreateTorrentParams;
struct TorrentStatusReport
{
uint nbDownloading = 0;
uint nbSeeding = 0;
uint nbCompleted = 0;
uint nbActive = 0;
uint nbInactive = 0;
uint nbPaused = 0;
uint nbResumed = 0;
uint nbErrored = 0;
};
class SessionSettingsEnums
{
Q_GADGET
@@ -395,7 +383,6 @@ namespace BitTorrent
void startUpTorrents();
TorrentHandle *findTorrent(const InfoHash &hash) const;
QHash<InfoHash, TorrentHandle *> torrents() const;
TorrentStatusReport torrentStatusReport() const;
bool hasActiveTorrents() const;
bool hasUnfinishedTorrents() const;
bool hasRunningSeed() const;
@@ -694,7 +681,6 @@ namespace BitTorrent
QHash<InfoHash, CreateTorrentParams> m_addingTorrents;
QHash<QString, AddTorrentParams> m_downloadedTorrents;
QHash<InfoHash, RemovingTorrentData> m_removingTorrents;
TorrentStatusReport m_torrentStatusReport;
QStringMap m_categories;
QSet<QString> m_tags;