From b50d7331c7d395e2bd3cb4798cd53f4bfbc9a8ab Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Sun, 18 May 2014 12:07:49 +0400 Subject: [PATCH] use post_status_update() Conflicts: src/qtlibtorrent/qbtsession.cpp --- src/qtlibtorrent/qbtsession.cpp | 7 +++++++ src/qtlibtorrent/qbtsession.h | 2 ++ src/qtlibtorrent/torrentmodel.cpp | 31 ++++++++++++++++++++----------- src/qtlibtorrent/torrentmodel.h | 3 ++- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 57f83eefb..57b32a39b 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -2568,6 +2568,9 @@ void QBtSession::handleAlert(libtorrent::alert* a) { boost::system::error_code ec; addConsoleMessage(tr("External IP: %1", "e.g. External IP: 192.168.0.1").arg(p->external_address.to_string(ec).c_str()), "blue"); } + else if (state_update_alert *p = dynamic_cast(a)) { + emit stateUpdate(p->status); + } } catch (const std::exception& e) { qWarning() << "Caught exception in readAlerts(): " << e.what(); } @@ -2819,6 +2822,10 @@ quint64 QBtSession::getAlltimeUL() const { return m_speedMonitor->getAlltimeUL(); } +void QBtSession::postTorrentUpdate() { + s->post_torrent_updates(); +} + void QBtSession::handleIPFilterParsed(int ruleCount) { addConsoleMessage(tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount)); diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index a794ad1da..df1888667 100755 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -111,6 +111,7 @@ public: inline bool isQueueingEnabled() const { return queueingEnabled; } quint64 getAlltimeDL() const; quint64 getAlltimeUL() const; + void postTorrentUpdate(); public slots: QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); @@ -232,6 +233,7 @@ signals: void recursiveTorrentDownloadPossible(const QTorrentHandle &h); void ipFilterParsed(bool error, int ruleCount); void metadataReceivedHidden(const QTorrentHandle &h); + void stateUpdate(const std::vector &statuses); private: // Bittorrent diff --git a/src/qtlibtorrent/torrentmodel.cpp b/src/qtlibtorrent/torrentmodel.cpp index 8140f4833..cbb303908 100644 --- a/src/qtlibtorrent/torrentmodel.cpp +++ b/src/qtlibtorrent/torrentmodel.cpp @@ -101,11 +101,9 @@ TorrentModelItem::TorrentModelItem(const QTorrentHandle &h) m_name = h.name(); } -void TorrentModelItem::refreshStatus() +void TorrentModelItem::refreshStatus(libtorrent::torrent_status const& status) { - try { - m_lastStatus = m_torrent.status(); - } catch(invalid_handle&) {} + m_lastStatus = status; } TorrentModelItem::State TorrentModelItem::state() const @@ -309,6 +307,7 @@ void TorrentModel::populate() { connect(QBtSession::instance(), SIGNAL(resumedTorrent(QTorrentHandle)), SLOT(handleTorrentUpdate(QTorrentHandle))); connect(QBtSession::instance(), SIGNAL(pausedTorrent(QTorrentHandle)), SLOT(handleTorrentUpdate(QTorrentHandle))); connect(QBtSession::instance(), SIGNAL(torrentFinishedChecking(QTorrentHandle)), SLOT(handleTorrentUpdate(QTorrentHandle))); + connect(QBtSession::instance(), SIGNAL(stateUpdate(std::vector)), SLOT(stateUpdated(std::vector))); } TorrentModel::~TorrentModel() { @@ -441,6 +440,7 @@ void TorrentModel::handleTorrentUpdate(const QTorrentHandle &h) { const int row = torrentRow(h.hash()); if (row >= 0) { + m_torrents[row]->refreshStatus(h.status(torrent_handle::query_accurate_download_counters)); notifyTorrentChanged(row); } } @@ -453,6 +453,7 @@ void TorrentModel::handleFinishedTorrent(const QTorrentHandle& h) // Update completion date m_torrents[row]->setData(TorrentModelItem::TR_SEED_DATE, QDateTime::currentDateTime(), Qt::DisplayRole); + m_torrents[row]->refreshStatus(h.status(torrent_handle::query_accurate_download_counters)); notifyTorrentChanged(row); } @@ -472,14 +473,8 @@ void TorrentModel::setRefreshInterval(int refreshInterval) void TorrentModel::forceModelRefresh() { - QList::const_iterator it = m_torrents.constBegin(); - QList::const_iterator itend = m_torrents.constEnd(); - for ( ; it != itend; ++it) { - TorrentModelItem* item = *it; - item->refreshStatus(); - } - emit dataChanged(index(0, 0), index(rowCount()-1, columnCount()-1)); + QBtSession::instance()->postTorrentUpdate(); } TorrentStatusReport TorrentModel::getTorrentStatusReport() const @@ -554,6 +549,20 @@ void TorrentModel::handleTorrentAboutToBeRemoved(const QTorrentHandle &h) } } +void TorrentModel::stateUpdated(const std::vector &statuses) +{ + typedef std::vector statuses_t; + + for (statuses_t::const_iterator i = statuses.begin(), end = statuses.end(); i != end; ++i) + { + libtorrent::torrent_status const& status = *i; + + const int row = torrentRow(misc::toQString(status.handle.info_hash())); + if (row >= 0) + m_torrents[row]->refreshStatus(status); + } +} + bool TorrentModel::inhibitSystem() { QList::const_iterator it = m_torrents.constBegin(); diff --git a/src/qtlibtorrent/torrentmodel.h b/src/qtlibtorrent/torrentmodel.h index ce1648801..511077491 100644 --- a/src/qtlibtorrent/torrentmodel.h +++ b/src/qtlibtorrent/torrentmodel.h @@ -53,7 +53,7 @@ public: public: TorrentModelItem(const QTorrentHandle& h); - void refreshStatus(); + void refreshStatus(libtorrent::torrent_status const& status); inline int columnCount() const { return NB_COLUMNS; } QVariant data(int column, int role = Qt::DisplayRole) const; bool setData(int column, const QVariant &value, int role = Qt::DisplayRole); @@ -112,6 +112,7 @@ private slots: void forceModelRefresh(); void handleTorrentLabelChange(QString previous, QString current); void handleTorrentAboutToBeRemoved(const QTorrentHandle & h); + void stateUpdated(const std::vector &statuses); private: void beginInsertTorrent(int row);