Browse Source

TorrentContentModel: Simplify progress update code

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
f3e465c142
  1. 4
      src/torrentcontentmodelfile.cpp
  2. 12
      src/torrentcontentmodelfolder.cpp
  3. 4
      src/torrentcontentmodelitem.cpp

4
src/torrentcontentmodelfile.cpp

@ -73,10 +73,6 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent)
m_priority = new_prio; m_priority = new_prio;
// Reset progress if priority is 0
if (m_priority == 0)
setProgress(0);
// Update parent // Update parent
if (update_parent) { if (update_parent) {
m_parentItem->updateSize(); m_parentItem->updateSize();

12
src/torrentcontentmodelfolder.cpp

@ -124,10 +124,6 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent)
m_priority = new_prio; m_priority = new_prio;
// Reset progress if priority is IGNORED
if (m_priority == prio::IGNORED)
setProgress(0);
// Update parent // Update parent
if (update_parent) { if (update_parent) {
m_parentItem->updateSize(); m_parentItem->updateSize();
@ -154,14 +150,14 @@ void TorrentContentModelFolder::updateProgress()
if (isRootItem()) if (isRootItem())
return; return;
m_totalDone = 0; qulonglong total_done = 0;
foreach (TorrentContentModelItem* child, m_childItems) { foreach (TorrentContentModelItem* child, m_childItems) {
if (child->priority() > 0) if (child->priority() > 0)
m_totalDone += child->totalDone(); total_done += child->totalDone();
} }
Q_ASSERT(m_totalDone <= m_size); Q_ASSERT(total_done <= m_size);
setProgress(m_totalDone); setProgress(total_done);
} }
void TorrentContentModelFolder::updateSize() void TorrentContentModelFolder::updateSize()

4
src/torrentcontentmodelitem.cpp

@ -76,8 +76,6 @@ void TorrentContentModelItem::setSize(qulonglong size)
void TorrentContentModelItem::setProgress(qulonglong done) void TorrentContentModelItem::setProgress(qulonglong done)
{ {
Q_ASSERT(!isRootItem()); Q_ASSERT(!isRootItem());
if (m_priority == prio::IGNORED)
return;
m_totalDone = done; m_totalDone = done;
Q_ASSERT(m_totalDone <= m_size); Q_ASSERT(m_totalDone <= m_size);
@ -94,7 +92,7 @@ float TorrentContentModelItem::progress() const
{ {
Q_ASSERT(!isRootItem()); Q_ASSERT(!isRootItem());
if (m_priority == prio::IGNORED) if (m_priority == prio::IGNORED)
return -1; return 0;
if (m_size > 0) if (m_size > 0)
return m_totalDone / (double) m_size; return m_totalDone / (double) m_size;

Loading…
Cancel
Save