From d8a06158b17d3849deb14bdbdcf6341cb695afbe Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Sun, 9 Sep 2018 08:15:08 -0400 Subject: [PATCH] [Companion][AppPreferencesDialog] Refactor firmwareOptionChanged(), getFirmwareVariant(), & populateFirmwareOptions() for clarity/efficiency; Remove AVR-only "voice" option handling and related items; Add getBaseFirmware(). --- companion/src/apppreferencesdialog.cpp | 180 +++--- companion/src/apppreferencesdialog.h | 32 +- companion/src/apppreferencesdialog.ui | 738 ++++++++++++------------- 3 files changed, 427 insertions(+), 523 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index 22b2523ad..b4f218d71 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -31,15 +31,15 @@ AppPreferencesDialog::AppPreferencesDialog(QWidget * parent) : QDialog(parent), + ui(new Ui::AppPreferencesDialog), updateLock(false), - mainWinHasDirtyChild(false), - ui(new Ui::AppPreferencesDialog) + mainWinHasDirtyChild(false) { ui->setupUi(this); setWindowIcon(CompanionIcon("apppreferences.png")); initSettings(); - connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged())); + connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(onBaseFirmwareChanged())); connect(ui->opt_appDebugLog, &QCheckBox::toggled, this, &AppPreferencesDialog::toggleAppLogSettings); connect(ui->opt_fwTraceLog, &QCheckBox::toggled, this, &AppPreferencesDialog::toggleAppLogSettings); @@ -111,7 +111,7 @@ void AppPreferencesDialog::accept() profile.name(ui->profileNameLE->text()); bool fwchange = false; - Firmware * newFw = getFirmwareVariant(); + Firmware * newFw = getFirmwareVariant(); // always !null // If a new fw type has been choosen, several things need to reset if (Firmware::getCurrentVariant()->getId() != newFw->getId()) { // check if we're going to be converting to a new radio type and there are unsaved files in the main window @@ -288,7 +288,7 @@ void AppPreferencesDialog::initSettings() } } - baseFirmwareChanged(); + onBaseFirmwareChanged(); } void AppPreferencesDialog::on_libraryPathButton_clicked() @@ -435,81 +435,47 @@ void AppPreferencesDialog::on_clearImageButton_clicked() ui->SplashFileName->clear(); } - -void AppPreferencesDialog::showVoice(bool show) +void AppPreferencesDialog::onBaseFirmwareChanged() { - ui->voiceLabel->setVisible(show); - ui->voiceCombo->setVisible(show); + populateFirmwareOptions(getBaseFirmware()); } -void AppPreferencesDialog::baseFirmwareChanged() +Firmware *AppPreferencesDialog::getBaseFirmware() const { - QString selected_firmware = ui->downloadVerCB->currentData().toString(); - - foreach(Firmware * firmware, Firmware::getRegisteredFirmwares()) { - if (firmware->getId() == selected_firmware) { - populateFirmwareOptions(firmware); - break; - } - } + return Firmware::getFirmwareForId(ui->downloadVerCB->currentData().toString()); } -Firmware * AppPreferencesDialog::getFirmwareVariant() +Firmware * AppPreferencesDialog::getFirmwareVariant() const { - QString selected_firmware = ui->downloadVerCB->currentData().toString(); + QString id = ui->downloadVerCB->currentData().toString(); - foreach(Firmware * firmware, Firmware::getRegisteredFirmwares()) { - QString id = firmware->getId(); - if (id == selected_firmware) { - foreach(QCheckBox *cb, optionsCheckBoxes) { - if (cb->isChecked()) { - id += "-" + cb->text(); - } - } - - if (voice && voice->isChecked()) { - id += "-tts" + ui->voiceCombo->currentText(); - } - - if (ui->langCombo->count()) { - id += "-" + ui->langCombo->currentText(); - } - - return Firmware::getFirmwareForId(id); - } + foreach(QCheckBox *cb, optionsCheckBoxes.values()) { + if (cb->isChecked()) + id += "-" + cb->text(); } - // Should never occur... - return Firmware::getDefaultVariant(); + if (ui->langCombo->count()) + id += "-" + ui->langCombo->currentText(); + + return Firmware::getFirmwareForId(id); } -void AppPreferencesDialog::firmwareOptionChanged(bool state) +void AppPreferencesDialog::onFirmwareOptionChanged(bool state) { QCheckBox *cb = qobject_cast(sender()); - if (cb == voice) { - showVoice(voice->isChecked()); - } - Firmware * firmware=NULL; - if (cb && state) { - QVariant selected_firmware = ui->downloadVerCB->currentData(); - foreach(firmware, Firmware::getRegisteredFirmwares()) { - if (firmware->getId() == selected_firmware) { - foreach(QList