From bf8f4431c8a646c45216dbcb358a2646507ec1c6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 18 Oct 2018 16:02:28 +0200 Subject: Ignore logout/shutdown timeouts too far in the past --- src/saverwidget.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/saverwidget.cpp b/src/saverwidget.cpp index d437b53..027212f 100644 --- a/src/saverwidget.cpp +++ b/src/saverwidget.cpp @@ -46,38 +46,35 @@ SaverWidget::SaverWidget(WId parentWinId, QWidget *parent) : _counter++; qlonglong now = QDateTime::currentMSecsSinceEpoch() / 1000; // Determine what's timing out next (session/schedule) - DeadlineType type; - qlonglong remaining = 0; - if (_shutdownDeadline > 0 && _shutdownDeadline < _logoutDeadline) { + DeadlineType type = DeadlineType::Unspecified; + qlonglong shutdownRemaining = _shutdownDeadline - now; + qlonglong logoutRemaining = _logoutDeadline - now; + if (shutdownRemaining > -330 && (shutdownRemaining < logoutRemaining || logoutRemaining <= -330)) { type = DeadlineType::Shutdown; - remaining = _shutdownDeadline - now; - } else if (_logoutDeadline > 0) { + } else if (logoutRemaining > -330) { type = (_isLocked ? DeadlineType::IdleKillLocked : DeadlineType::IdleKill); - remaining = _logoutDeadline - now; - } else { - type = DeadlineType::Unspecified; } if (type == DeadlineType::Shutdown) { // Shutdown is about to happen (sooner than idle logout) - if (remaining < 0) { - ui->lblHeader->setText(QString("Dieser Rechner ist seit %1 ausgeschaltet (theoretisch zumindest)").arg(formatTime(-remaining))); + if (shutdownRemaining < 0) { + ui->lblHeader->setText(QString("Dieser Rechner ist seit %1 ausgeschaltet (theoretisch zumindest)").arg(formatTime(-shutdownRemaining))); } else { - ui->lblHeader->setText(QString("Achtung: Rechner wird in %1 heruntergefahren!").arg(formatTime(remaining))); + ui->lblHeader->setText(QString("Achtung: Rechner wird in %1 heruntergefahren!").arg(formatTime(shutdownRemaining))); } } else if (type == DeadlineType::IdleKillLocked) { // Idle logout is about to happen - if (remaining < 0) { + if (logoutRemaining < 0) { //ui->lblHeader->setText("Diese Sitzung kann durch einen Klick auf 'New Login' beendet werden..."); ui->lblHeader->setText("Diese Sitzung wird in Kürze beendet..."); } else { - ui->lblHeader->setText(QString("Diese Sitzung wird in %1 beendet, wenn sie nicht entsperrt wird.").arg(formatTime(remaining))); + ui->lblHeader->setText(QString("Diese Sitzung wird in %1 beendet, wenn sie nicht entsperrt wird.").arg(formatTime(logoutRemaining))); } } else if (type == DeadlineType::IdleKill) { // Idle logout is about to happen, but password is not required to reactivate session - if (remaining < 0) { + if (logoutRemaining < 0) { ui->lblHeader->setText("Hier hat wohl jemand vergessen sich auszuloggen..."); } else { - ui->lblHeader->setText(QString("Diese Sitzung wird in %1 beendet, wenn sie nicht weiter verwendet wird.").arg(formatTime(remaining))); + ui->lblHeader->setText(QString("Diese Sitzung wird in %1 beendet, wenn sie nicht weiter verwendet wird.").arg(formatTime(logoutRemaining))); } } else { if (_isLocked) { @@ -88,7 +85,7 @@ SaverWidget::SaverWidget(WId parentWinId, QWidget *parent) : } ui->lblClock->setText(QDateTime::currentDateTime().toString(QLocale().dateFormat() + " HH:mm ")); displayText(type); - bool shouldDisable = remaining < 300; + bool shouldDisable = (logoutRemaining > -330 && logoutRemaining < 310) || (shutdownRemaining > -330 && shutdownRemaining < 310); if (_standbyDisabled != shouldDisable) { _standbyDisabled = shouldDisable; if (shouldDisable) { -- cgit v1.2.3-55-g7522