|
| 1 | +// Copyright (c) 2021 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <qml/bitcoin.h> |
| 6 | + |
| 7 | +#include <init.h> |
| 8 | +#include <interfaces/node.h> |
| 9 | +#include <node/context.h> |
| 10 | +#include <node/ui_interface.h> |
| 11 | +#include <noui.h> |
| 12 | +#include <qt/guiconstants.h> |
| 13 | +#include <util/system.h> |
| 14 | +#include <util/translation.h> |
| 15 | + |
| 16 | +#include <boost/signals2/connection.hpp> |
| 17 | +#include <memory> |
| 18 | + |
| 19 | +#include <QGuiApplication> |
| 20 | +#include <QQmlApplicationEngine> |
| 21 | + |
| 22 | +namespace { |
| 23 | +void SetupUIArgs(ArgsManager& argsman) |
| 24 | +{ |
| 25 | + argsman.AddArg("-lang=<lang>", "Set language, for example \"de_DE\" (default: system locale)", ArgsManager::ALLOW_ANY, OptionsCategory::GUI); |
| 26 | + argsman.AddArg("-min", "Start minimized", ArgsManager::ALLOW_ANY, OptionsCategory::GUI); |
| 27 | + argsman.AddArg("-resetguisettings", "Reset all settings changed in the GUI", ArgsManager::ALLOW_ANY, OptionsCategory::GUI); |
| 28 | + argsman.AddArg("-splash", strprintf("Show splash screen on startup (default: %u)", DEFAULT_SPLASHSCREEN), ArgsManager::ALLOW_ANY, OptionsCategory::GUI); |
| 29 | +} |
| 30 | +} // namespace |
| 31 | + |
| 32 | + |
| 33 | +int QmlGuiMain(int argc, char* argv[]) |
| 34 | +{ |
| 35 | + NodeContext node_context; |
| 36 | + std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context); |
| 37 | + |
| 38 | + // Subscribe to global signals from core |
| 39 | + boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox); |
| 40 | + boost::signals2::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion); |
| 41 | + boost::signals2::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect(noui_InitMessage); |
| 42 | + |
| 43 | + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
| 44 | + QGuiApplication app(argc, argv); |
| 45 | + QQmlApplicationEngine engine; |
| 46 | + |
| 47 | + // Parse command-line options. We do this after qt in order to show an error if there are problems parsing these. |
| 48 | + SetupServerArgs(gArgs); |
| 49 | + SetupUIArgs(gArgs); |
| 50 | + std::string error; |
| 51 | + if (!gArgs.ParseParameters(argc, argv, error)) { |
| 52 | + InitError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error)); |
| 53 | + return EXIT_FAILURE; |
| 54 | + } |
| 55 | + |
| 56 | + return app.exec(); |
| 57 | +} |
0 commit comments