2023-12-16 17:36:57 +01:00
|
|
|
#include "WUPSConfigItemV1.h"
|
2024-11-27 20:44:36 +01:00
|
|
|
#include "utils/StringTools.h"
|
|
|
|
#include "utils/logger.h"
|
2023-12-16 17:36:57 +01:00
|
|
|
|
|
|
|
namespace WUPSConfigAPIBackend {
|
2024-11-27 20:44:36 +01:00
|
|
|
WUPSConfigItemV1::WUPSConfigItemV1(const std::string_view configId,
|
|
|
|
const std::string_view displayName,
|
|
|
|
const WUPSConfigAPIItemCallbacksV1 &callbacks,
|
|
|
|
void *context) : WUPSConfigItem(std::string(displayName)) {
|
2023-12-16 17:36:57 +01:00
|
|
|
this->mConfigId = configId;
|
|
|
|
this->mContext = context;
|
|
|
|
this->mCallbacks = callbacks;
|
|
|
|
this->mDefaultValue = getCurrentValueDisplayImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
WUPSConfigItemV1::~WUPSConfigItemV1() {
|
|
|
|
if (this->mCallbacks.onDelete == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_WARN("onDelete callback not implemented. [%s]", mDisplayName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->mCallbacks.onDelete(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string WUPSConfigItemV1::getCurrentValueDisplayImpl() const {
|
|
|
|
if (this->mCallbacks.getCurrentValueDisplay == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("getCurrentValueDisplay callback not implemented. [%s]", mDisplayName.c_str());
|
|
|
|
return "NOT_IMPLEMENTED";
|
|
|
|
}
|
|
|
|
char buf[80];
|
|
|
|
int res = this->mCallbacks.getCurrentValueDisplay(mContext, buf, sizeof(buf));
|
|
|
|
if (res != 0) {
|
|
|
|
return string_format("[ERROR %d]", res);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string WUPSConfigItemV1::getCurrentValueDisplay() const {
|
|
|
|
return getCurrentValueDisplayImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string WUPSConfigItemV1::getCurrentValueSelectedDisplay() const {
|
|
|
|
if (this->mCallbacks.getCurrentValueSelectedDisplay == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("getCurrentValueSelectedDisplay callback not implemented. [%s]", mDisplayName.c_str());
|
|
|
|
return "NOT_IMPLEMENTED";
|
|
|
|
}
|
|
|
|
char buf[80];
|
|
|
|
int res = this->mCallbacks.getCurrentValueSelectedDisplay(mContext, buf, sizeof(buf));
|
|
|
|
if (res != 0) {
|
|
|
|
return string_format("[ERROR %d]", res);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2024-11-27 20:44:36 +01:00
|
|
|
void WUPSConfigItemV1::onSelected(const bool isSelected) const {
|
2023-12-16 17:36:57 +01:00
|
|
|
if (this->mCallbacks.onSelected == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("onSelected callback not implemented. [%s]", mDisplayName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->mCallbacks.onSelected(mContext, isSelected);
|
|
|
|
}
|
|
|
|
|
2024-11-27 20:44:36 +01:00
|
|
|
void WUPSConfigItemV1::onButtonPressed(const WUPSConfigButtons buttons) const {
|
2023-12-16 17:36:57 +01:00
|
|
|
if (this->mCallbacks.onButtonPressed == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("onButtonPressed callback not implemented. [%s]", mDisplayName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->mCallbacks.onButtonPressed(mContext, buttons);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WUPSConfigItemV1::isMovementAllowed() const {
|
|
|
|
if (this->mCallbacks.isMovementAllowed == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("isMovementAllowed callback not implemented. [%s]", mDisplayName.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->mCallbacks.isMovementAllowed(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WUPSConfigItemV1::restoreDefault() const {
|
|
|
|
if (this->mCallbacks.restoreDefault == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("restoreDefault callback not implemented. [%s]", mDisplayName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->mCallbacks.restoreDefault(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WUPSConfigItemV1::onCloseCallback() {
|
|
|
|
if (this->mCallbacks.callCallback == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("callCallback callback not implemented. [%s]", mDisplayName.c_str());
|
2024-04-27 17:44:51 +02:00
|
|
|
return;
|
2023-12-16 17:36:57 +01:00
|
|
|
}
|
|
|
|
if (mDefaultValue != getCurrentValueDisplay()) {
|
|
|
|
this->mCallbacks.callCallback(mContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WUPSConfigItemV1::setConfigId(const std::string &configId) {
|
|
|
|
mConfigId = configId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &WUPSConfigItemV1::getConfigId() {
|
|
|
|
return mConfigId;
|
|
|
|
}
|
|
|
|
} // namespace WUPSConfigAPIBackend
|