From afdc1ee93e66db6dec3e3e56ee9913a8781c35d2 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sun, 21 Dec 2014 17:26:31 +0300 Subject: [PATCH] HOTFIX: Correct command line parameters defaults. --- src/main.cpp | 109 +++++++++++++++++++++++++------- src/preferences/options_imp.cpp | 2 +- src/preferences/preferences.cpp | 2 +- src/preferences/preferences.h | 2 +- 4 files changed, 89 insertions(+), 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c1249baef..dafc60a23 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,8 +103,10 @@ void sigabrtHandler(int); struct QbtCommandLineParameters { - bool showVersion; bool showHelp; +#ifndef Q_OS_WIN + bool showVersion; +#endif #ifndef DISABLE_GUI bool noSplash; #else @@ -112,6 +114,20 @@ struct QbtCommandLineParameters #endif int webUiPort; 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(); @@ -120,9 +136,9 @@ QbtCommandLineParameters parseCommandLine(); void showSplashScreen(); #endif void displayVersion(); -void displayUsage(const char *prg_name); +void displayUsage(QString prg_name = QLatin1String("qbittorrent")); bool userAgreesWithLegalNotice(); -void displayBadArgMessage(const QString& message); +void displayBadArgMessage(QString message); // Main int main(int argc, char *argv[]) @@ -139,6 +155,7 @@ int main(int argc, char *argv[]) const QbtCommandLineParameters params = parseCommandLine(); +#ifndef Q_OS_WIN if (params.showVersion) { if (isOneArg) { displayVersion(); @@ -150,6 +167,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } } +#endif if (params.showHelp) { if (isOneArg) { @@ -228,7 +246,7 @@ int main(int argc, char *argv[]) } } #else - if (!(params.noSplash || Preferences::instance()->isSlashScreenDisabled())) + if (!params.noSplash) showSplashScreen(); #endif @@ -269,18 +287,20 @@ int main(int argc, char *argv[]) QbtCommandLineParameters parseCommandLine() { - QbtCommandLineParameters result = {0}; + QbtCommandLineParameters result; QStringList appArguments = qApp->arguments(); for (int i = 1; i < appArguments.size(); ++i) { const QString& arg = appArguments[i]; - if ((arg == QLatin1String("-v")) || (arg == QLatin1String("--version"))) { - result.showVersion = true; - } - else if ((arg == QLatin1String("-h")) || (arg == QLatin1String("--help"))) { + if ((arg == QLatin1String("-h")) || (arg == QLatin1String("--help"))) { 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="))) { QStringList parts = arg.split(QLatin1Char('=')); if (parts.size() == 2) @@ -384,18 +404,67 @@ void displayVersion() 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; - std::cout << '\t' << prg_name << " -v | --version: " << qPrintable(QObject::tr("displays program version")) << std::endl; + QString text; + + text += QObject::tr("Usage:") + QLatin1Char('\n'); +#ifndef Q_OS_WIN + text += QLatin1Char('\t') + prg_name + QLatin1String(" (-v | --version)") + QLatin1Char('\n'); +#endif + text += QLatin1Char('\t') + prg_name + QLatin1String(" (-h | --help)") + QLatin1Char('\n'); + text += QLatin1Char('\t') + prg_name + + QLatin1String(" [--webui-port=]") #ifndef DISABLE_GUI - std::cout << '\t' << prg_name << " --no-splash: " << qPrintable(QObject::tr("disable splash screen")) << std::endl; + + QLatin1String(" [--no-splash]") #else - std::cout << '\t' << prg_name << " -d | --daemon: " << qPrintable(QObject::tr("run in daemon-mode (background)")) << std::endl; + + QLatin1String(" [-d | --daemon]") +#endif + + QLatin1String("[( | )...]") + 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=\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 - 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() @@ -432,9 +501,3 @@ bool userAgreesWithLegalNotice() return false; } - -void displayBadArgMessage(const QString& message) -{ - std::cerr << qPrintable(QObject::tr("Bad command line: ")); - std::cerr << qPrintable(message) << std::endl; -} diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index 99636b16b..d0db28536 100755 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -524,7 +524,7 @@ void options_imp::loadOptions() { setLocale(pref->getLocale()); checkAltRowColors->setChecked(pref->useAlternatingRowColors()); checkShowSystray->setChecked(pref->systrayIntegration()); - checkShowSplash->setChecked(!pref->isSlashScreenDisabled()); + checkShowSplash->setChecked(!pref->isSplashScreenDisabled()); if (checkShowSystray->isChecked()) { checkCloseToSystray->setChecked(pref->closeToTray()); checkMinimizeToSysTray->setChecked(pref->minimizeToTray()); diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index fb9518a99..a26ccf4a4 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -279,7 +279,7 @@ void Preferences::setStartMinimized(bool b) { setValue("Preferences/General/StartMinimized", b); } -bool Preferences::isSlashScreenDisabled() const { +bool Preferences::isSplashScreenDisabled() const { return value("Preferences/General/NoSplashScreen", false).toBool(); } diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index 487aae02e..806755bce 100755 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -103,7 +103,7 @@ public: void setCloseToTray(bool b); bool startMinimized() const; void setStartMinimized(bool b); - bool isSlashScreenDisabled() const; + bool isSplashScreenDisabled() const; void setSplashScreenDisabled(bool b); bool preventFromSuspend() const; void setPreventFromSuspend(bool b);