Made progress calculation more efficient in torrent content model

Stop to address issue #24.
This commit is contained in:
Christophe Dumez 2012-08-27 22:01:35 +03:00
commit ca2a659970
4 changed files with 16 additions and 18 deletions

View file

@ -131,25 +131,22 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent)
foreach (TorrentContentModelItem* child, m_childItems)
child->setPriority(m_priority, false);
}
updateProgress();
}
void TorrentContentModelFolder::updateProgress()
void TorrentContentModelFolder::recalculateProgress()
{
if (isRootItem())
return;
qulonglong total_done = 0;
qulonglong totalDone = 0;
foreach (TorrentContentModelItem* child, m_childItems) {
if (child->priority() > 0)
total_done += child->totalDone();
if (child->priority() != prio::IGNORED) {
if (child->itemType() == FolderType)
static_cast<TorrentContentModelFolder*>(child)->recalculateProgress();
totalDone += child->totalDone();
}
}
Q_ASSERT(total_done <= m_size);
if (total_done != m_totalDone) {
m_totalDone = total_done;
m_parentItem->updateProgress();
if (!isRootItem()) {
m_totalDone = totalDone;
Q_ASSERT(m_totalDone <= m_size);
}
}