mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 21:14:33 +00:00
Merge pull request #11251 from Chocobo1/stats
Move "torrent status report" functionality out of Session class
This commit is contained in:
commit
50e0b2ab15
@ -1796,11 +1796,6 @@ QHash<InfoHash, TorrentHandle *> Session::torrents() const
|
|||||||
return m_torrents;
|
return m_torrents;
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentStatusReport Session::torrentStatusReport() const
|
|
||||||
{
|
|
||||||
return m_torrentStatusReport;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms)
|
bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms)
|
||||||
{
|
{
|
||||||
// `source`: .torrent file path/url or magnet uri
|
// `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);
|
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);
|
emit torrentsUpdated(updatedTorrents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,18 +86,6 @@ namespace BitTorrent
|
|||||||
class TrackerEntry;
|
class TrackerEntry;
|
||||||
struct CreateTorrentParams;
|
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
|
class SessionSettingsEnums
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
@ -395,7 +383,6 @@ namespace BitTorrent
|
|||||||
void startUpTorrents();
|
void startUpTorrents();
|
||||||
TorrentHandle *findTorrent(const InfoHash &hash) const;
|
TorrentHandle *findTorrent(const InfoHash &hash) const;
|
||||||
QHash<InfoHash, TorrentHandle *> torrents() const;
|
QHash<InfoHash, TorrentHandle *> torrents() const;
|
||||||
TorrentStatusReport torrentStatusReport() const;
|
|
||||||
bool hasActiveTorrents() const;
|
bool hasActiveTorrents() const;
|
||||||
bool hasUnfinishedTorrents() const;
|
bool hasUnfinishedTorrents() const;
|
||||||
bool hasRunningSeed() const;
|
bool hasRunningSeed() const;
|
||||||
@ -449,43 +436,42 @@ namespace BitTorrent
|
|||||||
void handleTorrentTrackerError(TorrentHandle *const torrent, const QString &trackerUrl);
|
void handleTorrentTrackerError(TorrentHandle *const torrent, const QString &trackerUrl);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void statsUpdated();
|
|
||||||
void torrentsUpdated(const QVector<BitTorrent::TorrentHandle *> &torrents);
|
|
||||||
void addTorrentFailed(const QString &error);
|
void addTorrentFailed(const QString &error);
|
||||||
void torrentAdded(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentNew(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentPaused(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentResumed(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentFinishedChecking(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentSavePathChanged(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentCategoryChanged(BitTorrent::TorrentHandle *const torrent, const QString &oldCategory);
|
|
||||||
void torrentTagAdded(TorrentHandle *const torrent, const QString &tag);
|
|
||||||
void torrentTagRemoved(TorrentHandle *const torrent, const QString &tag);
|
|
||||||
void torrentSavingModeChanged(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void allTorrentsFinished();
|
void allTorrentsFinished();
|
||||||
void metadataLoaded(const BitTorrent::TorrentInfo &info);
|
|
||||||
void torrentMetadataLoaded(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void fullDiskError(BitTorrent::TorrentHandle *const torrent, const QString &msg);
|
|
||||||
void trackerSuccess(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
|
||||||
void trackerWarning(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
|
||||||
void trackerError(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
|
||||||
void trackerAuthenticationRequired(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void recursiveTorrentDownloadPossible(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void speedLimitModeChanged(bool alternative);
|
|
||||||
void IPFilterParsed(bool error, int ruleCount);
|
|
||||||
void trackersAdded(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
|
||||||
void trackersRemoved(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
|
||||||
void trackersChanged(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void trackerlessStateChanged(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
|
||||||
void downloadFromUrlFailed(const QString &url, const QString &reason);
|
|
||||||
void downloadFromUrlFinished(const QString &url);
|
|
||||||
void categoryAdded(const QString &categoryName);
|
void categoryAdded(const QString &categoryName);
|
||||||
void categoryRemoved(const QString &categoryName);
|
void categoryRemoved(const QString &categoryName);
|
||||||
|
void downloadFromUrlFailed(const QString &url, const QString &reason);
|
||||||
|
void downloadFromUrlFinished(const QString &url);
|
||||||
|
void fullDiskError(BitTorrent::TorrentHandle *const torrent, const QString &msg);
|
||||||
|
void IPFilterParsed(bool error, int ruleCount);
|
||||||
|
void metadataLoaded(const BitTorrent::TorrentInfo &info);
|
||||||
|
void recursiveTorrentDownloadPossible(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void speedLimitModeChanged(bool alternative);
|
||||||
|
void statsUpdated();
|
||||||
void subcategoriesSupportChanged();
|
void subcategoriesSupportChanged();
|
||||||
void tagAdded(const QString &tag);
|
void tagAdded(const QString &tag);
|
||||||
void tagRemoved(const QString &tag);
|
void tagRemoved(const QString &tag);
|
||||||
|
void torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentAdded(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentCategoryChanged(BitTorrent::TorrentHandle *const torrent, const QString &oldCategory);
|
||||||
|
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentFinishedChecking(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentMetadataLoaded(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentNew(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentPaused(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentResumed(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentSavePathChanged(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentSavingModeChanged(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void torrentsUpdated(const QVector<BitTorrent::TorrentHandle *> &torrents);
|
||||||
|
void torrentTagAdded(TorrentHandle *const torrent, const QString &tag);
|
||||||
|
void torrentTagRemoved(TorrentHandle *const torrent, const QString &tag);
|
||||||
|
void trackerError(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
||||||
|
void trackerlessStateChanged(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
||||||
|
void trackersAdded(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
||||||
|
void trackersChanged(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void trackersRemoved(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
||||||
|
void trackerSuccess(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
||||||
|
void trackerWarning(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void configureDeferred();
|
void configureDeferred();
|
||||||
@ -695,7 +681,6 @@ namespace BitTorrent
|
|||||||
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;
|
||||||
TorrentStatusReport m_torrentStatusReport;
|
|
||||||
QStringMap m_categories;
|
QStringMap m_categories;
|
||||||
QSet<QString> m_tags;
|
QSet<QString> m_tags;
|
||||||
|
|
||||||
|
@ -146,8 +146,12 @@ void BaseFilterWidget::toggleFilter(bool checked)
|
|||||||
StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *transferList)
|
StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *transferList)
|
||||||
: BaseFilterWidget(parent, transferList)
|
: BaseFilterWidget(parent, transferList)
|
||||||
{
|
{
|
||||||
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentAdded
|
||||||
|
, this, &StatusFilterWidget::updateTorrentNumbers);
|
||||||
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated
|
||||||
, this, &StatusFilterWidget::updateTorrentNumbers);
|
, this, &StatusFilterWidget::updateTorrentNumbers);
|
||||||
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentAboutToBeRemoved
|
||||||
|
, this, &StatusFilterWidget::updateTorrentNumbers);
|
||||||
|
|
||||||
// Add status filters
|
// Add status filters
|
||||||
auto *all = new QListWidgetItem(this);
|
auto *all = new QListWidgetItem(this);
|
||||||
@ -190,17 +194,44 @@ StatusFilterWidget::~StatusFilterWidget()
|
|||||||
|
|
||||||
void StatusFilterWidget::updateTorrentNumbers()
|
void StatusFilterWidget::updateTorrentNumbers()
|
||||||
{
|
{
|
||||||
const BitTorrent::TorrentStatusReport report = BitTorrent::Session::instance()->torrentStatusReport();
|
int nbDownloading = 0;
|
||||||
|
int nbSeeding = 0;
|
||||||
|
int nbCompleted = 0;
|
||||||
|
int nbResumed = 0;
|
||||||
|
int nbPaused = 0;
|
||||||
|
int nbActive = 0;
|
||||||
|
int nbInactive = 0;
|
||||||
|
int nbErrored = 0;
|
||||||
|
|
||||||
item(TorrentFilter::All)->setData(Qt::DisplayRole, tr("All (%1)").arg(report.nbActive + report.nbInactive));
|
const QHash<BitTorrent::InfoHash, BitTorrent::TorrentHandle *> torrents = BitTorrent::Session::instance()->torrents();
|
||||||
item(TorrentFilter::Downloading)->setData(Qt::DisplayRole, tr("Downloading (%1)").arg(report.nbDownloading));
|
for (const BitTorrent::TorrentHandle *torrent : torrents) {
|
||||||
item(TorrentFilter::Seeding)->setData(Qt::DisplayRole, tr("Seeding (%1)").arg(report.nbSeeding));
|
if (torrent->isDownloading())
|
||||||
item(TorrentFilter::Completed)->setData(Qt::DisplayRole, tr("Completed (%1)").arg(report.nbCompleted));
|
++nbDownloading;
|
||||||
item(TorrentFilter::Paused)->setData(Qt::DisplayRole, tr("Paused (%1)").arg(report.nbPaused));
|
if (torrent->isUploading())
|
||||||
item(TorrentFilter::Resumed)->setData(Qt::DisplayRole, tr("Resumed (%1)").arg(report.nbResumed));
|
++nbSeeding;
|
||||||
item(TorrentFilter::Active)->setData(Qt::DisplayRole, tr("Active (%1)").arg(report.nbActive));
|
if (torrent->isCompleted())
|
||||||
item(TorrentFilter::Inactive)->setData(Qt::DisplayRole, tr("Inactive (%1)").arg(report.nbInactive));
|
++nbCompleted;
|
||||||
item(TorrentFilter::Errored)->setData(Qt::DisplayRole, tr("Errored (%1)").arg(report.nbErrored));
|
if (torrent->isResumed())
|
||||||
|
++nbResumed;
|
||||||
|
if (torrent->isPaused())
|
||||||
|
++nbPaused;
|
||||||
|
if (torrent->isActive())
|
||||||
|
++nbActive;
|
||||||
|
if (torrent->isInactive())
|
||||||
|
++nbInactive;
|
||||||
|
if (torrent->isErrored())
|
||||||
|
++nbErrored;
|
||||||
|
}
|
||||||
|
|
||||||
|
item(TorrentFilter::All)->setData(Qt::DisplayRole, tr("All (%1)").arg(torrents.count()));
|
||||||
|
item(TorrentFilter::Downloading)->setData(Qt::DisplayRole, tr("Downloading (%1)").arg(nbDownloading));
|
||||||
|
item(TorrentFilter::Seeding)->setData(Qt::DisplayRole, tr("Seeding (%1)").arg(nbSeeding));
|
||||||
|
item(TorrentFilter::Completed)->setData(Qt::DisplayRole, tr("Completed (%1)").arg(nbCompleted));
|
||||||
|
item(TorrentFilter::Resumed)->setData(Qt::DisplayRole, tr("Resumed (%1)").arg(nbResumed));
|
||||||
|
item(TorrentFilter::Paused)->setData(Qt::DisplayRole, tr("Paused (%1)").arg(nbPaused));
|
||||||
|
item(TorrentFilter::Active)->setData(Qt::DisplayRole, tr("Active (%1)").arg(nbActive));
|
||||||
|
item(TorrentFilter::Inactive)->setData(Qt::DisplayRole, tr("Inactive (%1)").arg(nbInactive));
|
||||||
|
item(TorrentFilter::Errored)->setData(Qt::DisplayRole, tr("Errored (%1)").arg(nbErrored));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusFilterWidget::showMenu(const QPoint &) {}
|
void StatusFilterWidget::showMenu(const QPoint &) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user