Skip to content

Commit 58fee8d

Browse files
committed
qml: Add bitcoin module
1 parent af9630a commit 58fee8d

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

src/Makefile.qt.include

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ QT_QRC_LOCALE_CPP = qt/qrc_bitcoin_locale.cpp
105105
QT_QRC_LOCALE = qt/bitcoin_locale.qrc
106106

107107
BITCOIN_QT_H = \
108+
qml/bitcoin.h \
108109
qt/addressbookpage.h \
109110
qt/addresstablemodel.h \
110111
qt/askpassphrasedialog.h \
@@ -276,6 +277,9 @@ BITCOIN_QT_WALLET_CPP = \
276277
qt/walletmodeltransaction.cpp \
277278
qt/walletview.cpp
278279

280+
BITCOIN_QML_BASE_CPP = \
281+
qml/bitcoin.cpp
282+
279283
BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP)
280284
if TARGET_WINDOWS
281285
BITCOIN_QT_CPP += $(BITCOIN_QT_WINDOWS_CPP)
@@ -303,6 +307,10 @@ endif
303307

304308
nodist_qt_libbitcoinqt_a_SOURCES = $(QT_MOC_CPP) $(QT_MOC) $(QT_QRC_CPP) $(QT_QRC_LOCALE_CPP)
305309

310+
if BUILD_WITH_QML
311+
qt_libbitcoinqt_a_SOURCES += $(BITCOIN_QML_BASE_CPP)
312+
endif # BUILD_WITH_QML
313+
306314
# forms/foo.h -> forms/ui_foo.h
307315
QT_FORMS_H=$(join $(dir $(QT_FORMS_UI)),$(addprefix ui_, $(notdir $(QT_FORMS_UI:.ui=.h))))
308316

src/qml/bitcoin.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}

src/qml/bitcoin.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
#ifndef BITCOIN_QML_BITCOIN_H
6+
#define BITCOIN_QML_BITCOIN_H
7+
8+
int QmlGuiMain(int argc, char* argv[]);
9+
10+
#endif // BITCOIN_QML_BITCOIN_H

src/qt/main.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#ifdef HAVE_CONFIG_H
6+
#include <config/bitcoin-config.h>
7+
#endif
8+
9+
#if USE_QML
10+
#include <qml/bitcoin.h>
11+
#else
512
#include <qt/bitcoin.h>
13+
#endif // USE_QML
614

715
#include <util/system.h>
816
#include <util/threadnames.h>
@@ -31,5 +39,9 @@ int main(int argc, char* argv[])
3139
SetupEnvironment();
3240
util::ThreadSetInternalName("main");
3341

42+
#if USE_QML
43+
return QmlGuiMain(argc, argv);
44+
#else
3445
return GuiMain(argc, argv);
46+
#endif // USE_QML
3547
}

0 commit comments

Comments
 (0)