Skip to content

Commit 48f4abb

Browse files
committed
qml: adapt runtime dialog callbacks to updated Core APIs
The updated Core node interface no longer supplies a caption for message box or question callbacks, so derive runtime dialog titles from style and remove the stale caption plumbing from the test bridge.
1 parent 58ce961 commit 48f4abb

8 files changed

Lines changed: 54 additions & 81 deletions

File tree

qml/bitcoin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ int QmlGuiMain(int argc, char* argv[])
257257

258258
std::unique_ptr<interfaces::Init> init = interfaces::MakeGuiInit(argc, argv);
259259
QStringList startup_warnings;
260-
auto handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(
261-
[&startup_warnings](const bilingual_str& message, const std::string& caption, unsigned int style) {
260+
auto handler_message_box = ::uiInterface.ThreadSafeMessageBox.connect(
261+
[&startup_warnings](const bilingual_str& message, unsigned int style) {
262262
if (style & CClientUIInterface::ICON_WARNING) {
263263
RecordStartupWarning(startup_warnings, message);
264264
return false;
265265
}
266-
return InitErrorMessageBox(message, caption, style);
266+
return InitErrorMessageBox(message, style);
267267
});
268268

269269
SetupEnvironment();

qml/models/nodemodel.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ QStringList SplitWarnings(const QString& warnings)
5252
return result;
5353
}
5454

55-
QString RuntimeDialogTitle(const QString& caption, unsigned int style)
55+
QString RuntimeDialogTitle(unsigned int style)
5656
{
57-
if (!caption.isEmpty()) {
58-
return caption;
59-
}
6057
if (style & CClientUIInterface::ICON_ERROR) {
6158
return QObject::tr("Error");
6259
}
@@ -386,7 +383,7 @@ void NodeModel::showStartupWarnings()
386383
const QString warnings{m_startup_warning_messages.join(QStringLiteral("\n\n"))};
387384
m_startup_warning_messages.clear();
388385
// MSG_WARNING is modal; startup notices should be shown once without blocking initialization.
389-
showRuntimeDialogOnGuiThread(warnings, QString{}, CClientUIInterface::ICON_WARNING, /*question=*/false);
386+
showRuntimeDialogOnGuiThread(warnings, CClientUIInterface::ICON_WARNING, /*question=*/false);
390387
}
391388

392389
void NodeModel::recordStartupErrorMessage(const QString& message)
@@ -567,20 +564,16 @@ void NodeModel::ConnectToRuntimeDialogSignals()
567564
assert(!m_handler_question);
568565

569566
m_handler_message_box = m_node.handleMessageBox(
570-
[this](const bilingual_str& message, const std::string& caption, unsigned int style) {
571-
return showRuntimeDialog(
567+
[this](const bilingual_str& message, unsigned int style) {
568+
showRuntimeMessageBox(
572569
QString::fromStdString(message.translated),
573-
QString::fromStdString(caption),
574-
style,
575-
/*question=*/false);
570+
style);
576571
});
577572
m_handler_question = m_node.handleQuestion(
578-
[this](const bilingual_str& message, [[maybe_unused]] const std::string& non_interactive_message, const std::string& caption, unsigned int style) {
579-
return showRuntimeDialog(
573+
[this](const bilingual_str& message, [[maybe_unused]] const std::string& non_interactive_message, unsigned int style) {
574+
return showRuntimeQuestion(
580575
QString::fromStdString(message.translated),
581-
QString::fromStdString(caption),
582-
style,
583-
/*question=*/true);
576+
style);
584577
});
585578
}
586579

@@ -658,7 +651,7 @@ QVariantList NodeModel::nodeInformationRows()
658651
rows.push_back(InformationRow(tr("User agent"), QString::fromStdString(strSubVersion)));
659652
rows.push_back(InformationRow(tr("Datadir"), QString::fromStdString(fs::PathToString(gArgs.GetDataDirNet()))));
660653
rows.push_back(InformationRow(tr("Blocks dir"), QString::fromStdString(fs::PathToString(gArgs.GetBlocksDirPath()))));
661-
rows.push_back(InformationRow(tr("Startup time"), QDateTime::fromSecsSinceEpoch(GetStartupTime()).toString()));
654+
rows.push_back(InformationRow(tr("Startup time"), QDateTime::currentDateTime().addSecs(-TicksSeconds(GetUptime())).toString()));
662655
rows.push_back(InformationRow(tr("Network"), QString::fromStdString(Params().GetChainTypeString())));
663656
rows.push_back(InformationRow(tr("Block height"), QString::number(block_height)));
664657
rows.push_back(InformationRow(tr("Header height"), QString::number(header_height)));
@@ -672,27 +665,39 @@ QVariantList NodeModel::nodeInformationRows()
672665
return rows;
673666
}
674667

675-
bool NodeModel::showRuntimeDialog(const QString& message, const QString& caption, unsigned int style, bool question)
668+
void NodeModel::showRuntimeMessageBox(const QString& message, unsigned int style)
676669
{
677670
if (QThread::currentThread() == thread()) {
678-
return showRuntimeDialogOnGuiThread(message, caption, style, question);
671+
showRuntimeDialogOnGuiThread(message, style, /*question=*/false);
672+
return;
679673
}
680674

681-
if (!(style & CClientUIInterface::MODAL) && !question) {
682-
QMetaObject::invokeMethod(this, [this, message, caption, style, question] {
683-
showRuntimeDialogOnGuiThread(message, caption, style, question);
675+
if (!(style & CClientUIInterface::MODAL)) {
676+
QMetaObject::invokeMethod(this, [this, message, style] {
677+
showRuntimeDialogOnGuiThread(message, style, /*question=*/false);
684678
}, Qt::QueuedConnection);
685-
return false;
679+
return;
680+
}
681+
682+
QMetaObject::invokeMethod(this, [this, message, style] {
683+
showRuntimeDialogOnGuiThread(message, style, /*question=*/false);
684+
}, Qt::BlockingQueuedConnection);
685+
}
686+
687+
bool NodeModel::showRuntimeQuestion(const QString& message, unsigned int style)
688+
{
689+
if (QThread::currentThread() == thread()) {
690+
return showRuntimeDialogOnGuiThread(message, style, /*question=*/true);
686691
}
687692

688693
bool result{false};
689-
QMetaObject::invokeMethod(this, [this, &result, message, caption, style, question] {
690-
result = showRuntimeDialogOnGuiThread(message, caption, style, question);
694+
QMetaObject::invokeMethod(this, [this, &result, message, style] {
695+
result = showRuntimeDialogOnGuiThread(message, style, /*question=*/true);
691696
}, Qt::BlockingQueuedConnection);
692697
return result;
693698
}
694699

695-
bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, const QString& caption, unsigned int style, bool question)
700+
bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, unsigned int style, bool question)
696701
{
697702
if (!m_runtime_dialogs_enabled && !question) {
698703
if (style & CClientUIInterface::ICON_WARNING) {
@@ -710,7 +715,6 @@ bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, const QStri
710715
const bool blocking{(style & CClientUIInterface::MODAL) || question};
711716
auto request{std::make_shared<RuntimeDialogRequest>()};
712717
request->message = message;
713-
request->caption = caption;
714718
request->style = style;
715719
request->question = question;
716720
if (!m_runtime_dialogs_enabled && (question || (style & CClientUIInterface::ICON_ERROR))) {
@@ -743,7 +747,7 @@ bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, const QStri
743747
void NodeModel::showRuntimeDialogRequest(const std::shared_ptr<RuntimeDialogRequest>& request)
744748
{
745749
m_runtime_dialog_active = request;
746-
m_runtime_dialog_title = RuntimeDialogTitle(request->caption, request->style);
750+
m_runtime_dialog_title = RuntimeDialogTitle(request->style);
747751
m_runtime_dialog_message = request->message;
748752
m_runtime_dialog_icon = RuntimeDialogIcon(request->style);
749753
m_runtime_dialog_buttons = RuntimeDialogButtons(request->style);
@@ -778,11 +782,10 @@ void NodeModel::answerRuntimeDialog(unsigned int button)
778782
}
779783

780784
#ifdef ENABLE_TEST_AUTOMATION
781-
void NodeModel::showRuntimeDialogForTest(const QString& message, const QString& caption, unsigned int style, bool question)
785+
void NodeModel::showRuntimeDialogForTest(const QString& message, unsigned int style, bool question)
782786
{
783787
auto request{std::make_shared<RuntimeDialogRequest>()};
784788
request->message = message;
785-
request->caption = caption;
786789
request->style = style;
787790
request->question = question;
788791

qml/models/nodemodel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class NodeModel : public QObject
127127
Q_INVOKABLE QVariantList nodeInformationRows();
128128
Q_INVOKABLE void answerRuntimeDialog(unsigned int button);
129129
#ifdef ENABLE_TEST_AUTOMATION
130-
Q_INVOKABLE void showRuntimeDialogForTest(const QString& message, const QString& caption, unsigned int style, bool question);
130+
Q_INVOKABLE void showRuntimeDialogForTest(const QString& message, unsigned int style, bool question);
131131
#endif
132132

133133
public Q_SLOTS:
@@ -170,7 +170,6 @@ public Q_SLOTS:
170170

171171
struct RuntimeDialogRequest {
172172
QString message;
173-
QString caption;
174173
unsigned int style{0};
175174
bool question{false};
176175
bool answer{false};
@@ -253,8 +252,9 @@ public Q_SLOTS:
253252
void setWarnings(const QString& warnings);
254253
void setBlockSyncActive(bool active);
255254
void setHeaderSyncState(int height, int64_t block_time, bool presync);
256-
bool showRuntimeDialog(const QString& message, const QString& caption, unsigned int style, bool question);
257-
bool showRuntimeDialogOnGuiThread(const QString& message, const QString& caption, unsigned int style, bool question);
255+
void showRuntimeMessageBox(const QString& message, unsigned int style);
256+
bool showRuntimeQuestion(const QString& message, unsigned int style);
257+
bool showRuntimeDialogOnGuiThread(const QString& message, unsigned int style, bool question);
258258
void showRuntimeDialogRequest(const std::shared_ptr<RuntimeDialogRequest>& request);
259259
void requestMempoolInfoRefresh();
260260
void fetchMempoolInfo();

qml/test/testbridge.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ QByteArray TestBridge::processCommand(const QByteArray& json_cmd)
442442
} else if (cmd == QLatin1String("show_runtime_dialog")) {
443443
return cmdShowRuntimeDialog(
444444
obj.value(QStringLiteral("message")).toString(),
445-
obj.value(QStringLiteral("caption")).toString(),
446445
static_cast<unsigned int>(obj.value(QStringLiteral("style")).toDouble()),
447446
obj.value(QStringLiteral("question")).toBool(false));
448447
} else if (cmd == QLatin1String("answer_runtime_dialog")) {
@@ -953,7 +952,7 @@ QByteArray TestBridge::cmdSaveScreenshot(const QString& path)
953952
return QJsonDocument(resp).toJson(QJsonDocument::Compact);
954953
}
955954

956-
QByteArray TestBridge::cmdShowRuntimeDialog(const QString& message, const QString& caption, unsigned int style, bool question)
955+
QByteArray TestBridge::cmdShowRuntimeDialog(const QString& message, unsigned int style, bool question)
957956
{
958957
QVariant node_model_value = m_engine->rootContext()->contextProperty(QStringLiteral("nodeModel"));
959958
QObject* node_model = node_model_value.value<QObject*>();
@@ -966,7 +965,6 @@ QByteArray TestBridge::cmdShowRuntimeDialog(const QString& message, const QStrin
966965
"showRuntimeDialogForTest",
967966
Qt::DirectConnection,
968967
Q_ARG(QString, message),
969-
Q_ARG(QString, caption),
970968
Q_ARG(unsigned int, style),
971969
Q_ARG(bool, question));
972970
if (!invoked) {

qml/test/testbridge.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/// {"cmd": "click_list_item", "objectName": "<view>", "index": <zero-based-row>, "childObjectName": "<optional-delegate-child>"}
3636
/// {"cmd": "get_list_item_property", "objectName": "<view>", "index": <zero-based-row>, "prop": "<delegate-root-property>"}
3737
/// {"cmd": "save_screenshot", "path": "<png_path>"}
38-
/// {"cmd": "show_runtime_dialog", "message": "<text>", "caption": "<title>", "style": <uint>, "question": <bool>}
38+
/// {"cmd": "show_runtime_dialog", "message": "<text>", "style": <uint>, "question": <bool>}
3939
/// {"cmd": "answer_runtime_dialog", "button": <uint>}
4040
/// {"cmd": "list_objects"}
4141
/// {"cmd": "close_window"}
@@ -88,7 +88,7 @@ private Q_SLOTS:
8888
QByteArray cmdClickListItem(const QString& view_object_name, int row_index, const QString& delegate_child_object_name);
8989
QByteArray cmdGetListItemProperty(const QString& view_object_name, int row_index, const QString& prop);
9090
QByteArray cmdSaveScreenshot(const QString& path);
91-
QByteArray cmdShowRuntimeDialog(const QString& message, const QString& caption, unsigned int style, bool question);
91+
QByteArray cmdShowRuntimeDialog(const QString& message, unsigned int style, bool question);
9292
QByteArray cmdAnswerRuntimeDialog(unsigned int button);
9393
QByteArray cmdListObjects();
9494
QByteArray cmdCloseWindow();

test/functional/qml_driver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,12 @@ def save_screenshot(self, path):
235235
)
236236
return resp
237237

238-
def show_runtime_dialog(self, message, caption, style, question=False):
238+
def show_runtime_dialog(self, message, style, question=False):
239239
"""Open a NodeRuntimeDialog through the test automation bridge."""
240240
resp = self._send(
241241
{
242242
"cmd": "show_runtime_dialog",
243243
"message": message,
244-
"caption": caption,
245244
"style": style,
246245
"question": question,
247246
}

test/functional/qml_test_node_runtime_dialogs.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"name": "database-read-error",
3838
"source": "bitcoin/src/init.cpp coins_error_cb",
3939
"message": "Error reading from database, shutting down.",
40-
"caption": "",
4140
"style": MSG_ERROR,
4241
"question": False,
4342
"buttons": [BTN_OK],
@@ -47,7 +46,6 @@
4746
"name": "deprecated-checkpoints-warning",
4847
"source": "bitcoin/src/init.cpp -checkpoints warning",
4948
"message": "Option '-checkpoints' is set but checkpoints were removed. This option has no effect.",
50-
"caption": "",
5149
"style": MSG_WARNING,
5250
"question": False,
5351
"buttons": [BTN_OK],
@@ -57,7 +55,6 @@
5755
"name": "reindex-question-ok-abort",
5856
"source": "bitcoin/src/init.cpp chainstate load failure retry question",
5957
"message": "Error opening block database.\n\nDo you want to rebuild the databases now?",
60-
"caption": "",
6158
"style": MSG_ERROR | BTN_ABORT,
6259
"question": True,
6360
"buttons": [BTN_OK, BTN_ABORT],
@@ -67,7 +64,6 @@
6764
"name": "network-options-error",
6865
"source": "bitcoin/src/net.cpp outgoing connection option conflict",
6966
"message": "Cannot provide specific connections and have addrman find outgoing connections at the same time.",
70-
"caption": "",
7167
"style": MSG_ERROR,
7268
"question": False,
7369
"buttons": [BTN_OK],
@@ -77,7 +73,6 @@
7773
"name": "abort-retry-ignore-button-mask",
7874
"source": "CClientUIInterface BTN_ABORT | BTN_RETRY | BTN_IGNORE contract sample using a net.cpp error message",
7975
"message": "Failed to listen on any port. Use -listen=0 if you want this.",
80-
"caption": "",
8176
"style": ICON_ERROR | MODAL | BTN_ABORT | BTN_RETRY | BTN_IGNORE,
8277
"question": True,
8378
"buttons": [BTN_ABORT, BTN_RETRY, BTN_IGNORE],
@@ -115,7 +110,6 @@ def screenshot_path(root, case_name):
115110
def open_case(gui, case):
116111
gui.show_runtime_dialog(
117112
message=case["message"],
118-
caption=case["caption"],
119113
style=case["style"],
120114
question=case["question"],
121115
)

0 commit comments

Comments
 (0)