Browse Source

Introduce a 'change listen port' cmd option

Closes #17789.
PR #17862.
adaptive-webui-19844
BallsOfSpaghetti 2 years ago committed by GitHub
parent
commit
fdba525e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/app/application.cpp
  2. 14
      src/app/cmdoptions.cpp
  3. 1
      src/app/cmdoptions.h

6
src/app/application.cpp

@ -196,6 +196,12 @@ Application::Application(int &argc, char **argv)
if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value
Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort); Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort);
if (m_commandLineArgs.torrentingPort > 0) // it will be -1 when user did not set any value
{
SettingValue<int> port {u"BitTorrent/Session/Port"_qs};
port = m_commandLineArgs.torrentingPort;
}
} }
Application::~Application() Application::~Application()

14
src/app/cmdoptions.cpp

@ -326,6 +326,7 @@ namespace
constexpr const BoolOption NO_SPLASH_OPTION {"no-splash"}; constexpr const BoolOption NO_SPLASH_OPTION {"no-splash"};
#endif #endif
constexpr const IntOption WEBUI_PORT_OPTION {"webui-port"}; constexpr const IntOption WEBUI_PORT_OPTION {"webui-port"};
constexpr const IntOption TORRENTING_PORT_OPTION {"torrenting-port"};
constexpr const StringOption PROFILE_OPTION {"profile"}; constexpr const StringOption PROFILE_OPTION {"profile"};
constexpr const StringOption CONFIGURATION_OPTION {"configuration"}; constexpr const StringOption CONFIGURATION_OPTION {"configuration"};
constexpr const BoolOption RELATIVE_FASTRESUME {"relative-fastresume"}; constexpr const BoolOption RELATIVE_FASTRESUME {"relative-fastresume"};
@ -353,6 +354,7 @@ QBtCommandLineParameters::QBtCommandLineParameters(const QProcessEnvironment &en
, shouldDaemonize(DAEMON_OPTION.value(env)) , shouldDaemonize(DAEMON_OPTION.value(env))
#endif #endif
, webUiPort(WEBUI_PORT_OPTION.value(env, -1)) , webUiPort(WEBUI_PORT_OPTION.value(env, -1))
, torrentingPort(TORRENTING_PORT_OPTION.value(env, -1))
, addPaused(PAUSED_OPTION.value(env)) , addPaused(PAUSED_OPTION.value(env))
, skipDialog(SKIP_DIALOG_OPTION.value(env)) , skipDialog(SKIP_DIALOG_OPTION.value(env))
, profileDir(PROFILE_OPTION.value(env)) , profileDir(PROFILE_OPTION.value(env))
@ -427,6 +429,15 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
throw CommandLineParameterError(QObject::tr("%1 must specify a valid port (1 to 65535).") throw CommandLineParameterError(QObject::tr("%1 must specify a valid port (1 to 65535).")
.arg(u"--webui-port"_qs)); .arg(u"--webui-port"_qs));
} }
else if (arg == TORRENTING_PORT_OPTION)
{
result.torrentingPort = TORRENTING_PORT_OPTION.value(arg);
if ((result.torrentingPort < 1) || (result.torrentingPort > 65535))
{
throw CommandLineParameterError(QObject::tr("%1 must specify a valid port (1 to 65535).")
.arg(u"--torrenting-port"_qs));
}
}
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
else if (arg == NO_SPLASH_OPTION) else if (arg == NO_SPLASH_OPTION)
{ {
@ -537,6 +548,9 @@ QString makeUsage(const QString &prgName)
+ WEBUI_PORT_OPTION.usage(QObject::tr("port")) + WEBUI_PORT_OPTION.usage(QObject::tr("port"))
+ wrapText(QObject::tr("Change the Web UI port")) + wrapText(QObject::tr("Change the Web UI port"))
+ u'\n' + u'\n'
+ TORRENTING_PORT_OPTION.usage(QObject::tr("port"))
+ wrapText(QObject::tr("Change the torrenting port"))
+ u'\n'
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
+ NO_SPLASH_OPTION.usage() + wrapText(QObject::tr("Disable splash screen")) + u'\n' + NO_SPLASH_OPTION.usage() + wrapText(QObject::tr("Disable splash screen")) + u'\n'
#elif !defined(Q_OS_WIN) #elif !defined(Q_OS_WIN)

1
src/app/cmdoptions.h

@ -56,6 +56,7 @@ struct QBtCommandLineParameters
bool shouldDaemonize; bool shouldDaemonize;
#endif #endif
int webUiPort; int webUiPort;
int torrentingPort;
std::optional<bool> addPaused; std::optional<bool> addPaused;
std::optional<bool> skipDialog; std::optional<bool> skipDialog;
QStringList torrents; QStringList torrents;

Loading…
Cancel
Save