Skip to content

Commit dacddb7

Browse files
committed
qml: adapt runtime dialog callbacks to Core v31
The Core v31 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 8a9dd02 commit dacddb7

8 files changed

Lines changed: 24 additions & 54 deletions

File tree

qml/bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ int QmlGuiMain(int argc, char* argv[])
239239
std::unique_ptr<interfaces::Init> init = interfaces::MakeGuiInit(argc, argv);
240240
QStringList startup_warnings;
241241
auto handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(
242-
[&startup_warnings](const bilingual_str& message, const std::string& caption, unsigned int style) {
242+
[&startup_warnings](const bilingual_str& message, unsigned int style) {
243243
if (style & CClientUIInterface::ICON_WARNING) {
244244
RecordStartupWarning(startup_warnings, message);
245245
return false;
246246
}
247-
return InitErrorMessageBox(message, caption, style);
247+
return InitErrorMessageBox(message, style);
248248
});
249249

250250
SetupEnvironment();

qml/models/nodemodel.cpp

Lines changed: 14 additions & 21 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,18 +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) {
567+
[this](const bilingual_str& message, unsigned int style) {
571568
return showRuntimeDialog(
572569
QString::fromStdString(message.translated),
573-
QString::fromStdString(caption),
574570
style,
575571
/*question=*/false);
576572
});
577573
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) {
574+
[this](const bilingual_str& message, [[maybe_unused]] const std::string& non_interactive_message, unsigned int style) {
579575
return showRuntimeDialog(
580576
QString::fromStdString(message.translated),
581-
QString::fromStdString(caption),
582577
style,
583578
/*question=*/true);
584579
});
@@ -658,7 +653,7 @@ QVariantList NodeModel::nodeInformationRows()
658653
rows.push_back(InformationRow(tr("User agent"), QString::fromStdString(strSubVersion)));
659654
rows.push_back(InformationRow(tr("Datadir"), QString::fromStdString(fs::PathToString(gArgs.GetDataDirNet()))));
660655
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()));
656+
rows.push_back(InformationRow(tr("Startup time"), QDateTime::currentDateTime().addSecs(-TicksSeconds(GetUptime())).toString()));
662657
rows.push_back(InformationRow(tr("Network"), QString::fromStdString(Params().GetChainTypeString())));
663658
rows.push_back(InformationRow(tr("Block height"), QString::number(block_height)));
664659
rows.push_back(InformationRow(tr("Header height"), QString::number(header_height)));
@@ -672,27 +667,27 @@ QVariantList NodeModel::nodeInformationRows()
672667
return rows;
673668
}
674669

675-
bool NodeModel::showRuntimeDialog(const QString& message, const QString& caption, unsigned int style, bool question)
670+
bool NodeModel::showRuntimeDialog(const QString& message, unsigned int style, bool question)
676671
{
677672
if (QThread::currentThread() == thread()) {
678-
return showRuntimeDialogOnGuiThread(message, caption, style, question);
673+
return showRuntimeDialogOnGuiThread(message, style, question);
679674
}
680675

681676
if (!(style & CClientUIInterface::MODAL) && !question) {
682-
QMetaObject::invokeMethod(this, [this, message, caption, style, question] {
683-
showRuntimeDialogOnGuiThread(message, caption, style, question);
677+
QMetaObject::invokeMethod(this, [this, message, style, question] {
678+
showRuntimeDialogOnGuiThread(message, style, question);
684679
}, Qt::QueuedConnection);
685680
return false;
686681
}
687682

688683
bool result{false};
689-
QMetaObject::invokeMethod(this, [this, &result, message, caption, style, question] {
690-
result = showRuntimeDialogOnGuiThread(message, caption, style, question);
684+
QMetaObject::invokeMethod(this, [this, &result, message, style, question] {
685+
result = showRuntimeDialogOnGuiThread(message, style, question);
691686
}, Qt::BlockingQueuedConnection);
692687
return result;
693688
}
694689

695-
bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, const QString& caption, unsigned int style, bool question)
690+
bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, unsigned int style, bool question)
696691
{
697692
if (!m_runtime_dialogs_enabled && !question) {
698693
if (style & CClientUIInterface::ICON_WARNING) {
@@ -710,7 +705,6 @@ bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, const QStri
710705
const bool blocking{(style & CClientUIInterface::MODAL) || question};
711706
auto request{std::make_shared<RuntimeDialogRequest>()};
712707
request->message = message;
713-
request->caption = caption;
714708
request->style = style;
715709
request->question = question;
716710
if (!m_runtime_dialogs_enabled && (question || (style & CClientUIInterface::ICON_ERROR))) {
@@ -743,7 +737,7 @@ bool NodeModel::showRuntimeDialogOnGuiThread(const QString& message, const QStri
743737
void NodeModel::showRuntimeDialogRequest(const std::shared_ptr<RuntimeDialogRequest>& request)
744738
{
745739
m_runtime_dialog_active = request;
746-
m_runtime_dialog_title = RuntimeDialogTitle(request->caption, request->style);
740+
m_runtime_dialog_title = RuntimeDialogTitle(request->style);
747741
m_runtime_dialog_message = request->message;
748742
m_runtime_dialog_icon = RuntimeDialogIcon(request->style);
749743
m_runtime_dialog_buttons = RuntimeDialogButtons(request->style);
@@ -778,11 +772,10 @@ void NodeModel::answerRuntimeDialog(unsigned int button)
778772
}
779773

780774
#ifdef ENABLE_TEST_AUTOMATION
781-
void NodeModel::showRuntimeDialogForTest(const QString& message, const QString& caption, unsigned int style, bool question)
775+
void NodeModel::showRuntimeDialogForTest(const QString& message, unsigned int style, bool question)
782776
{
783777
auto request{std::make_shared<RuntimeDialogRequest>()};
784778
request->message = message;
785-
request->caption = caption;
786779
request->style = style;
787780
request->question = question;
788781

qml/models/nodemodel.h

Lines changed: 3 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,8 @@ 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+
bool showRuntimeDialog(const QString& message, unsigned int style, bool question);
256+
bool showRuntimeDialogOnGuiThread(const QString& message, unsigned int style, bool question);
258257
void showRuntimeDialogRequest(const std::shared_ptr<RuntimeDialogRequest>& request);
259258
void requestMempoolInfoRefresh();
260259
void fetchMempoolInfo();

qml/test/testbridge.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ QByteArray TestBridge::processCommand(const QByteArray& json_cmd)
409409
} else if (cmd == QLatin1String("show_runtime_dialog")) {
410410
return cmdShowRuntimeDialog(
411411
obj.value(QStringLiteral("message")).toString(),
412-
obj.value(QStringLiteral("caption")).toString(),
413412
static_cast<unsigned int>(obj.value(QStringLiteral("style")).toDouble()),
414413
obj.value(QStringLiteral("question")).toBool(false));
415414
} else if (cmd == QLatin1String("answer_runtime_dialog")) {
@@ -883,7 +882,7 @@ QByteArray TestBridge::cmdSaveScreenshot(const QString& path)
883882
return QJsonDocument(resp).toJson(QJsonDocument::Compact);
884883
}
885884

886-
QByteArray TestBridge::cmdShowRuntimeDialog(const QString& message, const QString& caption, unsigned int style, bool question)
885+
QByteArray TestBridge::cmdShowRuntimeDialog(const QString& message, unsigned int style, bool question)
887886
{
888887
QVariant node_model_value = m_engine->rootContext()->contextProperty(QStringLiteral("nodeModel"));
889888
QObject* node_model = node_model_value.value<QObject*>();
@@ -896,7 +895,6 @@ QByteArray TestBridge::cmdShowRuntimeDialog(const QString& message, const QStrin
896895
"showRuntimeDialogForTest",
897896
Qt::DirectConnection,
898897
Q_ARG(QString, message),
899-
Q_ARG(QString, caption),
900898
Q_ARG(unsigned int, style),
901899
Q_ARG(bool, question));
902900
if (!invoked) {

qml/test/testbridge.h

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

test/functional/qml_driver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,12 @@ def save_screenshot(self, path):
227227
)
228228
return resp
229229

230-
def show_runtime_dialog(self, message, caption, style, question=False):
230+
def show_runtime_dialog(self, message, style, question=False):
231231
"""Open a NodeRuntimeDialog through the test automation bridge."""
232232
resp = self._send(
233233
{
234234
"cmd": "show_runtime_dialog",
235235
"message": message,
236-
"caption": caption,
237236
"style": style,
238237
"question": question,
239238
}

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
)

test/test_nodemodel.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ void NodeModelTests::startupWarningsAreShownOnceAndDoNotBecomeCurrentWarnings()
750750
QSignalSpy runtime_dialog_spy{&model, &NodeModel::runtimeDialogChanged};
751751
QVERIFY(!message_box_fn(
752752
bilingual_str{"Startup warning", "Translated startup warning"},
753-
"",
754753
CClientUIInterface::MSG_WARNING));
755754
QCOMPARE(runtime_dialog_spy.count(), 0);
756755

@@ -815,7 +814,6 @@ void NodeModelTests::runtimeMessageHandlerOpensAfterInitialization()
815814
std::thread worker([&] {
816815
result = message_box_fn(
817816
bilingual_str{"Runtime error", "Translated runtime error"},
818-
"",
819817
CClientUIInterface::MSG_ERROR);
820818
finished = true;
821819
});
@@ -852,7 +850,7 @@ void NodeModelTests::runtimeQuestionHandlerBlocksForAnswerAndReturnsResult()
852850
QObject::connect(&model, &NodeModel::runtimeDialogChanged, &model, [&] {
853851
if (!model.runtimeDialogVisible()) return;
854852
++prompt_count;
855-
QCOMPARE(model.runtimeDialogTitle(), QStringLiteral("Question caption"));
853+
QCOMPARE(model.runtimeDialogTitle(), QStringLiteral("Error"));
856854
QCOMPARE(model.runtimeDialogMessage(), QStringLiteral("Translated rebuild?"));
857855
QCOMPARE(model.runtimeDialogButtons(), static_cast<unsigned int>(CClientUIInterface::BTN_OK | CClientUIInterface::BTN_ABORT));
858856
QVERIFY(model.runtimeDialogQuestion());
@@ -865,7 +863,6 @@ void NodeModelTests::runtimeQuestionHandlerBlocksForAnswerAndReturnsResult()
865863
result = question_fn(
866864
bilingual_str{"Rebuild?", "Translated rebuild?"},
867865
"Non interactive",
868-
"Question caption",
869866
CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
870867
finished = true;
871868
});
@@ -918,7 +915,6 @@ void NodeModelTests::runtimeStartupQuestionFailureLetsInitializeResultRequestShu
918915
result = question_fn(
919916
bilingual_str{"Rebuild?", "Translated rebuild?"},
920917
"Non interactive",
921-
"",
922918
CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
923919
finished = true;
924920
});
@@ -980,7 +976,6 @@ void NodeModelTests::runtimeStartupErrorDialogLetsInitializeResultRequestShutdow
980976
std::thread worker([&] {
981977
result = message_box_fn(
982978
bilingual_str{"Failed to initialize", "Translated failed to initialize"},
983-
"",
984979
CClientUIInterface::MSG_ERROR);
985980
finished = true;
986981
});
@@ -1034,7 +1029,6 @@ void NodeModelTests::runtimeDialogDefaultsToOkWhenNoButtonsAreSpecified()
10341029
std::thread worker([&] {
10351030
result = message_box_fn(
10361031
bilingual_str{"Information", "Translated information"},
1037-
"",
10381032
CClientUIInterface::ICON_INFORMATION | CClientUIInterface::MODAL);
10391033
finished = true;
10401034
});
@@ -1082,7 +1076,6 @@ void NodeModelTests::runtimeDialogExposesFullCoreButtonMask()
10821076
std::thread worker([&] {
10831077
result = message_box_fn(
10841078
bilingual_str{"Full button mask", "Translated full button mask"},
1085-
"",
10861079
CClientUIInterface::ICON_WARNING | CClientUIInterface::MODAL | full_button_mask);
10871080
finished = true;
10881081
});
@@ -1128,7 +1121,6 @@ void NodeModelTests::runtimeBlockingDialogsAreQueued()
11281121
second_result = question_fn(
11291122
bilingual_str{"Second?", "Translated second?"},
11301123
"Non interactive",
1131-
"Second caption",
11321124
CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
11331125
} else if (model.runtimeDialogMessage() == QStringLiteral("Translated second?")) {
11341126
QTimer::singleShot(0, &model, [&model] {
@@ -1140,7 +1132,6 @@ void NodeModelTests::runtimeBlockingDialogsAreQueued()
11401132
first_result = question_fn(
11411133
bilingual_str{"First?", "Translated first?"},
11421134
"Non interactive",
1143-
"First caption",
11441135
CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
11451136

11461137
QCOMPARE(prompts, QStringList({QStringLiteral("Translated first?"), QStringLiteral("Translated second?")}));
@@ -1171,15 +1162,13 @@ void NodeModelTests::runtimeNonBlockingDialogsAreQueued()
11711162
QSignalSpy runtime_dialog_spy{&model, &NodeModel::runtimeDialogChanged};
11721163
QVERIFY(!message_box_fn(
11731164
bilingual_str{"First", "Translated first"},
1174-
"",
11751165
CClientUIInterface::ICON_INFORMATION));
11761166
QCOMPARE(runtime_dialog_spy.count(), 1);
11771167
QVERIFY(model.runtimeDialogVisible());
11781168
QCOMPARE(model.runtimeDialogMessage(), QStringLiteral("Translated first"));
11791169

11801170
QVERIFY(!message_box_fn(
11811171
bilingual_str{"Second", "Translated second"},
1182-
"",
11831172
CClientUIInterface::ICON_WARNING));
11841173
QCOMPARE(runtime_dialog_spy.count(), 1);
11851174
QVERIFY(model.runtimeDialogVisible());
@@ -1244,11 +1233,9 @@ void NodeModelTests::initializeFailureUsesNodeErrorMessages()
12441233
std::thread worker([&] {
12451234
message_box_fn(
12461235
bilingual_str{"Unable to bind original", "Translated unable to bind"},
1247-
"",
12481236
CClientUIInterface::ICON_ERROR);
12491237
message_box_fn(
12501238
bilingual_str{"Failed to listen original", "Translated failed to listen"},
1251-
"",
12521239
CClientUIInterface::ICON_ERROR);
12531240
finished = true;
12541241
});

0 commit comments

Comments
 (0)