summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2018-12-12 14:25:25 +0100
committerJonathan Bauer2018-12-12 14:25:25 +0100
commitca0a7675e30673b8261f2face0f57d6545d94b63 (patch)
treed2959d223f8e72503cb6e7f7faba629b73736b2f
parentadd TODO for url-icon support, if we were to use that feature again one (diff)
downloadvmchooser2-ca0a7675e30673b8261f2face0f57d6545d94b63.tar.gz
vmchooser2-ca0a7675e30673b8261f2face0f57d6545d94b63.tar.xz
vmchooser2-ca0a7675e30673b8261f2face0f57d6545d94b63.zip
rework url params parsing
-rw-r--r--src/main.cpp46
1 files changed, 19 insertions, 27 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 8d26c14..86311e5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -156,39 +156,31 @@ int main(int argc, char *argv[]) {
g_urlBase = cmdOptions.value("url");
} else if (settings.contains("url")) {
g_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 (!g_urlBase.startsWith("http://")) {
- std::cerr
- << a.translate("Console", "vmchooser: invalid URL").toUtf8().data()
- << std::endl;
- return EXIT_FAILURE;
- } else {
+ if (!g_urlBase.isNull() && !g_urlBase.isEmpty()) {
if (!g_urlBase.endsWith("/")) {
g_urlBase += "/";
}
}
- if (cmdOptions.contains("url-list")) {
- g_urlList = cmdOptions.value("url-list");
- } else {
- // if not explictly specified, use the old scheme
- g_urlList = g_urlBase + "list";
- }
- if (cmdOptions.contains("url-news")) {
- g_urlNews = cmdOptions.value("url-news");
- } else {
- g_urlNews = g_urlBase + "news";
- }
- if (cmdOptions.contains("url-help")) {
- g_urlHelp = cmdOptions.value("url-help");
- } else {
- g_urlHelp = g_urlBase + "help";
+ // parse urls for resources: list, news, help
+ QMap<QString, QString*> resources;
+ resources["list"] = &g_urlList;
+ resources["news"] = &g_urlNews;
+ resources["help"] = &g_urlHelp;
+ QMap<QString, QString*>::const_iterator r = resources.constBegin();
+ QString cur;
+ while (r != resources.constEnd()) {
+ cur = "url-" + r.key();
+ if (cmdOptions.contains(cur)) {
+ *r.value() = cmdOptions.value(cur);
+ } else {
+ if (!g_urlBase.isNull()) {
+ // if not explictly specified, use the old scheme
+ *r.value() = g_urlBase + r.key();
+ }
+ }
+ r++;
}
QString size;