summaryrefslogtreecommitdiffstats
path: root/src/vsession.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vsession.cpp')
-rw-r--r--src/vsession.cpp62
1 files changed, 33 insertions, 29 deletions
diff --git a/src/vsession.cpp b/src/vsession.cpp
index 79ef929..b61c759 100644
--- a/src/vsession.cpp
+++ b/src/vsession.cpp
@@ -21,8 +21,6 @@
#include "userldapdata.h"
#include "virtualizer.h"
-static QProcess _process;
-
static const QString VMWARE("vmware");
static const QString VIRTUALBOX("virtualbox");
@@ -65,6 +63,8 @@ static const QStringList directOsNames(
static const QRegularExpression cleanNameRegex("[^a-z0-9]");
+QString tmpFileName;
+
bool VSession::init(const QDomElement& xml) {
QDomElement settingsNode = this->doc_.createElement("settings");
this->doc_.appendChild(settingsNode);
@@ -238,44 +238,48 @@ int VSession::priority() const {
return prio;
}
-bool VSession::run() const {
- if (_process.state() != QProcess::NotRunning) {
- qDebug() << "Cannot start vsession while old one is still running";
+bool VSession::prepareRun() const {
+ if (!canRun(true))
return false;
- }
- if (g_debugMode) {
- qDebug() << "Sarting session " << shortDescription() << " ...";
- }
-
- if (g_noVtx && needsVtx()) {
- QMessageBox::warning(nullptr, QObject::trUtf8("Warning"),
- QObject::trUtf8("The selected session is based on a 64 bit operating system,"
- " but this computer doesn't seem to support this (VT-x/AMD-V not"
- " supported by CPU, or disabled in BIOS). You will probably get an"
- " error message while the virtualizer is initializing."));
- }
-
- QString command = getAttribute(QStringLiteral("command"));
- if (!command.isEmpty()) {
- return QProcess::startDetached(command);
- }
-
// write xml to temporary file
QTemporaryFile tmpfile(QDir::tempPath() + QStringLiteral("/vmchooser-XXXXXX.xml"));
if (!tmpfile.open() ||
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"));
return false;
}
- // Docs say we should call fileName() before closing to prevent deletion
- QString tmpFileName = tmpfile.fileName();
+ if (!tmpFileName.isEmpty()) {
+ QFile(tmpFileName).remove();
+ }
+ // Docs say we should call fileName() before closing, to prevent deletion
+ tmpFileName = tmpfile.fileName();
tmpfile.setAutoRemove(false);
tmpfile.close();
+ if (g_noVtx && needsVtx()) {
+ QMessageBox::StandardButton ret = QMessageBox::question(nullptr, QObject::tr("Warning"),
+ QObject::tr("The selected session is based on a 64 bit operating system,"
+ " but this computer doesn't seem to support this (VT-x/AMD-V not"
+ " supported by CPU, or disabled in BIOS). You will probably get an"
+ " error message while the virtualizer is initializing.\n\n"
+ "Do you still want to try to start this VM?"),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ if (ret != QMessageBox::Yes)
+ return false;
+ }
+ return true;
+}
- QObject::connect(&_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), QApplication::instance(), &QCoreApplication::quit);
- _process.start(Config::get(Config::RUNSCRIPT), QStringList(tmpFileName));
- _process.waitForStarted(10);
- return _process.state() == QProcess::Starting || _process.state() == QProcess::Running;
+void VSession::run() const {
+ if (g_debugMode) {
+ qDebug() << "Sarting session " << shortDescription() << " ...";
+ }
+ QByteArray fn = tmpFileName.toUtf8();
+ QByteArray script = Config::get(Config::RUNSCRIPT).toUtf8();
+ char *argv[3] = { script.data(), fn.data(), nullptr };
+ execv(script.data(), argv);
}
int VSession::type() const {