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 "icon";//infoToIconName(info);

    case PermissionsRole:
      return "xxx";//permissionsToString(info.permissions());

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

    case LastModifiedRole:
      return "iae";//datetimeToString(info.lastModified());

    case CreatedRole:
      return "ia";//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
void FileModel::toggleSelectedFile(int fileIndex)
{
    if (!m_files.at(fileIndex).isSelected()) {
        StatFileInfo info = m_files.at(fileIndex);
        info.setSelected(true);
        m_files[fileIndex] = info;
        m_selectedFileCount++;
    } else {
        StatFileInfo info = m_files.at(fileIndex);
        info.setSelected(false);
        m_files[fileIndex] = info;
        m_selectedFileCount--;
    }
    // emit signal for views
    QModelIndex topLeft = index(fileIndex, 0);
    QModelIndex bottomRight = index(fileIndex, 0);
    emit dataChanged(topLeft, bottomRight);

    emit selectedFileCountChanged();
}
Esempio n. 3
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";
}