diff options
author | Simon Rettberg | 2019-07-09 11:34:34 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-07-09 11:34:34 +0200 |
commit | d13f6df5ec3566c8e6a999427fd302f74c4754ec (patch) | |
tree | 7b5ad4d4fb7a76aeb6923dd88aeee12f7f67e586 /src/virtualizer.cpp | |
parent | Gray out and warn about VMs with missing hypervisor (diff) | |
download | vmchooser2-d13f6df5ec3566c8e6a999427fd302f74c4754ec.tar.gz vmchooser2-d13f6df5ec3566c8e6a999427fd302f74c4754ec.tar.xz vmchooser2-d13f6df5ec3566c8e6a999427fd302f74c4754ec.zip |
asfdöklgjsdflgkjt
Diffstat (limited to 'src/virtualizer.cpp')
-rw-r--r-- | src/virtualizer.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/virtualizer.cpp b/src/virtualizer.cpp new file mode 100644 index 0000000..521f885 --- /dev/null +++ b/src/virtualizer.cpp @@ -0,0 +1,31 @@ +#include "virtualizer.h" +#include "config.h" + +#include <QMap> +#include <QProcess> + +static QMap<QString, Virtualizer*> virtMap; + +static bool query(const QString &id) { + static const QString runVirt = Config::get(Config::RUNSCRIPT); + QProcess proc; + proc.start(runVirt, QStringList() << QStringLiteral("--query") << id); + // XXX: This should really only take about a millisecond, but it could be made async too + // and then once the result arrives, redraw the TreeView. Since the result is cached + // per virtualizer, it doesn't seem worth the effort right now. + return proc.waitForFinished(1000) && proc.exitCode() == 0; +} + +Virtualizer::Virtualizer(const QString &id) + : id(id), isAvailable(query(id)) { + +} + +const Virtualizer* Virtualizer::get(const QString &id) { + if (virtMap.contains(id)) { + return virtMap[id]; + } + Virtualizer *v = new Virtualizer(id); + virtMap.insert(id, v); + return v; +} |