From cc70529e19745b851cfa455a7bb466d63d881917 Mon Sep 17 00:00:00 2001 From: Jan Darmochwal Date: Thu, 4 Nov 2010 16:34:09 +0100 Subject: Read environment specific options * Vmchooser reads from $vmchooser_etc_path/vmchooser-$pool.xml and merges its contents to any virtual session .xml file * file format: Some Printer ... ... --- src/vsession.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++------ src/vsession.h | 1 + 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/vsession.cpp b/src/vsession.cpp index edcd1e8..f4c2326 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -111,10 +111,12 @@ bool VSession::isActive() const { } } - if (!pool.isEmpty() && - !getAttribute("pools").split("\\s*,\\s*").contains(pool)) { - // pools does not contain pool - return false; + if (!pool.isEmpty()) { + QStringList pools = getAttribute("pools").split("\\s*,\\s*"); + if (!pools.isEmpty() && !pools.contains(pool)) { + // pools does not contain pool + return false; + } } return true; @@ -199,6 +201,59 @@ void VSession::addUserAndHostname() { 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)) { + printf("mark a\n"); + return; + } + if (!doc.setContent(&file)) { + printf("mark b\n"); + + file.close(); + return; + } + file.close(); + + for (QDomElement envNode(doc.firstChildElement("environment")); + !envNode.isNull(); + envNode = envNode.nextSiblingElement()) { + printf("mark c\n"); + + if (envNode.attribute("param") != pool) continue; + + for (QDomElement typeNode(envNode.firstChildElement()); + !typeNode.isNull(); + typeNode = typeNode.nextSiblingElement()) { + printf("mark d\n"); + 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()) { + printf("mark e\n"); + destinationNode.appendChild(this->doc_.importNode(el, true)); + } + } + } +} + bool VSession::run() const { QString command = getAttribute("command"); if (!command.isEmpty()) { @@ -216,8 +271,7 @@ bool VSession::run() const { session.addUserAndHostname(); - // TODO: read the group configuration XML - // session.readGroupXml(&dat, env); + session.mergePoolXml(); // write xml to temporary file QTemporaryFile tmpfile(QDir::tempPath() + "/vmchooser-XXXXXX.xml"); diff --git a/src/vsession.h b/src/vsession.h index f9ab076..035b235 100644 --- a/src/vsession.h +++ b/src/vsession.h @@ -57,6 +57,7 @@ class VSession : public Session { void addPrinters(const QString& script, const QString& type = "printer"); void addScanners(const QString& script); void addUserAndHostname(); + void mergePoolXml(); QString toXml() const; -- cgit v1.2.3-55-g7522