diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -95,8 +95,9 @@ // 2) Language from QSettings QString lang_territory_qsettings = settings.value("language", "").toString(); - if (!lang_territory_qsettings.isEmpty()) + if (!lang_territory_qsettings.isEmpty()) { lang_territory = lang_territory_qsettings; + } // 3) -lang command line argument lang_territory = QString::fromStdString( gArgs.GetArg("-lang", lang_territory.toStdString())); @@ -129,24 +130,28 @@ // Load e.g. qt_de.qm if (qtTranslatorBase.load( "qt_" + lang, - QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { QApplication::installTranslator(&qtTranslatorBase); + } // Load e.g. qt_de_DE.qm if (qtTranslator.load( "qt_" + lang_territory, - QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { QApplication::installTranslator(&qtTranslator); + } // Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in // bitcoin.qrc) - if (translatorBase.load(lang, ":/translations/")) + if (translatorBase.load(lang, ":/translations/")) { QApplication::installTranslator(&translatorBase); + } // Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in // bitcoin.qrc) - if (translator.load(lang_territory, ":/translations/")) + if (translator.load(lang_territory, ":/translations/")) { QApplication::installTranslator(&translator); + } } /* qDebug() message handler --> debug.log */ @@ -306,7 +311,9 @@ platformStyle = PlatformStyle::instantiate(QString::fromStdString(platformName)); // Fall back to "other" if specified name not found. - if (!platformStyle) platformStyle = PlatformStyle::instantiate("other"); + if (!platformStyle) { + platformStyle = PlatformStyle::instantiate("other"); + } assert(platformStyle); } @@ -362,7 +369,9 @@ } void BitcoinApplication::startThread() { - if (coreThread) return; + if (coreThread) { + return; + } coreThread = new QThread(this); BitcoinABC *executor = new BitcoinABC(); executor->moveToThread(coreThread); @@ -439,59 +448,59 @@ void BitcoinApplication::initializeResult(bool success) { qDebug() << __func__ << ": Initialization result: " << success; returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE; - if (success) { - // Log this only after AppInit2 finishes, as then logging setup is - // guaranteed complete. - qWarning() << "Platform customization:" << platformStyle->getName(); + if (!success) { + // Exit main loop. + quit(); + return; + } + + // Log this only after AppInit2 finishes, as then logging setup is + // guaranteed complete. + qWarning() << "Platform customization:" << platformStyle->getName(); #ifdef ENABLE_WALLET - PaymentServer::LoadRootCAs(); - paymentServer->setOptionsModel(optionsModel); + PaymentServer::LoadRootCAs(); + paymentServer->setOptionsModel(optionsModel); #endif - clientModel = new ClientModel(optionsModel); - window->setClientModel(clientModel); + clientModel = new ClientModel(optionsModel); + window->setClientModel(clientModel); #ifdef ENABLE_WALLET - // TODO: Expose secondary wallets - if (!vpwallets.empty()) { - walletModel = - new WalletModel(platformStyle, vpwallets[0], optionsModel); - - window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel); - window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET); - - connect(walletModel, SIGNAL(coinsSent(CWallet *, SendCoinsRecipient, - QByteArray)), - paymentServer, - SLOT(fetchPaymentACK(CWallet *, const SendCoinsRecipient &, - QByteArray))); - } + // TODO: Expose secondary wallets + if (!vpwallets.empty()) { + walletModel = + new WalletModel(platformStyle, vpwallets[0], optionsModel); + + window->addWallet(BitcoinGUI::DEFAULT_WALLET, walletModel); + window->setCurrentWallet(BitcoinGUI::DEFAULT_WALLET); + + connect(walletModel, + SIGNAL(coinsSent(CWallet *, SendCoinsRecipient, QByteArray)), + paymentServer, + SLOT(fetchPaymentACK(CWallet *, const SendCoinsRecipient &, + QByteArray))); + } #endif - // If -min option passed, start window minimized. - if (gArgs.GetBoolArg("-min", false)) { - window->showMinimized(); - } else { - window->show(); - } - Q_EMIT splashFinished(window); + // If -min option passed, start window minimized. + if (gArgs.GetBoolArg("-min", false)) { + window->showMinimized(); + } else { + window->show(); + } + Q_EMIT splashFinished(window); #ifdef ENABLE_WALLET - // Now that initialization/startup is done, process any command-line - // bitcoincash: URIs or payment requests: - connect(paymentServer, - SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), window, - SLOT(handlePaymentRequest(SendCoinsRecipient))); - connect(window, SIGNAL(receivedURI(QString)), paymentServer, - SLOT(handleURIOrFile(QString))); - connect(paymentServer, SIGNAL(message(QString, QString, unsigned int)), - window, SLOT(message(QString, QString, unsigned int))); - QTimer::singleShot(100, paymentServer, SLOT(uiReady())); + // Now that initialization/startup is done, process any command-line + // bitcoincash: URIs or payment requests: + connect(paymentServer, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), + window, SLOT(handlePaymentRequest(SendCoinsRecipient))); + connect(window, SIGNAL(receivedURI(QString)), paymentServer, + SLOT(handleURIOrFile(QString))); + connect(paymentServer, SIGNAL(message(QString, QString, unsigned int)), + window, SLOT(message(QString, QString, unsigned int))); + QTimer::singleShot(100, paymentServer, SLOT(uiReady())); #endif - } else { - // Exit main loop. - quit(); - } } void BitcoinApplication::shutdownResult() { @@ -509,7 +518,9 @@ } WId BitcoinApplication::getMainWinId() const { - if (!window) return 0; + if (!window) { + return 0; + } return window->winId(); } @@ -637,7 +648,9 @@ /// 5. Now that settings and translations are available, ask user for data /// directory. User language is set up: pick a data directory. - if (!Intro::pickDataDirectory()) return EXIT_SUCCESS; + if (!Intro::pickDataDirectory()) { + return EXIT_SUCCESS; + } /// 6. Determine availability of data directory and parse bitcoin.conf /// - Do not call GetDataDir(true) before this step finishes. @@ -649,6 +662,7 @@ .arg(QString::fromStdString(gArgs.GetArg("-datadir", "")))); return EXIT_FAILURE; } + try { gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)); } catch (const std::exception &e) { @@ -701,7 +715,9 @@ // of the server. // - Do this after creating app and setting up translations, so errors are // translated properly. - if (PaymentServer::ipcSendCommandLine()) exit(EXIT_SUCCESS); + if (PaymentServer::ipcSendCommandLine()) { + exit(EXIT_SUCCESS); + } // Start up the payment server early, too, so impatient users that click on // bitcoincash: links repeatedly have their payment requests routed to this @@ -733,8 +749,9 @@ Config &config = const_cast(GetConfig()); if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && - !gArgs.GetBoolArg("-min", false)) + !gArgs.GetBoolArg("-min", false)) { app.createSplashScreen(networkStyle.data()); + } RPCServer rpcServer; HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); @@ -746,22 +763,23 @@ // initialization/shutdown thread. This is acceptable because this // function only contains steps that are quick to execute, so the GUI // thread won't be held up. - if (AppInitBase(config, rpcServer)) { - app.requestInitialize(config, httpRPCRequestProcessor, rpcServer); -#if defined(Q_OS_WIN) - WinShutdownMonitor::registerShutdownBlockReason( - QObject::tr("%1 didn't yet exit safely...") - .arg(QObject::tr(PACKAGE_NAME)), - (HWND)app.getMainWinId()); -#endif - app.exec(); - app.requestShutdown(config); - app.exec(); - rv = app.getReturnValue(); - } else { + if (!AppInitBase(config, rpcServer)) { // A dialog with detailed error will have been shown by InitError() rv = EXIT_FAILURE; + return rv; } + + app.requestInitialize(config, httpRPCRequestProcessor, rpcServer); +#if defined(Q_OS_WIN) + WinShutdownMonitor::registerShutdownBlockReason( + QObject::tr("%1 didn't yet exit safely...") + .arg(QObject::tr(PACKAGE_NAME)), + (HWND)app.getMainWinId()); +#endif + app.exec(); + app.requestShutdown(config); + app.exec(); + rv = app.getReturnValue(); } catch (const std::exception &e) { PrintExceptionContinue(&e, "Runaway exception"); app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));