mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 03:28:41 -07:00
HOTFIX: Correct command line parameters defaults.
This commit is contained in:
parent
96585ca73e
commit
afdc1ee93e
4 changed files with 91 additions and 28 deletions
113
src/main.cpp
113
src/main.cpp
|
@ -103,8 +103,10 @@ void sigabrtHandler(int);
|
||||||
|
|
||||||
struct QbtCommandLineParameters
|
struct QbtCommandLineParameters
|
||||||
{
|
{
|
||||||
bool showVersion;
|
|
||||||
bool showHelp;
|
bool showHelp;
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
bool showVersion;
|
||||||
|
#endif
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
bool noSplash;
|
bool noSplash;
|
||||||
#else
|
#else
|
||||||
|
@ -112,6 +114,20 @@ struct QbtCommandLineParameters
|
||||||
#endif
|
#endif
|
||||||
int webUiPort;
|
int webUiPort;
|
||||||
QStringList torrents;
|
QStringList torrents;
|
||||||
|
|
||||||
|
QbtCommandLineParameters()
|
||||||
|
: showHelp(false)
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
, showVersion(false)
|
||||||
|
#endif
|
||||||
|
#ifndef DISABLE_GUI
|
||||||
|
, noSplash(Preferences::instance()->isSplashScreenDisabled())
|
||||||
|
#else
|
||||||
|
, shouldDaemonize(false)
|
||||||
|
#endif
|
||||||
|
, webUiPort(Preferences::instance()->getWebUiPort())
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QbtCommandLineParameters parseCommandLine();
|
QbtCommandLineParameters parseCommandLine();
|
||||||
|
@ -120,9 +136,9 @@ QbtCommandLineParameters parseCommandLine();
|
||||||
void showSplashScreen();
|
void showSplashScreen();
|
||||||
#endif
|
#endif
|
||||||
void displayVersion();
|
void displayVersion();
|
||||||
void displayUsage(const char *prg_name);
|
void displayUsage(QString prg_name = QLatin1String("qbittorrent"));
|
||||||
bool userAgreesWithLegalNotice();
|
bool userAgreesWithLegalNotice();
|
||||||
void displayBadArgMessage(const QString& message);
|
void displayBadArgMessage(QString message);
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -139,6 +155,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
const QbtCommandLineParameters params = parseCommandLine();
|
const QbtCommandLineParameters params = parseCommandLine();
|
||||||
|
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
if (params.showVersion) {
|
if (params.showVersion) {
|
||||||
if (isOneArg) {
|
if (isOneArg) {
|
||||||
displayVersion();
|
displayVersion();
|
||||||
|
@ -150,6 +167,7 @@ int main(int argc, char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (params.showHelp) {
|
if (params.showHelp) {
|
||||||
if (isOneArg) {
|
if (isOneArg) {
|
||||||
|
@ -228,7 +246,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!(params.noSplash || Preferences::instance()->isSlashScreenDisabled()))
|
if (!params.noSplash)
|
||||||
showSplashScreen();
|
showSplashScreen();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -269,18 +287,20 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QbtCommandLineParameters parseCommandLine()
|
QbtCommandLineParameters parseCommandLine()
|
||||||
{
|
{
|
||||||
QbtCommandLineParameters result = {0};
|
QbtCommandLineParameters result;
|
||||||
QStringList appArguments = qApp->arguments();
|
QStringList appArguments = qApp->arguments();
|
||||||
|
|
||||||
for (int i = 1; i < appArguments.size(); ++i) {
|
for (int i = 1; i < appArguments.size(); ++i) {
|
||||||
const QString& arg = appArguments[i];
|
const QString& arg = appArguments[i];
|
||||||
|
|
||||||
if ((arg == QLatin1String("-v")) || (arg == QLatin1String("--version"))) {
|
if ((arg == QLatin1String("-h")) || (arg == QLatin1String("--help"))) {
|
||||||
result.showVersion = true;
|
|
||||||
}
|
|
||||||
else if ((arg == QLatin1String("-h")) || (arg == QLatin1String("--help"))) {
|
|
||||||
result.showHelp = true;
|
result.showHelp = true;
|
||||||
}
|
}
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
else if ((arg == QLatin1String("-v")) || (arg == QLatin1String("--version"))) {
|
||||||
|
result.showVersion = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else if (arg.startsWith(QLatin1String("--webui-port="))) {
|
else if (arg.startsWith(QLatin1String("--webui-port="))) {
|
||||||
QStringList parts = arg.split(QLatin1Char('='));
|
QStringList parts = arg.split(QLatin1Char('='));
|
||||||
if (parts.size() == 2)
|
if (parts.size() == 2)
|
||||||
|
@ -384,18 +404,67 @@ void displayVersion()
|
||||||
std::cout << qPrintable(qApp->applicationName()) << " " << VERSION << std::endl;
|
std::cout << qPrintable(qApp->applicationName()) << " " << VERSION << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayUsage(const char *prg_name)
|
QString makeUsage(QString prg_name)
|
||||||
{
|
{
|
||||||
std::cout << qPrintable(QObject::tr("Usage:")) << std::endl;
|
QString text;
|
||||||
std::cout << '\t' << prg_name << " -v | --version: " << qPrintable(QObject::tr("displays program version")) << std::endl;
|
|
||||||
#ifndef DISABLE_GUI
|
text += QObject::tr("Usage:") + QLatin1Char('\n');
|
||||||
std::cout << '\t' << prg_name << " --no-splash: " << qPrintable(QObject::tr("disable splash screen")) << std::endl;
|
#ifndef Q_OS_WIN
|
||||||
#else
|
text += QLatin1Char('\t') + prg_name + QLatin1String(" (-v | --version)") + QLatin1Char('\n');
|
||||||
std::cout << '\t' << prg_name << " -d | --daemon: " << qPrintable(QObject::tr("run in daemon-mode (background)")) << std::endl;
|
#endif
|
||||||
|
text += QLatin1Char('\t') + prg_name + QLatin1String(" (-h | --help)") + QLatin1Char('\n');
|
||||||
|
text += QLatin1Char('\t') + prg_name
|
||||||
|
+ QLatin1String(" [--webui-port=<port>]")
|
||||||
|
#ifndef DISABLE_GUI
|
||||||
|
+ QLatin1String(" [--no-splash]")
|
||||||
|
#else
|
||||||
|
+ QLatin1String(" [-d | --daemon]")
|
||||||
|
#endif
|
||||||
|
+ QLatin1String("[(<filename> | <url>)...]") + QLatin1Char('\n');
|
||||||
|
text += QObject::tr("Options:") + QLatin1Char('\n');
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
text += QLatin1String("\t-v | --version\t\t") + QObject::tr("Displays program version") + QLatin1Char('\n');
|
||||||
|
#endif
|
||||||
|
text += QLatin1String("\t-h | --help\t\t") + QObject::tr("Displays this help message") + QLatin1Char('\n');
|
||||||
|
text += QLatin1String("\t--webui-port=<port>\t")
|
||||||
|
+ QObject::tr("Changes the webui port (current: %1)").arg(QString::number(Preferences::instance()->getWebUiPort()))
|
||||||
|
+ QLatin1Char('\n');
|
||||||
|
#ifndef DISABLE_GUI
|
||||||
|
text += QLatin1String("\t--no-splash\t\t") + QObject::tr("Disable splash screen") + QLatin1Char('\n');
|
||||||
|
#else
|
||||||
|
text += QLatin1String("\t-d | --daemon\t\t") + QObject::tr("Run in daemon-mode (background)") + QLatin1Char('\n');
|
||||||
|
#endif
|
||||||
|
text += QLatin1String("\tfiles or urls\t\t") + QObject::tr("Downloads the torrents passed by the user");
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayUsage(QString prg_name)
|
||||||
|
{
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
std::cout << qPrintable(makeUsage(prg_name)) << std::endl;
|
||||||
|
#else
|
||||||
|
QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prg_name), QMessageBox::Ok);
|
||||||
|
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
||||||
|
msgBox.move(misc::screenCenter(&msgBox));
|
||||||
|
msgBox.exec();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayBadArgMessage(QString message)
|
||||||
|
{
|
||||||
|
QString help = QObject::tr("Run application with -h option to read about command line parameters.");
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
QMessageBox msgBox(QMessageBox::Critical, QObject::tr("Bad command line"),
|
||||||
|
message + QLatin1Char('\n') + help, QMessageBox::Ok);
|
||||||
|
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
||||||
|
msgBox.move(misc::screenCenter(&msgBox));
|
||||||
|
msgBox.exec();
|
||||||
|
#else
|
||||||
|
std::cerr << qPrintable(QObject::tr("Bad command line: "));
|
||||||
|
std::cerr << qPrintable(message) << std::endl;
|
||||||
|
std::cerr << qPrintable(help) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
std::cout << '\t' << prg_name << " -h | --help: " << qPrintable(QObject::tr("displays this help message")) << std::endl;
|
|
||||||
std::cout << '\t' << prg_name << " --webui-port=x: " << qPrintable(QObject::tr("changes the webui port (current: %1)").arg(QString::number(Preferences::instance()->getWebUiPort()))) << std::endl;
|
|
||||||
std::cout << '\t' << prg_name << " " << qPrintable(QObject::tr("[files or urls]: downloads the torrents passed by the user (optional)")) << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool userAgreesWithLegalNotice()
|
bool userAgreesWithLegalNotice()
|
||||||
|
@ -432,9 +501,3 @@ bool userAgreesWithLegalNotice()
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayBadArgMessage(const QString& message)
|
|
||||||
{
|
|
||||||
std::cerr << qPrintable(QObject::tr("Bad command line: "));
|
|
||||||
std::cerr << qPrintable(message) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
|
@ -524,7 +524,7 @@ void options_imp::loadOptions() {
|
||||||
setLocale(pref->getLocale());
|
setLocale(pref->getLocale());
|
||||||
checkAltRowColors->setChecked(pref->useAlternatingRowColors());
|
checkAltRowColors->setChecked(pref->useAlternatingRowColors());
|
||||||
checkShowSystray->setChecked(pref->systrayIntegration());
|
checkShowSystray->setChecked(pref->systrayIntegration());
|
||||||
checkShowSplash->setChecked(!pref->isSlashScreenDisabled());
|
checkShowSplash->setChecked(!pref->isSplashScreenDisabled());
|
||||||
if (checkShowSystray->isChecked()) {
|
if (checkShowSystray->isChecked()) {
|
||||||
checkCloseToSystray->setChecked(pref->closeToTray());
|
checkCloseToSystray->setChecked(pref->closeToTray());
|
||||||
checkMinimizeToSysTray->setChecked(pref->minimizeToTray());
|
checkMinimizeToSysTray->setChecked(pref->minimizeToTray());
|
||||||
|
|
|
@ -279,7 +279,7 @@ void Preferences::setStartMinimized(bool b) {
|
||||||
setValue("Preferences/General/StartMinimized", b);
|
setValue("Preferences/General/StartMinimized", b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Preferences::isSlashScreenDisabled() const {
|
bool Preferences::isSplashScreenDisabled() const {
|
||||||
return value("Preferences/General/NoSplashScreen", false).toBool();
|
return value("Preferences/General/NoSplashScreen", false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ public:
|
||||||
void setCloseToTray(bool b);
|
void setCloseToTray(bool b);
|
||||||
bool startMinimized() const;
|
bool startMinimized() const;
|
||||||
void setStartMinimized(bool b);
|
void setStartMinimized(bool b);
|
||||||
bool isSlashScreenDisabled() const;
|
bool isSplashScreenDisabled() const;
|
||||||
void setSplashScreenDisabled(bool b);
|
void setSplashScreenDisabled(bool b);
|
||||||
bool preventFromSuspend() const;
|
bool preventFromSuspend() const;
|
||||||
void setPreventFromSuspend(bool b);
|
void setPreventFromSuspend(bool b);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue