Esempio n. 1
0
QVariant FileModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || index.row() > m_files.size()-1)
        return QVariant();

    StatFileInfo info = m_files.at(index.row());
    switch (role) {

    case Qt::DisplayRole:
    case FilenameRole:
        return info.fileName();

    case FileKindRole:
        return info.kind();

    case FileIconRole:
        return infoToIconName(info);

    case PermissionsRole:
        return permissionsToString(info.permissions());

    case SizeRole:
        if (info.isSymLink() && info.isDirAtEnd()) return tr("dir-link");
        if (info.isDir()) return tr("dir");
        return filesizeToString(info.size());

    case LastModifiedRole:
        return datetimeToString(info.lastModified());

    case CreatedRole:
        return datetimeToString(info.created());

    case IsDirRole:
        return info.isDirAtEnd();

    case IsLinkRole:
        return info.isSymLink();

    case SymLinkTargetRole:
        return info.symLinkTarget();

    case IsSelectedRole:
        return info.isSelected();

    default:
        return QVariant();
    }
}
Esempio n. 2
0
QString infoToIconName(const StatFileInfo &info)
{
    if (info.isSymLink() && info.isDirAtEnd()) return "folder-link";
    if (info.isDir()) return "folder";
    if (info.isSymLink()) return "link";
    if (info.isFileAtEnd()) {
        QString suffix = info.suffix().toLower();
        return suffixToIconName(suffix);
    }
    return "file";
}