fix(cpn): Preserve sort order and selected labels (#3580)

* fix(cpn): read/write models Sort Order (based on work by dlktdr)

* fix(cpn): read and write labels and selected
This commit is contained in:
Neil Horne
2023-05-23 13:41:41 +10:00
committed by GitHub
parent 48e5d141aa
commit ad5d8e190e
6 changed files with 96 additions and 34 deletions
+11 -4
View File
@@ -140,7 +140,8 @@ bool LabelsStorageFormat::loadBin(RadioData & radioData)
// Add a Favorites label
if(getCurrentFirmware()->getCapability(HasModelLabels)) {
radioData.labels.append(tr("Favorites"));
RadioData::LabelData ld = { tr("Favorites"), false };
radioData.labels.append(ld);
}
return true;
}
@@ -218,9 +219,10 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData)
// - Update possible labels with all found in models too
QByteArray labelslistBuffer;
int sortOrder = 0;
if (loadFile(labelslistBuffer, "MODELS/labels.yml")) {
try {
if (!loadLabelsListFromYaml(radioData.labels, modelFiles, labelslistBuffer)) {
if (!loadLabelsListFromYaml(radioData.labels, sortOrder, modelFiles, labelslistBuffer)) {
setError(tr("Can't load MODELS/labels.yml"));
}
} catch(const std::runtime_error& e) {
@@ -228,6 +230,9 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData)
}
}
// Save Sort Order
radioData.sortOrder = sortOrder;
// Scan for all models
std::list<std::string> filelist;
if (!getFileList(filelist)) {
@@ -308,8 +313,10 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData)
radioData.addLabelsFromModels();
// If no labels, add a Favorites
if(!radioData.labels.size())
radioData.labels.append(tr("Favorites"));
if(!radioData.labels.size()) {
RadioData::LabelData ld = { tr("Favorites"), false };
radioData.labels.append(ld);
}
}
return true;