diff options
author | Nils Schwabe | 2014-04-04 15:00:58 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-04-04 15:00:58 +0200 |
commit | fc48e4b44760d0bb432a238e4c1b986062a91311 (patch) | |
tree | 6963b3bd46f06b2a9b57b80f1f0f5c09a84dc42b | |
parent | changed adDUSerAndHostname() (diff) | |
download | vmchooser2-fc48e4b44760d0bb432a238e4c1b986062a91311.tar.gz vmchooser2-fc48e4b44760d0bb432a238e4c1b986062a91311.tar.xz vmchooser2-fc48e4b44760d0bb432a238e4c1b986062a91311.zip |
removed addPrinters() and addScanners
introduced "change the run-virt.sh path" in cmd line and config file
-rw-r--r-- | src/command_line_options.cpp | 6 | ||||
-rw-r--r-- | src/globals.cpp | 3 | ||||
-rw-r--r-- | src/globals.h | 1 | ||||
-rw-r--r-- | src/i18n/de.ts | 40 | ||||
-rwxr-xr-x | src/i18n/pt.ts | 19 | ||||
-rw-r--r-- | src/main.cpp | 443 | ||||
-rw-r--r-- | src/vsession.cpp | 47 | ||||
-rw-r--r-- | src/vsession.h | 2 |
8 files changed, 280 insertions, 281 deletions
diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 9ac099f..9293870 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -17,12 +17,13 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { {"debug", no_argument, NULL, 'D'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, + {"runscript", no_argument, NULL, 'S'}, {0, 0, 0, 0} }; int c; - while ((c = getopt_long(argc, argv, "c:d:e:f:x:u:s:t:w:vhbD", longOptions, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "c:d:e:f:x:u:s:t:w:vhbDS", longOptions, NULL)) != -1) { switch (c) { case 'c': options.insert("config", optarg); @@ -60,6 +61,9 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { case 'h': options.insert("usage", "usage"); break; + case 'S': + options.insert("runscript", optarg); + break; case '?': default: options.insert("error", "error"); diff --git a/src/globals.cpp b/src/globals.cpp index 6ff6aed..babe0ad 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -11,9 +11,6 @@ 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"); QString sessionStartScript(VMCHOOSER_SESSION_START_SCRIPT); const QString globalConfFile(etcPath + "/vmchooser.conf"); diff --git a/src/globals.h b/src/globals.h index 00d10c5..28b0886 100644 --- a/src/globals.h +++ b/src/globals.h @@ -31,7 +31,6 @@ extern QString xSessionPath; extern QString userPath; extern QString runVmScript; -extern QString filterScript; extern QString printerScript; extern QString scannerScript; // Script that is run before the xsession/vsession is started diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 7ac1550..f3dda2c 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -67,7 +67,7 @@ FILE can be a vmware .xml or an X .desktop file FILE can be a vmware .xml or an X .desktop file </source> - <translation>Aufruf: vmchooser [ OPTIONS ] + <translation type="obsolete">Aufruf: vmchooser [ OPTIONS ] -d, --default Name der Default Session -c, --config Alternative Config Datei @@ -94,6 +94,44 @@ FILE can be a vmware .xml or an X .desktop file <source>vmchooser: invalid size argument</source> <translation>Ungültige Größe</translation> </message> + <message> + <source>Usage: vmchooser [ OPTIONS ] + + -d, --default name of default session + -c, --config alternative config file + -e, --env name of the environment + -f, --file direct boot .desktop file + -x, --xpath path of X Session .desktop files + -u, --url url of vmware .xml file + -s, --size window size <width>x<height> + -t, --theme theme + -b, --pvs show pvs options + -D, --debug print debug information + -v, --version print version and exit + -h, --help print usage information and exit + -S, --runscript change path to run-virt.sh + +FILE can be a vmware .xml or an X .desktop file +</source> + <translation>Usage: vmchooser [ OPTIONS ] + + -d, --default Name der Default Session + -c, --config Alternatives config file + -e, --env Name der Umgebung + -f, --file Boote .desktop file direkt + -x, --xpath Pfad der X Session .desktop files + -u, --url Url des vmware .xml files + -s, --size Fenster Größe <width>x<height> + -t, --theme theme + -b, --pvs Zeige pvs Optionen + -D, --debug print debug information + -v, --version print version and exit + -h, --help print usage information and exit + -S, --runscript change path to run-virt.sh + +FILE can be a vmware .xml or an X .desktop file +</translation> + </message> </context> <context> <name>Dialog</name> diff --git a/src/i18n/pt.ts b/src/i18n/pt.ts index 4782956..a36f536 100755 --- a/src/i18n/pt.ts +++ b/src/i18n/pt.ts @@ -30,7 +30,7 @@ ARQUIVO pode ser um arquivo xml do vmware ou do área de trabalho do X </translation> </message> <message> - <location filename="../main.cpp" line="32"/> + <location filename="../main.cpp" line="33"/> <source>Usage: vmchooser [ OPTIONS ] -d, --default name of default session @@ -45,6 +45,7 @@ ARQUIVO pode ser um arquivo xml do vmware ou do área de trabalho do X -D, --debug print debug information -v, --version print version and exit -h, --help print usage information and exit + -S, --runscript change path to run-virt.sh FILE can be a vmware .xml or an X .desktop file </source> @@ -61,17 +62,17 @@ FILE can be a vmware .xml or an X .desktop file <translation>vmchooser: arquivo de sessão inválido</translation> </message> <message> - <location filename="../main.cpp" line="128"/> + <location filename="../main.cpp" line="127"/> <source>vmchooser: no URL given</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../main.cpp" line="134"/> + <location filename="../main.cpp" line="142"/> <source>vmchooser: invalid URL</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../main.cpp" line="156"/> + <location filename="../main.cpp" line="166"/> <source>vmchooser: invalid size argument</source> <translation type="unfinished"></translation> </message> @@ -231,8 +232,8 @@ p, li { white-space: pre-wrap; } </message> <message> <location filename="../dialog.cpp" line="303"/> - <location filename="../dialog.cpp" line="342"/> - <location filename="../main.cpp" line="224"/> + <location filename="../dialog.cpp" line="333"/> + <location filename="../main.cpp" line="233"/> <source>Loading...</source> <translation type="unfinished"></translation> </message> @@ -242,17 +243,17 @@ p, li { white-space: pre-wrap; } <translation type="unfinished"></translation> </message> <message> - <location filename="../dialog.cpp" line="347"/> + <location filename="../dialog.cpp" line="338"/> <source>No Items</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../dialog.cpp" line="390"/> + <location filename="../dialog.cpp" line="380"/> <source>Native</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../dialog.cpp" line="391"/> + <location filename="../dialog.cpp" line="381"/> <source>Running on this machine.</source> <translation type="unfinished"></translation> </message> diff --git a/src/main.cpp b/src/main.cpp index d55f01c..e646620 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,221 +21,230 @@ #include "choosersettings.h" int main(int argc, char *argv[]) { - QApplication a(argc, argv); - - QTranslator translator; - translator.load(":" + QLocale::system().name()); - a.installTranslator(&translator); - - CommandLineOptions cmdOptions(argc, argv); - - std::string usage(a.translate( - "Console", - "Usage: vmchooser [ OPTIONS ]\n\n" - " -d, --default name of default session\n" - " -c, --config alternative config file\n" - " -e, --env name of the environment\n" - " -f, --file direct boot .desktop file\n" - " -x, --xpath path of X Session .desktop files\n" - " -u, --url url of vmware .xml file\n" - " -s, --size window size <width>x<height>\n" - " -t, --theme theme\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") - .toUtf8().data()); - - if (cmdOptions.contains("error")) { - std::cerr << usage; - return EXIT_FAILURE; - } - - if (cmdOptions.contains("usage")) { - std::cout << usage; - return EXIT_SUCCESS; - } - - if (cmdOptions.contains("version")) { - std::cout << "vmchooser " << VMCHOOSER_VERSION << std::endl; - return EXIT_SUCCESS; - } - - if (cmdOptions.contains("file")) { - QString file(cmdOptions.value("file")); - - if (file.endsWith(".desktop")) { - XSession s; - if (s.init(file) && s.run()) { - return EXIT_SUCCESS; - } - std::cerr << a.translate( - "Console", - "vmchooser: failed to run session").toUtf8().data() << - std::endl; - return EXIT_FAILURE; - } else { - std::cerr << a.translate( - "Console", - "vmchooser: invalid session file").toUtf8().data() << - std::endl; - return EXIT_FAILURE; - } - } - - // read configuration file: - // file supplied as command line option or - // user vmchooser.conf or - // global vmchooser.conf - QString confFile; - if (cmdOptions.contains("config")) { - confFile = cmdOptions.value("config"); - } else if (QFileInfo(userConfFile).exists()) { - confFile = userConfFile; - } else { - confFile = globalConfFile; - } - QSettings settings(confFile, QSettings::IniFormat); - settings.setIniCodec("UTF-8"); - - QString defaultSession; - if (cmdOptions.contains("default")) { - defaultSession = cmdOptions.value("default"); - } else if (settings.contains("default")) { - defaultSession = settings.value("default").toString(); - } else { - defaultSession = ChooserSettings::getSetting("last-session"); - } - - if (cmdOptions.contains("path")) { - vSessionPath = cmdOptions.value("path"); - } else if (settings.contains("path")) { - vSessionPath = settings.value("path").toString(); - } // else keep default path - - if (cmdOptions.contains("xpath")) { - xSessionPath = cmdOptions.value("xpath"); - } else if (settings.contains("xpath")) { - xSessionPath = settings.value("xpath").toString(); - } // else keep default path - - if (cmdOptions.contains("url")) { - urlBase = cmdOptions.value("url"); - } else if (settings.contains("url")) { - urlBase = settings.value("url").toString(); - } else { - std::cerr << a.translate("Console", "vmchooser: no URL given").toUtf8().data() << std::endl; - return EXIT_FAILURE; - } - - /* PARSE URL */ - if (!urlBase.startsWith("http://")) { - std::cerr << a.translate("Console", "vmchooser: invalid URL").toUtf8().data() << std::endl; - return EXIT_FAILURE; - } else { - if (!urlBase.endsWith("/")) { - urlBase += "/"; - } - } - - QString size; - if (cmdOptions.contains("size")) { - size = cmdOptions.value("size"); - } else if (settings.contains("size")) { - size = settings.value("size").toString(); - } - - int width, height; - QRegExp rx("^(\\d+)x(\\d+)$"); - if (rx.indexIn(size) != -1) { - QStringList list = rx.capturedTexts(); - width = list.value(1).toInt(); - height = list.value(2).toInt(); - } else if (!size.isEmpty()) { - std::cerr << a.translate( - "Console", - "vmchooser: invalid size argument").toUtf8().data() - << std::endl; - return EXIT_FAILURE; - } else { - width = VMCHOOSER_DEFAULT_WIDTH; - height = VMCHOOSER_DEFAULT_HEIGHT; - } - - if (cmdOptions.contains("env")) { - pool = cmdOptions.value("env"); - } else if (settings.contains("pool")) { - pool = settings.value("pool").toString(); - } - - if (cmdOptions.contains("theme")) { - theme = cmdOptions.value("theme"); - } else if (settings.contains("theme")) { - theme = settings.value("theme").toString(); - } - - if (cmdOptions.contains("debugMode")) { - debugMode = true; - } - - /* read session files */ - QList<Session*> xsessions(XSession::readSessions(xSessionPath)); - - Dialog w; - - /* DOWNLOAD VSESSIONS */ - HttpXmlDownloader httpxmldownloader; - httpxmldownloader.connectSlot(&w, SLOT(addSessionsAfterDownload(QNetworkReply*))); - - // read xml and add items later - httpxmldownloader.makeRequest(urlBase + "list.php"); - - /* DOWNLOAD NEWS */ - HttpXmlDownloader news_downloader; - news_downloader.connectSlot(&w, SLOT(addNewsAfterDownload(QNetworkReply*))); - news_downloader.makeRequest(urlBase + "news.php"); - - /* DOWNLOAD HELP-SECTION */ - HttpXmlDownloader help_downloader; - help_downloader.connectSlot(&w, SLOT(addHelpAfterDownload(QNetworkReply*))); - help_downloader.makeRequest(urlBase + "help.php"); - - w.setTheme(); - - w.setWindowFlags(Qt::FramelessWindowHint); - if (cmdOptions.contains("pvs")) { - pvsEnabled = true; - } else if (settings.contains("pvs")) { - if (settings.value("pvs").toInt() == 1) - pvsEnabled = true; - } - - if ( pvsEnabled ) - w.showSettingsPVS(); - - w.resize(width, height); - - if (xsessions.size()) { - qSort(xsessions.begin(), xsessions.end(), myLessThan); - w.addItems(xsessions, 0); - } - - w.addLabelItem(a.translate("Dialog", "Loading..."), 1); - - QSettings SLXsettings(OPENSLXCONFIG, QSettings::NativeFormat); - if ( SLXsettings.contains("SLX_BENCHMARK_VM") ) { - QString vm = SLXsettings.value("SLX_BENCHMARK_VM").toString(); - vm.remove('\''); - w.startSession(vm); - } - w.show(); - - // center dialog on primary screen - QRect desktopRect = QApplication::desktop()->availableGeometry(&w); - QPoint center = desktopRect.center(); - w.move(center.x()-w.width()*0.5, center.y()-w.height()*0.5); - a.setActiveWindow(&w); - - return a.exec(); + QApplication a(argc, argv); + + QTranslator translator; + translator.load(":" + QLocale::system().name()); + a.installTranslator(&translator); + + CommandLineOptions cmdOptions(argc, argv); + + std::string usage( + a.translate("Console", "Usage: vmchooser [ OPTIONS ]\n\n" + " -d, --default name of default session\n" + " -c, --config alternative config file\n" + " -e, --env name of the environment\n" + " -f, --file direct boot .desktop file\n" + " -x, --xpath path of X Session .desktop files\n" + " -u, --url url of vmware .xml file\n" + " -s, --size window size <width>x<height>\n" + " -t, --theme theme\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" + " -S, --runscript change path to run-virt.sh\n" + "\nFILE can be a vmware .xml or an X .desktop file\n").toUtf8().data()); + + if (cmdOptions.contains("error")) { + std::cerr << usage; + return EXIT_FAILURE; + } + + if (cmdOptions.contains("usage")) { + std::cout << usage; + return EXIT_SUCCESS; + } + + if (cmdOptions.contains("version")) { + std::cout << "vmchooser " << VMCHOOSER_VERSION << std::endl; + return EXIT_SUCCESS; + } + + if (cmdOptions.contains("file")) { + QString file(cmdOptions.value("file")); + + if (file.endsWith(".desktop")) { + XSession s; + if (s.init(file) && s.run()) { + return EXIT_SUCCESS; + } + std::cerr + << a.translate("Console", + "vmchooser: failed to run session").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } else { + std::cerr + << a.translate("Console", "vmchooser: invalid session file").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } + } + + // read configuration file: + // file supplied as command line option or + // user vmchooser.conf or + // global vmchooser.conf + QString confFile; + if (cmdOptions.contains("config")) { + confFile = cmdOptions.value("config"); + } else if (QFileInfo(userConfFile).exists()) { + confFile = userConfFile; + } else { + confFile = globalConfFile; + } + QSettings settings(confFile, QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + + QString defaultSession; + if (cmdOptions.contains("default")) { + defaultSession = cmdOptions.value("default"); + } else if (settings.contains("default")) { + defaultSession = settings.value("default").toString(); + } else { + defaultSession = ChooserSettings::getSetting("last-session"); + } + + if (cmdOptions.contains("path")) { + vSessionPath = cmdOptions.value("path"); + } else if (settings.contains("path")) { + vSessionPath = settings.value("path").toString(); + } // else keep default path + + if (cmdOptions.contains("xpath")) { + xSessionPath = cmdOptions.value("xpath"); + } else if (settings.contains("xpath")) { + xSessionPath = settings.value("xpath").toString(); + } // else keep default path + + if (cmdOptions.contains("url")) { + urlBase = cmdOptions.value("url"); + } else if (settings.contains("url")) { + urlBase = settings.value("url").toString(); + } else { + std::cerr + << a.translate("Console", "vmchooser: no URL given").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } + + // Change the runVmScript path + if (cmdOptions.contains("runscript")) { + runVmScript = cmdOptions.value("runscript"); + } else if (settings.contains("runscript")) { + runVmScript = settings.value("runscript").toString(); + } + + /* PARSE URL */ + if (!urlBase.startsWith("http://")) { + std::cerr + << a.translate("Console", "vmchooser: invalid URL").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } else { + if (!urlBase.endsWith("/")) { + urlBase += "/"; + } + } + + QString size; + if (cmdOptions.contains("size")) { + size = cmdOptions.value("size"); + } else if (settings.contains("size")) { + size = settings.value("size").toString(); + } + + int width, height; + QRegExp rx("^(\\d+)x(\\d+)$"); + if (rx.indexIn(size) != -1) { + QStringList list = rx.capturedTexts(); + width = list.value(1).toInt(); + height = list.value(2).toInt(); + } else if (!size.isEmpty()) { + std::cerr + << a.translate("Console", "vmchooser: invalid size argument").toUtf8().data() + << std::endl; + return EXIT_FAILURE; + } else { + width = VMCHOOSER_DEFAULT_WIDTH; + height = VMCHOOSER_DEFAULT_HEIGHT; + } + + if (cmdOptions.contains("env")) { + pool = cmdOptions.value("env"); + } else if (settings.contains("pool")) { + pool = settings.value("pool").toString(); + } + + if (cmdOptions.contains("theme")) { + theme = cmdOptions.value("theme"); + } else if (settings.contains("theme")) { + theme = settings.value("theme").toString(); + } + + if (cmdOptions.contains("debugMode")) { + debugMode = true; + } + + /* read session files */ + QList<Session*> xsessions(XSession::readSessions(xSessionPath)); + + Dialog w; + + /* DOWNLOAD VSESSIONS */ + HttpXmlDownloader httpxmldownloader; + httpxmldownloader.connectSlot(&w, + SLOT(addSessionsAfterDownload(QNetworkReply*))); + + // read xml and add items later + httpxmldownloader.makeRequest(urlBase + "list.php"); + + /* DOWNLOAD NEWS */ + HttpXmlDownloader news_downloader; + news_downloader.connectSlot(&w, SLOT(addNewsAfterDownload(QNetworkReply*))); + news_downloader.makeRequest(urlBase + "news.php"); + + /* DOWNLOAD HELP-SECTION */ + HttpXmlDownloader help_downloader; + help_downloader.connectSlot(&w, SLOT(addHelpAfterDownload(QNetworkReply*))); + help_downloader.makeRequest(urlBase + "help.php"); + + w.setTheme(); + + w.setWindowFlags(Qt::FramelessWindowHint); + if (cmdOptions.contains("pvs")) { + pvsEnabled = true; + } else if (settings.contains("pvs")) { + if (settings.value("pvs").toInt() == 1) + pvsEnabled = true; + } + + if (pvsEnabled) + w.showSettingsPVS(); + + w.resize(width, height); + + if (xsessions.size()) { + qSort(xsessions.begin(), xsessions.end(), myLessThan); + w.addItems(xsessions, 0); + } + + w.addLabelItem(a.translate("Dialog", "Loading..."), 1); + + QSettings SLXsettings(OPENSLXCONFIG, QSettings::NativeFormat); + if (SLXsettings.contains("SLX_BENCHMARK_VM")) { + QString vm = SLXsettings.value("SLX_BENCHMARK_VM").toString(); + vm.remove('\''); + w.startSession(vm); + } + w.show(); + + // center dialog on primary screen + QRect desktopRect = QApplication::desktop()->availableGeometry(&w); + QPoint center = desktopRect.center(); + w.move(center.x() - w.width() * 0.5, center.y() - w.height() * 0.5); + a.setActiveWindow(&w); + + return a.exec(); } diff --git a/src/vsession.cpp b/src/vsession.cpp index 30cbb88..2987a62 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -177,50 +177,6 @@ int VSession::priority() const { return getAttribute("priority").toInt(); } - -void VSession::addPrinters(const QString& script, const QString& type) { - QDomElement printersNode = - this->doc_.namedItem("eintrag").namedItem(type + "s").toElement(); - - if (printersNode.isNull()) { - // create new printers node - printersNode = this->doc_.createElement(type + "s"); - this->doc_.namedItem("eintrag").appendChild(printersNode); - } - - QProcess addPrintersScript; - addPrintersScript.start(script, QIODevice::ReadOnly); - while (!addPrintersScript.atEnd()) { - QString line(addPrintersScript.readLine()); - QStringList tokens(line.split("\t")); - - if (tokens.size() < 2 or tokens.size() > 3) { - // TODO error message - // invalid output of printerScript - // printserver\tprinter\tprinter description - continue; - } - - QDomElement printerNode(doc_.createElement(type)); - printerNode.setAttribute("name", tokens.at(1)); - printerNode.setAttribute("path", - "\\\\" + tokens.at(0) + "\\" + tokens.at(1)); - if (tokens.size() == 3) { - QDomText printerDescriptionNode(doc_.createTextNode(tokens.at(3))); - printerNode.appendChild(printerDescriptionNode); - } - printersNode.appendChild(printerNode); - } - - addPrintersScript.close(); - - return; -} - -void VSession::addScanners(const QString& script) { - addPrinters(script, "scanner"); -} - void VSession::addUserAndHostname() { QString username(getpwuid(geteuid())->pw_name); this->addNodeWithAttribute("username", username); @@ -306,9 +262,6 @@ bool VSession::run() const { VSession session = *this; - session.addPrinters(printerScript); - session.addScanners(scannerScript); - session.addUserAndHostname(); session.mergePoolXml(); diff --git a/src/vsession.h b/src/vsession.h index 9cb7a69..ea04e4e 100644 --- a/src/vsession.h +++ b/src/vsession.h @@ -49,8 +49,6 @@ class VSession : public Session { const QString& value, const QString& attribute = "param", bool replace = true); - void addPrinters(const QString& script, const QString& type = "printer"); - void addScanners(const QString& script); void addUserAndHostname(); void mergePoolXml(); |