32 m_status(
Job::Stopped),
34 m_checkusmVerified(0),
35 m_signatureVerified(0),
42 qDeleteAll(m_childItems);
47 m_childItems.append(child);
52 return m_childItems.value(row);
57 return m_childItems.count();
62 return m_childItems.isEmpty();
74 if (role == Qt::CheckStateRole)
78 else if (role == Qt::DisplayRole)
82 else if (role == Qt::DecorationRole)
84 if (m_mimeType.isNull()) {
86 m_mimeType = KIcon(KMimeType::iconNameForUrl(KUrl(m_name)));
88 m_mimeType = KIcon(
"folder");
97 if ((role == Qt::DisplayRole) || (role == Qt::DecorationRole))
106 if (role == Qt::DisplayRole)
108 return KIO::convertSize(m_totalSize);
111 if (role == Qt::DecorationRole) {
112 switch (m_checkusmVerified) {
114 return KIcon(
"dialog-ok");
116 return KIcon(
"dialog-error");
123 if (role == Qt::DecorationRole) {
124 switch (m_signatureVerified) {
126 return KIcon(
"dialog-ok");
128 return KIcon(
"dialog-information");
130 return KIcon(
"dialog-warning");
132 return KIcon(
"dialog-error");
152 if (role == Qt::CheckStateRole)
154 m_state =
static_cast<Qt::CheckState
>(value.toInt());
155 model->changeData(this->
row(), column,
this);
156 checkParents(m_state, model);
157 checkChildren(m_state, model);
160 else if (role == Qt::EditRole)
162 m_name = value.toString();
163 model->changeData(this->
row(), column,
this);
169 if (role == Qt::EditRole)
172 m_status =
static_cast<Job::Status>(value.toInt());
174 model->changeData(this->
row(), column,
this, finished);
182 if (role == Qt::EditRole)
184 KIO::fileoffset_t newSize = value.toLongLong();
187 m_parent->addSize(newSize - m_totalSize, model);
189 m_totalSize = newSize;
190 model->changeData(this->
row(), column,
this);
194 m_checkusmVerified = value.toInt();
195 model->changeData(this->
row(), column,
this);
198 m_signatureVerified = value.toInt();
199 model->changeData(this->
row(), column,
this);
206 void FileItem::checkParents(Qt::CheckState state,
FileModel *model)
220 if (child->m_state != state)
222 state = Qt::Unchecked;
227 m_parent->m_state = state;
229 m_parent->checkParents(state, model);
232 void FileItem::checkChildren(Qt::CheckState state,
FileModel *model)
242 foreach (
FileItem *child, m_childItems)
244 child->checkChildren(state, model);
257 return m_parent->m_childItems.indexOf(const_cast<FileItem*>(
this));
263 void FileItem::addSize(KIO::fileoffset_t size,
FileModel *model)
271 m_parent->addSize(size, model);
279 m_destDirectory(destDirectory),
280 m_checkStateChanged(false)
283 m_header << i18nc(
"file in a filesystem",
"File") << i18nc(
"status of the download",
"Status") << i18nc(
"size of the download",
"Size") << i18nc(
"checksum of a file",
"Checksum") << i18nc(
"signature of a file",
"Signature");
285 setupModelData(files);
293 void FileModel::setupModelData(
const QList<KUrl> &files)
295 QString destDirectory = m_destDirectory.pathOrUrl();
297 foreach (
const KUrl &file, files)
300 QStringList directories = file.pathOrUrl().remove(destDirectory).split(
'/', QString::SkipEmptyParts);
302 while (directories.count())
304 QString part = directories.takeFirst();
305 for (
int i = 0; i < parent->
childCount(); ++i)
308 if (parent->
child(i)->
data(0, Qt::DisplayRole).toString() == part)
310 parent = parent->
child(i);
312 if (!directories.count())
316 part = directories.takeFirst();
327 m_files.append(child);
334 if (parent.isValid())
346 if (!index.isValid())
353 const QVariant
data = item->
data(index.column(), role);
360 if (role == Qt::DisplayRole)
362 if (m_customStatusTexts.contains(status))
364 return m_customStatusTexts[status];
371 else if (role == Qt::DecorationRole)
373 if (m_customStatusIcons.contains(status))
375 return m_customStatusIcons[status];
392 if (!index.isValid())
399 if ((index.column() ==
FileItem::File) && (role == Qt::CheckStateRole)) {
400 const bool worked = item->
setData(index.column(), value,
this, role);
402 m_checkStateChanged =
true;
408 return item->
setData(index.column(), value,
this, role);
413 if (!index.isValid())
420 return QAbstractItemModel::flags(index) | Qt::ItemIsUserCheckable;
423 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
428 if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
430 return m_header.value(section);
438 if (!hasIndex(row, column, parent))
440 return QModelIndex();
444 if (parent.isValid())
446 parentItem =
static_cast<FileItem*
>(parent.internalPointer());
450 parentItem = m_rootItem;
456 return createIndex(row, column, childItem);
460 return QModelIndex();
469 return QModelIndex();
472 return createIndex(item->
row(), column, item);
477 QModelIndexList indexList;
480 int row = item->
row();
481 indexList.append(createIndex(row, column, item));
489 if (!index.isValid())
491 return QModelIndex();
496 if ((parentItem == m_rootItem) || (!parentItem))
498 return QModelIndex();
502 return createIndex(parentItem->
row(), 0, parentItem);
508 if (parent.column() > 0)
514 if (parent.isValid())
516 parentItem =
static_cast<FileItem*
>(parent.internalPointer());
520 parentItem = m_rootItem;
526 void FileModel::changeData(
int row,
int column,
FileItem *item,
bool finished)
528 QModelIndex
index = createIndex(row, column, item);
529 emit dataChanged(index, index);
532 const KUrl file =
getUrl(index);
540 m_destDirectory = newDirectory;
546 if (!index.isValid()) {
550 const QModelIndex file = index.sibling(index.row(),
FileItem::File);
552 return getUrl(static_cast<FileItem*>(file.internalPointer()));
557 const QString path = getPath(item);
559 KUrl url = m_destDirectory;
560 url.addPath(path + name);
565 QString FileModel::getPath(
FileItem *item)
569 while (parent && parent->
parent())
572 parent = parent->
parent();
578 FileItem *FileModel::getItem(
const KUrl &file)
580 if (m_itemCache.contains(file))
582 return m_itemCache[file];
585 QString destDirectory = m_destDirectory.pathOrUrl();
588 QStringList directories = file.pathOrUrl().remove(destDirectory).split(
'/', QString::SkipEmptyParts);
589 while (directories.count())
591 QString part = directories.takeFirst();
597 item = item->
child(i);
599 if (!directories.count())
603 part = directories.takeFirst();
610 if (item == m_rootItem)
616 m_itemCache[file] = item;
639 if (!index.isValid()) {
663 QString oldName = file.
data(Qt::DisplayRole).toString();
664 QString path = getPath(item);
666 KUrl oldUrl = m_destDirectory;
667 oldUrl.addPath(path + oldName);
668 KUrl newUrl = m_destDirectory;
669 newUrl.addPath(path + newName);
671 m_itemCache.remove(oldUrl);
675 emit
rename(oldUrl, newUrl);
678 void FileModel::renameFailed(
const KUrl &beforeRename,
const KUrl &afterRename)
680 Q_UNUSED(beforeRename)
681 Q_UNUSED(afterRename)
686 m_checkStateChanged =
false;
691 if (m_checkStateChanged)
696 m_checkStateChanged =
false;
Qt::ItemFlags flags(const QModelIndex &index) const
QPixmap statusPixmap() const
The job is stopped, but this also indicates that it stopped because an error occurred.
void appendChild(FileItem *child)
Status
The status property describes the current job status.
FileItem(const QString &name, FileItem *parent=0)
void stopWatchCheckState()
Emits checkStateChanged if a CheckState of an entry changend.
bool setData(int column, const QVariant &value, FileModel *model, int role=Qt::EditRole)
void fileFinished(const KUrl &file)
QModelIndex parent(const QModelIndex &index) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
QModelIndexList fileIndexes(int column) const
Returns a list of pointers to all files of this model.
void watchCheckState()
Watches if the check state changes, the result of that will be emitted when stopWatchCheckState() is ...
This model represents the files that are being downloaded.
int rowCount(const QModelIndex &parent=QModelIndex()) const
FileItem * child(int row)
void setDirectory(const KUrl &newDirectory)
Set the url to the directory the files are stored in, the filemodel stores its entries as relative pa...
FileModel(const QList< KUrl > &files, const KUrl &destDirectory, QObject *parent=0)
QString statusText() const
void rename(const QModelIndex &file, const QString &newName)
QVariant data(const QModelIndex &index, int role) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
int columnCount(const QModelIndex &parent=QModelIndex()) const
bool downloadFinished(const KUrl &file)
Checks if the download for file has been finished.
KUrl getUrl(const QModelIndex &index)
The url on the filesystem (no check if the file exists yet!) of index, it can be a folder or file...
QVariant data(int column, int role) const
bool isFile() const
Returns true if the index represents a file.
bool isFile(const QModelIndex &index) const
Returns true if the index represents a file.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const