mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Qcommandlineparser (#199)
* Replaced getoptplusplus with QCommandLineParser. Fixes #39 * enabling C++11 if possible * enabling C++11 if possible * fixed gcc compilation issues * fixed linux builds and improved os x build * trying to fix dispmanx * trying to fix dispmanx * simplified travis build script * fixed argumentparser default values * rewrote validator system and made sure default arguments are processed correctly * rewrote validator system and made sure default arguments are processed correctly * fixed bool vs. regular options * oops... removing debug code * reverted screenshot api change
This commit is contained in:
committed by
redPanther
parent
c13f2e20ec
commit
61db9f43b8
@@ -8,11 +8,10 @@
|
||||
// hyperion-remote includes
|
||||
#include "JsonConnection.h"
|
||||
|
||||
JsonConnection::JsonConnection(const std::string & a, bool printJson)
|
||||
JsonConnection::JsonConnection(const QString & address, bool printJson)
|
||||
: _printJson(printJson)
|
||||
, _socket()
|
||||
{
|
||||
QString address(a.c_str());
|
||||
QStringList parts = address.split(":");
|
||||
if (parts.size() != 2)
|
||||
{
|
||||
@@ -32,7 +31,7 @@ JsonConnection::JsonConnection(const std::string & a, bool printJson)
|
||||
throw std::runtime_error("Unable to connect to host");
|
||||
}
|
||||
|
||||
std::cout << "Connected to " << a << std::endl;
|
||||
qDebug() << "Connected to:" << address;
|
||||
}
|
||||
|
||||
JsonConnection::~JsonConnection()
|
||||
@@ -67,7 +66,7 @@ void JsonConnection::setColor(std::vector<QColor> colors, int priority, int dura
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setImage(QImage image, int priority, int duration)
|
||||
void JsonConnection::setImage(QImage &image, int priority, int duration)
|
||||
{
|
||||
std::cout << "Set image has size: " << image.width() << "x" << image.height() << std::endl;
|
||||
|
||||
@@ -93,7 +92,7 @@ void JsonConnection::setImage(QImage image, int priority, int duration)
|
||||
command["priority"] = priority;
|
||||
command["imagewidth"] = image.width();
|
||||
command["imageheight"] = image.height();
|
||||
command["imagedata"] = std::string(base64Image.data(), base64Image.size());
|
||||
command["imagedata"] = base64Image.data();
|
||||
if (duration > 0)
|
||||
{
|
||||
command["duration"] = duration;
|
||||
@@ -106,20 +105,20 @@ void JsonConnection::setImage(QImage image, int priority, int duration)
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setEffect(const std::string &effectName, const std::string & effectArgs, int priority, int duration)
|
||||
void JsonConnection::setEffect(const QString &effectName, const QString & effectArgs, int priority, int duration)
|
||||
{
|
||||
std::cout << "Start effect " << effectName << std::endl;
|
||||
qDebug() << "Start effect " << effectName;
|
||||
|
||||
// create command
|
||||
Json::Value command;
|
||||
command["command"] = "effect";
|
||||
command["priority"] = priority;
|
||||
Json::Value & effect = command["effect"];
|
||||
effect["name"] = effectName;
|
||||
effect["name"] = effectName.toStdString();
|
||||
if (effectArgs.size() > 0)
|
||||
{
|
||||
Json::Reader reader;
|
||||
if (!reader.parse(effectArgs, effect["args"], false))
|
||||
if (!reader.parse(effectArgs.toStdString(), effect["args"], false))
|
||||
{
|
||||
throw std::runtime_error("Error in effect arguments: " + reader.getFormattedErrorMessages());
|
||||
}
|
||||
@@ -193,16 +192,15 @@ void JsonConnection::clearAll()
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setComponentState(const std::string& component, const bool state)
|
||||
void JsonConnection::setComponentState(const QString & component, const bool state)
|
||||
{
|
||||
state ? std::cout << "Enable Component " : std::cout << "Disable Component ";
|
||||
std::cout << component << std::endl;
|
||||
qDebug() << (state ? "Enable" : "Disable") << "Component" << component;
|
||||
|
||||
// create command
|
||||
Json::Value command;
|
||||
command["command"] = "componentstate";
|
||||
Json::Value & parameter = command["componentstate"];
|
||||
parameter["component"] = component;
|
||||
parameter["component"] = component.toStdString();
|
||||
parameter["state"] = state;
|
||||
|
||||
// send command message
|
||||
@@ -268,7 +266,7 @@ QString JsonConnection::getConfig(std::string type)
|
||||
return QString();
|
||||
}
|
||||
|
||||
void JsonConnection::setConfig(const std::string &jsonString, bool create, bool overwrite)
|
||||
void JsonConnection::setConfig(const QString &jsonString, bool create, bool overwrite)
|
||||
{
|
||||
// create command
|
||||
Json::Value command;
|
||||
@@ -281,7 +279,7 @@ void JsonConnection::setConfig(const std::string &jsonString, bool create, bool
|
||||
if (jsonString.size() > 0)
|
||||
{
|
||||
Json::Reader reader;
|
||||
if (!reader.parse(jsonString, config, false))
|
||||
if (!reader.parse(jsonString.toStdString(), config, false))
|
||||
{
|
||||
throw std::runtime_error("Error in configset arguments: " + reader.getFormattedErrorMessages());
|
||||
}
|
||||
@@ -294,7 +292,16 @@ void JsonConnection::setConfig(const std::string &jsonString, bool create, bool
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setTransform(std::string * transformId, double * saturation, double * value, double * saturationL, double * luminance, double * luminanceMin, ColorTransformValues *threshold, ColorTransformValues *gamma, ColorTransformValues *blacklevel, ColorTransformValues *whitelevel)
|
||||
void JsonConnection::setTransform(const QString &transformId,
|
||||
double *saturation,
|
||||
double *value,
|
||||
double *saturationL,
|
||||
double *luminance,
|
||||
double *luminanceMin,
|
||||
QColor threshold,
|
||||
QColor gamma,
|
||||
QColor blacklevel,
|
||||
QColor whitelevel)
|
||||
{
|
||||
std::cout << "Set color transforms" << std::endl;
|
||||
|
||||
@@ -303,9 +310,9 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation
|
||||
command["command"] = "transform";
|
||||
Json::Value & transform = command["transform"];
|
||||
|
||||
if (transformId != nullptr)
|
||||
if (!transformId.isNull())
|
||||
{
|
||||
transform["id"] = *transformId;
|
||||
transform["id"] = transformId.toStdString();
|
||||
}
|
||||
|
||||
if (saturation != nullptr)
|
||||
@@ -333,36 +340,36 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation
|
||||
transform["luminanceMinimum"] = *luminanceMin;
|
||||
}
|
||||
|
||||
if (threshold != nullptr)
|
||||
if (threshold.isValid())
|
||||
{
|
||||
Json::Value & v = transform["threshold"];
|
||||
v.append(threshold->valueRed);
|
||||
v.append(threshold->valueGreen);
|
||||
v.append(threshold->valueBlue);
|
||||
v.append(threshold.red());
|
||||
v.append(threshold.green());
|
||||
v.append(threshold.blue());
|
||||
}
|
||||
|
||||
if (gamma != nullptr)
|
||||
if (gamma.isValid())
|
||||
{
|
||||
Json::Value & v = transform["gamma"];
|
||||
v.append(gamma->valueRed);
|
||||
v.append(gamma->valueGreen);
|
||||
v.append(gamma->valueBlue);
|
||||
v.append(gamma.red());
|
||||
v.append(gamma.green());
|
||||
v.append(gamma.blue());
|
||||
}
|
||||
|
||||
if (blacklevel != nullptr)
|
||||
if (blacklevel.isValid())
|
||||
{
|
||||
Json::Value & v = transform["blacklevel"];
|
||||
v.append(blacklevel->valueRed);
|
||||
v.append(blacklevel->valueGreen);
|
||||
v.append(blacklevel->valueBlue);
|
||||
v.append(blacklevel.red());
|
||||
v.append(blacklevel.green());
|
||||
v.append(blacklevel.blue());
|
||||
}
|
||||
|
||||
if (whitelevel != nullptr)
|
||||
if (whitelevel.isValid())
|
||||
{
|
||||
Json::Value & v = transform["whitelevel"];
|
||||
v.append(whitelevel->valueRed);
|
||||
v.append(whitelevel->valueGreen);
|
||||
v.append(whitelevel->valueBlue);
|
||||
v.append(whitelevel.red());
|
||||
v.append(whitelevel.green());
|
||||
v.append(whitelevel.blue());
|
||||
}
|
||||
|
||||
// send command message
|
||||
@@ -372,7 +379,7 @@ void JsonConnection::setTransform(std::string * transformId, double * saturation
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setCorrection(std::string * correctionId, ColorCorrectionValues *correction)
|
||||
void JsonConnection::setCorrection(QString &correctionId, const QColor & correction)
|
||||
{
|
||||
std::cout << "Set color corrections" << std::endl;
|
||||
|
||||
@@ -381,17 +388,17 @@ void JsonConnection::setCorrection(std::string * correctionId, ColorCorrectionVa
|
||||
command["command"] = "correction";
|
||||
Json::Value & correct = command["correction"];
|
||||
|
||||
if (correctionId != nullptr)
|
||||
if (!correctionId.isNull())
|
||||
{
|
||||
correct["id"] = *correctionId;
|
||||
correct["id"] = correctionId.toStdString();
|
||||
}
|
||||
|
||||
if (correction != nullptr)
|
||||
if (correction.isValid())
|
||||
{
|
||||
Json::Value & v = correct["correctionValues"];
|
||||
v.append(correction->valueRed);
|
||||
v.append(correction->valueGreen);
|
||||
v.append(correction->valueBlue);
|
||||
v.append(correction.red());
|
||||
v.append(correction.green());
|
||||
v.append(correction.blue());
|
||||
}
|
||||
|
||||
// send command message
|
||||
@@ -401,7 +408,7 @@ void JsonConnection::setCorrection(std::string * correctionId, ColorCorrectionVa
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setTemperature(std::string * temperatureId, ColorCorrectionValues *temperature)
|
||||
void JsonConnection::setTemperature(const QString &temperatureId, const QColor & temperature)
|
||||
{
|
||||
std::cout << "Set color temperature corrections" << std::endl;
|
||||
|
||||
@@ -410,17 +417,17 @@ void JsonConnection::setTemperature(std::string * temperatureId, ColorCorrection
|
||||
command["command"] = "temperature";
|
||||
Json::Value & temp = command["temperature"];
|
||||
|
||||
if (temperatureId != nullptr)
|
||||
if (!temperatureId.isNull())
|
||||
{
|
||||
temp["id"] = *temperatureId;
|
||||
temp["id"] = temperatureId.toStdString();
|
||||
}
|
||||
|
||||
if (temperature != nullptr)
|
||||
if (temperature.isValid())
|
||||
{
|
||||
Json::Value & v = temp["correctionValues"];
|
||||
v.append(temperature->valueRed);
|
||||
v.append(temperature->valueGreen);
|
||||
v.append(temperature->valueBlue);
|
||||
v.append(temperature.red());
|
||||
v.append(temperature.green());
|
||||
v.append(temperature.blue());
|
||||
}
|
||||
|
||||
// send command message
|
||||
@@ -430,7 +437,10 @@ void JsonConnection::setTemperature(std::string * temperatureId, ColorCorrection
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setAdjustment(std::string * adjustmentId, ColorAdjustmentValues * redAdjustment, ColorAdjustmentValues * greenAdjustment, ColorAdjustmentValues * blueAdjustment)
|
||||
void JsonConnection::setAdjustment(const QString &adjustmentId,
|
||||
const QColor & redAdjustment,
|
||||
const QColor & greenAdjustment,
|
||||
const QColor & blueAdjustment)
|
||||
{
|
||||
std::cout << "Set color adjustments" << std::endl;
|
||||
|
||||
@@ -439,33 +449,33 @@ void JsonConnection::setAdjustment(std::string * adjustmentId, ColorAdjustmentVa
|
||||
command["command"] = "adjustment";
|
||||
Json::Value & adjust = command["adjustment"];
|
||||
|
||||
if (adjustmentId != nullptr)
|
||||
if (!adjustmentId.isNull())
|
||||
{
|
||||
adjust["id"] = *adjustmentId;
|
||||
adjust["id"] = adjustmentId.toStdString();
|
||||
}
|
||||
|
||||
if (redAdjustment != nullptr)
|
||||
if (redAdjustment.isValid())
|
||||
{
|
||||
Json::Value & v = adjust["redAdjust"];
|
||||
v.append(redAdjustment->valueRed);
|
||||
v.append(redAdjustment->valueGreen);
|
||||
v.append(redAdjustment->valueBlue);
|
||||
v.append(redAdjustment.red());
|
||||
v.append(redAdjustment.green());
|
||||
v.append(redAdjustment.blue());
|
||||
}
|
||||
|
||||
if (greenAdjustment != nullptr)
|
||||
if (greenAdjustment.isValid())
|
||||
{
|
||||
Json::Value & v = adjust["greenAdjust"];
|
||||
v.append(greenAdjustment->valueRed);
|
||||
v.append(greenAdjustment->valueGreen);
|
||||
v.append(greenAdjustment->valueBlue);
|
||||
v.append(greenAdjustment.red());
|
||||
v.append(greenAdjustment.green());
|
||||
v.append(greenAdjustment.blue());
|
||||
}
|
||||
|
||||
if (blueAdjustment != nullptr)
|
||||
if (blueAdjustment.isValid())
|
||||
{
|
||||
Json::Value & v = adjust["blueAdjust"];
|
||||
v.append(blueAdjustment->valueRed);
|
||||
v.append(blueAdjustment->valueGreen);
|
||||
v.append(blueAdjustment->valueBlue);
|
||||
v.append(blueAdjustment.red());
|
||||
v.append(blueAdjustment.green());
|
||||
v.append(blueAdjustment.blue());
|
||||
}
|
||||
|
||||
// send command message
|
||||
|
||||
Reference in New Issue
Block a user