| 478 | } |
| 479 | |
| 480 | int GuiMain(int argc, char* argv[]) |
| 481 | { |
| 482 | std::unique_ptr<interfaces::Init> init = interfaces::MakeGuiInit(argc, argv); |
| 483 | |
| 484 | SetupEnvironment(); |
| 485 | util::ThreadSetInternalName("main"); |
| 486 | |
| 487 | // Subscribe to global signals from core |
| 488 | btcsignals::scoped_connection handler_message_box{::uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox)}; |
| 489 | btcsignals::scoped_connection handler_question{::uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion)}; |
| 490 | btcsignals::scoped_connection handler_init_message{::uiInterface.InitMessage.connect(noui_InitMessage)}; |
| 491 | |
| 492 | // Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory |
| 493 | |
| 494 | /// 1. Basic Qt initialization (not dependent on parameters or configuration) |
| 495 | Q_INIT_RESOURCE(bitcoin); |
| 496 | Q_INIT_RESOURCE(bitcoin_locale); |
| 497 | |
| 498 | #if defined(QT_QPA_PLATFORM_ANDROID) |
| 499 | QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar); |
| 500 | QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); |
| 501 | QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); |
| 502 | #endif |
| 503 | |
| 504 | BitcoinApplication app; |
| 505 | GUIUtil::LoadFont(QStringLiteral(":/fonts/monospace")); |
| 506 | |
| 507 | /// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these |
| 508 | // Command-line options take precedence: |
| 509 | SetupServerArgs(gArgs, init->canListenIpc()); |
| 510 | SetupUIArgs(gArgs); |
| 511 | std::string error; |
| 512 | if (!gArgs.ParseParameters(argc, argv, error)) { |
| 513 | InitError(Untranslated(strprintf("Error parsing command line arguments: %s", error))); |
| 514 | // Create a message box, because the gui has neither been created nor has subscribed to core signals |
| 515 | QMessageBox::critical(nullptr, CLIENT_NAME, |
| 516 | // message cannot be translated because translations have not been initialized |
| 517 | QString::fromStdString("Error parsing command line arguments: %1.").arg(QString::fromStdString(error))); |
| 518 | return EXIT_FAILURE; |
| 519 | } |
| 520 | |
| 521 | // Error out when loose non-argument tokens are encountered on command line |
| 522 | // However, allow BIP-21 URIs only if no options follow |
| 523 | bool payment_server_token_seen = false; |
| 524 | for (int i = 1; i < argc; i++) { |
| 525 | QString arg(argv[i]); |
| 526 | bool invalid_token = !arg.startsWith("-"); |
| 527 | #ifdef ENABLE_WALLET |
| 528 | if (arg.startsWith(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) { |
| 529 | invalid_token &= false; |
| 530 | payment_server_token_seen = true; |
| 531 | } |
| 532 | #endif |
| 533 | if (payment_server_token_seen && arg.startsWith("-")) { |
| 534 | InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i]))); |
| 535 | QMessageBox::critical(nullptr, CLIENT_NAME, |
| 536 | // message cannot be translated because translations have not been initialized |
| 537 | QString::fromStdString("Options ('%1') cannot follow a BIP-21 payment URI").arg(QString::fromStdString(argv[i]))); |
no test coverage detected