diff options
Diffstat (limited to 'src/qt/bitcoin.cpp')
-rw-r--r-- | src/qt/bitcoin.cpp | 85 |
1 files changed, 67 insertions, 18 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 3b98334696..e7cf440044 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -151,13 +151,39 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans QApplication::installTranslator(&translator); } +/* qDebug() message handler --> debug.log */ +#if QT_VERSION < 0x050000 +void DebugMessageHandler(QtMsgType type, const char * msg) +{ + OutputDebugStringF("%s\n", msg); +} +#else +void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg) +{ + OutputDebugStringF("%s\n", qPrintable(msg)); +} +#endif + #ifndef BITCOIN_QT_TEST int main(int argc, char *argv[]) { + bool fMissingDatadir = false; + bool fSelParFromCLFailed = false; + fHaveGUI = true; // Command-line options take precedence: ParseParameters(argc, argv); + // ... then bitcoin.conf: + if (!boost::filesystem::is_directory(GetDataDir(false))) { + fMissingDatadir = true; + } else { + ReadConfigFile(mapArgs, mapMultiArgs); + } + // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause) + if (!SelectParamsFromCommandLine()) { + fSelParFromCLFailed = true; + } #if QT_VERSION < 0x050000 // Internal string conversion is all UTF-8 @@ -175,7 +201,7 @@ int main(int argc, char *argv[]) // as it is used to locate QSettings) QApplication::setOrganizationName("Bitcoin"); QApplication::setOrganizationDomain("bitcoin.org"); - if (GetBoolArg("-testnet", false)) // Separate UI settings for testnet + if (TestNet()) // Separate UI settings for testnet QApplication::setApplicationName("Bitcoin-Qt-testnet"); else QApplication::setApplicationName("Bitcoin-Qt"); @@ -184,28 +210,34 @@ int main(int argc, char *argv[]) QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator); - // User language is set up: pick a data directory - Intro::pickDataDirectory(); - // Do this early as we don't want to bother initializing if we are just calling IPC - // ... but do it after creating app, so QCoreApplication::arguments is initialized: - if (PaymentServer::ipcSendCommandLine()) + // ... but do it after creating app and setting up translations, so errors are + // translated properly. + if (PaymentServer::ipcSendCommandLine(argc, argv)) exit(0); - PaymentServer* paymentServer = new PaymentServer(&app); - - // Install global event filter that makes sure that long tooltips can be word-wrapped - app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app)); - // ... then bitcoin.conf: - if (!boost::filesystem::is_directory(GetDataDir(false))) - { + // Now that translations are initialized check for errors and allow a translatable error message + if (fMissingDatadir) { QMessageBox::critical(0, QObject::tr("Bitcoin"), QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"]))); return 1; } - ReadConfigFile(mapArgs, mapMultiArgs); + else if (fSelParFromCLFailed) { + QMessageBox::critical(0, QObject::tr("Bitcoin"), QObject::tr("Error: Invalid combination of -regtest and -testnet.")); + return 1; + } - // ... then GUI settings: + // Start up the payment server early, too, so impatient users that click on + // bitcoin: links repeatedly have their payment requests routed to this process: + PaymentServer* paymentServer = new PaymentServer(&app); + + // User language is set up: pick a data directory + Intro::pickDataDirectory(); + + // Install global event filter that makes sure that long tooltips can be word-wrapped + app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app)); + + // ... now GUI settings: OptionsModel optionsModel; // Subscribe to global signals from core @@ -223,6 +255,13 @@ int main(int argc, char *argv[]) return 1; } + // Install qDebug() message handler to route to debug.log: +#if QT_VERSION < 0x050000 + qInstallMsgHandler(DebugMessageHandler); +#else + qInstallMessageHandler(DebugMessageHandler); +#endif + SplashScreen splash(QPixmap(), 0); if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false)) { @@ -245,7 +284,7 @@ int main(int argc, char *argv[]) boost::thread_group threadGroup; - BitcoinGUI window(GetBoolArg("-testnet", false), 0); + BitcoinGUI window(TestNet(), 0); guiref = &window; QTimer* pollShutdownTimer = new QTimer(guiref); @@ -260,6 +299,9 @@ int main(int argc, char *argv[]) optionsModel.Upgrade(); // Must be done after AppInit2 + PaymentServer::LoadRootCAs(); + paymentServer->initNetManager(optionsModel); + if (splashref) splash.finish(&window); @@ -281,8 +323,15 @@ int main(int argc, char *argv[]) } // Now that initialization/startup is done, process any command-line - // bitcoin: URIs - QObject::connect(paymentServer, SIGNAL(receivedURI(QString)), &window, SLOT(handleURI(QString))); + // bitcoin: URIs or payment requests: + QObject::connect(paymentServer, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), + &window, SLOT(handlePaymentRequest(SendCoinsRecipient))); + QObject::connect(&walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)), + paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray))); + QObject::connect(paymentServer, SIGNAL(receivedPaymentACK(QString)), + &window, SLOT(showPaymentACK(QString))); + QObject::connect(paymentServer, SIGNAL(reportError(QString, QString, unsigned int)), + guiref, SLOT(message(QString, QString, unsigned int))); QTimer::singleShot(100, paymentServer, SLOT(uiReady())); app.exec(); |