本文整理汇总了C++中QTorrentHandle::trackers方法的典型用法代码示例。如果您正苦于以下问题:C++ QTorrentHandle::trackers方法的具体用法?C++ QTorrentHandle::trackers怎么用?C++ QTorrentHandle::trackers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTorrentHandle
的用法示例。
在下文中一共展示了QTorrentHandle::trackers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTrackersForTorrent
/**
* Returns the trackers for a torrent in JSON format.
*
* The return value is a JSON-formatted list of dictionaries.
* The dictionary keys are:
* - "url": Tracker URL
* - "status": Tracker status
* - "num_peers": Tracker peer count
* - "msg": Tracker message (last)
*/
QByteArray btjson::getTrackersForTorrent(const QString& hash)
{
CACHED_VARIABLE_FOR_HASH(QVariantList, tracker_list, CACHE_DURATION_MS, hash);
try {
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
QHash<QString, TrackerInfos> trackers_data = QBtSession::instance()->getTrackersInfo(hash);
std::vector<announce_entry> vect_trackers = h.trackers();
std::vector<announce_entry>::const_iterator it = vect_trackers.begin();
std::vector<announce_entry>::const_iterator end = vect_trackers.end();
for (; it != end; ++it) {
QVariantMap tracker_dict;
const QString tracker_url = misc::toQString(it->url);
tracker_dict[KEY_TRACKER_URL] = tracker_url;
const TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
QString status;
if (it->verified) {
status = tr("Working");
}
else {
if (it->updating && it->fails == 0)
status = tr("Updating...");
else
status = it->fails > 0 ? tr("Not working") : tr("Not contacted yet");
}
tracker_dict[KEY_TRACKER_STATUS] = status;
tracker_dict[KEY_TRACKER_PEERS] = static_cast<qulonglong>(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers);
tracker_dict[KEY_TRACKER_MSG] = data.last_message.trimmed();
tracker_list.append(tracker_dict);
}
}
catch (const std::exception& e) {
qWarning() << Q_FUNC_INFO << "Invalid torrent: " << misc::toQStringU(e.what());
return QByteArray();
}
return json::toJson(tracker_list);
}