mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00: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:
committed by
brindosch
parent
4972bc086a
commit
c2faf07574
@@ -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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user