From 5f450cd48bae1a3c833b93089152f6b308d43c24 Mon Sep 17 00:00:00 2001
From: Sebastian Schmelzer
Date: Fri, 4 Mar 2011 18:14:37 +0100
Subject: * add debug mode * implement isValid() for vsessions (checks
vmdk/vbox existence) * make use of isValid() and isActive() when filling the
session list * add icons for vbox, lxde, unknown images, failsafe/term * use
exec to guess xsession icon instead of desciption * FIX: remove
newlines/whitespaces from xmlfilter.sh output
---
src/command_line_options.cpp | 6 +++++-
src/globals.cpp | 2 ++
src/globals.h | 2 ++
src/images.qrc | 4 ++++
src/img/locked.png | Bin 0 -> 1901 bytes
src/img/lxde.png | Bin 0 -> 8685 bytes
src/img/term.png | Bin 0 -> 18052 bytes
src/img/unknown.png | Bin 0 -> 13215 bytes
src/img/virtualbox.png | Bin 0 -> 17545 bytes
src/main.cpp | 5 +++++
src/session.h | 1 +
src/vsession.cpp | 34 +++++++++++++++++++++++++++++++---
src/vsession.h | 1 +
src/xsession.cpp | 14 +++++++++++---
src/xsession.h | 1 +
15 files changed, 63 insertions(+), 7 deletions(-)
create mode 100644 src/img/locked.png
create mode 100644 src/img/lxde.png
create mode 100644 src/img/term.png
create mode 100644 src/img/unknown.png
create mode 100644 src/img/virtualbox.png
diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp
index 6ace24a..1bc6c4a 100644
--- a/src/command_line_options.cpp
+++ b/src/command_line_options.cpp
@@ -12,12 +12,13 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) {
{"xpath", required_argument, NULL, 'x'},
{"size", required_argument, NULL, 's'},
{"pvs", no_argument, NULL, 'b'},
+ {"debug", no_argument, NULL, 'D'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
- int opt = getopt_long(argc, argv, "c:d:P:p:x:s:w:vhb", longOptions, NULL);
+ int opt = getopt_long(argc, argv, "c:d:P:p:x:s:w:vhbD", longOptions, NULL);
if (opt == -1) break;
switch (opt) {
@@ -27,6 +28,9 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) {
case 'd':
options.insert("default", optarg);
break;
+ case 'D':
+ options.insert("debugMode", "debugMode");
+ break;
case 'P':
options.insert("pool", optarg);
break;
diff --git a/src/globals.cpp b/src/globals.cpp
index 7dfc222..cc931f9 100644
--- a/src/globals.cpp
+++ b/src/globals.cpp
@@ -18,5 +18,7 @@ const QString globalConfFile(etcPath + "/vmchooser.conf");
const QString userConfFile(userPath + "/vmchooser.conf");
const QString previousSessionFile(userPath + "/vmchooser_prev_session");
+bool debugMode = false;
+
QString pool;
diff --git a/src/globals.h b/src/globals.h
index 6ddf350..7849d2d 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -15,6 +15,8 @@
class QString;
+extern bool debugMode;
+
extern QString binPath;
extern QString etcPath;
extern QString vSessionPath;
diff --git a/src/images.qrc b/src/images.qrc
index 0f203ad..cefbbd7 100644
--- a/src/images.qrc
+++ b/src/images.qrc
@@ -19,5 +19,9 @@
img/openslx-logo.png
img/title_r.png
img/title_l.png
+ img/lxde.png
+ img/virtualbox.png
+ img/unknown.png
+ img/term.png
diff --git a/src/img/locked.png b/src/img/locked.png
new file mode 100644
index 0000000..414a9be
Binary files /dev/null and b/src/img/locked.png differ
diff --git a/src/img/lxde.png b/src/img/lxde.png
new file mode 100644
index 0000000..69b0f9e
Binary files /dev/null and b/src/img/lxde.png differ
diff --git a/src/img/term.png b/src/img/term.png
new file mode 100644
index 0000000..f4c0200
Binary files /dev/null and b/src/img/term.png differ
diff --git a/src/img/unknown.png b/src/img/unknown.png
new file mode 100644
index 0000000..f74d0cf
Binary files /dev/null and b/src/img/unknown.png differ
diff --git a/src/img/virtualbox.png b/src/img/virtualbox.png
new file mode 100644
index 0000000..c311a98
Binary files /dev/null and b/src/img/virtualbox.png differ
diff --git a/src/main.cpp b/src/main.cpp
index 4d86369..7b90ee5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -40,6 +40,7 @@ int main(int argc, char *argv[]) {
" -x, --xpath path of X Session .desktop files\n"
" -s, --size window size x\n"
" -b, --pvs show pvs options\n"
+ " -D, --debug print debug information\n"
" -v, --version print version and exit\n"
" -h, --help print usage information and exit\n"
"\nFILE can be a vmware .xml or an X .desktop file\n")
@@ -161,6 +162,10 @@ int main(int argc, char *argv[]) {
pool = settings.value("vmchooser_env").toString();
}
+ if (cmdOptions.contains("debugMode")) {
+ debugMode = true;
+ }
+
/* read session files */
QList xsessions(XSession::readSessions(xSessionPath));
QList vsessions(VSession::readXmlDir(vSessionPath));
diff --git a/src/session.h b/src/session.h
index b031991..f3d4b4b 100644
--- a/src/session.h
+++ b/src/session.h
@@ -9,6 +9,7 @@ class Session {
virtual bool isActive() const = 0;
virtual bool isLocked() const = 0;
+ virtual bool isValid() const = 0;
virtual int priority() const = 0;
virtual QString shortDescription() const = 0;
virtual QString description() const = 0;
diff --git a/src/vsession.cpp b/src/vsession.cpp
index 05e5159..b543c0f 100644
--- a/src/vsession.cpp
+++ b/src/vsession.cpp
@@ -39,7 +39,9 @@ void VSession::addNodeWithAttribute(const QString& nodeName,
QString VSession::icon() const {
QString icon(getAttribute("icon"));
if (icon.isEmpty()) {
- icon = "vmware";
+ if (imgtype() == VMWARE) icon = "vmware";
+ else if (imgtype() == VBOX) icon = "virtualbox";
+ else icon = "unknown";
} else if (icon.contains(".") && QDir::isRelativePath(icon)) {
// non-built-in icon with relative path
icon.prepend(baseDirPath_ + "/");
@@ -87,7 +89,7 @@ ImgType VSession::imgtype() const {
bool VSession::isActive() const {
QString value(getAttribute("active"));
- if (value.compare("false")) {
+ if (value.compare("false") == 0) {
return false;
} else if (value.count("/") == 1) {
// try to interpret value as date range
@@ -108,11 +110,13 @@ bool VSession::isActive() const {
if (fromDate.isValid() && fromDate > today) {
// fromDate is in the future
+ if (debugMode) qDebug() << "ERR: fromDate is in the future";
return false;
}
if (tillDate.isValid() && tillDate < today) {
// tillDate is in the past
+ if (debugMode) qDebug() << "ERR: tillDate is in the past";
return false;
}
}
@@ -121,6 +125,7 @@ bool VSession::isActive() const {
QStringList pools = getAttribute("pools").split("\\s*,\\s*");
if (!pools.isEmpty() && !pools.contains(pool)) {
// pools does not contain pool
+ if (debugMode) qDebug() << "ERR: pools does not contain pool";
return false;
}
}
@@ -133,6 +138,11 @@ bool VSession::isLocked() const {
return getAttribute("locked").compare("true") == 0;
}
+bool VSession::isValid() const {
+ // default to false
+ return QFile::exists(QString(this->baseDirPath_).append("/").append(getAttribute("image_name")));
+}
+
int VSession::priority() const {
return getAttribute("priority").toInt();
}
@@ -333,8 +343,10 @@ QList VSession::readXmlDir(const QString& path) {
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 + "/");
}
@@ -350,9 +362,25 @@ QList VSession::readXmlDir(const QString& path) {
QDirIterator::FollowSymlinks);
while (di.hasNext()) {
if (!di.next().endsWith(".xml")) continue;
- retval.append(readXmlFile(di.fileInfo().absoluteFilePath()));
+ QList vsessionTmp = readXmlFile(di.fileInfo().absoluteFilePath());
+
+ 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;
+ }
+
+ retval.append(vsessionTmp);
}
}
+
+ for (int i=0; i < retval.count(); i++) {
+
+ }
return retval;
}
diff --git a/src/vsession.h b/src/vsession.h
index 093ec2f..8bbcc7e 100644
--- a/src/vsession.h
+++ b/src/vsession.h
@@ -21,6 +21,7 @@ class VSession : public Session {
ImgType imgtype() const;
bool isActive() const;
bool isLocked() const;
+ bool isValid() const;
int priority() const;
QString shortDescription() const {
diff --git a/src/xsession.cpp b/src/xsession.cpp
index 8c32df5..f4cc3d9 100644
--- a/src/xsession.cpp
+++ b/src/xsession.cpp
@@ -74,6 +74,10 @@ bool XSession::isActive() const {
return true;
}
+bool XSession::isValid() const {
+ return true;
+}
+
bool XSession::isLocked() const {
return false;
}
@@ -86,12 +90,16 @@ QString XSession::icon() const {
QString icon(this->icon_);
if (icon.isEmpty()) {
- if (this->name_.contains("kde", Qt::CaseInsensitive)) {
+ if (this->exec_.contains("kde", Qt::CaseInsensitive)) {
icon = "kde";
- } else if (this->name_.contains("gnome", Qt::CaseInsensitive)) {
+ } else if (this->exec_.contains("gnome", Qt::CaseInsensitive)) {
icon = "gnome";
- } else if (this->name_.contains("xfce", Qt::CaseInsensitive)) {
+ } else if (this->exec_.contains("term", Qt::CaseInsensitive)) {
+ icon = "term";
+ } else if (this->exec_.contains("xfce", Qt::CaseInsensitive)) {
icon = "xfce";
+ } else if (this->exec_.contains("lxde", Qt::CaseInsensitive)) {
+ icon = "lxde";
} else {
icon = "linux";
}
diff --git a/src/xsession.h b/src/xsession.h
index 72c174c..1d36d64 100644
--- a/src/xsession.h
+++ b/src/xsession.h
@@ -16,6 +16,7 @@ class XSession : public Session {
bool isActive() const;
bool isLocked() const;
+ bool isValid() const;
int priority() const;
QString shortDescription() const {
--
cgit v1.2.3-55-g7522