summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/config.cpp1
-rw-r--r--src/config.h1
-rw-r--r--src/dialog.cpp60
-rw-r--r--src/images.qrc3
-rw-r--r--src/img/docker.pngbin0 -> 5165 bytes
-rw-r--r--src/img/qemu.pngbin2854 -> 0 bytes
-rw-r--r--src/img/qemukvm.pngbin0 -> 4059 bytes
-rw-r--r--src/session.h4
-rw-r--r--src/userldapdata.cpp17
-rw-r--r--src/vsession.cpp30
-rw-r--r--src/vsession.h4
-rw-r--r--src/xsession.cpp5
13 files changed, 86 insertions, 43 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c58fa4b..7bac06e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,13 +5,13 @@ project(vmchooser)
SET(EXTRA_CXX_FLAGS "" CACHE STRING "Additional options to pass to C++ compiler")
-set(CMAKE_BUILD_TYPE Debug)
+set(CMAKE_BUILD_TYPE Release)
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wextra -Wpedantic -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Wdisabled-optimization -Wfloat-equal -Wformat -Wformat=2 -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winit-self -Winline -Winvalid-pch -Wlong-long -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wsign-compare -Wstack-protector -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default -Wswitch-enum -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wno-multichar")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wno-multichar")
set(CMAKE_CXX_STANDARD 11)
# Some cmake versions can't understand the CMAKE_CXX_STANDARD option above?
-SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${EXTRA_CXX_FLAGS}" )
+SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-multichar -Wno-error=deprecated-declarations ${EXTRA_CXX_FLAGS}" )
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
diff --git a/src/config.cpp b/src/config.cpp
index 0d4a72d..ca83bfc 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -56,6 +56,7 @@ const ConfigOption* const Config::PVS_CHECKED = new ConfigOption("", "pvs-checke
const ConfigOption* const Config::RUNSCRIPT = new ConfigOption("S", "runscript", "runscript", "path", RUN_VIRT_PATH, "Path to run-virt script");
const ConfigOption* const Config::WINDOW_SIZE = new ConfigOption("s", "size", "size", "WxH", "640x480", "Size of window if not using fullscreen");
const ConfigOption* const Config::DEFAULT_TAB = new ConfigOption("T", "tab", "tab", "tabno", "2", "Default tab to show, first tab being 0");
+const ConfigOption* const Config::FORCE_DEFAULT_TAB = new ConfigOption("", "force-tab", "force-tab", "", "", "Force the default tab to be shown, even if saved session is available");
const ConfigOption* const Config::THEME = new ConfigOption("t", "theme", "theme", "name", "", "Name of theme to load");
const ConfigOption* const Config::URL_BASE = new ConfigOption("u", "url", "url", "url", "", "Base URL path to fetch resources from");
const ConfigOption* const Config::URL_LIST = new ConfigOption("", "url-list", "url-list", "url", "", "Use this URL for the VM list instead of <urlbase>/list");
diff --git a/src/config.h b/src/config.h
index 011e82a..a1eecec 100644
--- a/src/config.h
+++ b/src/config.h
@@ -24,6 +24,7 @@ public:
static const ConfigOption* const RUNSCRIPT;
static const ConfigOption* const WINDOW_SIZE;
static const ConfigOption* const DEFAULT_TAB;
+ static const ConfigOption* const FORCE_DEFAULT_TAB;
static const ConfigOption* const THEME;
static const ConfigOption* const URL_BASE;
static const ConfigOption* const URL_LIST;
diff --git a/src/dialog.cpp b/src/dialog.cpp
index bdeab16..aea2d6e 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -170,35 +170,31 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
UserConfig::setNewsHelpOpen(!ui->helpBox->isHidden());
UserConfig::sync();
- QProcess *process = nullptr;
+ qint64 scriptPid = 0;
if (QFile::exists(SESSION_START_SCRIPT)) {
// Companion script
- process = new QProcess;
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- env.insert("SESSION_NAME", s->shortDescription());
- env.insert("SESSION_UUID", s->uuid());
- env.insert("SESSION_CMD", s->execCommand());
+ setenv("SESSION_NAME", s->shortDescription().toLocal8Bit().constData(), 1);
+ setenv("SESSION_UUID", s->uuid().toLocal8Bit().constData(), 1);
+ setenv("SESSION_CMD", s->execCommand().toLocal8Bit().constData(), 1);
if (s->type() == Session::VSESSION) {
- env.insert("SESSION_TYPE", "VSESSION");
+ setenv("SESSION_TYPE", "VSESSION", 1);
} else if (s->type() == Session::XSESSION) {
- env.insert("SESSION_TYPE", "XSESSION");
+ setenv("SESSION_TYPE", "XSESSION", 1);
+ }
+ if (!QProcess::startDetached(SESSION_START_SCRIPT, QStringList(), QStringLiteral("/"), &scriptPid)) {
+ scriptPid = 0;
}
- process->setProcessEnvironment(env);
- process->start(SESSION_START_SCRIPT);
- process->closeReadChannel(QProcess::StandardError);
- process->closeReadChannel(QProcess::StandardOutput);
- process->closeWriteChannel();
}
// Run session
s->run();
// Should not return on success
- if (process != nullptr) {
- process->terminate();
+ if (scriptPid > 0) {
+ ::kill(pid_t(scriptPid), SIGTERM);
}
QMessageBox::critical(
- this, trUtf8("vmchooser"),
- trUtf8("Vmchooser failed to run the selected session!"));
+ this, tr("vmchooser"),
+ tr("Vmchooser failed to run the selected session!"));
QApplication::instance()->quit();
}
@@ -293,10 +289,11 @@ bool Dialog::selectSession(const QString& name, int preferredTab) {
QModelIndex root(ui->treeView->rootIndex());
int bestTab = -1;
+ int matchLevel = 0;
+ int boost;
QModelIndex bestIndex;
for (int tab = TAB_COUNT - 1; tab >= 0; --tab) {
- if (bestTab != -1 && preferredTab != tab) // We already have a potential match, only keep going if this is the desired tab
- continue;
+ boost = (tab == preferredTab);
for (int i = 0; i < model_[tab]->rowCount(root); ++i) {
QModelIndex section(model_[tab]->index(i, 0, root));
if (!section.isValid())
@@ -313,8 +310,19 @@ bool Dialog::selectSession(const QString& name, int preferredTab) {
if ((!s->uuid().isEmpty() && s->uuid() == name) || s->shortDescription() == name) {
bestTab = tab;
bestIndex = index;
+ matchLevel = 5 + boost;
break; // Break inner, keep checking other tabs
}
+ if (matchLevel < 3 + boost && s->shortDescription().startsWith(name)) {
+ bestTab = tab;
+ bestIndex = index;
+ matchLevel = 3 + boost;
+ }
+ if (matchLevel < 1 + boost && name.length() > 3 && s->shortDescription().contains(name)) {
+ bestTab = tab;
+ bestIndex = index;
+ matchLevel = 1 + boost;
+ }
}
}
}
@@ -341,8 +349,16 @@ void Dialog::selectPreviousSession() {
return;
}
int lastTab = UserConfig::getLastTab();
+
+ if (Config::isSet(Config::FORCE_DEFAULT_TAB)) {
+ // Force specific tab preselect
+ lastTab = Config::get(Config::DEFAULT_TAB).toInt();
+ }
+
+ // Command line default session takes precedence
QString lastSession = Config::get(Config::DEFAULT_SESSION);
- if (lastSession.isEmpty()) {
+ if (lastSession.isEmpty() && !Config::isSet(Config::FORCE_DEFAULT_TAB)) {
+ // If no cmdline, use user's last session if we don't force a tab via cmdline
auto list = UserConfig::getLastSessions();
if (!list.isEmpty()) {
lastSession = list.back();
@@ -361,7 +377,7 @@ void Dialog::selectPreviousSession() {
if (lastTab >= 0 && lastTab < TAB_COUNT) {
qDebug() << "Trying to select last tab " << lastTab;
this->onTabButtonChanged(lastTab);
- } else {
+ } else if (Config::isSet(Config::DEFAULT_TAB)) {
int defaultTab = Config::get(Config::DEFAULT_TAB).toInt();
qDebug() << "Selected default tab " << defaultTab;
// Select default tab
@@ -430,7 +446,7 @@ void Dialog::onCenterTimer() {
if (autoQuit_ == 0) {
QCoreApplication::instance()->exit(0);
} else if (autoQuit_ < 60) {
- ui->lblAutoQuit->setText(trUtf8("Auto logout in %1").arg(autoQuit_));
+ ui->lblAutoQuit->setText(tr("Auto logout in %1").arg(autoQuit_));
ui->lblAutoQuit->show();
} else if (!ui->lblAutoQuit->isHidden()) {
ui->lblAutoQuit->hide();
diff --git a/src/images.qrc b/src/images.qrc
index dda48f1..e12f639 100644
--- a/src/images.qrc
+++ b/src/images.qrc
@@ -23,7 +23,7 @@
<file alias="virtualbox">img/virtualbox.png</file>
<file alias="unknown">img/unknown.png</file>
<file alias="dosbox">img/dosbox.png</file>
- <file alias="qemu">img/qemu.png</file>
+ <file alias="qemukvm">img/qemukvm.png</file>
<file alias="mess">img/mess.png</file>
<file alias="beos">img/beos.png</file>
<file alias="os2">img/os2.png</file>
@@ -43,5 +43,6 @@
<file alias="dos">img/msdos.png</file>
<file alias="vm-mix">img/vm-mix.png</file>
<file alias="i3">img/i3.png</file>
+ <file alias="docker">img/docker.png</file>
</qresource>
</RCC>
diff --git a/src/img/docker.png b/src/img/docker.png
new file mode 100644
index 0000000..0dc6379
--- /dev/null
+++ b/src/img/docker.png
Binary files differ
diff --git a/src/img/qemu.png b/src/img/qemu.png
deleted file mode 100644
index fadac31..0000000
--- a/src/img/qemu.png
+++ /dev/null
Binary files differ
diff --git a/src/img/qemukvm.png b/src/img/qemukvm.png
new file mode 100644
index 0000000..03d3489
--- /dev/null
+++ b/src/img/qemukvm.png
Binary files differ
diff --git a/src/session.h b/src/session.h
index c3f758c..675aada 100644
--- a/src/session.h
+++ b/src/session.h
@@ -28,8 +28,8 @@ class Session {
if (!error.isEmpty()) {
if (showError) {
QMessageBox::critical(
- nullptr, QObject::trUtf8("vmchooser"),
- QObject::trUtf8("Cannot start selected session:") + QStringLiteral("\n") + error);
+ nullptr, QObject::tr("vmchooser"),
+ QObject::tr("Cannot start selected session:") + QStringLiteral("\n") + error);
}
return false;
}
diff --git a/src/userldapdata.cpp b/src/userldapdata.cpp
index 4382800..d4f966f 100644
--- a/src/userldapdata.cpp
+++ b/src/userldapdata.cpp
@@ -4,6 +4,7 @@
#include <QFile>
#include <QDebug>
#include <QDir>
+#include <QRegularExpression>
#define INCBREAK if (++i >= len) break
@@ -39,6 +40,7 @@ bool init(QString inputFile)
keyEnd = i;
INCBREAK;
if (p[i] == ':') {
+ // Double ":", means base64 encoded data
INCBREAK;
b64 = true;
}
@@ -53,6 +55,7 @@ bool init(QString inputFile)
while (dataLen > 0 && p[dataStart + dataLen - 1] == '\n') {
dataLen--;
}
+ // Put "lowercase(key):value" into set
QString value = QString::fromUtf8(p, keyEnd).toLower() + ":";
if (b64) {
value += QString::fromUtf8(QByteArray::fromBase64(QByteArray(p + dataStart, dataLen)));
@@ -71,8 +74,18 @@ bool isEmpty()
bool isAllowed(const QString& attribute, const QString& value)
{
- const QString keyLow(attribute.toLower() + ":" + value);
- return _entries.contains(keyLow);
+ if (value.indexOf(QLatin1Char('*')) == -1 && value.indexOf(QLatin1Char('?')) == -1) {
+ const QString keyLow(attribute.toLower() + QLatin1String(":") + value);
+ return _entries.contains(keyLow);
+ }
+ // Wildcard matching
+ QRegularExpression re(QLatin1String("^") + QRegularExpression::escape(attribute.toLower()) + QLatin1String(":")
+ + QRegularExpression::wildcardToRegularExpression(value));
+ for (auto str : _entries) {
+ if (re.match(str).hasMatch())
+ return true;
+ }
+ return false;
}
}
diff --git a/src/vsession.cpp b/src/vsession.cpp
index b61c759..a3334c8 100644
--- a/src/vsession.cpp
+++ b/src/vsession.cpp
@@ -104,27 +104,33 @@ QIcon VSession::icon() const {
return res_icon;
}
// Everything failed, try to guess the OS
- QString os(this->os().toLower());
- os = os.replace(cleanNameRegex, QString());
- if (!os.isEmpty()) {
+ QString os1(this->os().toLower());
+ QString os2(this->osDisplayName().toLower());
+ os1 = os1.replace(cleanNameRegex, QString());
+ os2 = os2.replace(cleanNameRegex, QString());
+ if (!os1.isEmpty() || !os2.isEmpty()) {
// Now try known good OS names via .startsWith()
for (const QString& str : directOsNames) {
- if (os.startsWith(str))
+ if (os1.startsWith(str) || os2.startsWith(str))
return iconHolder->getIcon(str);
}
// Fuzzy matching via regex
for (const IconMap& map : iconMapping) {
- if (map.expr.match(os).hasMatch())
+ if (map.expr.match(os1).hasMatch() || map.expr.match(os2).hasMatch())
return iconHolder->getIcon(map.icon);
}
// Running out of ideas...
- if (os.startsWith(QStringLiteral("win")))
+ if (os2.startsWith(QStringLiteral("win")))
return iconHolder->getIcon(QStringLiteral("windows"));
- if (os.contains(QStringLiteral("linux")))
+ if (os2.contains(QStringLiteral("linux")))
return iconHolder->getIcon(QStringLiteral("linux"));
}
// Fallback to generic virtualizer icon (if found)
- return iconHolder->getIcon(virtualizer());
+ QIcon ret = iconHolder->getIcon(virtualizer());
+ if (ret.isNull()) {
+ ret = QIcon(QPixmap(64, 64));
+ }
+ return ret;
}
QString VSession::toXml() const {
@@ -219,10 +225,10 @@ bool VSession::isLocked() const {
QString VSession::checkCanRunInternal() const {
if (getAttribute(QStringLiteral("image_name")).isEmpty())
- return QObject::trUtf8("XML error: image_name is empty");
+ return QObject::tr("XML error: image_name is empty");
const Virtualizer* virt = Virtualizer::get(virtualizer());
if (!virt->isAvailable)
- return QObject::trUtf8("Virtualizer '%1' is not enabled.").arg(virt->id);
+ return QObject::tr("Virtualizer '%1' is not enabled.").arg(virt->id);
// Seems OK
return QString();
}
@@ -247,8 +253,8 @@ bool VSession::prepareRun() const {
tmpfile.write(this->toXml().toUtf8()) == -1) {
qDebug() << "Error writing xml to file" << tmpfile.fileName();
QMessageBox::critical(
- nullptr, QObject::trUtf8("vmchooser"),
- QObject::trUtf8("Error writing temporary XML file for run-virt"));
+ nullptr, QObject::tr("vmchooser"),
+ QObject::tr("Error writing temporary XML file for run-virt"));
return false;
}
if (!tmpFileName.isEmpty()) {
diff --git a/src/vsession.h b/src/vsession.h
index e571805..af01230 100644
--- a/src/vsession.h
+++ b/src/vsession.h
@@ -47,6 +47,10 @@ class VSession : public Session {
return getAttribute(QStringLiteral("os"));
}
+ QString osDisplayName() const {
+ return getAttribute(QStringLiteral("os_name"));
+ }
+
QString uuid() const {
return getAttribute(QStringLiteral("uuid"));
}
diff --git a/src/xsession.cpp b/src/xsession.cpp
index 5db3b11..dcc9d22 100644
--- a/src/xsession.cpp
+++ b/src/xsession.cpp
@@ -128,7 +128,7 @@ QString XSession::checkCanRunInternal() const {
if (fi.isFile() && fi.isExecutable())
return QString();
// Not found
- return QObject::trUtf8("Binary %1 not found.").arg(exe);
+ return QObject::tr("Binary %1 not found.").arg(exe);
}
bool XSession::isLocked() const {
@@ -175,8 +175,9 @@ void XSession::run() const {
command += exec_;
qDebug() << "Running via /bin/sh:" << command;
QByteArray cmdbin = command.toUtf8();
- char *argv[4] = { "/bin/sh", "-c", cmdbin.data(), nullptr };
+ char * const argv[4] = { strdup("/bin/sh"), strdup("-c"), cmdbin.data(), nullptr };
execv("/bin/sh", argv);
+ // Caller will show error on failure to exec
}
int XSession::type() const {