11
11
#include < noui.h>
12
12
#include < qml/nodemodel.h>
13
13
#include < qt/guiconstants.h>
14
+ #include < qt/initexecutor.h>
14
15
#include < util/system.h>
15
16
#include < util/translation.h>
16
17
@@ -36,20 +37,50 @@ void SetupUIArgs(ArgsManager& argsman)
36
37
37
38
int QmlGuiMain (int argc, char * argv[])
38
39
{
39
- NodeContext node_context;
40
- std::unique_ptr<interfaces::Node> node = interfaces::MakeNode (&node_context);
41
-
42
- // Subscribe to global signals from core
43
- boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect (noui_ThreadSafeMessageBox);
44
- boost::signals2::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect (noui_ThreadSafeQuestion);
45
- boost::signals2::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect (noui_InitMessage);
46
-
47
40
Q_INIT_RESOURCE (bitcoin_qml);
48
41
49
42
QGuiApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
50
43
QGuiApplication app (argc, argv);
51
44
45
+ // Parse command-line options. We do this after qt in order to show an error if there are problems parsing these.
46
+ SetupServerArgs (gArgs );
47
+ SetupUIArgs (gArgs );
48
+ std::string error;
49
+ if (!gArgs .ParseParameters (argc, argv, error)) {
50
+ InitError (strprintf (Untranslated (" Error parsing command line arguments: %s\n " ), error));
51
+ return EXIT_FAILURE;
52
+ }
53
+
54
+ CheckDataDirOption ();
55
+
56
+ gArgs .ReadConfigFiles (error, true );
57
+
58
+ SelectParams (gArgs .GetChainName ());
59
+
60
+ // Default printtoconsole to false for the GUI. GUI programs should not
61
+ // print to the console unnecessarily.
62
+ gArgs .SoftSetBoolArg (" -printtoconsole" , false );
63
+ InitLogging (gArgs );
64
+ InitParameterInteraction (gArgs );
65
+
66
+ NodeContext node_context;
67
+ node_context.args = &gArgs ;
68
+ std::unique_ptr<interfaces::Node> node = interfaces::MakeNode (&node_context);
69
+ node->baseInitialize ();
70
+
52
71
NodeModel node_model;
72
+ InitExecutor init_executor{*node};
73
+ QObject::connect (&node_model, &NodeModel::requestedInitialize, &init_executor, &InitExecutor::initialize);
74
+ QObject::connect (&node_model, &NodeModel::requestedShutdown, &init_executor, &InitExecutor::shutdown);
75
+ // QObject::connect(&init_executor, &InitExecutor::initializeResult, &node_model, &NodeModel::initializeResult);
76
+ QObject::connect (&init_executor, &InitExecutor::shutdownResult, qGuiApp, &QGuiApplication::quit, Qt::QueuedConnection);
77
+ // QObject::connect(&init_executor, &InitExecutor::runawayException, &node_model, &NodeModel::handleRunawayException);
78
+
79
+ qGuiApp->setQuitOnLastWindowClosed (false );
80
+ QObject::connect (qGuiApp, &QGuiApplication::lastWindowClosed, [&] {
81
+ node->startShutdown ();
82
+ node_model.startNodeShutdown ();
83
+ });
53
84
54
85
QQmlApplicationEngine engine;
55
86
engine.rootContext ()->setContextProperty (" nodeModel" , &node_model);
@@ -59,14 +90,5 @@ int QmlGuiMain(int argc, char* argv[])
59
90
return EXIT_FAILURE;
60
91
}
61
92
62
- // Parse command-line options. We do this after qt in order to show an error if there are problems parsing these.
63
- SetupServerArgs (gArgs );
64
- SetupUIArgs (gArgs );
65
- std::string error;
66
- if (!gArgs .ParseParameters (argc, argv, error)) {
67
- InitError (strprintf (Untranslated (" Error parsing command line arguments: %s\n " ), error));
68
- return EXIT_FAILURE;
69
- }
70
-
71
- return app.exec ();
93
+ return qGuiApp->exec ();
72
94
}
0 commit comments