mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08:00
Merge pull request #4062 from glassez/speedup
Some TransferListWidget speedup.
This commit is contained in:
commit
84f6a82d98
@ -112,19 +112,6 @@ AddTorrentParams::AddTorrentParams()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// TorrentStatusReport
|
|
||||||
|
|
||||||
TorrentStatusReport::TorrentStatusReport()
|
|
||||||
: nbDownloading(0)
|
|
||||||
, nbSeeding(0)
|
|
||||||
, nbCompleted(0)
|
|
||||||
, nbActive(0)
|
|
||||||
, nbInactive(0)
|
|
||||||
, nbPaused(0)
|
|
||||||
, nbResumed(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Session
|
// Session
|
||||||
|
|
||||||
Session *Session::m_instance = 0;
|
Session *Session::m_instance = 0;
|
||||||
@ -989,6 +976,11 @@ QHash<InfoHash, TorrentHandle *> Session::torrents() const
|
|||||||
return m_torrents;
|
return m_torrents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TorrentStatusReport Session::torrentStatusReport() const
|
||||||
|
{
|
||||||
|
return m_torrentStatusReport;
|
||||||
|
}
|
||||||
|
|
||||||
// source - .torrent file path/url or magnet uri (hash for preloaded torrent)
|
// source - .torrent file path/url or magnet uri (hash for preloaded torrent)
|
||||||
bool Session::addTorrent(QString source, const AddTorrentParams ¶ms)
|
bool Session::addTorrent(QString source, const AddTorrentParams ¶ms)
|
||||||
{
|
{
|
||||||
@ -2375,31 +2367,29 @@ void Session::handleStateUpdateAlert(libt::state_update_alert *p)
|
|||||||
{
|
{
|
||||||
foreach (const libt::torrent_status &status, p->status) {
|
foreach (const libt::torrent_status &status, p->status) {
|
||||||
TorrentHandle *const torrent = m_torrents.value(status.info_hash);
|
TorrentHandle *const torrent = m_torrents.value(status.info_hash);
|
||||||
if (torrent) {
|
if (torrent)
|
||||||
torrent->handleStateUpdate(status);
|
torrent->handleStateUpdate(status);
|
||||||
emit torrentStatusUpdated(torrent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentStatusReport torrentStatusReport;
|
m_torrentStatusReport = TorrentStatusReport();
|
||||||
foreach (TorrentHandle *const torrent, m_torrents) {
|
foreach (TorrentHandle *const torrent, m_torrents) {
|
||||||
if (torrent->isDownloading())
|
if (torrent->isDownloading())
|
||||||
++torrentStatusReport.nbDownloading;
|
++m_torrentStatusReport.nbDownloading;
|
||||||
if (torrent->isUploading())
|
if (torrent->isUploading())
|
||||||
++torrentStatusReport.nbSeeding;
|
++m_torrentStatusReport.nbSeeding;
|
||||||
if (torrent->isCompleted())
|
if (torrent->isCompleted())
|
||||||
++torrentStatusReport.nbCompleted;
|
++m_torrentStatusReport.nbCompleted;
|
||||||
if (torrent->isPaused())
|
if (torrent->isPaused())
|
||||||
++torrentStatusReport.nbPaused;
|
++m_torrentStatusReport.nbPaused;
|
||||||
if (torrent->isResumed())
|
if (torrent->isResumed())
|
||||||
++torrentStatusReport.nbResumed;
|
++m_torrentStatusReport.nbResumed;
|
||||||
if (torrent->isActive())
|
if (torrent->isActive())
|
||||||
++torrentStatusReport.nbActive;
|
++m_torrentStatusReport.nbActive;
|
||||||
if (torrent->isInactive())
|
if (torrent->isInactive())
|
||||||
++torrentStatusReport.nbInactive;
|
++m_torrentStatusReport.nbInactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit torrentsUpdated(torrentStatusReport);
|
emit torrentsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readFile(const QString &path, QByteArray &buf)
|
bool readFile(const QString &path, QByteArray &buf)
|
||||||
|
@ -127,15 +127,13 @@ namespace BitTorrent
|
|||||||
|
|
||||||
struct TorrentStatusReport
|
struct TorrentStatusReport
|
||||||
{
|
{
|
||||||
uint nbDownloading;
|
uint nbDownloading = 0;
|
||||||
uint nbSeeding;
|
uint nbSeeding = 0;
|
||||||
uint nbCompleted;
|
uint nbCompleted = 0;
|
||||||
uint nbActive;
|
uint nbActive = 0;
|
||||||
uint nbInactive;
|
uint nbInactive = 0;
|
||||||
uint nbPaused;
|
uint nbPaused = 0;
|
||||||
uint nbResumed;
|
uint nbResumed = 0;
|
||||||
|
|
||||||
TorrentStatusReport();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Session : public QObject
|
class Session : public QObject
|
||||||
@ -161,6 +159,7 @@ namespace BitTorrent
|
|||||||
|
|
||||||
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;
|
||||||
SessionStatus status() const;
|
SessionStatus status() const;
|
||||||
@ -214,11 +213,10 @@ namespace BitTorrent
|
|||||||
void handleTorrentTrackerAuthenticationRequired(TorrentHandle *const torrent, const QString &trackerUrl);
|
void handleTorrentTrackerAuthenticationRequired(TorrentHandle *const torrent, const QString &trackerUrl);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void torrentsUpdated(const BitTorrent::TorrentStatusReport &torrentStatusReport = BitTorrent::TorrentStatusReport());
|
void torrentsUpdated();
|
||||||
void addTorrentFailed(const QString &error);
|
void addTorrentFailed(const QString &error);
|
||||||
void torrentAdded(BitTorrent::TorrentHandle *const torrent);
|
void torrentAdded(BitTorrent::TorrentHandle *const torrent);
|
||||||
void torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
|
void torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
|
||||||
void torrentStatusUpdated(BitTorrent::TorrentHandle *const torrent);
|
|
||||||
void torrentPaused(BitTorrent::TorrentHandle *const torrent);
|
void torrentPaused(BitTorrent::TorrentHandle *const torrent);
|
||||||
void torrentResumed(BitTorrent::TorrentHandle *const torrent);
|
void torrentResumed(BitTorrent::TorrentHandle *const torrent);
|
||||||
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
|
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
|
||||||
@ -362,6 +360,7 @@ namespace BitTorrent
|
|||||||
QHash<InfoHash, TorrentHandle *> m_torrents;
|
QHash<InfoHash, TorrentHandle *> m_torrents;
|
||||||
QHash<InfoHash, AddTorrentData> m_addingTorrents;
|
QHash<InfoHash, AddTorrentData> m_addingTorrents;
|
||||||
QHash<QString, AddTorrentParams> m_downloadedTorrents;
|
QHash<QString, AddTorrentParams> m_downloadedTorrents;
|
||||||
|
TorrentStatusReport m_torrentStatusReport;
|
||||||
|
|
||||||
QMutex m_alertsMutex;
|
QMutex m_alertsMutex;
|
||||||
QWaitCondition m_alertsWaitCondition;
|
QWaitCondition m_alertsWaitCondition;
|
||||||
|
@ -67,7 +67,7 @@ TorrentModel::TorrentModel(QObject *parent)
|
|||||||
// Listen for torrent changes
|
// Listen for torrent changes
|
||||||
connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const)), SLOT(addTorrent(BitTorrent::TorrentHandle *const)));
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const)), SLOT(addTorrent(BitTorrent::TorrentHandle *const)));
|
||||||
connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)));
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)));
|
||||||
connect(BitTorrent::Session::instance(), SIGNAL(torrentStatusUpdated(BitTorrent::TorrentHandle *const)), this, SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentsUpdated()), SLOT(handleTorrentsUpdated()));
|
||||||
|
|
||||||
connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
||||||
connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
||||||
@ -307,6 +307,11 @@ void TorrentModel::handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const t
|
|||||||
emit dataChanged(index(row, 0), index(row, columnCount() - 1));
|
emit dataChanged(index(row, 0), index(row, columnCount() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TorrentModel::handleTorrentsUpdated()
|
||||||
|
{
|
||||||
|
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
|
|
||||||
QIcon getIconByState(BitTorrent::TorrentState state)
|
QIcon getIconByState(BitTorrent::TorrentState state)
|
||||||
|
@ -97,6 +97,7 @@ private slots:
|
|||||||
void addTorrent(BitTorrent::TorrentHandle *const torrent);
|
void addTorrent(BitTorrent::TorrentHandle *const torrent);
|
||||||
void handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
|
void handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
|
||||||
void handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const torrent);
|
void handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const torrent);
|
||||||
|
void handleTorrentsUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<BitTorrent::TorrentHandle *> m_torrents;
|
QList<BitTorrent::TorrentHandle *> m_torrents;
|
||||||
|
@ -110,7 +110,7 @@ void FiltersBase::toggleFilter(bool checked)
|
|||||||
StatusFiltersWidget::StatusFiltersWidget(QWidget *parent, TransferListWidget *transferList)
|
StatusFiltersWidget::StatusFiltersWidget(QWidget *parent, TransferListWidget *transferList)
|
||||||
: FiltersBase(parent, transferList)
|
: FiltersBase(parent, transferList)
|
||||||
{
|
{
|
||||||
connect(BitTorrent::Session::instance(), SIGNAL(torrentsUpdated(const BitTorrent::TorrentStatusReport &)), SLOT(updateTorrentNumbers(const BitTorrent::TorrentStatusReport &)));
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentsUpdated()), SLOT(updateTorrentNumbers()));
|
||||||
|
|
||||||
// Add status filters
|
// Add status filters
|
||||||
QListWidgetItem *all = new QListWidgetItem(this);
|
QListWidgetItem *all = new QListWidgetItem(this);
|
||||||
@ -148,8 +148,10 @@ StatusFiltersWidget::~StatusFiltersWidget()
|
|||||||
Preferences::instance()->setTransSelFilter(currentRow());
|
Preferences::instance()->setTransSelFilter(currentRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusFiltersWidget::updateTorrentNumbers(const BitTorrent::TorrentStatusReport &report)
|
void StatusFiltersWidget::updateTorrentNumbers()
|
||||||
{
|
{
|
||||||
|
auto report = BitTorrent::Session::instance()->torrentStatusReport();
|
||||||
|
|
||||||
item(TorrentFilter::All)->setData(Qt::DisplayRole, QVariant(tr("All (%1)").arg(report.nbActive + report.nbInactive)));
|
item(TorrentFilter::All)->setData(Qt::DisplayRole, QVariant(tr("All (%1)").arg(report.nbActive + report.nbInactive)));
|
||||||
item(TorrentFilter::Downloading)->setData(Qt::DisplayRole, QVariant(tr("Downloading (%1)").arg(report.nbDownloading)));
|
item(TorrentFilter::Downloading)->setData(Qt::DisplayRole, QVariant(tr("Downloading (%1)").arg(report.nbDownloading)));
|
||||||
item(TorrentFilter::Seeding)->setData(Qt::DisplayRole, QVariant(tr("Seeding (%1)").arg(report.nbSeeding)));
|
item(TorrentFilter::Seeding)->setData(Qt::DisplayRole, QVariant(tr("Seeding (%1)").arg(report.nbSeeding)));
|
||||||
|
@ -45,7 +45,6 @@ namespace BitTorrent
|
|||||||
{
|
{
|
||||||
class TorrentHandle;
|
class TorrentHandle;
|
||||||
class TrackerEntry;
|
class TrackerEntry;
|
||||||
struct TorrentStatusReport;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FiltersBase: public QListWidget
|
class FiltersBase: public QListWidget
|
||||||
@ -80,7 +79,7 @@ public:
|
|||||||
~StatusFiltersWidget();
|
~StatusFiltersWidget();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateTorrentNumbers(const BitTorrent::TorrentStatusReport &report);
|
void updateTorrentNumbers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// These 4 methods are virtual slots in the base class.
|
// These 4 methods are virtual slots in the base class.
|
||||||
|
Loading…
Reference in New Issue
Block a user