diff options
author | Jonathan Bauer | 2018-12-12 14:25:25 +0100 |
---|---|---|
committer | Jonathan Bauer | 2018-12-12 14:25:25 +0100 |
commit | ca0a7675e30673b8261f2face0f57d6545d94b63 (patch) | |
tree | d2959d223f8e72503cb6e7f7faba629b73736b2f | |
parent | add TODO for url-icon support, if we were to use that feature again one (diff) | |
download | vmchooser2-ca0a7675e30673b8261f2face0f57d6545d94b63.tar.gz vmchooser2-ca0a7675e30673b8261f2face0f57d6545d94b63.tar.xz vmchooser2-ca0a7675e30673b8261f2face0f57d6545d94b63.zip |
rework url params parsing
-rw-r--r-- | src/main.cpp | 46 |
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; |