Fix #659 : Allow manual editing of user_labels in normal ASCII

This commit is contained in:
vsonnier 2018-06-06 20:49:37 +02:00
parent 35482a0ede
commit 3e4aadfaef
4 changed files with 76 additions and 2 deletions

View File

@ -570,6 +570,38 @@ BookmarkEntryPtr BookmarkMgr::demodToBookmarkEntry(DemodulatorInstancePtr demod)
return be;
}
std::wstring BookmarkMgr::getSafeWstringValue(DataNode* node, const std::string& childNodeName) {
std::wstring decodedWString = L"";
if (node != nullptr) {
DataNode* childNode = node->getNext(childNodeName.c_str());
//1) decode as encoded wstring:
try {
childNode->element()->get(decodedWString);
} catch (DataTypeMismatchException* e) {
//2) wstring decode fail, try simple std::string
std::string decodedStdString;
try {
childNode->element()->get(decodedStdString);
//use wxString for a clean conversion to a wstring:
decodedWString = wxString(decodedStdString).ToStdWstring();
} catch (DataTypeMismatchException* e) {
//nothing works, return an empty string.
decodedWString = L"";
}
}
}
return decodedWString;
}
BookmarkEntryPtr BookmarkMgr::nodeToBookmark(DataNode *node) {
if (!node->hasAnother("frequency") || !node->hasAnother("type") || !node->hasAnother("bandwidth")) {
return nullptr;
@ -582,7 +614,7 @@ BookmarkEntryPtr BookmarkMgr::nodeToBookmark(DataNode *node) {
node->getNext("bandwidth")->element()->get(be->bandwidth);
if (node->hasAnother("user_label")) {
node->getNext("user_label")->element()->get(be->label);
be->label = BookmarkMgr::getSafeWstringValue( node, "user_label");
}
node->rewindAll();

View File

@ -129,10 +129,15 @@ public:
static std::wstring getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt);
static std::wstring getActiveDisplayName(DemodulatorInstancePtr demod);
protected:
void trimRecents();
void loadDefaultRanges();
//utility method that attemts to decode the childNodeName as std::wstring, else as std::string, else
//return an empty string.
static std::wstring getSafeWstringValue(DataNode* node, const std::string& childNodeName);
BookmarkEntryPtr demodToBookmarkEntry(DemodulatorInstancePtr demod);
BookmarkEntryPtr nodeToBookmark(DataNode *node);

View File

@ -16,6 +16,7 @@
#endif
#include "DataTree.h"
#include <wx/string.h>
bool demodFreqCompare (DemodulatorInstancePtr i, DemodulatorInstancePtr j) { return (i->getFrequency() < j->getFrequency()); }
bool inactiveCompare (DemodulatorInstancePtr i, DemodulatorInstancePtr j) { return (i->isActive() < j->isActive()); }
@ -432,6 +433,36 @@ void DemodulatorMgr::saveInstance(DataNode *node, DemodulatorInstancePtr inst) {
}
}
std::wstring DemodulatorMgr::getSafeWstringValue(DataNode* node) {
std::wstring decodedWString = L"";
if (node != nullptr) {
//1) decode as encoded wstring:
try {
node->element()->get(decodedWString);
} catch (DataTypeMismatchException* e) {
//2) wstring decode fail, try simple std::string
std::string decodedStdString;
try {
node->element()->get(decodedStdString);
//use wxString for a clean conversion to a wstring:
decodedWString = wxString(decodedStdString).ToStdWstring();
} catch (DataTypeMismatchException* e) {
//nothing works, return an empty string.
decodedWString = L"";
}
}
}
return decodedWString;
}
DemodulatorInstancePtr DemodulatorMgr::loadInstance(DataNode *node) {
std::lock_guard < std::recursive_mutex > lock(demods_busy);
@ -486,7 +517,8 @@ DemodulatorInstancePtr DemodulatorMgr::loadInstance(DataNode *node) {
DataNode *demodUserLabel = node->hasAnother("user_label") ? node->getNext("user_label") : nullptr;
if (demodUserLabel) {
demodUserLabel->element()->get(user_label);
user_label = DemodulatorMgr::getSafeWstringValue(demodUserLabel);
}
ModemSettings mSettings;

View File

@ -77,8 +77,13 @@ public:
DemodulatorInstancePtr loadInstance(DataNode *node);
private:
//utility method that attemts to decode node value as std::wstring, else as std::string, else
//return an empty string.
static std::wstring getSafeWstringValue(DataNode* node);
std::vector<DemodulatorInstancePtr> demods;
DemodulatorInstancePtr activeDemodulator;