|
19 | 19 | //
|
20 | 20 | //==========================================================================
|
21 | 21 |
|
| 22 | +#include <wx/tokenzr.h> |
22 | 23 | #include <inttypes.h>
|
23 | 24 |
|
24 | 25 | #include "../defines.h"
|
@@ -68,7 +69,58 @@ ReportingConfiguration::ReportingConfiguration()
|
68 | 69 | , freedvReporterRxRowBackgroundColor("/Reporting/FreeDV/RxRowBackgroundColor", "#379baf")
|
69 | 70 | , freedvReporterRxRowForegroundColor("/Reporting/FreeDV/RxRowForegroundColor", "#000000")
|
70 | 71 | {
|
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 | + }); |
72 | 124 | }
|
73 | 125 |
|
74 | 126 | void ReportingConfiguration::load(wxConfigBase* config)
|
|
0 commit comments