Browse Source

Merge pull request #4994 from evsh/availability-column

Add availability column to torrent contents
adaptive-webui-19844
Eugene Shalygin 8 years ago committed by GitHub
parent
commit
92a7479e2d
  1. 21
      src/base/bittorrent/torrenthandle.cpp
  2. 8
      src/base/bittorrent/torrenthandle.h
  3. 1
      src/base/unicodestrings.h
  4. 1
      src/gui/addnewtorrentdialog.cpp
  5. 1
      src/gui/properties/propertieswidget.cpp
  6. 14
      src/gui/properties/proplistdelegate.cpp
  7. 4
      src/gui/properties/proplistdelegate.h
  8. 18
      src/gui/torrentcontentmodel.cpp
  9. 10
      src/gui/torrentcontentmodel.h
  10. 27
      src/gui/torrentcontentmodelfile.cpp
  11. 9
      src/gui/torrentcontentmodelfile.h
  12. 73
      src/gui/torrentcontentmodelfolder.cpp
  13. 7
      src/gui/torrentcontentmodelfolder.h
  14. 26
      src/gui/torrentcontentmodelitem.cpp
  15. 48
      src/gui/torrentcontentmodelitem.h

21
src/base/bittorrent/torrenthandle.cpp

@ -1953,3 +1953,24 @@ void TorrentHandle::prioritizeFiles(const QVector<int> &priorities)
updateStatus(); updateStatus();
} }
QVector<qreal> TorrentHandle::availableFileFractions() const
{
QVector<int> piecesAvailability = pieceAvailability();
const auto filesCount = this->filesCount();
// libtorrent returns empty array for seeding only torrents
if (piecesAvailability.empty()) return QVector<qreal>(filesCount, -1.);
QVector<qreal> res;
res.reserve(filesCount);
TorrentInfo info = this->info();
for (int file = 0; file < filesCount; ++file) {
TorrentInfo::PieceRange filePieces = info.filePieces(file);
int availablePieces = 0;
for (int piece = filePieces.first(); piece <= filePieces.last(); ++piece) {
availablePieces += piecesAvailability[piece] > 0 ? 1 : 0;
}
res.push_back(static_cast<qreal>(availablePieces) / filePieces.size());
}
return res;
}

8
src/base/bittorrent/torrenthandle.h

@ -361,6 +361,14 @@ namespace BitTorrent
void handleAppendExtensionToggled(); void handleAppendExtensionToggled();
void saveResumeData(bool updateStatus = false); void saveResumeData(bool updateStatus = false);
/**
* @brief fraction of file pieces that are available at least from one peer
*
* This is not the same as torrrent availability, it is just a fraction of pieces
* that can be downloaded right now. It varies between 0 to 1.
*/
QVector<qreal> availableFileFractions() const;
private: private:
typedef boost::function<void ()> EventTrigger; typedef boost::function<void ()> EventTrigger;

1
src/base/unicodestrings.h

@ -39,6 +39,7 @@ const char C_NON_BREAKING_SPACE[] = " ";
const char C_UP[] = ""; const char C_UP[] = "";
const char C_DOWN[] = ""; const char C_DOWN[] = "";
const char C_COPYRIGHT[] = "©"; const char C_COPYRIGHT[] = "©";
const char C_THIN_SPACE[] = "";
const char C_UTP[] = "μTP"; const char C_UTP[] = "μTP";
const char C_LOCALE_ENGLISH[] = "English"; const char C_LOCALE_ENGLISH[] = "English";
const char C_LOCALE_ENGLISH_AUSTRALIA[] = "English(Australia)"; const char C_LOCALE_ENGLISH_AUSTRALIA[] = "English(Australia)";

1
src/gui/addnewtorrentdialog.cpp

@ -737,6 +737,7 @@ void AddNewTorrentDialog::setupTreeview()
// Hide useless columns after loading the header state // Hide useless columns after loading the header state
ui->contentTreeView->hideColumn(PROGRESS); ui->contentTreeView->hideColumn(PROGRESS);
ui->contentTreeView->hideColumn(REMAINING); ui->contentTreeView->hideColumn(REMAINING);
ui->contentTreeView->hideColumn(AVAILABILITY);
// Expand root folder // Expand root folder
ui->contentTreeView->setExpanded(m_contentModel->index(0, 0), true); ui->contentTreeView->setExpanded(m_contentModel->index(0, 0), true);

1
src/gui/properties/propertieswidget.cpp

@ -493,6 +493,7 @@ void PropertiesWidget::loadDynamicData()
qDebug("Updating priorities in files tab"); qDebug("Updating priorities in files tab");
m_ui->filesList->setUpdatesEnabled(false); m_ui->filesList->setUpdatesEnabled(false);
PropListModel->model()->updateFilesProgress(m_torrent->filesProgress()); PropListModel->model()->updateFilesProgress(m_torrent->filesProgress());
PropListModel->model()->updateFilesAvailability(m_torrent->availableFileFractions());
// XXX: We don't update file priorities regularly for performance // XXX: We don't update file priorities regularly for performance
// reasons. This means that priorities will not be updated if // reasons. This means that priorities will not be updated if
// set from the Web UI. // set from the Web UI.

14
src/gui/properties/proplistdelegate.cpp

@ -42,6 +42,7 @@
#include <QProxyStyle> #include <QProxyStyle>
#endif #endif
#include "base/unicodestrings.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "propertieswidget.h" #include "propertieswidget.h"
@ -131,6 +132,19 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
QItemDelegate::drawDisplay(painter, opt, option.rect, text); QItemDelegate::drawDisplay(painter, opt, option.rect, text);
} }
break; break;
case AVAILABILITY: {
const qreal availability = index.data().toDouble();
if (availability < 0) {
QItemDelegate::drawDisplay(painter, opt, option.rect, tr("N/A"));
}
else {
const QString value = (availability >= 1.0)
? QLatin1String("100")
: Utils::String::fromDouble(availability * 100., 1);
QItemDelegate::drawDisplay(painter, opt, option.rect, value + C_THIN_SPACE + QLatin1Char('%'));
}
}
break;
default: default:
QItemDelegate::paint(painter, option, index); QItemDelegate::paint(painter, option, index);
break; break;

4
src/gui/properties/proplistdelegate.h

@ -46,7 +46,8 @@ enum PropColumn
PCSIZE, PCSIZE,
PROGRESS, PROGRESS,
PRIORITY, PRIORITY,
REMAINING REMAINING,
AVAILABILITY
}; };
class PropListDelegate: public QItemDelegate class PropListDelegate: public QItemDelegate
@ -72,3 +73,4 @@ private:
}; };
#endif #endif

18
src/gui/torrentcontentmodel.cpp

@ -56,7 +56,7 @@ namespace
TorrentContentModel::TorrentContentModel(QObject *parent) TorrentContentModel::TorrentContentModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
, m_rootItem(new TorrentContentModelFolder(QList<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining") }))) , m_rootItem(new TorrentContentModelFolder(QList<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") })))
{ {
} }
@ -76,6 +76,7 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
m_filesIndex[i]->setProgress(fp[i]); m_filesIndex[i]->setProgress(fp[i]);
// Update folders progress in the tree // Update folders progress in the tree
m_rootItem->recalculateProgress(); m_rootItem->recalculateProgress();
m_rootItem->recalculateAvailability();
emit dataChanged(index(0, 0), index(rowCount(), columnCount())); emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
} }
@ -92,6 +93,20 @@ void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
emit dataChanged(index(0, 0), index(rowCount(), columnCount())); emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
} }
void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa)
{
Q_ASSERT(m_filesIndex.size() == fa.size());
// XXX: Why is this necessary?
if (m_filesIndex.size() != fa.size()) return;
emit layoutAboutToBeChanged();
for (int i = 0; i < fa.size(); ++i)
m_filesIndex[i]->setAvailability(fa[i]);
// Update folders progress in the tree
m_rootItem->recalculateProgress();
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
}
QVector<int> TorrentContentModel::getFilePriorities() const QVector<int> TorrentContentModel::getFilePriorities() const
{ {
QVector<int> prio; QVector<int> prio;
@ -134,6 +149,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
item->setPriority(prio::NORMAL); item->setPriority(prio::NORMAL);
// Update folders progress in the tree // Update folders progress in the tree
m_rootItem->recalculateProgress(); m_rootItem->recalculateProgress();
m_rootItem->recalculateAvailability();
emit dataChanged(this->index(0, 0), this->index(rowCount() - 1, columnCount() - 1)); emit dataChanged(this->index(0, 0), this->index(rowCount() - 1, columnCount() - 1));
emit filteredFilesChanged(); emit filteredFilesChanged();
} }

10
src/gui/torrentcontentmodel.h

@ -41,7 +41,8 @@
class TorrentContentModelFile; class TorrentContentModelFile;
class TorrentContentModel: public QAbstractItemModel { class TorrentContentModel: public QAbstractItemModel
{
Q_OBJECT Q_OBJECT
public: public:
@ -50,9 +51,10 @@ public:
void updateFilesProgress(const QVector<qreal> &fp); void updateFilesProgress(const QVector<qreal> &fp);
void updateFilesPriorities(const QVector<int> &fprio); void updateFilesPriorities(const QVector<int> &fprio);
void updateFilesAvailability(const QVector<qreal> &fa);
QVector<int> getFilePriorities() const; QVector<int> getFilePriorities() const;
bool allFiltered() const; bool allFiltered() const;
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const; virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
TorrentContentModelItem::ItemType itemType(const QModelIndex& index) const; TorrentContentModelItem::ItemType itemType(const QModelIndex& index) const;
int getFileIndex(const QModelIndex& index); int getFileIndex(const QModelIndex& index);
@ -73,8 +75,8 @@ public slots:
void selectNone(); void selectNone();
private: private:
TorrentContentModelFolder* m_rootItem; TorrentContentModelFolder *m_rootItem;
QVector<TorrentContentModelFile*> m_filesIndex; QVector<TorrentContentModelFile *> m_filesIndex;
}; };
#endif // TORRENTCONTENTMODEL_H #endif // TORRENTCONTENTMODEL_H

27
src/gui/torrentcontentmodelfile.cpp

@ -32,9 +32,9 @@
#include "torrentcontentmodelfolder.h" #include "torrentcontentmodelfolder.h"
TorrentContentModelFile::TorrentContentModelFile(const QString &fileName, qulonglong fileSize, TorrentContentModelFile::TorrentContentModelFile(const QString &fileName, qulonglong fileSize,
TorrentContentModelFolder* parent, int file_index) TorrentContentModelFolder *parent, int fileIndex)
: TorrentContentModelItem(parent) : TorrentContentModelItem(parent)
, m_fileIndex(file_index) , m_fileIndex(fileIndex)
{ {
Q_ASSERT(parent); Q_ASSERT(parent);
@ -52,23 +52,34 @@ int TorrentContentModelFile::fileIndex() const
return m_fileIndex; return m_fileIndex;
} }
void TorrentContentModelFile::setPriority(int new_prio, bool update_parent) void TorrentContentModelFile::setPriority(int newPriority, bool updateParent)
{ {
Q_ASSERT(new_prio != prio::MIXED); Q_ASSERT(newPriority != prio::MIXED);
if (m_priority == new_prio) if (m_priority == newPriority)
return; return;
m_priority = new_prio; m_priority = newPriority;
// Update parent // Update parent
if (update_parent) if (updateParent)
m_parentItem->updatePriority(); m_parentItem->updatePriority();
} }
void TorrentContentModelFile::setProgress(qreal progress) void TorrentContentModelFile::setProgress(qreal progress)
{ {
m_progress = progress; m_progress = progress;
m_remaining = (qulonglong)(m_size * (1.0 - m_progress)); m_remaining = static_cast<qulonglong>(m_size * (1.0 - m_progress));
Q_ASSERT(m_progress <= 1.); Q_ASSERT(m_progress <= 1.);
} }
void TorrentContentModelFile::setAvailability(qreal availability)
{
m_availability = availability;
Q_ASSERT(m_availability <= 1.);
}
TorrentContentModelItem::ItemType TorrentContentModelFile::itemType() const
{
return FileType;
}

9
src/gui/torrentcontentmodelfile.h

@ -33,16 +33,17 @@
#include "torrentcontentmodelitem.h" #include "torrentcontentmodelitem.h"
class TorrentContentModelFile : public TorrentContentModelItem class TorrentContentModelFile: public TorrentContentModelItem
{ {
public: public:
TorrentContentModelFile(const QString &fileName, qulonglong fileSize, TorrentContentModelFile(const QString &fileName, qulonglong fileSize,
TorrentContentModelFolder* parent, int file_index); TorrentContentModelFolder *parent, int fileIndex);
int fileIndex() const; int fileIndex() const;
void setPriority(int new_prio, bool update_parent = true); void setPriority(int newPriority, bool updateParent = true) override;
void setProgress(qreal progress); void setProgress(qreal progress);
ItemType itemType() const { return FileType; } void setAvailability(qreal availability);
ItemType itemType() const override;
private: private:
int m_fileIndex; int m_fileIndex;

73
src/gui/torrentcontentmodelfolder.cpp

@ -31,7 +31,7 @@
#include <QDebug> #include <QDebug>
#include "torrentcontentmodelfolder.h" #include "torrentcontentmodelfolder.h"
TorrentContentModelFolder::TorrentContentModelFolder(const QString& name, TorrentContentModelFolder* parent) TorrentContentModelFolder::TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent)
: TorrentContentModelItem(parent) : TorrentContentModelItem(parent)
{ {
Q_ASSERT(parent); Q_ASSERT(parent);
@ -41,7 +41,7 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString& name, Torren
m_name.chop(4); m_name.chop(4);
} }
TorrentContentModelFolder::TorrentContentModelFolder(const QList<QVariant>& data) TorrentContentModelFolder::TorrentContentModelFolder(const QList<QVariant> &data)
: TorrentContentModelItem(0) : TorrentContentModelItem(0)
{ {
Q_ASSERT(data.size() == NB_COL); Q_ASSERT(data.size() == NB_COL);
@ -53,6 +53,11 @@ TorrentContentModelFolder::~TorrentContentModelFolder()
qDeleteAll(m_childItems); qDeleteAll(m_childItems);
} }
TorrentContentModelItem::ItemType TorrentContentModelFolder::itemType() const
{
return FolderType;
}
void TorrentContentModelFolder::deleteAllChildren() void TorrentContentModelFolder::deleteAllChildren()
{ {
Q_ASSERT(isRootItem()); Q_ASSERT(isRootItem());
@ -60,12 +65,12 @@ void TorrentContentModelFolder::deleteAllChildren()
m_childItems.clear(); m_childItems.clear();
} }
const QList<TorrentContentModelItem*>& TorrentContentModelFolder::children() const const QList<TorrentContentModelItem *> &TorrentContentModelFolder::children() const
{ {
return m_childItems; return m_childItems;
} }
void TorrentContentModelFolder::appendChild(TorrentContentModelItem* item) void TorrentContentModelFolder::appendChild(TorrentContentModelItem *item)
{ {
Q_ASSERT(item); Q_ASSERT(item);
m_childItems.append(item); m_childItems.append(item);
@ -74,17 +79,16 @@ void TorrentContentModelFolder::appendChild(TorrentContentModelItem* item)
increaseSize(item->size()); increaseSize(item->size());
} }
TorrentContentModelItem* TorrentContentModelFolder::child(int row) const TorrentContentModelItem *TorrentContentModelFolder::child(int row) const
{ {
return m_childItems.value(row, 0); return m_childItems.value(row, 0);
} }
TorrentContentModelFolder* TorrentContentModelFolder::childFolderWithName(const QString& name) const TorrentContentModelFolder *TorrentContentModelFolder::childFolderWithName(const QString &name) const
{ {
foreach (TorrentContentModelItem* child, m_childItems) { foreach (TorrentContentModelItem *child, m_childItems)
if (child->itemType() == FolderType && child->name() == name) if ((child->itemType() == FolderType) && (child->name() == name))
return static_cast<TorrentContentModelFolder*>(child); return static_cast<TorrentContentModelFolder *>(child);
}
return 0; return 0;
} }
@ -105,7 +109,7 @@ void TorrentContentModelFolder::updatePriority()
// then the folder should have the same // then the folder should have the same
// priority // priority
const int prio = m_childItems.first()->priority(); const int prio = m_childItems.first()->priority();
for (int i=1; i<m_childItems.size(); ++i) { for (int i = 1; i < m_childItems.size(); ++i) {
if (m_childItems.at(i)->priority() != prio) { if (m_childItems.at(i)->priority() != prio) {
setPriority(prio::MIXED); setPriority(prio::MIXED);
return; return;
@ -116,22 +120,21 @@ void TorrentContentModelFolder::updatePriority()
setPriority(prio); setPriority(prio);
} }
void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent) void TorrentContentModelFolder::setPriority(int newPriority, bool updateParent)
{ {
if (m_priority == new_prio) if (m_priority == newPriority)
return; return;
m_priority = new_prio; m_priority = newPriority;
// Update parent priority // Update parent priority
if (update_parent) if (updateParent)
m_parentItem->updatePriority(); m_parentItem->updatePriority();
// Update children // Update children
if (m_priority != prio::MIXED) { if (m_priority != prio::MIXED)
foreach (TorrentContentModelItem* child, m_childItems) foreach (TorrentContentModelItem *child, m_childItems)
child->setPriority(m_priority, false); child->setPriority(m_priority, false);
}
} }
void TorrentContentModelFolder::recalculateProgress() void TorrentContentModelFolder::recalculateProgress()
@ -139,23 +142,51 @@ void TorrentContentModelFolder::recalculateProgress()
qreal tProgress = 0; qreal tProgress = 0;
qulonglong tSize = 0; qulonglong tSize = 0;
qulonglong tRemaining = 0; qulonglong tRemaining = 0;
foreach (TorrentContentModelItem* child, m_childItems) { foreach (TorrentContentModelItem *child, m_childItems) {
if (child->priority() != prio::IGNORED) { if (child->priority() != prio::IGNORED) {
if (child->itemType() == FolderType) if (child->itemType() == FolderType)
static_cast<TorrentContentModelFolder*>(child)->recalculateProgress(); static_cast<TorrentContentModelFolder *>(child)->recalculateProgress();
tProgress += child->progress() * child->size(); tProgress += child->progress() * child->size();
tSize += child->size(); tSize += child->size();
tRemaining += child->remaining(); tRemaining += child->remaining();
} }
} }
if (!isRootItem() && tSize > 0) { if (!isRootItem() && (tSize > 0)) {
m_progress = tProgress / tSize; m_progress = tProgress / tSize;
m_remaining = tRemaining; m_remaining = tRemaining;
Q_ASSERT(m_progress <= 1.); Q_ASSERT(m_progress <= 1.);
} }
} }
void TorrentContentModelFolder::recalculateAvailability()
{
qreal tAvailability = 0;
qulonglong tSize = 0;
bool foundAnyData = false;
foreach (TorrentContentModelItem* child, m_childItems) {
if (child->priority() == prio::IGNORED)
continue;
if (child->itemType() == FolderType)
static_cast<TorrentContentModelFolder*>(child)->recalculateAvailability();
const qreal childAvailability = child->availability();
if (childAvailability >= 0) { // -1 means "no data"
tAvailability += childAvailability * child->size();
foundAnyData = true;
}
tSize += child->size();
}
if (!isRootItem() && (tSize > 0) && foundAnyData) {
m_availability = tAvailability / tSize;
Q_ASSERT(m_availability <= 1.);
}
else {
m_availability = -1.;
}
}
void TorrentContentModelFolder::increaseSize(qulonglong delta) void TorrentContentModelFolder::increaseSize(qulonglong delta)
{ {
if (isRootItem()) if (isRootItem())

7
src/gui/torrentcontentmodelfolder.h

@ -33,7 +33,7 @@
#include "torrentcontentmodelitem.h" #include "torrentcontentmodelitem.h"
class TorrentContentModelFolder : public TorrentContentModelItem class TorrentContentModelFolder: public TorrentContentModelItem
{ {
public: public:
// Folder constructor // Folder constructor
@ -44,13 +44,14 @@ public:
~TorrentContentModelFolder(); ~TorrentContentModelFolder();
ItemType itemType() const { return FolderType; } ItemType itemType() const override;
void increaseSize(qulonglong delta); void increaseSize(qulonglong delta);
void recalculateProgress(); void recalculateProgress();
void recalculateAvailability();
void updatePriority(); void updatePriority();
void setPriority(int new_prio, bool update_parent = true); void setPriority(int newPriority, bool updateParent = true) override;
void deleteAllChildren(); void deleteAllChildren();
const QList<TorrentContentModelItem*>& children() const; const QList<TorrentContentModelItem*>& children() const;

26
src/gui/torrentcontentmodelitem.cpp

@ -34,17 +34,21 @@
#include "torrentcontentmodelfolder.h" #include "torrentcontentmodelfolder.h"
#include <QDebug> #include <QDebug>
TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder* parent) TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder *parent)
: m_parentItem(parent) : m_parentItem(parent)
, m_size(0) , m_size(0)
, m_remaining(0) , m_remaining(0)
, m_priority(prio::NORMAL) , m_priority(prio::NORMAL)
, m_progress(0) , m_progress(0)
, m_availability(-1.)
{ {
} }
TorrentContentModelItem::~TorrentContentModelItem() TorrentContentModelItem::~TorrentContentModelItem() = default;
bool TorrentContentModelItem::isRootItem() const
{ {
return !m_parentItem;
} }
QString TorrentContentModelItem::name() const QString TorrentContentModelItem::name() const
@ -53,7 +57,7 @@ QString TorrentContentModelItem::name() const
return m_name; return m_name;
} }
void TorrentContentModelItem::setName(const QString& name) void TorrentContentModelItem::setName(const QString &name)
{ {
Q_ASSERT(!isRootItem()); Q_ASSERT(!isRootItem());
m_name = name; m_name = name;
@ -81,6 +85,13 @@ qulonglong TorrentContentModelItem::remaining() const
return m_remaining; return m_remaining;
} }
qreal TorrentContentModelItem::availability() const
{
Q_ASSERT(!isRootItem());
return m_size > 0 ? m_availability : 0.;
}
int TorrentContentModelItem::priority() const int TorrentContentModelItem::priority() const
{ {
Q_ASSERT(!isRootItem()); Q_ASSERT(!isRootItem());
@ -97,7 +108,7 @@ QVariant TorrentContentModelItem::data(int column) const
if (isRootItem()) if (isRootItem())
return m_itemData.value(column); return m_itemData.value(column);
switch(column) { switch (column) {
case COL_NAME: case COL_NAME:
return m_name; return m_name;
case COL_PRIO: case COL_PRIO:
@ -108,6 +119,8 @@ QVariant TorrentContentModelItem::data(int column) const
return m_size; return m_size;
case COL_REMAINING: case COL_REMAINING:
return remaining(); return remaining();
case COL_AVAILABILITY:
return availability();
default: default:
Q_ASSERT(false); Q_ASSERT(false);
return QVariant(); return QVariant();
@ -117,11 +130,12 @@ QVariant TorrentContentModelItem::data(int column) const
int TorrentContentModelItem::row() const int TorrentContentModelItem::row() const
{ {
if (m_parentItem) if (m_parentItem)
return m_parentItem->children().indexOf(const_cast<TorrentContentModelItem*>(this)); return m_parentItem->children().indexOf(const_cast<TorrentContentModelItem *>(this));
return 0; return 0;
} }
TorrentContentModelFolder* TorrentContentModelItem::parent() const TorrentContentModelFolder *TorrentContentModelItem::parent() const
{ {
return m_parentItem; return m_parentItem;
} }

48
src/gui/torrentcontentmodelitem.h

@ -34,40 +34,65 @@
#include <QList> #include <QList>
#include <QVariant> #include <QVariant>
namespace prio { namespace prio
enum FilePriority {IGNORED=0, NORMAL=1, HIGH=6, MAXIMUM=7, MIXED=-1}; {
enum FilePriority
{
IGNORED=0,
NORMAL=1,
HIGH=6,
MAXIMUM=7,
MIXED=-1
};
} }
class TorrentContentModelFolder; class TorrentContentModelFolder;
class TorrentContentModelItem { class TorrentContentModelItem
{
public: public:
enum TreeItemColumns {COL_NAME, COL_SIZE, COL_PROGRESS, COL_PRIO, COL_REMAINING, NB_COL}; enum TreeItemColumns
enum ItemType { FileType, FolderType }; {
COL_NAME,
COL_SIZE,
COL_PROGRESS,
COL_PRIO,
COL_REMAINING,
COL_AVAILABILITY,
NB_COL
};
TorrentContentModelItem(TorrentContentModelFolder* parent); enum ItemType
{
FileType,
FolderType
};
TorrentContentModelItem(TorrentContentModelFolder *parent);
virtual ~TorrentContentModelItem(); virtual ~TorrentContentModelItem();
inline bool isRootItem() const { return !m_parentItem; } bool isRootItem() const;
TorrentContentModelFolder* parent() const; TorrentContentModelFolder *parent() const;
virtual ItemType itemType() const = 0; virtual ItemType itemType() const = 0;
QString name() const; QString name() const;
void setName(const QString& name); void setName(const QString &name);
qulonglong size() const; qulonglong size() const;
qreal progress() const; qreal progress() const;
qulonglong remaining() const; qulonglong remaining() const;
qreal availability() const;
int priority() const; int priority() const;
virtual void setPriority(int new_prio, bool update_parent = true) = 0; virtual void setPriority(int newPriority, bool updateParent = true) = 0;
int columnCount() const; int columnCount() const;
QVariant data(int column) const; QVariant data(int column) const;
int row() const; int row() const;
protected: protected:
TorrentContentModelFolder* m_parentItem; TorrentContentModelFolder *m_parentItem;
// Root item members // Root item members
QList<QVariant> m_itemData; QList<QVariant> m_itemData;
// Non-root item members // Non-root item members
@ -76,6 +101,7 @@ protected:
qulonglong m_remaining; qulonglong m_remaining;
int m_priority; int m_priority;
qreal m_progress; qreal m_progress;
qreal m_availability;
}; };
#endif // TORRENTCONTENTMODELITEM_H #endif // TORRENTCONTENTMODELITEM_H

Loading…
Cancel
Save