X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fcliparser.cpp;h=a5b72234dd7bdbe772ff83265e7013a8f14d225e;hp=a34af80af41701db135876a7b016d3e3c41ace46;hb=e531fd1f1ea36a360a9d876c94e73b0f3b1bcd22;hpb=5c6804f291a63f978e328aeddcc8448e3443b45e diff --git a/src/common/cliparser.cpp b/src/common/cliparser.cpp index a34af80a..a5b72234 100644 --- a/src/common/cliparser.cpp +++ b/src/common/cliparser.cpp @@ -20,11 +20,47 @@ #include "cliparser.h" #include +#include #include #include -#include +#ifdef HAVE_KDE +# include +#endif + +CliParser::CliParser() { + +} + +#ifdef HAVE_KDE void CliParser::addArgument(const QString &longName, const CliParserArg &arg) { + if(arg.shortName != 0) { + _cmdLineOptions.add(QByteArray().append(arg.shortName)); + } + _cmdLineOptions.add(longName.toUtf8(), ki18n(arg.help.toUtf8()), arg.def.toUtf8()); +} + +bool CliParser::init(const QStringList &) { + KCmdLineArgs::addCmdLineOptions(_cmdLineOptions); + return true; +} + +QString CliParser::value(const QString &longName) { + return KCmdLineArgs::parsedArgs()->getOption(longName.toUtf8()); +} + +bool CliParser::isSet(const QString &longName) { + return KCmdLineArgs::parsedArgs()->isSet(longName.toUtf8()); +} + +void CliParser::usage() { + KCmdLineArgs::usage(); +} + +#else +void CliParser::addArgument(const QString &longName_, const CliParserArg &arg) { + QString longName = longName_; + longName.remove(QRegExp("\\s*<.*>\\s*")); // KCmdLineArgs takes args of the form "arg " if(argsHash.contains(longName)) qWarning() << "Warning: Multiple definition of argument" << longName; if(arg.shortName != 0 && !lnameOfShortArg(arg.shortName).isNull()) qWarning().nospace() << "Warning: Redefining shortName '" << arg.shortName << "' for " << longName << " previously defined for " << lnameOfShortArg(arg.shortName); @@ -77,7 +113,7 @@ QString CliParser::escapedValue(const QString &value) { return escapedValue; } -bool CliParser::parse(const QStringList &args) { +bool CliParser::init(const QStringList &args) { argsRaw = args; QStringList::const_iterator currentArg; for (currentArg = argsRaw.constBegin(); currentArg != argsRaw.constEnd(); ++currentArg) { @@ -178,7 +214,7 @@ void CliParser::usage() { if(arg.value().type == CliParserArg::CliArgOption && !arg.value().def.isNull()) { output.append(". Default is: ").append(arg.value().def); } - qWarning(output.toLatin1()); + qWarning() << output.toLatin1(); } } @@ -213,3 +249,5 @@ QString CliParser::lnameOfShortArg(const char arg) { } return QString(); } + +#endif