diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 69b61045e..2318c9bf9 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -134,6 +134,7 @@ namespace BlackGui if (sGui && sGui->getIContextSimulator()) { connect(sGui->getIContextSimulator(), &IContextSimulator::ownAircraftModelChanged, this, &CLoginComponent::onSimulatorModelChanged); + connect(sGui->getIContextSimulator(), &IContextSimulator::vitalityLost, this, &CLoginComponent::autoLogoffDetection); } // server and UI elements when in disconnect state @@ -208,19 +209,20 @@ namespace BlackGui } } - void CLoginComponent::setLogoffCountdown(int timeout) + void CLoginComponent::setLogoffCountdown(int timeoutSeconds) { - if (timeout < 0) { timeout = LogoffIntervalSeconds; } + if (timeoutSeconds < 0) { timeoutSeconds = LogoffIntervalSeconds; } - ui->pb_LogoffTimeout->setMaximum(timeout); - ui->pb_LogoffTimeout->setValue(timeout); - m_logoffIntervalSeconds = timeout; + ui->pb_LogoffTimeout->setMaximum(timeoutSeconds); + ui->pb_LogoffTimeout->setValue(timeoutSeconds); + m_logoffIntervalSeconds = timeoutSeconds; } void CLoginComponent::loginCancelled() { m_logoffCountdownTimer.stop(); - ui->pb_LogoffTimeout->setValue(LogoffIntervalSeconds); + this->setLogoffCountdown(); // reset time + this->closeOverlay(); emit this->loginOrLogoffCancelled(); } @@ -235,6 +237,9 @@ namespace BlackGui ui->form_Pilot->setVatsimValidation(vatsimLogin); this->setUiLoginState(isConnected); + // reset time + this->setLogoffCountdown(); + CServer currentServer; // used for login CSimulatedAircraft ownAircraft; // used own aircraft CStatusMessage msg; @@ -322,7 +327,6 @@ namespace BlackGui sGui->getIContextAudio()->leaveAllVoiceRooms(); sGui->setExtraWindowTitle(""); msg = sGui->getIContextNetwork()->disconnectFromNetwork(); - } // log message and trigger events @@ -481,7 +485,7 @@ namespace BlackGui void CLoginComponent::startLogoffTimerCountdown() { ui->pb_LogoffTimeout->setValue(m_logoffIntervalSeconds); - m_logoffCountdownTimer.setInterval(m_logoffIntervalSeconds * 1000 / 10); + m_logoffCountdownTimer.setInterval(1000); m_logoffCountdownTimer.start(); } @@ -622,6 +626,20 @@ namespace BlackGui } } + void CLoginComponent::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, "Auto logoff in progress"); + const int delaySecs = 45; + this->showOverlayMessage(m, qRound(1000 * delaySecs * 0.8)); + this->setLogoffCountdown(delaySecs); + + emit this->requestLoginPage(); + } + void CLoginComponent::reverseLookupAircraftModel() { if (!sGui->getIContextSimulator()->isSimulatorAvailable()) { return; } diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index 04b36936b..be47b585f 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -81,8 +81,8 @@ namespace BlackGui //! Main info area changed void mainInfoAreaChanged(const QWidget *currentWidget); - //! Set a logoof time - void setLogoffCountdown(int timeout = -1); + //! Set a logoff time + void setLogoffCountdown(int timeoutSeconds = -1); signals: //! Login @@ -94,6 +94,9 @@ namespace BlackGui //! Request network settings void requestNetworkSettings(); + //! Request to be shown + void requestLoginPage(); + //! Relevant login data changed (digest version) void loginDataChangedDigest(); @@ -174,6 +177,9 @@ namespace BlackGui //! Logoff countdown void logoffCountdown(); + //! Auto-logoff detection + void autoLogoffDetection(); + //! Reverse lookup model void reverseLookupAircraftModel(); @@ -232,7 +238,7 @@ namespace BlackGui QScopedPointer m_mappingWizard; BlackMisc::CDigestSignal m_changedLoginDataDigestSignal { this, &CLoginComponent::loginDataChangedDigest, 1500, 10 }; bool m_autoPopupWizard = false; //!< automatically popup wizard if mapping is needed - bool m_visible = false; //!< is this component selected? + bool m_visible = false; //!< is this component selected? bool m_updatePilotOnServerChanges = true; const QIcon m_iconPlay {":/famfamfam/icons/famfamfam/icons/silk/control_play_blue.png"}; const QIcon m_iconPause {":/famfamfam/icons/famfamfam/icons/silk/control_pause_blue.png"}; diff --git a/src/blackgui/components/logincomponent.ui b/src/blackgui/components/logincomponent.ui index 2fc8f2189..05c40d869 100644 --- a/src/blackgui/components/logincomponent.ui +++ b/src/blackgui/components/logincomponent.ui @@ -6,8 +6,8 @@ 0 0 - 272 - 748 + 295 + 735 @@ -226,7 +226,7 @@ - 0 + 3 @@ -788,7 +788,7 @@ - 3 + 10 3 @@ -799,7 +799,7 @@ 3 - + Qt::Horizontal @@ -812,7 +812,7 @@ - + cancel @@ -822,13 +822,23 @@ - + ok + + + + automatically logoff when simulator changes or appears crashed + + + auto logoff + + + diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index 57991a693..87cecf3cb 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -245,9 +245,15 @@ void SwiftGuiStd::initGuiSignals() connect(ui->comp_Login, &CLoginComponent::loginDataChangedDigest, ui->comp_MainInfoArea->getFlightPlanComponent(), &CFlightPlanComponent::loginDataSet); connect(ui->comp_Login, &CLoginComponent::requestNetworkSettings, [ this ]() { + if (!sApp || sApp->isShuttingDown()) { return; } this->setMainPageInfoArea(CMainInfoAreaComponent::InfoAreaSettings); ui->comp_MainInfoArea->getSettingsComponent()->setTab(CSettingsComponent::SettingTabServers); }); + connect(ui->comp_Login, &CLoginComponent::requestLoginPage, [ this ]() + { + if (!sApp || sApp->isShuttingDown()) { return; } + ui->sw_MainMiddle->setCurrentIndex(MainPageLogin); + }); connect(this, &SwiftGuiStd::currentMainInfoAreaChanged, ui->comp_Login, &CLoginComponent::mainInfoAreaChanged); // text messages