mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-13 00:07:54 +00:00
WebUI: Implement limit/offset.
This commit is contained in:
parent
59ff08c107
commit
e279dcf904
@ -235,7 +235,8 @@ static QVariantMap toMap(const QTorrentHandle& h)
|
|||||||
* - "eta": Torrent ETA
|
* - "eta": Torrent ETA
|
||||||
* - "state": Torrent state
|
* - "state": Torrent state
|
||||||
*/
|
*/
|
||||||
QByteArray btjson::getTorrents(QString filter, QString label, QString sortedColumn, bool reverse)
|
QByteArray btjson::getTorrents(QString filter, QString label,
|
||||||
|
QString sortedColumn, bool reverse, int limit, int offset)
|
||||||
{
|
{
|
||||||
QVariantList torrent_list;
|
QVariantList torrent_list;
|
||||||
|
|
||||||
@ -252,7 +253,20 @@ QByteArray btjson::getTorrents(QString filter, QString label, QString sortedColu
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::sort(torrent_list.begin(), torrent_list.end(), QTorrentCompare(sortedColumn, reverse));
|
std::sort(torrent_list.begin(), torrent_list.end(), QTorrentCompare(sortedColumn, reverse));
|
||||||
return json::toJson(torrent_list);
|
int size = torrent_list.size();
|
||||||
|
// normalize offset
|
||||||
|
if (offset < 0)
|
||||||
|
offset = size - offset;
|
||||||
|
if ((offset >= size) || (offset < 0))
|
||||||
|
offset = 0;
|
||||||
|
// normalize limit
|
||||||
|
if (limit <= 0)
|
||||||
|
limit = -1; // unlimited
|
||||||
|
|
||||||
|
if ((limit > 0) || (offset > 0))
|
||||||
|
return json::toJson(torrent_list.mid(offset, limit));
|
||||||
|
else
|
||||||
|
return json::toJson(torrent_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +45,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static QByteArray getTorrents(QString filter = "all", QString label = QString(),
|
static QByteArray getTorrents(QString filter = "all", QString label = QString(),
|
||||||
QString sortedColumn = "name", bool reverse = false);
|
QString sortedColumn = "name", bool reverse = false, int limit = 0, int offset = 0);
|
||||||
static QByteArray getTrackersForTorrent(const QString& hash);
|
static QByteArray getTrackersForTorrent(const QString& hash);
|
||||||
static QByteArray getPropertiesForTorrent(const QString& hash);
|
static QByteArray getPropertiesForTorrent(const QString& hash);
|
||||||
static QByteArray getFilesForTorrent(const QString& hash);
|
static QByteArray getFilesForTorrent(const QString& hash);
|
||||||
|
@ -186,12 +186,20 @@ void RequestHandler::action_public_images()
|
|||||||
printFile(path);
|
printFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET params:
|
||||||
|
// - filter (string): all, downloading, completed, paused, active, inactive
|
||||||
|
// - label (string): torrent label for filtering by it (empty string means "unlabeled"; no "label" param presented means "any label")
|
||||||
|
// - sort (string): name of column for sorting by its value
|
||||||
|
// - reverse (bool): enable reverse sorting
|
||||||
|
// - limit (int): set limit number of torrents returned (if greater than 0, otherwise - unlimited)
|
||||||
|
// - offset (int): set offset (if less than 0 - offset from end)
|
||||||
void RequestHandler::action_json_torrents()
|
void RequestHandler::action_json_torrents()
|
||||||
{
|
{
|
||||||
const QStringMap& gets = request().gets;
|
const QStringMap& gets = request().gets;
|
||||||
|
|
||||||
print(btjson::getTorrents(
|
print(btjson::getTorrents(
|
||||||
gets["filter"], gets["label"], gets["sort"], gets["reverse"] == "true"
|
gets["filter"], gets["label"], gets["sort"], gets["reverse"] == "true",
|
||||||
|
gets["limit"].toInt(), gets["offset"].toInt()
|
||||||
), CONTENT_TYPE_JS);
|
), CONTENT_TYPE_JS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user