diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/api/config/items/attribute.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/Wasabi/api/config/items/attribute.cpp')
-rw-r--r-- | Src/Wasabi/api/config/items/attribute.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/Src/Wasabi/api/config/items/attribute.cpp b/Src/Wasabi/api/config/items/attribute.cpp new file mode 100644 index 00000000..27b519b6 --- /dev/null +++ b/Src/Wasabi/api/config/items/attribute.cpp @@ -0,0 +1,131 @@ +#include <precomp.h> + +#include "attribute.h" +#include <api/config/items/cfgitemi.h> + + +Attribute::Attribute(const wchar_t *newname, const wchar_t *_desc) : + NamedW(newname), desc(_desc), cfgitemi(NULL), private_storage(NULL) { } + +Attribute::~Attribute() { + delete private_storage; +} + +const wchar_t *Attribute::getAttributeName() { + return NamedW::getName(); +} + +const wchar_t *Attribute::getAttributeDesc() { + return desc; +} + +int Attribute::getValueAsInt() +{ + wchar_t buf[1024]=L""; + getData(buf, 1024); + return WTOI(buf); +} + +int Attribute::setValueAsInt(int newval, bool def) +{ + return setData(StringPrintfW(newval), def); +} + +double Attribute::getValueAsDouble() +{ + wchar_t buf[1024] = {0}; + getData(buf, 1024); + return WTOF(buf); +} + +double Attribute::setValueAsDouble(double newval, bool def) +{ + return setData(StringPrintfW(newval), def); +} + +int Attribute::getDataLen() { + if (private_storage != NULL) + return (int)private_storage->len()+1; + + ASSERTPR(WASABI_API_CONFIG != NULL, "getDataLen() before API"); + int r = WASABI_API_CONFIG->getStringPrivateLen(mkTag()); + if (r < 0) { + r = (int)default_val.len()+1; + } + return r; +} + +int Attribute::getData(wchar_t *data, int data_len) +{ + if (data == NULL || data_len < 0) + return 0; + if (private_storage != NULL) + { + if (private_storage->isempty()) + { + if (data_len >= 1) { + *data = 0; + return 1; + } + return 0; + } + WCSCPYN(data, private_storage->getValue(), data_len); + return MIN((int)private_storage->len(), data_len); + } + ASSERTPR(WASABI_API_CONFIG != NULL, "can't get without api"); + if (WASABI_API_CONFIG == NULL) return 0; + int r = WASABI_API_CONFIG->getStringPrivate(mkTag(), data, data_len, default_val.isempty() ? L"" : default_val.getValue()); + return r; +} + +int Attribute::setData(const wchar_t *data, bool def) +{ + if (def) { // setting default value + default_val = data; + return 1; + } + ASSERTPR(WASABI_API_CONFIG != NULL, "can't set data before api"); + if (WASABI_API_CONFIG == NULL) return 0; + + int r = setDataNoCB(data); + if (r && cfgitemi != NULL) cfgitemi->cfgitem_onAttribSetValue(this); + return r; +} + +int Attribute::setDataNoCB(const wchar_t *data) +{ + if (private_storage != NULL) { + private_storage->setValue(data); + } else { + WASABI_API_CONFIG->setStringPrivate(mkTag(), data); + } + dependent_sendEvent(Attribute::depend_getClassGuid(), Event_DATACHANGE); + return 1; +} + +void Attribute::setCfgItem(CfgItemI *item) +{ + delete private_storage; private_storage = NULL; + ASSERT(cfgitemi == NULL || item == NULL); + cfgitemi = item; + if (cfgitemi != NULL) + { + if (cfgitemi->cfgitem_usePrivateStorage()) + private_storage = new StringW; + } +} + +StringW Attribute::mkTag() +{ + StringW ret; + if (cfgitemi) + { + ret = cfgitemi->cfgitem_getPrefix(); + } + ret.cat(getName()); + return ret; +} + +void Attribute::disconnect() { + setCfgItem(NULL); +} |