summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-12-22 14:02:31 +0100
committerSimon Rettberg2016-12-22 14:02:31 +0100
commit69a87ddf7faee8b26747b3e0c1cc97ab06bc779d (patch)
tree9f835c13c1a367af994e79734989d8f08f385bb2
parentDon't lower() window on startup (diff)
downloadvmchooser2-69a87ddf7faee8b26747b3e0c1cc97ab06bc779d.tar.gz
vmchooser2-69a87ddf7faee8b26747b3e0c1cc97ab06bc779d.tar.xz
vmchooser2-69a87ddf7faee8b26747b3e0c1cc97ab06bc779d.zip
Add --autoquit <seconds> that will quit automatically if no action is performed within a given time span
-rw-r--r--src/command_line_options.cpp4
-rw-r--r--src/dialog.cpp28
-rw-r--r--src/globals.cpp1
-rw-r--r--src/globals.h1
-rw-r--r--src/main.cpp42
-rw-r--r--src/ui/dialog.ui34
6 files changed, 75 insertions, 35 deletions
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 <width>x<height>\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 <width>x<height>\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 @@
<rect>
<x>0</x>
<y>0</y>
- <width>653</width>
- <height>684</height>
+ <width>895</width>
+ <height>692</height>
</rect>
</property>
<property name="windowTitle">
@@ -129,11 +129,11 @@ margin-bottom:0px;}</string>
<item>
<widget class="QTextBrowser" name="helpTextBrowser">
<property name="html">
- <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+ <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVuSans'; font-size:9pt;&quot;&gt;Loading...&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Loading...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -161,11 +161,11 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QTextBrowser" name="newsTextBrowser">
<property name="html">
- <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+ <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVuSans'; font-size:9pt;&quot;&gt;Loading...&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Loading...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -489,11 +489,11 @@ border:1px solid #999;
<item row="3" column="0">
<widget class="QTextBrowser" name="textBrowser">
<property name="html">
- <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+ <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVuSans'; font-size:9pt;&quot;&gt;Click on an item on the left side for more information&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Click on an item on the left side for more information&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -501,6 +501,18 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
+ <widget class="QLabel" name="lblAutoQuit">
+ <property name="font">
+ <font>
+ <pointsize>14</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string notr="true">Auto Logout Notice</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<spacer name="horizontalSpacer_5">