Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/LtsLogin/logout_info_dialog.cpp
T

95 lines
2.2 KiB
C++
Executable File

#include "logout_info_dialog.h"
#include "ui_logout_info_dialog.h"
#include <QTimer>
namespace LtsLogin
{
LogoutInformationDialog::LogoutInformationDialog(int timeOut, AssetManagement::ShutdownAction shutdownAction, QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_ui(new Ui::LogoutInformationDialog)
, m_timer(new QTimer(this))
, m_timeOut(timeOut)
, m_secsLeft(timeOut)
{
m_ui->setupUi(this);
QString actionText;
switch(shutdownAction.underlying())
{
case AssetManagement::ShutdownAction::NoAction:
case AssetManagement::ShutdownAction::Logout:
actionText = tr("logout");
break;
case AssetManagement::ShutdownAction::Shutdown:
actionText = tr("shutdown");
break;
case AssetManagement::ShutdownAction::Reboot:
actionText = tr("reboot");
break;
}
setText(tr("A %1 was triggered by a remote workstation.").arg(actionText));
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Ok), &QPushButton::clicked, this, &LogoutInformationDialog::acceptClicked);
connect(m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &LogoutInformationDialog::closeClicked);
connect(m_timer, &QTimer::timeout, this, &LogoutInformationDialog::onTimerTimeout);
m_timer->setInterval(1000);
}
LogoutInformationDialog::~LogoutInformationDialog()
{
delete m_ui;
}
void LogoutInformationDialog::setText(const QString &text)
{
m_ui->lblLogoutText->setText(text);
}
void LogoutInformationDialog::onTimerTimeout()
{
if (m_secsLeft > 0)
{
m_secsLeft--;
setCloseButtonText(m_secsLeft);
}
else
{
acceptClicked();
}
}
void LogoutInformationDialog::acceptClicked()
{
m_timer->stop();
accept();
}
void LogoutInformationDialog::closeClicked()
{
m_timer->stop();
reject();
}
void LogoutInformationDialog::setCloseButtonText(int secsLeft)
{
m_ui->buttonBox->getButton(LtsWidgets::DialogButton::Close)->setText(tr("Abort [%1]").arg(secsLeft));
}
void LogoutInformationDialog::showEvent(QShowEvent *event)
{
m_secsLeft = m_timeOut;
setCloseButtonText(m_secsLeft);
m_timer->start();
LtsWidgets::LtsFramelessDialog::showEvent(event);
}
}