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/command_line_options.cpp | 4 ++++ src/dialog.cpp | 28 +++++++++++++++++++++------- src/globals.cpp | 1 + src/globals.h | 1 + src/main.cpp | 42 +++++++++++++++++++++++++----------------- src/ui/dialog.ui | 34 +++++++++++++++++++++++----------- 6 files changed, 75 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 9b00080..f020f0d 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -6,6 +6,7 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { // parse command line arguments (please sort by short option for easier handling) static const struct option longOptions[] = { + {"autoquit", required_argument, NULL, 'aqit'}, {"base", required_argument, NULL, 'b'}, {"path", required_argument, NULL, 'b'}, // Compatibility to v1.0 {"config", required_argument, NULL, 'c'}, @@ -37,6 +38,9 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { // Again, please sort alphabetically in getopt_long call and switch statement while ((c = getopt_long(argc, argv, "b:c:Dd:Ff:hl:P:pSs:t:T:u:vx:?", longOptions, NULL)) != -1) { switch (c) { + case 'aqit': + options.insert("autoquit", optarg); + break; case 'b': options.insert("base", optarg); break; 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(); + } } } diff --git a/src/globals.cpp b/src/globals.cpp index 6ff2e25..50bb19a 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -20,6 +20,7 @@ const QString previousSessionFile(userPath + "/vmchooser2.ini"); bool debugMode = false; bool pvsEnabled = false; +int g_autoQuitSeconds = 0; QString pool; QString theme; diff --git a/src/globals.h b/src/globals.h index a3b1e99..a2a8805 100644 --- a/src/globals.h +++ b/src/globals.h @@ -24,6 +24,7 @@ class Session; extern bool debugMode; extern bool pvsEnabled; +extern int g_autoQuitSeconds; extern QString binPath; extern QString etcPath; diff --git a/src/main.cpp b/src/main.cpp index b37e73c..74cee75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,27 +34,27 @@ int main(int argc, char *argv[]) { std::string usage( a.translate("Console", "Usage: vmchooser [ OPTIONS ]\n\n" - " -b --base base directory where VM images are accessible\n" - " -d, --default name of default session\n" - " -c, --config alternative config file\n" + " -b --base base directory where VM images are accessible\n" + " -d, --default name of default session\n" + " -c, --config alternative config file\n" " -l, --locations location id(s), space separated\n" " --location-mode how to treat entries for this location (IGNORE, BUMP or EXCLUSIVE)\n" - " --exam-mode enable exam mode\n" - " -P, --pool one or more pool names to display (comma separated)\n" - " -f, --file direct boot .desktop file\n" - " -x, --xpath path of X Session .desktop files\n" - " -u, --url url of vmware .xml file\n" - " -s, --size window size x\n" - " -t, --theme theme\n" + " --exam-mode enable exam mode\n" + " -P, --pool one or more pool names to display (comma separated)\n" + " -f, --file direct boot .desktop file\n" + " -x, --xpath path of X Session .desktop files\n" + " -u, --url url of vmware .xml file\n" + " -s, --size window size x\n" + " -t, --theme theme\n" " --template-mode how to treat template entries (IGNORE or BUMP)\n" - " -p, --pvs show pvs options\n" - " -D, --debug print debug information\n" - " -v, --version print version and exit\n" - " -h, --help print usage information and exit\n" + " -p, --pvs show pvs options\n" + " -D, --debug print debug information\n" + " -v, --version print version and exit\n" + " -h, --help print usage information and exit\n" " -S, --runscript change path to run-virt.sh\n" - " -T --tab default tab (0=xsession, 1=my vms, 2=all vms)\n" - " --no-vtx Host doesn't support VT-x/AMD-V (mark 64bit guests)\n" - " --start-uuid start lecture with the given uuid\n" + " -T --tab default tab (0=xsession, 1=my vms, 2=all vms)\n" + " --no-vtx Host doesn't support VT-x/AMD-V (mark 64bit guests)\n" + " --start-uuid start lecture with the given uuid\n" "\nFILE can be a vmware .xml or an X .desktop file\n").toUtf8().data()); if (cmdOptions.contains("error")) { @@ -300,6 +300,14 @@ int main(int argc, char *argv[]) { pvsEnabled = true; } + if (cmdOptions.contains("autoquit")) { + bool ok = false; + g_autoQuitSeconds = cmdOptions.value("autoquit").toInt(&ok, 10); + if (!ok) { + g_autoQuitSeconds = 0; + } + } + QRect desktopRect = QApplication::desktop()->availableGeometry(&w); if (size == "fullscreen") { width = desktopRect.width(); diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui index cbf3b38..cde9282 100644 --- a/src/ui/dialog.ui +++ b/src/ui/dialog.ui @@ -6,8 +6,8 @@ 0 0 - 653 - 684 + 895 + 692 @@ -129,11 +129,11 @@ margin-bottom:0px;} - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVuSans'; font-size:9pt;">Loading...</span></p></body></html> +</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Loading...</p></body></html> @@ -161,11 +161,11 @@ p, li { white-space: pre-wrap; } - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVuSans'; font-size:9pt;">Loading...</span></p></body></html> +</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Loading...</p></body></html> @@ -489,17 +489,29 @@ border:1px solid #999; - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'DejaVuSans'; font-size:9pt;">Click on an item on the left side for more information</span></p></body></html> +</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Click on an item on the left side for more information</p></body></html> + + + + + 14 + + + + Auto Logout Notice + + + -- cgit v1.2.3-55-g7522