From f1208c7f5c98d9dab908147f6ecd80848f0a920d Mon Sep 17 00:00:00 2001 From: vsonnier Date: Mon, 8 Jan 2018 19:23:01 +0100 Subject: [PATCH] When saving bookmarks, use active information when available + Fixed std::string <=> std::wstring conversions using wxString + cleanups. --- src/BookmarkMgr.cpp | 27 +++++++++++++---- src/forms/Bookmark/BookmarkView.cpp | 45 ++++++++++++++++------------- src/util/GLFont.cpp | 8 +++-- 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/src/BookmarkMgr.cpp b/src/BookmarkMgr.cpp index 521ef88..8cb4d5c 100644 --- a/src/BookmarkMgr.cpp +++ b/src/BookmarkMgr.cpp @@ -4,6 +4,7 @@ #include "BookmarkMgr.h" #include "CubicSDR.h" #include "DataTree.h" +#include #define BOOKMARK_RECENTS_MAX 25 @@ -49,7 +50,21 @@ void BookmarkMgr::saveToFile(std::string bookmarkFn, bool backup, bool useFullpa *group->newChild("@expanded") = (getExpandState(bmd_i.first)?std::string("true"):std::string("false")); for (auto &bm_i : bmd_i.second ) { - group->newChildCloneFrom("modem", bm_i->node); + + //if a matching demodulator exists, use its data instead to be be saved, because output_device could have been + //modified by the user. So, save that "live" version instead. + auto matchingDemod = wxGetApp().getDemodMgr().getLastDemodulatorWith(bm_i->type, + bm_i->label, + bm_i->frequency, + bm_i->bandwidth); + + if (matchingDemod != nullptr) { + + wxGetApp().getDemodMgr().saveInstance(group->newChild("modem"), matchingDemod); + } + else { + group->newChildCloneFrom("modem", bm_i->node); + } } } @@ -557,9 +572,10 @@ BookmarkEntryPtr BookmarkMgr::nodeToBookmark(DataNode *node) { std::wstring BookmarkMgr::getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt) { std::wstring dispName = bmEnt->label; - if (dispName == "") { + if (dispName == L"") { std::string freqStr = frequencyToStr(bmEnt->frequency) + " " + bmEnt->type; - dispName = wstring(freqStr.begin(),freqStr.end()); + + dispName = wxString(freqStr).ToStdWstring(); } return dispName; @@ -568,9 +584,10 @@ std::wstring BookmarkMgr::getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt) { std::wstring BookmarkMgr::getActiveDisplayName(DemodulatorInstancePtr demod) { std::wstring activeName = demod->getDemodulatorUserLabel(); - if (activeName == "") { + if (activeName == L"") { std::string wstr = frequencyToStr(demod->getFrequency()) + " " + demod->getDemodulatorType(); - activeName = std::wstring(wstr.begin(),wstr.end()); + + activeName = wxString(wstr).ToStdWstring(); } return activeName; diff --git a/src/forms/Bookmark/BookmarkView.cpp b/src/forms/Bookmark/BookmarkView.cpp index 4cb9888..a30d6a6 100644 --- a/src/forms/Bookmark/BookmarkView.cpp +++ b/src/forms/Bookmark/BookmarkView.cpp @@ -78,7 +78,8 @@ public: if (name.length() == 0) { std::string wstr = frequencyToStr(rangeEnt->startFreq) + " - " + frequencyToStr(rangeEnt->endFreq); - name = std::wstring(wstr.begin(),wstr.end()); + + name = wxString(wstr).ToStdWstring(); } m_questionText->SetLabelText(L"Are you sure you want to remove the range\n '" + name + L"'?"); @@ -103,7 +104,8 @@ public: if (name.length() == 0) { std::string wstr = frequencyToStr(rangeEnt->startFreq) + " - " + frequencyToStr(rangeEnt->endFreq); - name = std::wstring(wstr.begin(),wstr.end()); + + name = wxString(wstr).ToStdWstring(); } m_questionText->SetLabelText(L"Are you sure you want to update the range\n '" + name + L"' to the active range?"); @@ -311,9 +313,9 @@ wxTreeItemId BookmarkView::refreshBookmarks() { std::wstring fullText = labelVal + L" " + bmEnt->label + L" " + std::to_wstring(bmEnt->frequency) + - L" " + std::wstring(freqStr.begin(),freqStr.end()) + - L" " + std::wstring(bwStr.begin(),bwStr.end()) + - L" " + std::wstring(bmEnt->type.begin(),bmEnt->type.end()); + L" " + wxString(freqStr).ToStdWstring() + + L" " + wxString(bwStr).ToStdWstring() + + L" " + wxString(bmEnt->type).ToStdWstring(); if (!isKeywordMatch(fullText, searchKeywords)) { continue; @@ -379,9 +381,9 @@ void BookmarkView::doUpdateActiveList() { std::wstring fullText = activeLabel.ToStdWstring() + L" " + demod_i->getDemodulatorUserLabel() + L" " + std::to_wstring(demod_i->getFrequency()) + - L" " + std::wstring(freqStr.begin(),freqStr.end()) + - L" " + std::wstring(bwStr.begin(),bwStr.end()) + - L" " + std::wstring(mtype.begin(),mtype.end()); + L" " + wxString(freqStr).ToStdWstring() + + L" " + wxString(bwStr).ToStdWstring() + + L" " + wxString(mtype).ToStdWstring(); if (!isKeywordMatch(fullText, searchKeywords)) { continue; @@ -418,9 +420,10 @@ void BookmarkView::doUpdateActiveList() { std::wstring labelVal = re_i->label; - if (labelVal == "") { + if (labelVal == L"") { std::string wstr = frequencyToStr(re_i->startFreq) + " - " + frequencyToStr(re_i->endFreq); - labelVal = std::wstring(wstr.begin(),wstr.end()); + + labelVal = wxString(wstr).ToStdWstring(); } wxTreeItemId itm = m_treeView->AppendItem(rangeBranch, labelVal); @@ -448,9 +451,10 @@ void BookmarkView::doUpdateActiveList() { std::wstring labelVal; bmr_i->node->child("user_label")->element()->get(labelVal); - if (labelVal == "") { - std::string wstr = frequencyToStr(bmr_i->frequency) + " " + bmr_i->type; - labelVal = std::wstring(wstr.begin(),wstr.end()); + if (labelVal == L"") { + std::string str = frequencyToStr(bmr_i->frequency) + " " + bmr_i->type; + + labelVal = wxString(str).ToStdWstring(); } if (searchKeywords.size()) { @@ -460,9 +464,10 @@ void BookmarkView::doUpdateActiveList() { std::wstring fullText = labelVal + L" " + std::to_wstring(bmr_i->frequency) + - L" " + std::wstring(freqStr.begin(),freqStr.end()) + - L" " + std::wstring(bwStr.begin(),bwStr.end()) + - L" " + std::wstring(bmr_i->type.begin(),tvi->bookmarkEnt->type.end()); + + L" " + wxString(freqStr).ToStdWstring() + + L" " + wxString(bwStr).ToStdWstring() + + L" " + wxString(bmr_i->type).ToStdWstring(); if (!isKeywordMatch(fullText, searchKeywords)) { continue; @@ -971,7 +976,7 @@ void BookmarkView::rangeSelection(BookmarkRangeEntryPtr re) { std::string strFreq = frequencyToStr(re->startFreq) + "-" + frequencyToStr(re->endFreq); - m_frequencyVal->SetLabelText(std::wstring(strFreq.begin(),strFreq.end())); + m_frequencyVal->SetLabelText(wxString(strFreq)); showProps(); @@ -1473,16 +1478,16 @@ void BookmarkView::onSearchTextFocus( wxMouseEvent& event ) { void BookmarkView::onSearchText( wxCommandEvent& event ) { - wstring searchText = m_searchText->GetValue().Trim().Lower().ToStdWstring(); + std::wstring searchText = m_searchText->GetValue().Trim().Lower().ToStdWstring(); searchKeywords.clear(); if (searchText.length() != 0) { std::wstringstream searchTextLo(searchText); - wstring tmp; + std::wstring tmp; while(std::getline(searchTextLo, tmp, L' ')) { - if (tmp.length() != 0 && tmp.find(L"search.") == wstring::npos) { + if (tmp.length() != 0 && tmp.find(L"search.") == std::wstring::npos) { searchKeywords.push_back(tmp); // std::wcout << L"Keyword: " << tmp << '\n'; } diff --git a/src/util/GLFont.cpp b/src/util/GLFont.cpp index 6e1a46a..924f9f8 100644 --- a/src/util/GLFont.cpp +++ b/src/util/GLFont.cpp @@ -3,6 +3,8 @@ #include "GLFont.h" +#include + #include #include #include @@ -245,11 +247,11 @@ void GLFont::loadFontOnce() { //Re-compute the resource dir. resourceFolder = fontDefFileName.GetPath(); - std::wstring fontDefFileNamePath = fontDefFileName.GetFullPath(wxPATH_NATIVE).ToStdWstring(); + std::string fontDefFileNamePath = fontDefFileName.GetFullPath(wxPATH_NATIVE).ToStdString(); std::wifstream input; - std::string inpFileStr(fontDefFileNamePath.begin(), fontDefFileNamePath.end()); - input.open(inpFileStr, std::ios::in); + + input.open(fontDefFileNamePath, std::ios::in); std::wstring op;