From f3e465c1427a8aa80e993fd50d21f2c2b62787f0 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 26 Aug 2012 18:45:41 +0300 Subject: [PATCH] TorrentContentModel: Simplify progress update code --- src/torrentcontentmodelfile.cpp | 4 ---- src/torrentcontentmodelfolder.cpp | 12 ++++-------- src/torrentcontentmodelitem.cpp | 4 +--- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/torrentcontentmodelfile.cpp b/src/torrentcontentmodelfile.cpp index e11d81e12..29b2320be 100644 --- a/src/torrentcontentmodelfile.cpp +++ b/src/torrentcontentmodelfile.cpp @@ -73,10 +73,6 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent) m_priority = new_prio; - // Reset progress if priority is 0 - if (m_priority == 0) - setProgress(0); - // Update parent if (update_parent) { m_parentItem->updateSize(); diff --git a/src/torrentcontentmodelfolder.cpp b/src/torrentcontentmodelfolder.cpp index 476ca27b7..e9ade8da8 100644 --- a/src/torrentcontentmodelfolder.cpp +++ b/src/torrentcontentmodelfolder.cpp @@ -124,10 +124,6 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent) m_priority = new_prio; - // Reset progress if priority is IGNORED - if (m_priority == prio::IGNORED) - setProgress(0); - // Update parent if (update_parent) { m_parentItem->updateSize(); @@ -154,14 +150,14 @@ void TorrentContentModelFolder::updateProgress() if (isRootItem()) return; - m_totalDone = 0; + qulonglong total_done = 0; foreach (TorrentContentModelItem* child, m_childItems) { if (child->priority() > 0) - m_totalDone += child->totalDone(); + total_done += child->totalDone(); } - Q_ASSERT(m_totalDone <= m_size); - setProgress(m_totalDone); + Q_ASSERT(total_done <= m_size); + setProgress(total_done); } void TorrentContentModelFolder::updateSize() diff --git a/src/torrentcontentmodelitem.cpp b/src/torrentcontentmodelitem.cpp index 63a534d00..c8add9b75 100644 --- a/src/torrentcontentmodelitem.cpp +++ b/src/torrentcontentmodelitem.cpp @@ -76,8 +76,6 @@ void TorrentContentModelItem::setSize(qulonglong size) void TorrentContentModelItem::setProgress(qulonglong done) { Q_ASSERT(!isRootItem()); - if (m_priority == prio::IGNORED) - return; m_totalDone = done; Q_ASSERT(m_totalDone <= m_size); @@ -94,7 +92,7 @@ float TorrentContentModelItem::progress() const { Q_ASSERT(!isRootItem()); if (m_priority == prio::IGNORED) - return -1; + return 0; if (m_size > 0) return m_totalDone / (double) m_size;