From 69a87ddf7faee8b26747b3e0c1cc97ab06bc779d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 22 Dec 2016 14:02:31 +0100 Subject: Add --autoquit that will quit automatically if no action is performed within a given time span --- src/dialog.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 6b934e9..105d476 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -55,6 +55,7 @@ Dialog::Dialog(int defaultTab, bool examMode, QWidget *parent) ui->helpBox->hide(); ui->newsBox->hide(); + ui->lblAutoQuit->hide(); this->addStatusString(STR_LOADING); @@ -166,6 +167,7 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index) } ChooserSettings::setSetting("last-session", (s->shortDescription())); ChooserSettings::setSetting("last-tab", QString::number(activeTab_)); + g_autoQuitSeconds = 0; // So we don't kill the session :> setVisible(false); } else { QMessageBox::warning( @@ -369,13 +371,25 @@ void Dialog::setTheme() { void Dialog::onCenterTimer() { // center dialog on primary screen - QRect desktopRect = QApplication::desktop()->availableGeometry(this); - QPoint center = desktopRect.center(); - if (center != oldCenter_) { - if (_fullscreen) - this->resize(desktopRect.width(), desktopRect.height()); - this->move(center.x() - this->width() / 2, center.y() - this->height() / 2); - oldCenter_ = center; + if (isVisible()) { + QRect desktopRect = QApplication::desktop()->availableGeometry(this); + QPoint center = desktopRect.center(); + if (center != oldCenter_) { + if (_fullscreen) + this->resize(desktopRect.width(), desktopRect.height()); + this->move(center.x() - this->width() / 2, center.y() - this->height() / 2); + oldCenter_ = center; + } + } + // Handle auto-quit timeout + if (g_autoQuitSeconds > 0) { + g_autoQuitSeconds--; + if (g_autoQuitSeconds == 0) { + qApp->exit(0); + } else if (g_autoQuitSeconds < 60) { + ui->lblAutoQuit->setText(this->trUtf8("Auto logout in %1").arg(g_autoQuitSeconds)); + ui->lblAutoQuit->show(); + } } } -- cgit v1.2.3-55-g7522