26 #include <util/functions.h>
27 #include <interfaces/torrentinterface.h>
28 #include <interfaces/torrentfileinterface.h>
35 IWFileListModel::IWFileListModel(bt::TorrentInterface* tc,
QObject* parent)
38 mmfile = IsMultimediaFile(tc->getStats().output_path);
50 if (!parent.isValid())
58 if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
66 case 2:
return i18n(
"Priority");
67 case 3:
return i18n(
"Preview");
69 case 4:
return i18nc(
"Percent of File Downloaded",
"% Complete");
70 default:
return QVariant();
76 switch(file->getPriority())
78 case FIRST_PRIORITY:
return i18nc(
"Download first",
"First");
79 case LAST_PRIORITY:
return i18nc(
"Download last",
"Last");
80 case ONLY_SEED_PRIORITY:
82 case PREVIEW_PRIORITY:
84 default:
return i18nc(
"Download Normal (not as first or last)",
"Normal");
90 if (index.column() < 2 && role != Qt::ForegroundRole)
93 if (!index.isValid() || index.row() < 0 || index.row() >=
rowCount(QModelIndex()))
96 if (role == Qt::ForegroundRole && index.column() == 2 &&
tc->getStats().multi_file_torrent)
98 const bt::TorrentFileInterface* file = &
tc->getTorrentFile(index.row());
99 switch (file->getPriority())
115 if (role == Qt::DisplayRole)
116 return displayData(index);
117 else if (role == Qt::UserRole)
118 return sortData(index);
123 QVariant IWFileListModel::displayData(
const QModelIndex & index)
const
125 if (
tc->getStats().multi_file_torrent)
127 const bt::TorrentFileInterface* file = &
tc->getTorrentFile(index.row());
128 switch (index.column())
132 if (file->isMultimedia())
134 if (file->isPreviewAvailable())
135 return i18nc(
"Preview available",
"Available");
137 return i18nc(
"Preview pending",
"Pending");
140 return i18nc(
"No preview available",
"No");
143 float percent = file->getDownloadPercentage();
144 return ki18n(
"%1 %").subs(percent, 0,
'f', 2).toString();
146 default:
return QVariant();
151 switch (index.column())
153 case 2:
return QVariant();
157 if (
tc->readyForPreview())
158 return i18nc(
"Preview available",
"Available");
160 return i18nc(
"Preview pending",
"Pending");
163 return i18nc(
"No preview available",
"No");
166 double percent = bt::Percentage(
tc->getStats());
167 return ki18n(
"%1 %").subs(percent, 0,
'f', 2).toString();
169 default:
return QVariant();
175 QVariant IWFileListModel::sortData(
const QModelIndex & index)
const
177 if (
tc->getStats().multi_file_torrent)
179 const bt::TorrentFileInterface* file = &
tc->getTorrentFile(index.row());
180 switch (index.column())
182 case 2:
return (
int)file->getPriority();
184 if (file->isMultimedia())
186 if (file->isPreviewAvailable())
194 return file->getDownloadPercentage();
199 switch (index.column())
201 case 2:
return QVariant();
205 if (
tc->readyForPreview())
213 return bt::Percentage(
tc->getStats());
222 if (role == Qt::CheckStateRole)
225 if (!index.isValid() || role != Qt::UserRole)
229 if (r < 0 || r >=
rowCount(QModelIndex()))
232 bt::TorrentFileInterface & file =
tc->getTorrentFile(r);;
233 Priority prio = (bt::Priority)value.toInt();
234 Priority old = file.getPriority();
238 file.setPriority(prio);
239 dataChanged(createIndex(index.row(),0),createIndex(index.row(),4));
248 QModelIndex idx = createIndex(file->getIndex(),4,file);
249 emit dataChanged(idx,idx);
255 QModelIndex idx = createIndex(file->getIndex(),3,file);
256 emit dataChanged(idx,idx);
261 if (!
tc->getStats().multi_file_torrent)
263 bool changed =
false;
264 bool np = mmfile &&
tc->readyForPreview();
271 double perc = bt::Percentage(
tc->getStats());
272 if (fabs(perc - percentage) > 0.01)
279 dataChanged(createIndex(0,0),createIndex(0,4));
284 #include "iwfilelistmodel.moc"
virtual QVariant data(const QModelIndex &index, int role) const
void update()
Update gui if necessary.
Model for displaying file trees of a torrent.
bt::TorrentInterface * tc
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual int rowCount(const QModelIndex &parent) const
void filePreviewChanged(bt::TorrentFileInterface *file, bool preview)
virtual QVariant data(const QModelIndex &index, int role) const
virtual ~IWFileListModel()
virtual int columnCount(const QModelIndex &parent) const
static QString PriorityString(const bt::TorrentFileInterface *file)
void filePercentageChanged(bt::TorrentFileInterface *file, float percentage)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)