diff --git a/src/blackgui/components/loginoverviewcomponent.cpp b/src/blackgui/components/loginoverviewcomponent.cpp new file mode 100644 index 000000000..a0ec96bbe --- /dev/null +++ b/src/blackgui/components/loginoverviewcomponent.cpp @@ -0,0 +1,201 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +#include "ui_loginoverviewcomponent.h" +#include "loginoverviewcomponent.h" +#include "serverlistselector.h" +#include "dbquickmappingwizard.h" +#include "blackgui/editors/serverform.h" +#include "blackgui/editors/pilotform.h" +#include "blackgui/guiapplication.h" +#include "blackgui/loginmodebuttons.h" +#include "blackgui/ticklabel.h" +#include "blackgui/uppercasevalidator.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextsimulator.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/data/globalsetup.h" +#include "blackcore/webdataservices.h" +#include "blackcore/network.h" +#include "blackcore/simulator.h" +#include "blackmisc/simulation/simulatorinternals.h" +#include "blackmisc/simulation/aircraftmodel.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/aviation/aircrafticaocode.h" +#include "blackmisc/aviation/airlineicaocode.h" +#include "blackmisc/aviation/airporticaocode.h" +#include "blackmisc/network/entityflags.h" +#include "blackmisc/network/serverlist.h" +#include "blackmisc/icons.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/crashhandler.h" +#include "blackconfig/buildconfig.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace BlackConfig; +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Audio; +using namespace BlackMisc::Network; +using namespace BlackMisc::Simulation; +using namespace BlackCore; +using namespace BlackCore::Data; +using namespace BlackCore::Context; +using namespace BlackGui; + +namespace BlackGui +{ + namespace Components + { + const CLogCategoryList &CLoginOverviewComponent::getLogCategories() + { + static const BlackMisc::CLogCategoryList cats { CLogCategory::guiComponent() }; + return cats; + } + + CLoginOverviewComponent::CLoginOverviewComponent(QWidget *parent) : + COverlayMessagesFrame(parent), + ui(new Ui::CLoginOverviewComponent) + { + ui->setupUi(this); + + connect(ui->pb_Cancel, &QPushButton::clicked, this, &CLoginOverviewComponent::loginCancelled, Qt::QueuedConnection); + connect(ui->pb_Ok, &QPushButton::clicked, this, &CLoginOverviewComponent::toggleNetworkConnection, Qt::QueuedConnection); + + // overlay + this->setOverlaySizeFactors(0.8, 0.5); + this->setReducedInfo(true); + this->setForceSmall(true); + this->showKillButton(false); + + // forms + ui->form_Pilot->setReadOnly(true); + ui->form_Server->setReadOnly(true); + + // auto logoff + // we decided to make it difficult for users to disable it + if (!CBuildConfig::isLocalDeveloperDebugBuild()) + { + ui->cb_AutoLogoff->setChecked(true); + } + + // inital setup, if data already available + ui->form_Pilot->validate(); + ui->cb_AutoLogoff->setChecked(m_networkSetup.useAutoLogoff()); + } + + CLoginOverviewComponent::~CLoginOverviewComponent() + { } + + void CLoginOverviewComponent::setAutoLogoff(bool autoLogoff) + { + ui->cb_AutoLogoff->setChecked(autoLogoff); + } + + void CLoginOverviewComponent::loginCancelled() + { + this->closeOverlay(); + emit this->loginOrLogoffCancelled(); + } + + void CLoginOverviewComponent::toggleNetworkConnection() + { + if (!sGui || sGui->isShuttingDown()) { return; } + if (!sGui->getIContextNetwork() || !sGui->getIContextAudio()) { return; } + + const bool isConnected = sGui && sGui->getIContextNetwork()->isConnected(); + m_networkSetup.setAutoLogoff(ui->cb_AutoLogoff->isChecked()); + + CStatusMessage msg; + if (!isConnected) + { + // void + } + else + { + // disconnect from network + sGui->getIContextAudio()->leaveAllVoiceRooms(); + sGui->setExtraWindowTitle(""); + msg = sGui->getIContextNetwork()->disconnectFromNetwork(); + } + + // log message and trigger events + msg.addCategories(this); + CLogMessage::preformatted(msg); + if (msg.isSuccess()) + { + emit this->loginOrLogoffSuccessful(); + } + else + { + emit this->loginOrLogoffCancelled(); + } + } + + void CLoginOverviewComponent::showCurrentValues() + { + if (!this->hasValidContexts()) { return; } + const CServer server = sGui->getIContextNetwork()->getConnectedServer(); + ui->form_Server->setServer(server); + ui->form_Pilot->setUser(server.getUser()); + ui->comp_NetworkAircraft->showValues(); + } + + void CLoginOverviewComponent::onSimulatorStatusChanged(int status) + { + ISimulator::SimulatorStatus s = static_cast(status); + if (!this->hasValidContexts()) { return; } + if (sGui->getIContextNetwork()->isConnected()) + { + if (!s.testFlag(ISimulator::Connected)) + { + // sim NOT connected but network connected + this->autoLogoffDetection(); + } + } + } + + bool CLoginOverviewComponent::hasValidContexts() const + { + if (!sGui || !sGui->supportsContexts()) { return false; } + if (sGui->isShuttingDown()) { return false; } + if (!sGui->getIContextSimulator()) { return false; } + if (!sGui->getIContextNetwork()) { return false; } + if (!sGui->getIContextOwnAircraft()) { return false; } + return true; + } + + void CLoginOverviewComponent::autoLogoffDetection() + { + if (!ui->cb_AutoLogoff->isChecked()) { return; } + if (!this->hasValidContexts()) { return; } + if (!sGui->getIContextNetwork()->isConnected()) { return; } // nothing to logoff + + const CStatusMessage m = CStatusMessage(this, CStatusMessage::SeverityInfo, u"Auto logoff in progress (could be simulator shutdown, crash, closing simulator)"); + const int delaySecs = 30; + this->showOverlayHTMLMessage(m, qRound(1000 * delaySecs * 0.8)); + } + + } // namespace +} // namespace diff --git a/src/blackgui/components/loginoverviewcomponent.h b/src/blackgui/components/loginoverviewcomponent.h new file mode 100644 index 000000000..fa1fcd6fa --- /dev/null +++ b/src/blackgui/components/loginoverviewcomponent.h @@ -0,0 +1,115 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_LOGINOVERVIEWCOMPONENT_H +#define BLACKGUI_COMPONENTS_LOGINOVERVIEWCOMPONENT_H + +#include "blackcore/vatsim/vatsimsettings.h" +#include "blackcore/data/networksetup.h" +#include "blackgui/settings/guisettings.h" +#include "blackgui/overlaymessagesframe.h" +#include "blackgui/blackguiexport.h" +#include "blackmisc/simulation/data/lastmodel.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/network/server.h" +#include "blackmisc/network/user.h" +#include "blackmisc/digestsignal.h" +#include "blackmisc/settingscache.h" +#include "blackmisc/datacache.h" + +#include +#include +#include +#include +#include +#include + +namespace Ui { class CLoginOverviewComponent; } +namespace BlackMisc +{ + namespace Simulation + { + class CAircraftModel; + class CSimulatedAircraft; + } +} +namespace BlackGui +{ + namespace Components + { + /*! + * Login component to flight network + */ + class BLACKGUI_EXPORT CLoginOverviewComponent : public COverlayMessagesFrame + { + Q_OBJECT + + public: + //! Log categories + static const BlackMisc::CLogCategoryList &getLogCategories(); + + //! Constructor + explicit CLoginOverviewComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CLoginOverviewComponent() override; + + //! Set auto logoff + void setAutoLogoff(bool autoLogoff); + + //! Login requested + void toggleNetworkConnection(); + + //! Show current values + void showCurrentValues(); + + signals: + //! Login + void loginOrLogoffSuccessful(); + + //! Cancelled + void loginOrLogoffCancelled(); + + //! Relevant login data changed (digest version) + void loginDataChangedDigest(); + + private: + // -------------- others ----------------- + + //! Login cancelled + void loginCancelled(); + + //! Auto-logoff detection + void autoLogoffDetection(); + + //! Pause/Continue timeout + void toggleTimeout(); + + //! Set OK button string + void setOkButtonString(bool connected); + + //! Simulator status changed + void onSimulatorStatusChanged(int status); + + //! Has contexts? + bool hasValidContexts() const; + + static constexpr int OverlayMessageMs = 5000; + static constexpr int LogoffIntervalSeconds = 20; //!< time before logoff + + QScopedPointer ui; + BlackMisc::CDigestSignal m_changedLoginDataDigestSignal { this, &CLoginOverviewComponent::loginDataChangedDigest, 1500, 10 }; + BlackCore::Data::CNetworkSetup m_networkSetup; //!< servers last used + }; + } // namespace +} // namespace + +#endif // guard diff --git a/src/blackgui/components/loginoverviewcomponent.ui b/src/blackgui/components/loginoverviewcomponent.ui new file mode 100644 index 000000000..42fac09e8 --- /dev/null +++ b/src/blackgui/components/loginoverviewcomponent.ui @@ -0,0 +1,275 @@ + + + CLoginOverviewComponent + + + + 0 + 0 + 295 + 264 + + + + Login component + + + + 2 + + + 1 + + + 1 + + + 1 + + + 1 + + + + + Server + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + QFrame::Panel + + + + + + + + + + Matching log. + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + Pilot's info + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + 0 + 60 + + + + Qt::NoFocus + + + + + + + + + + Qt::StrongFocus + + + Own aircraft + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 10 + + + 3 + + + 3 + + + 3 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + cancel + + + Esc + + + + + + + ok + + + + + + + automatically logoff when simulator changes or appears crashed + + + auto logoff + + + + + + + + + + + BlackGui::Components::CModelMatcherLogEnable + QFrame +
blackgui/components/modelmatcherlogenable.h
+ 1 +
+ + BlackGui::Editors::CPilotForm + QFrame +
blackgui/editors/pilotform.h
+ 1 +
+ + BlackGui::Editors::CServerForm + QFrame +
blackgui/editors/serverform.h
+ 1 +
+ + BlackGui::Components::CNetworkAircraftValuesComponent + QFrame +
blackgui/components/networkaircraftvaluescomponent.h
+ 1 +
+
+ + form_Pilot + cb_AutoLogoff + pb_Ok + pb_Cancel + + + +
diff --git a/src/blackgui/components/networkaircraftvaluescomponent.cpp b/src/blackgui/components/networkaircraftvaluescomponent.cpp new file mode 100644 index 000000000..1363e1084 --- /dev/null +++ b/src/blackgui/components/networkaircraftvaluescomponent.cpp @@ -0,0 +1,51 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +#include "networkaircraftvaluescomponent.h" +#include "ui_networkaircraftvaluescomponent.h" + +#include "blackgui/guiapplication.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextnetwork.h" + +using namespace BlackCore::Context; + +namespace BlackGui +{ + namespace Components + { + CNetworkAircraftValuesComponent::CNetworkAircraftValuesComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CNetworkAircraftValuesComponent) + { + ui->setupUi(this); + } + + CNetworkAircraftValuesComponent::~CNetworkAircraftValuesComponent() + { + // void + } + + void CNetworkAircraftValuesComponent::showValues() + { + if (!sGui || sGui->isShuttingDown()) { return; } + if (!sGui->getIContextOwnAircraft() || !sGui->getIContextNetwork()) { return; } + + ui->le_SimModel->setText(sGui->getIContextOwnAircraft()->getOwnAircraft().getModelString()); + const QStringList values = sGui->getIContextNetwork()->getNetworkPresetValues(); + if (values.size() >= 5) + { + ui->le_SentModel->setText(values.at(0)); + ui->le_SentLivery->setText(values.at(1)); + ui->le_Aircraft->setText(values.at(2)); + ui->le_Airline->setText(values.at(3)); + ui->le_Callsign->setText(values.at(4)); + } + } + } // ns +} // ns diff --git a/src/blackgui/components/networkaircraftvaluescomponent.h b/src/blackgui/components/networkaircraftvaluescomponent.h new file mode 100644 index 000000000..15469fc8a --- /dev/null +++ b/src/blackgui/components/networkaircraftvaluescomponent.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_NETWORKAIRCRAFTVALUESCOMPONENT_H +#define BLACKGUI_COMPONENTS_NETWORKAIRCRAFTVALUESCOMPONENT_H + +#include +#include + +namespace Ui { class CNetworkAircraftValuesComponent; } +namespace BlackGui +{ + namespace Components + { + //! Display the network aircraft values as sent + class CNetworkAircraftValuesComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CNetworkAircraftValuesComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CNetworkAircraftValuesComponent() override; + + //! Show the current values + void showValues(); + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/networkaircraftvaluescomponent.ui b/src/blackgui/components/networkaircraftvaluescomponent.ui new file mode 100644 index 000000000..2236cb59b --- /dev/null +++ b/src/blackgui/components/networkaircraftvaluescomponent.ui @@ -0,0 +1,105 @@ + + + CNetworkAircraftValuesComponent + + + + 0 + 0 + 158 + 176 + + + + Frame + + + + + + Simulator model + + + + + + + true + + + + + + + Sent model + + + + + + + true + + + + + + + Sent livery + + + + + + + true + + + + + + + true + + + + + + + Callsign + + + + + + + Aircraft + + + + + + + Airline + + + + + + + true + + + + + + + true + + + + + + + +