26 #include <util/functions.h>
27 #include <interfaces/torrentinterface.h>
28 #include <interfaces/torrentfileinterface.h>
35 IWFileTreeModel::IWFileTreeModel(bt::TorrentInterface* tc,
QObject* parent)
38 mmfile = IsMultimediaFile(tc->getStats().output_path);
44 BitSet d = tc->downloadedChunksBitSet();
45 d -= tc->onlySeedChunksBitSet();
62 if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
70 case 2:
return i18n(
"Priority");
71 case 3:
return i18n(
"Preview");
73 case 4:
return i18nc(
"Percent of File Downloaded",
"% Complete");
74 default:
return QVariant();
80 switch(file->getPriority())
82 case FIRST_PRIORITY:
return i18nc(
"Download first",
"First");
83 case LAST_PRIORITY:
return i18nc(
"Download last",
"Last");
84 case ONLY_SEED_PRIORITY:
86 case PREVIEW_PRIORITY:
88 default:
return i18nc(
"Download normally(not as first or last)",
"Normal");
95 if (index.column() < 2 && role != Qt::ForegroundRole)
98 if (!index.isValid() || !(n = (
Node*)index.internalPointer()))
101 if (role == Qt::ForegroundRole && index.column() == 2 &&
tc->getStats().multi_file_torrent && n->
file)
103 const bt::TorrentFileInterface* file = n->
file;
104 switch (file->getPriority())
120 if (role == Qt::DisplayRole)
121 return displayData(n,index);
122 else if (role == Qt::UserRole)
123 return sortData(n,index);
128 QVariant IWFileTreeModel::displayData(Node* n,
const QModelIndex & index)
const
130 if (
tc->getStats().multi_file_torrent && n->file)
132 const bt::TorrentFileInterface* file = n->file;
133 switch (index.column())
137 if (file->isMultimedia())
139 if (file->isPreviewAvailable())
140 return i18nc(
"preview available",
"Available");
142 return i18nc(
"Preview pending",
"Pending");
145 return i18nc(
"No preview available",
"No");
147 if (file->getPriority() == ONLY_SEED_PRIORITY || file->getPriority() == EXCLUDED)
150 return ki18n(
"%1 %").subs(n->percentage, 0,
'f', 2).toString();
151 default:
return QVariant();
154 else if (!
tc->getStats().multi_file_torrent)
156 switch (index.column())
158 case 2:
return QVariant();
162 if (
tc->readyForPreview())
163 return i18nc(
"Preview available",
"Available");
165 return i18nc(
"Preview pending",
"Pending");
168 return i18nc(
"No preview available",
"No");
170 return ki18n(
"%1 %").subs(bt::Percentage(
tc->getStats()), 0,
'f', 2).toString();
171 default:
return QVariant();
174 else if (
tc->getStats().multi_file_torrent && index.column() == 4)
176 return ki18n(
"%1 %").subs(n->percentage, 0,
'f', 2).toString();
182 QVariant IWFileTreeModel::sortData(Node* n,
const QModelIndex & index)
const
184 if (
tc->getStats().multi_file_torrent && n->file)
186 const bt::TorrentFileInterface* file = n->file;
187 switch (index.column())
189 case 2:
return (
int)file->getPriority();
191 if (file->isMultimedia())
193 if (file->isPreviewAvailable())
201 return n->percentage;
204 else if (!
tc->getStats().multi_file_torrent)
206 switch (index.column())
208 case 2:
return QVariant();
212 if (
tc->readyForPreview())
220 return bt::Percentage(
tc->getStats());
223 else if (
tc->getStats().multi_file_torrent && index.column() == 4)
225 return n->percentage;
234 if (role == Qt::CheckStateRole)
237 if (!index.isValid() || role != Qt::UserRole)
240 Node* n =
static_cast<Node*
>(index.internalPointer());
246 for (
int i = 0;i < n->
children.count();i++)
249 setData(index.child(i,0),value,role);
254 bt::TorrentFileInterface* file = n->
file;
255 Priority prio = (bt::Priority)value.toInt();
256 Priority old = file->getPriority();
260 file->setPriority(prio);
261 dataChanged(createIndex(index.row(),0),createIndex(index.row(),4));
262 QModelIndex
parent = index.parent();
263 if (parent.isValid())
264 dataChanged(parent,parent);
285 Node* n = (Node*)idx.internalPointer();
286 if (n->file && n->file == file)
288 QModelIndex i = createIndex(idx.row(),col,n);
289 emit dataChanged(i,i);
295 BitSet d =
tc->downloadedChunksBitSet();
296 d -=
tc->onlySeedChunksBitSet();
297 n->updatePercentage(d);
300 QModelIndex
parent = idx.parent();
301 while (parent.isValid())
303 Node* nd = (Node*)parent.internalPointer();
304 i = createIndex(parent.row(),4,nd);
305 emit dataChanged(i,i);
306 parent = parent.parent();
312 for (
int i = 0;i < n->children.count();i++)
315 update(idx.child(i,0),file,col);
322 if (!
tc->getStats().multi_file_torrent)
324 bool changed =
false;
325 bool np = mmfile &&
tc->readyForPreview();
332 double perc = bt::Percentage(
tc->getStats());
333 if (fabs(perc - percentage) > 0.01)
340 dataChanged(createIndex(0,2),createIndex(0,4));
345 #include "iwfiletreemodel.moc"
bt::TorrentInterface * tc
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
void filePercentageChanged(bt::TorrentFileInterface *file, float percentage)
virtual QModelIndex parent(const QModelIndex &index) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
void initPercentage(const bt::TorrentInterface *tc, const bt::BitSet &havechunks)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
Model for displaying file trees of a torrent.
bt::TorrentFileInterface * file
virtual int columnCount(const QModelIndex &parent) const
static QString PriorityString(const bt::TorrentFileInterface *file)
virtual ~IWFileTreeModel()
virtual QVariant data(const QModelIndex &index, int role) const
void filePreviewChanged(bt::TorrentFileInterface *file, bool preview)
virtual void update()
Update gui if necessary.
virtual QVariant data(const QModelIndex &index, int role) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)