summaryrefslogtreecommitdiffstats
path: root/examples/network/torrent/trackerclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network/torrent/trackerclient.cpp')
-rw-r--r--examples/network/torrent/trackerclient.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp
index b82442b8c0..12110ba0ae 100644
--- a/examples/network/torrent/trackerclient.cpp
+++ b/examples/network/torrent/trackerclient.cpp
@@ -20,7 +20,7 @@ TrackerClient::TrackerClient(TorrentClient *downloader, QObject *parent)
void TrackerClient::start(const MetaInfo &info)
{
metaInfo = info;
- QTimer::singleShot(0, this, SLOT(fetchPeerList()));
+ QTimer::singleShot(0, this, &TrackerClient::fetchPeerList);
if (metaInfo.fileForm() == MetaInfo::SingleFileForm) {
length = metaInfo.singleFile().length;
@@ -54,18 +54,16 @@ void TrackerClient::timerEvent(QTimerEvent *event)
void TrackerClient::fetchPeerList()
{
+ if (metaInfo.announceUrl().isEmpty())
+ return;
QUrl url(metaInfo.announceUrl());
// Base the query on announce url to include a passkey (if any)
QUrlQuery query(url);
// Percent encode the hash
- QByteArray infoHash = torrentDownloader->infoHash();
- QByteArray encodedSum;
- for (int i = 0; i < infoHash.size(); ++i) {
- encodedSum += '%';
- encodedSum += QByteArray::number(infoHash[i], 16).right(2).rightJustified(2, '0');
- }
+ const QByteArray infoHash = torrentDownloader->infoHash();
+ const QByteArray encodedSum = infoHash.toPercentEncoding();
bool seeding = (torrentDownloader->state() == TorrentClient::Seeding);
@@ -155,7 +153,7 @@ void TrackerClient::httpRequestDone(QNetworkReply *reply)
// Mandatory item
if (requestIntervalTimer != -1)
killTimer(requestIntervalTimer);
- requestIntervalTimer = startTimer(dict.value("interval").toInt() * 1000);
+ requestIntervalTimer = startTimer(std::chrono::seconds(dict.value("interval").toInt()));
}
if (dict.contains("peers")) {