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

4
src/app/cmdoptions.h

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

40
src/app/main.cpp

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

Loading…
Cancel
Save