示例#1
0
QVariant TorrentModelItem::data(int column, int role) const
{
    if ((role == Qt::DecorationRole) && (column == TR_NAME))
        return getIconByState(state());

    if (role == Qt::ForegroundRole)
        return getColorByState(state());

    if ((role != Qt::DisplayRole) && (role != Qt::UserRole))
        return QVariant();

    switch(column) {
    case TR_NAME:
        return m_torrent->name();
    case TR_PRIORITY:
        return m_torrent->queuePosition();
    case TR_SIZE:
        return m_torrent->hasMetadata() ? m_torrent->wantedSize() : -1;
    case TR_PROGRESS:
        return m_torrent->progress();
    case TR_STATUS:
        return static_cast<int>(m_torrent->state());
    case TR_SEEDS:
        return (role == Qt::DisplayRole) ? m_torrent->seedsCount() : m_torrent->completeCount();
    case TR_PEERS:
        return (role == Qt::DisplayRole) ? (m_torrent->peersCount() - m_torrent->seedsCount()) : m_torrent->incompleteCount();
    case TR_DLSPEED:
        return m_torrent->downloadPayloadRate();
    case TR_UPSPEED:
        return m_torrent->uploadPayloadRate();
    case TR_ETA:
        return m_torrent->eta();
    case TR_RATIO:
        return m_torrent->realRatio();
    case TR_LABEL:
        return m_torrent->label();
    case TR_ADD_DATE:
        return m_torrent->addedTime();
    case TR_SEED_DATE:
        return m_torrent->completedTime();
    case TR_TRACKER:
        return m_torrent->currentTracker();
    case TR_DLLIMIT:
        return m_torrent->downloadLimit();
    case TR_UPLIMIT:
        return m_torrent->uploadLimit();
    case TR_AMOUNT_DOWNLOADED:
        return m_torrent->totalDownload();
    case TR_AMOUNT_UPLOADED:
        return m_torrent->totalUpload();
    case TR_AMOUNT_DOWNLOADED_SESSION:
        return m_torrent->totalPayloadDownload();
    case TR_AMOUNT_UPLOADED_SESSION:
        return m_torrent->totalPayloadUpload();
    case TR_AMOUNT_LEFT:
        return m_torrent->incompletedSize();
    case TR_TIME_ELAPSED:
        return (role == Qt::DisplayRole) ? m_torrent->activeTime() : m_torrent->seedingTime();
    case TR_SAVE_PATH:
        return m_torrent->savePathParsed();
    case TR_COMPLETED:
        return m_torrent->completedSize();
    case TR_RATIO_LIMIT:
        return m_torrent->maxRatio();
    case TR_SEEN_COMPLETE_DATE:
        return m_torrent->lastSeenComplete();
    case TR_LAST_ACTIVITY:
        if (m_torrent->isPaused() || m_torrent->isChecking())
            return -1;
        if (m_torrent->timeSinceUpload() < m_torrent->timeSinceDownload())
            return m_torrent->timeSinceUpload();
        else
            return m_torrent->timeSinceDownload();
    case TR_TOTAL_SIZE:
        return m_torrent->hasMetadata() ? m_torrent->totalSize() : -1;
    default:
        return QVariant();
    }
}
示例#2
0
QVariant TorrentModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) return QVariant();

    BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
    if (!torrent) return QVariant();

    if ((role == Qt::DecorationRole) && (index.column() == TR_NAME))
        return getIconByState(torrent->state());

    if (role == Qt::ForegroundRole)
        return getColorByState(torrent->state());

    if ((role != Qt::DisplayRole) && (role != Qt::UserRole))
        return QVariant();

    switch(index.column()) {
    case TR_NAME:
        return torrent->name();
    case TR_PRIORITY:
        return torrent->queuePosition();
    case TR_SIZE:
        return torrent->wantedSize();
    case TR_PROGRESS:
        return torrent->progress();
    case TR_STATUS:
        return static_cast<int>(torrent->state());
    case TR_SEEDS:
        return (role == Qt::DisplayRole) ? torrent->seedsCount() : torrent->completeCount();
    case TR_PEERS:
        return (role == Qt::DisplayRole) ? (torrent->peersCount() - torrent->seedsCount()) : torrent->incompleteCount();
    case TR_DLSPEED:
        return torrent->downloadPayloadRate();
    case TR_UPSPEED:
        return torrent->uploadPayloadRate();
    case TR_ETA:
        return torrent->eta();
    case TR_RATIO:
        return torrent->realRatio();
    case TR_LABEL:
        return torrent->label();
    case TR_ADD_DATE:
        return torrent->addedTime();
    case TR_SEED_DATE:
        return torrent->completedTime();
    case TR_TRACKER:
        return torrent->currentTracker();
    case TR_DLLIMIT:
        return torrent->downloadLimit();
    case TR_UPLIMIT:
        return torrent->uploadLimit();
    case TR_AMOUNT_DOWNLOADED:
        return torrent->totalDownload();
    case TR_AMOUNT_UPLOADED:
        return torrent->totalUpload();
    case TR_AMOUNT_DOWNLOADED_SESSION:
        return torrent->totalPayloadDownload();
    case TR_AMOUNT_UPLOADED_SESSION:
        return torrent->totalPayloadUpload();
    case TR_AMOUNT_LEFT:
        return torrent->incompletedSize();
    case TR_TIME_ELAPSED:
        return (role == Qt::DisplayRole) ? torrent->activeTime() : torrent->seedingTime();
    case TR_SAVE_PATH:
        return Utils::Fs::toNativePath(torrent->rootPath());
    case TR_COMPLETED:
        return torrent->completedSize();
    case TR_RATIO_LIMIT:
        return torrent->maxRatio();
    case TR_SEEN_COMPLETE_DATE:
        return torrent->lastSeenComplete();
    case TR_LAST_ACTIVITY:
        if (torrent->isPaused() || torrent->isChecking())
            return -1;
        return torrent->timeSinceActivity();
    case TR_TOTAL_SIZE:
        return  torrent->totalSize();
    default:
        return QVariant();
    }

    return QVariant();
}