When saving bookmarks, use active information when available

+ Fixed std::string <=> std::wstring conversions using wxString
+ cleanups.
This commit is contained in:
vsonnier 2018-01-08 19:23:01 +01:00
parent 8f45451df2
commit f1208c7f5c
3 changed files with 52 additions and 28 deletions

View File

@ -4,6 +4,7 @@
#include "BookmarkMgr.h"
#include "CubicSDR.h"
#include "DataTree.h"
#include <wx/string.h>
#define BOOKMARK_RECENTS_MAX 25
@ -49,9 +50,23 @@ 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 ) {
//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);
}
}
}
DataNode *recent_modems = s.rootNode()->newChild("recent_modems");
@ -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;

View File

@ -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';
}

View File

@ -3,6 +3,8 @@
#include "GLFont.h"
#include <wx/string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
@ -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;