diff options
author | Jan Darmochwal | 2010-11-04 16:34:09 +0100 |
---|---|---|
committer | Jan Darmochwal | 2010-11-04 16:34:09 +0100 |
commit | cc70529e19745b851cfa455a7bb466d63d881917 (patch) | |
tree | bada819dbecc7b47c34f66447c2c56ceb8774776 | |
parent | Config option: pool (diff) | |
download | vmchooser-cc70529e19745b851cfa455a7bb466d63d881917.tar.gz vmchooser-cc70529e19745b851cfa455a7bb466d63d881917.tar.xz vmchooser-cc70529e19745b851cfa455a7bb466d63d881917.zip |
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:
<environment param="$pool">
<printers>
<printer path="..." name="...">Some Printer</printer>
</printers>
<scanners>...</scanners>
<shared_folders>...</shared_folders>
</environment>
-rw-r--r-- | src/vsession.cpp | 66 | ||||
-rw-r--r-- | 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; |