mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-10 15:32:48 -07:00
Move parsing of TriStateBool to a static class function
This commit is contained in:
parent
cfb55d9d77
commit
e022c371ff
5 changed files with 18 additions and 17 deletions
|
@ -28,6 +28,17 @@
|
||||||
|
|
||||||
#include "tristatebool.h"
|
#include "tristatebool.h"
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
const TriStateBool TriStateBool::Undefined(-1);
|
const TriStateBool TriStateBool::Undefined(-1);
|
||||||
const TriStateBool TriStateBool::False(0);
|
const TriStateBool TriStateBool::False(0);
|
||||||
const TriStateBool TriStateBool::True(1);
|
const TriStateBool TriStateBool::True(1);
|
||||||
|
|
||||||
|
TriStateBool TriStateBool::fromString(const QString &string)
|
||||||
|
{
|
||||||
|
if (string.compare("true", Qt::CaseInsensitive) == 0)
|
||||||
|
return True;
|
||||||
|
if (string.compare("false", Qt::CaseInsensitive) == 0)
|
||||||
|
return False;
|
||||||
|
return Undefined;
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
class QString;
|
||||||
|
|
||||||
class TriStateBool
|
class TriStateBool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -54,6 +56,8 @@ public:
|
||||||
return (left.m_value == right.m_value);
|
return (left.m_value == right.m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TriStateBool fromString(const QString &string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit constexpr TriStateBool(const int value)
|
explicit constexpr TriStateBool(const int value)
|
||||||
: m_value((value < 0) ? -1 : ((value > 0) ? 1 : 0))
|
: m_value((value < 0) ? -1 : ((value > 0) ? 1 : 0))
|
||||||
|
|
|
@ -42,8 +42,6 @@
|
||||||
#include <QThreadStorage>
|
#include <QThreadStorage>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "base/tristatebool.h"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class NaturalCompare
|
class NaturalCompare
|
||||||
|
@ -199,15 +197,6 @@ bool Utils::String::parseBool(const QString &string, const bool defaultValue)
|
||||||
return (string.compare("true", Qt::CaseInsensitive) == 0) ? true : false;
|
return (string.compare("true", Qt::CaseInsensitive) == 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TriStateBool Utils::String::parseTriStateBool(const QString &string)
|
|
||||||
{
|
|
||||||
if (string.compare("true", Qt::CaseInsensitive) == 0)
|
|
||||||
return TriStateBool::True;
|
|
||||||
if (string.compare("false", Qt::CaseInsensitive) == 0)
|
|
||||||
return TriStateBool::False;
|
|
||||||
return TriStateBool::Undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Utils::String::join(const QVector<QStringRef> &strings, const QString &separator)
|
QString Utils::String::join(const QVector<QStringRef> &strings, const QString &separator)
|
||||||
{
|
{
|
||||||
if (strings.empty())
|
if (strings.empty())
|
||||||
|
|
|
@ -37,8 +37,6 @@
|
||||||
|
|
||||||
class QStringRef;
|
class QStringRef;
|
||||||
|
|
||||||
class TriStateBool;
|
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
namespace String
|
namespace String
|
||||||
|
@ -69,7 +67,6 @@ namespace Utils
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parseBool(const QString &string, bool defaultValue);
|
bool parseBool(const QString &string, bool defaultValue);
|
||||||
TriStateBool parseTriStateBool(const QString &string);
|
|
||||||
|
|
||||||
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/net/downloadmanager.h"
|
#include "base/net/downloadmanager.h"
|
||||||
#include "base/torrentfilter.h"
|
#include "base/torrentfilter.h"
|
||||||
|
#include "base/tristatebool.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/string.h"
|
#include "base/utils/string.h"
|
||||||
#include "apierror.h"
|
#include "apierror.h"
|
||||||
|
@ -117,7 +118,6 @@ const char KEY_FILE_AVAILABILITY[] = "availability";
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using Utils::String::parseBool;
|
using Utils::String::parseBool;
|
||||||
using Utils::String::parseTriStateBool;
|
|
||||||
|
|
||||||
void applyToTorrents(const QStringList &hashes, const std::function<void (BitTorrent::TorrentHandle *torrent)> &func)
|
void applyToTorrents(const QStringList &hashes, const std::function<void (BitTorrent::TorrentHandle *torrent)> &func)
|
||||||
{
|
{
|
||||||
|
@ -605,7 +605,7 @@ void TorrentsController::addAction()
|
||||||
const bool skipChecking = parseBool(params()["skip_checking"], false);
|
const bool skipChecking = parseBool(params()["skip_checking"], false);
|
||||||
const bool seqDownload = parseBool(params()["sequentialDownload"], false);
|
const bool seqDownload = parseBool(params()["sequentialDownload"], false);
|
||||||
const bool firstLastPiece = parseBool(params()["firstLastPiecePrio"], false);
|
const bool firstLastPiece = parseBool(params()["firstLastPiecePrio"], false);
|
||||||
const TriStateBool addPaused = parseTriStateBool(params()["paused"]);
|
const auto addPaused = TriStateBool::fromString(params()["paused"]);
|
||||||
const QString savepath = params()["savepath"].trimmed();
|
const QString savepath = params()["savepath"].trimmed();
|
||||||
const QString category = params()["category"];
|
const QString category = params()["category"];
|
||||||
const QSet<QString> tags = List::toSet(params()["tags"].split(',', QString::SkipEmptyParts));
|
const QSet<QString> tags = List::toSet(params()["tags"].split(',', QString::SkipEmptyParts));
|
||||||
|
@ -613,7 +613,7 @@ void TorrentsController::addAction()
|
||||||
const QString torrentName = params()["rename"].trimmed();
|
const QString torrentName = params()["rename"].trimmed();
|
||||||
const int upLimit = params()["upLimit"].toInt();
|
const int upLimit = params()["upLimit"].toInt();
|
||||||
const int dlLimit = params()["dlLimit"].toInt();
|
const int dlLimit = params()["dlLimit"].toInt();
|
||||||
const TriStateBool autoTMM = parseTriStateBool(params()["autoTMM"]);
|
const auto autoTMM = TriStateBool::fromString(params()["autoTMM"]);
|
||||||
|
|
||||||
const QString contentLayoutParam = params()["contentLayout"];
|
const QString contentLayoutParam = params()["contentLayout"];
|
||||||
const boost::optional<BitTorrent::TorrentContentLayout> contentLayout = (!contentLayoutParam.isEmpty()
|
const boost::optional<BitTorrent::TorrentContentLayout> contentLayout = (!contentLayoutParam.isEmpty()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue