Skip to content

Commit 06506c6

Browse files
authored
Merge pull request #561 from drowe67/ms-freq-list-locale
Properly convert frequency list entries to current locale.
2 parents 1f0b0e2 + 7d91958 commit 06506c6

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

USER_MANUAL.md

+1
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
917917
* Fix issue causing duplicate entries when filtering is enabled and users disconnect/reconnect. (PR #557)
918918
* Default to the audio from the current TX mode if no modes decode (works around Codec2 bug with 1600 mode). (PR #544)
919919
* Fix bug preventing proper restore of selected tabs. (PR #548)
920+
* Properly handle frequency entry based on user's current location. (PR #561)
920921
* Improve labeling of PTT/CAT control options. (PR #550)
921922
* Clarify behavior of "On Top" menu option. (PR #549)
922923
* Work around Xcode issue preventing FreeDV from starting on macOS < 12. (PR #553)

src/config/ReportingConfiguration.cpp

+53-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020
//==========================================================================
2121

22+
#include <wx/tokenzr.h>
2223
#include <inttypes.h>
2324

2425
#include "../defines.h"
@@ -68,7 +69,58 @@ ReportingConfiguration::ReportingConfiguration()
6869
, freedvReporterRxRowBackgroundColor("/Reporting/FreeDV/RxRowBackgroundColor", "#379baf")
6970
, freedvReporterRxRowForegroundColor("/Reporting/FreeDV/RxRowForegroundColor", "#000000")
7071
{
71-
// empty
72+
// Special handling for the frequency list to properly handle locales
73+
reportingFrequencyList.setLoadProcessor([](std::vector<wxString> list) {
74+
std::vector<wxString> newList;
75+
for (auto& val : list)
76+
{
77+
// Frequencies are unfortunately saved in US format (legacy behavior). We need
78+
// to manually parse and convert to Hz, then output MHz values in the user's current
79+
// locale.
80+
wxStringTokenizer tok(val, ".");
81+
wxString wholeNumber = tok.GetNextToken();
82+
wxString fraction = "0";
83+
if (tok.HasMoreTokens())
84+
{
85+
fraction = tok.GetNextToken();
86+
}
87+
88+
if (fraction.Length() < 6)
89+
{
90+
fraction += wxString('0', 6 - fraction.Length());
91+
}
92+
93+
long hz = 0;
94+
long mhz = 0;
95+
wholeNumber.ToLong(&mhz);
96+
fraction.ToLong(&hz);
97+
uint64_t freq = mhz * 1000000 + hz;
98+
99+
float mhzFloat = freq / 1000000.0;
100+
newList.push_back(wxString::Format("%.04f", mhzFloat));
101+
}
102+
103+
return newList;
104+
});
105+
106+
reportingFrequencyList.setSaveProcessor([](std::vector<wxString> list) {
107+
std::vector<wxString> newList;
108+
for (auto& val : list)
109+
{
110+
// Frequencies are unfortunately saved in US format (legacy behavior). We need
111+
// to manually parse and convert to Hz, then output MHz values in US format.
112+
double mhz = 0.0;
113+
val.ToDouble(&mhz);
114+
115+
uint64_t hz = mhz * 1000000;
116+
uint64_t mhzInt = hz / 1000000;
117+
hz = hz % 1000000;
118+
119+
wxString newVal = wxString::Format("%" PRIu64 ".%06" PRIu64, mhzInt, hz);
120+
newList.push_back(newVal);
121+
}
122+
return newList;
123+
});
72124
}
73125

74126
void ReportingConfiguration::load(wxConfigBase* config)

src/dlg_options.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -903,11 +903,12 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent)
903903
wxGetApp().appConfiguration.reportingConfiguration.freedvReporterTxRowForegroundColor = txForegroundColor.GetAsString(wxC2S_HTML_SYNTAX);
904904

905905
// Save new reporting frequency list.
906-
wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyList->clear();
906+
std::vector<wxString> tmpList;
907907
for (unsigned int index = 0; index < m_freqList->GetCount(); index++)
908908
{
909-
wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyList->push_back(m_freqList->GetString(index));
909+
tmpList.push_back(m_freqList->GetString(index));
910910
}
911+
wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyList = tmpList;
911912

912913
wxGetApp().appConfiguration.enableSpaceBarForPTT = m_ckboxEnableSpacebarForPTT->GetValue();
913914

0 commit comments

Comments
 (0)