Browse Source

Merge pull request #9702 from knackebrot/master

Fix building qbittorrent-nox on Windows
adaptive-webui-19844
Vladimir Golovnev 6 years ago committed by GitHub
parent
commit
36f6e9b288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/app/cmdoptions.cpp
  2. 4
      src/app/cmdoptions.h
  3. 40
      src/app/main.cpp

22
src/app/cmdoptions.cpp

@ -37,7 +37,7 @@
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QTextStream> #include <QTextStream>
#ifdef Q_OS_WIN #if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
#include <QMessageBox> #include <QMessageBox>
#endif #endif
@ -310,7 +310,7 @@ namespace
constexpr const BoolOption SHOW_HELP_OPTION {"help", 'h'}; constexpr const BoolOption SHOW_HELP_OPTION {"help", 'h'};
constexpr const BoolOption SHOW_VERSION_OPTION {"version", 'v'}; constexpr const BoolOption SHOW_VERSION_OPTION {"version", 'v'};
#ifdef DISABLE_GUI #if defined(DISABLE_GUI) && !defined(Q_OS_WIN)
constexpr const BoolOption DAEMON_OPTION {"daemon", 'd'}; constexpr const BoolOption DAEMON_OPTION {"daemon", 'd'};
#else #else
constexpr const BoolOption NO_SPLASH_OPTION {"no-splash"}; constexpr const BoolOption NO_SPLASH_OPTION {"no-splash"};
@ -336,12 +336,12 @@ QBtCommandLineParameters::QBtCommandLineParameters(const QProcessEnvironment &en
, skipChecking(SKIP_HASH_CHECK_OPTION.value(env)) , skipChecking(SKIP_HASH_CHECK_OPTION.value(env))
, sequential(SEQUENTIAL_OPTION.value(env)) , sequential(SEQUENTIAL_OPTION.value(env))
, firstLastPiecePriority(FIRST_AND_LAST_OPTION.value(env)) , firstLastPiecePriority(FIRST_AND_LAST_OPTION.value(env))
#ifndef Q_OS_WIN #if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
, showVersion(false) , showVersion(false)
#endif #endif
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
, noSplash(NO_SPLASH_OPTION.value(env)) , noSplash(NO_SPLASH_OPTION.value(env))
#else #elif !defined(Q_OS_WIN)
, 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))
@ -411,7 +411,7 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
if (arg == SHOW_HELP_OPTION) { if (arg == SHOW_HELP_OPTION) {
result.showHelp = true; result.showHelp = true;
} }
#ifndef Q_OS_WIN #if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
else if (arg == SHOW_VERSION_OPTION) { else if (arg == SHOW_VERSION_OPTION) {
result.showVersion = true; result.showVersion = true;
} }
@ -426,7 +426,7 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
else if (arg == NO_SPLASH_OPTION) { else if (arg == NO_SPLASH_OPTION) {
result.noSplash = true; result.noSplash = true;
} }
#else #elif !defined(Q_OS_WIN)
else if (arg == DAEMON_OPTION) { else if (arg == DAEMON_OPTION) {
result.shouldDaemonize = true; result.shouldDaemonize = true;
} }
@ -524,7 +524,7 @@ QString makeUsage(const QString &prgName)
stream << indentation << prgName << QLatin1String(" [options] [(<filename> | <url>)...]") << '\n'; stream << indentation << prgName << QLatin1String(" [options] [(<filename> | <url>)...]") << '\n';
stream << QObject::tr("Options:") << '\n'; stream << QObject::tr("Options:") << '\n';
#ifndef Q_OS_WIN #if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
stream << SHOW_VERSION_OPTION.usage() << wrapText(QObject::tr("Display program version and exit")) << '\n'; stream << SHOW_VERSION_OPTION.usage() << wrapText(QObject::tr("Display program version and exit")) << '\n';
#endif #endif
stream << SHOW_HELP_OPTION.usage() << wrapText(QObject::tr("Display this help message and exit")) << '\n'; stream << SHOW_HELP_OPTION.usage() << wrapText(QObject::tr("Display this help message and exit")) << '\n';
@ -533,7 +533,7 @@ QString makeUsage(const QString &prgName)
<< '\n'; << '\n';
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
stream << NO_SPLASH_OPTION.usage() << wrapText(QObject::tr("Disable splash screen")) << '\n'; stream << NO_SPLASH_OPTION.usage() << wrapText(QObject::tr("Disable splash screen")) << '\n';
#else #elif !defined(Q_OS_WIN)
stream << DAEMON_OPTION.usage() << wrapText(QObject::tr("Run in daemon-mode (background)")) << '\n'; stream << DAEMON_OPTION.usage() << wrapText(QObject::tr("Run in daemon-mode (background)")) << '\n';
#endif #endif
//: Use appropriate short form or abbreviation of "directory" //: Use appropriate short form or abbreviation of "directory"
@ -579,12 +579,12 @@ QString makeUsage(const QString &prgName)
void displayUsage(const QString &prgName) void displayUsage(const QString &prgName)
{ {
#ifndef Q_OS_WIN #if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
printf("%s\n", qUtf8Printable(makeUsage(prgName)));
#else
QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok); QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok);
msgBox.show(); // Need to be shown or to moveToCenter does not work msgBox.show(); // Need to be shown or to moveToCenter does not work
msgBox.move(Utils::Gui::screenCenter(&msgBox)); msgBox.move(Utils::Gui::screenCenter(&msgBox));
msgBox.exec(); msgBox.exec();
#else
printf("%s\n", qUtf8Printable(makeUsage(prgName)));
#endif #endif
} }

4
src/app/cmdoptions.h

@ -43,12 +43,12 @@ class QProcessEnvironment;
struct QBtCommandLineParameters struct QBtCommandLineParameters
{ {
bool showHelp, relativeFastresumePaths, portableMode, skipChecking, sequential, firstLastPiecePriority; bool showHelp, relativeFastresumePaths, portableMode, skipChecking, sequential, firstLastPiecePriority;
#ifndef Q_OS_WIN #if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
bool showVersion; bool showVersion;
#endif #endif
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
bool noSplash; bool noSplash;
#else #elif !defined(Q_OS_WIN)
bool shouldDaemonize; bool shouldDaemonize;
#endif #endif
int webUiPort; int webUiPort;

40
src/app/main.cpp

@ -35,6 +35,8 @@
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
#include <unistd.h> #include <unistd.h>
#elif defined Q_OS_WIN && defined DISABLE_GUI
#include <io.h>
#endif #endif
#include <QDebug> #include <QDebug>
@ -65,7 +67,9 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#include "stacktrace.h" #include "stacktrace.h"
#else #else
#include "stacktrace_win.h" #include "stacktrace_win.h"
#ifndef DISABLE_GUI
#include "stacktracedialog.h" #include "stacktracedialog.h"
#endif // DISABLE_GUI
#endif // Q_OS_UNIX #endif // Q_OS_UNIX
#endif //STACKTRACE #endif //STACKTRACE
@ -100,7 +104,7 @@ const char *const sysSigName[] = {
#endif #endif
}; };
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
void reportToUser(const char *str); void reportToUser(const char *str);
#endif #endif
@ -130,7 +134,7 @@ int main(int argc, char *argv[])
"--random-parameter is an unknown command line parameter.") "--random-parameter is an unknown command line parameter.")
.arg(params.unknownParameter)); .arg(params.unknownParameter));
} }
#ifndef Q_OS_WIN #if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
if (params.showVersion) { if (params.showVersion) {
if (isOneArg) { if (isOneArg) {
displayVersion(); displayVersion();
@ -156,6 +160,12 @@ int main(int argc, char *argv[])
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (!userAgreesWithLegalNotice()) if (!userAgreesWithLegalNotice())
return EXIT_SUCCESS; return EXIT_SUCCESS;
#elif defined(Q_OS_WIN)
if (_isatty(_fileno(stdin))
&& _isatty(_fileno(stdout))
&& !userAgreesWithLegalNotice())
return EXIT_SUCCESS;
#else #else
if (!params.shouldDaemonize if (!params.shouldDaemonize
&& isatty(fileno(stdin)) && isatty(fileno(stdin))
@ -166,7 +176,7 @@ int main(int argc, char *argv[])
// Check if qBittorrent is already running for this user // Check if qBittorrent is already running for this user
if (app->isRunning()) { if (app->isRunning()) {
#ifdef DISABLE_GUI #if defined(DISABLE_GUI) && !defined(Q_OS_WIN)
if (params.shouldDaemonize) { if (params.shouldDaemonize) {
throw CommandLineParameterError(QObject::tr("You cannot use %1: qBittorrent is already running for this user.") throw CommandLineParameterError(QObject::tr("You cannot use %1: qBittorrent is already running for this user.")
.arg(QLatin1String("-d (or --daemon)"))); .arg(QLatin1String("-d (or --daemon)")));
@ -194,7 +204,7 @@ int main(int argc, char *argv[])
// 3. https://bugreports.qt.io/browse/QTBUG-46015 // 3. https://bugreports.qt.io/browse/QTBUG-46015
qputenv("QT_BEARER_POLL_TIMEOUT", QByteArray::number(-1)); qputenv("QT_BEARER_POLL_TIMEOUT", QByteArray::number(-1));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) && !defined(DISABLE_GUI)
// this is the default in Qt6 // this is the default in Qt6
app->setAttribute(Qt::AA_DisableWindowContextHelpButton); app->setAttribute(Qt::AA_DisableWindowContextHelpButton);
#endif #endif
@ -214,12 +224,15 @@ int main(int argc, char *argv[])
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (!upgrade()) return EXIT_FAILURE; if (!upgrade()) return EXIT_FAILURE;
#elif defined(Q_OS_WIN)
if (!upgrade(_isatty(_fileno(stdin))
&& _isatty(_fileno(stdout)))) return EXIT_FAILURE;
#else #else
if (!upgrade(!params.shouldDaemonize if (!upgrade(!params.shouldDaemonize
&& isatty(fileno(stdin)) && isatty(fileno(stdin))
&& isatty(fileno(stdout)))) return EXIT_FAILURE; && isatty(fileno(stdout)))) return EXIT_FAILURE;
#endif #endif
#ifdef DISABLE_GUI #if defined(DISABLE_GUI) && !defined(Q_OS_WIN)
if (params.shouldDaemonize) { if (params.shouldDaemonize) {
app.reset(); // Destroy current application app.reset(); // Destroy current application
if (daemon(1, 0) == 0) { if (daemon(1, 0) == 0) {
@ -234,7 +247,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
#else #elif !defined(DISABLE_GUI)
if (!(params.noSplash || Preferences::instance()->isSplashScreenDisabled())) if (!(params.noSplash || Preferences::instance()->isSplashScreenDisabled()))
showSplashScreen(); showSplashScreen();
#endif #endif
@ -254,12 +267,17 @@ int main(int argc, char *argv[])
} }
} }
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
void reportToUser(const char *str) void reportToUser(const char *str)
{ {
const size_t strLen = strlen(str); const size_t strLen = strlen(str);
#ifndef Q_OS_WIN
if (write(STDERR_FILENO, str, strLen) < static_cast<ssize_t>(strLen)) { if (write(STDERR_FILENO, str, strLen) < static_cast<ssize_t>(strLen)) {
const auto dummy = write(STDOUT_FILENO, str, strLen); const auto dummy = write(STDOUT_FILENO, str, strLen);
#else
if (_write(STDERR_FILENO, str, strLen) < static_cast<ssize_t>(strLen)) {
const auto dummy = _write(STDOUT_FILENO, str, strLen);
#endif
Q_UNUSED(dummy); Q_UNUSED(dummy);
} }
} }
@ -267,7 +285,7 @@ void reportToUser(const char *str)
void sigNormalHandler(int signum) void sigNormalHandler(int signum)
{ {
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
const char msg1[] = "Catching signal: "; const char msg1[] = "Catching signal: ";
const char msg2[] = "\nExiting cleanly\n"; const char msg2[] = "\nExiting cleanly\n";
reportToUser(msg1); reportToUser(msg1);
@ -282,7 +300,7 @@ void sigNormalHandler(int signum)
void sigAbnormalHandler(int signum) void sigAbnormalHandler(int signum)
{ {
const char *sigName = sysSigName[signum]; const char *sigName = sysSigName[signum];
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
const char msg[] = "\n\n*************************************************************\n" const char msg[] = "\n\n*************************************************************\n"
"Please file a bug report at http://bug.qbittorrent.org and provide the following information:\n\n" "Please file a bug report at http://bug.qbittorrent.org and provide the following information:\n\n"
"qBittorrent version: " QBT_VERSION "\n\n" "qBittorrent version: " QBT_VERSION "\n\n"
@ -293,7 +311,7 @@ void sigAbnormalHandler(int signum)
print_stacktrace(); // unsafe print_stacktrace(); // unsafe
#endif #endif
#if defined Q_OS_WIN #if defined Q_OS_WIN && !defined DISABLE_GUI
StacktraceDialog dlg; // unsafe StacktraceDialog dlg; // unsafe
dlg.setStacktraceString(QLatin1String(sigName), straceWin::getBacktrace()); dlg.setStacktraceString(QLatin1String(sigName), straceWin::getBacktrace());
dlg.exec(); dlg.exec();
@ -328,7 +346,7 @@ void displayVersion()
void displayBadArgMessage(const QString &message) void displayBadArgMessage(const QString &message)
{ {
const QString help = QObject::tr("Run application with -h option to read about command line parameters."); const QString help = QObject::tr("Run application with -h option to read about command line parameters.");
#ifdef Q_OS_WIN #if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
QMessageBox msgBox(QMessageBox::Critical, QObject::tr("Bad command line"), QMessageBox msgBox(QMessageBox::Critical, QObject::tr("Bad command line"),
message + QLatin1Char('\n') + help, QMessageBox::Ok); message + QLatin1Char('\n') + help, QMessageBox::Ok);
msgBox.show(); // Need to be shown or to moveToCenter does not work msgBox.show(); // Need to be shown or to moveToCenter does not work

Loading…
Cancel
Save