Browse Source

Fix main.cpp indentation. Issue #2192.

adaptive-webui-19844
Vladimir Golovnev (Glassez) 10 years ago
parent
commit
1fcca6f434
  1. 414
      src/main.cpp

414
src/main.cpp

@ -132,263 +132,287 @@ bool userAgreesWithLegalNotice()
} }
#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) #if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
void sigintHandler(int) { void sigintHandler(int)
signal(SIGINT, 0); {
qDebug("Catching SIGINT, exiting cleanly"); signal(SIGINT, 0);
qApp->exit(); qDebug("Catching SIGINT, exiting cleanly");
qApp->exit();
} }
void sigtermHandler(int) { void sigtermHandler(int)
signal(SIGTERM, 0); {
qDebug("Catching SIGTERM, exiting cleanly"); signal(SIGTERM, 0);
qApp->exit(); qDebug("Catching SIGTERM, exiting cleanly");
qApp->exit();
} }
void sigsegvHandler(int) {
signal(SIGABRT, 0); void sigsegvHandler(int)
signal(SIGSEGV, 0); {
signal(SIGABRT, 0);
signal(SIGSEGV, 0);
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
std::cerr << "\n\n*************************************************************\n"; std::cerr << "\n\n*************************************************************\n";
std::cerr << "Catching SIGSEGV, please report a bug at http://bug.qbittorrent.org\nand provide the following backtrace:\n"; std::cerr << "Catching SIGSEGV, please report a bug at http://bug.qbittorrent.org\nand provide the following backtrace:\n";
std::cerr << "qBittorrent version: " << VERSION << std::endl; std::cerr << "qBittorrent version: " << VERSION << std::endl;
print_stacktrace(); print_stacktrace();
#else #else
#ifdef STACKTRACE_WIN #ifdef STACKTRACE_WIN
StraceDlg dlg; StraceDlg dlg;
dlg.setStacktraceString(straceWin::getBacktrace()); dlg.setStacktraceString(straceWin::getBacktrace());
dlg.exec(); dlg.exec();
#endif #endif
#endif #endif
raise(SIGSEGV); raise(SIGSEGV);
} }
void sigabrtHandler(int) {
signal(SIGABRT, 0); void sigabrtHandler(int)
signal(SIGSEGV, 0); {
signal(SIGABRT, 0);
signal(SIGSEGV, 0);
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
std::cerr << "\n\n*************************************************************\n"; std::cerr << "\n\n*************************************************************\n";
std::cerr << "Catching SIGABRT, please report a bug at http://bug.qbittorrent.org\nand provide the following backtrace:\n"; std::cerr << "Catching SIGABRT, please report a bug at http://bug.qbittorrent.org\nand provide the following backtrace:\n";
std::cerr << "qBittorrent version: " << VERSION << std::endl; std::cerr << "qBittorrent version: " << VERSION << std::endl;
print_stacktrace(); print_stacktrace();
#else #else
#ifdef STACKTRACE_WIN #ifdef STACKTRACE_WIN
StraceDlg dlg; StraceDlg dlg;
dlg.setStacktraceString(straceWin::getBacktrace()); dlg.setStacktraceString(straceWin::getBacktrace());
dlg.exec(); dlg.exec();
#endif #endif
#endif #endif
raise(SIGABRT); raise(SIGABRT);
} }
#endif #endif
// Main // Main
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
#if defined(Q_OS_MACX) && !defined(DISABLE_GUI) #if defined(Q_OS_MACX) && !defined(DISABLE_GUI)
if ( QSysInfo::MacintoshVersion > QSysInfo::MV_10_8 ) if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) {
{ // fix Mac OS X 10.9 (mavericks) font issue
// fix Mac OS X 10.9 (mavericks) font issue // https://bugreports.qt-project.org/browse/QTBUG-32789
// https://bugreports.qt-project.org/browse/QTBUG-32789 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); }
}
#endif #endif
// Create Application
QString uid = misc::getUserIDString(); // Create Application
QString uid = misc::getUserIDString();
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
bool shouldDaemonize = false; bool shouldDaemonize = false;
for(int i=1; i<argc; i++) { for (int i = 1; i < argc; i++) {
if(strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--daemon") == 0) { if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--daemon") == 0) {
shouldDaemonize = true; shouldDaemonize = true;
argc--; argc--;
for(int j=i; j<argc; j++) { for (int j = i; j < argc; j++) {
argv[j] = argv[j+1]; argv[j] = argv[j + 1];
} }
i--; i--;
}
} }
} QtSingleCoreApplication app("qBittorrent-"+uid, argc, argv);
QtSingleCoreApplication app("qBittorrent-"+uid, argc, argv);
#else #else
SessionApplication app("qBittorrent-"+uid, argc, argv); SessionApplication app("qBittorrent-"+uid, argc, argv);
#endif #endif
// Check if qBittorrent is already running for this user // Check if qBittorrent is already running for this user
if (app.isRunning()) { if (app.isRunning()) {
qDebug("qBittorrent is already running for this user."); qDebug("qBittorrent is already running for this user.");
// Read torrents given on command line // Read torrents given on command line
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
DWORD pid = (DWORD)app.getRunningPid(); DWORD pid = (DWORD)app.getRunningPid();
if (pid > 0) { if (pid > 0) {
BOOL b = AllowSetForegroundWindow(pid); BOOL b = AllowSetForegroundWindow(pid);
qDebug("AllowSetForegroundWindow() returns %s", b ? "TRUE" : "FALSE"); qDebug("AllowSetForegroundWindow() returns %s", b ? "TRUE" : "FALSE");
} }
#endif #endif
QStringList torrentCmdLine = app.arguments(); QStringList torrentCmdLine = app.arguments();
//Pass program parameters if any //Pass program parameters if any
QString message; QString message;
QFileInfo torrentPath; QFileInfo torrentPath;
for (int a = 1; a < torrentCmdLine.size(); ++a) { for (int a = 1; a < torrentCmdLine.size(); ++a) {
if (torrentCmdLine[a].startsWith("--")) continue; if (torrentCmdLine[a].startsWith("--")) continue;
torrentPath.setFile(torrentCmdLine[a]);
if (torrentPath.exists()) torrentPath.setFile(torrentCmdLine[a]);
message += torrentPath.absoluteFilePath(); if (torrentPath.exists())
else message += torrentPath.absoluteFilePath();
message += torrentCmdLine[a]; else
if (a < argc-1) message += torrentCmdLine[a];
message += "|";
} if (a < argc-1)
if (!message.isEmpty()) { message += "|";
qDebug("Passing program parameters to running instance..."); }
qDebug("Message: %s", qPrintable(message));
app.sendMessage(message); if (!message.isEmpty()) {
} else { // Raise main window qDebug("Passing program parameters to running instance...");
app.sendMessage("qbt://show"); qDebug("Message: %s", qPrintable(message));
app.sendMessage(message);
}
else { // Raise main window
app.sendMessage("qbt://show");
}
return EXIT_SUCCESS;
} }
return 0;
}
srand(time(0)); srand(time(0));
Preferences* const pref = Preferences::instance(); Preferences* const pref = Preferences::instance();
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
bool no_splash = false; bool no_splash = false;
#else #else
if(shouldDaemonize && daemon(1, 0) != 0) { if (shouldDaemonize && daemon(1, 0) != 0) {
qCritical("Something went wrong while daemonizing, exiting..."); qCritical("Something went wrong while daemonizing, exiting...");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
#endif #endif
// Load translation // Load translation
QString locale = pref->getLocale(); QString locale = pref->getLocale();
QTranslator qtTranslator; QTranslator qtTranslator;
QTranslator translator; QTranslator translator;
if (locale.isEmpty()) { if (locale.isEmpty()) {
locale = QLocale::system().name(); locale = QLocale::system().name();
pref->setLocale(locale); pref->setLocale(locale);
} }
if (qtTranslator.load(
if (qtTranslator.load(
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QString::fromUtf8("qtbase_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) || QString::fromUtf8("qtbase_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) ||
qtTranslator.load( qtTranslator.load(
#endif #endif
QString::fromUtf8("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { QString::fromUtf8("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
qDebug("Qt %s locale recognized, using translation.", qPrintable(locale)); qDebug("Qt %s locale recognized, using translation.", qPrintable(locale));
}else{ }
qDebug("Qt %s locale unrecognized, using default (en).", qPrintable(locale)); else {
} qDebug("Qt %s locale unrecognized, using default (en).", qPrintable(locale));
app.installTranslator(&qtTranslator); }
if (translator.load(QString::fromUtf8(":/lang/qbittorrent_") + locale)) { app.installTranslator(&qtTranslator);
qDebug("%s locale recognized, using translation.", qPrintable(locale));
}else{
qDebug("%s locale unrecognized, using default (en).", qPrintable(locale));
}
app.installTranslator(&translator);
#ifndef DISABLE_GUI
if (locale.startsWith("ar") || locale.startsWith("he")) {
qDebug("Right to Left mode");
app.setLayoutDirection(Qt::RightToLeft);
} else {
app.setLayoutDirection(Qt::LeftToRight);
}
#endif
app.setApplicationName(QString::fromUtf8("qBittorrent"));
// Check for executable parameters if (translator.load(QString::fromUtf8(":/lang/qbittorrent_") + locale)) {
if (argc > 1) { qDebug("%s locale recognized, using translation.", qPrintable(locale));
if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--version")) {
std::cout << "qBittorrent " << VERSION << '\n';
return 0;
} }
if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--help")) { else {
displayUsage(argv[0]); qDebug("%s locale unrecognized, using default (en).", qPrintable(locale));
return 0;
} }
app.installTranslator(&translator);
for (int i=1; i<argc; ++i) {
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (QString::fromLocal8Bit(argv[i]) == QString::fromUtf8("--no-splash")) { if (locale.startsWith("ar") || locale.startsWith("he")) {
no_splash = true; qDebug("Right to Left mode");
} else { app.setLayoutDirection(Qt::RightToLeft);
}
else {
app.setLayoutDirection(Qt::LeftToRight);
}
#endif #endif
if (QString::fromLocal8Bit(argv[i]).startsWith("--webui-port=")) {
QStringList parts = QString::fromLocal8Bit(argv[i]).split("="); app.setApplicationName(QString::fromUtf8("qBittorrent"));
if (parts.size() == 2) {
bool ok = false; // Check for executable parameters
int new_port = parts.last().toInt(&ok); if (argc > 1) {
if (ok && new_port > 0 && new_port <= 65535) { if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--version")) {
Preferences::instance()->setWebUiPort(new_port); std::cout << "qBittorrent " << VERSION << '\n';
} return EXIT_SUCCESS;
}
} }
if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--help")) {
displayUsage(argv[0]);
return EXIT_SUCCESS;
}
for (int i = 1; i < argc; ++i) {
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
} if (QString::fromLocal8Bit(argv[i]) == QString::fromUtf8("--no-splash")) {
no_splash = true;
}
else {
#endif #endif
if (QString::fromLocal8Bit(argv[i]).startsWith("--webui-port=")) {
QStringList parts = QString::fromLocal8Bit(argv[i]).split("=");
if (parts.size() == 2) {
bool ok = false;
int new_port = parts.last().toInt(&ok);
if (ok && new_port > 0 && new_port <= 65535) {
Preferences::instance()->setWebUiPort(new_port);
}
}
}
#ifndef DISABLE_GUI
}
#endif
}
} }
}
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (pref->isSlashScreenDisabled()) { if (pref->isSlashScreenDisabled()) {
no_splash = true; no_splash = true;
} }
QSplashScreen *splash = 0;
if (!no_splash) { QSplashScreen *splash = 0;
QPixmap splash_img(":/Icons/skin/splash.png"); if (!no_splash) {
QPainter painter(&splash_img); QPixmap splash_img(":/Icons/skin/splash.png");
QString version = VERSION; QPainter painter(&splash_img);
painter.setPen(QPen(Qt::white)); QString version = VERSION;
painter.setFont(QFont("Arial", 22, QFont::Black)); painter.setPen(QPen(Qt::white));
painter.drawText(224 - painter.fontMetrics().width(version), 270, version); painter.setFont(QFont("Arial", 22, QFont::Black));
splash = new QSplashScreen(splash_img, Qt::WindowStaysOnTopHint); painter.drawText(224 - painter.fontMetrics().width(version), 270, version);
QTimer::singleShot(1500, splash, SLOT(deleteLater())); splash = new QSplashScreen(splash_img, Qt::WindowStaysOnTopHint);
splash->show(); QTimer::singleShot(1500, splash, SLOT(deleteLater()));
app.processEvents(); splash->show();
} app.processEvents();
}
#endif #endif
// Set environment variable
if (!qputenv("QBITTORRENT", QByteArray(VERSION))) { // Set environment variable
std::cerr << "Couldn't set environment variable...\n"; if (!qputenv("QBITTORRENT", QByteArray(VERSION))) {
} std::cerr << "Couldn't set environment variable...\n";
}
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
app.setStyleSheet("QStatusBar::item { border-width: 0; }"); app.setStyleSheet("QStatusBar::item { border-width: 0; }");
#endif #endif
if (!userAgreesWithLegalNotice()) { if (!userAgreesWithLegalNotice()) {
return 0; return EXIT_SUCCESS;
} }
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
app.setQuitOnLastWindowClosed(false); app.setQuitOnLastWindowClosed(false);
#endif #endif
#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) #if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
signal(SIGABRT, sigabrtHandler); signal(SIGABRT, sigabrtHandler);
signal(SIGTERM, sigtermHandler); signal(SIGTERM, sigtermHandler);
signal(SIGINT, sigintHandler); signal(SIGINT, sigintHandler);
signal(SIGSEGV, sigsegvHandler); signal(SIGSEGV, sigsegvHandler);
#endif #endif
// Read torrents given on command line
QStringList torrents; // Read torrents given on command line
QStringList appArguments = app.arguments(); QStringList torrents;
for (int i = 1; i < appArguments.size(); ++i) { QStringList appArguments = app.arguments();
if (!appArguments[i].startsWith("--")) { for (int i = 1; i < appArguments.size(); ++i) {
qDebug() << "Command line argument:" << appArguments[i]; if (!appArguments[i].startsWith("--")) {
torrents << appArguments[i]; qDebug() << "Command line argument:" << appArguments[i];
torrents << appArguments[i];
}
} }
}
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
MainWindow window(0, torrents); MainWindow window(0, torrents);
QObject::connect(&app, SIGNAL(messageReceived(const QString&)), QObject::connect(&app, SIGNAL(messageReceived(const QString&)),
&window, SLOT(processParams(const QString&))); &window, SLOT(processParams(const QString&)));
app.setActivationWindow(&window); app.setActivationWindow(&window);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
static_cast<QMacApplication*>(&app)->setReadyToProcessEvents(); static_cast<QMacApplication*>(&app)->setReadyToProcessEvents();
#endif // Q_OS_MAC #endif // Q_OS_MAC
#else #else
// Load Headless class // Load Headless class
HeadlessLoader loader(torrents); HeadlessLoader loader(torrents);
QObject::connect(&app, SIGNAL(messageReceived(const QString&)), QObject::connect(&app, SIGNAL(messageReceived(const QString&)),
&loader, SLOT(processParams(const QString&))); &loader, SLOT(processParams(const QString&)));
#endif #endif
int ret = app.exec(); int ret = app.exec();
qDebug("Application has exited"); qDebug("Application has exited");
return ret; return ret;
} }

Loading…
Cancel
Save