diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 21e4c29a6..0d6928b85 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -113,6 +113,7 @@ add_subdirectory(thirdparty/qxtcommandoptions) set(common_SRCS eeprominterface.cpp + radiodata.cpp firmwares/er9x/er9xeeprom.cpp firmwares/er9x/er9xinterface.cpp firmwares/ersky9x/ersky9xeeprom.cpp diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 81f291355..657318ca0 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -611,48 +611,38 @@ void MainWindow::openRecentFile() } } -void MainWindow::loadProfile() //TODO Load all variables - Also HW! +void MainWindow::loadProfile() // TODO Load all variables - Also HW! { - QAction *action = qobject_cast(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()); - - foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { - MdiChild *mdiChild = qobject_cast(window->widget()); - mdiChild->eepromInterfaceChanged(); - } - - updateMenus(); - } + QAction * action = qobject_cast(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(); + } } void MainWindow::appPrefs() { - AppPreferencesDialog *pd = new AppPreferencesDialog(this); - pd->exec(); - updateMenus(); + AppPreferencesDialog * dialog = new AppPreferencesDialog(this); + dialog->exec(); + updateMenus(); } void MainWindow::fwPrefs() { - FirmwarePreferencesDialog *pd = new FirmwarePreferencesDialog(this); - pd->exec(); - foreach (QMdiSubWindow *window, mdiArea->subWindowList()) { - MdiChild *mdiChild = qobject_cast(window->widget()); - mdiChild->eepromInterfaceChanged(); - } - updateMenus(); + FirmwarePreferencesDialog * dialog = new FirmwarePreferencesDialog(this); + dialog->exec(); + emit FirmwareChanged(); + updateMenus(); } void MainWindow::contributors() { - ContributorsDialog * dialog = new ContributorsDialog(this); - dialog->exec(); + ContributorsDialog * dialog = new ContributorsDialog(this); + dialog->exec(); } void MainWindow::sdsync() @@ -785,16 +775,6 @@ bool MainWindow::readFirmwareFromRadio(const QString &filename) return result; } -bool MainWindow::writeFirmwareToRadio(const QString &filename) -{ - ProgressDialog progressDialog(this, tr("Write Firmware to Radio"), CompanionIcon("write_flash.png")); - bool result = writeFirmware(filename, progressDialog.progress()); - if (!result) { - progressDialog.exec(); - } - return result; -} - bool MainWindow::readEepromFromRadio(const QString &filename) { ProgressDialog progressDialog(this, tr("Read Models and Settings from Radio"), CompanionIcon("read_eeprom.png")); @@ -805,16 +785,6 @@ bool MainWindow::readEepromFromRadio(const QString &filename) return result; } -bool MainWindow::writeEepromToRadio(const QString &filename) -{ - ProgressDialog progressDialog(this, tr("Write Models and Settings to Radio"), CompanionIcon("write_eeprom.png")); - bool result = ::writeEeprom(filename, progressDialog.progress()); - if (!result) { - progressDialog.exec(); - } - return result; -} - void MainWindow::writeBackup() { FlashEEpromDialog *cd = new FlashEEpromDialog(this); @@ -823,8 +793,8 @@ void MainWindow::writeBackup() void MainWindow::writeFlash(QString fileToFlash) { - FlashFirmwareDialog *cd = new FlashFirmwareDialog(this); - cd->exec(); + FlashFirmwareDialog * cd = new FlashFirmwareDialog(this); + cd->exec(); } void MainWindow::readBackup() @@ -929,9 +899,9 @@ void MainWindow::updateMenus() setWindowTitle(tr("OpenTX Companion %1 - Radio: %2 - Profile: %3").arg(VERSION).arg(GetCurrentFirmware()->getName()).arg(g.profile[g.id()].name())); } -MdiChild *MainWindow::createMdiChild() +MdiChild * MainWindow::createMdiChild() { - MdiChild * child = new MdiChild(); + MdiChild * child = new MdiChild(this); mdiArea->addSubWindow(child); if (!child->parentWidget()->isMaximized() && !child->parentWidget()->isMinimized()) { child->parentWidget()->resize(400, 400); diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index 79b6dcab0..4aa012510 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -52,6 +52,9 @@ class MainWindow : public QMainWindow public: MainWindow(); + + signals: + void FirmwareChanged(); protected: QString getCompanionUpdateBaseUrl(); @@ -73,13 +76,9 @@ class MainWindow : public QMainWindow void setFILanguage() { setLanguage("fi_FI"); }; void setFRLanguage() { setLanguage("fr_FR"); }; void setITLanguage() { setLanguage("it_IT"); }; - void setHELanguage() { setLanguage("he_IL"); }; void setPLLanguage() { setLanguage("pl_PL"); }; void setESLanguage() { setLanguage("es_ES"); }; - void setPTLanguage() { setLanguage("pt_PT"); }; - void setRULanguage() { setLanguage("ru_RU"); }; void setSELanguage() { setLanguage("sv_SE"); }; - void setNLLanguage() { setLanguage("nl_NL"); }; void setCNLanguage() { setLanguage("zh_CN"); }; void setTheme(int index); @@ -139,7 +138,7 @@ class MainWindow : public QMainWindow void fwPrefs(); void updateMenus(); void createProfile(); - MdiChild *createMdiChild(); + MdiChild * createMdiChild(); void setActiveSubWindow(QWidget *window); QMenu * createRecentFileMenu(); QMenu * createProfilesMenu(); @@ -164,18 +163,13 @@ class MainWindow : public QMainWindow void updateLanguageActions(); void updateIconThemeActions(); - QString Theme; - QString ISize; QString strippedName(const QString & fullFileName); - MdiChild *activeMdiChild(); - QMdiSubWindow *findMdiChild(const QString & fileName); - int getEpromVersion(QString fileName); + MdiChild * activeMdiChild(); + QMdiSubWindow * findMdiChild(const QString & fileName); bool readEepromFromRadio(const QString & filename); - bool writeEepromToRadio(const QString & filename); bool readFirmwareFromRadio(const QString & filename); - bool writeFirmwareToRadio(const QString & filename); QMdiArea *mdiArea; QSignalMapper *windowMapper; @@ -198,7 +192,6 @@ class MainWindow : public QMainWindow QToolBar *helpToolBar; QAction *newAct; QAction *openAct; - QAction *recentAct; QAction *saveAct; QAction *saveAsAct; QAction *exitAct; @@ -249,13 +242,9 @@ class MainWindow : public QMainWindow QAction *finnishLangAct; QAction *frenchLangAct; QAction *italianLangAct; - // QAction *hebrewLangAct; QAction *polishLangAct; - // QAction *portugueseLangAct; QAction *spanishLangAct; QAction *swedishLangAct; - // QAction *russianLangAct; - // QAction *dutchLangAct; QAction *chineseLangAct; QAction *openDocURLAct; diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 2a820a732..205c82c46 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -39,15 +39,13 @@ #include #endif -MdiChild::MdiChild(): +MdiChild::MdiChild(MainWindow * parent): QWidget(), ui(new Ui::MdiChild), firmware(GetCurrentFirmware()), isUntitled(true), fileChanged(false) { - BoardEnum board = GetCurrentFirmware()->getBoard(); - ui->setupUi(this); setWindowIcon(CompanionIcon("open.png")); @@ -56,7 +54,9 @@ MdiChild::MdiChild(): ui->simulateButton->setIcon(CompanionIcon("simulate.png")); setAttribute(Qt::WA_DeleteOnClose); - eepromInterfaceChanged(); + onFirmwareChanged(); + + connect(parent, SIGNAL(FirmwareChanged()), this, SLOT(onFirmwareChanged())); connect(ui->modelsList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openModelEditWindow())); connect(ui->modelsList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showModelsListContextMenu(const QPoint &))); @@ -70,14 +70,6 @@ MdiChild::MdiChild(): // ui->modelsList->setDragDropOverwriteMode(true); // ui->modelsList->setDropIndicatorShown(true); - if (IS_HORUS(board)) { - ui->modelsList->header()->hide(); - } - else { - ui->modelsList->setIndentation(0); - } - - if (!(isMaximized() || isMinimized())) { adjustSize(); } @@ -94,7 +86,7 @@ void MdiChild::refresh(bool expand) if (1 || expand) { ui->modelsList->expandAll(); } - ui->simulateButton->setEnabled(GetCurrentFirmware()->getCapability(Simulation)); + ui->simulateButton->setEnabled(firmware->getCapability(Simulation)); updateTitle(); } @@ -147,7 +139,7 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos) contextMenu.addSeparator(); contextMenu.addAction(CompanionIcon("simulate.png"), tr("&Simulate model"), this, SLOT(modelSimulate()), tr("Alt+S")); } - else if (IS_HORUS(GetCurrentFirmware()->getBoard())) { + else if (IS_HORUS(firmware->getBoard())) { if (modelsListModel->getCategoryIndex(modelIndex) >= 0) { contextMenu.addAction(CompanionIcon("add.png"), tr("&Add model"), this, SLOT(modelAdd())); } @@ -162,8 +154,19 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos) contextMenu.exec(globalPos); } -void MdiChild::eepromInterfaceChanged() +void MdiChild::onFirmwareChanged() { + Firmware * previous = firmware; + firmware = GetCurrentFirmware(); + qDebug() << "onFirmwareChanged" << previous->getName() << "=>" << firmware->getName(); + + BoardEnum board = firmware->getBoard(); + ui->modelsList->header()->setVisible(!IS_HORUS(board)); + if (IS_HORUS(board)) + ui->modelsList->resetIndentation(); + else + ui->modelsList->setIndentation(0); + radioData.convert(previous, firmware); refresh(); } @@ -223,7 +226,7 @@ void MdiChild::doPaste(QByteArray * gmData, int index) size += sizeof(GeneralSettings); } else if (c == 'M') { - if (GetCurrentFirmware()->getCapability(Models) == 0 || index < GetCurrentFirmware()->getCapability(Models)) { + if (firmware->getCapability(Models) == 0 || index < firmware->getCapability(Models)) { // Model data int ret = QMessageBox::Yes; if (!radioData.models[index].isEmpty()) { @@ -274,7 +277,7 @@ bool MdiChild::hasSelection() const void MdiChild::updateTitle() { - QString title = userFriendlyCurrentFile() + "[*]" + " (" + GetCurrentFirmware()->getName() + QString(")"); + QString title = userFriendlyCurrentFile() + "[*]" + " (" + firmware->getName() + QString(")"); int availableEEpromSize = modelsListModel->getAvailableEEpromSize(); if (availableEEpromSize >= 0) { title += QString(" - %1 ").arg(availableEEpromSize) + tr("free bytes"); @@ -327,7 +330,7 @@ void MdiChild::checkAndInitModel(int row) void MdiChild::generalEdit() { - GeneralEdit * t = new GeneralEdit(this, radioData, GetCurrentFirmware()/*firmware*/); + GeneralEdit * t = new GeneralEdit(this, radioData, firmware); connect(t, SIGNAL(modified()), this, SLOT(setModified())); t->show(); } @@ -364,7 +367,7 @@ void MdiChild::modelEdit() ModelData & model = radioData.models[row]; gStopwatch.restart(); gStopwatch.report("ModelEdit creation"); - ModelEdit * t = new ModelEdit(this, radioData, (row), GetCurrentFirmware()/*firmware*/); + ModelEdit * t = new ModelEdit(this, radioData, (row), firmware); gStopwatch.report("ModelEdit created"); t->setWindowTitle(tr("Editing model %1: ").arg(row+1) + model.name); connect(t, SIGNAL(modified()), this, SLOT(setModified())); @@ -581,10 +584,10 @@ void MdiChild::print(int model, const QString & filename) PrintDialog * pd = NULL; if (model>=0 && !filename.isEmpty()) { - pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, radioData.generalSettings, radioData.models[model], filename); + pd = new PrintDialog(this, firmware, radioData.generalSettings, radioData.models[model], filename); } else if (getCurrentRow()) { - pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, radioData.generalSettings, radioData.models[getCurrentRow()]); + pd = new PrintDialog(this, firmware, radioData.generalSettings, radioData.models[getCurrentRow()]); } if (pd) { diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 634290a1d..45510f557 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -25,18 +25,20 @@ #include "modelslist.h" #include +class MainWindow; + namespace Ui { class MdiChild; } class MdiChild : public QWidget { - friend class ModelsListWidget; + // friend class ModelsListWidget; Q_OBJECT public: - MdiChild(); + MdiChild(MainWindow * parent); ~MdiChild(); void newFile(); @@ -49,7 +51,6 @@ class MdiChild : public QWidget QString userFriendlyCurrentFile() const; QString currentFile() const { return curFile; } void viableModelSelected(bool viable); - void eepromInterfaceChanged(); int getCurrentRow() const; void refresh(bool expand=false); void keyPressEvent(QKeyEvent * event); @@ -65,6 +66,7 @@ class MdiChild : public QWidget void on_simulateButton_clicked(); void on_radioSettings_clicked(); void setDefault(); + void onFirmwareChanged(); public slots: void showModelsListContextMenu(const QPoint & pos); diff --git a/companion/src/radiodata.cpp b/companion/src/radiodata.cpp new file mode 100644 index 000000000..64aed81ef --- /dev/null +++ b/companion/src/radiodata.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "radiodata.h" +#include "eeprominterface.h" + +// TODO here we will move a lot of functions from eeprominterface.cpp when no merge risk + +void ModelData::convert(Firmware * before, Firmware * after) +{ + // Here we can add explicit conversions when moving from one board to another +} + +void GeneralSettings::convert(Firmware * before, Firmware * after) +{ + // Here we can add explicit conversions when moving from one board to another +} + +void RadioData::convert(Firmware * before, Firmware * after) +{ + generalSettings.convert(before, after); + for (unsigned i=0; i #include +class Firmware; + enum Switches { SWITCH_NONE, @@ -1004,7 +1006,9 @@ class ModelData { ModelData(); ModelData(const ModelData & src); ModelData & operator = (const ModelData & src); - + + void convert(Firmware * before, Firmware * after); + ExpoData * insertInput(const int idx); void removeInput(const int idx); @@ -1144,6 +1148,7 @@ class GeneralSettings { }; GeneralSettings(); + void convert(Firmware * before, Firmware * after); int getDefaultStick(unsigned int channel) const; RawSource getDefaultSource(unsigned int channel) const; @@ -1269,6 +1274,8 @@ class RadioData { GeneralSettings generalSettings; std::vector categories; std::vector models; + + void convert(Firmware * before, Firmware * after); void setCurrentModel(unsigned int index) {