Skip to content

Add basic start/shutdown functionality #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ QT_FORMS_UI = \
qt/forms/transactiondescdialog.ui

QT_MOC_CPP = \
qml/moc_nodemodel.cpp \
qt/moc_addressbookpage.cpp \
qt/moc_addresstablemodel.cpp \
qt/moc_askpassphrasedialog.cpp \
Expand Down Expand Up @@ -107,6 +108,7 @@ QT_QRC_LOCALE = qt/bitcoin_locale.qrc

BITCOIN_QT_H = \
qml/bitcoin.h \
qml/nodemodel.h \
qt/addressbookpage.h \
qt/addresstablemodel.h \
qt/askpassphrasedialog.h \
Expand Down Expand Up @@ -281,7 +283,8 @@ BITCOIN_QT_WALLET_CPP = \
qt/walletview.cpp

BITCOIN_QML_BASE_CPP = \
qml/bitcoin.cpp
qml/bitcoin.cpp \
qml/nodemodel.cpp

QML_QRC_CPP = qml/qrc_bitcoin.cpp
QML_QRC = qml/bitcoin_qml.qrc
Expand Down
1 change: 1 addition & 0 deletions src/qml/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/moc_*.cpp
57 changes: 43 additions & 14 deletions src/qml/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <node/context.h>
#include <node/ui_interface.h>
#include <noui.h>
#include <qml/nodemodel.h>
#include <qt/guiconstants.h>
#include <qt/initexecutor.h>
#include <util/system.h>
#include <util/translation.h>

Expand All @@ -18,6 +20,7 @@

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QStringLiteral>
#include <QUrl>

Expand All @@ -34,23 +37,10 @@ void SetupUIArgs(ArgsManager& argsman)

int QmlGuiMain(int argc, char* argv[])
{
NodeContext node_context;
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);

// Subscribe to global signals from core
boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
boost::signals2::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
boost::signals2::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect(noui_InitMessage);

Q_INIT_RESOURCE(bitcoin_qml);

QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///qml/pages/stub.qml")));
if (engine.rootObjects().isEmpty()) {
return EXIT_FAILURE;
}

// Parse command-line options. We do this after qt in order to show an error if there are problems parsing these.
SetupServerArgs(gArgs);
Expand All @@ -61,5 +51,44 @@ int QmlGuiMain(int argc, char* argv[])
return EXIT_FAILURE;
}

return app.exec();
CheckDataDirOption();

gArgs.ReadConfigFiles(error, true);

SelectParams(gArgs.GetChainName());

// Default printtoconsole to false for the GUI. GUI programs should not
// print to the console unnecessarily.
gArgs.SoftSetBoolArg("-printtoconsole", false);
InitLogging(gArgs);
InitParameterInteraction(gArgs);

NodeContext node_context;
node_context.args = &gArgs;
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);
node->baseInitialize();

NodeModel node_model;
InitExecutor init_executor{*node};
QObject::connect(&node_model, &NodeModel::requestedInitialize, &init_executor, &InitExecutor::initialize);
QObject::connect(&node_model, &NodeModel::requestedShutdown, &init_executor, &InitExecutor::shutdown);
// QObject::connect(&init_executor, &InitExecutor::initializeResult, &node_model, &NodeModel::initializeResult);
QObject::connect(&init_executor, &InitExecutor::shutdownResult, qGuiApp, &QGuiApplication::quit, Qt::QueuedConnection);
// QObject::connect(&init_executor, &InitExecutor::runawayException, &node_model, &NodeModel::handleRunawayException);

qGuiApp->setQuitOnLastWindowClosed(false);
QObject::connect(qGuiApp, &QGuiApplication::lastWindowClosed, [&] {
node->startShutdown();
node_model.startNodeShutdown();
});

QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("nodeModel", &node_model);

engine.load(QUrl(QStringLiteral("qrc:///qml/pages/stub.qml")));
if (engine.rootObjects().isEmpty()) {
return EXIT_FAILURE;
}

return qGuiApp->exec();
}
17 changes: 17 additions & 0 deletions src/qml/nodemodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qml/nodemodel.h>

#include <QDebug>

void NodeModel::startNodeInitializionThread()
{
Q_EMIT requestedInitialize();
}

void NodeModel::startNodeShutdown()
{
Q_EMIT requestedShutdown();
}
24 changes: 24 additions & 0 deletions src/qml/nodemodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_QML_NODEMODEL_H
#define BITCOIN_QML_NODEMODEL_H

#include <QObject>

/** Model for Bitcoin network client. */
class NodeModel : public QObject
{
Q_OBJECT

public:
Q_INVOKABLE void startNodeInitializionThread();
void startNodeShutdown();

Q_SIGNALS:
void requestedInitialize();
void requestedShutdown();
};

#endif // BITCOIN_QML_NODEMODEL_H
3 changes: 3 additions & 0 deletions src/qml/pages/stub.qml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import QtQml 2.12
import QtQuick.Controls 2.12

ApplicationWindow {
Expand All @@ -6,4 +7,6 @@ ApplicationWindow {
minimumWidth: 750
minimumHeight: 450
visible: true

Component.onCompleted: nodeModel.startNodeInitializionThread();
}