diff options
author | Sebastian Schmelzer | 2011-03-04 18:14:37 +0100 |
---|---|---|
committer | Sebastian Schmelzer | 2011-03-04 18:14:37 +0100 |
commit | 5f450cd48bae1a3c833b93089152f6b308d43c24 (patch) | |
tree | d74ab79170e6b219f64bfb5ac0f9da6e76a4a078 /src | |
parent | Merge branch 'master' of openslx.org:openslx/tools/vmchooser (diff) | |
download | vmchooser-5f450cd48bae1a3c833b93089152f6b308d43c24.tar.gz vmchooser-5f450cd48bae1a3c833b93089152f6b308d43c24.tar.xz vmchooser-5f450cd48bae1a3c833b93089152f6b308d43c24.zip |
* 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
Diffstat (limited to 'src')
-rw-r--r-- | src/command_line_options.cpp | 6 | ||||
-rw-r--r-- | src/globals.cpp | 2 | ||||
-rw-r--r-- | src/globals.h | 2 | ||||
-rw-r--r-- | src/images.qrc | 4 | ||||
-rw-r--r-- | src/img/locked.png | bin | 0 -> 1901 bytes | |||
-rw-r--r-- | src/img/lxde.png | bin | 0 -> 8685 bytes | |||
-rw-r--r-- | src/img/term.png | bin | 0 -> 18052 bytes | |||
-rw-r--r-- | src/img/unknown.png | bin | 0 -> 13215 bytes | |||
-rw-r--r-- | src/img/virtualbox.png | bin | 0 -> 17545 bytes | |||
-rw-r--r-- | src/main.cpp | 5 | ||||
-rw-r--r-- | src/session.h | 1 | ||||
-rw-r--r-- | src/vsession.cpp | 34 | ||||
-rw-r--r-- | src/vsession.h | 1 | ||||
-rw-r--r-- | src/xsession.cpp | 14 | ||||
-rw-r--r-- | src/xsession.h | 1 |
15 files changed, 63 insertions, 7 deletions
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 @@ <file alias="openslx">img/openslx-logo.png</file> <file alias="title_r">img/title_r.png</file> <file alias="title_l">img/title_l.png</file> + <file alias="lxde">img/lxde.png</file> + <file alias="virtualbox">img/virtualbox.png</file> + <file alias="unknown">img/unknown.png</file> + <file alias="term">img/term.png</file> </qresource> </RCC> diff --git a/src/img/locked.png b/src/img/locked.png Binary files differnew file mode 100644 index 0000000..414a9be --- /dev/null +++ b/src/img/locked.png diff --git a/src/img/lxde.png b/src/img/lxde.png Binary files differnew file mode 100644 index 0000000..69b0f9e --- /dev/null +++ b/src/img/lxde.png diff --git a/src/img/term.png b/src/img/term.png Binary files differnew file mode 100644 index 0000000..f4c0200 --- /dev/null +++ b/src/img/term.png diff --git a/src/img/unknown.png b/src/img/unknown.png Binary files differnew file mode 100644 index 0000000..f74d0cf --- /dev/null +++ b/src/img/unknown.png diff --git a/src/img/virtualbox.png b/src/img/virtualbox.png Binary files differnew file mode 100644 index 0000000..c311a98 --- /dev/null +++ b/src/img/virtualbox.png 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 <width>x<height>\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<Session*> xsessions(XSession::readSessions(xSessionPath)); QList<Session*> 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<Session*> 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<Session*> VSession::readXmlDir(const QString& path) { QDirIterator::FollowSymlinks); while (di.hasNext()) { if (!di.next().endsWith(".xml")) continue; - retval.append(readXmlFile(di.fileInfo().absoluteFilePath())); + QList<Session*> 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 { |