From 83254e97aa439ce8905eaab58514e1b04cbd5f67 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 19 Jul 2019 03:13:33 +0200 Subject: [PATCH] Ref T659, network details component for FSD/voice setup --- .../components/networkdetailscomponent.cpp | 186 ++++++++ .../components/networkdetailscomponent.h | 85 +++- .../components/networkdetailscomponent.ui | 433 ++++++++++++++---- 3 files changed, 615 insertions(+), 89 deletions(-) diff --git a/src/blackgui/components/networkdetailscomponent.cpp b/src/blackgui/components/networkdetailscomponent.cpp index 0a8d2a94f..e438ae7d1 100644 --- a/src/blackgui/components/networkdetailscomponent.cpp +++ b/src/blackgui/components/networkdetailscomponent.cpp @@ -8,10 +8,17 @@ #include "networkdetailscomponent.h" #include "ui_networkdetailscomponent.h" +#include "blackgui/uppercasevalidator.h" +#include "blackgui/guiapplication.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/webdataservices.h" + +#include using namespace BlackMisc::Network; using namespace BlackMisc::Audio; using namespace BlackCore; +using namespace BlackCore::Data; namespace BlackGui { @@ -22,6 +29,44 @@ namespace BlackGui ui(new Ui::CNetworkDetailsComponent) { ui->setupUi(this); + ui->tw_Details->setCurrentIndex(0); + ui->sw_NetworkServerDetails->setCurrentIndex(PageServer); + + connect(ui->comp_OtherServers, &CServerListSelector::serverChanged, this, &CNetworkDetailsComponent::onSelectedServerChanged); + connect(ui->comp_VatsimServers, &CServerListSelector::serverChanged, this, &CNetworkDetailsComponent::onSelectedServerChanged); + connect(ui->tw_Network, &QTabWidget::currentChanged, this, &CNetworkDetailsComponent::onServerTabWidgetChanged); + connect(ui->tw_Details, &QTabWidget::currentChanged, this, &CNetworkDetailsComponent::onDetailsTabChanged); + connect(ui->pb_OtherServersGotoSettings, &QPushButton::pressed, this, &CNetworkDetailsComponent::requestNetworkSettings); + connect(ui->pb_OverrideCredentialsVatsim, &QPushButton::clicked, this, &CNetworkDetailsComponent::onOverrideCredentialsToPilot); + connect(ui->pb_OverrideCredentialsOtherServers, &QPushButton::clicked, this, &CNetworkDetailsComponent::onOverrideCredentialsToPilot); + connect(ui->pb_DetailsVatsim, &QPushButton::clicked, this, &CNetworkDetailsComponent::onChangePage); + connect(ui->pb_DetailsOtherServers, &QPushButton::clicked, this, &CNetworkDetailsComponent::onChangePage); + connect(ui->pb_BackToServer, &QPushButton::clicked, this, &CNetworkDetailsComponent::onChangePage); + connect(&m_networkSetup, &CNetworkSetup::setupChanged, this, &CNetworkDetailsComponent::reloadOtherServersSetup, Qt::QueuedConnection); + + // web service data + if (sGui && sGui->getWebDataServices()) + { + connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CNetworkDetailsComponent::onWebServiceDataRead, Qt::QueuedConnection); + } + + ui->form_FsdDetails->showEnableInfo(true); + ui->form_FsdDetails->setFsdSetupEnabled(false); + ui->form_Voice->showEnableInfo(true); + ui->form_Voice->setVoiceSetupEnabled(false); + + constexpr int MaxLength = 10; + constexpr int MinLength = 0; + CUpperCaseValidator *ucv = new CUpperCaseValidator(MinLength, MaxLength, ui->le_Copilot); + ucv->setAllowedCharacters09AZ(); + ui->le_Copilot->setMaxLength(MaxLength); + ui->le_Copilot->setValidator(ucv); + + const int tab = m_networkSetup.wasLastUsedWithOtherServer() ? LoginOthers : LoginVATSIM; + ui->tw_Network->setCurrentIndex(tab); + + this->reloadOtherServersSetup(); + this->onWebServiceDataRead(CEntityFlags::VatsimDataFile, CEntityFlags::ReadFinished, -1); } CNetworkDetailsComponent::~CNetworkDetailsComponent() @@ -32,14 +77,155 @@ namespace BlackGui return ui->frp_LoginMode->getLoginMode(); } + void CNetworkDetailsComponent::setLoginMode(INetwork::LoginMode mode) + { + ui->frp_LoginMode->setLoginMode(mode); + } + + bool CNetworkDetailsComponent::isVatsimServerSelected() const + { + const bool vatsim = ui->tw_Network->currentWidget() == ui->tb_NetworkVatsim; + return vatsim; + } + + bool CNetworkDetailsComponent::isOtherServerSelected() const + { + return ui->tw_Details->currentWidget() == ui->tb_OtherServers; + } + CVoiceSetup CNetworkDetailsComponent::getVoiceSetup() const { return ui->form_Voice->getValue(); } + bool CNetworkDetailsComponent::isVoiceSetupOverrideEnabled() const + { + return ui->form_Voice->isVoiceSetupEnabled(); + } + CFsdSetup CNetworkDetailsComponent::getFsdSetup() const { return ui->form_FsdDetails->getValue(); } + + bool CNetworkDetailsComponent::isFsdSetupOverrideEnabled() const + { + return ui->form_FsdDetails->isFsdSetupEnabled(); + } + + void CNetworkDetailsComponent::setServerButtonsVisible(bool visible) + { + ui->wi_OtherServersButtons->setVisible(visible); + ui->wi_VatsimButtons->setVisible(visible); + } + + void CNetworkDetailsComponent::onDetailsTabChanged(int index) + { + if (index == DetailsBack) + { + ui->sw_NetworkServerDetails->setCurrentIndex(PageServer); + return; + } + + Q_UNUSED(index); + const CServer server = this->getCurrentServer(); + + // only override if not yet enabled + if (!ui->form_FsdDetails->isFsdSetupEnabled()) { ui->form_FsdDetails->setValue(server.getFsdSetup()); } + if (!ui->form_Voice->isVoiceSetupEnabled()) { ui->form_Voice->setValue(server.getVoiceSetup()); } + } + + void CNetworkDetailsComponent::onOverrideCredentialsToPilot() + { + CServer server; + const QObject *s = QObject::sender(); + if (s == ui->pb_OverrideCredentialsOtherServers) + { + server = this->getCurrentOtherServer(); + } + else if (s == ui->pb_OverrideCredentialsVatsim) + { + // the VATSIM server selected has no valid user credentials + server = m_networkSetup.getLastVatsimServer(); + } + else { return; } + emit this->overridePilot(server.getUser()); + } + + void CNetworkDetailsComponent::onServerTabWidgetChanged(int index) + { + Q_UNUSED(index); + if (!m_updatePilotOnServerChanges) { return; } + const bool vatsim = this->isVatsimServerSelected(); + const CServer server = vatsim ? this->getCurrentVatsimServer() : this->getCurrentOtherServer(); + emit this->overridePilot(server.getUser()); + } + + void CNetworkDetailsComponent::onSelectedServerChanged(const CServer &server) + { + if (!m_updatePilotOnServerChanges) { return; } + const bool vatsim = this->isVatsimServerSelected(); + const CUser user = vatsim ? this->getCurrentVatsimServer().getUser() : server.getUser(); + emit this->overridePilot(server.getUser()); + } + + void CNetworkDetailsComponent::onWebServiceDataRead(CEntityFlags::Entity entity, CEntityFlags::ReadState state, int number) + { + if (!CEntityFlags::isFinishedReadState(state)) { return; } + Q_UNUSED(number); + + if (entity == CEntityFlags::VatsimDataFile) + { + CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers(); + if (vatsimFsdServers.isEmpty()) { return; } + vatsimFsdServers.sortBy(&CServer::getName); + const CServer currentServer = m_networkSetup.getLastVatsimServer(); + ui->comp_VatsimServers->setServers(vatsimFsdServers, true); + ui->comp_VatsimServers->preSelect(currentServer.getName()); + } + } + + void CNetworkDetailsComponent::onChangePage() + { + const QObject *s = QObject::sender(); + if (s == ui->pb_DetailsVatsim || s == ui->pb_DetailsOtherServers) + { + ui->sw_NetworkServerDetails->setCurrentIndex(PageDetails); + ui->tw_Details->setCurrentIndex(DetailsServer); + } + else + { + ui->sw_NetworkServerDetails->setCurrentIndex(PageServer); + } + } + + CServer CNetworkDetailsComponent::getCurrentVatsimServer() const + { + CServer server = ui->comp_VatsimServers->currentServer(); + if (!server.getUser().hasValidVatsimId()) + { + // normally VATSIM server have no valid user associated + const CUser user = m_networkSetup.getLastVatsimServer().getUser(); + server.setUser(user); + } + return server; + } + + CServer CNetworkDetailsComponent::getCurrentOtherServer() const + { + return ui->comp_OtherServers->currentServer(); + } + + CServer CNetworkDetailsComponent::getCurrentServer() const + { + return this->isVatsimServerSelected() ? this->getCurrentVatsimServer() : this->getCurrentOtherServer(); + } + + void CNetworkDetailsComponent::reloadOtherServersSetup() + { + const CServerList otherServers(m_networkSetup.getOtherServersPlusPredefinedServers()); + ui->comp_OtherServers->setServers(otherServers); + } + } // ns } // ns diff --git a/src/blackgui/components/networkdetailscomponent.h b/src/blackgui/components/networkdetailscomponent.h index 30c311ee5..a9e90befd 100644 --- a/src/blackgui/components/networkdetailscomponent.h +++ b/src/blackgui/components/networkdetailscomponent.h @@ -14,9 +14,14 @@ #include #include +#include "blackcore/data/networksetup.h" +#include "blackcore/network.h" +#include "blackmisc/network/data/lastserver.h" +#include "blackmisc/network/entityflags.h" #include "blackmisc/network/fsdsetup.h" #include "blackmisc/audio/voicesetup.h" -#include "blackcore/network.h" +#include "blackmisc/settingscache.h" +#include "blackmisc/datacache.h" namespace Ui { class CNetworkDetailsComponent; } namespace BlackGui @@ -29,6 +34,28 @@ namespace BlackGui Q_OBJECT public: + //! The tabs + enum Tab + { + LoginVATSIM, + LoginOthers, + }; + + //! Pages + enum Page + { + PageServer, + PageDetails + }; + + //! Details + enum Details + { + DetailsServer, + DetailsVoice, + DetailsBack + }; + //! Ctor explicit CNetworkDetailsComponent(QWidget *parent = nullptr); @@ -38,13 +65,69 @@ namespace BlackGui //! FSD setup BlackMisc::Network::CFsdSetup getFsdSetup() const; + //! Specific setup enabled? + bool isFsdSetupOverrideEnabled() const; + //! Voice setup BlackMisc::Audio::CVoiceSetup getVoiceSetup() const; + //! Specific setup enabled? + bool isVoiceSetupOverrideEnabled() const; + //! Login mode BlackCore::INetwork::LoginMode getLoginMode() const; + //! Login mode + void setLoginMode(BlackCore::INetwork::LoginMode mode); + + //! Selected server @{ + bool isVatsimServerSelected() const; + bool isOtherServerSelected() const; + //! @} + + //! Selected server (VATSIM) + BlackMisc::Network::CServer getCurrentVatsimServer() const; + + //! Selected server (others) + BlackMisc::Network::CServer getCurrentOtherServer() const; + + //! Current server based on selected tab + BlackMisc::Network::CServer getCurrentServer() const; + + signals: + //! Override the pilot + void overridePilot(const BlackMisc::Network::CUser &user); + + //! Request network settings + void requestNetworkSettings(); + private: + //! Settings have been changed + void reloadOtherServersSetup(); + + //! Tab widget (server) changed + void onServerTabWidgetChanged(int index); + + //! Server changed + void onSelectedServerChanged(const BlackMisc::Network::CServer &server); + + //! Set the server buttons visible + void setServerButtonsVisible(bool visible); + + //! Tab index changed + void onDetailsTabChanged(int index); + + //! Override credentials + void onOverrideCredentialsToPilot(); + + //! VATSIM data file was loaded + void onWebServiceDataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); + + //! Change page + void onChangePage(); + + BlackCore::Data::CNetworkSetup m_networkSetup; //!< servers last used + bool m_updatePilotOnServerChanges = true; QScopedPointer ui; }; } // ns diff --git a/src/blackgui/components/networkdetailscomponent.ui b/src/blackgui/components/networkdetailscomponent.ui index ab56c08f2..685210a1b 100644 --- a/src/blackgui/components/networkdetailscomponent.ui +++ b/src/blackgui/components/networkdetailscomponent.ui @@ -2,10 +2,18 @@ CNetworkDetailsComponent + + + 0 + 0 + 394 + 134 + + Network details - + 0 @@ -19,126 +27,360 @@ 0 - + 0 - - - Mode - - + + - 3 + 2 - 3 + 2 - 3 + 2 - 3 - - - - - - - - - FSD details - - - - 3 - - - 3 - - - 3 - - - 3 + 2 - - - true + + + QTabWidget::North - - - - 0 - 0 - 192 - 55 - + + 0 + + + + Login at VATSIM - + + VATSIM + + - 2 + 3 - 2 + 3 - 2 + 3 - 2 + 3 - - + + 3 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + details + + + + + + + + 0 + 0 + + + + copy credentials to pilot section + + + override pilot + + + + + + + + + + + + + + Other servers + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + reload + + + + :/diagona/icons/diagona/icons/arrow-circle-225.png:/diagona/icons/diagona/icons/arrow-circle-225.png + + + + + + + settings + + + + + + + details + + + + + + + copy credentials to pilot section + + + override pilot + + + + + - - - - - Voice - - - - 3 - - - 3 - - - 3 - - - 3 - - - + + + + + 0 + 30 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + partner callsign + + + + + + + Login + + + + + + + + 0 + 20 + + + + + + + + Co/Pilot callsign + + + + + - - - Matching log - - + + - 3 + 2 - 3 + 2 - 3 + 2 - 3 + 2 - - + + + + 0 + + + + FSD details + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 150 + 75 + + + + + + + + + Voice + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 150 + 50 + + + + + + + + + + :/pastel/icons/pastel/16/close.png:/pastel/icons/pastel/16/close.png + + + Back to server + + + + + + back to server + + + + + + @@ -160,10 +402,9 @@ 1 - BlackGui::Components::CModelMatcherLogEnable - QFrame -
blackgui/components/modelmatcherlogenable.h
- 1 + BlackGui::Components::CServerListSelector + QComboBox +
blackgui/components/serverlistselector.h
BlackGui::CLoginModeButtons @@ -172,6 +413,22 @@ 1 - + + tw_Network + comp_VatsimServers + pb_DetailsVatsim + pb_OverrideCredentialsVatsim + le_Copilot + comp_OtherServers + pb_RefreshOtherServers + pb_OtherServersGotoSettings + pb_DetailsOtherServers + pb_OverrideCredentialsOtherServers + tw_Details + pb_BackToServer + + + +