本文整理汇总了C++中QTorrentHandle::download_payload_rate方法的典型用法代码示例。如果您正苦于以下问题:C++ QTorrentHandle::download_payload_rate方法的具体用法?C++ QTorrentHandle::download_payload_rate怎么用?C++ QTorrentHandle::download_payload_rate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTorrentHandle
的用法示例。
在下文中一共展示了QTorrentHandle::download_payload_rate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toJson
static JsonDict toJson(const QTorrentHandle& h)
{
JsonDict ret;
ret.add(KEY_TORRENT_HASH, h.hash());
ret.add(KEY_TORRENT_NAME, h.name());
ret.add(KEY_TORRENT_SIZE, misc::friendlyUnit(h.actual_size())); // FIXME: Should pass as Number, not formatted String (for sorting).
ret.add(KEY_TORRENT_PROGRESS, (double)h.progress());
ret.add(KEY_TORRENT_DLSPEED, misc::friendlyUnit(h.download_payload_rate(), true)); // FIXME: Should be passed as a Number
ret.add(KEY_TORRENT_UPSPEED, misc::friendlyUnit(h.upload_payload_rate(), true)); // FIXME: Should be passed as a Number
if (QBtSession::instance()->isQueueingEnabled() && h.queue_position() >= 0)
ret.add(KEY_TORRENT_PRIORITY, QString::number(h.queue_position()));
else
ret.add(KEY_TORRENT_PRIORITY, "*");
QString seeds = QString::number(h.num_seeds());
if (h.num_complete() > 0)
seeds += " ("+QString::number(h.num_complete())+")";
ret.add(KEY_TORRENT_SEEDS, seeds);
QString leechs = QString::number(h.num_peers() - h.num_seeds());
if (h.num_incomplete() > 0)
leechs += " ("+QString::number(h.num_incomplete())+")";
ret.add(KEY_TORRENT_LEECHS, leechs);
const qreal ratio = QBtSession::instance()->getRealRatio(h.hash());
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
ret.add(KEY_TORRENT_RATIO, (ratio > 100.) ? QString::fromUtf8("∞") : QString::number((int)(ratio*10)/10.0, 'f', 1));
QString eta;
QString state;
if (h.is_paused()) {
if (h.has_error())
state = "error";
else
state = h.is_seed() ? "pausedUP" : "pausedDL";
} else {
if (QBtSession::instance()->isQueueingEnabled() && h.is_queued())
state = h.is_seed() ? "queuedUP" : "queuedDL";
else {
switch (h.state()) {
case torrent_status::finished:
case torrent_status::seeding:
state = h.upload_payload_rate() > 0 ? "uploading" : "stalledUP";
break;
case torrent_status::allocating:
case torrent_status::checking_files:
case torrent_status::queued_for_checking:
case torrent_status::checking_resume_data:
state = h.is_seed() ? "checkingUP" : "checkingDL";
break;
case torrent_status::downloading:
case torrent_status::downloading_metadata:
state = h.download_payload_rate() > 0 ? "downloading" : "stalledDL";
eta = misc::userFriendlyDuration(QBtSession::instance()->getETA(h.hash()));
break;
default:
qWarning("Unrecognized torrent status, should not happen!!! status was %d", h.state());
}
}
}
ret.add(KEY_TORRENT_ETA, eta.isEmpty() ? QString::fromUtf8("∞") : eta);
ret.add(KEY_TORRENT_STATE, state);
return ret;
}