mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 18:25:42 +08:00
Countdown for logoff
A countdown is displayed, and logoff is completed automatically after timeout
This commit is contained in:
@@ -13,14 +13,17 @@
|
|||||||
#include "blackcore/context_settings.h"
|
#include "blackcore/context_settings.h"
|
||||||
#include "blackcore/context_ownaircraft.h"
|
#include "blackcore/context_ownaircraft.h"
|
||||||
#include "blackcore/context_audio.h"
|
#include "blackcore/context_audio.h"
|
||||||
|
#include "blackcore/context_simulator.h"
|
||||||
#include "blackcore/network.h"
|
#include "blackcore/network.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/avaircrafticao.h"
|
||||||
#include "../uppercasevalidator.h"
|
#include "../uppercasevalidator.h"
|
||||||
#include <QIntValidator>
|
#include <QIntValidator>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
|
using namespace BlackMisc::Simulation;
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
using namespace BlackGui;
|
using namespace BlackGui;
|
||||||
|
|
||||||
@@ -34,6 +37,11 @@ namespace BlackGui
|
|||||||
ui(new Ui::CLoginComponent)
|
ui(new Ui::CLoginComponent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
this->m_logoffCountdownTimer = new QTimer(this);
|
||||||
|
this->ui->pb_LogoffTimeout->setMaximum(LogoffIntervalSeconds);
|
||||||
|
this->ui->pb_LogoffTimeout->setValue(LogoffIntervalSeconds);
|
||||||
|
connect(this->m_logoffCountdownTimer, &QTimer::timeout, this, &CLoginComponent::ps_logoffCountdown);
|
||||||
|
|
||||||
setOkButtonString(false);
|
setOkButtonString(false);
|
||||||
connect(this->ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &CLoginComponent::ps_loginCancelled);
|
connect(this->ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &CLoginComponent::ps_loginCancelled);
|
||||||
connect(this->ui->bb_OkCancel, &QDialogButtonBox::accepted, this, &CLoginComponent::ps_toggleNetworkConnection);
|
connect(this->ui->bb_OkCancel, &QDialogButtonBox::accepted, this, &CLoginComponent::ps_toggleNetworkConnection);
|
||||||
@@ -67,7 +75,7 @@ namespace BlackGui
|
|||||||
connect(ui->le_VatsimRealName, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateVatsimValues);
|
connect(ui->le_VatsimRealName, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateVatsimValues);
|
||||||
|
|
||||||
// own aircraft
|
// own aircraft
|
||||||
this->ui->le_Callsign->setMaxLength(10);
|
this->ui->le_Callsign->setMaxLength(LogoffIntervalSeconds);
|
||||||
this->ui->le_Callsign->setValidator(new CUpperCaseValidator(this));
|
this->ui->le_Callsign->setValidator(new CUpperCaseValidator(this));
|
||||||
connect(ui->le_Callsign, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateAircraftValues);
|
connect(ui->le_Callsign, &QLineEdit::editingFinished, this, &CLoginComponent::ps_validateAircraftValues);
|
||||||
|
|
||||||
@@ -93,25 +101,28 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CLoginComponent::mainInfoAreaChanged(const QWidget *currentWidget)
|
void CLoginComponent::mainInfoAreaChanged(const QWidget *currentWidget)
|
||||||
{
|
{
|
||||||
|
this->m_logoffCountdownTimer->stop(); // in any case stop the timer
|
||||||
if (currentWidget != this && currentWidget != this->parentWidget())
|
if (currentWidget != this && currentWidget != this->parentWidget())
|
||||||
{
|
{
|
||||||
this->m_visible = false;
|
this->m_visible = false;
|
||||||
|
this->m_logoffCountdownTimer->stop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
this->setOwnModel();
|
||||||
if (this->m_visible)
|
if (this->m_visible)
|
||||||
{
|
{
|
||||||
|
// already visible:
|
||||||
// re-trigger! treat as same as OK
|
// re-trigger! treat as same as OK
|
||||||
this->ps_toggleNetworkConnection();
|
this->ps_toggleNetworkConnection();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
this->m_visible = true;
|
this->m_visible = true;
|
||||||
bool isConnected = this->getIContextNetwork()->isConnected();
|
bool isConnected = this->getIContextNetwork()->isConnected();
|
||||||
this->setGuiVisibility(isConnected);
|
this->setGuiVisibility(isConnected);
|
||||||
this->setOkButtonString(isConnected);
|
this->setOkButtonString(isConnected);
|
||||||
|
if (isConnected) { this->startLogoffTimerCountdown(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +144,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CLoginComponent::ps_loginCancelled()
|
void CLoginComponent::ps_loginCancelled()
|
||||||
{
|
{
|
||||||
|
this->m_logoffCountdownTimer->stop();
|
||||||
|
this->ui->pb_LogoffTimeout->setValue(LogoffIntervalSeconds);
|
||||||
emit loginOrLogoffCancelled();
|
emit loginOrLogoffCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +214,7 @@ namespace BlackGui
|
|||||||
currentServer = this->getCurrentOtherServer();
|
currentServer = this->getCurrentOtherServer();
|
||||||
}
|
}
|
||||||
this->ui->frp_CurrentServer->setServer(currentServer);
|
this->ui->frp_CurrentServer->setServer(currentServer);
|
||||||
|
this->getIContextOwnAircraft()->updatePilot(currentServer.getUser(), loginOriginator());
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
msg = this->getIContextNetwork()->connectToNetwork(currentServer, static_cast<uint>(mode));
|
msg = this->getIContextNetwork()->connectToNetwork(currentServer, static_cast<uint>(mode));
|
||||||
@@ -223,7 +237,6 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
emit loginOrLogoffCancelled();
|
emit loginOrLogoffCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLoginComponent::ps_onVatsimDataFileLoaded()
|
void CLoginComponent::ps_onVatsimDataFileLoaded()
|
||||||
@@ -247,10 +260,7 @@ namespace BlackGui
|
|||||||
void CLoginComponent::loadFromSettings()
|
void CLoginComponent::loadFromSettings()
|
||||||
{
|
{
|
||||||
//! \todo replace with loading from settings when completed
|
//! \todo replace with loading from settings when completed
|
||||||
this->ui->le_Callsign->setText("BLACK");
|
this->ui->le_Callsign->setText("SWIFT");
|
||||||
this->ui->le_AircraftIcaoDesignator->setText("C172");
|
|
||||||
this->ui->le_AircraftIcaoAirline->setText("GA");
|
|
||||||
this->ui->le_AircraftCombinedType->setText("L1P");
|
|
||||||
this->ui->le_VatsimId->setText("1288459");
|
this->ui->le_VatsimId->setText("1288459");
|
||||||
this->ui->le_VatsimPassword->setText("4769");
|
this->ui->le_VatsimPassword->setText("4769");
|
||||||
this->ui->le_VatsimHomeAirport->setText("LOWI");
|
this->ui->le_VatsimHomeAirport->setText("LOWI");
|
||||||
@@ -312,7 +322,57 @@ namespace BlackGui
|
|||||||
this->ui->gbp_LoginMode->setVisible(!connected);
|
this->ui->gbp_LoginMode->setVisible(!connected);
|
||||||
this->ui->gb_OwnAircraft->setVisible(!connected);
|
this->ui->gb_OwnAircraft->setVisible(!connected);
|
||||||
this->ui->gb_Network->setVisible(!connected);
|
this->ui->gb_Network->setVisible(!connected);
|
||||||
this->ui->gb_CurrentServer->setVisible(connected);
|
this->ui->fr_LogoffConfirmation->setVisible(connected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLoginComponent::startLogoffTimerCountdown()
|
||||||
|
{
|
||||||
|
this->ui->pb_LogoffTimeout->setValue(LogoffIntervalSeconds);
|
||||||
|
this->m_logoffCountdownTimer->setInterval(1000);
|
||||||
|
this->m_logoffCountdownTimer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLoginComponent::setOwnModel()
|
||||||
|
{
|
||||||
|
static const CAircraftIcao defaultIcao("C172", "L1P", "FOO", "", ""); //! \todo set values for OBS
|
||||||
|
bool simConnected = this->getIContextSimulator() && this->getIContextSimulator()->isSimulating();
|
||||||
|
if (simConnected)
|
||||||
|
{
|
||||||
|
CAircraftModel model = this->getIContextSimulator()->getOwnAircraftModel();
|
||||||
|
this->ui->le_SimulatorModel->setText(model.getModelString());
|
||||||
|
this->setIcaoValuesIfEmpty(model.getIcao());
|
||||||
|
|
||||||
|
// still empty?
|
||||||
|
if (this->ui->le_AircraftIcaoDesignator->text().trimmed().isEmpty())
|
||||||
|
{
|
||||||
|
this->setIcaoValuesIfEmpty(defaultIcao);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Set observer mode without simulator
|
||||||
|
//! \todo Currently not working in OBS mode
|
||||||
|
this->ui->gbp_LoginMode->setLoginMode(INetwork::LoginNormal);
|
||||||
|
this->setIcaoValuesIfEmpty(defaultIcao);
|
||||||
|
this->ui->le_SimulatorModel->setText("No simulator");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLoginComponent::setIcaoValuesIfEmpty(const CAircraftIcao &icao)
|
||||||
|
{
|
||||||
|
if (this->ui->le_AircraftIcaoDesignator->text().trimmed().isEmpty())
|
||||||
|
{
|
||||||
|
this->ui->le_AircraftIcaoDesignator->setText(icao.getAircraftDesignator());
|
||||||
|
}
|
||||||
|
if (this->ui->le_AircraftIcaoAirline->text().trimmed().isEmpty())
|
||||||
|
{
|
||||||
|
this->ui->le_AircraftIcaoAirline->setText(icao.getAirlineDesignator());
|
||||||
|
}
|
||||||
|
if (this->ui->le_AircraftCombinedType->text().trimmed().isEmpty())
|
||||||
|
{
|
||||||
|
this->ui->le_AircraftCombinedType->setText(icao.getAircraftCombinedType());
|
||||||
|
}
|
||||||
|
this->ps_validateAircraftValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLoginComponent::ps_validateAircraftValues()
|
bool CLoginComponent::ps_validateAircraftValues()
|
||||||
@@ -364,6 +424,19 @@ namespace BlackGui
|
|||||||
this->ui->cbp_OtherServers->setServers(otherServers);
|
this->ui->cbp_OtherServers->setServers(otherServers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CLoginComponent::ps_logoffCountdown()
|
||||||
|
{
|
||||||
|
int v = this->ui->pb_LogoffTimeout->value();
|
||||||
|
v -= 1;
|
||||||
|
if (v < 0) { v = 0; }
|
||||||
|
this->ui->pb_LogoffTimeout->setValue(v);
|
||||||
|
if (v <= 0)
|
||||||
|
{
|
||||||
|
this->m_logoffCountdownTimer->stop();
|
||||||
|
this->ps_toggleNetworkConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const QString &CLoginComponent::loginOriginator()
|
const QString &CLoginComponent::loginOriginator()
|
||||||
{
|
{
|
||||||
// string is generated once, the timestamp allows to use multiple
|
// string is generated once, the timestamp allows to use multiple
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ namespace BlackGui
|
|||||||
//! Settings have been changed
|
//! Settings have been changed
|
||||||
void ps_onSettingsChanged(uint settingsType);
|
void ps_onSettingsChanged(uint settingsType);
|
||||||
|
|
||||||
|
//! Logoff countdown
|
||||||
|
void ps_logoffCountdown();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! GUI aircraft values, formatted
|
//! GUI aircraft values, formatted
|
||||||
@@ -127,11 +130,22 @@ namespace BlackGui
|
|||||||
//! Show/hide elements as appropriate
|
//! Show/hide elements as appropriate
|
||||||
void setGuiVisibility(bool connected);
|
void setGuiVisibility(bool connected);
|
||||||
|
|
||||||
|
//! Logoff countdown
|
||||||
|
void startLogoffTimerCountdown();
|
||||||
|
|
||||||
|
//! Own model string
|
||||||
|
void setOwnModel();
|
||||||
|
|
||||||
|
//! Set ICAO values if fields are empty
|
||||||
|
void setIcaoValuesIfEmpty(const BlackMisc::Aviation::CAircraftIcao &icao);
|
||||||
|
|
||||||
//! Identifies sender of cockpit updates
|
//! Identifies sender of cockpit updates
|
||||||
static const QString &loginOriginator();
|
static const QString &loginOriginator();
|
||||||
|
|
||||||
bool m_visible = false; //!< is this component selected?
|
bool m_visible = false; //!< is this component selected?
|
||||||
QScopedPointer<Ui::CLoginComponent> ui;
|
QScopedPointer<Ui::CLoginComponent> ui;
|
||||||
|
const int LogoffIntervalSeconds = 10;
|
||||||
|
QTimer *m_logoffCountdownTimer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -10,6 +10,12 @@
|
|||||||
<height>412</height>
|
<height>412</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Frame</string>
|
<string>Frame</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -438,33 +444,67 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="gb_CurrentServer">
|
<widget class="QFrame" name="fr_LogoffConfirmation">
|
||||||
<property name="title">
|
<property name="minimumSize">
|
||||||
<string>Current server</string>
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="vl_CurrentServer">
|
<layout class="QVBoxLayout" name="vl_LogoffConfirmation">
|
||||||
<property name="spacing">
|
|
||||||
<number>3</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>3</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>3</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>3</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>3</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="BlackGui::CServerForm" name="frp_CurrentServer">
|
<widget class="QGroupBox" name="gb_CurrentServer">
|
||||||
<property name="frameShape">
|
<property name="title">
|
||||||
<enum>QFrame::StyledPanel</enum>
|
<string>Current server</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShadow">
|
<layout class="QVBoxLayout" name="vl_CurrentServer">
|
||||||
<enum>QFrame::Raised</enum>
|
<property name="leftMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CServerForm" name="frp_CurrentServer">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="pb_LogoffTimeout">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="format">
|
||||||
|
<string>%v</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user