Browse Source

Fix main.cpp indentation. Issue #2192.

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

72
src/main.cpp

@ -132,18 +132,22 @@ 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); signal(SIGINT, 0);
qDebug("Catching SIGINT, exiting cleanly"); qDebug("Catching SIGINT, exiting cleanly");
qApp->exit(); qApp->exit();
} }
void sigtermHandler(int) { void sigtermHandler(int)
{
signal(SIGTERM, 0); signal(SIGTERM, 0);
qDebug("Catching SIGTERM, exiting cleanly"); qDebug("Catching SIGTERM, exiting cleanly");
qApp->exit(); qApp->exit();
} }
void sigsegvHandler(int) {
void sigsegvHandler(int)
{
signal(SIGABRT, 0); signal(SIGABRT, 0);
signal(SIGSEGV, 0); signal(SIGSEGV, 0);
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
@ -160,7 +164,9 @@ void sigsegvHandler(int) {
#endif #endif
raise(SIGSEGV); raise(SIGSEGV);
} }
void sigabrtHandler(int) {
void sigabrtHandler(int)
{
signal(SIGABRT, 0); signal(SIGABRT, 0);
signal(SIGSEGV, 0); signal(SIGSEGV, 0);
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
@ -180,25 +186,26 @@ void sigabrtHandler(int) {
#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 // Create Application
QString uid = misc::getUserIDString(); 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--;
} }
@ -225,22 +232,27 @@ int main(int argc, char *argv[]) {
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]); torrentPath.setFile(torrentCmdLine[a]);
if (torrentPath.exists()) if (torrentPath.exists())
message += torrentPath.absoluteFilePath(); message += torrentPath.absoluteFilePath();
else else
message += torrentCmdLine[a]; message += torrentCmdLine[a];
if (a < argc-1) if (a < argc-1)
message += "|"; message += "|";
} }
if (!message.isEmpty()) { if (!message.isEmpty()) {
qDebug("Passing program parameters to running instance..."); qDebug("Passing program parameters to running instance...");
qDebug("Message: %s", qPrintable(message)); qDebug("Message: %s", qPrintable(message));
app.sendMessage(message); app.sendMessage(message);
} else { // Raise main window }
else { // Raise main window
app.sendMessage("qbt://show"); app.sendMessage("qbt://show");
} }
return 0;
return EXIT_SUCCESS;
} }
srand(time(0)); srand(time(0));
@ -248,7 +260,7 @@ int main(int argc, char *argv[]) {
#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;
} }
@ -262,6 +274,7 @@ int main(int argc, char *argv[]) {
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)) ||
@ -269,42 +282,50 @@ int main(int argc, char *argv[]) {
#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{ }
else {
qDebug("Qt %s locale unrecognized, using default (en).", qPrintable(locale)); qDebug("Qt %s locale unrecognized, using default (en).", qPrintable(locale));
} }
app.installTranslator(&qtTranslator); app.installTranslator(&qtTranslator);
if (translator.load(QString::fromUtf8(":/lang/qbittorrent_") + locale)) { if (translator.load(QString::fromUtf8(":/lang/qbittorrent_") + locale)) {
qDebug("%s locale recognized, using translation.", qPrintable(locale)); qDebug("%s locale recognized, using translation.", qPrintable(locale));
}else{ }
else {
qDebug("%s locale unrecognized, using default (en).", qPrintable(locale)); qDebug("%s locale unrecognized, using default (en).", qPrintable(locale));
} }
app.installTranslator(&translator); app.installTranslator(&translator);
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (locale.startsWith("ar") || locale.startsWith("he")) { if (locale.startsWith("ar") || locale.startsWith("he")) {
qDebug("Right to Left mode"); qDebug("Right to Left mode");
app.setLayoutDirection(Qt::RightToLeft); app.setLayoutDirection(Qt::RightToLeft);
} else { }
else {
app.setLayoutDirection(Qt::LeftToRight); app.setLayoutDirection(Qt::LeftToRight);
} }
#endif #endif
app.setApplicationName(QString::fromUtf8("qBittorrent")); app.setApplicationName(QString::fromUtf8("qBittorrent"));
// Check for executable parameters // Check for executable parameters
if (argc > 1) { if (argc > 1) {
if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--version")) { if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--version")) {
std::cout << "qBittorrent " << VERSION << '\n'; std::cout << "qBittorrent " << VERSION << '\n';
return 0; return EXIT_SUCCESS;
} }
if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--help")) { if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--help")) {
displayUsage(argv[0]); displayUsage(argv[0]);
return 0; return EXIT_SUCCESS;
} }
for (int i=1; i<argc; ++i) { for (int i = 1; i < argc; ++i) {
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (QString::fromLocal8Bit(argv[i]) == QString::fromUtf8("--no-splash")) { if (QString::fromLocal8Bit(argv[i]) == QString::fromUtf8("--no-splash")) {
no_splash = true; no_splash = true;
} else { }
else {
#endif #endif
if (QString::fromLocal8Bit(argv[i]).startsWith("--webui-port=")) { if (QString::fromLocal8Bit(argv[i]).startsWith("--webui-port=")) {
QStringList parts = QString::fromLocal8Bit(argv[i]).split("="); QStringList parts = QString::fromLocal8Bit(argv[i]).split("=");
@ -326,6 +347,7 @@ int main(int argc, char *argv[]) {
if (pref->isSlashScreenDisabled()) { if (pref->isSlashScreenDisabled()) {
no_splash = true; no_splash = true;
} }
QSplashScreen *splash = 0; QSplashScreen *splash = 0;
if (!no_splash) { if (!no_splash) {
QPixmap splash_img(":/Icons/skin/splash.png"); QPixmap splash_img(":/Icons/skin/splash.png");
@ -340,6 +362,7 @@ int main(int argc, char *argv[]) {
app.processEvents(); app.processEvents();
} }
#endif #endif
// Set environment variable // Set environment variable
if (!qputenv("QBITTORRENT", QByteArray(VERSION))) { if (!qputenv("QBITTORRENT", QByteArray(VERSION))) {
std::cerr << "Couldn't set environment variable...\n"; std::cerr << "Couldn't set environment variable...\n";
@ -350,17 +373,20 @@ int main(int argc, char *argv[]) {
#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 // Read torrents given on command line
QStringList torrents; QStringList torrents;
QStringList appArguments = app.arguments(); QStringList appArguments = app.arguments();
@ -390,5 +416,3 @@ int main(int argc, char *argv[]) {
qDebug("Application has exited"); qDebug("Application has exited");
return ret; return ret;
} }

Loading…
Cancel
Save