[Companion] Radio profile/current firmware handling: (#4737)
* Fix possible confusion/data corruption when deleting radio profile (closes #4734, ref: #4686); * Add Delete Profile action to Radio Profiles menu (closes #4736) (but remove from from app prefs. panel); * Add confirmation prompt before deleting profile; * Open profile settings dialog when creating/copying a profile (closes #4735); * Make sure current (global) firmware flavor is properly updated when changing fw type/options in profile; * Append "-Copy" to name of copied profile; * Factor out Firmware global vars/functions in favor of static members.
This commit is contained in:
committed by
Bertrand Songis
parent
8d0db05e78
commit
36bb951314
@@ -100,12 +100,13 @@ void AppPreferencesDialog::writeValues()
|
||||
g.profile[g.id()].name(ui->profileNameLE->text());
|
||||
|
||||
// If a new fw type has been choosen, several things need to reset
|
||||
current_firmware_variant = getFirmwareVariant();
|
||||
QString id = current_firmware_variant->getId();
|
||||
Firmware::setCurrentVariant(getFirmwareVariant());
|
||||
QString id = Firmware::getCurrentVariant()->getId();
|
||||
if (g.profile[g.id()].fwType() != id) {
|
||||
g.profile[g.id()].fwName("");
|
||||
g.profile[g.id()].initFwVariables();
|
||||
g.profile[g.id()].fwType(id);
|
||||
emit firmwareProfileChanged(g.id());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,10 +228,10 @@ void AppPreferencesDialog::initSettings()
|
||||
}
|
||||
ui->lblGeneralSettings->setText(hwSettings);
|
||||
|
||||
Firmware * current_firmware = getCurrentFirmware();
|
||||
foreach(Firmware * firmware, firmwares) {
|
||||
QString currType = QStringList(g.profile[g.id()].fwType().split('-').mid(0, 2)).join('-');
|
||||
foreach(Firmware * firmware, Firmware::getRegisteredFirmwares()) {
|
||||
ui->downloadVerCB->addItem(firmware->getName(), firmware->getId());
|
||||
if (current_firmware->getFirmwareBase() == firmware) {
|
||||
if (currType == firmware->getId()) {
|
||||
ui->downloadVerCB->setCurrentIndex(ui->downloadVerCB->count() - 1);
|
||||
}
|
||||
}
|
||||
@@ -332,18 +333,6 @@ void AppPreferencesDialog::on_sdPathButton_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void AppPreferencesDialog::on_removeProfileButton_clicked()
|
||||
{
|
||||
if ( g.id() == 0 ) {
|
||||
QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed."));
|
||||
}
|
||||
else {
|
||||
g.profile[g.id()].remove();
|
||||
g.id( 0 );
|
||||
initSettings();
|
||||
}
|
||||
}
|
||||
|
||||
bool AppPreferencesDialog::displayImage(const QString & fileName)
|
||||
{
|
||||
// Start by clearing the label
|
||||
@@ -395,9 +384,9 @@ void AppPreferencesDialog::showVoice(bool show)
|
||||
|
||||
void AppPreferencesDialog::baseFirmwareChanged()
|
||||
{
|
||||
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
||||
QString selected_firmware = ui->downloadVerCB->currentData().toString();
|
||||
|
||||
foreach(Firmware * firmware, firmwares) {
|
||||
foreach(Firmware * firmware, Firmware::getRegisteredFirmwares()) {
|
||||
if (firmware->getId() == selected_firmware) {
|
||||
populateFirmwareOptions(firmware);
|
||||
break;
|
||||
@@ -407,31 +396,31 @@ void AppPreferencesDialog::baseFirmwareChanged()
|
||||
|
||||
Firmware * AppPreferencesDialog::getFirmwareVariant()
|
||||
{
|
||||
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
||||
QString selected_firmware = ui->downloadVerCB->currentData().toString();
|
||||
|
||||
foreach(Firmware * firmware, firmwares) {
|
||||
foreach(Firmware * firmware, Firmware::getRegisteredFirmwares()) {
|
||||
QString id = firmware->getId();
|
||||
if (id == selected_firmware) {
|
||||
foreach(QCheckBox *cb, optionsCheckBoxes) {
|
||||
if (cb->isChecked()) {
|
||||
id += QString("-") + cb->text();
|
||||
id += "-" + cb->text();
|
||||
}
|
||||
}
|
||||
|
||||
if (voice && voice->isChecked()) {
|
||||
id += QString("-tts") + ui->voiceCombo->currentText();
|
||||
id += "-tts" + ui->voiceCombo->currentText();
|
||||
}
|
||||
|
||||
if (ui->langCombo->count()) {
|
||||
id += QString("-") + ui->langCombo->currentText();
|
||||
id += "-" + ui->langCombo->currentText();
|
||||
}
|
||||
|
||||
return getFirmware(id);
|
||||
return Firmware::getFirmwareForId(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Should never occur...
|
||||
return default_firmware_variant;
|
||||
return Firmware::getDefaultVariant();
|
||||
}
|
||||
|
||||
void AppPreferencesDialog::firmwareOptionChanged(bool state)
|
||||
@@ -442,8 +431,8 @@ void AppPreferencesDialog::firmwareOptionChanged(bool state)
|
||||
}
|
||||
Firmware * firmware=NULL;
|
||||
if (cb && state) {
|
||||
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
||||
foreach(firmware, firmwares) {
|
||||
QVariant selected_firmware = ui->downloadVerCB->currentData();
|
||||
foreach(firmware, Firmware::getRegisteredFirmwares()) {
|
||||
if (firmware->getId() == selected_firmware) {
|
||||
foreach(QList<Option> opts, firmware->opts) {
|
||||
foreach(Option opt, opts) {
|
||||
@@ -472,7 +461,7 @@ void AppPreferencesDialog::populateFirmwareOptions(const Firmware * firmware)
|
||||
|
||||
updateLock = true;
|
||||
|
||||
QString id = current_firmware_variant->getId();
|
||||
QString id = Firmware::getCurrentVariant()->getId();
|
||||
ui->langCombo->clear();
|
||||
foreach(const char *lang, parent->languages) {
|
||||
ui->langCombo->addItem(lang);
|
||||
|
||||
@@ -40,6 +40,9 @@ class AppPreferencesDialog : public QDialog
|
||||
~AppPreferencesDialog();
|
||||
Joystick * joystick;
|
||||
|
||||
signals:
|
||||
void firmwareProfileChanged(int profId);
|
||||
|
||||
private:
|
||||
QList<QCheckBox *> optionsCheckBoxes;
|
||||
bool updateLock;
|
||||
@@ -69,7 +72,6 @@ class AppPreferencesDialog : public QDialog
|
||||
void on_ge_pathButton_clicked();
|
||||
|
||||
void on_sdPathButton_clicked();
|
||||
void on_removeProfileButton_clicked();
|
||||
void on_SplashSelect_clicked();
|
||||
void on_clearImageButton_clicked();
|
||||
|
||||
|
||||
@@ -46,13 +46,6 @@
|
||||
<string>Radio Profile</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0,0">
|
||||
<item row="0" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="removeProfileButton">
|
||||
<property name="text">
|
||||
<string>Remove Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="sdPathButton">
|
||||
<property name="text">
|
||||
@@ -1128,7 +1121,6 @@ Mode 4:
|
||||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>profileNameLE</tabstop>
|
||||
<tabstop>removeProfileButton</tabstop>
|
||||
<tabstop>downloadVerCB</tabstop>
|
||||
<tabstop>langCombo</tabstop>
|
||||
<tabstop>voiceCombo</tabstop>
|
||||
|
||||
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
|
||||
SimulatorLoader::registerSimulators();
|
||||
|
||||
if (g.profile[g.id()].fwType().isEmpty()){
|
||||
g.profile[g.id()].fwType(default_firmware_variant->getId());
|
||||
g.profile[g.id()].fwType(Firmware::getDefaultVariant()->getId());
|
||||
g.profile[g.id()].fwName("");
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
|
||||
QPixmap pixmap = QPixmap(splashScreen);
|
||||
QSplashScreen *splash = new QSplashScreen(pixmap);
|
||||
|
||||
current_firmware_variant = getFirmware(g.profile[g.id()].fwType());
|
||||
Firmware::setCurrentVariant(Firmware::getFirmwareForId(g.profile[g.id()].fwType()));
|
||||
|
||||
MainWindow *mainWin = new MainWindow();
|
||||
if (g.showSplash()) {
|
||||
|
||||
@@ -239,7 +239,7 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
|
||||
{
|
||||
RawSourceRange result;
|
||||
|
||||
Firmware * firmware = getCurrentFirmware();
|
||||
Firmware * firmware = Firmware::getCurrentVariant();
|
||||
int board = firmware->getBoard();
|
||||
bool singleprec = (flags & RANGE_SINGLE_PRECISION);
|
||||
|
||||
@@ -912,7 +912,7 @@ QString CustomFunctionData::funcToString() const
|
||||
void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox * b, unsigned int value = 0)
|
||||
{
|
||||
int val = 0;
|
||||
Firmware * firmware = getCurrentFirmware();
|
||||
Firmware * firmware = Firmware::getCurrentVariant();
|
||||
Board::Type board = firmware->getBoard();
|
||||
|
||||
b->addItem(QObject::tr("Timer1"), val++);
|
||||
@@ -1138,7 +1138,7 @@ GeneralSettings::GeneralSettings()
|
||||
calibSpanPos[i] = 0x180;
|
||||
}
|
||||
|
||||
Firmware * firmware = getCurrentFirmware();
|
||||
Firmware * firmware = Firmware::getCurrentVariant();
|
||||
Board::Type board = firmware->getBoard();
|
||||
|
||||
for (int i=0; i<getBoardCapability(board, Board::FactoryInstalledSwitches); i++) {
|
||||
@@ -1735,10 +1735,6 @@ void unregisterEEpromInterfaces()
|
||||
OpenTxEepromCleanup();
|
||||
}
|
||||
|
||||
QList<Firmware *> firmwares;
|
||||
Firmware * default_firmware_variant;
|
||||
Firmware * current_firmware_variant;
|
||||
|
||||
void ShowEepromErrors(QWidget *parent, const QString &title, const QString &mainMessage, unsigned long errorsFound)
|
||||
{
|
||||
std::bitset<NUM_ERRORS> errors((unsigned long long)errorsFound);
|
||||
@@ -1790,16 +1786,22 @@ void ShowEepromWarnings(QWidget *parent, const QString &title, unsigned long err
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
Firmware * getFirmware(const QString & id)
|
||||
// static
|
||||
QVector<Firmware *> Firmware::registeredFirmwares;
|
||||
Firmware * Firmware::defaultVariant = NULL;
|
||||
Firmware * Firmware::currentVariant = NULL;
|
||||
|
||||
// static
|
||||
Firmware * Firmware::getFirmwareForId(const QString & id)
|
||||
{
|
||||
foreach(Firmware * firmware, firmwares) {
|
||||
foreach(Firmware * firmware, registeredFirmwares) {
|
||||
Firmware * result = firmware->getFirmwareVariant(id);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return default_firmware_variant;
|
||||
return defaultVariant;
|
||||
}
|
||||
|
||||
void Firmware::addOption(const char *option, QString tooltip, uint32_t variant)
|
||||
|
||||
@@ -325,11 +325,41 @@ class Firmware {
|
||||
|
||||
const int getFlashSize();
|
||||
|
||||
static Firmware * getFirmwareForId(const QString & id);
|
||||
|
||||
static QVector<Firmware *> getRegisteredFirmwares()
|
||||
{
|
||||
return registeredFirmwares;
|
||||
}
|
||||
static void addRegisteredFirmware(Firmware * fw)
|
||||
{
|
||||
registeredFirmwares.append(fw);
|
||||
}
|
||||
|
||||
static Firmware * getDefaultVariant()
|
||||
{
|
||||
return defaultVariant;
|
||||
}
|
||||
static void setDefaultVariant(Firmware * value)
|
||||
{
|
||||
defaultVariant = value;
|
||||
}
|
||||
|
||||
static Firmware * getCurrentVariant()
|
||||
{
|
||||
return currentVariant;
|
||||
}
|
||||
static void setCurrentVariant(Firmware * value)
|
||||
{
|
||||
currentVariant = value;
|
||||
}
|
||||
|
||||
public:
|
||||
QList<const char *> languages;
|
||||
QList<const char *> ttslanguages;
|
||||
QList< QList<Option> > opts;
|
||||
|
||||
|
||||
protected:
|
||||
QString id;
|
||||
QString name;
|
||||
@@ -338,30 +368,28 @@ class Firmware {
|
||||
Firmware * base;
|
||||
EEPROMInterface * eepromInterface;
|
||||
|
||||
static QVector<Firmware *> registeredFirmwares;
|
||||
static Firmware * defaultVariant;
|
||||
static Firmware * currentVariant;
|
||||
|
||||
private:
|
||||
Firmware();
|
||||
|
||||
};
|
||||
|
||||
extern QList<Firmware *> firmwares;
|
||||
extern Firmware * default_firmware_variant;
|
||||
extern Firmware * current_firmware_variant;
|
||||
|
||||
Firmware * getFirmware(const QString & id);
|
||||
|
||||
inline Firmware * getCurrentFirmware()
|
||||
{
|
||||
return current_firmware_variant;
|
||||
return Firmware::getCurrentVariant();
|
||||
}
|
||||
|
||||
inline EEPROMInterface * getCurrentEEpromInterface()
|
||||
{
|
||||
return getCurrentFirmware()->getEEpromInterface();
|
||||
return Firmware::getCurrentVariant()->getEEpromInterface();
|
||||
}
|
||||
|
||||
inline Board::Type getCurrentBoard()
|
||||
{
|
||||
return getCurrentFirmware()->getBoard();
|
||||
return Firmware::getCurrentVariant()->getBoard();
|
||||
}
|
||||
|
||||
inline int divRoundClosest(const int n, const int d)
|
||||
|
||||
@@ -1198,7 +1198,7 @@ void registerOpenTxFirmware(OpenTxFirmware * firmware)
|
||||
firmware->setEEpromInterface(eepromInterface);
|
||||
opentxEEpromInterfaces.push_back(eepromInterface);
|
||||
eepromInterfaces.push_back(eepromInterface);
|
||||
firmwares.push_back(firmware);
|
||||
Firmware::addRegisteredFirmware(firmware);
|
||||
}
|
||||
|
||||
void registerOpenTxFirmwares()
|
||||
@@ -1507,13 +1507,13 @@ void registerOpenTxFirmwares()
|
||||
addOpenTxCommonOptions(firmware);
|
||||
registerOpenTxFirmware(firmware);
|
||||
|
||||
default_firmware_variant = getFirmware("opentx-x9d+");
|
||||
current_firmware_variant = default_firmware_variant;
|
||||
Firmware::setDefaultVariant(Firmware::getFirmwareForId("opentx-x9d+"));
|
||||
Firmware::setCurrentVariant(Firmware::getDefaultVariant());
|
||||
}
|
||||
|
||||
void unregisterOpenTxFirmwares()
|
||||
{
|
||||
foreach (Firmware * f, firmwares) {
|
||||
foreach (Firmware * f, Firmware::getRegisteredFirmwares()) {
|
||||
delete f;
|
||||
}
|
||||
unregisterEEpromInterfaces();
|
||||
|
||||
@@ -37,7 +37,7 @@ FirmwarePreferencesDialog::FirmwarePreferencesDialog(QWidget *parent) :
|
||||
|
||||
foreach(const char *lang, getCurrentFirmware()->getFirmwareBase()->ttslanguages) {
|
||||
ui->voiceCombo->addItem(lang);
|
||||
if (current_firmware_variant->getId().contains(QString("-tts%1").arg(lang)))
|
||||
if (Firmware::getCurrentVariant()->getId().contains(QString("-tts%1").arg(lang)))
|
||||
ui->voiceCombo->setCurrentIndex(ui->voiceCombo->count() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ void MainWindow::firmwareDownloadAccepted()
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
g.fwRev.set(current_firmware_variant->getId(), version2index(firmwareVersionString));
|
||||
g.fwRev.set(Firmware::getCurrentVariant()->getId(), version2index(firmwareVersionString));
|
||||
if (g.profile[g.id()].burnFirmware()) {
|
||||
int ret = QMessageBox::question(this, "Companion", tr("Do you want to write the firmware to the radio now ?"), QMessageBox::Yes | QMessageBox::No);
|
||||
if (ret == QMessageBox::Yes) {
|
||||
@@ -406,7 +406,7 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
||||
download = true;
|
||||
}
|
||||
else {
|
||||
int currentVersion = g.fwRev.get(current_firmware_variant->getId());
|
||||
int currentVersion = g.fwRev.get(Firmware::getCurrentVariant()->getId());
|
||||
QString currentVersionString = index2version(currentVersion);
|
||||
|
||||
QMessageBox msgBox;
|
||||
@@ -418,7 +418,8 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
||||
if (currentVersion == 0) {
|
||||
QString rn = getCurrentFirmware()->getReleaseNotesUrl();
|
||||
QAbstractButton *rnButton = NULL;
|
||||
msgBox.setText(tr("Firmware %1 does not seem to have ever been downloaded.\nRelease %2 is available.\nDo you want to download it now?\n\nWe recommend you view the release notes using the button below to learn about any changes that may be important to you.").arg(current_firmware_variant->getId()).arg(fullVersionString));
|
||||
msgBox.setText(tr("Firmware %1 does not seem to have ever been downloaded.\nRelease %2 is available.\nDo you want to download it now?\n\nWe recommend you view the release notes using the button below to learn about any changes that may be important to you.")
|
||||
.arg(Firmware::getCurrentVariant()->getId()).arg(fullVersionString));
|
||||
QAbstractButton *YesButton = msgBox.addButton(trUtf8("Yes"), QMessageBox::YesRole);
|
||||
msgBox.addButton(trUtf8("No"), QMessageBox::NoRole);
|
||||
if (!rn.isEmpty()) {
|
||||
@@ -446,7 +447,8 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
||||
else if (version > currentVersion) {
|
||||
QString rn = getCurrentFirmware()->getReleaseNotesUrl();
|
||||
QAbstractButton *rnButton = NULL;
|
||||
msgBox.setText(tr("A new version of %1 firmware is available:\n - current is %2\n - newer is %3\n\nDo you want to download it now?\n\nWe recommend you view the release notes using the button below to learn about any changes that may be important to you.").arg(current_firmware_variant->getId()).arg(currentVersionString).arg(fullVersionString));
|
||||
msgBox.setText(tr("A new version of %1 firmware is available:\n - current is %2\n - newer is %3\n\nDo you want to download it now?\n\nWe recommend you view the release notes using the button below to learn about any changes that may be important to you.")
|
||||
.arg(Firmware::getCurrentVariant()->getId()).arg(currentVersionString).arg(fullVersionString));
|
||||
QAbstractButton *YesButton = msgBox.addButton(trUtf8("Yes"), QMessageBox::YesRole);
|
||||
msgBox.addButton(trUtf8("No"), QMessageBox::NoRole);
|
||||
if (!rn.isEmpty()) {
|
||||
@@ -484,7 +486,7 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
||||
if (ignore) {
|
||||
int res = QMessageBox::question(this, "Companion", tr("Ignore this release %1?").arg(fullVersionString), QMessageBox::Yes | QMessageBox::No);
|
||||
if (res==QMessageBox::Yes) {
|
||||
g.fwRev.set(current_firmware_variant->getId(), version);
|
||||
g.fwRev.set(Firmware::getCurrentVariant()->getId(), version);
|
||||
}
|
||||
}
|
||||
else if (download == true) {
|
||||
@@ -497,10 +499,10 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
|
||||
|
||||
void MainWindow::startFirmwareDownload()
|
||||
{
|
||||
QString url = current_firmware_variant->getFirmwareUrl();
|
||||
QString url = Firmware::getCurrentVariant()->getFirmwareUrl();
|
||||
qDebug() << "Downloading firmware" << url;
|
||||
QString ext = url.mid(url.lastIndexOf("."));
|
||||
QString defaultFilename = g.flashDir() + "/" + current_firmware_variant->getId();
|
||||
QString defaultFilename = g.flashDir() + "/" + Firmware::getCurrentVariant()->getId();
|
||||
if (g.profile[g.id()].renameFwFiles()) {
|
||||
defaultFilename += "-" + firmwareVersionString;
|
||||
}
|
||||
@@ -659,36 +661,49 @@ void MainWindow::openRecentFile()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadProfile() // TODO Load all variables - Also HW!
|
||||
void MainWindow::loadProfileId(const unsigned pid) // TODO Load all variables - Also HW!
|
||||
{
|
||||
if (pid >= MAX_PROFILES)
|
||||
return;
|
||||
|
||||
// Set the new profile number
|
||||
g.id(pid);
|
||||
Firmware::setCurrentVariant(Firmware::getFirmwareForId(g.profile[pid].fwType()));
|
||||
emit FirmwareChanged();
|
||||
updateMenus();
|
||||
}
|
||||
|
||||
void MainWindow::loadProfile()
|
||||
{
|
||||
QAction * action = qobject_cast<QAction *>(sender());
|
||||
if (action) {
|
||||
// Set the new profile number
|
||||
int profnum = action->data().toInt();
|
||||
g.id(profnum);
|
||||
current_firmware_variant = getFirmware(g.profile[g.id()].fwType());
|
||||
emit FirmwareChanged();
|
||||
updateMenus();
|
||||
bool ok = false;
|
||||
unsigned profnum = action->data().toUInt(&ok);
|
||||
if (ok)
|
||||
loadProfileId(profnum);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::appPrefs()
|
||||
{
|
||||
AppPreferencesDialog * dialog = new AppPreferencesDialog(this);
|
||||
connect(dialog, &AppPreferencesDialog::firmwareProfileChanged, this, &MainWindow::loadProfileId);
|
||||
dialog->exec();
|
||||
updateMenus();
|
||||
dialog->deleteLater();
|
||||
}
|
||||
|
||||
void MainWindow::fwPrefs()
|
||||
{
|
||||
FirmwarePreferencesDialog * dialog = new FirmwarePreferencesDialog(this);
|
||||
dialog->exec();
|
||||
dialog->deleteLater();
|
||||
}
|
||||
|
||||
void MainWindow::contributors()
|
||||
{
|
||||
ContributorsDialog * dialog = new ContributorsDialog(this);
|
||||
dialog->exec();
|
||||
dialog->deleteLater();
|
||||
}
|
||||
|
||||
void MainWindow::sdsync()
|
||||
@@ -715,6 +730,7 @@ void MainWindow::changelog()
|
||||
{
|
||||
ReleaseNotesDialog * dialog = new ReleaseNotesDialog(this);
|
||||
dialog->exec();
|
||||
dialog->deleteLater();
|
||||
}
|
||||
|
||||
void MainWindow::fwchangelog()
|
||||
@@ -727,6 +743,7 @@ void MainWindow::fwchangelog()
|
||||
else {
|
||||
ReleaseNotesFirmwareDialog * dialog = new ReleaseNotesFirmwareDialog(this, url);
|
||||
dialog->exec();
|
||||
dialog->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,6 +751,7 @@ void MainWindow::customizeSplash()
|
||||
{
|
||||
customizeSplashDialog * dialog = new customizeSplashDialog(this);
|
||||
dialog->exec();
|
||||
dialog->deleteLater();
|
||||
}
|
||||
|
||||
void MainWindow::cut()
|
||||
@@ -1058,8 +1076,6 @@ void MainWindow::createActions()
|
||||
burnFusesAct = addAct("fuses.png", tr("Fuses..."), tr("Show fuses dialog"), SLOT(burnFuses()));
|
||||
readFlashAct = addAct("read_flash.png", tr("Read Firmware from Radio"),tr("Read firmware from Radio"), SLOT(readFlash()));
|
||||
writeFlashAct = addAct("write_flash.png", tr("Write Firmware to Radio"), tr("Write firmware to Radio"), SLOT(writeFlash()));
|
||||
createProfileAct = addAct("", tr("Add Radio Profile"), tr("Create a new Radio Setting Profile"), SLOT(createProfile()));
|
||||
copyProfileAct = addAct("", tr("Copy Current Radio Profile"), tr("Duplicate current Radio Setting Profile"), SLOT(copyProfile()));
|
||||
openDocURLAct = addAct("", tr("Manuals and other Documents"), tr("Open the OpenTX document page in a web browser"), SLOT(openDocURL()));
|
||||
writeEepromAct = addAct("write_eeprom.png", tr("Write Models and Settings To Radio"), tr("Write Models and Settings to Radio"), SLOT(writeEeprom()));
|
||||
readEepromAct = addAct("read_eeprom.png", tr("Read Models and Settings From Radio"), tr("Read Models and Settings from Radio"), SLOT(readEeprom()));
|
||||
@@ -1069,6 +1085,10 @@ void MainWindow::createActions()
|
||||
contributorsAct = addAct("contributors.png", tr("Contributors..."), tr("A tribute to those who have contributed to OpenTX and Companion"), SLOT(contributors()));
|
||||
sdsyncAct = addAct("sdsync.png", tr("Synchronize SD"), tr("SD card synchronization"), SLOT(sdsync()));
|
||||
|
||||
createProfileAct = addAct("new.png", tr("Add Radio Profile"), tr("Create a new Radio Settings Profile"), SLOT(createProfile()));
|
||||
copyProfileAct = addAct("copy.png", tr("Copy Current Radio Profile"), tr("Duplicate current Radio Settings Profile"), SLOT(copyProfile()));
|
||||
deleteProfileAct = addAct("clear.png", tr("Delete Current Radio Profile"), tr("Delete the current Radio Settings Profile"), SLOT(deleteCurrentProfile()));
|
||||
|
||||
compareAct->setEnabled(false);
|
||||
simulateAct->setEnabled(false);
|
||||
printAct->setEnabled(false);
|
||||
@@ -1220,6 +1240,7 @@ QMenu *MainWindow::createProfilesMenu()
|
||||
|
||||
profilesMenu->addAction(createProfileAct);
|
||||
profilesMenu->addAction(copyProfileAct);
|
||||
profilesMenu->addAction(deleteProfileAct);
|
||||
profilesMenu->setIcon(CompanionIcon("profiles.png"));
|
||||
return profilesMenu;
|
||||
}
|
||||
@@ -1400,30 +1421,63 @@ void MainWindow::updateProfilesActions()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::copyProfile()
|
||||
{
|
||||
int previous = g.id();
|
||||
|
||||
createProfile();
|
||||
if (g.id() == previous) //Failed to find free slot
|
||||
return;
|
||||
g.profile[g.id()] = g.profile[previous];
|
||||
updateMenus();
|
||||
}
|
||||
|
||||
void MainWindow::createProfile()
|
||||
int MainWindow::newProfile(bool loadProfile)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<MAX_PROFILES && g.profile[i].existsOnDisk(); i++);
|
||||
if (i==MAX_PROFILES) //Failed to find free slot
|
||||
return;
|
||||
for (i=0; i < MAX_PROFILES && g.profile[i].existsOnDisk(); i++)
|
||||
;
|
||||
if (i == MAX_PROFILES) //Failed to find free slot
|
||||
return -1;
|
||||
|
||||
g.profile[i].init(i);
|
||||
g.profile[i].name(tr("New Radio"));
|
||||
|
||||
g.id(i);
|
||||
updateMenus();
|
||||
if (loadProfile) {
|
||||
g.id(i);
|
||||
loadProfileId(i);
|
||||
appPrefs();
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void MainWindow::createProfile()
|
||||
{
|
||||
newProfile(true);
|
||||
}
|
||||
|
||||
void MainWindow::copyProfile()
|
||||
{
|
||||
int newId = newProfile(false);
|
||||
|
||||
if (newId > -1) {
|
||||
g.profile[newId] = g.profile[g.id()];
|
||||
g.id(newId);
|
||||
g.profile[newId].name(g.profile[newId].name() + tr(" - Copy"));
|
||||
loadProfileId(newId);
|
||||
appPrefs();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::deleteProfile(const int pid)
|
||||
{
|
||||
if (pid == 0) {
|
||||
QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed."));
|
||||
return;
|
||||
}
|
||||
int ret = QMessageBox::question(this,
|
||||
tr("Confirm Delete Profile"),
|
||||
tr("Are you sure you wish to delete the \"%1\" radio profile? There is no way to undo this action!").arg(g.profile[pid].name()));
|
||||
if (ret != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
g.profile[pid].remove();
|
||||
loadProfileId(0);
|
||||
}
|
||||
|
||||
void MainWindow::deleteCurrentProfile()
|
||||
{
|
||||
deleteProfile(g.id());
|
||||
}
|
||||
|
||||
QString MainWindow::strippedName(const QString &fullFileName)
|
||||
|
||||
@@ -96,6 +96,7 @@ class MainWindow : public QMainWindow
|
||||
void saveAs();
|
||||
void cut();
|
||||
void openRecentFile();
|
||||
void loadProfileId(const unsigned pid);
|
||||
void loadProfile();
|
||||
void logFile();
|
||||
void copy();
|
||||
@@ -124,6 +125,8 @@ class MainWindow : public QMainWindow
|
||||
void updateMenus();
|
||||
void createProfile();
|
||||
void copyProfile();
|
||||
void deleteProfile(const int pid);
|
||||
void deleteCurrentProfile();
|
||||
void setActiveSubWindow(QWidget *window);
|
||||
void autoClose();
|
||||
|
||||
@@ -149,6 +152,7 @@ class MainWindow : public QMainWindow
|
||||
void updateRecentFileActions();
|
||||
void updateProfilesActions();
|
||||
|
||||
int newProfile(bool loadProfile = true);
|
||||
QString strippedName(const QString & fullFileName);
|
||||
|
||||
MdiChild * createMdiChild();
|
||||
@@ -215,6 +219,7 @@ class MainWindow : public QMainWindow
|
||||
QAction *profileActs[MAX_PROFILES];
|
||||
QAction *createProfileAct;
|
||||
QAction *copyProfileAct;
|
||||
QAction *deleteProfileAct;
|
||||
QAction *openDocURLAct;
|
||||
};
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ int main(int argc, char *argv[])
|
||||
return finish(2);
|
||||
}
|
||||
|
||||
current_firmware_variant = getFirmware(simOptions.firmwareId);
|
||||
Firmware::setCurrentVariant(Firmware::getFirmwareForId(simOptions.firmwareId));
|
||||
|
||||
g.sessionId(profileId);
|
||||
g.simuLastProfId(profileId);
|
||||
|
||||
Reference in New Issue
Block a user