From 4165a0d656ea317c558ead8bc7eec791b4f7ba32 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 14 Oct 2024 10:44:43 -0700 Subject: [PATCH] Fix status text escaping/signalling Regular status text messages should move around system un-formatted Add missing textMessageReceived signaling --- src/MAVLink/StatusTextHandler.cc | 5 +++-- src/MAVLink/StatusTextHandler.h | 2 +- src/Vehicle/Vehicle.cc | 5 +++-- test/MAVLink/StatusTextHandlerTest.cc | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/MAVLink/StatusTextHandler.cc b/src/MAVLink/StatusTextHandler.cc index f27ed1f76d7..05799e4f71e 100644 --- a/src/MAVLink/StatusTextHandler.cc +++ b/src/MAVLink/StatusTextHandler.cc @@ -137,9 +137,10 @@ void StatusTextHandler::resetErrorLevelMessages() } } -void StatusTextHandler::handleTextMessage(MAV_COMPONENT compId, MAV_SEVERITY severity, const QString &text, const QString &description) +void StatusTextHandler::handleHTMLEscapedTextMessage(MAV_COMPONENT compId, MAV_SEVERITY severity, const QString &text, const QString &description) { QString htmlText(text); + (void) htmlText.replace("\n", "
"); // TODO: handle text + description separately in the UI @@ -335,7 +336,7 @@ void StatusTextHandler::_chunkedStatusTextCompleted(MAV_COMPONENT compId) (void) m_chunkedStatusTextInfoMap.remove(compId); - emit textMessageReceived(compId, severity, messageText.toHtmlEscaped(), ""); + emit textMessageReceived(compId, severity, messageText, ""); } void StatusTextHandler::_handleTextMessage(uint32_t newCount, MessageType messageType) diff --git a/src/MAVLink/StatusTextHandler.h b/src/MAVLink/StatusTextHandler.h index 8bffd4b483b..6eba5ec6f2f 100644 --- a/src/MAVLink/StatusTextHandler.h +++ b/src/MAVLink/StatusTextHandler.h @@ -57,7 +57,7 @@ class StatusTextHandler : public QObject ~StatusTextHandler(); void mavlinkMessageReceived(const mavlink_message_t &message); - void handleTextMessage(MAV_COMPONENT componentid, MAV_SEVERITY severity, const QString &text, const QString &description); + void handleHTMLEscapedTextMessage(MAV_COMPONENT componentid, MAV_SEVERITY severity, const QString &text, const QString &description); void clearMessages(); void resetAllMessages(); diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 27145ba2df8..9fbf14621e6 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -1227,7 +1227,7 @@ void Vehicle::_handleEvent(uint8_t comp_id, std::unique_ptrhandleTextMessage(static_cast(comp_id), static_cast(severity), text, QString::fromStdString(description)); + m_statusTextHandler->handleHTMLEscapedTextMessage(static_cast(comp_id), static_cast(severity), text, QString::fromStdString(description)); } } } @@ -4047,7 +4047,8 @@ void Vehicle::_textMessageReceived(MAV_COMPONENT componentid, MAV_SEVERITY sever _say(text); } - m_statusTextHandler->handleTextMessage(componentid, severity, text.toHtmlEscaped(), description); + emit textMessageReceived(id(), componentid, severity, text, description); + m_statusTextHandler->handleHTMLEscapedTextMessage(componentid, severity, text.toHtmlEscaped(), description); } void Vehicle::_errorMessageReceived(QString message) diff --git a/test/MAVLink/StatusTextHandlerTest.cc b/test/MAVLink/StatusTextHandlerTest.cc index 4f72e88b441..eeea3f5172a 100644 --- a/test/MAVLink/StatusTextHandlerTest.cc +++ b/test/MAVLink/StatusTextHandlerTest.cc @@ -26,14 +26,14 @@ void StatusTextHandlerTest::_testHandleTextMessage() { StatusTextHandler* statusTextHandler = new StatusTextHandler(this); - statusTextHandler->handleTextMessage(MAV_COMP_ID_USER1, MAV_SEVERITY_INFO, "StatusTextHandlerTestInfo", "This is the StatusTextHandlerTestInfo Test"); + statusTextHandler->handleHTMLEscapedTextMessage(MAV_COMP_ID_USER1, MAV_SEVERITY_INFO, "StatusTextHandlerTestInfo", "This is the StatusTextHandlerTestInfo Test"); QString messages = statusTextHandler->formattedMessages(); QVERIFY(!messages.isEmpty()); QVERIFY(messages.contains("StatusTextHandlerTestInfo")); QCOMPARE(statusTextHandler->getNormalCount(), 1); QCOMPARE(statusTextHandler->messageCount(), 1); - statusTextHandler->handleTextMessage(MAV_COMP_ID_USER1, MAV_SEVERITY_WARNING, "StatusTextHandlerTestWarning", "This is the StatusTextHandlerTestWarning Test"); + statusTextHandler->handleHTMLEscapedTextMessage(MAV_COMP_ID_USER1, MAV_SEVERITY_WARNING, "StatusTextHandlerTestWarning", "This is the StatusTextHandlerTestWarning Test"); messages = statusTextHandler->formattedMessages(); QVERIFY(messages.contains("StatusTextHandlerTestInfo")); QVERIFY(messages.contains("StatusTextHandlerTestWarning"));