Bsongis/companion warning before automatic conversions (#4271)
* Does this work? * Warning before automatic conversions
This commit is contained in:
@@ -34,7 +34,8 @@ enum BoardEnum {
|
|||||||
BOARD_TARANIS_X9DP,
|
BOARD_TARANIS_X9DP,
|
||||||
BOARD_TARANIS_X9E,
|
BOARD_TARANIS_X9E,
|
||||||
BOARD_FLAMENCO,
|
BOARD_FLAMENCO,
|
||||||
BOARD_HORUS
|
BOARD_HORUS,
|
||||||
|
BOARD_UNKNOWN = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CPN_MAX_MODELS 60
|
#define CPN_MAX_MODELS 60
|
||||||
|
|||||||
@@ -1573,14 +1573,14 @@ void unregisterOpenTxFirmwares()
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class T, class M>
|
template <class T, class M>
|
||||||
bool loadFromByteArray(T & dest, const QByteArray & data)
|
OpenTxEepromInterface * loadFromByteArray(T & dest, const QByteArray & data)
|
||||||
{
|
{
|
||||||
foreach(OpenTxEepromInterface * eepromInterface, opentxEEpromInterfaces) {
|
foreach(OpenTxEepromInterface * eepromInterface, opentxEEpromInterfaces) {
|
||||||
if (eepromInterface->loadFromByteArray<T, M>(dest, data)) {
|
if (eepromInterface->loadFromByteArray<T, M>(dest, data)) {
|
||||||
return true;
|
return eepromInterface;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, class M>
|
template <class T, class M>
|
||||||
@@ -1595,12 +1595,12 @@ bool saveToByteArray(const T & dest, QByteArray & data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loadModelFromByteArray(ModelData & model, const QByteArray & data)
|
OpenTxEepromInterface * loadModelFromByteArray(ModelData & model, const QByteArray & data)
|
||||||
{
|
{
|
||||||
return loadFromByteArray<ModelData, OpenTxModelData>(model, data);
|
return loadFromByteArray<ModelData, OpenTxModelData>(model, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loadRadioSettingsFromByteArray(GeneralSettings & settings, const QByteArray & data)
|
OpenTxEepromInterface * loadRadioSettingsFromByteArray(GeneralSettings & settings, const QByteArray & data)
|
||||||
{
|
{
|
||||||
return loadFromByteArray<GeneralSettings, OpenTxGeneralData>(settings, data);
|
return loadFromByteArray<GeneralSettings, OpenTxGeneralData>(settings, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,8 +150,8 @@ void unregisterOpenTxFirmwares();
|
|||||||
|
|
||||||
extern QList<OpenTxEepromInterface *> opentxEEpromInterfaces;
|
extern QList<OpenTxEepromInterface *> opentxEEpromInterfaces;
|
||||||
|
|
||||||
bool loadModelFromByteArray(ModelData & model, const QByteArray & data);
|
OpenTxEepromInterface * loadModelFromByteArray(ModelData & model, const QByteArray & data);
|
||||||
bool loadRadioSettingsFromByteArray(GeneralSettings & settings, const QByteArray & data);
|
OpenTxEepromInterface * loadRadioSettingsFromByteArray(GeneralSettings & settings, const QByteArray & data);
|
||||||
|
|
||||||
bool writeModelToByteArray(const ModelData & model, QByteArray & data);
|
bool writeModelToByteArray(const ModelData & model, QByteArray & data);
|
||||||
bool writeRadioSettingsToByteArray(const GeneralSettings & settings, QByteArray & data);
|
bool writeRadioSettingsToByteArray(const GeneralSettings & settings, QByteArray & data);
|
||||||
|
|||||||
+29
-12
@@ -152,13 +152,28 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos)
|
|||||||
contextMenu.exec(globalPos);
|
contextMenu.exec(globalPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MdiChild::setCurrentFileExtension(const QString & ext)
|
||||||
|
{
|
||||||
|
QFileInfo info(curFile);
|
||||||
|
curFile = info.path() + "/" + info.baseName() + ext;
|
||||||
|
}
|
||||||
|
|
||||||
void MdiChild::onFirmwareChanged()
|
void MdiChild::onFirmwareChanged()
|
||||||
{
|
{
|
||||||
Firmware * previous = firmware;
|
Firmware * previous = firmware;
|
||||||
firmware = getCurrentFirmware();
|
firmware = getCurrentFirmware();
|
||||||
qDebug() << "onFirmwareChanged" << previous->getName() << "=>" << firmware->getName();
|
qDebug() << "onFirmwareChanged" << previous->getName() << "=>" << firmware->getName();
|
||||||
radioData.convert(previous, firmware);
|
convertStorage(previous->getBoard(), firmware->getBoard());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MdiChild::convertStorage(BoardEnum from, BoardEnum to)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, "Companion", tr("Models and settings will be automatically converted"), QMessageBox::Ok);
|
||||||
|
radioData.convert(from, to);
|
||||||
|
setCurrentFileExtension(".otx");
|
||||||
initModelsList();
|
initModelsList();
|
||||||
|
fileChanged = true;
|
||||||
|
documentWasModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MdiChild::initModelsList()
|
void MdiChild::initModelsList()
|
||||||
@@ -491,6 +506,10 @@ bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile)
|
|||||||
setCurrentFile(filename);
|
setCurrentFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (storage.getBoard() != getCurrentBoard()) {
|
||||||
|
convertStorage(storage.getBoard(), getCurrentBoard());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,21 +554,19 @@ bool MdiChild::saveAs(bool isNew)
|
|||||||
|
|
||||||
bool MdiChild::saveFile(const QString & filename, bool setCurrent)
|
bool MdiChild::saveFile(const QString & filename, bool setCurrent)
|
||||||
{
|
{
|
||||||
BoardEnum board = getCurrentBoard();
|
|
||||||
QString path = filename;
|
|
||||||
if (IS_SKY9X(board)) {
|
|
||||||
path.replace(".eepe", ".bin");
|
|
||||||
}
|
|
||||||
|
|
||||||
radioData.fixModelFilenames();
|
radioData.fixModelFilenames();
|
||||||
Storage storage(path);
|
Storage storage(filename);
|
||||||
bool result = storage.write(radioData);
|
bool result = storage.write(radioData);
|
||||||
|
if (!result) {
|
||||||
if (result && setCurrent) {
|
QMessageBox::warning(this, "Companion", tr("Cannot save file"), QMessageBox::Ok);
|
||||||
setCurrentFile(path);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
if (setCurrent) {
|
||||||
|
setCurrentFile(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MdiChild::userFriendlyCurrentFile() const
|
QString MdiChild::userFriendlyCurrentFile() const
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ class MdiChild : public QWidget
|
|||||||
void copyAvailable(bool val);
|
void copyAvailable(bool val);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void convertStorage(BoardEnum from, BoardEnum to);
|
||||||
|
void setCurrentFileExtension(const QString & ext);
|
||||||
void closeEvent(QCloseEvent * event);
|
void closeEvent(QCloseEvent * event);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|||||||
@@ -23,17 +23,17 @@
|
|||||||
|
|
||||||
// TODO here we will move a lot of functions from eeprominterface.cpp when no merge risk
|
// TODO here we will move a lot of functions from eeprominterface.cpp when no merge risk
|
||||||
|
|
||||||
void ModelData::convert(Firmware * before, Firmware * after)
|
void ModelData::convert(BoardEnum before, BoardEnum after)
|
||||||
{
|
{
|
||||||
// Here we can add explicit conversions when moving from one board to another
|
// Here we can add explicit conversions when moving from one board to another
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralSettings::convert(Firmware * before, Firmware * after)
|
void GeneralSettings::convert(BoardEnum before, BoardEnum after)
|
||||||
{
|
{
|
||||||
// Here we can add explicit conversions when moving from one board to another
|
// Here we can add explicit conversions when moving from one board to another
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioData::convert(Firmware * before, Firmware * after)
|
void RadioData::convert(BoardEnum before, BoardEnum after)
|
||||||
{
|
{
|
||||||
generalSettings.convert(before, after);
|
generalSettings.convert(before, after);
|
||||||
for (unsigned i=0; i<models.size(); i++) {
|
for (unsigned i=0; i<models.size(); i++) {
|
||||||
|
|||||||
@@ -1007,7 +1007,7 @@ class ModelData {
|
|||||||
ModelData(const ModelData & src);
|
ModelData(const ModelData & src);
|
||||||
ModelData & operator = (const ModelData & src);
|
ModelData & operator = (const ModelData & src);
|
||||||
|
|
||||||
void convert(Firmware * before, Firmware * after);
|
void convert(BoardEnum before, BoardEnum after);
|
||||||
|
|
||||||
ExpoData * insertInput(const int idx);
|
ExpoData * insertInput(const int idx);
|
||||||
void removeInput(const int idx);
|
void removeInput(const int idx);
|
||||||
@@ -1148,7 +1148,7 @@ class GeneralSettings {
|
|||||||
};
|
};
|
||||||
|
|
||||||
GeneralSettings();
|
GeneralSettings();
|
||||||
void convert(Firmware * before, Firmware * after);
|
void convert(BoardEnum before, BoardEnum after);
|
||||||
|
|
||||||
int getDefaultStick(unsigned int channel) const;
|
int getDefaultStick(unsigned int channel) const;
|
||||||
RawSource getDefaultSource(unsigned int channel) const;
|
RawSource getDefaultSource(unsigned int channel) const;
|
||||||
@@ -1275,7 +1275,7 @@ class RadioData {
|
|||||||
std::vector<CategoryData> categories;
|
std::vector<CategoryData> categories;
|
||||||
std::vector<ModelData> models;
|
std::vector<ModelData> models;
|
||||||
|
|
||||||
void convert(Firmware * before, Firmware * after);
|
void convert(BoardEnum before, BoardEnum after);
|
||||||
|
|
||||||
void setCurrentModel(unsigned int index)
|
void setCurrentModel(unsigned int index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,7 +50,11 @@ bool BinEepromFormat::write(const RadioData & radioData)
|
|||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
EEPROMInterface * eepromInterface = getCurrentEEpromInterface();
|
EEPROMInterface * eepromInterface = getCurrentEEpromInterface();
|
||||||
uint8_t * eeprom = (uint8_t *)malloc(getEEpromSize(eepromInterface->getBoard()));
|
int size = getEEpromSize(eepromInterface->getBoard());
|
||||||
|
if (size == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint8_t * eeprom = (uint8_t *)malloc(size);
|
||||||
int eeprom_size = eepromInterface->save(eeprom, radioData, 0, getCurrentFirmware()->getVariantNumber());
|
int eeprom_size = eepromInterface->save(eeprom, radioData, 0, getCurrentFirmware()->getVariantNumber());
|
||||||
if (eeprom_size) {
|
if (eeprom_size) {
|
||||||
result = writeToFile(eeprom, eeprom_size);
|
result = writeToFile(eeprom, eeprom_size);
|
||||||
@@ -91,6 +95,7 @@ bool BinEepromFormat::extract(RadioData & radioData, const QByteArray & eeprom)
|
|||||||
if (errors.test(HAS_WARNINGS)) {
|
if (errors.test(HAS_WARNINGS)) {
|
||||||
// TODO ShowEepromWarnings(this, QObject::tr("Warning"), errors.to_ulong());
|
// TODO ShowEepromWarnings(this, QObject::tr("Warning"), errors.to_ulong());
|
||||||
}
|
}
|
||||||
|
board = eepromInterface->getBoard();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -29,10 +29,13 @@ bool CategorizedStorageFormat::load(RadioData & radioData)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loadRadioSettingsFromByteArray(radioData.generalSettings, radioSettingsBuffer)) {
|
OpenTxEepromInterface * loadInterface = loadRadioSettingsFromByteArray(radioData.generalSettings, radioSettingsBuffer);
|
||||||
|
if (!loadInterface) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
board = loadInterface->getBoard();
|
||||||
|
|
||||||
QByteArray modelsListBuffer;
|
QByteArray modelsListBuffer;
|
||||||
if (!loadFile(modelsListBuffer, "RADIO/models.txt")) {
|
if (!loadFile(modelsListBuffer, "RADIO/models.txt")) {
|
||||||
setError(QObject::tr("Can't extract RADIO/models.txt"));
|
setError(QObject::tr("Can't extract RADIO/models.txt"));
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ bool Storage::load(RadioData & radioData)
|
|||||||
foreach(StorageFactory * factory, registeredStorageFactories) {
|
foreach(StorageFactory * factory, registeredStorageFactories) {
|
||||||
StorageFormat * format = factory->instance(filename);
|
StorageFormat * format = factory->instance(filename);
|
||||||
if (format->load(radioData)) {
|
if (format->load(radioData)) {
|
||||||
|
board = format->getBoard();
|
||||||
setWarning(format->warning());
|
setWarning(format->warning());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ class StorageFormat
|
|||||||
public:
|
public:
|
||||||
StorageFormat(const QString & filename, uint8_t version=0):
|
StorageFormat(const QString & filename, uint8_t version=0):
|
||||||
filename(filename),
|
filename(filename),
|
||||||
version(version)
|
version(version),
|
||||||
|
board(BOARD_UNKNOWN)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +62,10 @@ class StorageFormat
|
|||||||
|
|
||||||
virtual QString name() = 0;
|
virtual QString name() = 0;
|
||||||
|
|
||||||
|
virtual BoardEnum getBoard() {
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setError(const QString & error)
|
void setError(const QString & error)
|
||||||
{
|
{
|
||||||
@@ -78,6 +83,7 @@ class StorageFormat
|
|||||||
uint8_t version;
|
uint8_t version;
|
||||||
QString _error;
|
QString _error;
|
||||||
QString _warning;
|
QString _warning;
|
||||||
|
BoardEnum board;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StorageFactory
|
class StorageFactory
|
||||||
|
|||||||
Reference in New Issue
Block a user