mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Delete custom created effect configurations with JSON RPC (#289)
* Add ability to delete custom created Effects * Add deleteEffect function to Hyperion-Remote * Add deleteEffect function to Hyperion-Remote * Update schema.json * Update JsonSchemas.qrc * Add schema-delete-effect.json * Add deleteEffect function to JSON RPC * Add deleteEffect function to JSON RPC * Add Effect configuration file (.json) to Effect Definition * Update EffectDefinition.h
This commit is contained in:
parent
4972bc086a
commit
c2faf07574
@ -6,7 +6,6 @@
|
||||
|
||||
struct EffectDefinition
|
||||
{
|
||||
QString name;
|
||||
QString script;
|
||||
QString name, script, file;
|
||||
QJsonObject args;
|
||||
};
|
||||
|
@ -248,6 +248,7 @@ bool EffectEngine::loadEffectDefinition(const QString &path, const QString &effe
|
||||
|
||||
// ---------- setup the definition ----------
|
||||
|
||||
effectDefinition.file = fileName;
|
||||
QJsonObject config = configEffect.object();
|
||||
QString scriptName = config["script"].toString();
|
||||
effectDefinition.name = config["name"].toString();
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <QHostInfo>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QCoreApplication>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
@ -285,6 +286,8 @@ void JsonClientConnection::handleMessage(const QString& messageString)
|
||||
handleEffectCommand(message, command, tan);
|
||||
else if (command == "create-effect")
|
||||
handleCreateEffectCommand(message, command, tan);
|
||||
else if (command == "delete-effect")
|
||||
handleDeleteEffectCommand(message, command, tan);
|
||||
else if (command == "serverinfo")
|
||||
handleServerInfoCommand(message, command, tan);
|
||||
else if (command == "clear")
|
||||
@ -481,7 +484,15 @@ void JsonClientConnection::handleCreateEffectCommand(const QJsonObject& message,
|
||||
effectJson["name"] = message["name"].toString();
|
||||
effectJson["script"] = message["script"].toString();
|
||||
effectJson["args"] = message["args"].toObject();
|
||||
QJsonFactory::writeJson(effectArray[0].toString() + QDir::separator() + message["name"].toString().replace(QString(" "), QString("")) + QString(".json"), effectJson);
|
||||
|
||||
QFileInfo newFileName(effectArray[0].toString() + QDir::separator() + message["name"].toString().replace(QString(" "), QString("")) + QString(".json"));
|
||||
|
||||
while(newFileName.exists())
|
||||
{
|
||||
newFileName.setFile(effectArray[0].toString() + QDir::separator() + newFileName.baseName() + QString::number(qrand() % ((10) - 0) + 0) + QString(".json"));
|
||||
}
|
||||
|
||||
QJsonFactory::writeJson(newFileName.absoluteFilePath(), effectJson);
|
||||
} else
|
||||
{
|
||||
sendErrorReply("Can't save new effect. Effect path empty", command, tan);
|
||||
@ -497,6 +508,43 @@ void JsonClientConnection::handleCreateEffectCommand(const QJsonObject& message,
|
||||
sendErrorReply("Error while parsing json: Message size " + QString(message.size()), command, tan);
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleDeleteEffectCommand(const QJsonObject& message, const QString& command, const int tan)
|
||||
{
|
||||
struct find_effect: std::unary_function<EffectDefinition, bool>
|
||||
{
|
||||
QString effectName;
|
||||
find_effect(QString effectName) :effectName(effectName) { }
|
||||
bool operator()(EffectDefinition const& effectDefinition) const
|
||||
{
|
||||
return effectDefinition.name == effectName;
|
||||
}
|
||||
};
|
||||
|
||||
if(message.size() > 0)
|
||||
{
|
||||
QString effectName = message["name"].toString();
|
||||
std::list<EffectDefinition> effectsDefinition = _hyperion->getEffects();
|
||||
std::list<EffectDefinition>::iterator it = std::find_if(effectsDefinition.begin(), effectsDefinition.end(), find_effect(effectName));
|
||||
|
||||
if (it != effectsDefinition.end())
|
||||
{
|
||||
QFileInfo effectConfigurationFile(it->file);
|
||||
if (effectConfigurationFile.absoluteFilePath().mid(0, 1) != ":" )
|
||||
{
|
||||
if (effectConfigurationFile.exists())
|
||||
{
|
||||
bool result = QFile::remove(effectConfigurationFile.absoluteFilePath());
|
||||
(result) ? sendSuccessReply(command, tan) : sendErrorReply("Can't delete effect configuration file: " + effectConfigurationFile.absoluteFilePath() + ". Please check permissions", command, tan);
|
||||
} else
|
||||
sendErrorReply("Can't find effect configuration file: " + effectConfigurationFile.absoluteFilePath(), command, tan);
|
||||
} else
|
||||
sendErrorReply("Can't delete internal effect: " + message["name"].toString(), command, tan);
|
||||
} else
|
||||
sendErrorReply("Effect " + message["name"].toString() + " not found", command, tan);
|
||||
} else
|
||||
sendErrorReply("Error while parsing json: Message size " + QString(message.size()), command, tan);
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QString& command, const int tan)
|
||||
{
|
||||
// create result
|
||||
@ -649,6 +697,7 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt
|
||||
{
|
||||
QJsonObject effect;
|
||||
effect["name"] = effectDefinition.name;
|
||||
effect["file"] = effectDefinition.file;
|
||||
effect["script"] = effectDefinition.script;
|
||||
effect["args"] = effectDefinition.args;
|
||||
effects.append(effect);
|
||||
|
@ -96,6 +96,13 @@ private:
|
||||
///
|
||||
void handleCreateEffectCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Effect message (Delete JSON Effect)
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleDeleteEffectCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Server info message
|
||||
///
|
||||
|
@ -12,6 +12,7 @@
|
||||
<file alias="schema-adjustment">schema/schema-adjustment.json</file>
|
||||
<file alias="schema-effect">schema/schema-effect.json</file>
|
||||
<file alias="schema-create-effect">schema/schema-create-effect.json</file>
|
||||
<file alias="schema-delete-effect">schema/schema-delete-effect.json</file>
|
||||
<file alias="schema-sourceselect">schema/schema-sourceselect.json</file>
|
||||
<file alias="schema-config">schema/schema-config.json</file>
|
||||
<file alias="schema-componentstate">schema/schema-componentstate.json</file>
|
||||
|
21
libsrc/jsonserver/schema/schema-delete-effect.json
Normal file
21
libsrc/jsonserver/schema/schema-delete-effect.json
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["delete-effect"]
|
||||
},
|
||||
"tan" : {
|
||||
"type" : "integer"
|
||||
},
|
||||
"name" :
|
||||
{
|
||||
"type" : "string",
|
||||
"required" : true
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["color", "image", "effect", "create-effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "config", "componentstate", "ledcolors"]
|
||||
"enum" : ["color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "config", "componentstate", "ledcolors"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -209,6 +209,22 @@ void JsonConnection::createEffect(const QString &effectName, const QString &effe
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::deleteEffect(const QString &effectName)
|
||||
{
|
||||
qDebug() << "Delete effect configuration" << effectName;
|
||||
|
||||
// create command
|
||||
QJsonObject effect;
|
||||
effect["command"] = QString("delete-effect");
|
||||
effect["name"] = effectName;
|
||||
|
||||
// send command message
|
||||
QJsonObject reply = sendMessage(effect);
|
||||
|
||||
// parse reply message
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
QString JsonConnection::getServerInfo()
|
||||
{
|
||||
qDebug() << "Get server info";
|
||||
|
@ -64,6 +64,13 @@ public:
|
||||
/// @param effectArgs The arguments of the effect
|
||||
///
|
||||
void createEffect(const QString &effectName, const QString &effectScript, const QString & effectArgs);
|
||||
|
||||
///
|
||||
/// Delete a effect configuration file (.json)
|
||||
///
|
||||
/// @param effectName The name of the effect
|
||||
///
|
||||
void deleteEffect(const QString &effectName);
|
||||
|
||||
///
|
||||
/// Retrieve a list of all occupied priority channels
|
||||
|
@ -65,6 +65,7 @@ int main(int argc, char * argv[])
|
||||
Option & argEffectFile = parser.add<Option> (0x0, "effectFile", "Arguments to use in combination with --createEffect");
|
||||
Option & argEffectArgs = parser.add<Option> (0x0, "effectArgs", "Arguments to use in combination with the specified effect. Should be a Json object string.", "");
|
||||
Option & argCreateEffect= parser.add<Option> (0x0, "createEffect","Write a new Json Effect configuration file.\nFirst parameter = Effect name.\nSecond parameter = Effect file (--effectFile).\nLast parameter = Effect arguments (--effectArgs.)", "");
|
||||
Option & argDeleteEffect= parser.add<Option> (0x0, "deleteEffect","Delete a custom created Json Effect configuration file.");
|
||||
BooleanOption & argServerInfo = parser.add<BooleanOption>('l', "list" , "List server info and active effects with priority and duration");
|
||||
BooleanOption & argClear = parser.add<BooleanOption>('x', "clear" , "Clear data for the priority channel provided by the -p option");
|
||||
BooleanOption & argClearAll = parser.add<BooleanOption>(0x0, "clearall" , "Clear data for all active priority channels");
|
||||
@ -108,7 +109,7 @@ int main(int argc, char * argv[])
|
||||
bool colorModding = colorTransform || colorAdjust;
|
||||
|
||||
// check that exactly one command was given
|
||||
int commandCount = count({parser.isSet(argColor), parser.isSet(argImage), parser.isSet(argEffect), parser.isSet(argCreateEffect), parser.isSet(argServerInfo), parser.isSet(argClear), parser.isSet(argClearAll), parser.isSet(argEnableComponent), parser.isSet(argDisableComponent), colorModding, parser.isSet(argSource), parser.isSet(argSourceAuto), parser.isSet(argSourceOff), parser.isSet(argConfigGet), parser.isSet(argSchemaGet), parser.isSet(argConfigSet)});
|
||||
int commandCount = count({parser.isSet(argColor), parser.isSet(argImage), parser.isSet(argEffect), parser.isSet(argCreateEffect), parser.isSet(argDeleteEffect), parser.isSet(argServerInfo), parser.isSet(argClear), parser.isSet(argClearAll), parser.isSet(argEnableComponent), parser.isSet(argDisableComponent), colorModding, parser.isSet(argSource), parser.isSet(argSourceAuto), parser.isSet(argSourceOff), parser.isSet(argConfigGet), parser.isSet(argSchemaGet), parser.isSet(argConfigSet)});
|
||||
if (commandCount != 1)
|
||||
{
|
||||
qWarning() << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:";
|
||||
@ -116,6 +117,7 @@ int main(int argc, char * argv[])
|
||||
showHelp(argImage);
|
||||
showHelp(argEffect);
|
||||
showHelp(argCreateEffect);
|
||||
showHelp(argDeleteEffect);
|
||||
showHelp(argServerInfo);
|
||||
showHelp(argClear);
|
||||
showHelp(argClearAll);
|
||||
@ -163,6 +165,10 @@ int main(int argc, char * argv[])
|
||||
{
|
||||
connection.createEffect(argCreateEffect.value(parser), argEffectFile.value(parser), argEffectArgs.value(parser));
|
||||
}
|
||||
else if (parser.isSet(argDeleteEffect))
|
||||
{
|
||||
connection.deleteEffect(argDeleteEffect.value(parser));
|
||||
}
|
||||
else if (parser.isSet(argServerInfo))
|
||||
{
|
||||
QString info = connection.getServerInfo();
|
||||
|
Loading…
Reference in New Issue
Block a user