From d15d0db431345be048fe60296d789c2f169621c6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 8 Jan 2014 00:09:03 +0000 Subject: [PATCH] post-voice changes in blackgui from the kbatclist branch refs #81 --- samples/blackgui/mainwindow.cpp | 195 +++---- samples/blackgui/mainwindow.h | 68 ++- samples/blackgui/mainwindow.ui | 636 ++++++++++++++++------- samples/blackgui/mainwindow_aircraft.cpp | 75 +++ samples/blackgui/mainwindow_atc.cpp | 92 ++++ samples/blackgui/mainwindow_cockpit.cpp | 57 ++ samples/blackgui/mainwindow_init.cpp | 10 + samples/blackgui/mainwindow_voice.cpp | 79 +++ src/blackgui/userlistmodel.cpp | 27 + src/blackgui/userlistmodel.h | 31 ++ 10 files changed, 959 insertions(+), 311 deletions(-) create mode 100644 samples/blackgui/mainwindow_aircraft.cpp create mode 100644 samples/blackgui/mainwindow_atc.cpp create mode 100644 samples/blackgui/mainwindow_voice.cpp create mode 100644 src/blackgui/userlistmodel.cpp create mode 100644 src/blackgui/userlistmodel.h diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 8cff9d0b4..c413ac3b4 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -12,6 +12,7 @@ using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Geo; using namespace BlackMisc::Settings; +using namespace BlackMisc::Voice; /* * Constructor @@ -19,11 +20,16 @@ using namespace BlackMisc::Settings; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_init(false), m_withDBus(true), + m_coreAvailable(false), m_contextNetworkAvailable(false), m_contextVoiceAvailable(false), m_dBusConnection("dummy"), m_coreRuntime(nullptr), - m_atcListOnline(nullptr), m_atcListBooked(nullptr), m_trafficServerList(nullptr), m_aircraftsInRange(nullptr), - m_contextNetwork(nullptr), m_contextSettings(nullptr), - m_ownAircraft(), - m_timerUpdateAtcStationsOnline(nullptr), m_timerUpdateAircraftsInRange(nullptr), m_timerContextWatchdog(nullptr), m_timerCollectedCockpitUpdates(nullptr) + m_atcListOnline(nullptr), m_atcListBooked(nullptr), + m_trafficServerList(nullptr), m_aircraftsInRange(nullptr), + m_contextApplication(nullptr), + m_contextNetwork(nullptr), m_contextVoice(nullptr), + m_contextSettings(nullptr), + m_ownAircraft(), m_voiceRoomCom1(), m_voiceRoomCom2(), + m_timerUpdateAtcStationsOnline(nullptr), m_timerUpdateAircraftsInRange(nullptr), + m_timerCollectedCockpitUpdates(nullptr), m_timerContextWatchdog(nullptr) { ui->setupUi(this); } @@ -51,6 +57,11 @@ void MainWindow::gracefulShutdown() this->m_contextNetwork->disconnectFromNetwork(); } + if (this->m_contextVoiceAvailable) + { + this->m_contextVoice->leaveAllVoiceRooms(); + } + if (this->m_timerUpdateAircraftsInRange) { this->m_timerUpdateAircraftsInRange->disconnect(this); @@ -71,7 +82,6 @@ void MainWindow::gracefulShutdown() this->m_timerCollectedCockpitUpdates->disconnect(this); this->m_timerCollectedCockpitUpdates->stop(); } - } /* @@ -102,52 +112,6 @@ void MainWindow::setMainPage(bool start) this->ui->sw_MainMiddle->setCurrentIndex(6); } -/* - * Read stations - */ -void MainWindow::reloadAtcStationsBooked() -{ - if (!this->isContextNetworkAvailableCheck()) return; - this->m_atcListBooked->update(this->m_contextNetwork->getAtcStationsBooked()); - this->ui->tv_AtcStationsBooked->resizeColumnsToContents(); -} - -/* - * Read stations - */ -void MainWindow::reloadAtcStationsOnline() -{ - if (!this->isContextNetworkAvailableCheck()) return; - this->m_atcListOnline->update(this->m_contextNetwork->getAtcStationsOnline()); - this->ui->tv_AtcStationsOnline->resizeColumnsToContents(); -} - -/* - * Read aircrafts - */ -void MainWindow::reloadAircraftsInRange() -{ - if (!this->isContextNetworkAvailableCheck()) return; - this->m_aircraftsInRange->update(this->m_contextNetwork->getAircraftsInRange()); - this->ui->tv_AircraftsInRange->resizeColumnsToContents(); -} - -/* - * Read own aircraft - */ -bool MainWindow::reloadOwnAircraft() -{ - if (!this->isContextNetworkAvailableCheck()) return false; - if (this->isCockpitUpdatePending()) return false; - CAircraft loadedAircraft = this->m_contextNetwork->getOwnAircraft(); - if (loadedAircraft == this->m_ownAircraft) return false; - - // changed aircraft - this->m_ownAircraft = loadedAircraft; - this->updateCockpitFromContext(); - return true; -} - /* * Connect to Network */ @@ -170,6 +134,7 @@ void MainWindow::toggleNetworkConnection() else { msgs = this->m_contextNetwork->disconnectFromNetwork(); + this->m_contextVoice->leaveAllVoiceRooms(); } if (!msgs.isEmpty()) this->displayStatusMessages(msgs); } @@ -184,6 +149,16 @@ bool MainWindow::isContextNetworkAvailableCheck() return false; } +/* + * Is the voice context available? + */ +bool MainWindow::isContextVoiceAvailableCheck() +{ + if (this->m_contextVoiceAvailable) return true; + this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityError, "Voice context not available")); + return false; +} + /* * Display a status message */ @@ -265,30 +240,8 @@ void MainWindow::connectionStatusChanged(uint /** from **/, uint to) } /* - * Station selected - */ -void MainWindow::onlineAtcStationSelected(QModelIndex index) -{ - this->ui->te_AtcStationsOnlineInfo->setText(""); // reset - const CAtcStation stationClicked = this->m_atcListOnline->at(index); - QString infoMessage; - - if (stationClicked.hasAtis()) - { - infoMessage.append(stationClicked.getAtis().getMessage()); - } - if (stationClicked.hasMetar()) - { - if (!infoMessage.isEmpty()) infoMessage.append("\n\n"); - infoMessage.append(stationClicked.getMetar().getMessage()); - } - - this->ui->te_AtcStationsOnlineInfo->setText(infoMessage); -} - -/* - * Timer event - */ +* Timer event +*/ void MainWindow::updateTimer() { QObject *sender = QObject::sender(); @@ -308,8 +261,7 @@ void MainWindow::updateTimer() } else if (sender == this->m_timerContextWatchdog) { - qint64 t = QDateTime::currentMSecsSinceEpoch(); - m_contextNetworkAvailable = (this->m_contextNetwork->usingLocalObjects() || (this->m_contextNetwork->ping(t) == t)); + this->setContextAvailability(); this->updateGuiStatusInformation(); } @@ -321,43 +273,19 @@ void MainWindow::updateTimer() } /* - * Get METAR - */ -void MainWindow::getMetar(const QString &airportIcaoCode) +* Context availability +*/ +void MainWindow::setContextAvailability() { - if (!this->isContextNetworkAvailableCheck()) return; - if (!this->m_contextNetwork->isConnected()) return; - QString icao = airportIcaoCode.isEmpty() ? this->ui->le_AtcStationsOnlineMetar->text().trimmed().toUpper() : airportIcaoCode.trimmed().toUpper(); - this->ui->le_AtcStationsOnlineMetar->setText(icao); - if (icao.length() != 4) return; - CInformationMessage metar = this->m_contextNetwork->getMetar(icao); - if (metar.getType() != CInformationMessage::METAR) return; - if (metar.isEmpty()) return; - this->ui->te_AtcStationsOnlineInfo->setText(metar.getMessage()); + qint64 t = QDateTime::currentMSecsSinceEpoch(); + this->m_coreAvailable = this->m_contextApplication->ping(t) == t; + this->m_contextNetworkAvailable = this->m_coreAvailable || this->m_contextNetwork->usingLocalObjects(); + this->m_contextVoiceAvailable = this->m_coreAvailable || this->m_contextVoice->usingLocalObjects(); } /* - * ATC station tab changed are changed - */ -void MainWindow::atcStationTabChanged(int /** tabIndex **/) -{ - if (this->isContextNetworkAvailableCheck()) - { - if (this->ui->tw_AtcStations->currentWidget() == this->ui->tb_AtcStationsBooked) - { - if (this->m_atcListBooked->rowCount() < 1) - this->reloadAtcStationsBooked(); - } - else if (this->ui->tw_AtcStations->currentWidget() == this->ui->tb_AtcStationsOnline) - { - this->reloadAtcStationsOnline(); - } - } -} - -/* - * Middle panel changed - */ +* Middle panel changed +*/ void MainWindow::middlePanelChanged(int /* index */) { if (this->isContextNetworkAvailableCheck()) @@ -373,32 +301,39 @@ void MainWindow::middlePanelChanged(int /* index */) } /* - * Update GUI - */ +* Update GUI +*/ void MainWindow::updateGuiStatusInformation() { + const QString now = QDateTime::currentDateTimeUtc().toString("yyyy - MM - dd HH: mm: ss"); + QString network("unavailable"); if (this->m_contextNetworkAvailable) { - const QString now = QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd HH:mm:ss"); - this->ui->le_networkContextAvailable->setText( - this->m_contextNetwork->usingLocalObjects() ? "local" : - now); - if (this->m_contextNetwork->isConnected()) - { - this->ui->pb_MainConnect->setText("Disconnect"); - this->ui->pb_MainConnect->setStyleSheet("background-color: green"); - if (!this->ui->le_StatusNetworkConnected->text().startsWith("2")) - this->ui->le_StatusNetworkConnected->setText(now); - } - else - { - this->ui->pb_MainConnect->setText("Connect"); - this->ui->pb_MainConnect->setStyleSheet("background-color:"); - this->ui->le_StatusNetworkConnected->setText("Disconnected"); - } + network = this->m_contextNetwork->usingLocalObjects() ? "local" : now; + } + + QString voice("unavailable"); + if (this->m_contextVoiceAvailable) + { + voice = this->m_contextVoice->usingLocalObjects() ? "local" : now; + } + + this->ui->le_StatusNetworkContext->setText(network); + this->ui->le_StatusVoiceContext->setText(voice); + this->ui->cb_StatusWithDBus->setCheckState(this->m_withDBus ? Qt::Checked : Qt::Unchecked); + + // Connected button + if (this->m_contextNetworkAvailable && this->m_contextNetwork->isConnected()) + { + this->ui->pb_MainConnect->setText("Disconnect"); + this->ui->pb_MainConnect->setStyleSheet("background-color: green"); + if (!this->ui->le_StatusNetworkConnected->text().startsWith("2")) + this->ui->le_StatusNetworkConnected->setText(now); } else { - this->ui->le_networkContextAvailable->setText("Not available"); + this->ui->pb_MainConnect->setText("Connect"); + this->ui->pb_MainConnect->setStyleSheet("background-color: "); + this->ui->le_StatusNetworkConnected->setText("Disconnected"); } } diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index f2d99c202..1fd8eec02 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -10,8 +10,10 @@ #include "blackgui/aircraftlistmodel.h" #include "blackmisc/statusmessage.h" #include "blackmisc/nwtextmessage.h" +#include "blackcore/context_voice.h" #include "blackcore/context_network_interface.h" #include "blackcore/context_settings_interface.h" +#include "blackcore/context_application_interface.h" #include "blackcore/coreruntime.h" #include #include @@ -57,20 +59,26 @@ private: Ui::MainWindow *ui; bool m_init; bool m_withDBus; + bool m_coreAvailable; bool m_contextNetworkAvailable; + bool m_contextVoiceAvailable; QDBusConnection m_dBusConnection; BlackCore::CCoreRuntime *m_coreRuntime; /*!< runtime, if working with local core */ BlackGui::CAtcListModel *m_atcListOnline; BlackGui::CAtcListModel *m_atcListBooked; BlackGui::CServerListModel *m_trafficServerList; BlackGui::CAircraftListModel *m_aircraftsInRange; + BlackCore::IContextApplication *m_contextApplication; /*!< overall application state */ BlackCore::IContextNetwork *m_contextNetwork; + BlackCore::IContextVoice *m_contextVoice; BlackCore::IContextSettings *m_contextSettings; - BlackMisc::Aviation::CAircraft m_ownAircraft; - QTimer *m_timerUpdateAtcStationsOnline; - QTimer *m_timerUpdateAircraftsInRange; - QTimer *m_timerCollectedCockpitUpdates; - QTimer *m_timerContextWatchdog; + BlackMisc::Aviation::CAircraft m_ownAircraft; /*!< own aircraft's state */ + BlackMisc::Voice::CVoiceRoom m_voiceRoomCom1; + BlackMisc::Voice::CVoiceRoom m_voiceRoomCom2; + QTimer *m_timerUpdateAtcStationsOnline; /*!< update stations */ + QTimer *m_timerUpdateAircraftsInRange; /*!< update aircrafts */ + QTimer *m_timerCollectedCockpitUpdates; /*!< collect cockpit updates over a short period before sending */ + QTimer *m_timerContextWatchdog; /*!< core available? */ /*! * \brief GUI status update @@ -95,11 +103,17 @@ private: void initialDataReads(); /*! - * \brief Context network available check, otherwise status message + * \brief Context network availability check, otherwise status message * \return */ bool isContextNetworkAvailableCheck(); + /*! + * \brief Context voice availability check, otherwise status message + * \return + */ + bool isContextVoiceAvailableCheck(); + /*! * \brief Own cockpit, update from context */ @@ -138,6 +152,25 @@ private: */ BlackMisc::Network::CTextMessage getTextMessageStubForChannel(); + /*! + * \brief Audio device lists + * \return + */ + void setAudioDeviceLists(); + + /*! + * \brief Context availability, used by watchdog + */ + void setContextAvailability(); + + /*! + * \brief Position of own plane for testing + * \param wgsLatitude + * \param wgsLongitude + * \param altitude + */ + void setTestPosition(const QString &wgsLatitude, const QString &wgsLongitude, const BlackMisc::Aviation::CAltitude &altitude); + private slots: // @@ -175,7 +208,7 @@ private slots: * \brief Display status messages * \param messages */ - void displayStatusMessages(const BlackMisc::CStatusMessages &messages); + void displayStatusMessages(const BlackMisc::CStatusMessageList &messages); /*! * \brief Connection status changed @@ -287,6 +320,27 @@ private slots: */ void cockpitValuesChanged(); + /*! + * \brief Audio device selected + * \param index + */ + void audioDeviceSelected(int index); + + /*! + * \brief Reset transponder to standby + */ + void resetTransponderModerToStandby(); + + /*! + * \brief Reset transponder to Charly + */ + void resetTransponderModerToCharly(); + + /*! + * \brief Override voice room + */ + void voiceRoomOverride(); + }; #pragma pop_macro("interface") diff --git a/samples/blackgui/mainwindow.ui b/samples/blackgui/mainwindow.ui index 1d5f7a040..a0270aedf 100644 --- a/samples/blackgui/mainwindow.ui +++ b/samples/blackgui/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 600 + 615 541 @@ -160,11 +160,24 @@ - - - + + + + + true + + + + + - Network connected + DBus + + + true + + + false @@ -175,6 +188,27 @@ + + + + true + + + + + + + Voice context + + + + + + + Network connected + + + @@ -182,13 +216,6 @@ - - - - true - - - @@ -591,144 +618,10 @@ - + 3 - - - - false - - - 3 - - - 118.000000000000000 - - - 136.000000000000000 - - - 0.250000000000000 - - - 118.250000000000000 - - - - - - - 0 - - - 7777.000000000000000 - - - 7000.000000000000000 - - - - - - - - 75 - 16777215 - - - - 3 - - - 118.000000000000000 - - - 136.000000000000000 - - - 0.250000000000000 - - - 118.000000000000000 - - - - - - - - 12 - - - - COM 2 - - - - - - - - 12 - - - - Transponder - - - - - - - - 12 - - - - COM 1 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 50 - 16777215 - - - - - S - - - - - C - - - - - I - - - - @@ -760,6 +653,31 @@ + + + + + 50 + 16777215 + + + + + S + + + + + C + + + + + I + + + + @@ -779,6 +697,174 @@ + + + + + 12 + + + + Transponder + + + + + + + + 12 + + + + COM 1 + + + + + + + + 12 + + + + COM 2 + + + + + + + false + + + 3 + + + 118.000000000000000 + + + 136.000000000000000 + + + 0.250000000000000 + + + 118.250000000000000 + + + + + + + + 75 + 16777215 + + + + 3 + + + 118.000000000000000 + + + 136.000000000000000 + + + 0.250000000000000 + + + 118.000000000000000 + + + + + + + 0 + + + 7777.000000000000000 + + + 7000.000000000000000 + + + + + + + + + + + + + + + + + + 2 + + + 2 + + + + + + 7 + + + + true + + + + + + + Ovr. + + + + + + + + + + + 2 + + + 2 + + + + + + 7 + + + + true + + + + + + + Ovr. + + + + + + @@ -1002,14 +1088,14 @@ - + Real name - + @@ -1086,22 +1172,56 @@ - + - Whatsoever + Voice + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + In + + + + + + + + + + Out + + + + + + + + + + + + + Aircraft - + - + Callsign - + BLACK @@ -1228,7 +1348,7 @@ 0 0 - 600 + 615 21 @@ -1243,6 +1363,7 @@ + @@ -1266,17 +1387,17 @@ - Position EDDF + Position EDDF (Frankfurt, GER) - Position EDDM + Position EDDM (Munich, GER) - Position EDRY + Position EDRY (Speyer, GER) @@ -1284,6 +1405,11 @@ Reload settings + + + Position EDNX (Schleißheim, GER) + + @@ -1503,8 +1629,8 @@ reloadAtcStationsBooked() - 178 - 110 + 175 + 72 2 @@ -1519,8 +1645,8 @@ onlineAtcStationSelected(QModelIndex) - 253 - 116 + 174 + 50 -1 @@ -1583,8 +1709,8 @@ commandEntered() - 176 - 73 + 166 + 63 4 @@ -1599,8 +1725,8 @@ getMetar() - 374 - 491 + 145 + 71 20 @@ -1615,8 +1741,8 @@ getMetar() - 338 - 491 + 118 + 71 341 @@ -1631,8 +1757,8 @@ cockpitValuesChanged() - 370 - 55 + 449 + 73 337 @@ -1663,8 +1789,8 @@ cockpitValuesChanged() - 379 - 88 + 449 + 96 253 @@ -1711,8 +1837,8 @@ cockpitValuesChanged() - 385 - 103 + 449 + 119 1 @@ -1720,6 +1846,166 @@ + + cb_VoiceOutputDevice + currentIndexChanged(int) + MainWindow + audioDeviceSelected(int) + + + 166 + 63 + + + 2 + 316 + + + + + cb_VoiceOutputDevice + currentIndexChanged(int) + MainWindow + audioDeviceSelected(int) + + + 166 + 63 + + + 20 + 379 + + + + + cb_VoiceInputDevice + currentIndexChanged(int) + MainWindow + audioDeviceSelected(int) + + + 166 + 55 + + + 26 + 355 + + + + + menu_TestLocationsEDNX + triggered() + MainWindow + menuClicked() + + + -1 + -1 + + + 307 + 270 + + + + + menu_TestLocationsEDDF + triggered() + MainWindow + menuClicked() + + + -1 + -1 + + + 307 + 270 + + + + + menu_TestLocationsEDDM + triggered() + MainWindow + menuClicked() + + + -1 + -1 + + + 307 + 270 + + + + + le_CockpitVoiceRoomCom1 + returnPressed() + MainWindow + voiceRoomOverride() + + + 232 + 64 + + + 40 + 388 + + + + + le_CockpitVoiceRoomCom2 + returnPressed() + MainWindow + voiceRoomOverride() + + + 253 + 82 + + + 70 + 304 + + + + + cb_CockpitVoiceRoom2Override + clicked() + MainWindow + voiceRoomOverride() + + + 346 + 91 + + + 559 + 412 + + + + + cb_CockpitVoiceRoom1Override + clicked() + MainWindow + voiceRoomOverride() + + + 368 + 61 + + + 587 + 340 + + + setMainPage() @@ -1732,5 +2018,7 @@ commandEntered() getMetar() cockpitValuesChanged() + audioDeviceSelected(int) + voiceRoomOverride() diff --git a/samples/blackgui/mainwindow_aircraft.cpp b/samples/blackgui/mainwindow_aircraft.cpp new file mode 100644 index 000000000..a4af91159 --- /dev/null +++ b/samples/blackgui/mainwindow_aircraft.cpp @@ -0,0 +1,75 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "blackgui/atcstationlistmodel.h" +#include "blackcore/dbus_server.h" +#include "blackcore/context_network.h" + +using namespace BlackCore; +using namespace BlackMisc; +using namespace BlackGui; +using namespace BlackMisc::Network; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Settings; +using namespace BlackMisc::Voice; + +/* + * Read aircrafts + */ +void MainWindow::reloadAircraftsInRange() +{ + if (!this->isContextNetworkAvailableCheck()) return; + this->m_aircraftsInRange->update(this->m_contextNetwork->getAircraftsInRange()); + this->ui->tv_AircraftsInRange->resizeColumnsToContents(); +} + +/* + * Read own aircraft + */ +bool MainWindow::reloadOwnAircraft() +{ + if (!this->isContextNetworkAvailableCheck()) return false; + if (this->isCockpitUpdatePending()) return false; + CAircraft loadedAircraft = this->m_contextNetwork->getOwnAircraft(); + + // changed aircraft + if (loadedAircraft == this->m_ownAircraft) return false; + this->m_ownAircraft = loadedAircraft; + + // update voice rooms + if (this->m_contextVoiceAvailable) + { + CVoiceRoomList selectedRooms = this->m_contextNetwork->getSelectedVoiceRooms(); + this->m_voiceRoomCom1 = this->ui->cb_CockpitVoiceRoom1Override->isChecked() ? + this->ui->le_CockpitVoiceRoomCom1->text().trimmed() : + selectedRooms[0]; + this->m_voiceRoomCom2 = this->ui->cb_CockpitVoiceRoom2Override->isChecked() ? + this->ui->le_CockpitVoiceRoomCom2->text().trimmed() : + selectedRooms[1]; + } + + // + this->updateCockpitFromContext(); + + // something has changed + return true; +} + +/* +* Position +*/ +void MainWindow::setTestPosition(const QString &wgsLatitude, const QString &wgsLongitude, const CAltitude &altitude) +{ + CCoordinateGeodetic coordinate( + CLatitude::fromWgs84(wgsLatitude), + CLongitude::fromWgs84(wgsLongitude), + CLength(0, CLengthUnit::m())); + + this->m_ownAircraft.setPosition(coordinate); + this->m_ownAircraft.setAltitude(altitude); + this->m_contextNetwork->updateOwnPosition( + coordinate, + altitude + ); +} diff --git a/samples/blackgui/mainwindow_atc.cpp b/samples/blackgui/mainwindow_atc.cpp new file mode 100644 index 000000000..57717d9d0 --- /dev/null +++ b/samples/blackgui/mainwindow_atc.cpp @@ -0,0 +1,92 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "blackgui/atcstationlistmodel.h" +#include "blackcore/dbus_server.h" +#include "blackcore/context_network.h" + +using namespace BlackCore; +using namespace BlackMisc; +using namespace BlackGui; +using namespace BlackMisc::Network; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Settings; + + +/* + * Read booked stations + */ +void MainWindow::reloadAtcStationsBooked() +{ + if (!this->isContextNetworkAvailableCheck()) return; + this->m_atcListBooked->update(this->m_contextNetwork->getAtcStationsBooked()); + this->ui->tv_AtcStationsBooked->resizeColumnsToContents(); +} + +/* + * Read online stations + */ +void MainWindow::reloadAtcStationsOnline() +{ + if (!this->isContextNetworkAvailableCheck()) return; + this->m_atcListOnline->update(this->m_contextNetwork->getAtcStationsOnline()); + this->ui->tv_AtcStationsOnline->resizeColumnsToContents(); +} + +/* + * Station selected + */ +void MainWindow::onlineAtcStationSelected(QModelIndex index) +{ + this->ui->te_AtcStationsOnlineInfo->setText(""); // reset + const CAtcStation stationClicked = this->m_atcListOnline->at(index); + QString infoMessage; + + if (stationClicked.hasAtis()) + { + infoMessage.append(stationClicked.getAtis().getMessage()); + } + if (stationClicked.hasMetar()) + { + if (!infoMessage.isEmpty()) infoMessage.append("\n\n"); + infoMessage.append(stationClicked.getMetar().getMessage()); + } + + this->ui->te_AtcStationsOnlineInfo->setText(infoMessage); +} + +/* + * Get METAR + */ +void MainWindow::getMetar(const QString &airportIcaoCode) +{ + if (!this->isContextNetworkAvailableCheck()) return; + if (!this->m_contextNetwork->isConnected()) return; + QString icao = airportIcaoCode.isEmpty() ? this->ui->le_AtcStationsOnlineMetar->text().trimmed().toUpper() : airportIcaoCode.trimmed().toUpper(); + this->ui->le_AtcStationsOnlineMetar->setText(icao); + if (icao.length() != 4) return; + CInformationMessage metar = this->m_contextNetwork->getMetar(icao); + if (metar.getType() != CInformationMessage::METAR) return; + if (metar.isEmpty()) return; + this->ui->te_AtcStationsOnlineInfo->setText(metar.getMessage()); +} + +/* + * ATC station tab changed are changed + */ +void MainWindow::atcStationTabChanged(int /** tabIndex **/) +{ + if (this->isContextNetworkAvailableCheck()) + { + if (this->ui->tw_AtcStations->currentWidget() == this->ui->tb_AtcStationsBooked) + { + if (this->m_atcListBooked->rowCount() < 1) + this->reloadAtcStationsBooked(); + } + else if (this->ui->tw_AtcStations->currentWidget() == this->ui->tb_AtcStationsOnline) + { + this->reloadAtcStationsOnline(); + } + } +} diff --git a/samples/blackgui/mainwindow_cockpit.cpp b/samples/blackgui/mainwindow_cockpit.cpp index 264959159..cb8577e16 100644 --- a/samples/blackgui/mainwindow_cockpit.cpp +++ b/samples/blackgui/mainwindow_cockpit.cpp @@ -86,6 +86,34 @@ void MainWindow::updateCockpitFromContext() break; } + // + // voice + // + if (!this->ui->cb_CockpitVoiceRoom1Override->isChecked()) + { + if (!this->ui->cb_CockpitVoiceRoom1Override->isChecked() && this->m_voiceRoomCom1.isValid()) + { + QString s(this->m_voiceRoomCom1.isConnected() ? "*" : ""); + s.append(this->m_voiceRoomCom1.getVoiceRoomUrl()); + this->ui->le_CockpitVoiceRoomCom1->setText(s); + } + else + this->ui->le_CockpitVoiceRoomCom1->setText(""); + } + + if (!this->ui->cb_CockpitVoiceRoom2Override->isChecked()) + { + if (this->m_voiceRoomCom2.isValid()) + { + QString s(this->m_voiceRoomCom2.isConnected() ? "*" : ""); + s.append(this->m_voiceRoomCom2.getVoiceRoomUrl()); + this->ui->le_CockpitVoiceRoomCom2->setText(s); + } + else + this->ui->le_CockpitVoiceRoomCom2->setText(""); + } +} + /* * Reset transponder mode to Standby */ @@ -164,4 +192,33 @@ void MainWindow::sendCockpitUpdates() changedCockpit = true; } } + + // + // Now with the new voice room data, really set the + // voice rooms in the context + // + if (changedCockpit && this->m_contextVoiceAvailable) + { + // set voice rooms here, this allows to use local/remote + // voice context + this->m_contextVoice->setComVoiceRooms(this->m_voiceRoomCom1, this->m_voiceRoomCom2); + } +} + +/* + * Voice room override + */ +void MainWindow::voiceRoomOverride() +{ + this->ui->le_CockpitVoiceRoomCom1->setReadOnly(!this->ui->cb_CockpitVoiceRoom1Override->isChecked()); + this->ui->le_CockpitVoiceRoomCom2->setReadOnly(!this->ui->cb_CockpitVoiceRoom2Override->isChecked()); + if (this->ui->cb_CockpitVoiceRoom1Override->isChecked()) + { + this->m_voiceRoomCom1 = this->ui->cb_CockpitVoiceRoom1Override->text().trimmed(); + } + + if (this->ui->cb_CockpitVoiceRoom2Override->isChecked()) + { + this->m_voiceRoomCom2 = this->ui->cb_CockpitVoiceRoom2Override->text().trimmed(); + } } diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 15850f90e..59ae0f830 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -62,13 +62,17 @@ void MainWindow::init(bool withDBus) { this->m_dBusConnection = QDBusConnection::sessionBus(); this->m_contextNetwork = new BlackCore::IContextNetwork(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); + this->m_contextVoice = new BlackCore::IContextVoice(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextSettings = new BlackCore::IContextSettings(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); + this->m_contextApplication = new BlackCore::IContextApplication(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); } else { this->m_coreRuntime = new CCoreRuntime(false, this); this->m_contextNetwork = this->m_coreRuntime->getIContextNetwork(); + this->m_contextVoice = this->m_coreRuntime->getIContextVoice(); this->m_contextSettings = this->m_coreRuntime->getIContextSettings(); + this->m_contextApplication = this->m_coreRuntime->getIContextApplication(); } // relay status messages @@ -127,6 +131,12 @@ void MainWindow::init(bool withDBus) this->m_timerUpdateAtcStationsOnline->start(10 * 1000); this->m_timerContextWatchdog->start(2 * 1000); + // init availability + this->setContextAvailability(); + + // voice panel + this->setAudioDeviceLists(); + // data this->initialDataReads(); diff --git a/samples/blackgui/mainwindow_voice.cpp b/samples/blackgui/mainwindow_voice.cpp new file mode 100644 index 000000000..c9d6193dc --- /dev/null +++ b/samples/blackgui/mainwindow_voice.cpp @@ -0,0 +1,79 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "blackgui/atcstationlistmodel.h" +#include "blackcore/dbus_server.h" +#include "blackcore/context_network.h" +#include "blackcore/context_voice.h" + +using namespace BlackCore; +using namespace BlackMisc; +using namespace BlackGui; +using namespace BlackMisc::Network; +using namespace BlackMisc::Voice; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Settings; +using namespace BlackMisc::Math; + +/* + * Set audio device lists + */ +void MainWindow::setAudioDeviceLists() +{ + if (!this->isContextVoiceAvailableCheck()) return; + this->ui->cb_VoiceOutputDevice->clear(); + this->ui->cb_VoiceInputDevice->clear(); + + foreach(CAudioDevice device, this->m_contextVoice->getAudioDevices()) + { + if (device.getType() == CAudioDevice::InputDevice) + { + this->ui->cb_VoiceInputDevice->addItem(device.toQString(true)); + } + else if (device.getType() == CAudioDevice::OutputDevice) + { + this->ui->cb_VoiceOutputDevice->addItem(device.toQString(true)); + } + } + + foreach(CAudioDevice device, this->m_contextVoice->getCurrentAudioDevices()) + { + if (device.getType() == CAudioDevice::InputDevice) + { + this->ui->cb_VoiceInputDevice->setCurrentText(device.toQString(true)); + } + else if (device.getType() == CAudioDevice::OutputDevice) + { + this->ui->cb_VoiceOutputDevice->setCurrentText(device.toQString(true)); + } + } +} + +/* + * Select audio device + */ +void MainWindow::audioDeviceSelected(int index) +{ + if (!this->m_init) return; // not during init + if (!this->isContextVoiceAvailableCheck()) return; + if (index < 0)return; + CAudioDeviceList devices = this->m_contextVoice->getAudioDevices(); + if (devices.isEmpty()) return; + CAudioDevice selectedDevice; + QObject *sender = QObject::sender(); + if (sender == this->ui->cb_VoiceInputDevice) + { + CAudioDeviceList inputDevices = devices.getInputDevices(); + if (index >= inputDevices.size()) return; + selectedDevice = inputDevices[index]; + this->m_contextVoice->setCurrentAudioDevice(selectedDevice); + } + else if (sender == this->ui->cb_VoiceOutputDevice) + { + CAudioDeviceList outputDevices = devices.getOutputDevices(); + if (index >= outputDevices.size()) return; + selectedDevice = outputDevices[index]; + this->m_contextVoice->setCurrentAudioDevice(selectedDevice); + } +} diff --git a/src/blackgui/userlistmodel.cpp b/src/blackgui/userlistmodel.cpp new file mode 100644 index 000000000..844a52df8 --- /dev/null +++ b/src/blackgui/userlistmodel.cpp @@ -0,0 +1,27 @@ +#include "userlistmodel.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include + +using namespace BlackMisc::Network; + +namespace BlackGui +{ + /* + * Constructor + */ + CUserListModel::CUserListModel(QObject *parent) : + CListModelBase("ViewUserList", parent) + { + this->m_columns.addColumn(CUser::IndexId, "id"); + this->m_columns.addColumn(CUser::IndexRealName, "realname"); + this->m_columns.addColumn(CUser::IndexId, "userid"); + this->m_columns.addColumn(CUser::IndexEmail, "email"); + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewUserList", "id"); + (void)QT_TRANSLATE_NOOP("ViewUserList", "realname"); + (void)QT_TRANSLATE_NOOP("ViewUserList", "userid"); + (void)QT_TRANSLATE_NOOP("ViewUserList", "email"); + } +} diff --git a/src/blackgui/userlistmodel.h b/src/blackgui/userlistmodel.h new file mode 100644 index 000000000..da8010c65 --- /dev/null +++ b/src/blackgui/userlistmodel.h @@ -0,0 +1,31 @@ +#ifndef BLACKGUI_USERLISTMODEL_H +#define BLACKGUI_USERLISTMODEL_H + +#include +#include +#include "blackmisc/nwuserlist.h" +#include "blackgui/listmodelbase.h" + +namespace BlackGui +{ + /*! + * \brief Server list model + */ + class CUserListModel : public CListModelBase + { + + public: + + /*! + * \brief Constructor + * \param parent + */ + explicit CUserListModel(QObject *parent = nullptr); + + /*! + * \brief Destructor + */ + virtual ~CUserListModel() {} + }; +} +#endif // guard