Skip to content

Commit

Permalink
Handle dynamic translation
Browse files Browse the repository at this point in the history
  • Loading branch information
oben01 committed Oct 23, 2020
1 parent 2ef8cd4 commit 39baea0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 32 deletions.
55 changes: 29 additions & 26 deletions sources/plugins/StreamDeck/StreamDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,52 +201,55 @@ void CStreamDeck::doWork(boost::shared_ptr<yApi::IYPluginApi> api)
{
shared::CDataContainer mainSection;
mainSection.set("type", "section");
mainSection.createArray("content");
mainSection.set("i18nKey", "mainSection");

auto keys = CDeviceManagerHelper::buildKeys(m_usbDeviceInformation->keyCols,
m_usbDeviceInformation->keyRows);

auto defaultIconsNames = CDefaultIconSelector::getAllDefaultIconNames();

for (auto& key : keys)
auto body = shared::CDataContainer::make();
auto keySection = shared::CDataContainer::make();
auto keyOptionSection = shared::CDataContainer::make();

for (auto i = 0; i < keys.size(); ++i)
{
shared::CDataContainer subSection;
subSection.set("type", "section");
subSection.set("name", key);
subSection.set("enableWithCheckBox", "true");
subSection.set("enableWithCheckBoxDefaultValue", "false");
shared::CDataContainer keyOptions;
keyOptions.set("type", "section");
keyOptions.set("name", keys[i]);
keyOptions.set("enableWithCheckBox", "true");
keyOptions.set("enableWithCheckBoxDefaultValue", "false");

shared::CDataContainer iconsOptions;
iconsOptions.set("type", "enum");
iconsOptions.set("name", "icons");
iconsOptions.set("description", "List of available icons");
iconsOptions.set("i18nKey", "iconsArray");
iconsOptions.set("values", defaultIconsNames);
iconsOptions.set("defaultValue", defaultIconsNames[0]);

shared::CDataContainer customTextOptions;
customTextOptions.set("type", "string");
customTextOptions.set("name", "Custom text");
customTextOptions.set("description", "Custom text to display below the icon (Optional)");
customTextOptions.set("i18nKey", "customTextArray");
customTextOptions.set("required", "false");

subSection.createArray("content");
subSection.appendArray("content", iconsOptions);
subSection.appendArray("content", customTextOptions);
shared::CDataContainer subSectionContent;
subSectionContent.set("subSection", subSection);
keyOptionSection->set("icon", iconsOptions);
keyOptionSection->set("customText", customTextOptions);

keyOptions.set("content", keyOptionSection);

mainSection.appendArray("content", subSection);
keyOptions.set("i18nKey", "keyElement");
keySection->set("keyElement#" + std::to_string(i), keyOptions);

mainSection.set("content", keySection);
}
auto body = shared::CDataContainer::make();

body->set("mainSection", mainSection);
auto test = body->serialize();
YADOMS_LOG(information) << "Body : " << body->serialize();

auto deviceConfigurationSchemaRequest = api
->getEventHandler().getEventData<boost::shared_ptr<yApi::
IDeviceConfigurationSchemaRequest>>();

YADOMS_LOG(information) << "Body : " << body->serialize();

deviceConfigurationSchemaRequest->sendSuccess(body);

break;
Expand All @@ -261,25 +264,25 @@ void CStreamDeck::doWork(boost::shared_ptr<yApi::IYPluginApi> api)

auto pluginPath = api->getInformation()->getPath().string();
auto keyCounter = 0;
while (config->exists("mainSection.content." + std::to_string(keyCounter)))
while (config->exists("mainSection.content.keyElement#" + std::to_string(keyCounter)))
{
auto isKeyChecked = config->get<bool>("mainSection.content." + std::to_string(keyCounter) + ".checkbox");
auto isKeyChecked = config->get<bool>(
"mainSection.content.keyElement#" + std::to_string(keyCounter) + ".checkbox");
if (isKeyChecked)
{
auto iconNameIndex = config->get<int>(
"mainSection.content." + std::to_string(keyCounter) + ".content.0");
"mainSection.content.keyElement#" + std::to_string(keyCounter) + ".content.icon");

auto iconPath = CDefaultIconSelector::getIconPath(pluginPath, iconNameIndex);
auto customText = config->get<std::string>(
"mainSection.content." + std::to_string(keyCounter) + ".content.1");
"mainSection.content.keyElement#" + std::to_string(keyCounter) + ".content.customText");

CFileManager fileManager(iconPath);
fileManager.read();
auto img = fileManager.getData();
fileManager.close();

m_deviceManager->setKeyImage(img, keyCounter, customText);

}
keyCounter++;
}
Expand All @@ -306,7 +309,7 @@ void CStreamDeck::declareDeviceAndKeywords(boost::shared_ptr<yApi::IYPluginApi>&
const auto keywordsAsVector = CDeviceManagerHelper::mapToHistorizableVector(m_keywords);

const auto deviceModel = CDeviceManagerHelper::getDeviceModelAsAString(m_usbDeviceInformation->productID);
api->declareDevice(m_usbDeviceInformation->deviceName, m_usbDeviceInformation->serialNumber,
api->declareDevice(m_usbDeviceInformation->deviceName, "keyCreationDynamic",
deviceModel, keywordsAsVector);
}
}
Expand Down
26 changes: 23 additions & 3 deletions sources/plugins/StreamDeck/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,29 @@
}
},
"deviceConfiguration": {
"mainSection": {
"name": "Build keys",
"description": "Personalize your stream deck keys with predefined icons and customizable texts. If the key box is not checked, the key will be empty."
"dynamicConfigurationSchema": {
"schemas": {
"keyCreationDynamic": {
"mainSection": {
"name": "Build keys",
"description": "Personalize your stream deck keys with predefined icons and customizable texts. If the key box is not checked, the key will be empty.",
"content": {
"keyElement": {
"content": {
"iconsArray": {
"name": "Icons",
"description": "List of available icons (see [the Wiki](https://github.com/Yadoms/yadoms/wiki/StreamDeck#available-icons))"
},
"customTextArray": {
"name": "Custom text",
"description": "Custom text to display below the icon (OPTIONAL)"
}
}
}
}
}
}
}
}
}
}
26 changes: 23 additions & 3 deletions sources/plugins/StreamDeck/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,29 @@
}
},
"deviceConfiguration": {
"mainSection": {
"name": "Création des touches",
"description": "Personnaliser vos touches stream deck avec des icones predefinies et des textes personnalisable. Si la case à touche n'est pas cochée, la touche sera vide"
"dynamicConfigurationSchema": {
"schemas": {
"keyCreationDynamic": {
"mainSection": {
"name": "Création des touches",
"description": "Personnaliser vos touches stream deck avec des icones predefinies et des textes personnalisable. Si la case à touche n'est pas cochée, la touche sera vide",
"content": {
"keyElement": {
"content": {
"iconsArray": {
"name": "Icône",
"description": "La liste des icones disponible (voir [le Wiki](https://github.com/Yadoms/yadoms/wiki/StreamDeck#available-icons))"
},
"customTextArray": {
"name": "Texte personnalisé",
"description": "Texte personnalisé à afficher en dessous de l'icône (OPTIONNEL)"
}
}
}
}
}
}
}
}
}
}

0 comments on commit 39baea0

Please sign in to comment.