mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 01:33:07 -07:00
Improve coding style
This commit is contained in:
parent
acad35c5bc
commit
c41df9ffbd
147 changed files with 4454 additions and 2227 deletions
|
@ -217,7 +217,8 @@ namespace
|
|||
|
||||
bool ok;
|
||||
int res = val.toInt(&ok);
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
qDebug() << QObject::tr("Expected integer number in environment variable '%1', but got '%2'")
|
||||
.arg(envVarName(), val);
|
||||
return defaultValue;
|
||||
|
@ -257,16 +258,20 @@ namespace
|
|||
{
|
||||
QStringList parts = arg.split(QLatin1Char('='));
|
||||
|
||||
if (parts.size() == 1) {
|
||||
if (parts.size() == 1)
|
||||
{
|
||||
return TriStateBool(m_defaultValue);
|
||||
}
|
||||
if (parts.size() == 2) {
|
||||
if (parts.size() == 2)
|
||||
{
|
||||
QString val = parts[1];
|
||||
|
||||
if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) {
|
||||
if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1")))
|
||||
{
|
||||
return TriStateBool::True;
|
||||
}
|
||||
if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) {
|
||||
if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0")))
|
||||
{
|
||||
return TriStateBool::False;
|
||||
}
|
||||
}
|
||||
|
@ -281,16 +286,20 @@ namespace
|
|||
{
|
||||
const QString val = env.value(envVarName(), "-1");
|
||||
|
||||
if (val.isEmpty()) {
|
||||
if (val.isEmpty())
|
||||
{
|
||||
return TriStateBool(m_defaultValue);
|
||||
}
|
||||
if (val == QLatin1String("-1")) {
|
||||
if (val == QLatin1String("-1"))
|
||||
{
|
||||
return TriStateBool::Undefined;
|
||||
}
|
||||
if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) {
|
||||
if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1")))
|
||||
{
|
||||
return TriStateBool::True;
|
||||
}
|
||||
if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) {
|
||||
if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0")))
|
||||
{
|
||||
return TriStateBool::False;
|
||||
}
|
||||
|
||||
|
@ -365,10 +374,12 @@ QStringList QBtCommandLineParameters::paramList() const
|
|||
if (!savePath.isEmpty())
|
||||
result.append(QLatin1String("@savePath=") + savePath);
|
||||
|
||||
if (addPaused == TriStateBool::True) {
|
||||
if (addPaused == TriStateBool::True)
|
||||
{
|
||||
result.append(QLatin1String("@addPaused=1"));
|
||||
}
|
||||
else if (addPaused == TriStateBool::False) {
|
||||
else if (addPaused == TriStateBool::False)
|
||||
{
|
||||
result.append(QLatin1String("@addPaused=0"));
|
||||
}
|
||||
|
||||
|
@ -384,10 +395,12 @@ QStringList QBtCommandLineParameters::paramList() const
|
|||
if (firstLastPiecePriority)
|
||||
result.append(QLatin1String("@firstLastPiecePriority"));
|
||||
|
||||
if (skipDialog == TriStateBool::True) {
|
||||
if (skipDialog == TriStateBool::True)
|
||||
{
|
||||
result.append(QLatin1String("@skipDialog=1"));
|
||||
}
|
||||
else if (skipDialog == TriStateBool::False) {
|
||||
else if (skipDialog == TriStateBool::False)
|
||||
{
|
||||
result.append(QLatin1String("@skipDialog=0"));
|
||||
}
|
||||
|
||||
|
@ -399,72 +412,91 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
|
|||
{
|
||||
QBtCommandLineParameters result {QProcessEnvironment::systemEnvironment()};
|
||||
|
||||
for (int i = 1; i < args.count(); ++i) {
|
||||
for (int i = 1; i < args.count(); ++i)
|
||||
{
|
||||
const QString &arg = args[i];
|
||||
|
||||
if ((arg.startsWith("--") && !arg.endsWith(".torrent"))
|
||||
|| (arg.startsWith('-') && (arg.size() == 2))) {
|
||||
|| (arg.startsWith('-') && (arg.size() == 2)))
|
||||
{
|
||||
// Parse known parameters
|
||||
if (arg == SHOW_HELP_OPTION) {
|
||||
if (arg == SHOW_HELP_OPTION)
|
||||
{
|
||||
result.showHelp = true;
|
||||
}
|
||||
#if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
|
||||
else if (arg == SHOW_VERSION_OPTION) {
|
||||
else if (arg == SHOW_VERSION_OPTION)
|
||||
{
|
||||
result.showVersion = true;
|
||||
}
|
||||
#endif
|
||||
else if (arg == WEBUI_PORT_OPTION) {
|
||||
else if (arg == WEBUI_PORT_OPTION)
|
||||
{
|
||||
result.webUiPort = WEBUI_PORT_OPTION.value(arg);
|
||||
if ((result.webUiPort < 1) || (result.webUiPort > 65535))
|
||||
throw CommandLineParameterError(QObject::tr("%1 must specify a valid port (1 to 65535).")
|
||||
.arg(QLatin1String("--webui-port")));
|
||||
}
|
||||
#ifndef DISABLE_GUI
|
||||
else if (arg == NO_SPLASH_OPTION) {
|
||||
else if (arg == NO_SPLASH_OPTION)
|
||||
{
|
||||
result.noSplash = true;
|
||||
}
|
||||
#elif !defined(Q_OS_WIN)
|
||||
else if (arg == DAEMON_OPTION) {
|
||||
else if (arg == DAEMON_OPTION)
|
||||
{
|
||||
result.shouldDaemonize = true;
|
||||
}
|
||||
#endif
|
||||
else if (arg == PROFILE_OPTION) {
|
||||
else if (arg == PROFILE_OPTION)
|
||||
{
|
||||
result.profileDir = PROFILE_OPTION.value(arg);
|
||||
}
|
||||
else if (arg == RELATIVE_FASTRESUME) {
|
||||
else if (arg == RELATIVE_FASTRESUME)
|
||||
{
|
||||
result.relativeFastresumePaths = true;
|
||||
}
|
||||
else if (arg == CONFIGURATION_OPTION) {
|
||||
else if (arg == CONFIGURATION_OPTION)
|
||||
{
|
||||
result.configurationName = CONFIGURATION_OPTION.value(arg);
|
||||
}
|
||||
else if (arg == SAVE_PATH_OPTION) {
|
||||
else if (arg == SAVE_PATH_OPTION)
|
||||
{
|
||||
result.savePath = SAVE_PATH_OPTION.value(arg);
|
||||
}
|
||||
else if (arg == PAUSED_OPTION) {
|
||||
else if (arg == PAUSED_OPTION)
|
||||
{
|
||||
result.addPaused = PAUSED_OPTION.value(arg);
|
||||
}
|
||||
else if (arg == SKIP_HASH_CHECK_OPTION) {
|
||||
else if (arg == SKIP_HASH_CHECK_OPTION)
|
||||
{
|
||||
result.skipChecking = true;
|
||||
}
|
||||
else if (arg == CATEGORY_OPTION) {
|
||||
else if (arg == CATEGORY_OPTION)
|
||||
{
|
||||
result.category = CATEGORY_OPTION.value(arg);
|
||||
}
|
||||
else if (arg == SEQUENTIAL_OPTION) {
|
||||
else if (arg == SEQUENTIAL_OPTION)
|
||||
{
|
||||
result.sequential = true;
|
||||
}
|
||||
else if (arg == FIRST_AND_LAST_OPTION) {
|
||||
else if (arg == FIRST_AND_LAST_OPTION)
|
||||
{
|
||||
result.firstLastPiecePriority = true;
|
||||
}
|
||||
else if (arg == SKIP_DIALOG_OPTION) {
|
||||
else if (arg == SKIP_DIALOG_OPTION)
|
||||
{
|
||||
result.skipDialog = SKIP_DIALOG_OPTION.value(arg);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// Unknown argument
|
||||
result.unknownParameter = arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
QFileInfo torrentPath;
|
||||
torrentPath.setFile(arg);
|
||||
|
||||
|
@ -495,11 +527,14 @@ QString wrapText(const QString &text, int initialIndentation = USAGE_TEXT_COLUMN
|
|||
QStringList lines = {words.first()};
|
||||
int currentLineMaxLength = wrapAtColumn - initialIndentation;
|
||||
|
||||
for (const QString &word : asConst(words.mid(1))) {
|
||||
if (lines.last().length() + word.length() + 1 < currentLineMaxLength) {
|
||||
for (const QString &word : asConst(words.mid(1)))
|
||||
{
|
||||
if (lines.last().length() + word.length() + 1 < currentLineMaxLength)
|
||||
{
|
||||
lines.last().append(' ' + word);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
lines.append(QString(initialIndentation, ' ') + word);
|
||||
currentLineMaxLength = wrapAtColumn;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue