mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
Merge pull request #6720 from sledgehammer999/implicit_value_for_tristate_options
Don't enforce an explicit value for TriState cmd options.
This commit is contained in:
commit
e38829218e
6 changed files with 47 additions and 30 deletions
|
@ -3,14 +3,14 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
set(QBT_APP_HEADERS
|
set(QBT_APP_HEADERS
|
||||||
application.h
|
application.h
|
||||||
|
cmdoptions.h
|
||||||
filelogger.h
|
filelogger.h
|
||||||
options.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(QBT_APP_SOURCES
|
set(QBT_APP_SOURCES
|
||||||
application.cpp
|
application.cpp
|
||||||
|
cmdoptions.cpp
|
||||||
filelogger.cpp
|
filelogger.cpp
|
||||||
options.cpp
|
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@ usesystemqtsingleapplication {
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/application.h \
|
$$PWD/application.h \
|
||||||
$$PWD/filelogger.h \
|
$$PWD/cmdoptions.h \
|
||||||
$$PWD/options.h
|
$$PWD/filelogger.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/application.cpp \
|
$$PWD/application.cpp \
|
||||||
|
$$PWD/cmdoptions.cpp \
|
||||||
$$PWD/filelogger.cpp \
|
$$PWD/filelogger.cpp \
|
||||||
$$PWD/options.cpp \
|
|
||||||
$$PWD/main.cpp
|
$$PWD/main.cpp
|
||||||
|
|
||||||
unix: HEADERS += $$PWD/stacktrace.h
|
unix: HEADERS += $$PWD/stacktrace.h
|
||||||
|
|
|
@ -51,7 +51,7 @@ typedef QtSingleCoreApplication BaseApplication;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "options.h"
|
#include "cmdoptions.h"
|
||||||
|
|
||||||
#ifndef DISABLE_WEBUI
|
#ifndef DISABLE_WEBUI
|
||||||
class WebUI;
|
class WebUI;
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
* Contact : chris@qbittorrent.org
|
* Contact : chris@qbittorrent.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "options.h"
|
#include "cmdoptions.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -242,45 +242,59 @@ namespace
|
||||||
|
|
||||||
// Option that is explicitly set to true or false, and whose value is undefined when unspecified.
|
// Option that is explicitly set to true or false, and whose value is undefined when unspecified.
|
||||||
// May not have a shortcut.
|
// May not have a shortcut.
|
||||||
class TriStateBoolOption: protected StringOption
|
class TriStateBoolOption: protected Option
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr TriStateBoolOption(const char *name)
|
constexpr TriStateBoolOption(const char *name, bool defaultValue)
|
||||||
: StringOption {name}
|
: Option {name, 0}
|
||||||
|
, m_defaultValue(defaultValue)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
using StringOption::operator==;
|
bool operator==(const QString &arg) const
|
||||||
|
{
|
||||||
|
QStringList parts = arg.split(QLatin1Char('='));
|
||||||
|
return parts[0] == fullParameter();
|
||||||
|
}
|
||||||
|
|
||||||
QString usage() const
|
QString usage() const
|
||||||
{
|
{
|
||||||
return StringOption::usage(QLatin1String("true|false"));
|
return padUsageText(fullParameter() + QLatin1String("=<true|false>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TriStateBool value(const QString &arg) const
|
TriStateBool value(const QString &arg) const
|
||||||
{
|
{
|
||||||
QString val = StringOption::value(arg);
|
QStringList parts = arg.split(QLatin1Char('='));
|
||||||
|
|
||||||
if (val.toUpper() == QLatin1String("TRUE") || val == QLatin1String("1")) {
|
if (parts.size() == 1) {
|
||||||
return TriStateBool::True;
|
return TriStateBool(m_defaultValue);
|
||||||
}
|
}
|
||||||
else if (val.toUpper() == QLatin1String("FALSE") || val == QLatin1String("0")) {
|
else if (parts.size() == 2) {
|
||||||
return TriStateBool::False;
|
QString val = parts[1];
|
||||||
}
|
|
||||||
else {
|
if (val.toUpper() == QLatin1String("TRUE") || val == QLatin1String("1")) {
|
||||||
throw CommandLineParameterError(QObject::tr("Parameter '%1' must follow syntax '%1=%2'",
|
return TriStateBool::True;
|
||||||
"e.g. Parameter '--add-paused' must follow syntax "
|
}
|
||||||
"'--add-paused=<true|false>'")
|
else if (val.toUpper() == QLatin1String("FALSE") || val == QLatin1String("0")) {
|
||||||
.arg(fullParameter())
|
return TriStateBool::False;
|
||||||
.arg(QLatin1String("<true|false>")));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw CommandLineParameterError(QObject::tr("Parameter '%1' must follow syntax '%1=%2'",
|
||||||
|
"e.g. Parameter '--add-paused' must follow syntax "
|
||||||
|
"'--add-paused=<true|false>'")
|
||||||
|
.arg(fullParameter())
|
||||||
|
.arg(QLatin1String("<true|false>")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TriStateBool value(const QProcessEnvironment &env) const
|
TriStateBool value(const QProcessEnvironment &env) const
|
||||||
{
|
{
|
||||||
QString val = env.value(envVarName());
|
QString val = env.value(envVarName(), "-1");
|
||||||
|
|
||||||
if (val.isEmpty()) {
|
if (val.isEmpty()) {
|
||||||
|
return TriStateBool(m_defaultValue);
|
||||||
|
}
|
||||||
|
else if (val == QLatin1String("-1")) {
|
||||||
return TriStateBool::Undefined;
|
return TriStateBool::Undefined;
|
||||||
}
|
}
|
||||||
else if (val.toUpper() == QLatin1String("TRUE") || val == QLatin1String("1")) {
|
else if (val.toUpper() == QLatin1String("TRUE") || val == QLatin1String("1")) {
|
||||||
|
@ -295,6 +309,8 @@ namespace
|
||||||
return TriStateBool::Undefined;
|
return TriStateBool::Undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool m_defaultValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const QString &s, const TriStateBoolOption &o)
|
bool operator==(const QString &s, const TriStateBoolOption &o)
|
||||||
|
@ -315,12 +331,12 @@ namespace
|
||||||
constexpr const BoolOption PORTABLE_OPTION = {"portable"};
|
constexpr const BoolOption PORTABLE_OPTION = {"portable"};
|
||||||
constexpr const BoolOption RELATIVE_FASTRESUME = {"relative-fastresume"};
|
constexpr const BoolOption RELATIVE_FASTRESUME = {"relative-fastresume"};
|
||||||
constexpr const StringOption SAVE_PATH_OPTION = {"save-path"};
|
constexpr const StringOption SAVE_PATH_OPTION = {"save-path"};
|
||||||
constexpr const TriStateBoolOption PAUSED_OPTION = {"add-paused"};
|
constexpr const TriStateBoolOption PAUSED_OPTION = {"add-paused", true};
|
||||||
constexpr const BoolOption SKIP_HASH_CHECK_OPTION = {"skip-hash-check"};
|
constexpr const BoolOption SKIP_HASH_CHECK_OPTION = {"skip-hash-check"};
|
||||||
constexpr const StringOption CATEGORY_OPTION = {"category"};
|
constexpr const StringOption CATEGORY_OPTION = {"category"};
|
||||||
constexpr const BoolOption SEQUENTIAL_OPTION = {"sequential"};
|
constexpr const BoolOption SEQUENTIAL_OPTION = {"sequential"};
|
||||||
constexpr const BoolOption FIRST_AND_LAST_OPTION = {"first-and-last"};
|
constexpr const BoolOption FIRST_AND_LAST_OPTION = {"first-and-last"};
|
||||||
constexpr const TriStateBoolOption SKIP_DIALOG_OPTION = {"skip-dialog"};
|
constexpr const TriStateBoolOption SKIP_DIALOG_OPTION = {"skip-dialog", true};
|
||||||
}
|
}
|
||||||
|
|
||||||
QBtCommandLineParameters::QBtCommandLineParameters(const QProcessEnvironment &env)
|
QBtCommandLineParameters::QBtCommandLineParameters(const QProcessEnvironment &env)
|
|
@ -69,11 +69,12 @@ Q_IMPORT_PLUGIN(QICOPlugin)
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "options.h"
|
|
||||||
#include "base/profile.h"
|
#include "base/profile.h"
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
|
#include "cmdoptions.h"
|
||||||
|
|
||||||
#include "upgrade.h"
|
#include "upgrade.h"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue