QString MimetypeModel::formatMimeTypeInfo(const QMimeType &t) { QString result; QTextStream str(&result); str << "<html><head/><body><h3><center>" << t.name() << "</center></h3><br><table>"; const QStringList &aliases = t.aliases(); if (!aliases.isEmpty()) str << "<tr><td>Aliases:</td><td>" << " (" << aliases << ')'; str << "</td></tr>" << "<tr><td>Comment:</td><td>" << t.comment() << "</td></tr>" << "<tr><td>Icon name:</td><td>" << t.iconName() << "</td></tr>" << "<tr><td>Generic icon name</td><td>" << t.genericIconName() << "</td></tr>"; const QString &filter = t.filterString(); if (!filter.isEmpty()) str << "<tr><td>Filter:</td><td>" << t.filterString() << "</td></tr>"; const QStringList &patterns = t.globPatterns(); if (!patterns.isEmpty()) str << "<tr><td>Glob patterns:</td><td>" << patterns << "</td></tr>"; const QStringList &parentMimeTypes = t.parentMimeTypes(); if (!parentMimeTypes.isEmpty()) str << "<tr><td>Parent types:</td><td>" << t.parentMimeTypes() << "</td></tr>"; QStringList suffixes = t.suffixes(); if (!suffixes.isEmpty()) { str << "<tr><td>Suffixes:</td><td>"; const QString &preferredSuffix = t.preferredSuffix(); if (!preferredSuffix.isEmpty()) { suffixes.removeOne(preferredSuffix); str << "<b>" << preferredSuffix << "</b> "; } str << suffixes << "</td></tr>"; } str << "</table></body></html>"; return result; }
QVariant DirModel::data(const QModelIndex &index, int role) const { //its not for QML #if defined(REGRESSION_TEST_FOLDERLISTMODEL) if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::DecorationRole && role != Qt::BackgroundRole) ) { return QVariant(); } if (role == Qt::DecorationRole && index.column() == 0) { QIcon icon; QMimeType mime = mDirectoryContents.at(index.row()).mimeType(); if (mime.isValid()) { if (QIcon::hasThemeIcon(mime.iconName()) ) { icon = QIcon::fromTheme(mime.iconName()); } else if (QIcon::hasThemeIcon(mime.genericIconName())) { icon = QIcon::fromTheme(mime.genericIconName()); } } if (icon.isNull()) { if (mDirectoryContents.at(index.row()).isLocal()) { icon = QFileIconProvider().icon(mDirectoryContents.at(index.row()).diskFileInfo()); } else if (mDirectoryContents.at(index.row()).isDir()) { icon = QFileIconProvider().icon(QFileIconProvider::Folder); } else { icon = QFileIconProvider().icon(QFileIconProvider::File); } } return icon; } if (role == Qt::BackgroundRole && index.column() == 0) { if (mDirectoryContents.at(index.row()).isSelected()) { //TODO it'd better to get some style or other default // background color return QBrush(Qt::lightGray); } return QVariant(); } role = FileNameRole + index.column(); #else if (role < FileNameRole || role > TrackCoverRole) { qWarning() << Q_FUNC_INFO << this << "Got an out of range role: " << role; return QVariant(); } if (index.row() < 0 || index.row() >= mDirectoryContents.count()) { qWarning() << "Attempted to access out of range row: " << index.row(); return QVariant(); } if (index.column() != 0) return QVariant(); #endif const DirItemInfo &fi = mDirectoryContents.at(index.row()); switch (role) { case FileNameRole: return fi.fileName(); case AccessedDateRole: return fi.lastRead(); case CreationDateRole: return fi.created(); case ModifiedDateRole: return fi.lastModified(); case FileSizeRole: { if (fi.isDir() && fi.isLocal()) { return dirItems(fi.diskFileInfo()); } return fileSize(fi.size()); } case IconSourceRole: { const QString &fileName = fi.fileName(); if (fi.isDir()) return QLatin1String("image://theme/icon-m-common-directory"); if (fileName.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive) || fileName.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)) { return QLatin1String("image://nemoThumbnail/") + fi.filePath(); } return "image://theme/icon-m-content-document"; } case FilePathRole: return fi.filePath(); case MimeTypeRole: return fi.mimeType().name(); case MimeTypeDescriptionRole: return fi.mimeType().comment(); case IsDirRole: return fi.isDir(); case IsFileRole: return !fi.isDir(); case IsReadableRole: return fi.isReadable(); case IsWritableRole: return fi.isWritable(); case IsExecutableRole: return fi.isExecutable(); case IsSelectedRole: return fi.isSelected(); #ifndef DO_NOT_USE_TAG_LIB case TrackTitleRole: case TrackArtistRole: case TrackAlbumRole: case TrackYearRole: case TrackNumberRole: case TrackGenreRole: case TrackLengthRole: case TrackCoverRole: if (mReadsMediaMetadata && fi.isLocal()) { return getAudioMetaData(fi.diskFileInfo(), role); } break; #endif default: #if !defined(REGRESSION_TEST_FOLDERLISTMODEL) // this should not happen, ever Q_ASSERT(false); qWarning() << Q_FUNC_INFO << this << "Got an unknown role: " << role; #endif break; } return QVariant(); }
QVariant DTrashItemModel::data(const QModelIndex& index, int role) const { if (role != Qt::DisplayRole && role != Qt::DecorationRole && role != Qt::TextAlignmentRole && role != Qt::ToolTipRole) { return QVariant(); } const DTrashItemInfo& item = d->data[index.row()]; if (role == Qt::TextAlignmentRole) return Qt::AlignCenter; if (role == Qt::DecorationRole && index.column() == 0) { QPixmap pix; QString thumbPath; if (!d->failedThumbnails.contains(item.collectionPath)) { thumbPath = item.collectionPath; } else { thumbPath = item.trashPath; } if (pixmapForItem(thumbPath, pix)) { if (pix.isNull()) { QMimeType mimeType = QMimeDatabase().mimeTypeForFile(item.trashPath); if (mimeType.isValid()) { pix = QIcon::fromTheme(mimeType.genericIconName()).pixmap(128); } } return pix; } else { return QVariant(QVariant::Pixmap); } } if (role == Qt::ToolTipRole && index.column() == 1) return item.collectionRelativePath; switch (index.column()) { case 1: return item.collectionRelativePath; case 2: { QString dateTimeFormat = QLocale().dateTimeFormat(); if (!dateTimeFormat.contains(QLatin1String("yyyy"))) { dateTimeFormat.replace(QLatin1String("yy"), QLatin1String("yyyy")); } return item.deletionTimestamp.toString(dateTimeFormat); } default: return QVariant(); }; }