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 | |
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
-rw-r--r-- | src/virtualizer.cpp | 31 | ||||
-rw-r--r-- | src/virtualizer.h | 30 |
2 files changed, 61 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; +} diff --git a/src/virtualizer.h b/src/virtualizer.h new file mode 100644 index 0000000..7b3fc76 --- /dev/null +++ b/src/virtualizer.h @@ -0,0 +1,30 @@ +#ifndef _VIRTUALIZER_H_ +#define _VIRTUALIZER_H_ + +#include <QString> + +class Virtualizer +{ + +public: + /** + * Get instance representing given virtualizer. + * Never returns null. + */ + static const Virtualizer* get(const QString &id); + + /** + * The ID if the virtualizer + */ + const QString id; + /** + * Does a plugin exist for this virtualizer type? + */ + const bool isAvailable; + +private: + explicit Virtualizer(const QString &id); + +}; + +#endif |