From ba3c5aa40274c11f9cefd4e9842be3488cad07b4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 15 Jun 2018 14:05:25 +0200 Subject: Fix indentation, cleanup, refactoring, deletions * Remove unused methods for adding hostname and user to xml * Avoid copying/(de)serializing XML a thousand times * Fix Session::isValid() or rather make it a bit more usable (although it's unused currently) * baseDir is global, not per VSession, which doesn't make any sense without the legacy approach of recusively loading one xml file per entry --- src/choosersettings.cpp | 62 ++--- src/choosersettings.h | 14 +- src/command_line_options.cpp | 6 +- src/dialog.cpp | 6 +- src/filedownloader.cpp | 64 ++--- src/httpxmldownloader.cpp | 18 +- src/httpxmldownloader.h | 10 +- src/main.cpp | 642 +++++++++++++++++++++---------------------- src/sessionsiconholder.cpp | 144 +++++----- src/sessionsiconholder.h | 18 +- src/vsession.cpp | 189 ++++--------- src/vsession.h | 10 +- src/xsession.cpp | 3 +- 13 files changed, 556 insertions(+), 630 deletions(-) (limited to 'src') diff --git a/src/choosersettings.cpp b/src/choosersettings.cpp index a67897e..36c9a0f 100644 --- a/src/choosersettings.cpp +++ b/src/choosersettings.cpp @@ -12,46 +12,46 @@ bool ChooserSettings::settingsLoaded = false; ChooserSettings* ChooserSettings::chooserSettings = NULL; ChooserSettings::ChooserSettings() { - // test (and make) directory - QDir saveFileDir(QFileInfo(previousSessionFile).absoluteDir()); - if (!saveFileDir.exists()) { - if (!saveFileDir.mkpath(saveFileDir.path())) { - return; - } - } - - settings = new QSettings(previousSessionFile, QSettings::IniFormat); - settings->setIniCodec("UTF-8"); - - if (settings->status() != QSettings::NoError) { - if (debugMode) { - qDebug() << "Settings: " << previousSessionFile << " contains erros."; - } - return; - } - - settingsLoaded = true; + // test (and make) directory + QDir saveFileDir(QFileInfo(previousSessionFile).absoluteDir()); + if (!saveFileDir.exists()) { + if (!saveFileDir.mkpath(saveFileDir.path())) { + return; + } + } + + settings = new QSettings(previousSessionFile, QSettings::IniFormat); + settings->setIniCodec("UTF-8"); + + if (settings->status() != QSettings::NoError) { + if (debugMode) { + qDebug() << "Settings: " << previousSessionFile << " contains erros."; + } + return; + } + + settingsLoaded = true; } ChooserSettings::~ChooserSettings() { - settings->deleteLater(); + settings->deleteLater(); } QString ChooserSettings::getSetting(QString key) { - if (!settingsLoaded) { - chooserSettings = new ChooserSettings(); - if (!settingsLoaded) return ""; - } + if (!settingsLoaded) { + chooserSettings = new ChooserSettings(); + if (!settingsLoaded) return ""; + } - return chooserSettings->settings->value(key).toString(); + return chooserSettings->settings->value(key).toString(); } bool ChooserSettings::setSetting(QString key, QString value) { - if (!settingsLoaded) { - chooserSettings = new ChooserSettings(); - if (!settingsLoaded) return false; - } - chooserSettings->settings->setValue(key, value); + if (!settingsLoaded) { + chooserSettings = new ChooserSettings(); + if (!settingsLoaded) return false; + } + chooserSettings->settings->setValue(key, value); // chooserSettings->settings->sync(); - return true; + return true; } diff --git a/src/choosersettings.h b/src/choosersettings.h index 28bf619..ea0bb76 100644 --- a/src/choosersettings.h +++ b/src/choosersettings.h @@ -15,17 +15,17 @@ // TODO: Proper name. This is the user specific settings, not global class ChooserSettings { public: - static QString getSetting(QString key); - static bool setSetting(QString key, QString value); + static QString getSetting(QString key); + static bool setSetting(QString key, QString value); private: - static ChooserSettings* chooserSettings; - static bool settingsLoaded; + static ChooserSettings* chooserSettings; + static bool settingsLoaded; - QSettings* settings; + QSettings* settings; - ChooserSettings(); - virtual ~ChooserSettings(); + ChooserSettings(); + virtual ~ChooserSettings(); }; #endif /* CHOOSERSETTINGS_H_ */ diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 818bc06..2018760 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -6,7 +6,7 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { // parse command line arguments (please sort by short option for easier handling) static const struct option longOptions[] = { - {"allow-vm-edit", no_argument, NULL, 'vmed'}, + {"allow-vm-edit", no_argument, NULL, 'vmed'}, {"autoquit", required_argument, NULL, 'aqit'}, {"base", required_argument, NULL, 'b'}, {"path", required_argument, NULL, 'b'}, // Compatibility to v1.0 @@ -114,8 +114,8 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { options.insert("uuid", optarg); break; case 'vmed': - options.insert("allow-vm-edit", ""); - break; + options.insert("allow-vm-edit", ""); + break; default: options.insert("error", "error"); break; diff --git a/src/dialog.cpp b/src/dialog.cpp index 926c65b..7e22962 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -52,7 +52,7 @@ Dialog::Dialog(int defaultTab, bool examMode, QWidget *parent) ui->treeView->setFocusProxy(ui->filterEdit); // ui->filterEdit->installEventFilter(this); - qApp->installEventFilter(this); + QCoreApplication::instance()->installEventFilter(this); ui->helpBox->hide(); ui->newsBox->hide(); @@ -286,7 +286,7 @@ bool Dialog::selectSession(const QString& name) { bool Dialog::selectSessionByUuid(const QString& name) { QModelIndex root(ui->treeView->rootIndex()); - for (int tab = 0; tab < TAB_COUNT; ++tab) { + for (int tab = 0; tab < TAB_COUNT; ++tab) { for (int i = 0; i < model_[tab]->rowCount(root); ++i) { QModelIndex section(model_[tab]->index(i, 0, root)); if (!section.isValid()) { @@ -405,7 +405,7 @@ void Dialog::onCenterTimer() { if (autoQuit_ > 0) { autoQuit_--; if (autoQuit_ == 0) { - qApp->exit(0); + QCoreApplication::instance()->exit(0); } else if (autoQuit_ < 60) { ui->lblAutoQuit->setText(this->trUtf8("Auto logout in %1").arg(autoQuit_)); ui->lblAutoQuit->show(); diff --git a/src/filedownloader.cpp b/src/filedownloader.cpp index 0af2544..7e2574b 100644 --- a/src/filedownloader.cpp +++ b/src/filedownloader.cpp @@ -15,7 +15,7 @@ static QNetworkAccessManager m_WebCtrl; FileDownloader::FileDownloader(const QUrl& fileUrl, QObject *parent) : - QObject(parent), started(false), url(fileUrl) { + QObject(parent), started(false), url(fileUrl) { } FileDownloader::~FileDownloader() { @@ -23,15 +23,15 @@ FileDownloader::~FileDownloader() { } bool FileDownloader::downloadFile() { - if (this->started) - return true; - QNetworkReply *reply = m_WebCtrl.get(QNetworkRequest(this->url)); - if (reply == NULL) - return false; - this->started = true; - connect(reply, SIGNAL(finished()), SLOT(fileDownloaded())); - connect(reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); - return true; + if (this->started) + return true; + QNetworkReply *reply = m_WebCtrl.get(QNetworkRequest(this->url)); + if (reply == NULL) + return false; + this->started = true; + connect(reply, SIGNAL(finished()), SLOT(fileDownloaded())); + connect(reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); + return true; } /* @@ -39,35 +39,35 @@ bool FileDownloader::downloadFile() { */ void FileDownloader::downloadFailed(QNetworkReply::NetworkError) { - QNetworkReply *reply = (QNetworkReply*)this->sender(); - killReply(reply); - emit downloaded(this->url, QByteArray()); + QNetworkReply *reply = (QNetworkReply*)this->sender(); + killReply(reply); + emit downloaded(this->url, QByteArray()); } void FileDownloader::fileDownloaded() { - QNetworkReply *reply = (QNetworkReply*)this->sender(); - if (reply == NULL) - return; - QByteArray downloadedData(reply->readAll()); - killReply(reply); - //emit a signal - emit downloaded(this->url, downloadedData); + QNetworkReply *reply = (QNetworkReply*)this->sender(); + if (reply == NULL) + return; + QByteArray downloadedData(reply->readAll()); + killReply(reply); + //emit a signal + emit downloaded(this->url, downloadedData); } void FileDownloader::downloadProgress(qint64 received, qint64 totalSize) { - QNetworkReply *reply = (QNetworkReply*)this->sender(); - if (reply == NULL) - return; - if (received > MAXSIZE || totalSize > MAXSIZE) { - killReply(reply); - emit downloaded(this->url, QByteArray()); - } + QNetworkReply *reply = (QNetworkReply*)this->sender(); + if (reply == NULL) + return; + if (received > MAXSIZE || totalSize > MAXSIZE) { + killReply(reply); + emit downloaded(this->url, QByteArray()); + } } void FileDownloader::killReply(QNetworkReply *reply) { - if (reply == NULL) - return; - reply->blockSignals(true); - reply->abort(); - reply->deleteLater(); + if (reply == NULL) + return; + reply->blockSignals(true); + reply->abort(); + reply->deleteLater(); } diff --git a/src/httpxmldownloader.cpp b/src/httpxmldownloader.cpp index 56b256e..c143995 100644 --- a/src/httpxmldownloader.cpp +++ b/src/httpxmldownloader.cpp @@ -4,19 +4,19 @@ #include HttpXmlDownloader::HttpXmlDownloader() { - nam = new QNetworkAccessManager(this); + nam = new QNetworkAccessManager(this); } QNetworkReply* HttpXmlDownloader::makeRequest(const QString& xmlurl, const QString& locationIds) { - QUrl url(xmlurl); - if (!locationIds.isEmpty()) { - QUrlQuery query(url); - query.addQueryItem("locations", locationIds); - url.setQuery(query); - } - return nam->get(QNetworkRequest(url)); + QUrl url(xmlurl); + if (!locationIds.isEmpty()) { + QUrlQuery query(url); + query.addQueryItem("locations", locationIds); + url.setQuery(query); + } + return nam->get(QNetworkRequest(url)); } void HttpXmlDownloader::connectSlot(QObject* obj, const char* slot) { - QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), obj, slot); + QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), obj, slot); } diff --git a/src/httpxmldownloader.h b/src/httpxmldownloader.h index 068a733..dbca643 100644 --- a/src/httpxmldownloader.h +++ b/src/httpxmldownloader.h @@ -8,12 +8,12 @@ #include class HttpXmlDownloader : public QObject { - Q_OBJECT - QNetworkAccessManager* nam; + Q_OBJECT + QNetworkAccessManager* nam; public: - HttpXmlDownloader(); - QNetworkReply* makeRequest(const QString& xmlurl, const QString& locationIds = QString()); - void connectSlot(QObject* obj, const char* slot); + HttpXmlDownloader(); + QNetworkReply* makeRequest(const QString& xmlurl, const QString& locationIds = QString()); + void connectSlot(QObject* obj, const char* slot); }; #endif /* HTTPTEST_H_ */ diff --git a/src/main.cpp b/src/main.cpp index 3e94d99..a8ce657 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,325 +22,325 @@ #include "choosersettings.h" int main(int argc, char *argv[]) { - QApplication a(argc, argv); - - QTranslator translator; - translator.load(":" + QLocale::system().name()); - a.installTranslator(&translator); - - CommandLineOptions cmdOptions(argc, argv); - - QString autostart_uuid(""); - - std::string usage( - a.translate("Console", "Usage: vmchooser [ OPTIONS ]\n\n" - " --allow-vm-edit show the 'edit this vm' checkbox\n" - " --autoquit [secs] automatically exit if no selection is made after secs seconds\n" - " -b --base base directory where VM images are accessible\n" - " -d, --default name of default session\n" - " -c, --config alternative config file\n" - " -l, --locations location id(s), space separated\n" - " --location-mode how to treat entries for this location (IGNORE, BUMP or EXCLUSIVE)\n" - " --exam-mode enable exam mode\n" - " -P, --pool one or more pool names to display (comma separated)\n" - " -f, --file direct boot .desktop file\n" - " -x, --xpath path of X Session .desktop files\n" - " -u, --url url of vmware .xml file\n" - " -s, --size window size x\n" - " -t, --theme theme\n" - " --template-mode how to treat template entries (IGNORE or BUMP)\n" - " -p, --pvs show pvs options\n" - " --pvs-checked check pvs box by default\n" - " -D, --debug print debug information\n" - " -v, --version print version and exit\n" - " -h, --help print usage information and exit\n" - " -S, --runscript change path to run-virt.sh\n" - " -T --tab default tab (0=xsession, 1=my vms, 2=all vms)\n" - " --no-vtx Host doesn't support VT-x/AMD-V (mark 64bit guests)\n" - " --start-uuid start lecture with the given uuid\n" - "\nFILE can be a vmware .xml or an X .desktop file\n").toUtf8().data()); - - if (cmdOptions.contains("error")) { - std::cerr << usage; - return EXIT_FAILURE; - } - - if (cmdOptions.contains("usage")) { - std::cout << usage; - return EXIT_SUCCESS; - } - - if (cmdOptions.contains("version")) { - std::cout << "vmchooser " << VMCHOOSER_VERSION << std::endl; - return EXIT_SUCCESS; - } - - if (cmdOptions.contains("uuid")) { - autostart_uuid = cmdOptions.value("uuid"); - } - - if (cmdOptions.contains("file")) { - QString file(cmdOptions.value("file")); - - if (file.endsWith(".desktop")) { - XSession s; - if (s.init(file) && s.run()) { - return EXIT_SUCCESS; - } - std::cerr - << a.translate("Console", - "vmchooser: failed to run session").toUtf8().constData() - << std::endl; - return EXIT_FAILURE; - } else { - std::cerr - << a.translate("Console", "vmchooser: invalid session file").toUtf8().constData() - << std::endl; - return EXIT_FAILURE; - } - } - - // read configuration file: - // file supplied as command line option or - // user vmchooser.conf or - // global vmchooser.conf - QString confFile; - if (cmdOptions.contains("config")) { - if (QFileInfo(cmdOptions.value("config")).exists()) { - confFile = cmdOptions.value("config"); - } else { - std::cerr << a.translate("Console", "Requested --config not found: ").toUtf8().constData() << cmdOptions.value("config").toUtf8().constData() << std::endl; - } - } - if (confFile.isEmpty() && QFileInfo(userConfFile).exists()) { - confFile = userConfFile; - std::cerr << a.translate("Console", "Using user specific config: ").toUtf8().constData() << userConfFile.toUtf8().constData() << std::endl; - } - if (confFile.isEmpty() && QFileInfo(globalConfFile).exists()) { - confFile = globalConfFile; - std::cerr << a.translate("Console", "Using global config: ").toUtf8().constData() << globalConfFile.toUtf8().constData() << std::endl; - } - if (confFile.isEmpty()) { - std::cerr << a.translate("Console", "No config file found or given").toUtf8().constData() << std::endl; - } - - // TODO: This is the system wide settings, give proper name - QSettings settings(confFile, QSettings::IniFormat); - settings.setIniCodec("UTF-8"); - - if (ChooserSettings::getSetting("last-session").isEmpty()) { - QString defaultSession; - if (cmdOptions.contains("default")) { - defaultSession = cmdOptions.value("default"); - } else if (settings.contains("default")) { - defaultSession = settings.value("default").toString(); - } - ChooserSettings::setSetting("last-session", defaultSession); - } - - if (cmdOptions.contains("xpath")) { - xSessionPath = cmdOptions.value("xpath"); - } else if (settings.contains("xpath")) { - xSessionPath = settings.value("xpath").toString(); - } // else keep default path - - if (cmdOptions.contains("url")) { - urlBase = cmdOptions.value("url"); - } else if (settings.contains("url")) { - urlBase = settings.value("url").toString(); - } else { - std::cerr - << a.translate("Console", "vmchooser: no URL given").toUtf8().data() - << std::endl; - return EXIT_FAILURE; - } - - // Change the runVmScript path - if (cmdOptions.contains("runscript")) { - runVmScript = cmdOptions.value("runscript"); - } else if (settings.contains("runscript")) { - runVmScript = settings.value("runscript").toString(); - } - - /* PARSE URL */ - if (!urlBase.startsWith("http://")) { - std::cerr - << a.translate("Console", "vmchooser: invalid URL").toUtf8().data() - << std::endl; - return EXIT_FAILURE; - } else { - if (!urlBase.endsWith("/")) { - urlBase += "/"; - } - } - - QString size; - int width = VMCHOOSER_DEFAULT_WIDTH, height = VMCHOOSER_DEFAULT_HEIGHT; - if (cmdOptions.contains("fullscreen")) { - size = "fullscreen"; - } else if (settings.contains("fullscreen")) { - size = "fullscreen"; - } else if (cmdOptions.contains("size")) { - size = cmdOptions.value("size"); - } else if (settings.contains("size")) { - size = settings.value("size").toString(); - } - - if (size != "fullscreen") { - QRegExp rx("^(\\d+)x(\\d+)$"); - if (rx.indexIn(size) != -1) { - QStringList list = rx.capturedTexts(); - width = list.value(1).toInt(); - height = list.value(2).toInt(); - } else if (!size.isEmpty()) { - std::cerr - << a.translate("Console", "vmchooser: invalid size argument").toUtf8().data() - << std::endl; - return EXIT_FAILURE; - } - } - - if (cmdOptions.contains("pool")) { - pool = cmdOptions.value("pool"); - } else if (settings.contains("pool")) { - pool = settings.value("pool").toString(); - } - - if (cmdOptions.contains("theme")) { - theme = cmdOptions.value("theme"); - } else if (settings.contains("theme")) { - theme = settings.value("theme").toString(); - } - - if (cmdOptions.contains("debugMode")) { - debugMode = true; - } - - if (cmdOptions.contains("base")) { - basePath = cmdOptions.value("base"); - } else if (settings.contains("base")) { - basePath = settings.value("base").toString(); - } else if (settings.contains("path")) { // Compatibility to v1.0 - basePath = settings.value("path").toString(); - } - - if (cmdOptions.contains("location-mode")) { - QString mode = cmdOptions.value("location-mode"); - if (mode == "IGNORE") { - g_forLocationHandling = LOCATION_IGNORE; - } else if (mode == "BUMP") { - g_forLocationHandling = LOCATION_BUMP; - } else if (mode == "EXCLUSIVE") { - g_forLocationHandling = LOCATION_EXCLUSIVE; - } else { - qDebug() << "Invalid location mode: " << mode; - QMessageBox::critical(NULL, "Error", "Invalid location mode: " + mode); - return 1; - } - } - - if (cmdOptions.contains("template-mode")) { - QString mode = cmdOptions.value("template-mode"); - if (mode == "IGNORE") { - g_templateHandling = LOCATION_IGNORE; - } else if (mode == "BUMP") { - g_templateHandling = LOCATION_BUMP; - } else { - qDebug() << "Invalid template mode: " << mode; - QMessageBox::critical(NULL, "Error", "Invalid template mode: " + mode); - return 1; - } - } - - int defaultTab = -1; - if (cmdOptions.contains("tab")) { - defaultTab = cmdOptions.value("tab").toInt(); - } - - QString locationIds; - if (cmdOptions.contains("locations")) { - locationIds = cmdOptions.value("locations"); - } - - if (cmdOptions.contains("no-vtx")) { - g_noVtx = true; - } - - if (cmdOptions.contains("pvs")) { - g_pvsEnabled = true; - } - if (cmdOptions.contains("pvs-checked")) { - g_pvsChecked = true; - } - - if (cmdOptions.contains("autoquit")) { - bool ok = false; - g_autoQuitSeconds = cmdOptions.value("autoquit").toInt(&ok, 10); - if (!ok) { - g_autoQuitSeconds = 0; - } - } - - g_allowVmEdit = cmdOptions.contains("allow-vm-edit"); - - /* read session files */ - QList xsessions(XSession::readSessions(xSessionPath)); - - Dialog w(defaultTab, cmdOptions.contains("exam-mode")); - - /* DOWNLOAD VSESSIONS */ - HttpXmlDownloader httpxmldownloader; - httpxmldownloader.connectSlot(&w, - SLOT(addSessionsAfterDownload(QNetworkReply*))); - - // read xml and add items later - if (cmdOptions.contains("exam-mode")) { - httpxmldownloader.makeRequest(urlBase + "list?exams=exam-mode", locationIds); - } else { - httpxmldownloader.makeRequest(urlBase + "list", locationIds); - } - - /* DOWNLOAD NEWS */ - HttpXmlDownloader news_downloader; - news_downloader.connectSlot(&w, SLOT(addNewsAfterDownload(QNetworkReply*))); - news_downloader.makeRequest(urlBase + "news"); - - /* DOWNLOAD HELP-SECTION */ - HttpXmlDownloader help_downloader; - help_downloader.connectSlot(&w, SLOT(addHelpAfterDownload(QNetworkReply*))); - help_downloader.makeRequest(urlBase + "help"); - - w.setTheme(); - - w.setWindowFlags(Qt::FramelessWindowHint); - - QRect desktopRect = QApplication::desktop()->availableGeometry(&w); - if (size == "fullscreen") { - width = desktopRect.width(); - height = desktopRect.height(); - _fullscreen = true; - } - - w.resize(width, height); - - if (xsessions.size()) { - qSort(xsessions.begin(), xsessions.end(), myLessThan); - w.addItems(xsessions, 0); - } - - w.show(); - - if (autostart_uuid != "") { - qDebug() << "using startSession() from main.cpp"; - w.startSession(autostart_uuid); - } - - - - // center dialog on primary screen - QPoint center = desktopRect.center(); - w.move(center.x() - w.width() * 0.5, center.y() - w.height() * 0.5); - a.setActiveWindow(&w); - - return a.exec(); + QApplication a(argc, argv); + + QTranslator translator; + translator.load(":" + QLocale::system().name()); + a.installTranslator(&translator); + + CommandLineOptions cmdOptions(argc, argv); + + QString autostart_uuid(""); + + std::string usage( + a.translate("Console", "Usage: vmchooser [ OPTIONS ]\n\n" + " --allow-vm-edit show the 'edit this vm' checkbox\n" + " --autoquit [secs] automatically exit if no selection is made after secs seconds\n" + " -b --base base directory where VM images are accessible\n" + " -d, --default name of default session\n" + " -c, --config alternative config file\n" + " -l, --locations location id(s), space separated\n" + " --location-mode how to treat entries for this location (IGNORE, BUMP or EXCLUSIVE)\n" + " --exam-mode enable exam mode\n" + " -P, --pool one or more pool names to display (comma separated)\n" + " -f, --file direct boot .desktop file\n" + " -x, --xpath path of X Session .desktop files\n" + " -u, --url url of vmware .xml file\n" + " -s, --size window size x\n" + " -t, --theme theme\n" + " --template-mode how to treat template entries (IGNORE or BUMP)\n" + " -p, --pvs show pvs options\n" + " --pvs-checked check pvs box by default\n" + " -D, --debug print debug information\n" + " -v, --version print version and exit\n" + " -h, --help print usage information and exit\n" + " -S, --runscript change path to run-virt.sh\n" + " -T --tab default tab (0=xsession, 1=my vms, 2=all vms)\n" + " --no-vtx Host doesn't support VT-x/AMD-V (mark 64bit guests)\n" + " --start-uuid start lecture with the given uuid\n" + "\nFILE can be a vmware .xml or an X .desktop file\n").toUtf8().data()); + + if (cmdOptions.contains("error")) { + std::cerr << usage; + return EXIT_FAILURE; + } + + if (cmdOptions.contains("usage")) { + std::cout << usage; + return EXIT_SUCCESS; + } + + if (cmdOptions.contains("version")) { + std::cout << "vmchooser " << VMCHOOSER_VERSION << std::endl; + return EXIT_SUCCESS; + } + + if (cmdOptions.contains("uuid")) { + autostart_uuid = cmdOptions.value("uuid"); + } + + if (cmdOptions.contains("file")) { + QString file(cmdOptions.value("file")); + + if (file.endsWith(".desktop")) { + XSession s; + if (s.init(file) && s.run()) { + return EXIT_SUCCESS; + } + std::cerr + << a.translate("Console", + "vmchooser: failed to run session").toUtf8().constData() + << std::endl; + return EXIT_FAILURE; + } else { + std::cerr + << a.translate("Console", "vmchooser: invalid session file").toUtf8().constData() + << std::endl; + return EXIT_FAILURE; + } + } + + // read configuration file: + // file supplied as command line option or + // user vmchooser.conf or + // global vmchooser.conf + QString confFile; + if (cmdOptions.contains("config")) { + if (QFileInfo(cmdOptions.value("config")).exists()) { + confFile = cmdOptions.value("config"); + } else { + std::cerr << a.translate("Console", "Requested --config not found: ").toUtf8().constData() << cmdOptions.value("config").toUtf8().constData() << std::endl; + } + } + if (confFile.isEmpty() && QFileInfo(userConfFile).exists()) { + confFile = userConfFile; + std::cerr << a.translate("Console", "Using user specific config: ").toUtf8().constData() << userConfFile.toUtf8().constData() << std::endl; + } + if (confFile.isEmpty() && QFileInfo(globalConfFile).exists()) { + confFile = globalConfFile; + std::cerr << a.translate("Console", "Using global config: ").toUtf8().constData() << globalConfFile.toUtf8().constData() << std::endl; + } + if (confFile.isEmpty()) { + std::cerr << a.translate("Console", "No config file found or given").toUtf8().constData() << std::endl; + } + + // TODO: This is the system wide settings, give proper name + QSettings settings(confFile, QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + + if (ChooserSettings::getSetting("last-session").isEmpty()) { + QString defaultSession; + if (cmdOptions.contains("default")) { + defaultSession = cmdOptions.value("default"); + } else if (settings.contains("default")) { + defaultSession = settings.value("default").toString(); + } + ChooserSettings::setSetting("last-session", defaultSession); + } + + if (cmdOptions.contains("xpath")) { + xSessionPath = cmdOptions.value("xpath"); + } else if (settings.contains("xpath")) { + xSessionPath = settings.value("xpath").toString(); + } // else keep default path + + if (cmdOptions.contains("url")) { + urlBase = cmdOptions.value("url"); + } else if (settings.contains("url")) { + urlBase = settings.value("url").toString(); + } else { + std::cerr + << a.translate("Console", "vmchooser: no URL given").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } + + // Change the runVmScript path + if (cmdOptions.contains("runscript")) { + runVmScript = cmdOptions.value("runscript"); + } else if (settings.contains("runscript")) { + runVmScript = settings.value("runscript").toString(); + } + + /* PARSE URL */ + if (!urlBase.startsWith("http://")) { + std::cerr + << a.translate("Console", "vmchooser: invalid URL").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } else { + if (!urlBase.endsWith("/")) { + urlBase += "/"; + } + } + + QString size; + int width = VMCHOOSER_DEFAULT_WIDTH, height = VMCHOOSER_DEFAULT_HEIGHT; + if (cmdOptions.contains("fullscreen")) { + size = "fullscreen"; + } else if (settings.contains("fullscreen")) { + size = "fullscreen"; + } else if (cmdOptions.contains("size")) { + size = cmdOptions.value("size"); + } else if (settings.contains("size")) { + size = settings.value("size").toString(); + } + + if (size != "fullscreen") { + QRegExp rx("^(\\d+)x(\\d+)$"); + if (rx.indexIn(size) != -1) { + QStringList list = rx.capturedTexts(); + width = list.value(1).toInt(); + height = list.value(2).toInt(); + } else if (!size.isEmpty()) { + std::cerr + << a.translate("Console", "vmchooser: invalid size argument").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } + } + + if (cmdOptions.contains("pool")) { + pool = cmdOptions.value("pool"); + } else if (settings.contains("pool")) { + pool = settings.value("pool").toString(); + } + + if (cmdOptions.contains("theme")) { + theme = cmdOptions.value("theme"); + } else if (settings.contains("theme")) { + theme = settings.value("theme").toString(); + } + + if (cmdOptions.contains("debugMode")) { + debugMode = true; + } + + if (cmdOptions.contains("base")) { + basePath = cmdOptions.value("base"); + } else if (settings.contains("base")) { + basePath = settings.value("base").toString(); + } else if (settings.contains("path")) { // Compatibility to v1.0 + basePath = settings.value("path").toString(); + } + + if (cmdOptions.contains("location-mode")) { + QString mode = cmdOptions.value("location-mode"); + if (mode == "IGNORE") { + g_forLocationHandling = LOCATION_IGNORE; + } else if (mode == "BUMP") { + g_forLocationHandling = LOCATION_BUMP; + } else if (mode == "EXCLUSIVE") { + g_forLocationHandling = LOCATION_EXCLUSIVE; + } else { + qDebug() << "Invalid location mode: " << mode; + QMessageBox::critical(NULL, "Error", "Invalid location mode: " + mode); + return 1; + } + } + + if (cmdOptions.contains("template-mode")) { + QString mode = cmdOptions.value("template-mode"); + if (mode == "IGNORE") { + g_templateHandling = LOCATION_IGNORE; + } else if (mode == "BUMP") { + g_templateHandling = LOCATION_BUMP; + } else { + qDebug() << "Invalid template mode: " << mode; + QMessageBox::critical(NULL, "Error", "Invalid template mode: " + mode); + return 1; + } + } + + int defaultTab = -1; + if (cmdOptions.contains("tab")) { + defaultTab = cmdOptions.value("tab").toInt(); + } + + QString locationIds; + if (cmdOptions.contains("locations")) { + locationIds = cmdOptions.value("locations"); + } + + if (cmdOptions.contains("no-vtx")) { + g_noVtx = true; + } + + if (cmdOptions.contains("pvs")) { + g_pvsEnabled = true; + } + if (cmdOptions.contains("pvs-checked")) { + g_pvsChecked = true; + } + + if (cmdOptions.contains("autoquit")) { + bool ok = false; + g_autoQuitSeconds = cmdOptions.value("autoquit").toInt(&ok, 10); + if (!ok) { + g_autoQuitSeconds = 0; + } + } + + g_allowVmEdit = cmdOptions.contains("allow-vm-edit"); + + /* read session files */ + QList xsessions(XSession::readSessions(xSessionPath)); + + Dialog w(defaultTab, cmdOptions.contains("exam-mode")); + + /* DOWNLOAD VSESSIONS */ + HttpXmlDownloader httpxmldownloader; + httpxmldownloader.connectSlot(&w, + SLOT(addSessionsAfterDownload(QNetworkReply*))); + + // read xml and add items later + if (cmdOptions.contains("exam-mode")) { + httpxmldownloader.makeRequest(urlBase + "list?exams=exam-mode", locationIds); + } else { + httpxmldownloader.makeRequest(urlBase + "list", locationIds); + } + + /* DOWNLOAD NEWS */ + HttpXmlDownloader news_downloader; + news_downloader.connectSlot(&w, SLOT(addNewsAfterDownload(QNetworkReply*))); + news_downloader.makeRequest(urlBase + "news"); + + /* DOWNLOAD HELP-SECTION */ + HttpXmlDownloader help_downloader; + help_downloader.connectSlot(&w, SLOT(addHelpAfterDownload(QNetworkReply*))); + help_downloader.makeRequest(urlBase + "help"); + + w.setTheme(); + + w.setWindowFlags(Qt::FramelessWindowHint); + + QRect desktopRect = QApplication::desktop()->availableGeometry(&w); + if (size == "fullscreen") { + width = desktopRect.width(); + height = desktopRect.height(); + _fullscreen = true; + } + + w.resize(width, height); + + if (xsessions.size()) { + qSort(xsessions.begin(), xsessions.end(), myLessThan); + w.addItems(xsessions, 0); + } + + w.show(); + + if (autostart_uuid != "") { + qDebug() << "using startSession() from main.cpp"; + w.startSession(autostart_uuid); + } + + + + // center dialog on primary screen + QPoint center = desktopRect.center(); + w.move(center.x() - w.width() * 0.5, center.y() - w.height() * 0.5); + a.setActiveWindow(&w); + + return a.exec(); } diff --git a/src/sessionsiconholder.cpp b/src/sessionsiconholder.cpp index 61616ad..872df07 100644 --- a/src/sessionsiconholder.cpp +++ b/src/sessionsiconholder.cpp @@ -22,88 +22,88 @@ SessionsIconHolder* SessionsIconHolder::instance = NULL; static inline QString url2filename(const QString& url) { - return iconsTempPath + QString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex()); + return iconsTempPath + QString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex()); } SessionsIconHolder::SessionsIconHolder() { - QDir().mkpath(iconsTempPath); + QDir().mkpath(iconsTempPath); } void SessionsIconHolder::afterDownload(const QUrl& url, const QByteArray& downloadedData) { - // save the data to disk - QString strUrl(url.toString()); - QString file_path(url2filename(strUrl)); - QFile file(file_path); - if (!file.open(QFile::WriteOnly)) { - if (debugMode) { - qDebug() << "Could not write file: " << file_path; - } - return; - } - file.write(downloadedData); - - if (file.write(downloadedData) != downloadedData.length()) { - if (debugMode) { - qDebug() << "Could not write file: " << file_path; - } - return; - } - - file.close(); - - QIcon icon(file_path); - icons.insert(strUrl, icon); - - emit iconDownloaded(url, icon); + // save the data to disk + QString strUrl(url.toString()); + QString file_path(url2filename(strUrl)); + QFile file(file_path); + if (!file.open(QFile::WriteOnly)) { + if (debugMode) { + qDebug() << "Could not write file: " << file_path; + } + return; + } + file.write(downloadedData); + + if (file.write(downloadedData) != downloadedData.length()) { + if (debugMode) { + qDebug() << "Could not write file: " << file_path; + } + return; + } + + file.close(); + + QIcon icon(file_path); + icons.insert(strUrl, icon); + + emit iconDownloaded(url, icon); } QIcon SessionsIconHolder::getIcon(const QString& name) { - // check if icon was loaded before - if (icons.contains(name)) { - return icons[name]; - } - - // else load icon from resource - QIcon icon; - QString resName(":" + name.toLower()); - if (QResource(resName).isValid()) { - icon = QIcon(resName); - } else if (QFileInfo(name).isAbsolute() && QFile::exists(name)) { - // absolute icon path and file exists - icon = QIcon(name); - } else { - icon = QIcon(); - } - - // insert icon to hash table - icons.insert(name, icon); - return icon; + // check if icon was loaded before + if (icons.contains(name)) { + return icons[name]; + } + + // else load icon from resource + QIcon icon; + QString resName(":" + name.toLower()); + if (QResource(resName).isValid()) { + icon = QIcon(resName); + } else if (QFileInfo(name).isAbsolute() && QFile::exists(name)) { + // absolute icon path and file exists + icon = QIcon(name); + } else { + icon = QIcon(); + } + + // insert icon to hash table + icons.insert(name, icon); + return icon; } QIcon SessionsIconHolder::getIcon(const QUrl& url) { - // check if icon was loaded before - if (icons.contains(url.toString())) { - return icons[url.toString()]; - } - - // search the icon in the tmp folder - QString strUrl(url.toString()); - QString file_path(url2filename(strUrl)); - - if (QFile::exists(file_path)) { - QIcon icon(file_path); - icons.insert(strUrl, icon); - return icon; - } - // Put empty icon in map while we're downloading, so successive calls won't trigger - // more downloads before the running download finishes - icons.insert(strUrl, QIcon()); - - // else load icon from url - FileDownloader* fileDownloader = new FileDownloader(url, this); - QObject::connect(fileDownloader, SIGNAL(downloaded(const QUrl&, const QByteArray&)), - this, SLOT(afterDownload(const QUrl&, const QByteArray&))); - fileDownloader->downloadFile(); - - return QIcon(); + // check if icon was loaded before + if (icons.contains(url.toString())) { + return icons[url.toString()]; + } + + // search the icon in the tmp folder + QString strUrl(url.toString()); + QString file_path(url2filename(strUrl)); + + if (QFile::exists(file_path)) { + QIcon icon(file_path); + icons.insert(strUrl, icon); + return icon; + } + // Put empty icon in map while we're downloading, so successive calls won't trigger + // more downloads before the running download finishes + icons.insert(strUrl, QIcon()); + + // else load icon from url + FileDownloader* fileDownloader = new FileDownloader(url, this); + QObject::connect(fileDownloader, SIGNAL(downloaded(const QUrl&, const QByteArray&)), + this, SLOT(afterDownload(const QUrl&, const QByteArray&))); + fileDownloader->downloadFile(); + + return QIcon(); } diff --git a/src/sessionsiconholder.h b/src/sessionsiconholder.h index 3284bf7..8935606 100644 --- a/src/sessionsiconholder.h +++ b/src/sessionsiconholder.h @@ -22,23 +22,23 @@ class SessionTreeModel; class SessionsIconHolder : public QObject { - Q_OBJECT + Q_OBJECT private: - QHash icons; - SessionsIconHolder(); - static SessionsIconHolder* instance; + QHash icons; + SessionsIconHolder(); + static SessionsIconHolder* instance; signals: - void iconDownloaded(const QUrl& url, const QIcon& icon); + void iconDownloaded(const QUrl& url, const QIcon& icon); public: - QIcon getIcon(const QString& name); - QIcon getIcon(const QUrl& url); - static SessionsIconHolder* get() { if (instance == NULL) instance = new SessionsIconHolder(); return instance; } + QIcon getIcon(const QString& name); + QIcon getIcon(const QUrl& url); + static SessionsIconHolder* get() { if (instance == NULL) instance = new SessionsIconHolder(); return instance; } public slots: - void afterDownload(const QUrl& url, const QByteArray& downloadedData); + void afterDownload(const QUrl& url, const QByteArray& downloadedData); }; #endif /* SESSIONSICONHOLDER_H_ */ diff --git a/src/vsession.cpp b/src/vsession.cpp index c22e1bd..6344ec8 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -7,21 +7,21 @@ #include #include #include -#if 0 #include // available since Qt 4.7 -#endif -#include // for HOST_NAME_MAX -#include // for gethostname(), getuid() -#include // for getuid, getpwuid -#include // for getpwuid +#include // for getuid() +#include // for getuid(), getpwuid() +#include // for getpwuid() #include "globals.h" #include "vsession.h" #include "sessionsiconholder.h" -bool VSession::init(const QString& xml, const QString& baseDirPath) { - this->baseDirPath_ = baseDirPath; - _process = new QProcess(); - return this->doc_.setContent(xml); +static QProcess _process; + +bool VSession::init(const QDomElement& xml) { + QDomElement settingsNode = this->doc_.createElement("settings"); + this->doc_.appendChild(settingsNode); + eintrag_ = this->doc_.importNode(xml, true).toElement(); + return !settingsNode.appendChild(eintrag_).isNull() && !settingsNode.isNull(); } void VSession::addNodeWithAttribute(const QString& nodeName, @@ -29,12 +29,12 @@ void VSession::addNodeWithAttribute(const QString& nodeName, const QString& attribute, bool replace) { QDomElement node = - this->doc_.namedItem("eintrag").namedItem(nodeName).toElement(); + eintrag_.firstChildElement(nodeName); if (replace == false || node.isNull()) { // create a new node node = this->doc_.createElement(nodeName); - this->doc_.namedItem("eintrag").appendChild(node); + eintrag_.appendChild(node); } node.setAttribute(attribute, value); @@ -94,24 +94,29 @@ QIcon VSession::icon() const { } QString VSession::toXml() const { - QDomDocument doc; - doc.appendChild(doc.createElement("settings")); - - doc.firstChild().appendChild(doc.importNode(doc_.documentElement(), true)); + QDomDocument doc(doc_); QDomNode xmlNode = doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\""); doc.insertBefore(xmlNode, doc.firstChild()); - + QString image(this->getAttribute("image_name")); + QDomElement path = doc.firstChildElement("settings") + .firstChildElement("eintrag") + .appendChild(doc.createElement("image_path")) + .toElement(); + if (QFileInfo(image).isRelative()) { + // make path to image absolute + path.setAttribute("param", basePath + "/" + image); + } else { + path.setAttribute("param", image); + } return doc.toString(); } QString VSession::getAttribute(const QString &nodeName, const QString &attribute) const { - QDomDocument doc = this->doc_; - QDomNode n = doc.namedItem("eintrag").namedItem(nodeName); - return this->doc_.namedItem("eintrag").namedItem(nodeName).toElement() - .attribute(attribute); + QDomNode n = eintrag_.firstChildElement(nodeName); + return eintrag_.firstChildElement(nodeName).attribute(attribute); } QList VSession::keywords() const { @@ -119,7 +124,7 @@ QList VSession::keywords() const { } void VSession::readKeywords() { - QDomNode keywordsNode = this->doc_.namedItem("eintrag").namedItem("keywords"); + QDomNode keywordsNode = eintrag_.namedItem("keywords"); for (QDomElement el(keywordsNode.firstChildElement("keyword")); !el.isNull(); el = el.nextSiblingElement("keyword")) { @@ -216,8 +221,7 @@ bool VSession::isLocked() const { } bool VSession::isValid() const { - // default to false - return QFile::exists(QString(this->baseDirPath_).append("/").append(getAttribute("image_name"))); + return !getAttribute("image_name").isEmpty(); } int VSession::priority() const { @@ -231,90 +235,21 @@ int VSession::priority() const { return prio; } -void VSession::addUserAndHostname() { - QString username(getpwuid(geteuid())->pw_name); - this->addNodeWithAttribute("username", username); - - // Qt >= 4.7 has - // QString hostname(QHostInfo::localHostName()); - char hname[HOST_NAME_MAX + 1]; - QString hostname; - if (gethostname(hname, HOST_NAME_MAX) == 0) { - hostname = QString::fromUtf8(hname); - } else { - hostname = QString::fromUtf8("unknown-%1").arg(qrand()); - } - this->addNodeWithAttribute("hostname", hostname); - - QString image(this->getAttribute("image_name")); - if (QFileInfo(image).isRelative()) { - // make path to image absolute - this->addNodeWithAttribute("image_path", - this->baseDirPath_ + "/" + image); - } else { - this->addNodeWithAttribute("image_path", image); - } - - // insert computername as the first child of - // bootpgm needs computername within the first 500 bytes - QDomElement computername(doc_.createElement("computername")); - computername.setAttribute("param", hostname.append("-%1").arg(qrand())); - this->doc_.namedItem("eintrag").insertBefore(computername, QDomNode()); -} - -void VSession::mergePoolXml() { - QDomDocument doc; - - QString poolXmlFile = etcPath + "/vmchooser-" + pool + ".xml"; - - QFile file(poolXmlFile); - if (!file.open(QIODevice::ReadOnly)) { - return; - } - if (!doc.setContent(&file)) { - file.close(); - return; - } - file.close(); - - for (QDomElement envNode(doc.firstChildElement("environment")); - !envNode.isNull(); - envNode = envNode.nextSiblingElement()) { - if (envNode.attribute("param") != pool) continue; - - for (QDomElement typeNode(envNode.firstChildElement()); - !typeNode.isNull(); - typeNode = typeNode.nextSiblingElement()) { - QString type = typeNode.nodeName(); - if (type != "shared_folders" && - type != "printers" && - type != "scanners") continue; - - QDomElement destinationNode = - this->doc_.namedItem("eintrag").namedItem(type).toElement(); - - if (destinationNode.isNull()) { - // create new node - destinationNode = this->doc_.createElement(type); - this->doc_.namedItem("eintrag").appendChild(destinationNode); - } - - for (QDomElement el(typeNode.firstChildElement()); - !el.isNull(); - el = el.nextSiblingElement()) { - destinationNode.appendChild(this->doc_.importNode(el, true)); - } - } - } -} - bool VSession::run() const { + if (_process.state() != QProcess::NotRunning) { + qDebug() << "Cannot start vsession while old one is still running"; + return false; + } if (debugMode) { qDebug() << "Sarting session " << this->getAttribute("short_description", "param") << " ..."; } if (g_noVtx && is64Bit()) { - QMessageBox::warning(NULL, 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.")); + QMessageBox::warning(NULL, 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("command"); @@ -322,24 +257,22 @@ bool VSession::run() const { return QProcess::startDetached(command); } - VSession session = *this; - - session.addUserAndHostname(); - - session.mergePoolXml(); - // write xml to temporary file QTemporaryFile tmpfile(QDir::tempPath() + "/vmchooser-XXXXXX.xml"); if (!tmpfile.open() || - tmpfile.write(session.toXml().toUtf8()) == -1) { + tmpfile.write(this->toXml().toUtf8()) == -1) { + qDebug() << "Error writing xml to file" << tmpfile.fileName(); return false; } - tmpfile.close(); + // Docs say we should call fileName() before closing to prevent deletion + QString tmpFileName = tmpfile.fileName(); tmpfile.setAutoRemove(false); + tmpfile.close(); - _process->start(runVmScript, QStringList(tmpfile.fileName())); - QObject::connect(_process, SIGNAL(finished(int, QProcess::ExitStatus)), QApplication::instance(), SLOT(quit())); - if (_process->state() == QProcess::Starting || _process->state() == QProcess::Running) + QObject::connect(&_process, SIGNAL(finished(int, QProcess::ExitStatus)), QApplication::instance(), SLOT(quit())); + _process.start(runVmScript, QStringList(tmpFileName)); + _process.waitForStarted(10); + if (_process.state() == QProcess::Starting || _process.state() == QProcess::Running) return true; else return false; @@ -350,7 +283,7 @@ int VSession::type() const { } QList VSession::readXmlFile(const QString& filepath) { - QList retval; + QList sessionList; QDomDocument doc; QFile file(filepath); @@ -360,7 +293,7 @@ QList VSession::readXmlFile(const QString& filepath) { if (debugMode) { qDebug() << "Cannot read file: " << file.fileName(); } - return retval; + return sessionList; } if (!doc.setContent(&file)) { @@ -375,7 +308,7 @@ QList VSession::readXmlFile(const QString& filepath) { if (debugMode) { qDebug() << "Cannot read backup file " << xml_filename << " either"; } - return retval; + return sessionList; } if (!doc.setContent(&backup_file)) { @@ -383,7 +316,7 @@ QList VSession::readXmlFile(const QString& filepath) { qDebug() << "XML file not valid: " << backup_file.fileName(); } backup_file.close(); - return retval; + return sessionList; } if (debugMode) { @@ -404,30 +337,26 @@ QList VSession::readXmlFile(const QString& filepath) { } } - QString dirName; - if (basePath.isEmpty()) { - dirName = QFileInfo(xml_filename).dir().absolutePath(); - } else { - dirName = basePath; - } QDomElement settingsNode = doc.firstChildElement("settings"); for (QDomElement el(settingsNode.firstChildElement("eintrag")); !el.isNull(); el = el.nextSiblingElement("eintrag")) { - QDomDocument dummy; - dummy.appendChild(dummy.importNode(el, true)); VSession* e = new VSession; - if (e->init(dummy.toString(), dirName) && e->isActive()) { + if (e->init(el) && e->isActive()) { e->readKeywords(); - retval.append(e); + sessionList.append(e); + } else { + delete e; } } - return retval; + return sessionList; } bool VSession::is64Bit() const { - return imgtype() == VMWARE && getAttribute("os").endsWith("64"); - // TODO: vmbox, qemu-kvm, ... + ImgType type = imgtype(); + return (type == VMWARE && getAttribute("os").endsWith("-64")) + || (type == VBOX && getAttribute("os").endsWith("_64")); + // TODO: qemu-kvm, ... } QVariant VSession::foregroundRole() const { diff --git a/src/vsession.h b/src/vsession.h index 2ded3ae..bd0f7a2 100644 --- a/src/vsession.h +++ b/src/vsession.h @@ -5,7 +5,6 @@ #include #include #include -#include #include "session.h" #include "httpxmldownloader.h" @@ -17,7 +16,7 @@ enum ImgType { class VSession : public Session { public: - bool init(const QString& xml, const QString& baseDirPath); + bool init(const QDomElement& xml); ImgType imgtype() const; bool isActive() const; @@ -79,8 +78,6 @@ class VSession : public Session { const QString& value, const QString& attribute = "param", bool replace = true); - void addUserAndHostname(); - void mergePoolXml(); QString toXml() const; @@ -97,11 +94,10 @@ class VSession : public Session { private: QList keywords_; QDomDocument doc_; - QString baseDirPath_; - - QProcess *_process; + QDomElement eintrag_; void readKeywords(); + }; #endif /*VMCHOOSER_VSESSION_H_*/ diff --git a/src/xsession.cpp b/src/xsession.cpp index 3583079..0c41136 100644 --- a/src/xsession.cpp +++ b/src/xsession.cpp @@ -76,7 +76,8 @@ bool XSession::isActive() const { } bool XSession::isValid() const { - return true; + QFileInfo fi(this->exec_); + return !fi.isAbsolute() || (fi.isFile() && fi.isExecutable()); } bool XSession::isLocked() const { -- cgit v1.2.3-55-g7522