Browse Source

WebAPI refactor: utilize parseBool() function

Coding style cleanup
Rename variable
Return const reference
Add const
adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
ce362f0e5e
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 4
      src/webui/abstractwebapplication.h
  2. 41
      src/webui/webapplication.cpp

4
src/webui/abstractwebapplication.h

@ -79,8 +79,8 @@ protected: @@ -79,8 +79,8 @@ protected:
static QString saveTmpFile(const QByteArray &data);
WebSessionData *session();
Http::Request request() const { return request_; }
Http::Environment env() const { return env_; }
const Http::Request &request() const { return request_; }
const Http::Environment &env() const { return env_; }
private slots:
void UnbanTimerEvent();

41
src/webui/webapplication.cpp

@ -262,12 +262,12 @@ void WebApplication::action_public_images() @@ -262,12 +262,12 @@ void WebApplication::action_public_images()
void WebApplication::action_query_torrents()
{
CHECK_URI(0);
const QStringMap& gets = request().gets;
const QStringMap &gets = request().gets;
print(btjson::getTorrents(
gets["filter"], gets["category"], gets["sort"], gets["reverse"] == "true",
gets["limit"].toInt(), gets["offset"].toInt()
), Http::CONTENT_TYPE_JSON);
gets["filter"], gets["category"], gets["sort"], parseBool(gets["reverse"], false),
gets["limit"].toInt(), gets["offset"].toInt())
, Http::CONTENT_TYPE_JSON);
}
void WebApplication::action_query_preferences()
@ -315,18 +315,18 @@ void WebApplication::action_query_propertiesFiles() @@ -315,18 +315,18 @@ void WebApplication::action_query_propertiesFiles()
void WebApplication::action_query_getLog()
{
CHECK_URI(0);
bool normal = request().gets["normal"] != "false";
bool info = request().gets["info"] != "false";
bool warning = request().gets["warning"] != "false";
bool critical = request().gets["critical"] != "false";
int lastKnownId;
bool ok;
lastKnownId = request().gets["last_known_id"].toInt(&ok);
const bool isNormal = parseBool(request().gets["normal"], true);
const bool isInfo = parseBool(request().gets["info"], true);
const bool isWarning = parseBool(request().gets["warning"], true);
const bool isCritical = parseBool(request().gets["critical"], true);
bool ok = false;
int lastKnownId = request().gets["last_known_id"].toInt(&ok);
if (!ok)
lastKnownId = -1;
print(btjson::getLog(normal, info, warning, critical, lastKnownId), Http::CONTENT_TYPE_JSON);
print(btjson::getLog(isNormal, isInfo, isWarning, isCritical, lastKnownId), Http::CONTENT_TYPE_JSON);
}
// GET params:
@ -698,8 +698,9 @@ void WebApplication::action_command_setSuperSeeding() @@ -698,8 +698,9 @@ void WebApplication::action_command_setSuperSeeding()
{
CHECK_URI(0);
CHECK_PARAMETERS("hashes" << "value");
bool value = request().posts["value"] == "true";
QStringList hashes = request().posts["hashes"].split('|');
const bool value = parseBool(request().posts["value"], false);
const QStringList hashes = request().posts["hashes"].split('|');
foreach (const QString &hash, hashes) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent)
@ -711,8 +712,9 @@ void WebApplication::action_command_setForceStart() @@ -711,8 +712,9 @@ void WebApplication::action_command_setForceStart()
{
CHECK_URI(0);
CHECK_PARAMETERS("hashes" << "value");
bool value = request().posts["value"] == "true";
QStringList hashes = request().posts["hashes"].split('|');
const bool value = parseBool(request().posts["value"], false);
const QStringList hashes = request().posts["hashes"].split('|');
foreach (const QString &hash, hashes) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent)
@ -840,13 +842,12 @@ void WebApplication::action_command_setAutoTMM() @@ -840,13 +842,12 @@ void WebApplication::action_command_setAutoTMM()
CHECK_URI(0);
CHECK_PARAMETERS("hashes" << "enable");
QStringList hashes = request().posts["hashes"].split('|');
QString enableStr = request().posts["enable"];
const QStringList hashes = request().posts["hashes"].split('|');
const bool isEnabled = parseBool(request().posts["enable"], false);
foreach (const QString &hash, hashes) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent)
torrent->setAutoTMMEnabled(QString::compare(enableStr, "true", Qt::CaseInsensitive) == 0);
torrent->setAutoTMMEnabled(isEnabled);
}
}

Loading…
Cancel
Save