summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNils Schwabe2014-03-19 17:48:16 +0100
committerNils Schwabe2014-03-19 17:48:16 +0100
commitba34b15fddcd16b82338a2d88b7aee8a1654af1f (patch)
tree5c412e3d6d0f7014538877b60b4954ab523e8428 /src
parent- changed dialog desgin (diff)
downloadvmchooser2-ba34b15fddcd16b82338a2d88b7aee8a1654af1f.tar.gz
vmchooser2-ba34b15fddcd16b82338a2d88b7aee8a1654af1f.tar.xz
vmchooser2-ba34b15fddcd16b82338a2d88b7aee8a1654af1f.zip
removed the file and path option for XMLs
Diffstat (limited to 'src')
-rw-r--r--src/command_line_options.cpp6
-rw-r--r--src/dialog.cpp22
-rw-r--r--src/globals.cpp7
-rw-r--r--src/globals.h6
-rw-r--r--src/main.cpp41
-rw-r--r--src/sessionsiconholder.cpp4
-rw-r--r--src/vsession.cpp75
7 files changed, 36 insertions, 125 deletions
diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp
index baeca05..9ac099f 100644
--- a/src/command_line_options.cpp
+++ b/src/command_line_options.cpp
@@ -9,7 +9,6 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) {
{"default", required_argument, NULL, 'd'},
{"env", required_argument, NULL, 'e'},
{"file", required_argument, NULL, 'f'},
- {"path", required_argument, NULL, 'p'},
{"xpath", required_argument, NULL, 'x'},
{"url", required_argument, NULL, 'u'},
{"size", required_argument, NULL, 's'},
@@ -23,7 +22,7 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) {
int c;
- while ((c = getopt_long(argc, argv, "c:d:e:f:p:x:u:s:t:w:vhbD", longOptions, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "c:d:e:f:x:u:s:t:w:vhbD", longOptions, NULL)) != -1) {
switch (c) {
case 'c':
options.insert("config", optarg);
@@ -40,9 +39,6 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) {
case 'e':
options.insert("env", optarg);
break;
- case 'p':
- options.insert("path", optarg);
- break;
case 'x':
options.insert("xpath", optarg);
break;
diff --git a/src/dialog.cpp b/src/dialog.cpp
index b156231..3adfef6 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -262,19 +262,16 @@ void Dialog::onCenterTimer() {
}
void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
- QString filename = "/tmp/vmchooser2.xml";
- QString backup_filename = "/tmp/vmchooser2_backup.xml";
-
if (reply->error() != QNetworkReply::NoError) {
if (debugMode) {
qDebug() << "Error reading from URL: " << reply->error();
}
- QFile backup_file(backup_filename);
+ QFile backup_file(xml_backup_filename);
if (!backup_file.open(QIODevice::ReadOnly)) {
if (debugMode) {
- qDebug() << "Cannot read backup file " << backup_filename << " either";
+ qDebug() << "Cannot read backup file " << xml_backup_filename << " either";
}
this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."),QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
@@ -282,19 +279,24 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
}
if (debugMode) {
- qDebug() << "Used backup file " << backup_filename;
+ qDebug() << "Used backup file " << xml_backup_filename;
}
backup_file.close();
- this->addItems(VSession::readXmlFile(backup_filename), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
+
+ QList<Session*> sessions = VSession::readXmlFile(xml_backup_filename);
+
+ qSort(sessions.begin(), sessions.end(), myLessThan);
+
+ this->addItems(sessions, QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
} else {
- QFile file(filename);
+ QFile file(xml_filename);
if (!file.open(QIODevice::WriteOnly)) {
if (debugMode) {
- qDebug() << "Could not write XML to " << filename;
+ qDebug() << "Could not write XML to " << xml_filename;
}
return;
}
@@ -308,7 +310,7 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
file.close();
}
- const QList<Session*> sessions = VSession::readXmlFile(filename);
+ const QList<Session*> sessions = VSession::readXmlFile(xml_filename);
this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."),QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
diff --git a/src/globals.cpp b/src/globals.cpp
index 4f6ad81..92026b8 100644
--- a/src/globals.cpp
+++ b/src/globals.cpp
@@ -1,6 +1,7 @@
#include <QDir>
#include <QString>
#include "globals.h"
+#include "session.h"
//QString binPath(QApplication::applicationDirPath());
QString binPath(VMCHOOSER_BIN_PATH);
@@ -26,3 +27,9 @@ QString pool;
QString theme;
const QString iconsTempPath("/tmp/vmchooser2/icons/");
+const QString xml_backup_filename("/tmp/vmchooser2/vmchooser2_backup.xml");
+const QString xml_filename("/tmp/vmchooser2/vmchooser2.xml");
+
+bool myLessThan(Session* a, Session* b) {
+ return *a < *b;
+}
diff --git a/src/globals.h b/src/globals.h
index c3a39ff..8215c19 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -19,6 +19,7 @@
#define OPENSLXCONFIG "/opt/openslx/config"
class QString;
+class Session;
extern bool debugMode;
extern bool pvsEnabled;
@@ -43,7 +44,10 @@ extern const QString previousSessionFile;
extern QString pool;
extern QString theme;
-// tmp folders
extern const QString iconsTempPath;
+extern const QString xml_backup_filename;
+extern const QString xml_filename;
+
+bool myLessThan(Session* a, Session* b);
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 207f36e..9acc10e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -20,10 +20,6 @@
#include "xsession.h"
#include "httpxmldownloader.h"
-bool myLessThan(Session* a, Session* b) {
- return *a < *b;
-}
-
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
@@ -39,8 +35,7 @@ int main(int argc, char *argv[]) {
" -d, --default name of default session\n"
" -c, --config alternative config file\n"
" -e, --env name of the environment\n"
- " -f, --file direct boot FILE\n"
- " -p, --path path to vmware .xml files\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 <width>x<height>\n"
@@ -80,17 +75,6 @@ int main(int argc, char *argv[]) {
"vmchooser: failed to run session").toUtf8().data() <<
std::endl;
return EXIT_FAILURE;
- } else if (file.endsWith(".xml")) {
- // our XML-files can contain multiple sessions
- // let's just take the first one
- Session* s(VSession::readXmlFile(file).value(0));
- if (s && s->run()) {
- return EXIT_SUCCESS;
- }
- std::cerr << a.translate(
- "Console",
- "vmchooser: failed to run session").toUtf8().data() <<
- std::endl;
} else {
std::cerr << a.translate(
"Console",
@@ -103,7 +87,7 @@ int main(int argc, char *argv[]) {
// read configuration file:
// file supplied as command line option or
// user vmchooser.conf or
- // globel vmchooser.conf
+ // global vmchooser.conf
QString confFile;
if (cmdOptions.contains("config")) {
confFile = cmdOptions.value("config");
@@ -185,7 +169,6 @@ int main(int argc, char *argv[]) {
/* read session files */
QList<Session*> xsessions(XSession::readSessions(xSessionPath));
- QList<Session*> vsessions(VSession::readXmlDir(vSessionPath));
Dialog w;
@@ -211,13 +194,7 @@ int main(int argc, char *argv[]) {
w.showSettingsPVS();
w.resize(width, height);
- if (xsessions.empty() && vsessions.empty()) {
- std::cerr << a.translate(
- "Console",
- "vmchooser: no sessions found").toUtf8().data()
- << std::endl;
- return EXIT_FAILURE;
- }
+
if (xsessions.size()) {
qSort(xsessions.begin(), xsessions.end(), myLessThan);
w.addItems(xsessions, a.translate("Dialog", "X Sessions"));
@@ -226,18 +203,6 @@ int main(int argc, char *argv[]) {
if (!vSessionUrl.isEmpty()) {
w.addLabelItem(a.translate("Dialog", "Loading..."), a.translate("Dialog", "Virtual Sessions"));
}
- if (vsessions.size()) {
- if (!(QFile::permissions(runVmScript) & QFile::ExeUser)) {
- std::cerr << a.translate(
- "Console",
- "vmchooser: external script %1 is not executable")
- .arg(runVmScript).toUtf8().data()
- << std::endl;
- return EXIT_FAILURE;
- }
- qSort(vsessions.begin(), vsessions.end(), myLessThan);
- w.addItems(vsessions, a.translate("Dialog", "Virtual Sessions"));
- }
QSettings SLXsettings(OPENSLXCONFIG, QSettings::NativeFormat);
if ( SLXsettings.contains("SLX_BENCHMARK_VM") ) {
diff --git a/src/sessionsiconholder.cpp b/src/sessionsiconholder.cpp
index a158773..5f7c590 100644
--- a/src/sessionsiconholder.cpp
+++ b/src/sessionsiconholder.cpp
@@ -85,7 +85,9 @@ QIcon SessionsIconHolder::getIcon(const QUrl& url) {
QString file_path = iconsTempPath + file_name;
if (QFile::exists(file_path)) {
- qDebug() << "Loaded file from: " << file_path;
+ if (debugMode) {
+ qDebug() << "Loaded file from: " << file_path;
+ }
QIcon icon(file_path);
icons.insert(url.toString(), icon);
return icon;
diff --git a/src/vsession.cpp b/src/vsession.cpp
index e5dfba2..ebe369a 100644
--- a/src/vsession.cpp
+++ b/src/vsession.cpp
@@ -302,8 +302,7 @@ QList<Session*> VSession::readXmlFile(const QString& filepath) {
QDomDocument doc;
QFile file(filepath);
- QString backup_filename = "/tmp/vmchooser2_backup.xml";
- QFile backup_file(backup_filename);
+ QFile backup_file(xml_backup_filename);
if (!file.open(QIODevice::ReadOnly)) {
@@ -322,7 +321,7 @@ QList<Session*> VSession::readXmlFile(const QString& filepath) {
// try to use backup file
if (!backup_file.open(QIODevice::ReadOnly)) {
if (debugMode) {
- qDebug() << "Cannot read backup file " << backup_filename << " either";
+ qDebug() << "Cannot read backup file " << xml_backup_filename << " either";
}
return retval;
}
@@ -336,14 +335,14 @@ QList<Session*> VSession::readXmlFile(const QString& filepath) {
}
if (debugMode) {
- qDebug() << "Used backup file " << backup_filename;
+ qDebug() << "Used backup file " << xml_backup_filename;
}
backup_file.close();
} else {
// file is valid --> create backup file
- QFile::remove(backup_filename);
- QFile::copy(filepath, backup_filename);
+ QFile::remove(xml_backup_filename);
+ QFile::copy(filepath, xml_backup_filename);
}
file.close();
@@ -363,70 +362,6 @@ QList<Session*> VSession::readXmlFile(const QString& filepath) {
return retval;
}
-/**
- * - calls xmlfilter.sh to glob a folder for xmls
- * -> if no xmlfilter.sh is available, it globs for available xmls
- * - reads all xml files and creates for each its own VSession-struct
- */
-QList<Session*> VSession::readXmlDir(const QString& path) {
- QList<Session*> retval;
-
- if (QFile::exists(filterScript)) {
- // run filterScript
- // treat every output line as a filename and read it
- QProcess myFilterScript;
- myFilterScript.start(filterScript, QStringList(path),
- QIODevice::ReadOnly);
- myFilterScript.waitForFinished();
- while (!myFilterScript.atEnd()) {
- QString filename(myFilterScript.readLine());
- filename = filename.trimmed();
- if (QDir::isRelativePath(filename)) {
- filename.prepend(path + "/");
- }
- retval.append(readXmlFile(filename));
- }
-
- myFilterScript.close();
- } else {
- // iterate over all .xml files in directory <path> (and sub-directories)
- // and read them
- QDirIterator di(path,
- QDirIterator::Subdirectories |
- QDirIterator::FollowSymlinks);
- while (di.hasNext()) {
- if (!di.next().endsWith(".xml")) continue;
-
- if (!di.fileInfo().isReadable()) {
- if (debugMode) qDebug() << "skip" << di.fileInfo().absoluteFilePath() << ": xml not readable, incorrect file permissions";
- continue;
- }
-
- QList<Session*> vsessionTmp = readXmlFile(di.fileInfo().absoluteFilePath());
-
- if (vsessionTmp.isEmpty()) {
- if (debugMode) qDebug() << "skip" << di.fileInfo().absoluteFilePath() << ": reading xml failed for some reason";
- continue;
- }
-
- if (!vsessionTmp.first()->isValid()) {
- if (debugMode) qDebug() << "skip" << vsessionTmp.first()->shortDescription() << ": vdi/vmdk missing";
- continue;
- }
-
- if (!vsessionTmp.first()->isActive()) {
- if (debugMode) qDebug() << "skip" << vsessionTmp.first()->shortDescription() << ": not active";
- continue;
- }
-
- if (debugMode) qDebug() << "added " << vsessionTmp.first()->shortDescription() << " to list";
-
- retval.append(vsessionTmp);
- }
- }
- return retval;
-}
-
bool VSession::operator<(const Session& other) const {
int p0 = this->priority();
int p1 = other.priority();