Use QString literals

It covers src/webui and enables `QT_NO_CAST_FROM_ASCII`.
This commit is contained in:
Chocobo1
2022-03-19 15:57:41 +08:00
parent f888fb4ac7
commit efc04645b7
25 changed files with 836 additions and 824 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -30,6 +30,7 @@
#include <QString>
#include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/utils/password.h"
@@ -45,8 +46,8 @@ void AuthController::loginAction()
}
const QString clientAddr {sessionManager()->clientId()};
const QString usernameFromWeb {params()["username"]};
const QString passwordFromWeb {params()["password"]};
const QString usernameFromWeb {params()[u"username"_qs]};
const QString passwordFromWeb {params()[u"password"_qs]};
if (isBanned())
{

View File

@@ -61,13 +61,13 @@ void LogController::mainAction()
{
using Utils::String::parseBool;
const bool isNormal = parseBool(params()["normal"]).value_or(true);
const bool isInfo = parseBool(params()["info"]).value_or(true);
const bool isWarning = parseBool(params()["warning"]).value_or(true);
const bool isCritical = parseBool(params()["critical"]).value_or(true);
const bool isNormal = parseBool(params()[u"normal"_qs]).value_or(true);
const bool isInfo = parseBool(params()[u"info"_qs]).value_or(true);
const bool isWarning = parseBool(params()[u"warning"_qs]).value_or(true);
const bool isCritical = parseBool(params()[u"critical"_qs]).value_or(true);
bool ok = false;
int lastKnownId = params()["last_known_id"].toInt(&ok);
int lastKnownId = params()[u"last_known_id"_qs].toInt(&ok);
if (!ok)
lastKnownId = -1;
@@ -107,7 +107,7 @@ void LogController::mainAction()
void LogController::peersAction()
{
bool ok = false;
int lastKnownId = params()["last_known_id"].toInt(&ok);
int lastKnownId = params()[u"last_known_id"_qs].toInt(&ok);
if (!ok)
lastKnownId = -1;

View File

@@ -47,9 +47,9 @@ using Utils::String::parseBool;
void RSSController::addFolderAction()
{
requireParams({"path"});
requireParams({u"path"_qs});
const QString path = params()["path"].trimmed();
const QString path = params()[u"path"_qs].trimmed();
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFolder(path);
if (!result)
throw APIError(APIErrorType::Conflict, result.error());
@@ -57,10 +57,10 @@ void RSSController::addFolderAction()
void RSSController::addFeedAction()
{
requireParams({"url", "path"});
requireParams({u"url"_qs, u"path"_qs});
const QString url = params()["url"].trimmed();
const QString path = params()["path"].trimmed();
const QString url = params()[u"url"_qs].trimmed();
const QString path = params()[u"path"_qs].trimmed();
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFeed(url, (path.isEmpty() ? url : path));
if (!result)
throw APIError(APIErrorType::Conflict, result.error());
@@ -68,9 +68,9 @@ void RSSController::addFeedAction()
void RSSController::removeItemAction()
{
requireParams({"path"});
requireParams({u"path"_qs});
const QString path = params()["path"].trimmed();
const QString path = params()[u"path"_qs].trimmed();
const nonstd::expected<void, QString> result = RSS::Session::instance()->removeItem(path);
if (!result)
throw APIError(APIErrorType::Conflict, result.error());
@@ -78,10 +78,10 @@ void RSSController::removeItemAction()
void RSSController::moveItemAction()
{
requireParams({"itemPath", "destPath"});
requireParams({u"itemPath"_qs, u"destPath"_qs});
const QString itemPath = params()["itemPath"].trimmed();
const QString destPath = params()["destPath"].trimmed();
const QString itemPath = params()[u"itemPath"_qs].trimmed();
const QString destPath = params()[u"destPath"_qs].trimmed();
const nonstd::expected<void, QString> result = RSS::Session::instance()->moveItem(itemPath, destPath);
if (!result)
throw APIError(APIErrorType::Conflict, result.error());
@@ -89,7 +89,7 @@ void RSSController::moveItemAction()
void RSSController::itemsAction()
{
const bool withData {parseBool(params()["withData"]).value_or(false)};
const bool withData {parseBool(params()[u"withData"_qs]).value_or(false)};
const auto jsonVal = RSS::Session::instance()->rootFolder()->toJsonValue(withData);
setResult(jsonVal.toObject());
@@ -97,10 +97,10 @@ void RSSController::itemsAction()
void RSSController::markAsReadAction()
{
requireParams({"itemPath"});
requireParams({u"itemPath"_qs});
const QString itemPath {params()["itemPath"]};
const QString articleId {params()["articleId"]};
const QString itemPath {params()[u"itemPath"_qs]};
const QString articleId {params()[u"articleId"_qs]};
RSS::Item *item = RSS::Session::instance()->itemByPath(itemPath);
if (!item) return;
@@ -123,9 +123,9 @@ void RSSController::markAsReadAction()
void RSSController::refreshItemAction()
{
requireParams({"itemPath"});
requireParams({u"itemPath"_qs});
const QString itemPath {params()["itemPath"]};
const QString itemPath {params()[u"itemPath"_qs]};
RSS::Item *item = RSS::Session::instance()->itemByPath(itemPath);
if (item)
item->refresh();
@@ -133,10 +133,10 @@ void RSSController::refreshItemAction()
void RSSController::setRuleAction()
{
requireParams({"ruleName", "ruleDef"});
requireParams({u"ruleName"_qs, u"ruleDef"_qs});
const QString ruleName {params()["ruleName"].trimmed()};
const QByteArray ruleDef {params()["ruleDef"].trimmed().toUtf8()};
const QString ruleName {params()[u"ruleName"_qs].trimmed()};
const QByteArray ruleDef {params()[u"ruleDef"_qs].trimmed().toUtf8()};
const auto jsonObj = QJsonDocument::fromJson(ruleDef).object();
RSS::AutoDownloader::instance()->insertRule(RSS::AutoDownloadRule::fromJsonObject(jsonObj, ruleName));
@@ -144,19 +144,19 @@ void RSSController::setRuleAction()
void RSSController::renameRuleAction()
{
requireParams({"ruleName", "newRuleName"});
requireParams({u"ruleName"_qs, u"newRuleName"_qs});
const QString ruleName {params()["ruleName"].trimmed()};
const QString newRuleName {params()["newRuleName"].trimmed()};
const QString ruleName {params()[u"ruleName"_qs].trimmed()};
const QString newRuleName {params()[u"newRuleName"_qs].trimmed()};
RSS::AutoDownloader::instance()->renameRule(ruleName, newRuleName);
}
void RSSController::removeRuleAction()
{
requireParams({"ruleName"});
requireParams({u"ruleName"_qs});
const QString ruleName {params()["ruleName"].trimmed()};
const QString ruleName {params()[u"ruleName"_qs].trimmed()};
RSS::AutoDownloader::instance()->removeRule(ruleName);
}
@@ -172,9 +172,9 @@ void RSSController::rulesAction()
void RSSController::matchingArticlesAction()
{
requireParams({"ruleName"});
requireParams({u"ruleName"_qs});
const QString ruleName {params()["ruleName"]};
const QString ruleName {params()[u"ruleName"_qs]};
const RSS::AutoDownloadRule rule = RSS::AutoDownloader::instance()->ruleByName(ruleName);
QJsonObject jsonObj;

View File

@@ -72,8 +72,8 @@ namespace
{
QJsonArray categoriesInfo
{QJsonObject {
{QLatin1String("id"), "all"},
{QLatin1String("name"), SearchPluginManager::categoryFullName("all")}
{QLatin1String("id"), u"all"_qs},
{QLatin1String("name"), SearchPluginManager::categoryFullName(u"all"_qs)}
}};
categories.sort(Qt::CaseInsensitive);
@@ -92,22 +92,22 @@ namespace
void SearchController::startAction()
{
requireParams({"pattern", "category", "plugins"});
requireParams({u"pattern"_qs, u"category"_qs, u"plugins"_qs});
if (!Utils::ForeignApps::pythonInfo().isValid())
throw APIError(APIErrorType::Conflict, tr("Python must be installed to use the Search Engine."));
const QString pattern = params()["pattern"].trimmed();
const QString category = params()["category"].trimmed();
const QStringList plugins = params()["plugins"].split('|');
const QString pattern = params()[u"pattern"_qs].trimmed();
const QString category = params()[u"category"_qs].trimmed();
const QStringList plugins = params()[u"plugins"_qs].split(u'|');
QStringList pluginsToUse;
if (plugins.size() == 1)
{
const QString pluginsLower = plugins[0].toLower();
if (pluginsLower == "all")
if (pluginsLower == u"all")
pluginsToUse = SearchPluginManager::instance()->allPlugins();
else if ((pluginsLower == "enabled") || (pluginsLower == "multi"))
else if ((pluginsLower == u"enabled") || (pluginsLower == u"multi"))
pluginsToUse = SearchPluginManager::instance()->enabledPlugins();
else
pluginsToUse << plugins;
@@ -134,15 +134,15 @@ void SearchController::startAction()
activeSearches.insert(id);
session->setData(ACTIVE_SEARCHES, QVariant::fromValue(activeSearches));
const QJsonObject result = {{"id", id}};
const QJsonObject result = {{u"id"_qs, id}};
setResult(result);
}
void SearchController::stopAction()
{
requireParams({"id"});
requireParams({u"id"_qs});
const int id = params()["id"].toInt();
const int id = params()[u"id"_qs].toInt();
ISession *const session = sessionManager()->session();
const auto searchHandlers = session->getData<SearchHandlerDict>(SEARCH_HANDLERS);
@@ -160,7 +160,7 @@ void SearchController::stopAction()
void SearchController::statusAction()
{
const int id = params()["id"].toInt();
const int id = params()[u"id"_qs].toInt();
const auto searchHandlers = sessionManager()->session()->getData<SearchHandlerDict>(SEARCH_HANDLERS);
if ((id != 0) && !searchHandlers.contains(id))
@@ -174,9 +174,9 @@ void SearchController::statusAction()
const SearchHandlerPtr searchHandler = searchHandlers[searchId];
statusArray << QJsonObject
{
{"id", searchId},
{"status", searchHandler->isActive() ? "Running" : "Stopped"},
{"total", searchHandler->results().size()}
{u"id"_qs, searchId},
{u"status"_qs, searchHandler->isActive() ? u"Running"_qs : u"Stopped"_qs},
{u"total"_qs, searchHandler->results().size()}
};
}
@@ -185,11 +185,11 @@ void SearchController::statusAction()
void SearchController::resultsAction()
{
requireParams({"id"});
requireParams({u"id"_qs});
const int id = params()["id"].toInt();
int limit = params()["limit"].toInt();
int offset = params()["offset"].toInt();
const int id = params()[u"id"_qs].toInt();
int limit = params()[u"limit"_qs].toInt();
int offset = params()[u"offset"_qs].toInt();
const auto searchHandlers = sessionManager()->session()->getData<SearchHandlerDict>(SEARCH_HANDLERS);
if (!searchHandlers.contains(id))
@@ -218,9 +218,9 @@ void SearchController::resultsAction()
void SearchController::deleteAction()
{
requireParams({"id"});
requireParams({u"id"_qs});
const int id = params()["id"].toInt();
const int id = params()[u"id"_qs].toInt();
ISession *const session = sessionManager()->session();
auto searchHandlers = session->getData<SearchHandlerDict>(SEARCH_HANDLERS);
@@ -243,28 +243,28 @@ void SearchController::pluginsAction()
void SearchController::installPluginAction()
{
requireParams({"sources"});
requireParams({u"sources"_qs});
const QStringList sources = params()["sources"].split('|');
const QStringList sources = params()[u"sources"_qs].split(u'|');
for (const QString &source : sources)
SearchPluginManager::instance()->installPlugin(source);
}
void SearchController::uninstallPluginAction()
{
requireParams({"names"});
requireParams({u"names"_qs});
const QStringList names = params()["names"].split('|');
const QStringList names = params()[u"names"_qs].split(u'|');
for (const QString &name : names)
SearchPluginManager::instance()->uninstallPlugin(name.trimmed());
}
void SearchController::enablePluginAction()
{
requireParams({"names", "enable"});
requireParams({u"names"_qs, u"enable"_qs});
const QStringList names = params()["names"].split('|');
const bool enable = Utils::String::parseBool(params()["enable"].trimmed()).value_or(false);
const QStringList names = params()[u"names"_qs].split(u'|');
const bool enable = Utils::String::parseBool(params()[u"enable"_qs].trimmed()).value_or(false);
for (const QString &name : names)
SearchPluginManager::instance()->enablePlugin(name.trimmed(), enable);
@@ -344,21 +344,21 @@ QJsonObject SearchController::getResults(const QList<SearchResult> &searchResult
{
searchResultsArray << QJsonObject
{
{"fileName", searchResult.fileName},
{"fileUrl", searchResult.fileUrl},
{"fileSize", searchResult.fileSize},
{"nbSeeders", searchResult.nbSeeders},
{"nbLeechers", searchResult.nbLeechers},
{"siteUrl", searchResult.siteUrl},
{"descrLink", searchResult.descrLink}
{u"fileName"_qs, searchResult.fileName},
{u"fileUrl"_qs, searchResult.fileUrl},
{u"fileSize"_qs, searchResult.fileSize},
{u"nbSeeders"_qs, searchResult.nbSeeders},
{u"nbLeechers"_qs, searchResult.nbLeechers},
{u"siteUrl"_qs, searchResult.siteUrl},
{u"descrLink"_qs, searchResult.descrLink}
};
}
const QJsonObject result =
{
{"status", isSearchActive ? "Running" : "Stopped"},
{"results", searchResultsArray},
{"total", totalResults}
{u"status"_qs, isSearchActive ? u"Running"_qs : u"Stopped"_qs},
{u"results"_qs, searchResultsArray},
{u"total"_qs, totalResults}
};
return result;
@@ -387,12 +387,12 @@ QJsonArray SearchController::getPluginsInfo(const QStringList &plugins) const
pluginsArray << QJsonObject
{
{"name", pluginInfo->name},
{"version", QString(pluginInfo->version)},
{"fullName", pluginInfo->fullName},
{"url", pluginInfo->url},
{"supportedCategories", getPluginCategories(pluginInfo->supportedCategories)},
{"enabled", pluginInfo->enabled}
{u"name"_qs, pluginInfo->name},
{u"version"_qs, QString(pluginInfo->version)},
{u"fullName"_qs, pluginInfo->fullName},
{u"url"_qs, pluginInfo->url},
{u"supportedCategories"_qs, getPluginCategories(pluginInfo->supportedCategories)},
{u"enabled"_qs, pluginInfo->enabled}
};
}

View File

@@ -30,6 +30,8 @@
#include <QVariant>
#include "base/global.h"
namespace BitTorrent
{
class Torrent;
@@ -37,54 +39,54 @@ namespace BitTorrent
// Torrent keys
// TODO: Rename it to `id`.
inline const char KEY_TORRENT_ID[] = "hash";
inline const char KEY_TORRENT_INFOHASHV1[] = "infohash_v1";
inline const char KEY_TORRENT_INFOHASHV2[] = "infohash_v2";
inline const char KEY_TORRENT_NAME[] = "name";
inline const char KEY_TORRENT_MAGNET_URI[] = "magnet_uri";
inline const char KEY_TORRENT_SIZE[] = "size";
inline const char KEY_TORRENT_PROGRESS[] = "progress";
inline const char KEY_TORRENT_DLSPEED[] = "dlspeed";
inline const char KEY_TORRENT_UPSPEED[] = "upspeed";
inline const char KEY_TORRENT_QUEUE_POSITION[] = "priority";
inline const char KEY_TORRENT_SEEDS[] = "num_seeds";
inline const char KEY_TORRENT_NUM_COMPLETE[] = "num_complete";
inline const char KEY_TORRENT_LEECHS[] = "num_leechs";
inline const char KEY_TORRENT_NUM_INCOMPLETE[] = "num_incomplete";
inline const char KEY_TORRENT_RATIO[] = "ratio";
inline const char KEY_TORRENT_ETA[] = "eta";
inline const char KEY_TORRENT_STATE[] = "state";
inline const char KEY_TORRENT_SEQUENTIAL_DOWNLOAD[] = "seq_dl";
inline const char KEY_TORRENT_FIRST_LAST_PIECE_PRIO[] = "f_l_piece_prio";
inline const char KEY_TORRENT_CATEGORY[] = "category";
inline const char KEY_TORRENT_TAGS[] = "tags";
inline const char KEY_TORRENT_SUPER_SEEDING[] = "super_seeding";
inline const char KEY_TORRENT_FORCE_START[] = "force_start";
inline const char KEY_TORRENT_SAVE_PATH[] = "save_path";
inline const char KEY_TORRENT_DOWNLOAD_PATH[] = "download_path";
inline const char KEY_TORRENT_CONTENT_PATH[] = "content_path";
inline const char KEY_TORRENT_ADDED_ON[] = "added_on";
inline const char KEY_TORRENT_COMPLETION_ON[] = "completion_on";
inline const char KEY_TORRENT_TRACKER[] = "tracker";
inline const char KEY_TORRENT_TRACKERS_COUNT[] = "trackers_count";
inline const char KEY_TORRENT_DL_LIMIT[] = "dl_limit";
inline const char KEY_TORRENT_UP_LIMIT[] = "up_limit";
inline const char KEY_TORRENT_AMOUNT_DOWNLOADED[] = "downloaded";
inline const char KEY_TORRENT_AMOUNT_UPLOADED[] = "uploaded";
inline const char KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION[] = "downloaded_session";
inline const char KEY_TORRENT_AMOUNT_UPLOADED_SESSION[] = "uploaded_session";
inline const char KEY_TORRENT_AMOUNT_LEFT[] = "amount_left";
inline const char KEY_TORRENT_AMOUNT_COMPLETED[] = "completed";
inline const char KEY_TORRENT_MAX_RATIO[] = "max_ratio";
inline const char KEY_TORRENT_MAX_SEEDING_TIME[] = "max_seeding_time";
inline const char KEY_TORRENT_RATIO_LIMIT[] = "ratio_limit";
inline const char KEY_TORRENT_SEEDING_TIME_LIMIT[] = "seeding_time_limit";
inline const char KEY_TORRENT_LAST_SEEN_COMPLETE_TIME[] = "seen_complete";
inline const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity";
inline const char KEY_TORRENT_TOTAL_SIZE[] = "total_size";
inline const char KEY_TORRENT_AUTO_TORRENT_MANAGEMENT[] = "auto_tmm";
inline const char KEY_TORRENT_TIME_ACTIVE[] = "time_active";
inline const char KEY_TORRENT_SEEDING_TIME[] = "seeding_time";
inline const char KEY_TORRENT_AVAILABILITY[] = "availability";
inline const QString KEY_TORRENT_ID = u"hash"_qs;
inline const QString KEY_TORRENT_INFOHASHV1 = u"infohash_v1"_qs;
inline const QString KEY_TORRENT_INFOHASHV2 = u"infohash_v2"_qs;
inline const QString KEY_TORRENT_NAME = u"name"_qs;
inline const QString KEY_TORRENT_MAGNET_URI = u"magnet_uri"_qs;
inline const QString KEY_TORRENT_SIZE = u"size"_qs;
inline const QString KEY_TORRENT_PROGRESS = u"progress"_qs;
inline const QString KEY_TORRENT_DLSPEED = u"dlspeed"_qs;
inline const QString KEY_TORRENT_UPSPEED = u"upspeed"_qs;
inline const QString KEY_TORRENT_QUEUE_POSITION = u"priority"_qs;
inline const QString KEY_TORRENT_SEEDS = u"num_seeds"_qs;
inline const QString KEY_TORRENT_NUM_COMPLETE = u"num_complete"_qs;
inline const QString KEY_TORRENT_LEECHS = u"num_leechs"_qs;
inline const QString KEY_TORRENT_NUM_INCOMPLETE = u"num_incomplete"_qs;
inline const QString KEY_TORRENT_RATIO = u"ratio"_qs;
inline const QString KEY_TORRENT_ETA = u"eta"_qs;
inline const QString KEY_TORRENT_STATE = u"state"_qs;
inline const QString KEY_TORRENT_SEQUENTIAL_DOWNLOAD = u"seq_dl"_qs;
inline const QString KEY_TORRENT_FIRST_LAST_PIECE_PRIO = u"f_l_piece_prio"_qs;
inline const QString KEY_TORRENT_CATEGORY = u"category"_qs;
inline const QString KEY_TORRENT_TAGS = u"tags"_qs;
inline const QString KEY_TORRENT_SUPER_SEEDING = u"super_seeding"_qs;
inline const QString KEY_TORRENT_FORCE_START = u"force_start"_qs;
inline const QString KEY_TORRENT_SAVE_PATH = u"save_path"_qs;
inline const QString KEY_TORRENT_DOWNLOAD_PATH = u"download_path"_qs;
inline const QString KEY_TORRENT_CONTENT_PATH = u"content_path"_qs;
inline const QString KEY_TORRENT_ADDED_ON = u"added_on"_qs;
inline const QString KEY_TORRENT_COMPLETION_ON = u"completion_on"_qs;
inline const QString KEY_TORRENT_TRACKER = u"tracker"_qs;
inline const QString KEY_TORRENT_TRACKERS_COUNT = u"trackers_count"_qs;
inline const QString KEY_TORRENT_DL_LIMIT = u"dl_limit"_qs;
inline const QString KEY_TORRENT_UP_LIMIT = u"up_limit"_qs;
inline const QString KEY_TORRENT_AMOUNT_DOWNLOADED = u"downloaded"_qs;
inline const QString KEY_TORRENT_AMOUNT_UPLOADED = u"uploaded"_qs;
inline const QString KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION = u"downloaded_session"_qs;
inline const QString KEY_TORRENT_AMOUNT_UPLOADED_SESSION = u"uploaded_session"_qs;
inline const QString KEY_TORRENT_AMOUNT_LEFT = u"amount_left"_qs;
inline const QString KEY_TORRENT_AMOUNT_COMPLETED = u"completed"_qs;
inline const QString KEY_TORRENT_MAX_RATIO = u"max_ratio"_qs;
inline const QString KEY_TORRENT_MAX_SEEDING_TIME = u"max_seeding_time"_qs;
inline const QString KEY_TORRENT_RATIO_LIMIT = u"ratio_limit"_qs;
inline const QString KEY_TORRENT_SEEDING_TIME_LIMIT = u"seeding_time_limit"_qs;
inline const QString KEY_TORRENT_LAST_SEEN_COMPLETE_TIME = u"seen_complete"_qs;
inline const QString KEY_TORRENT_LAST_ACTIVITY_TIME = u"last_activity"_qs;
inline const QString KEY_TORRENT_TOTAL_SIZE = u"total_size"_qs;
inline const QString KEY_TORRENT_AUTO_TORRENT_MANAGEMENT = u"auto_tmm"_qs;
inline const QString KEY_TORRENT_TIME_ACTIVE = u"time_active"_qs;
inline const QString KEY_TORRENT_SEEDING_TIME = u"seeding_time"_qs;
inline const QString KEY_TORRENT_AVAILABILITY = u"availability"_qs;
QVariantMap serialize(const BitTorrent::Torrent &torrent);

View File

@@ -54,58 +54,58 @@ namespace
const int FREEDISKSPACE_CHECK_TIMEOUT = 30000;
// Sync main data keys
const char KEY_SYNC_MAINDATA_QUEUEING[] = "queueing";
const char KEY_SYNC_MAINDATA_REFRESH_INTERVAL[] = "refresh_interval";
const char KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS[] = "use_alt_speed_limits";
const QString KEY_SYNC_MAINDATA_QUEUEING = u"queueing"_qs;
const QString KEY_SYNC_MAINDATA_REFRESH_INTERVAL = u"refresh_interval"_qs;
const QString KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS = u"use_alt_speed_limits"_qs;
// Sync torrent peers keys
const char KEY_SYNC_TORRENT_PEERS_SHOW_FLAGS[] = "show_flags";
const QString KEY_SYNC_TORRENT_PEERS_SHOW_FLAGS = u"show_flags"_qs;
// Peer keys
const char KEY_PEER_CLIENT[] = "client";
const char KEY_PEER_CONNECTION_TYPE[] = "connection";
const char KEY_PEER_COUNTRY[] = "country";
const char KEY_PEER_COUNTRY_CODE[] = "country_code";
const char KEY_PEER_DOWN_SPEED[] = "dl_speed";
const char KEY_PEER_FILES[] = "files";
const char KEY_PEER_FLAGS[] = "flags";
const char KEY_PEER_FLAGS_DESCRIPTION[] = "flags_desc";
const char KEY_PEER_IP[] = "ip";
const char KEY_PEER_PORT[] = "port";
const char KEY_PEER_PROGRESS[] = "progress";
const char KEY_PEER_RELEVANCE[] = "relevance";
const char KEY_PEER_TOT_DOWN[] = "downloaded";
const char KEY_PEER_TOT_UP[] = "uploaded";
const char KEY_PEER_UP_SPEED[] = "up_speed";
const QString KEY_PEER_CLIENT = u"client"_qs;
const QString KEY_PEER_CONNECTION_TYPE = u"connection"_qs;
const QString KEY_PEER_COUNTRY = u"country"_qs;
const QString KEY_PEER_COUNTRY_CODE = u"country_code"_qs;
const QString KEY_PEER_DOWN_SPEED = u"dl_speed"_qs;
const QString KEY_PEER_FILES = u"files"_qs;
const QString KEY_PEER_FLAGS = u"flags"_qs;
const QString KEY_PEER_FLAGS_DESCRIPTION = u"flags_desc"_qs;
const QString KEY_PEER_IP = u"ip"_qs;
const QString KEY_PEER_PORT = u"port"_qs;
const QString KEY_PEER_PROGRESS = u"progress"_qs;
const QString KEY_PEER_RELEVANCE = u"relevance"_qs;
const QString KEY_PEER_TOT_DOWN = u"downloaded"_qs;
const QString KEY_PEER_TOT_UP = u"uploaded"_qs;
const QString KEY_PEER_UP_SPEED = u"up_speed"_qs;
// TransferInfo keys
const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status";
const char KEY_TRANSFER_DHT_NODES[] = "dht_nodes";
const char KEY_TRANSFER_DLDATA[] = "dl_info_data";
const char KEY_TRANSFER_DLRATELIMIT[] = "dl_rate_limit";
const char KEY_TRANSFER_DLSPEED[] = "dl_info_speed";
const char KEY_TRANSFER_FREESPACEONDISK[] = "free_space_on_disk";
const char KEY_TRANSFER_UPDATA[] = "up_info_data";
const char KEY_TRANSFER_UPRATELIMIT[] = "up_rate_limit";
const char KEY_TRANSFER_UPSPEED[] = "up_info_speed";
const QString KEY_TRANSFER_CONNECTION_STATUS = u"connection_status"_qs;
const QString KEY_TRANSFER_DHT_NODES = u"dht_nodes"_qs;
const QString KEY_TRANSFER_DLDATA = u"dl_info_data"_qs;
const QString KEY_TRANSFER_DLRATELIMIT = u"dl_rate_limit"_qs;
const QString KEY_TRANSFER_DLSPEED = u"dl_info_speed"_qs;
const QString KEY_TRANSFER_FREESPACEONDISK = u"free_space_on_disk"_qs;
const QString KEY_TRANSFER_UPDATA = u"up_info_data"_qs;
const QString KEY_TRANSFER_UPRATELIMIT = u"up_rate_limit"_qs;
const QString KEY_TRANSFER_UPSPEED = u"up_info_speed"_qs;
// Statistics keys
const char KEY_TRANSFER_ALLTIME_DL[] = "alltime_dl";
const char KEY_TRANSFER_ALLTIME_UL[] = "alltime_ul";
const char KEY_TRANSFER_AVERAGE_TIME_QUEUE[] = "average_time_queue";
const char KEY_TRANSFER_GLOBAL_RATIO[] = "global_ratio";
const char KEY_TRANSFER_QUEUED_IO_JOBS[] = "queued_io_jobs";
const char KEY_TRANSFER_READ_CACHE_HITS[] = "read_cache_hits";
const char KEY_TRANSFER_READ_CACHE_OVERLOAD[] = "read_cache_overload";
const char KEY_TRANSFER_TOTAL_BUFFERS_SIZE[] = "total_buffers_size";
const char KEY_TRANSFER_TOTAL_PEER_CONNECTIONS[] = "total_peer_connections";
const char KEY_TRANSFER_TOTAL_QUEUED_SIZE[] = "total_queued_size";
const char KEY_TRANSFER_TOTAL_WASTE_SESSION[] = "total_wasted_session";
const char KEY_TRANSFER_WRITE_CACHE_OVERLOAD[] = "write_cache_overload";
const QString KEY_TRANSFER_ALLTIME_DL = u"alltime_dl"_qs;
const QString KEY_TRANSFER_ALLTIME_UL = u"alltime_ul"_qs;
const QString KEY_TRANSFER_AVERAGE_TIME_QUEUE = u"average_time_queue"_qs;
const QString KEY_TRANSFER_GLOBAL_RATIO = u"global_ratio"_qs;
const QString KEY_TRANSFER_QUEUED_IO_JOBS = u"queued_io_jobs"_qs;
const QString KEY_TRANSFER_READ_CACHE_HITS = u"read_cache_hits"_qs;
const QString KEY_TRANSFER_READ_CACHE_OVERLOAD = u"read_cache_overload"_qs;
const QString KEY_TRANSFER_TOTAL_BUFFERS_SIZE = u"total_buffers_size"_qs;
const QString KEY_TRANSFER_TOTAL_PEER_CONNECTIONS = u"total_peer_connections"_qs;
const QString KEY_TRANSFER_TOTAL_QUEUED_SIZE = u"total_queued_size"_qs;
const QString KEY_TRANSFER_TOTAL_WASTE_SESSION = u"total_wasted_session"_qs;
const QString KEY_TRANSFER_WRITE_CACHE_OVERLOAD = u"write_cache_overload"_qs;
const char KEY_FULL_UPDATE[] = "full_update";
const char KEY_RESPONSE_ID[] = "rid";
const char KEY_SUFFIX_REMOVED[] = "_removed";
const QString KEY_FULL_UPDATE = u"full_update"_qs;
const QString KEY_RESPONSE_ID = u"rid"_qs;
const QString KEY_SUFFIX_REMOVED = u"_removed"_qs;
void processMap(const QVariantMap &prevData, const QVariantMap &data, QVariantMap &syncData);
void processHash(QVariantHash prevData, const QVariantHash &data, QVariantMap &syncData, QVariantList &removedItems);
@@ -131,11 +131,11 @@ namespace
map[KEY_TRANSFER_ALLTIME_DL] = atd;
map[KEY_TRANSFER_ALLTIME_UL] = atu;
map[KEY_TRANSFER_TOTAL_WASTE_SESSION] = sessionStatus.totalWasted;
map[KEY_TRANSFER_GLOBAL_RATIO] = ((atd > 0) && (atu > 0)) ? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2) : "-";
map[KEY_TRANSFER_GLOBAL_RATIO] = ((atd > 0) && (atu > 0)) ? Utils::String::fromDouble(static_cast<qreal>(atu) / atd, 2) : u"-"_qs;
map[KEY_TRANSFER_TOTAL_PEER_CONNECTIONS] = sessionStatus.peersCount;
const qreal readRatio = cacheStatus.readRatio; // TODO: remove when LIBTORRENT_VERSION_NUM >= 20000
map[KEY_TRANSFER_READ_CACHE_HITS] = (readRatio > 0) ? Utils::String::fromDouble(100 * readRatio, 2) : "0";
map[KEY_TRANSFER_READ_CACHE_HITS] = (readRatio > 0) ? Utils::String::fromDouble(100 * readRatio, 2) : u"0"_qs;
map[KEY_TRANSFER_TOTAL_BUFFERS_SIZE] = cacheStatus.totalUsedBuffers * 16 * 1024;
map[KEY_TRANSFER_WRITE_CACHE_OVERLOAD] = ((sessionStatus.diskWriteQueue > 0) && (sessionStatus.peersCount > 0))
@@ -151,8 +151,8 @@ namespace
map[KEY_TRANSFER_DHT_NODES] = sessionStatus.dhtNodes;
map[KEY_TRANSFER_CONNECTION_STATUS] = session->isListening()
? (sessionStatus.hasIncomingConnections ? "connected" : "firewalled")
: "disconnected";
? (sessionStatus.hasIncomingConnections ? u"connected"_qs : u"firewalled"_qs)
: u"disconnected"_qs;
return map;
}
@@ -470,7 +470,7 @@ void SyncController::maindataAction()
// Calculated last activity time can differ from actual value by up to 10 seconds (this is a libtorrent issue).
// So we don't need unnecessary updates of last activity time in response.
const auto iterTorrents = lastResponse.find("torrents");
const auto iterTorrents = lastResponse.find(u"torrents"_qs);
if (iterTorrents != lastResponse.end())
{
const QVariantHash lastResponseTorrents = iterTorrents->toHash();
@@ -495,7 +495,7 @@ void SyncController::maindataAction()
torrents[torrentID.toString()] = map;
}
data["torrents"] = torrents;
data[u"torrents"_qs] = torrents;
QVariantHash categories;
const QStringList categoriesList = session->categories();
@@ -508,28 +508,28 @@ void SyncController::maindataAction()
category.insert(QLatin1String("name"), categoryName);
categories[categoryName] = category.toVariantMap();
}
data["categories"] = categories;
data[u"categories"_qs] = categories;
QVariantList tags;
for (const QString &tag : asConst(session->tags()))
tags << tag;
data["tags"] = tags;
data[u"tags"_qs] = tags;
QVariantHash trackersHash;
for (auto i = trackers.constBegin(); i != trackers.constEnd(); ++i)
{
trackersHash[i.key()] = i.value();
}
data["trackers"] = trackersHash;
data[u"trackers"_qs] = trackersHash;
QVariantMap serverState = getTransferInfo();
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = session->isAltGlobalSpeedLimitEnabled();
serverState[KEY_SYNC_MAINDATA_REFRESH_INTERVAL] = session->refreshInterval();
data["server_state"] = serverState;
data[u"server_state"_qs] = serverState;
const int acceptedResponseId {params()["rid"].toInt()};
const int acceptedResponseId {params()[u"rid"_qs].toInt()};
setResult(QJsonObject::fromVariantMap(generateSyncData(acceptedResponseId, data, lastAcceptedResponse, lastResponse)));
sessionManager()->session()->setData(QLatin1String("syncMainDataLastResponse"), lastResponse);
@@ -544,7 +544,7 @@ void SyncController::torrentPeersAction()
auto lastResponse = sessionManager()->session()->getData(QLatin1String("syncTorrentPeersLastResponse")).toMap();
auto lastAcceptedResponse = sessionManager()->session()->getData(QLatin1String("syncTorrentPeersLastAcceptedResponse")).toMap();
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
const BitTorrent::Torrent *torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
@@ -596,9 +596,9 @@ void SyncController::torrentPeersAction()
peers[pi.address().toString()] = peer;
}
data["peers"] = peers;
data[u"peers"_qs] = peers;
const int acceptedResponseId {params()["rid"].toInt()};
const int acceptedResponseId {params()[u"rid"_qs].toInt()};
setResult(QJsonObject::fromVariantMap(generateSyncData(acceptedResponseId, data, lastAcceptedResponse, lastResponse)));
sessionManager()->session()->setData(QLatin1String("syncTorrentPeersLastResponse"), lastResponse);

View File

@@ -57,63 +57,63 @@
#include "serialize/serialize_torrent.h"
// Tracker keys
const char KEY_TRACKER_URL[] = "url";
const char KEY_TRACKER_STATUS[] = "status";
const char KEY_TRACKER_TIER[] = "tier";
const char KEY_TRACKER_MSG[] = "msg";
const char KEY_TRACKER_PEERS_COUNT[] = "num_peers";
const char KEY_TRACKER_SEEDS_COUNT[] = "num_seeds";
const char KEY_TRACKER_LEECHES_COUNT[] = "num_leeches";
const char KEY_TRACKER_DOWNLOADED_COUNT[] = "num_downloaded";
const QString KEY_TRACKER_URL = u"url"_qs;
const QString KEY_TRACKER_STATUS = u"status"_qs;
const QString KEY_TRACKER_TIER = u"tier"_qs;
const QString KEY_TRACKER_MSG = u"msg"_qs;
const QString KEY_TRACKER_PEERS_COUNT = u"num_peers"_qs;
const QString KEY_TRACKER_SEEDS_COUNT = u"num_seeds"_qs;
const QString KEY_TRACKER_LEECHES_COUNT = u"num_leeches"_qs;
const QString KEY_TRACKER_DOWNLOADED_COUNT = u"num_downloaded"_qs;
// Web seed keys
const char KEY_WEBSEED_URL[] = "url";
const QString KEY_WEBSEED_URL = u"url"_qs;
// Torrent keys (Properties)
const char KEY_PROP_TIME_ELAPSED[] = "time_elapsed";
const char KEY_PROP_SEEDING_TIME[] = "seeding_time";
const char KEY_PROP_ETA[] = "eta";
const char KEY_PROP_CONNECT_COUNT[] = "nb_connections";
const char KEY_PROP_CONNECT_COUNT_LIMIT[] = "nb_connections_limit";
const char KEY_PROP_DOWNLOADED[] = "total_downloaded";
const char KEY_PROP_DOWNLOADED_SESSION[] = "total_downloaded_session";
const char KEY_PROP_UPLOADED[] = "total_uploaded";
const char KEY_PROP_UPLOADED_SESSION[] = "total_uploaded_session";
const char KEY_PROP_DL_SPEED[] = "dl_speed";
const char KEY_PROP_DL_SPEED_AVG[] = "dl_speed_avg";
const char KEY_PROP_UP_SPEED[] = "up_speed";
const char KEY_PROP_UP_SPEED_AVG[] = "up_speed_avg";
const char KEY_PROP_DL_LIMIT[] = "dl_limit";
const char KEY_PROP_UP_LIMIT[] = "up_limit";
const char KEY_PROP_WASTED[] = "total_wasted";
const char KEY_PROP_SEEDS[] = "seeds";
const char KEY_PROP_SEEDS_TOTAL[] = "seeds_total";
const char KEY_PROP_PEERS[] = "peers";
const char KEY_PROP_PEERS_TOTAL[] = "peers_total";
const char KEY_PROP_RATIO[] = "share_ratio";
const char KEY_PROP_REANNOUNCE[] = "reannounce";
const char KEY_PROP_TOTAL_SIZE[] = "total_size";
const char KEY_PROP_PIECES_NUM[] = "pieces_num";
const char KEY_PROP_PIECE_SIZE[] = "piece_size";
const char KEY_PROP_PIECES_HAVE[] = "pieces_have";
const char KEY_PROP_CREATED_BY[] = "created_by";
const char KEY_PROP_LAST_SEEN[] = "last_seen";
const char KEY_PROP_ADDITION_DATE[] = "addition_date";
const char KEY_PROP_COMPLETION_DATE[] = "completion_date";
const char KEY_PROP_CREATION_DATE[] = "creation_date";
const char KEY_PROP_SAVE_PATH[] = "save_path";
const char KEY_PROP_DOWNLOAD_PATH[] = "download_path";
const char KEY_PROP_COMMENT[] = "comment";
const QString KEY_PROP_TIME_ELAPSED = u"time_elapsed"_qs;
const QString KEY_PROP_SEEDING_TIME = u"seeding_time"_qs;
const QString KEY_PROP_ETA = u"eta"_qs;
const QString KEY_PROP_CONNECT_COUNT = u"nb_connections"_qs;
const QString KEY_PROP_CONNECT_COUNT_LIMIT = u"nb_connections_limit"_qs;
const QString KEY_PROP_DOWNLOADED = u"total_downloaded"_qs;
const QString KEY_PROP_DOWNLOADED_SESSION = u"total_downloaded_session"_qs;
const QString KEY_PROP_UPLOADED = u"total_uploaded"_qs;
const QString KEY_PROP_UPLOADED_SESSION = u"total_uploaded_session"_qs;
const QString KEY_PROP_DL_SPEED = u"dl_speed"_qs;
const QString KEY_PROP_DL_SPEED_AVG = u"dl_speed_avg"_qs;
const QString KEY_PROP_UP_SPEED = u"up_speed"_qs;
const QString KEY_PROP_UP_SPEED_AVG = u"up_speed_avg"_qs;
const QString KEY_PROP_DL_LIMIT = u"dl_limit"_qs;
const QString KEY_PROP_UP_LIMIT = u"up_limit"_qs;
const QString KEY_PROP_WASTED = u"total_wasted"_qs;
const QString KEY_PROP_SEEDS = u"seeds"_qs;
const QString KEY_PROP_SEEDS_TOTAL = u"seeds_total"_qs;
const QString KEY_PROP_PEERS = u"peers"_qs;
const QString KEY_PROP_PEERS_TOTAL = u"peers_total"_qs;
const QString KEY_PROP_RATIO = u"share_ratio"_qs;
const QString KEY_PROP_REANNOUNCE = u"reannounce"_qs;
const QString KEY_PROP_TOTAL_SIZE = u"total_size"_qs;
const QString KEY_PROP_PIECES_NUM = u"pieces_num"_qs;
const QString KEY_PROP_PIECE_SIZE = u"piece_size"_qs;
const QString KEY_PROP_PIECES_HAVE = u"pieces_have"_qs;
const QString KEY_PROP_CREATED_BY = u"created_by"_qs;
const QString KEY_PROP_LAST_SEEN = u"last_seen"_qs;
const QString KEY_PROP_ADDITION_DATE = u"addition_date"_qs;
const QString KEY_PROP_COMPLETION_DATE = u"completion_date"_qs;
const QString KEY_PROP_CREATION_DATE = u"creation_date"_qs;
const QString KEY_PROP_SAVE_PATH = u"save_path"_qs;
const QString KEY_PROP_DOWNLOAD_PATH = u"download_path"_qs;
const QString KEY_PROP_COMMENT = u"comment"_qs;
// File keys
const char KEY_FILE_INDEX[] = "index";
const char KEY_FILE_NAME[] = "name";
const char KEY_FILE_SIZE[] = "size";
const char KEY_FILE_PROGRESS[] = "progress";
const char KEY_FILE_PRIORITY[] = "priority";
const char KEY_FILE_IS_SEED[] = "is_seed";
const char KEY_FILE_PIECE_RANGE[] = "piece_range";
const char KEY_FILE_AVAILABILITY[] = "availability";
const QString KEY_FILE_INDEX = u"index"_qs;
const QString KEY_FILE_NAME = u"name"_qs;
const QString KEY_FILE_SIZE = u"size"_qs;
const QString KEY_FILE_PROGRESS = u"progress"_qs;
const QString KEY_FILE_PRIORITY = u"priority"_qs;
const QString KEY_FILE_IS_SEED = u"is_seed"_qs;
const QString KEY_FILE_PIECE_RANGE = u"piece_range"_qs;
const QString KEY_FILE_AVAILABILITY = u"availability"_qs;
namespace
{
@@ -184,9 +184,9 @@ namespace
const QJsonObject dht
{
{KEY_TRACKER_URL, "** [DHT] **"},
{KEY_TRACKER_URL, u"** [DHT] **"_qs},
{KEY_TRACKER_TIER, -1},
{KEY_TRACKER_MSG, (isTorrentPrivate ? privateMsg : "")},
{KEY_TRACKER_MSG, (isTorrentPrivate ? privateMsg : u""_qs)},
{KEY_TRACKER_STATUS, ((BitTorrent::Session::instance()->isDHTEnabled() && !isTorrentPrivate) ? working : disabled)},
{KEY_TRACKER_PEERS_COUNT, 0},
{KEY_TRACKER_DOWNLOADED_COUNT, 0},
@@ -196,9 +196,9 @@ namespace
const QJsonObject pex
{
{KEY_TRACKER_URL, "** [PeX] **"},
{KEY_TRACKER_URL, u"** [PeX] **"_qs},
{KEY_TRACKER_TIER, -1},
{KEY_TRACKER_MSG, (isTorrentPrivate ? privateMsg : "")},
{KEY_TRACKER_MSG, (isTorrentPrivate ? privateMsg : u""_qs)},
{KEY_TRACKER_STATUS, ((BitTorrent::Session::instance()->isPeXEnabled() && !isTorrentPrivate) ? working : disabled)},
{KEY_TRACKER_PEERS_COUNT, 0},
{KEY_TRACKER_DOWNLOADED_COUNT, 0},
@@ -208,9 +208,9 @@ namespace
const QJsonObject lsd
{
{KEY_TRACKER_URL, "** [LSD] **"},
{KEY_TRACKER_URL, u"** [LSD] **"_qs},
{KEY_TRACKER_TIER, -1},
{KEY_TRACKER_MSG, (isTorrentPrivate ? privateMsg : "")},
{KEY_TRACKER_MSG, (isTorrentPrivate ? privateMsg : u""_qs)},
{KEY_TRACKER_STATUS, ((BitTorrent::Session::instance()->isLSDEnabled() && !isTorrentPrivate) ? working : disabled)},
{KEY_TRACKER_PEERS_COUNT, 0},
{KEY_TRACKER_DOWNLOADED_COUNT, 0},
@@ -263,14 +263,14 @@ namespace
// - offset (int): set offset (if less than 0 - offset from end)
void TorrentsController::infoAction()
{
const QString filter {params()["filter"]};
const QString filter {params()[u"filter"_qs]};
const std::optional<QString> category = getOptionalString(params(), QLatin1String("category"));
const std::optional<QString> tag = getOptionalString(params(), QLatin1String("tag"));
const QString sortedColumn {params()["sort"]};
const bool reverse {parseBool(params()["reverse"]).value_or(false)};
int limit {params()["limit"].toInt()};
int offset {params()["offset"].toInt()};
const QStringList hashes {params()["hashes"].split('|', Qt::SkipEmptyParts)};
const QString sortedColumn {params()[u"sort"_qs]};
const bool reverse {parseBool(params()[u"reverse"_qs]).value_or(false)};
int limit {params()[u"limit"_qs].toInt()};
int offset {params()[u"offset"_qs].toInt()};
const QStringList hashes {params()[u"hashes"_qs].split(u'|', Qt::SkipEmptyParts)};
std::optional<TorrentIDSet> idSet;
if (!hashes.isEmpty())
@@ -389,9 +389,9 @@ void TorrentsController::infoAction()
// - "comment": Torrent comment
void TorrentsController::propertiesAction()
{
requireParams({"hash"});
requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
@@ -463,9 +463,9 @@ void TorrentsController::propertiesAction()
// - "msg": Tracker message (last)
void TorrentsController::trackersAction()
{
requireParams({"hash"});
requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
@@ -496,9 +496,9 @@ void TorrentsController::trackersAction()
// - "url": Web seed URL
void TorrentsController::webseedsAction()
{
requireParams({"hash"});
requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
@@ -528,9 +528,9 @@ void TorrentsController::webseedsAction()
// and the second number is the ending piece index (inclusive)
void TorrentsController::filesAction()
{
requireParams({"hash"});
requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
@@ -540,7 +540,7 @@ void TorrentsController::filesAction()
const auto idxIt = params().constFind(QLatin1String("indexes"));
if (idxIt != params().cend())
{
const QStringList indexStrings = idxIt.value().split('|');
const QStringList indexStrings = idxIt.value().split(u'|');
fileIndexes.reserve(indexStrings.size());
std::transform(indexStrings.cbegin(), indexStrings.cend(), std::back_inserter(fileIndexes)
, [&filesCount](const QString &indexString) -> int
@@ -597,9 +597,9 @@ void TorrentsController::filesAction()
// The return value is a JSON-formatted array of strings (hex strings).
void TorrentsController::pieceHashesAction()
{
requireParams({"hash"});
requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
@@ -609,7 +609,7 @@ void TorrentsController::pieceHashesAction()
{
const QVector<QByteArray> hashes = torrent->info().pieceHashes();
for (const QByteArray &hash : hashes)
pieceHashes.append(QString(hash.toHex()));
pieceHashes.append(QString::fromLatin1(hash.toHex()));
}
setResult(pieceHashes);
@@ -622,9 +622,9 @@ void TorrentsController::pieceHashesAction()
// 2: piece already downloaded
void TorrentsController::pieceStatesAction()
{
requireParams({"hash"});
requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
@@ -646,26 +646,26 @@ void TorrentsController::pieceStatesAction()
void TorrentsController::addAction()
{
const QString urls = params()["urls"];
const QString cookie = params()["cookie"];
const QString urls = params()[u"urls"_qs];
const QString cookie = params()[u"cookie"_qs];
const bool skipChecking = parseBool(params()["skip_checking"]).value_or(false);
const bool seqDownload = parseBool(params()["sequentialDownload"]).value_or(false);
const bool firstLastPiece = parseBool(params()["firstLastPiecePrio"]).value_or(false);
const std::optional<bool> addPaused = parseBool(params()["paused"]);
const QString savepath = params()["savepath"].trimmed();
const QString downloadPath = params()["downloadPath"].trimmed();
const std::optional<bool> useDownloadPath = parseBool(params()["useDownloadPath"]);
const QString category = params()["category"];
const QStringList tags = params()["tags"].split(',', Qt::SkipEmptyParts);
const QString torrentName = params()["rename"].trimmed();
const int upLimit = parseInt(params()["upLimit"]).value_or(-1);
const int dlLimit = parseInt(params()["dlLimit"]).value_or(-1);
const double ratioLimit = parseDouble(params()["ratioLimit"]).value_or(BitTorrent::Torrent::USE_GLOBAL_RATIO);
const int seedingTimeLimit = parseInt(params()["seedingTimeLimit"]).value_or(BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME);
const std::optional<bool> autoTMM = parseBool(params()["autoTMM"]);
const bool skipChecking = parseBool(params()[u"skip_checking"_qs]).value_or(false);
const bool seqDownload = parseBool(params()[u"sequentialDownload"_qs]).value_or(false);
const bool firstLastPiece = parseBool(params()[u"firstLastPiecePrio"_qs]).value_or(false);
const std::optional<bool> addPaused = parseBool(params()[u"paused"_qs]);
const QString savepath = params()[u"savepath"_qs].trimmed();
const QString downloadPath = params()[u"downloadPath"_qs].trimmed();
const std::optional<bool> useDownloadPath = parseBool(params()[u"useDownloadPath"_qs]);
const QString category = params()[u"category"_qs];
const QStringList tags = params()[u"tags"_qs].split(u',', Qt::SkipEmptyParts);
const QString torrentName = params()[u"rename"_qs].trimmed();
const int upLimit = parseInt(params()[u"upLimit"_qs]).value_or(-1);
const int dlLimit = parseInt(params()[u"dlLimit"_qs]).value_or(-1);
const double ratioLimit = parseDouble(params()[u"ratioLimit"_qs]).value_or(BitTorrent::Torrent::USE_GLOBAL_RATIO);
const int seedingTimeLimit = parseInt(params()[u"seedingTimeLimit"_qs]).value_or(BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME);
const std::optional<bool> autoTMM = parseBool(params()[u"autoTMM"_qs]);
const QString contentLayoutParam = params()["contentLayout"];
const QString contentLayoutParam = params()[u"contentLayout"_qs];
const std::optional<BitTorrent::TorrentContentLayout> contentLayout = (!contentLayoutParam.isEmpty()
? Utils::String::toEnum(contentLayoutParam, BitTorrent::TorrentContentLayout::Original)
: std::optional<BitTorrent::TorrentContentLayout> {});
@@ -673,11 +673,11 @@ void TorrentsController::addAction()
QList<QNetworkCookie> cookies;
if (!cookie.isEmpty())
{
const QStringList cookiesStr = cookie.split("; ");
const QStringList cookiesStr = cookie.split(u"; "_qs);
for (QString cookieStr : cookiesStr)
{
cookieStr = cookieStr.trimmed();
int index = cookieStr.indexOf('=');
int index = cookieStr.indexOf(u'=');
if (index > 1)
{
QByteArray name = cookieStr.left(index).toLatin1();
@@ -707,7 +707,7 @@ void TorrentsController::addAction()
addTorrentParams.useAutoTMM = autoTMM;
bool partialSuccess = false;
for (QString url : asConst(urls.split('\n')))
for (QString url : asConst(urls.split(u'\n')))
{
url = url.trimmed();
if (!url.isEmpty())
@@ -737,15 +737,15 @@ void TorrentsController::addAction()
void TorrentsController::addTrackersAction()
{
requireParams({"hash", "urls"});
requireParams({u"hash"_qs, u"urls"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
QVector<BitTorrent::TrackerEntry> trackers;
for (const QString &urlStr : asConst(params()["urls"].split('\n')))
for (const QString &urlStr : asConst(params()[u"urls"_qs].split(u'\n')))
{
const QUrl url {urlStr.trimmed()};
if (url.isValid())
@@ -756,11 +756,11 @@ void TorrentsController::addTrackersAction()
void TorrentsController::editTrackerAction()
{
requireParams({"hash", "origUrl", "newUrl"});
requireParams({u"hash"_qs, u"origUrl"_qs, u"newUrl"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const QString origUrl = params()["origUrl"];
const QString newUrl = params()["newUrl"];
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
const QString origUrl = params()[u"origUrl"_qs];
const QString newUrl = params()[u"newUrl"_qs];
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
@@ -771,7 +771,7 @@ void TorrentsController::editTrackerAction()
if (origTrackerUrl == newTrackerUrl)
return;
if (!newTrackerUrl.isValid())
throw APIError(APIErrorType::BadParams, "New tracker URL is invalid");
throw APIError(APIErrorType::BadParams, u"New tracker URL is invalid"_qs);
QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
bool match = false;
@@ -779,7 +779,7 @@ void TorrentsController::editTrackerAction()
{
const QUrl trackerUrl(tracker.url);
if (trackerUrl == newTrackerUrl)
throw APIError(APIErrorType::Conflict, "New tracker URL already exists");
throw APIError(APIErrorType::Conflict, u"New tracker URL already exists"_qs);
if (trackerUrl == origTrackerUrl)
{
match = true;
@@ -787,7 +787,7 @@ void TorrentsController::editTrackerAction()
}
}
if (!match)
throw APIError(APIErrorType::Conflict, "Tracker not found");
throw APIError(APIErrorType::Conflict, u"Tracker not found"_qs);
torrent->replaceTrackers(trackers);
@@ -797,14 +797,14 @@ void TorrentsController::editTrackerAction()
void TorrentsController::removeTrackersAction()
{
requireParams({"hash", "urls"});
requireParams({u"hash"_qs, u"urls"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
const QStringList urls = params()["urls"].split('|');
const QStringList urls = params()[u"urls"_qs].split(u'|');
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
QVector<BitTorrent::TrackerEntry> remainingTrackers;
@@ -816,7 +816,7 @@ void TorrentsController::removeTrackersAction()
}
if (remainingTrackers.size() == trackers.size())
throw APIError(APIErrorType::Conflict, "No trackers were removed");
throw APIError(APIErrorType::Conflict, u"No trackers were removed"_qs);
torrent->replaceTrackers(remainingTrackers);
@@ -826,10 +826,10 @@ void TorrentsController::removeTrackersAction()
void TorrentsController::addPeersAction()
{
requireParams({"hashes", "peers"});
requireParams({u"hashes"_qs, u"peers"_qs});
const QStringList hashes = params()["hashes"].split('|');
const QStringList peers = params()["peers"].split('|');
const QStringList hashes = params()[u"hashes"_qs].split(u'|');
const QStringList peers = params()[u"peers"_qs].split(u'|');
QVector<BitTorrent::PeerAddress> peerList;
peerList.reserve(peers.size());
@@ -841,7 +841,7 @@ void TorrentsController::addPeersAction()
}
if (peerList.isEmpty())
throw APIError(APIErrorType::BadParams, "No valid peers were specified");
throw APIError(APIErrorType::BadParams, u"No valid peers were specified"_qs);
QJsonObject results;
@@ -854,8 +854,8 @@ void TorrentsController::addPeersAction()
results[torrent->id().toString()] = QJsonObject
{
{"added", peersAdded},
{"failed", (peers.size() - peersAdded)}
{u"added"_qs, peersAdded},
{u"failed"_qs, (peers.size() - peersAdded)}
};
});
@@ -864,27 +864,27 @@ void TorrentsController::addPeersAction()
void TorrentsController::pauseAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList hashes = params()["hashes"].split('|');
const QStringList hashes = params()[u"hashes"_qs].split(u'|');
applyToTorrents(hashes, [](BitTorrent::Torrent *const torrent) { torrent->pause(); });
}
void TorrentsController::resumeAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList idStrings = params()["hashes"].split('|');
const QStringList idStrings = params()[u"hashes"_qs].split(u'|');
applyToTorrents(idStrings, [](BitTorrent::Torrent *const torrent) { torrent->resume(); });
}
void TorrentsController::filePrioAction()
{
requireParams({"hash", "id", "priority"});
requireParams({u"hash"_qs, u"id"_qs, u"priority"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
bool ok = false;
const auto priority = static_cast<BitTorrent::DownloadPriority>(params()["priority"].toInt(&ok));
const auto priority = static_cast<BitTorrent::DownloadPriority>(params()[u"priority"_qs].toInt(&ok));
if (!ok)
throw APIError(APIErrorType::BadParams, tr("Priority must be an integer"));
@@ -900,7 +900,7 @@ void TorrentsController::filePrioAction()
const int filesCount = torrent->filesCount();
QVector<BitTorrent::DownloadPriority> priorities = torrent->filePriorities();
bool priorityChanged = false;
for (const QString &fileID : params()["id"].split('|'))
for (const QString &fileID : params()[u"id"_qs].split(u'|'))
{
const int id = fileID.toInt(&ok);
if (!ok)
@@ -921,9 +921,9 @@ void TorrentsController::filePrioAction()
void TorrentsController::uploadLimitAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList idList {params()["hashes"].split('|')};
const QStringList idList {params()[u"hashes"_qs].split(u'|')};
QJsonObject map;
for (const QString &id : idList)
{
@@ -939,9 +939,9 @@ void TorrentsController::uploadLimitAction()
void TorrentsController::downloadLimitAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList idList {params()["hashes"].split('|')};
const QStringList idList {params()[u"hashes"_qs].split(u'|')};
QJsonObject map;
for (const QString &id : idList)
{
@@ -957,35 +957,35 @@ void TorrentsController::downloadLimitAction()
void TorrentsController::setUploadLimitAction()
{
requireParams({"hashes", "limit"});
requireParams({u"hashes"_qs, u"limit"_qs});
qlonglong limit = params()["limit"].toLongLong();
qlonglong limit = params()[u"limit"_qs].toLongLong();
if (limit == 0)
limit = -1;
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [limit](BitTorrent::Torrent *const torrent) { torrent->setUploadLimit(limit); });
}
void TorrentsController::setDownloadLimitAction()
{
requireParams({"hashes", "limit"});
requireParams({u"hashes"_qs, u"limit"_qs});
qlonglong limit = params()["limit"].toLongLong();
qlonglong limit = params()[u"limit"_qs].toLongLong();
if (limit == 0)
limit = -1;
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [limit](BitTorrent::Torrent *const torrent) { torrent->setDownloadLimit(limit); });
}
void TorrentsController::setShareLimitsAction()
{
requireParams({"hashes", "ratioLimit", "seedingTimeLimit"});
requireParams({u"hashes"_qs, u"ratioLimit"_qs, u"seedingTimeLimit"_qs});
const qreal ratioLimit = params()["ratioLimit"].toDouble();
const qlonglong seedingTimeLimit = params()["seedingTimeLimit"].toLongLong();
const QStringList hashes = params()["hashes"].split('|');
const qreal ratioLimit = params()[u"ratioLimit"_qs].toDouble();
const qlonglong seedingTimeLimit = params()[u"seedingTimeLimit"_qs].toLongLong();
const QStringList hashes = params()[u"hashes"_qs].split(u'|');
applyToTorrents(hashes, [ratioLimit, seedingTimeLimit](BitTorrent::Torrent *const torrent)
{
@@ -996,35 +996,35 @@ void TorrentsController::setShareLimitsAction()
void TorrentsController::toggleSequentialDownloadAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [](BitTorrent::Torrent *const torrent) { torrent->toggleSequentialDownload(); });
}
void TorrentsController::toggleFirstLastPiecePrioAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [](BitTorrent::Torrent *const torrent) { torrent->toggleFirstLastPiecePriority(); });
}
void TorrentsController::setSuperSeedingAction()
{
requireParams({"hashes", "value"});
requireParams({u"hashes"_qs, u"value"_qs});
const bool value {parseBool(params()["value"]).value_or(false)};
const QStringList hashes {params()["hashes"].split('|')};
const bool value {parseBool(params()[u"value"_qs]).value_or(false)};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [value](BitTorrent::Torrent *const torrent) { torrent->setSuperSeeding(value); });
}
void TorrentsController::setForceStartAction()
{
requireParams({"hashes", "value"});
requireParams({u"hashes"_qs, u"value"_qs});
const bool value {parseBool(params()["value"]).value_or(false)};
const QStringList hashes {params()["hashes"].split('|')};
const bool value {parseBool(params()[u"value"_qs]).value_or(false)};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [value](BitTorrent::Torrent *const torrent)
{
torrent->resume(value ? BitTorrent::TorrentOperatingMode::Forced : BitTorrent::TorrentOperatingMode::AutoManaged);
@@ -1033,10 +1033,10 @@ void TorrentsController::setForceStartAction()
void TorrentsController::deleteAction()
{
requireParams({"hashes", "deleteFiles"});
requireParams({u"hashes"_qs, u"deleteFiles"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const DeleteOption deleteOption = parseBool(params()["deleteFiles"]).value_or(false)
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
const DeleteOption deleteOption = parseBool(params()[u"deleteFiles"_qs]).value_or(false)
? DeleteTorrentAndFiles : DeleteTorrent;
applyToTorrents(hashes, [deleteOption](const BitTorrent::Torrent *torrent)
{
@@ -1046,54 +1046,54 @@ void TorrentsController::deleteAction()
void TorrentsController::increasePrioAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
if (!BitTorrent::Session::instance()->isQueueingSystemEnabled())
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
BitTorrent::Session::instance()->increaseTorrentsQueuePos(toTorrentIDs(hashes));
}
void TorrentsController::decreasePrioAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
if (!BitTorrent::Session::instance()->isQueueingSystemEnabled())
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
BitTorrent::Session::instance()->decreaseTorrentsQueuePos(toTorrentIDs(hashes));
}
void TorrentsController::topPrioAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
if (!BitTorrent::Session::instance()->isQueueingSystemEnabled())
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
BitTorrent::Session::instance()->topTorrentsQueuePos(toTorrentIDs(hashes));
}
void TorrentsController::bottomPrioAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
if (!BitTorrent::Session::instance()->isQueueingSystemEnabled())
throw APIError(APIErrorType::Conflict, tr("Torrent queueing must be enabled"));
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
BitTorrent::Session::instance()->bottomTorrentsQueuePos(toTorrentIDs(hashes));
}
void TorrentsController::setLocationAction()
{
requireParams({"hashes", "location"});
requireParams({u"hashes"_qs, u"location"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const Path newLocation {params()["location"].trimmed()};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
const Path newLocation {params()[u"location"_qs].trimmed()};
if (newLocation.isEmpty())
throw APIError(APIErrorType::BadParams, tr("Save path cannot be empty"));
@@ -1117,10 +1117,10 @@ void TorrentsController::setLocationAction()
void TorrentsController::setSavePathAction()
{
requireParams({"id", "path"});
requireParams({u"id"_qs, u"path"_qs});
const QStringList ids {params()["id"].split('|')};
const Path newPath {params()["path"]};
const QStringList ids {params()[u"id"_qs].split(u'|')};
const Path newPath {params()[u"path"_qs]};
if (newPath.isEmpty())
throw APIError(APIErrorType::BadParams, tr("Save path cannot be empty"));
@@ -1142,10 +1142,10 @@ void TorrentsController::setSavePathAction()
void TorrentsController::setDownloadPathAction()
{
requireParams({"id", "path"});
requireParams({u"id"_qs, u"path"_qs});
const QStringList ids {params()["id"].split('|')};
const Path newPath {params()["path"]};
const QStringList ids {params()[u"id"_qs].split(u'|')};
const Path newPath {params()[u"path"_qs]};
if (!newPath.isEmpty())
{
@@ -1167,10 +1167,10 @@ void TorrentsController::setDownloadPathAction()
void TorrentsController::renameAction()
{
requireParams({"hash", "name"});
requireParams({u"hash"_qs, u"name"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
QString name = params()["name"].trimmed();
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
QString name = params()[u"name"_qs].trimmed();
if (name.isEmpty())
throw APIError(APIErrorType::Conflict, tr("Incorrect torrent name"));
@@ -1179,16 +1179,16 @@ void TorrentsController::renameAction()
if (!torrent)
throw APIError(APIErrorType::NotFound);
name.replace(QRegularExpression("\r?\n|\r"), " ");
name.replace(QRegularExpression(u"\r?\n|\r"_qs), u" "_qs);
torrent->setName(name);
}
void TorrentsController::setAutoManagementAction()
{
requireParams({"hashes", "enable"});
requireParams({u"hashes"_qs, u"enable"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const bool isEnabled {parseBool(params()["enable"]).value_or(false)};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
const bool isEnabled {parseBool(params()[u"enable"_qs]).value_or(false)};
applyToTorrents(hashes, [isEnabled](BitTorrent::Torrent *const torrent)
{
@@ -1198,26 +1198,26 @@ void TorrentsController::setAutoManagementAction()
void TorrentsController::recheckAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [](BitTorrent::Torrent *const torrent) { torrent->forceRecheck(); });
}
void TorrentsController::reannounceAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
applyToTorrents(hashes, [](BitTorrent::Torrent *const torrent) { torrent->forceReannounce(); });
}
void TorrentsController::setCategoryAction()
{
requireParams({"hashes", "category"});
requireParams({u"hashes"_qs, u"category"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const QString category {params()["category"]};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
const QString category {params()[u"category"_qs]};
applyToTorrents(hashes, [category](BitTorrent::Torrent *const torrent)
{
@@ -1228,22 +1228,22 @@ void TorrentsController::setCategoryAction()
void TorrentsController::createCategoryAction()
{
requireParams({"category"});
requireParams({u"category"_qs});
const QString category = params()["category"];
const QString category = params()[u"category"_qs];
if (category.isEmpty())
throw APIError(APIErrorType::BadParams, tr("Category cannot be empty"));
if (!BitTorrent::Session::isValidCategoryName(category))
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
const Path savePath {params()["savePath"]};
const auto useDownloadPath = parseBool(params()["downloadPathEnabled"]);
const Path savePath {params()[u"savePath"_qs]};
const auto useDownloadPath = parseBool(params()[u"downloadPathEnabled"_qs]);
BitTorrent::CategoryOptions categoryOptions;
categoryOptions.savePath = savePath;
if (useDownloadPath.has_value())
{
const Path downloadPath {params()["downloadPath"]};
const Path downloadPath {params()[u"downloadPath"_qs]};
categoryOptions.downloadPath = {useDownloadPath.value(), downloadPath};
}
@@ -1253,19 +1253,19 @@ void TorrentsController::createCategoryAction()
void TorrentsController::editCategoryAction()
{
requireParams({"category", "savePath"});
requireParams({u"category"_qs, u"savePath"_qs});
const QString category = params()["category"];
const QString category = params()[u"category"_qs];
if (category.isEmpty())
throw APIError(APIErrorType::BadParams, tr("Category cannot be empty"));
const Path savePath {params()["savePath"]};
const auto useDownloadPath = parseBool(params()["downloadPathEnabled"]);
const Path savePath {params()[u"savePath"_qs]};
const auto useDownloadPath = parseBool(params()[u"downloadPathEnabled"_qs]);
BitTorrent::CategoryOptions categoryOptions;
categoryOptions.savePath = savePath;
if (useDownloadPath.has_value())
{
const Path downloadPath {params()["downloadPath"]};
const Path downloadPath {params()[u"downloadPath"_qs]};
categoryOptions.downloadPath = {useDownloadPath.value(), downloadPath};
}
@@ -1275,9 +1275,9 @@ void TorrentsController::editCategoryAction()
void TorrentsController::removeCategoriesAction()
{
requireParams({"categories"});
requireParams({u"categories"_qs});
const QStringList categories {params()["categories"].split('\n')};
const QStringList categories {params()[u"categories"_qs].split(u'\n')};
for (const QString &category : categories)
BitTorrent::Session::instance()->removeCategory(category);
}
@@ -1303,10 +1303,10 @@ void TorrentsController::categoriesAction()
void TorrentsController::addTagsAction()
{
requireParams({"hashes", "tags"});
requireParams({u"hashes"_qs, u"tags"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList tags {params()["tags"].split(',', Qt::SkipEmptyParts)};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
const QStringList tags {params()[u"tags"_qs].split(u',', Qt::SkipEmptyParts)};
for (const QString &tag : tags)
{
@@ -1320,10 +1320,10 @@ void TorrentsController::addTagsAction()
void TorrentsController::removeTagsAction()
{
requireParams({"hashes"});
requireParams({u"hashes"_qs});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList tags {params()["tags"].split(',', Qt::SkipEmptyParts)};
const QStringList hashes {params()[u"hashes"_qs].split(u'|')};
const QStringList tags {params()[u"tags"_qs].split(u',', Qt::SkipEmptyParts)};
for (const QString &tag : tags)
{
@@ -1345,9 +1345,9 @@ void TorrentsController::removeTagsAction()
void TorrentsController::createTagsAction()
{
requireParams({"tags"});
requireParams({u"tags"_qs});
const QStringList tags {params()["tags"].split(',', Qt::SkipEmptyParts)};
const QStringList tags {params()[u"tags"_qs].split(u',', Qt::SkipEmptyParts)};
for (const QString &tag : tags)
BitTorrent::Session::instance()->addTag(tag.trimmed());
@@ -1355,9 +1355,9 @@ void TorrentsController::createTagsAction()
void TorrentsController::deleteTagsAction()
{
requireParams({"tags"});
requireParams({u"tags"_qs});
const QStringList tags {params()["tags"].split(',', Qt::SkipEmptyParts)};
const QStringList tags {params()[u"tags"_qs].split(u',', Qt::SkipEmptyParts)};
for (const QString &tag : tags)
BitTorrent::Session::instance()->removeTag(tag.trimmed());
}
@@ -1372,15 +1372,15 @@ void TorrentsController::tagsAction()
void TorrentsController::renameFileAction()
{
requireParams({"hash", "oldPath", "newPath"});
requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
const Path oldPath {params()["oldPath"]};
const Path newPath {params()["newPath"]};
const Path oldPath {params()[u"oldPath"_qs]};
const Path newPath {params()[u"newPath"_qs]};
try
{
@@ -1394,15 +1394,15 @@ void TorrentsController::renameFileAction()
void TorrentsController::renameFolderAction()
{
requireParams({"hash", "oldPath", "newPath"});
requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()["hash"]);
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
const Path oldPath {params()["oldPath"]};
const Path newPath {params()["newPath"]};
const Path oldPath {params()[u"oldPath"_qs]};
const Path newPath {params()[u"newPath"_qs]};
try
{

View File

@@ -37,14 +37,14 @@
#include "base/global.h"
#include "apierror.h"
const char KEY_TRANSFER_DLSPEED[] = "dl_info_speed";
const char KEY_TRANSFER_DLDATA[] = "dl_info_data";
const char KEY_TRANSFER_DLRATELIMIT[] = "dl_rate_limit";
const char KEY_TRANSFER_UPSPEED[] = "up_info_speed";
const char KEY_TRANSFER_UPDATA[] = "up_info_data";
const char KEY_TRANSFER_UPRATELIMIT[] = "up_rate_limit";
const char KEY_TRANSFER_DHT_NODES[] = "dht_nodes";
const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status";
const QString KEY_TRANSFER_DLSPEED = u"dl_info_speed"_qs;
const QString KEY_TRANSFER_DLDATA = u"dl_info_data"_qs;
const QString KEY_TRANSFER_DLRATELIMIT = u"dl_rate_limit"_qs;
const QString KEY_TRANSFER_UPSPEED = u"up_info_speed"_qs;
const QString KEY_TRANSFER_UPDATA = u"up_info_data"_qs;
const QString KEY_TRANSFER_UPRATELIMIT = u"up_rate_limit"_qs;
const QString KEY_TRANSFER_DHT_NODES = u"dht_nodes"_qs;
const QString KEY_TRANSFER_CONNECTION_STATUS = u"connection_status"_qs;
// Returns the global transfer information in JSON format.
// The return value is a JSON-formatted dictionary.
@@ -90,8 +90,8 @@ void TransferController::downloadLimitAction()
void TransferController::setUploadLimitAction()
{
requireParams({"limit"});
qlonglong limit = params()["limit"].toLongLong();
requireParams({u"limit"_qs});
qlonglong limit = params()[u"limit"_qs].toLongLong();
if (limit == 0) limit = -1;
BitTorrent::Session::instance()->setUploadSpeedLimit(limit);
@@ -99,8 +99,8 @@ void TransferController::setUploadLimitAction()
void TransferController::setDownloadLimitAction()
{
requireParams({"limit"});
qlonglong limit = params()["limit"].toLongLong();
requireParams({u"limit"_qs});
qlonglong limit = params()[u"limit"_qs].toLongLong();
if (limit == 0) limit = -1;
BitTorrent::Session::instance()->setDownloadSpeedLimit(limit);
@@ -119,9 +119,9 @@ void TransferController::speedLimitsModeAction()
void TransferController::banPeersAction()
{
requireParams({"peers"});
requireParams({u"peers"_qs});
const QStringList peers = params()["peers"].split('|');
const QStringList peers = params()[u"peers"_qs].split(u'|');
for (const QString &peer : peers)
{
const BitTorrent::PeerAddress addr = BitTorrent::PeerAddress::parse(peer.trimmed());