Browse Source

Great improve size calculation in torrent content model

Step to address issue #24.
adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
d7ea394993
  1. 4
      src/torrentcontentmodelfile.cpp
  2. 20
      src/torrentcontentmodelfolder.cpp
  3. 2
      src/torrentcontentmodelfolder.h
  4. 1
      src/torrentcontentmodelitem.cpp

4
src/torrentcontentmodelfile.cpp

@ -53,9 +53,8 @@ TorrentContentModelFile::TorrentContentModelFile(const libtorrent::file_entry& f @@ -53,9 +53,8 @@ TorrentContentModelFile::TorrentContentModelFile(const libtorrent::file_entry& f
m_size = (qulonglong)f.size;
// Update parent
// Add to parent
m_parentItem->appendChild(this);
m_parentItem->updateSize();
}
int TorrentContentModelFile::fileIndex() const
@ -74,7 +73,6 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent) @@ -74,7 +73,6 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent)
// Update parent
if (update_parent) {
m_parentItem->updateSize();
m_parentItem->updateProgress();
m_parentItem->updatePriority();
}

20
src/torrentcontentmodelfolder.cpp

@ -39,7 +39,7 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString& name, Torren @@ -39,7 +39,7 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString& name, Torren
if (m_name.endsWith(".!qB"))
m_name.chop(4);
// Update parent
// Add to parent
m_parentItem->appendChild(this);
}
@ -71,6 +71,9 @@ void TorrentContentModelFolder::appendChild(TorrentContentModelItem* item) @@ -71,6 +71,9 @@ void TorrentContentModelFolder::appendChild(TorrentContentModelItem* item)
{
Q_ASSERT(item);
m_childItems.append(item);
// Update own size
if (item->itemType() == FileType)
increaseSize(item->size());
}
TorrentContentModelItem* TorrentContentModelFolder::child(int row) const
@ -132,7 +135,6 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent) @@ -132,7 +135,6 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent)
child->setPriority(m_priority, false);
}
updateSize();
updateProgress();
}
@ -154,19 +156,11 @@ void TorrentContentModelFolder::updateProgress() @@ -154,19 +156,11 @@ void TorrentContentModelFolder::updateProgress()
}
}
void TorrentContentModelFolder::updateSize()
void TorrentContentModelFolder::increaseSize(qulonglong delta)
{
if (isRootItem())
return;
qulonglong size = 0;
foreach (TorrentContentModelItem* child, m_childItems) {
if (child->priority() != prio::IGNORED)
size += child->size();
}
if (size != m_size) {
m_size = size;
m_parentItem->updateSize();
}
m_size += delta;
m_parentItem->increaseSize(delta);
}

2
src/torrentcontentmodelfolder.h

@ -46,7 +46,7 @@ public: @@ -46,7 +46,7 @@ public:
ItemType itemType() const { return FolderType; }
void updateSize();
void increaseSize(qulonglong delta);
void updateProgress();
void updatePriority();

1
src/torrentcontentmodelitem.cpp

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder* parent)
: m_parentItem(parent)
, m_size(0)
, m_priority(prio::NORMAL)
, m_totalDone(0)
{

Loading…
Cancel
Save