From d7a2fa3deab98d40b297ab3f5524c8b4e9f332b6 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 25 Sep 2014 20:54:08 +0100 Subject: [PATCH] refs #316 Swiftgui using CLogMessage to emit messages. --- src/swiftgui_standard/mainwindow.cpp | 21 +++++++++++---------- src/swiftgui_standard/mainwindow.h | 3 +++ src/swiftgui_standard/mainwindow_init.cpp | 6 +++--- src/swiftgui_standard/mainwindow_menus.cpp | 9 ++++----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/swiftgui_standard/mainwindow.cpp b/src/swiftgui_standard/mainwindow.cpp index ea8a6d0e4..70374a01e 100644 --- a/src/swiftgui_standard/mainwindow.cpp +++ b/src/swiftgui_standard/mainwindow.cpp @@ -17,6 +17,7 @@ #include "blackcore/context_application.h" #include "blackcore/network.h" #include "blackmisc/avaircraft.h" +#include "blackmisc/logmessage.h" #include using namespace BlackCore; @@ -229,7 +230,6 @@ bool MainWindow::isMainPageSelected(MainWindow::MainPageIndex mainPage) const */ void MainWindow::ps_toggleNetworkConnection() { - CStatusMessageList msgs; if (!this->isContextNetworkAvailableCheck()) return; if (!this->getIContextNetwork()->isConnected()) { @@ -251,14 +251,15 @@ void MainWindow::ps_toggleNetworkConnection() if (this->ui->comp_MainInfoArea->getSettingsComponent()->loginStealth()) { mode = INetwork::LoginStealth; - this->ps_displayStatusMessageInGui(CStatusMessage::getInfoMessage("login in stealth mode")); + this->ps_displayStatusMessageInGui(CLogMessage().info(this, "login in stealth mode")); } else if (this->ui->comp_MainInfoArea->getSettingsComponent()->loginAsObserver()) { mode = INetwork::LoginAsObserver; - this->ps_displayStatusMessageInGui(CStatusMessage::getInfoMessage("login in observer mode")); + this->ps_displayStatusMessageInGui(CLogMessage().info(this, "login in observer mode")); } - msgs = this->getIContextNetwork()->connectToNetwork(static_cast(mode)); + CStatusMessage msg = this->getIContextNetwork()->connectToNetwork(static_cast(mode)); + this->ps_displayStatusMessageInGui(msg); this->startUpdateTimersWhenConnected(); } else @@ -266,9 +267,9 @@ void MainWindow::ps_toggleNetworkConnection() // disconnect from network this->stopUpdateTimersWhenDisconnected(); // stop update timers, to avoid updates during disconnecting (a short time frame) if (this->m_contextAudioAvailable) this->getIContextAudio()->leaveAllVoiceRooms(); - msgs = this->getIContextNetwork()->disconnectFromNetwork(); + CStatusMessage msg = this->getIContextNetwork()->disconnectFromNetwork(); + this->ps_displayStatusMessageInGui(msg); } - if (!msgs.isEmpty()) this->ps_displayStatusMessagesInGui(msgs); } /* @@ -277,7 +278,7 @@ void MainWindow::ps_toggleNetworkConnection() bool MainWindow::isContextNetworkAvailableCheck() { if (this->m_contextNetworkAvailable) return true; - this->ps_displayStatusMessageInGui(CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityError, "Network context not available, no updates this time")); + this->ps_displayStatusMessageInGui(CLogMessage().error(this, "Network context not available, no updates this time")); return false; } @@ -287,7 +288,7 @@ bool MainWindow::isContextNetworkAvailableCheck() bool MainWindow::isContextAudioAvailableCheck() { if (this->m_contextAudioAvailable) return true; - this->ps_displayStatusMessageInGui(CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityError, "Voice context not available")); + this->ps_displayStatusMessageInGui(CLogMessage().error(this, "Voice context not available")); return false; } @@ -507,13 +508,13 @@ void MainWindow::ps_toogleWindowStayOnTop() { flags ^= Qt::WindowStaysOnTopHint; flags |= Qt::WindowStaysOnBottomHint; - this->ps_displayStatusMessageInGui(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityInfo, "Window on bottom")); + this->ps_displayStatusMessageInGui(CLogMessage().info(this, "Window on bottom")); } else { flags ^= Qt::WindowStaysOnBottomHint; flags |= Qt::WindowStaysOnTopHint; - this->ps_displayStatusMessageInGui(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityInfo, "Window on top")); + this->ps_displayStatusMessageInGui(CLogMessage().info(this, "Window on top")); } this->setWindowFlags(flags); this->show(); diff --git a/src/swiftgui_standard/mainwindow.h b/src/swiftgui_standard/mainwindow.h index a26121a64..59120d594 100644 --- a/src/swiftgui_standard/mainwindow.h +++ b/src/swiftgui_standard/mainwindow.h @@ -60,6 +60,9 @@ public: //! Graceful shutdown void gracefulShutdown(); + //! Log message category + static QString getMessageCategory() { return "swift.gui.component.mainwindow"; } + protected: //! Close event, e.g. when window is closed void closeEvent(QCloseEvent *event); diff --git a/src/swiftgui_standard/mainwindow_init.cpp b/src/swiftgui_standard/mainwindow_init.cpp index 870dab70c..ab74fa756 100644 --- a/src/swiftgui_standard/mainwindow_init.cpp +++ b/src/swiftgui_standard/mainwindow_init.cpp @@ -21,6 +21,7 @@ #include "blackmisc/avselcal.h" #include "blackmisc/project.h" #include "blackmisc/hotkeyfunction.h" +#include "blackmisc/logmessage.h" #include #include #include @@ -233,14 +234,13 @@ void MainWindow::initialDataReads() this->m_coreAvailable = (this->getIContextNetwork()->usingLocalObjects() || (this->getIContextApplication()->ping(t) == t)); if (!this->m_coreAvailable) { - this->ps_displayStatusMessageInGui(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityError, - "no initial data read as network context is not available")); + this->ps_displayStatusMessageInGui(CLogMessage().error(this, "no initial data read as network context is not available")); return; } this->ui->comp_MainInfoArea->getSettingsComponent()->reloadSettings(); // init read this->ps_reloadOwnAircraft(); // init read, independent of traffic network - this->ps_displayStatusMessageInGui(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityInfo, "initial data read")); + this->ps_displayStatusMessageInGui(CLogMessage().info(this, "initial data read")); } /* diff --git a/src/swiftgui_standard/mainwindow_menus.cpp b/src/swiftgui_standard/mainwindow_menus.cpp index ef4d90e91..a13e9f337 100644 --- a/src/swiftgui_standard/mainwindow_menus.cpp +++ b/src/swiftgui_standard/mainwindow_menus.cpp @@ -3,6 +3,7 @@ #include "blackgui/stylesheetutility.h" #include "blackmisc/statusmessagelist.h" #include "blackmisc/avaltitude.h" +#include "blackmisc/logmessage.h" #include #include #include @@ -20,7 +21,6 @@ using namespace BlackMisc::Aviation; void MainWindow::ps_onMenuClicked() { QObject *sender = QObject::sender(); - CStatusMessageList msgs; if (sender == this->ui->menu_TestLocationsEDRY) { @@ -41,7 +41,7 @@ void MainWindow::ps_onMenuClicked() else if (sender == this->ui->menu_ReloadSettings) { this->ui->comp_MainInfoArea->getSettingsComponent()->reloadSettings(); - msgs.insert(CStatusMessage::getInfoMessage("Settings reloaded")); + this->ps_displayStatusMessageInGui(CLogMessage().info(this, "Settings reloaded")); } else if (sender == this->ui->menu_FileReloadStyleSheets) { @@ -54,7 +54,7 @@ void MainWindow::ps_onMenuClicked() } else if (sender == this->ui->menu_FileClose) { - msgs.insert(CStatusMessage::getInfoMessage("Closing")); + this->ps_displayStatusMessageInGui(CLogMessage().info(this, "Closing")); this->close(); } else if (sender == this->ui->menu_FileSettingsDirectory) @@ -65,7 +65,6 @@ void MainWindow::ps_onMenuClicked() else if (sender == this->ui->menu_FileResetSettings) { Q_ASSERT(this->getIContextSettings()); - msgs.insert(this->getIContextSettings()->reset(true)); + this->getIContextSettings()->reset(true); } - if (!msgs.isEmpty()) this->ps_displayStatusMessagesInGui(msgs); }