mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
e1165e112f
* fix/refactor backlight stuff: - fix colors dont turn of when backlight 0 and black is set - add option to use not colored backlight - fix colored backlight not colored on very low color values - various code style tunings * apply needed change to wizard * backlight disabled on static color and efects * fix warnings * try fix udp compiler warnings
94 lines
1.9 KiB
C++
94 lines
1.9 KiB
C++
#include <QtDebug>
|
|
#include <QtGui>
|
|
#include "commandline/Parser.h"
|
|
|
|
using namespace commandline;
|
|
|
|
bool Parser::parse(const QStringList &arguments)
|
|
{
|
|
if (!_parser.parse(arguments))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Q_FOREACH(Option * option, _options)
|
|
{
|
|
QString value = this->value(*option);
|
|
if (!option->validate(*this, value)) {
|
|
const QString error = option->getError();
|
|
if (error.size()) {
|
|
_errorText = tr("%1 is not a valid option for %2\n%3").arg(value, option->name(), error);
|
|
}
|
|
else
|
|
{
|
|
_errorText = tr("%1 is not a valid option for %2").arg(value, option->name());
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void Parser::process(const QStringList &arguments)
|
|
{
|
|
_parser.process(arguments);
|
|
if (!parse(arguments))
|
|
{
|
|
fprintf(stdout, "%s", qPrintable(tr("Error: %1").arg(_errorText)));
|
|
showHelp(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
void Parser::process(const QCoreApplication &app)
|
|
{
|
|
Q_UNUSED(app);
|
|
process(QCoreApplication::arguments());
|
|
}
|
|
|
|
QString Parser::errorText() const
|
|
{
|
|
return (_errorText.size()) ? _errorText : _parser.errorText();
|
|
}
|
|
|
|
bool Parser::addOption(Option &option)
|
|
{
|
|
return addOption(&option);
|
|
}
|
|
|
|
bool Parser::addOption(Option * const option)
|
|
{
|
|
_options[option->name()] = option;
|
|
return _parser.addOption(*option);
|
|
}
|
|
|
|
QStringList Parser::_getNames(const char shortOption, const QString longOption)
|
|
{
|
|
QStringList names;
|
|
if (shortOption != 0x0)
|
|
{
|
|
names << QString(shortOption);
|
|
}
|
|
if (longOption.size())
|
|
{
|
|
names << longOption;
|
|
}
|
|
return names;
|
|
}
|
|
|
|
QString Parser::_getDescription(const QString description, const QString default_)
|
|
{
|
|
/* Add the translations if available */
|
|
QString formattedDescription(tr(qPrintable(description)));
|
|
|
|
/* Fill in the default if needed */
|
|
if (default_.size())
|
|
{
|
|
if(!formattedDescription.contains("%1"))
|
|
{
|
|
formattedDescription += " [default: %1]";
|
|
}
|
|
formattedDescription = formattedDescription.arg(default_);
|
|
}
|
|
return formattedDescription;
|
|
}
|