int TorrentContentModel::getFileIndex(const QModelIndex& index)
{
    TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
    if (item->itemType() == TorrentContentModelItem::FileType)
        return static_cast<TorrentContentModelFile*>(item)->fileIndex();

    Q_ASSERT(item->itemType() == TorrentContentModelItem::FileType);
    return -1;
}
QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid())
        return QVariant();

    TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());

    if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::DecorationRole)) {
        if (item->itemType() == TorrentContentModelItem::FolderType)
            return getDirectoryIcon();
        else
            return getFileIcon();
    }

    if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) {
        if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED)
            return Qt::Unchecked;
        if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::MIXED)
            return Qt::PartiallyChecked;
        return Qt::Checked;
    }

    if (role == Qt::DisplayRole)
        return item->data(index.column());

    return QVariant();
}