diff options
author | Jan Darmochwal | 2010-11-01 16:57:08 +0100 |
---|---|---|
committer | Jan Darmochwal | 2010-11-01 16:57:08 +0100 |
commit | b0093484346fdf15337af8cddd687d377da759ce (patch) | |
tree | b21c8691784e5c9deb0527243d880029431c860a /src | |
parent | License information for vmware logo (diff) | |
download | vmchooser-b0093484346fdf15337af8cddd687d377da759ce.tar.gz vmchooser-b0093484346fdf15337af8cddd687d377da759ce.tar.xz vmchooser-b0093484346fdf15337af8cddd687d377da759ce.zip |
Added global vars, version number in globals.h
Diffstat (limited to 'src')
-rw-r--r-- | src/globals.cpp | 17 | ||||
-rw-r--r-- | src/globals.h | 35 | ||||
-rw-r--r-- | src/main.cpp | 33 | ||||
-rw-r--r-- | src/save_restore_session.cpp | 11 | ||||
-rw-r--r-- | src/vsession.cpp | 25 |
5 files changed, 62 insertions, 59 deletions
diff --git a/src/globals.cpp b/src/globals.cpp index 91a39b8..0606243 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -1,5 +1,20 @@ +#include <QDir> #include <QString> #include "globals.h" -const QString filterscript("xmlfilter.sh"); +//QString binPath(QApplication::applicationDirPath()); +QString binPath(VMCHOOSER_BIN_PATH); +QString etcPath(VMCHOOSER_ETC_BASE_PATH); +QString vSessionPath(VMCHOOSER_VMPATH); +QString xSessionPath(VMCHOOSER_X_SESSIONS_PATH); +QString userPath(QDir::homePath() + "/.openslx"); + +QString runVmScript(binPath + "/run-virt.sh"); +QString filterScript(binPath + "/xmlfilter.sh"); +QString printerScript(etcPath + "/printer.sh"); +QString scannerScript(etcPath + "/scanner.sh"); + +const QString globalConfFile(etcPath + "/vmchooser.conf"); +const QString userConfFile(userPath + "/vmchooser.conf"); +const QString previousSessionFile(userPath + "/vmchooser_prev_session"); diff --git a/src/globals.h b/src/globals.h index 5aa78ba..a505628 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,26 +1,33 @@ #ifndef VMCHOOSER_GLOBALS_H #define VMCHOOSER_GLOBALS_H -// #define VMCHOOSER_PLUGIN_PATH "/opt/openslx/plugin-repo/vmchooser/" -// #define VMCHOOSER_BIN_PATH "/var/opt/openslx/bin/" -// #define VMCHOOSER_ETC_BASE_PATH "/etc/opt/openslx/plugins/vmchooser/" -// #define VMCHOOSER_VMPATH "/var/lib/virt" +#define VMCHOOSER_VERSION "0.1.0" -#define VMCHOOSER_PLUGIN_PATH "/home/zwerg/vmchooser/plugin/" -#define VMCHOOSER_BIN_PATH "/home/zwerg/vmchooser/bin/" -#define VMCHOOSER_ETC_BASE_PATH "/home/zwerg/vmchooser/etc/" -#define VMCHOOSER_VMPATH "/home/zwerg/vmchooser/vm/" -#define VMCHOOSER_USER_PATH ".openslx" +#define VMCHOOSER_PLUGIN_PATH "/opt/openslx/plugin-repo/vmchooser" +#define VMCHOOSER_BIN_PATH "/var/opt/openslx/bin" +#define VMCHOOSER_ETC_BASE_PATH "/etc/opt/openslx/plugins/vmchooser" +#define VMCHOOSER_VMPATH "/var/lib/virt" -#define VMCHOOSER_X_SESSIONS_PATH "/usr/share/xsessions/" +#define VMCHOOSER_X_SESSIONS_PATH "/usr/share/xsessions" #define VMCHOOSER_DEFAULT_WIDTH 500 #define VMCHOOSER_DEFAULT_HEIGHT 580 -#define VMCHOOSER_CONF_FILE "vmchooser.conf" -#define VMCHOOSER_PREVIOUS_SESSION_FILE "vmchooser.conf" - class QString; -extern const QString filterscript; + +extern QString binPath; +extern QString etcPath; +extern QString vSessionPath; +extern QString xSessionPath; +extern QString userPath; + +extern QString runVmScript; +extern QString filterScript; +extern QString printerScript; +extern QString scannerScript; + +extern const QString globalConfFile; +extern const QString userConfFile; +extern const QString previousSessionFile; #endif diff --git a/src/main.cpp b/src/main.cpp index 54487d8..fbb3f67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,8 +27,6 @@ int main(int argc, char *argv[]) { translator.load(":" + QLocale::system().name()); a.installTranslator(&translator); - std::string version = "0.0.13"; - CommandLineOptions cmdOptions(argc, argv); std::string usage(a.translate( @@ -54,7 +52,7 @@ int main(int argc, char *argv[]) { } if (cmdOptions.contains("version")) { - std::cout << version; + std::cout << "vmchooser " << VMCHOOSER_VERSION << std::endl; return EXIT_SUCCESS; } @@ -96,11 +94,6 @@ int main(int argc, char *argv[]) { // user vmchooser.conf or // globel vmchooser.conf QString confFile; - QString userConfFile(QDir::homePath() + "/" + - VMCHOOSER_USER_PATH + "/" + - VMCHOOSER_CONF_FILE); - QString globalConfFile(QString(VMCHOOSER_ETC_BASE_PATH) + "/" + - VMCHOOSER_CONF_FILE); if (cmdOptions.contains("config")) { confFile = cmdOptions.value("config"); } else if (QFileInfo(userConfFile).exists()) { @@ -120,23 +113,17 @@ int main(int argc, char *argv[]) { defaultSession = readSessionName(); } - QString vSessionXmlPath; if (cmdOptions.contains("path")) { - vSessionXmlPath = cmdOptions.value("path"); + vSessionPath = cmdOptions.value("path"); } else if (settings.contains("path")) { - vSessionXmlPath = settings.value("path").toString(); - } else { - vSessionXmlPath = VMCHOOSER_VMPATH; - } + vSessionPath = settings.value("path").toString(); + } // else keep default path - QString xSessionPath; if (cmdOptions.contains("xpath")) { xSessionPath = cmdOptions.value("xpath"); } else if (settings.contains("xpath")) { xSessionPath = settings.value("xpath").toString(); - } else { - xSessionPath = VMCHOOSER_X_SESSIONS_PATH; - } + } // else keep default path QString size; if (cmdOptions.contains("size")) { @@ -164,7 +151,7 @@ int main(int argc, char *argv[]) { /* read session files */ QList<Session*> xsessions(XSession::readSessions(xSessionPath)); - QList<Session*> vsessions(VSession::readXmlDir(vSessionXmlPath)); + QList<Session*> vsessions(VSession::readXmlDir(vSessionPath)); Dialog w; w.resize(width, height); @@ -180,6 +167,14 @@ int main(int argc, char *argv[]) { w.addItems(xsessions, a.translate("Dialog", "X 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")); } diff --git a/src/save_restore_session.cpp b/src/save_restore_session.cpp index a9f31f1..8ca1f9d 100644 --- a/src/save_restore_session.cpp +++ b/src/save_restore_session.cpp @@ -5,9 +5,7 @@ #include "globals.h" void writeSessionName(QString name) { - QDir saveFileDir(QDir::homePath() + "/" + VMCHOOSER_USER_PATH); - QString saveFileName(VMCHOOSER_PREVIOUS_SESSION_FILE); - + QDir saveFileDir(QFileInfo(previousSessionFile).absoluteDir()); if (!saveFileDir.exists()) { if (!saveFileDir.mkpath(saveFileDir.path())) { // TODO: error @@ -15,7 +13,7 @@ void writeSessionName(QString name) { } } - QFile saveFile(saveFileDir.path() + "/" + saveFileName); + QFile saveFile(previousSessionFile); if (!saveFile.open(QIODevice::WriteOnly) || saveFile.write(name.toUtf8().data()) == -1) { // TODO: error @@ -23,10 +21,7 @@ void writeSessionName(QString name) { } QString readSessionName() { - QDir saveFileDir(QDir::homePath() + "/" + VMCHOOSER_USER_PATH); - QString saveFileName(VMCHOOSER_PREVIOUS_SESSION_FILE); - - QFile saveFile(saveFileDir.path() + "/" + saveFileName); + QFile saveFile(previousSessionFile); if (saveFile.open(QIODevice::ReadOnly)) { return QString(saveFile.readAll()); diff --git a/src/vsession.cpp b/src/vsession.cpp index a49105d..d3c0296 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -182,7 +182,7 @@ void VSession::addUserAndHostname() { QString image(this->getAttribute("image_name")); if (QFileInfo(image).isRelative()) { // make path to image absolute - this->addNodeWithAttribute("image_name", this->baseDirPath_ + image); + this->addNodeWithAttribute("image_name", this->baseDirPath_ + "/" + image); } // insert computername as the first child of <eintrag> @@ -204,10 +204,8 @@ bool VSession::run() const { VSession session = *this; - QString etcpath(VMCHOOSER_ETC_BASE_PATH); - // TODO: put script names in (global?) constants - session.addPrinters(etcpath + "printer.sh"); - session.addScanners(etcpath + "scanner.sh"); + session.addPrinters(printerScript); + session.addScanners(scannerScript); session.addUserAndHostname(); @@ -223,14 +221,8 @@ bool VSession::run() const { tmpfile.close(); tmpfile.setAutoRemove(false); - // TODO: put script name in constant - // TODO: check if run-virt.sh exists - QString runVmScript(QString(VMCHOOSER_BIN_PATH) + "run-virt.sh"); - if (QProcess::startDetached(runVmScript, QStringList(tmpfile.fileName()))) { - // TODO: save session - return true; - } - return false; + return QProcess::startDetached(runVmScript, + QStringList(tmpfile.fileName())); } QList<Session*> VSession::readXmlFile(const QString& filepath) { @@ -273,12 +265,11 @@ QList<Session*> VSession::readXmlFile(const QString& filepath) { QList<Session*> VSession::readXmlDir(const QString& path) { QList<Session*> retval; - QDir appDir(QApplication::applicationDirPath()); - if (QFile::exists(appDir.filePath(filterscript))) { - // run filterscript + if (QFile::exists(filterScript)) { + // run filterScript // treat every output line as a filename and read it QProcess myFilterScript; - myFilterScript.start(appDir.filePath(filterscript), QStringList(path), + myFilterScript.start(filterScript, QStringList(path), QIODevice::ReadOnly); while (!myFilterScript.atEnd()) { QString filename(myFilterScript.readLine()); |