diff options
author | Nils Schwabe | 2014-03-04 17:54:57 +0100 |
---|---|---|
committer | Nils Schwabe | 2014-03-04 17:54:57 +0100 |
commit | 03b7858c880ea1fba3915af17c55b42d5e13c58a (patch) | |
tree | 7d1ea603194b98d213c3f90253371ef974f8ee0f /src | |
parent | Added httpxmldownloader (diff) | |
download | vmchooser2-03b7858c880ea1fba3915af17c55b42d5e13c58a.tar.gz vmchooser2-03b7858c880ea1fba3915af17c55b42d5e13c58a.tar.xz vmchooser2-03b7858c880ea1fba3915af17c55b42d5e13c58a.zip |
- included the --url commandline options for a xml url
- httpxmldownloader moved to main.cpp (it's finally working :D)
- given url is downloaded and printed on commandline
- todo: parse http response
Diffstat (limited to 'src')
-rw-r--r-- | src/command_line_options.cpp | 6 | ||||
-rw-r--r-- | src/httpxmldownloader.cpp | 12 | ||||
-rw-r--r-- | src/httpxmldownloader.h | 1 | ||||
-rw-r--r-- | src/main.cpp | 23 | ||||
-rw-r--r-- | src/vsession.cpp | 51 | ||||
-rw-r--r-- | src/vsession.h | 2 |
6 files changed, 86 insertions, 9 deletions
diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 1cf1194..baeca05 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -11,6 +11,7 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { {"file", required_argument, NULL, 'f'}, {"path", required_argument, NULL, 'p'}, {"xpath", required_argument, NULL, 'x'}, + {"url", required_argument, NULL, 'u'}, {"size", required_argument, NULL, 's'}, {"theme", required_argument, NULL, 't'}, {"pvs", no_argument, NULL, 'b'}, @@ -22,7 +23,7 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { int c; - while ((c = getopt_long(argc, argv, "c:d:e:f:p:x:s:t:w:vhbD", longOptions, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "c:d:e:f:p:x:u:s:t:w:vhbD", longOptions, NULL)) != -1) { switch (c) { case 'c': options.insert("config", optarg); @@ -45,6 +46,9 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { case 'x': options.insert("xpath", optarg); break; + case 'u': + options.insert("url", optarg); + break; case 's': options.insert("size", optarg); break; diff --git a/src/httpxmldownloader.cpp b/src/httpxmldownloader.cpp index 4474b9d..788f8f2 100644 --- a/src/httpxmldownloader.cpp +++ b/src/httpxmldownloader.cpp @@ -6,11 +6,17 @@ httpxmldownloader::httpxmldownloader() { nam = new QNetworkAccessManager(this); QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedSlot(QNetworkReply*))); + /** + * TODO: + * connect readyRead() + * + */ - QString url_string = "http://localhost/test.xml"; + qDebug() << "httpdownloader"; +} - QUrl url(url_string); - nam->get(QNetworkRequest(url)); +QNetworkReply* httpxmldownloader::makeRequest(const QString& xmlurl) { + return nam->get(QNetworkRequest(QUrl(xmlurl))); } void httpxmldownloader::finishedSlot(QNetworkReply* reply) { diff --git a/src/httpxmldownloader.h b/src/httpxmldownloader.h index 7bdaf56..6cfd1a7 100644 --- a/src/httpxmldownloader.h +++ b/src/httpxmldownloader.h @@ -12,6 +12,7 @@ class httpxmldownloader : public QObject { QNetworkAccessManager* nam; public: httpxmldownloader(); + QNetworkReply* makeRequest(const QString& xmlurl); private slots: void finishedSlot(QNetworkReply*); }; diff --git a/src/main.cpp b/src/main.cpp index d1b0ace..365287e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ int main(int argc, char *argv[]) { " -f, --file direct boot FILE\n" " -p, --path path to vmware .xml files\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" @@ -51,11 +52,6 @@ int main(int argc, char *argv[]) { "\nFILE can be a vmware .xml or an X .desktop file\n") .toUtf8().data()); - // --------- - std::cout << "testing http" << std::endl; - httpxmldownloader httpxmldownloader; - // --------- - if (cmdOptions.contains("error")) { std::cerr << usage; return EXIT_FAILURE; @@ -140,6 +136,13 @@ int main(int argc, char *argv[]) { xSessionPath = settings.value("xpath").toString(); } // else keep default path + QString vSessionUrl = ""; + if (cmdOptions.contains("url")) { + vSessionUrl = cmdOptions.value("url"); + } else if (settings.contains("url")) { + vSessionUrl = settings.value("url").toString(); + } + QString size; if (cmdOptions.contains("size")) { size = cmdOptions.value("size"); @@ -184,6 +187,16 @@ int main(int argc, char *argv[]) { QList<Session*> xsessions(XSession::readSessions(xSessionPath)); QList<Session*> vsessions(VSession::readXmlDir(vSessionPath)); + /* add sessions from remote xml if possible */ + httpxmldownloader httpxmldownloader; + if (!vSessionUrl.isEmpty()) { + vsessions.append(VSession::readXmlUrl(vSessionUrl, httpxmldownloader)); + } else { + if (debugMode) { + qDebug() << "empty URl given"; + } + } + Dialog w; w.setTheme(); diff --git a/src/vsession.cpp b/src/vsession.cpp index 9800908..7e41b51 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -3,6 +3,7 @@ #include <QApplication> #include <QProcess> #include <QDate> +#include <QThread> #include <QStringList> #if 0 #include <QHostInfo> // available since Qt 4.7 @@ -13,6 +14,7 @@ #include <pwd.h> // for getpwuid #include "globals.h" #include "vsession.h" +#include "httpxmldownloader.h" bool VSession::init(const QString& xml, const QString& baseDirPath) { this->baseDirPath_ = baseDirPath; @@ -298,6 +300,55 @@ int VSession::type() const { return Session::VSESSION; } +QList<Session*> VSession::readXmlUrl(const QString& xmlurl, httpxmldownloader& httpxmldownloader) { + QList<Session*> retval; + + // create thread + //QThread thread; + + QNetworkReply* reply = httpxmldownloader.makeRequest(xmlurl); + + if (reply->isFinished()) {} + +// for (int i = 0; i < 5; i++) { +// qDebug() << reply->isRunning(); +// sleep(1); +// } +// +// //downloader.moveToThread(&thread); +// //thread.start(); +// +// +// if (debugMode) { +// qDebug() << "Made http request with: " << xmlurl; +// } +// +// QDomDocument doc; +// +// QString xml_doc(reply->readAll()); +// +// if (!doc.setContent(QString(reply->readAll()))) { +// // error in xml, return emtpy list +// return retval; +// } + +// // TODO: what dirName??# +// // copied from readXmlFile(...) +// QString dirName = "/loaded/from/url"; +// QDomElement settingsNode = doc.firstChildElement("settings"); +// for (QDomElement el(settingsNode.firstChildElement("eintrag")); +// !el.isNull(); +// el = el.nextSiblingElement("eintrag")) { +// QDomDocument dummy; +// dummy.appendChild(dummy.importNode(el, true)); +// VSession* e = new VSession; +// if (e->init(dummy.toString(), dirName)) { +// retval.append(e); +// } +// } + return retval; +} + QList<Session*> VSession::readXmlFile(const QString& filepath) { QList<Session*> retval; diff --git a/src/vsession.h b/src/vsession.h index 8bbcc7e..f13c377 100644 --- a/src/vsession.h +++ b/src/vsession.h @@ -7,6 +7,7 @@ #include <QDir> #include <QProcess> #include "session.h" +#include "httpxmldownloader.h" enum ImgType { VMWARE, @@ -61,6 +62,7 @@ class VSession : public Session { static QList<Session*> readXmlDir(const QString& path); static QList<Session*> readXmlFile(const QString& filepath); + static QList<Session*> readXmlUrl(const QString& xmlurl, httpxmldownloader& httpxmldownloader); private: QDomDocument doc_; |