mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Use C++11 uniform initialization
This commit is contained in:
parent
bad588a749
commit
7f300b757f
@ -78,12 +78,13 @@ void LogController::mainAction()
|
||||
|| (msg.type == Log::WARNING && isWarning)
|
||||
|| (msg.type == Log::CRITICAL && isCritical)))
|
||||
continue;
|
||||
QVariantMap map;
|
||||
map[KEY_LOG_ID] = msg.id;
|
||||
map[KEY_LOG_TIMESTAMP] = msg.timestamp;
|
||||
map[KEY_LOG_MSG_TYPE] = msg.type;
|
||||
map[KEY_LOG_MSG_MESSAGE] = msg.message;
|
||||
msgList.append(map);
|
||||
|
||||
msgList.append(QVariantMap {
|
||||
{KEY_LOG_ID, msg.id},
|
||||
{KEY_LOG_TIMESTAMP, msg.timestamp},
|
||||
{KEY_LOG_MSG_TYPE, msg.type},
|
||||
{KEY_LOG_MSG_MESSAGE, msg.message}
|
||||
});
|
||||
}
|
||||
|
||||
setResult(QJsonArray::fromVariantList(msgList));
|
||||
@ -112,13 +113,13 @@ void LogController::peersAction()
|
||||
QVariantList peerList;
|
||||
|
||||
for (const Log::Peer &peer : asConst(logger->getPeers(lastKnownId))) {
|
||||
QVariantMap map;
|
||||
map[KEY_LOG_ID] = peer.id;
|
||||
map[KEY_LOG_TIMESTAMP] = peer.timestamp;
|
||||
map[KEY_LOG_PEER_IP] = peer.ip;
|
||||
map[KEY_LOG_PEER_BLOCKED] = peer.blocked;
|
||||
map[KEY_LOG_PEER_REASON] = peer.reason;
|
||||
peerList.append(map);
|
||||
peerList.append(QVariantMap {
|
||||
{KEY_LOG_ID, peer.id},
|
||||
{KEY_LOG_TIMESTAMP, peer.timestamp},
|
||||
{KEY_LOG_PEER_IP, peer.ip},
|
||||
{KEY_LOG_PEER_BLOCKED, peer.blocked},
|
||||
{KEY_LOG_PEER_REASON, peer.reason}
|
||||
});
|
||||
}
|
||||
|
||||
setResult(QJsonArray::fromVariantList(peerList));
|
||||
|
@ -82,50 +82,55 @@ namespace
|
||||
|
||||
QVariantMap serialize(const BitTorrent::TorrentHandle &torrent)
|
||||
{
|
||||
QVariantMap ret;
|
||||
ret[KEY_TORRENT_HASH] = QString(torrent.hash());
|
||||
ret[KEY_TORRENT_NAME] = torrent.name();
|
||||
ret[KEY_TORRENT_MAGNET_URI] = torrent.toMagnetUri();
|
||||
ret[KEY_TORRENT_SIZE] = torrent.wantedSize();
|
||||
ret[KEY_TORRENT_PROGRESS] = torrent.progress();
|
||||
ret[KEY_TORRENT_DLSPEED] = torrent.downloadPayloadRate();
|
||||
ret[KEY_TORRENT_UPSPEED] = torrent.uploadPayloadRate();
|
||||
ret[KEY_TORRENT_QUEUE_POSITION] = static_cast<int>(torrent.queuePosition());
|
||||
ret[KEY_TORRENT_SEEDS] = torrent.seedsCount();
|
||||
ret[KEY_TORRENT_NUM_COMPLETE] = torrent.totalSeedsCount();
|
||||
ret[KEY_TORRENT_LEECHS] = torrent.leechsCount();
|
||||
ret[KEY_TORRENT_NUM_INCOMPLETE] = torrent.totalLeechersCount();
|
||||
QVariantMap ret = {
|
||||
{KEY_TORRENT_HASH, QString(torrent.hash())},
|
||||
{KEY_TORRENT_NAME, torrent.name()},
|
||||
{KEY_TORRENT_MAGNET_URI, torrent.toMagnetUri()},
|
||||
{KEY_TORRENT_SIZE, torrent.wantedSize()},
|
||||
{KEY_TORRENT_PROGRESS, torrent.progress()},
|
||||
{KEY_TORRENT_DLSPEED, torrent.downloadPayloadRate()},
|
||||
{KEY_TORRENT_UPSPEED, torrent.uploadPayloadRate()},
|
||||
{KEY_TORRENT_QUEUE_POSITION, torrent.queuePosition()},
|
||||
{KEY_TORRENT_SEEDS, torrent.seedsCount()},
|
||||
{KEY_TORRENT_NUM_COMPLETE, torrent.totalSeedsCount()},
|
||||
{KEY_TORRENT_LEECHS, torrent.leechsCount()},
|
||||
{KEY_TORRENT_NUM_INCOMPLETE, torrent.totalLeechersCount()},
|
||||
|
||||
{KEY_TORRENT_STATE, torrentStateToString(torrent.state())},
|
||||
{KEY_TORRENT_ETA, torrent.eta()},
|
||||
{KEY_TORRENT_SEQUENTIAL_DOWNLOAD, torrent.isSequentialDownload()},
|
||||
{KEY_TORRENT_FIRST_LAST_PIECE_PRIO, torrent.hasFirstLastPiecePriority()},
|
||||
|
||||
{KEY_TORRENT_CATEGORY, torrent.category()},
|
||||
{KEY_TORRENT_TAGS, torrent.tags().toList().join(", ")},
|
||||
{KEY_TORRENT_SUPER_SEEDING, torrent.superSeeding()},
|
||||
{KEY_TORRENT_FORCE_START, torrent.isForced()},
|
||||
{KEY_TORRENT_SAVE_PATH, Utils::Fs::toNativePath(torrent.savePath())},
|
||||
{KEY_TORRENT_ADDED_ON, torrent.addedTime().toTime_t()},
|
||||
{KEY_TORRENT_COMPLETION_ON, torrent.completedTime().toTime_t()},
|
||||
{KEY_TORRENT_TRACKER, torrent.currentTracker()},
|
||||
{KEY_TORRENT_DL_LIMIT, torrent.downloadLimit()},
|
||||
{KEY_TORRENT_UP_LIMIT, torrent.uploadLimit()},
|
||||
{KEY_TORRENT_AMOUNT_DOWNLOADED, torrent.totalDownload()},
|
||||
{KEY_TORRENT_AMOUNT_UPLOADED, torrent.totalUpload()},
|
||||
{KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION, torrent.totalPayloadDownload()},
|
||||
{KEY_TORRENT_AMOUNT_UPLOADED_SESSION, torrent.totalPayloadUpload()},
|
||||
{KEY_TORRENT_AMOUNT_LEFT, torrent.incompletedSize()},
|
||||
{KEY_TORRENT_AMOUNT_COMPLETED, torrent.completedSize()},
|
||||
{KEY_TORRENT_MAX_RATIO, torrent.maxRatio()},
|
||||
{KEY_TORRENT_MAX_SEEDING_TIME, torrent.maxSeedingTime()},
|
||||
{KEY_TORRENT_RATIO_LIMIT, torrent.ratioLimit()},
|
||||
{KEY_TORRENT_SEEDING_TIME_LIMIT, torrent.seedingTimeLimit()},
|
||||
{KEY_TORRENT_LAST_SEEN_COMPLETE_TIME, torrent.lastSeenComplete().toTime_t()},
|
||||
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
|
||||
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
|
||||
{KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()},
|
||||
|
||||
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
|
||||
};
|
||||
|
||||
const qreal ratio = torrent.realRatio();
|
||||
ret[KEY_TORRENT_RATIO] = (ratio > BitTorrent::TorrentHandle::MAX_RATIO) ? -1 : ratio;
|
||||
ret[KEY_TORRENT_STATE] = torrentStateToString(torrent.state());
|
||||
ret[KEY_TORRENT_ETA] = torrent.eta();
|
||||
ret[KEY_TORRENT_SEQUENTIAL_DOWNLOAD] = torrent.isSequentialDownload();
|
||||
if (torrent.hasMetadata())
|
||||
ret[KEY_TORRENT_FIRST_LAST_PIECE_PRIO] = torrent.hasFirstLastPiecePriority();
|
||||
ret[KEY_TORRENT_CATEGORY] = torrent.category();
|
||||
ret[KEY_TORRENT_TAGS] = torrent.tags().toList().join(", ");
|
||||
ret[KEY_TORRENT_SUPER_SEEDING] = torrent.superSeeding();
|
||||
ret[KEY_TORRENT_FORCE_START] = torrent.isForced();
|
||||
ret[KEY_TORRENT_SAVE_PATH] = Utils::Fs::toNativePath(torrent.savePath());
|
||||
ret[KEY_TORRENT_ADDED_ON] = torrent.addedTime().toTime_t();
|
||||
ret[KEY_TORRENT_COMPLETION_ON] = torrent.completedTime().toTime_t();
|
||||
ret[KEY_TORRENT_TRACKER] = torrent.currentTracker();
|
||||
ret[KEY_TORRENT_DL_LIMIT] = torrent.downloadLimit();
|
||||
ret[KEY_TORRENT_UP_LIMIT] = torrent.uploadLimit();
|
||||
ret[KEY_TORRENT_AMOUNT_DOWNLOADED] = torrent.totalDownload();
|
||||
ret[KEY_TORRENT_AMOUNT_UPLOADED] = torrent.totalUpload();
|
||||
ret[KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION] = torrent.totalPayloadDownload();
|
||||
ret[KEY_TORRENT_AMOUNT_UPLOADED_SESSION] = torrent.totalPayloadUpload();
|
||||
ret[KEY_TORRENT_AMOUNT_LEFT] = torrent.incompletedSize();
|
||||
ret[KEY_TORRENT_AMOUNT_COMPLETED] = torrent.completedSize();
|
||||
ret[KEY_TORRENT_MAX_RATIO] = torrent.maxRatio();
|
||||
ret[KEY_TORRENT_MAX_SEEDING_TIME] = torrent.maxSeedingTime();
|
||||
ret[KEY_TORRENT_RATIO_LIMIT] = torrent.ratioLimit();
|
||||
ret[KEY_TORRENT_SEEDING_TIME_LIMIT] = torrent.seedingTimeLimit();
|
||||
ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent.lastSeenComplete().toTime_t();
|
||||
ret[KEY_TORRENT_AUTO_TORRENT_MANAGEMENT] = torrent.isAutoTMMEnabled();
|
||||
ret[KEY_TORRENT_TIME_ACTIVE] = torrent.activeTime();
|
||||
ret[KEY_TORRENT_AVAILABILITY] = torrent.distributedCopies();
|
||||
|
||||
if (torrent.isPaused() || torrent.isChecking()) {
|
||||
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0;
|
||||
@ -136,7 +141,5 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent)
|
||||
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = dt.toTime_t();
|
||||
}
|
||||
|
||||
ret[KEY_TORRENT_TOTAL_SIZE] = torrent.totalSize();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -503,26 +503,28 @@ void SyncController::torrentPeersAction()
|
||||
for (const BitTorrent::PeerInfo &pi : peersList) {
|
||||
if (pi.address().ip.isNull()) continue;
|
||||
|
||||
QVariantMap peer;
|
||||
QVariantMap peer = {
|
||||
{KEY_PEER_IP, pi.address().ip.toString()},
|
||||
{KEY_PEER_PORT, pi.address().port},
|
||||
{KEY_PEER_CLIENT, pi.client()},
|
||||
{KEY_PEER_PROGRESS, pi.progress()},
|
||||
{KEY_PEER_DOWN_SPEED, pi.payloadDownSpeed()},
|
||||
{KEY_PEER_UP_SPEED, pi.payloadUpSpeed()},
|
||||
{KEY_PEER_TOT_DOWN, pi.totalDownload()},
|
||||
{KEY_PEER_TOT_UP, pi.totalUpload()},
|
||||
{KEY_PEER_CONNECTION_TYPE, pi.connectionType()},
|
||||
{KEY_PEER_FLAGS, pi.flags()},
|
||||
{KEY_PEER_FLAGS_DESCRIPTION, pi.flagsDescription()},
|
||||
{KEY_PEER_RELEVANCE, pi.relevance()},
|
||||
{KEY_PEER_FILES, torrent->info().filesForPiece(pi.downloadingPieceIndex()).join('\n')}
|
||||
};
|
||||
|
||||
#ifndef DISABLE_COUNTRIES_RESOLUTION
|
||||
if (resolvePeerCountries) {
|
||||
peer[KEY_PEER_COUNTRY_CODE] = pi.country().toLower();
|
||||
peer[KEY_PEER_COUNTRY] = Net::GeoIPManager::CountryName(pi.country());
|
||||
}
|
||||
#endif
|
||||
peer[KEY_PEER_IP] = pi.address().ip.toString();
|
||||
peer[KEY_PEER_PORT] = pi.address().port;
|
||||
peer[KEY_PEER_CLIENT] = pi.client();
|
||||
peer[KEY_PEER_PROGRESS] = pi.progress();
|
||||
peer[KEY_PEER_DOWN_SPEED] = pi.payloadDownSpeed();
|
||||
peer[KEY_PEER_UP_SPEED] = pi.payloadUpSpeed();
|
||||
peer[KEY_PEER_TOT_DOWN] = pi.totalDownload();
|
||||
peer[KEY_PEER_TOT_UP] = pi.totalUpload();
|
||||
peer[KEY_PEER_CONNECTION_TYPE] = pi.connectionType();
|
||||
peer[KEY_PEER_FLAGS] = pi.flags();
|
||||
peer[KEY_PEER_FLAGS_DESCRIPTION] = pi.flagsDescription();
|
||||
peer[KEY_PEER_RELEVANCE] = pi.relevance();
|
||||
peer[KEY_PEER_FILES] = torrent->info().filesForPiece(pi.downloadingPieceIndex()).join(QLatin1String("\n"));
|
||||
|
||||
peers[pi.address().ip.toString() + ':' + QString::number(pi.address().port)] = peer;
|
||||
}
|
||||
|
@ -417,9 +417,9 @@ void TorrentsController::webseedsAction()
|
||||
throw APIError(APIErrorType::NotFound);
|
||||
|
||||
for (const QUrl &webseed : asConst(torrent->urlSeeds())) {
|
||||
QVariantMap webSeedDict;
|
||||
webSeedDict[KEY_WEBSEED_URL] = webseed.toString();
|
||||
webSeedList.append(webSeedDict);
|
||||
webSeedList.append(QVariantMap {
|
||||
{KEY_WEBSEED_URL, webseed.toString()}
|
||||
});
|
||||
}
|
||||
|
||||
setResult(QJsonArray::fromVariantList(webSeedList));
|
||||
@ -451,11 +451,12 @@ void TorrentsController::filesAction()
|
||||
const QVector<qreal> fileAvailability = torrent->availableFileFractions();
|
||||
const BitTorrent::TorrentInfo info = torrent->info();
|
||||
for (int i = 0; i < torrent->filesCount(); ++i) {
|
||||
QVariantMap fileDict;
|
||||
fileDict[KEY_FILE_PROGRESS] = fp[i];
|
||||
fileDict[KEY_FILE_PRIORITY] = static_cast<int>(priorities[i]);
|
||||
fileDict[KEY_FILE_SIZE] = torrent->fileSize(i);
|
||||
fileDict[KEY_FILE_AVAILABILITY] = fileAvailability[i];
|
||||
QVariantMap fileDict = {
|
||||
{KEY_FILE_PROGRESS, fp[i]},
|
||||
{KEY_FILE_PRIORITY, static_cast<int>(priorities[i])},
|
||||
{KEY_FILE_SIZE, torrent->fileSize(i)},
|
||||
{KEY_FILE_AVAILABILITY, fileAvailability[i]}
|
||||
};
|
||||
|
||||
QString fileName = torrent->filePath(i);
|
||||
if (fileName.endsWith(QB_EXT, Qt::CaseInsensitive))
|
||||
|
Loading…
Reference in New Issue
Block a user