summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/virtualizer.cpp31
-rw-r--r--src/virtualizer.h30
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