qBittorrent
anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption Class Reference
Inheritance diagram for anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption:
Collaboration diagram for anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption:

Public Member Functions

constexpr TriStateBoolOption (const char *name, bool defaultValue)
 
bool operator== (const QString &arg) const
 
QString usage () const
 
std::optional< bool > value (const QString &arg) const
 
std::optional< bool > value (const QProcessEnvironment &env) const
 

Public Attributes

bool m_defaultValue
 

Additional Inherited Members

- Protected Member Functions inherited from anonymous_namespace{cmdoptions.cpp}::Option
constexpr Option (const char *name, char shortcut=0)
 
QString fullParameter () const
 
QString shortcutParameter () const
 
bool hasShortcut () const
 
QString envVarName () const
 
- Static Protected Member Functions inherited from anonymous_namespace{cmdoptions.cpp}::Option
static QString padUsageText (const QString &usage)
 

Detailed Description

Definition at line 237 of file cmdoptions.cpp.

Constructor & Destructor Documentation

◆ TriStateBoolOption()

constexpr anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption::TriStateBoolOption ( const char *  name,
bool  defaultValue 
)
inlineconstexpr

Definition at line 240 of file cmdoptions.cpp.

241  : Option {name, 0}
242  , m_defaultValue(defaultValue)
243  {
244  }
constexpr Option(const char *name, char shortcut=0)
Definition: cmdoptions.cpp:62

Member Function Documentation

◆ operator==()

bool anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption::operator== ( const QString &  arg) const
inline

Definition at line 246 of file cmdoptions.cpp.

247  {
248  QStringList parts = arg.split(QLatin1Char('='));
249  return parts[0] == fullParameter();
250  }

◆ usage()

QString anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption::usage ( ) const
inline

Definition at line 252 of file cmdoptions.cpp.

253  {
254  return padUsageText(fullParameter() + QLatin1String("=<true|false>"));
255  }
static QString padUsageText(const QString &usage)
Definition: cmdoptions.cpp:90

Referenced by makeUsage().

Here is the caller graph for this function:

◆ value() [1/2]

std::optional<bool> anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption::value ( const QProcessEnvironment &  env) const
inline

Definition at line 285 of file cmdoptions.cpp.

286  {
287  const QString val = env.value(envVarName(), "-1");
288 
289  if (val.isEmpty())
290  {
291  return m_defaultValue;
292  }
293  if (val == QLatin1String("-1"))
294  {
295  return std::nullopt;
296  }
297  if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1")))
298  {
299  return true;
300  }
301  if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0")))
302  {
303  return false;
304  }
305 
306  qDebug() << QObject::tr("Expected %1 in environment variable '%2', but got '%3'")
307  .arg(QLatin1String("true|false"), envVarName(), val);
308  return std::nullopt;
309  }

Referenced by nova3.socks.ProxyError::__str__(), nova3.socks.GeneralProxyError::__str__(), nova3.socks.Socks5AuthError::__str__(), nova3.socks.Socks5Error::__str__(), nova3.socks.Socks4Error::__str__(), and nova3.socks.HTTPError::__str__().

Here is the caller graph for this function:

◆ value() [2/2]

std::optional<bool> anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption::value ( const QString &  arg) const
inline

Definition at line 257 of file cmdoptions.cpp.

258  {
259  QStringList parts = arg.split(QLatin1Char('='));
260 
261  if (parts.size() == 1)
262  {
263  return m_defaultValue;
264  }
265  if (parts.size() == 2)
266  {
267  QString val = parts[1];
268 
269  if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1")))
270  {
271  return true;
272  }
273  if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0")))
274  {
275  return false;
276  }
277  }
278 
279  throw CommandLineParameterError(QObject::tr("Parameter '%1' must follow syntax '%1=%2'",
280  "e.g. Parameter '--add-paused' must follow syntax "
281  "'--add-paused=<true|false>'")
282  .arg(fullParameter(), QLatin1String("<true|false>")));
283  }

Referenced by nova3.socks.ProxyError::__str__(), nova3.socks.GeneralProxyError::__str__(), nova3.socks.Socks5AuthError::__str__(), nova3.socks.Socks5Error::__str__(), nova3.socks.Socks4Error::__str__(), nova3.socks.HTTPError::__str__(), and parseCommandLine().

Here is the caller graph for this function:

Member Data Documentation

◆ m_defaultValue

bool anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption::m_defaultValue

Definition at line 311 of file cmdoptions.cpp.


The documentation for this class was generated from the following file: