diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index 6e0287237..e9f60e533 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -118,6 +118,9 @@ namespace BlackCore //! Relevant simulator messages to be explicitly displayed void driverMessages(const BlackMisc::CStatusMessageList &messages); + //! Request a console message (whatever the console maybe) + void requestUiConsoleMessage(const QString &driverMessage, bool clear); + public slots: //! Simulator info, currently loaded plugin virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0; diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index c047f0004..3619475cf 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -319,6 +319,8 @@ namespace BlackCore Q_ASSERT(c); c = connect(simulator, &ISimulator::driverMessages, this, &IContextSimulator::driverMessages); Q_ASSERT(c); + c = connect(simulator, &ISimulator::requestUiConsoleMessage, this, &IContextSimulator::requestUiConsoleMessage); + Q_ASSERT(c); // log from context to simulator c = connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, &CContextSimulator::relayStatusMessageToSimulator); diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index 5c0fd33b4..7d07b2c03 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -77,6 +77,10 @@ namespace BlackCore s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "driverMessages", this, SIGNAL(driverMessages(BlackMisc::CStatusMessageList))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "requestUiConsoleMessage", this, SIGNAL(requestUiConsoleMessage(QString, bool))); + Q_ASSERT(s); Q_UNUSED(s); this->relayBaseClassSignals(serviceName, connection, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName()); diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 208ca8f31..2a4d32399 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -223,6 +223,9 @@ namespace BlackCore //! Relevant simulator messages to be explicitly displayed void driverMessages(const BlackMisc::CStatusMessageList &messages); + //! Request a console message (whatever the console maybe) + void requestUiConsoleMessage(const QString &driverMessage, bool clear); + protected: //! Default constructor ISimulator(QObject *parent = nullptr); diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index 35d3a5daf..6d8cca453 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -820,7 +820,11 @@ namespace BlackCore QStringLiteral("Situation: ") % s.toQString(false, false, true, true, true, true, sep); } if (p.tsCurrent > 0) { dm += (dm.isEmpty() ? QStringLiteral("") : QStringLiteral("\n\n")) % QStringLiteral("Parts: ") % p.toQString(sep); } - if (!dm.isEmpty()) { this->displayStatusMessage(CStatusMessage(this).info(dm)); } + if (!dm.isEmpty()) + { + this->displayStatusMessage(CStatusMessage(this).info(dm)); + emit this->requestUiConsoleMessage(dm, true); + } const int t = 4500 + (qrand() % 1000); // makes sure not always using the same time difference QTimer::singleShot(t, this, [ = ] diff --git a/src/blackgui/components/logcomponent.cpp b/src/blackgui/components/logcomponent.cpp index 041d8b4a0..5434fc67b 100644 --- a/src/blackgui/components/logcomponent.cpp +++ b/src/blackgui/components/logcomponent.cpp @@ -104,6 +104,16 @@ namespace BlackGui ui->comp_StatusMessages->clear(); } + void CLogComponent::clearConsole() + { + ui->tep_StatusPageConsole->clear(); + } + + void CLogComponent::clearMessages() + { + ui->comp_StatusMessages->clear(); + } + void CLogComponent::appendStatusMessageToConsole(const CStatusMessage &statusMessage) { if (statusMessage.isEmpty()) return; diff --git a/src/blackgui/components/logcomponent.h b/src/blackgui/components/logcomponent.h index 8b6ad0100..51c3a1e47 100644 --- a/src/blackgui/components/logcomponent.h +++ b/src/blackgui/components/logcomponent.h @@ -83,6 +83,12 @@ namespace BlackGui //! Clear void clear(); + //! Clear + void clearConsole(); + + //! Clear + void clearMessages(); + //! Append status message to console void appendStatusMessageToConsole(const BlackMisc::CStatusMessage &statusMessage); diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index 94eff6fea..7fdb8fcd4 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -9,9 +9,6 @@ #include "swiftguistd.h" #include "ui_swiftguistd.h" -#include "blackconfig/buildconfig.h" -#include "blackcore/webdataservices.h" -#include "blackcore/context/contextnetwork.h" #include "blackgui/components/aircraftcomponent.h" #include "blackgui/components/atcstationcomponent.h" #include "blackgui/components/cockpitcomponent.h" @@ -30,12 +27,16 @@ #include "blackgui/managedstatusbar.h" #include "blackgui/overlaymessagesframe.h" #include "blackgui/stylesheetutility.h" +#include "blackcore/webdataservices.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextsimulator.h" #include "blackmisc/network/networkutils.h" #include "blackmisc/loghandler.h" #include "blackmisc/logmessage.h" #include "blackmisc/logpattern.h" #include "blackmisc/slot.h" #include "blackmisc/statusmessage.h" +#include "blackconfig/buildconfig.h" #include #include @@ -62,6 +63,7 @@ void SwiftGuiStd::init() // POST(!) GUI init Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); Q_ASSERT_X(sGui->getWebDataServices(), Q_FUNC_INFO, "Missing web services"); + Q_ASSERT_X(sGui->supportsContexts(), Q_FUNC_INFO, "Missing contexts"); if (m_init) { return; } @@ -118,6 +120,9 @@ void SwiftGuiStd::init() this->initGuiSignals(); // signal / slots contexts / timers + Q_ASSERT_X(sGui->getIContextNetwork(), Q_FUNC_INFO, "Missing network context"); + Q_ASSERT_X(sGui->getIContextSimulator(), Q_FUNC_INFO, "Missing simulator context"); + bool s = connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &SwiftGuiStd::onConnectionStatusChanged, Qt::QueuedConnection); Q_ASSERT(s); s = connect(sGui->getIContextNetwork(), &IContextNetwork::kicked, this, &SwiftGuiStd::onKickedFromNetwork, Qt::QueuedConnection); @@ -126,6 +131,15 @@ void SwiftGuiStd::init() Q_ASSERT(s); s = connect(sGui->getIContextNetwork(), &IContextNetwork::textMessageSent, ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::onTextMessageSent, Qt::QueuedConnection); Q_ASSERT(s); + s = connect(sGui->getIContextSimulator(), &IContextSimulator::requestUiConsoleMessage, this, [ = ](const QString & logMsg, bool clear) + { + if (logMsg.isEmpty()) { return; } + CLogComponent *log = ui->comp_MainInfoArea->getLogComponent(); + Q_ASSERT_X(log, Q_FUNC_INFO, "Missing log component"); + if (clear) { log->clearConsole(); } + log->appendPlainTextToConsole(logMsg); + }, Qt::QueuedConnection); + Q_ASSERT(s); s = connect(&m_timerContextWatchdog, &QTimer::timeout, this, &SwiftGuiStd::handleTimerBasedUpdates); Q_ASSERT(s); Q_UNUSED(s); @@ -194,12 +208,12 @@ void SwiftGuiStd::initGuiSignals() connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::changedOpacity, this , &SwiftGuiStd::onChangedWindowOpacity); connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::identPressed, ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::setSelectedTransponderModeStateIdent); connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::textEntered, ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::handleGlobalCommandLineText); - connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::onMainInfoAreaChanged); connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::audioPressed, [ = ] { ui->comp_MainInfoArea->getCockpitComponent()->showAudio(); ui->comp_MainInfoArea->selectArea(CMainInfoAreaComponent::InfoAreaCockpit); }); + connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::onMainInfoAreaChanged); // menu connect(ui->menu_TestLocationsEDDF, &QAction::triggered, this, &SwiftGuiStd::onMenuClicked);