Browse Source

Better on-demand reloading of torrent data

adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
1f3bf75fff
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 6
      src/base/bittorrent/session.cpp
  2. 2
      src/base/bittorrent/session.h
  3. 13
      src/gui/transferlistmodel.cpp
  4. 2
      src/gui/transferlistmodel.h

6
src/base/bittorrent/session.cpp

@ -4376,6 +4376,9 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
void Session::handleStateUpdateAlert(const lt::state_update_alert *p) void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
{ {
QVector<BitTorrent::TorrentHandle *> updatedTorrents;
updatedTorrents.reserve(p->status.size());
for (const lt::torrent_status &status : p->status) { for (const lt::torrent_status &status : p->status) {
TorrentHandle *const torrent = m_torrents.value(status.info_hash); TorrentHandle *const torrent = m_torrents.value(status.info_hash);
@ -4383,6 +4386,7 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
continue; continue;
torrent->handleStateUpdate(status); torrent->handleStateUpdate(status);
updatedTorrents.push_back(torrent);
} }
m_torrentStatusReport = TorrentStatusReport(); m_torrentStatusReport = TorrentStatusReport();
@ -4405,7 +4409,7 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
++m_torrentStatusReport.nbErrored; ++m_torrentStatusReport.nbErrored;
} }
emit torrentsUpdated(); emit torrentsUpdated(updatedTorrents);
} }
namespace namespace

2
src/base/bittorrent/session.h

@ -450,7 +450,7 @@ namespace BitTorrent
signals: signals:
void statsUpdated(); void statsUpdated();
void torrentsUpdated(); void torrentsUpdated(const QVector<BitTorrent::TorrentHandle *> &torrents);
void addTorrentFailed(const QString &error); void addTorrentFailed(const QString &error);
void torrentAdded(BitTorrent::TorrentHandle *const torrent); void torrentAdded(BitTorrent::TorrentHandle *const torrent);
void torrentNew(BitTorrent::TorrentHandle *const torrent); void torrentNew(BitTorrent::TorrentHandle *const torrent);

13
src/gui/transferlistmodel.cpp

@ -315,9 +315,18 @@ void TransferListModel::handleTorrentStatusUpdated(BitTorrent::TorrentHandle *co
emit dataChanged(index(row, 0), index(row, columnCount() - 1)); emit dataChanged(index(row, 0), index(row, columnCount() - 1));
} }
void TransferListModel::handleTorrentsUpdated() void TransferListModel::handleTorrentsUpdated(const QVector<BitTorrent::TorrentHandle *> &torrents)
{ {
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); const int columns = (columnCount() - 1);
for (BitTorrent::TorrentHandle *const torrent : torrents) {
const int row = m_torrents.indexOf(torrent);
if (row < 0)
continue;
emit dataChanged(index(row, 0), index(row, columns));
}
} }
// Static functions // Static functions

2
src/gui/transferlistmodel.h

@ -97,7 +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(); void handleTorrentsUpdated(const QVector<BitTorrent::TorrentHandle *> &torrents);
private: private:
QList<BitTorrent::TorrentHandle *> m_torrents; QList<BitTorrent::TorrentHandle *> m_torrents;

Loading…
Cancel
Save