Use InfoHash type in queueing operations

This avoids redundant type conversions.
This commit is contained in:
Chocobo1 2019-10-02 12:52:51 +08:00
commit e0a23ba93d
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
4 changed files with 59 additions and 43 deletions

View file

@ -40,6 +40,7 @@
#include <QUrl>
#include "base/bittorrent/downloadpriority.h"
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/peeraddress.h"
#include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h"
@ -197,6 +198,15 @@ namespace
return {dht, pex, lsd};
}
QVector<BitTorrent::InfoHash> toInfoHashes(const QStringList &hashes)
{
QVector<BitTorrent::InfoHash> infoHashes;
infoHashes.reserve(hashes.size());
for (const QString &hash : hashes)
infoHashes << hash;
return infoHashes;
}
}
// Returns all the torrents in JSON format.
@ -901,7 +911,7 @@ void TorrentsController::increasePrioAction()
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
BitTorrent::Session::instance()->increaseTorrentsQueuePos(hashes);
BitTorrent::Session::instance()->increaseTorrentsQueuePos(toInfoHashes(hashes));
}
void TorrentsController::decreasePrioAction()
@ -912,7 +922,7 @@ void TorrentsController::decreasePrioAction()
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
BitTorrent::Session::instance()->decreaseTorrentsQueuePos(hashes);
BitTorrent::Session::instance()->decreaseTorrentsQueuePos(toInfoHashes(hashes));
}
void TorrentsController::topPrioAction()
@ -923,7 +933,7 @@ void TorrentsController::topPrioAction()
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
BitTorrent::Session::instance()->topTorrentsQueuePos(hashes);
BitTorrent::Session::instance()->topTorrentsQueuePos(toInfoHashes(hashes));
}
void TorrentsController::bottomPrioAction()
@ -934,7 +944,7 @@ void TorrentsController::bottomPrioAction()
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
BitTorrent::Session::instance()->bottomTorrentsQueuePos(hashes);
BitTorrent::Session::instance()->bottomTorrentsQueuePos(toInfoHashes(hashes));
}
void TorrentsController::setLocationAction()