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_X9E,
|
||||
BOARD_FLAMENCO,
|
||||
BOARD_HORUS
|
||||
BOARD_HORUS,
|
||||
BOARD_UNKNOWN = -1
|
||||
};
|
||||
|
||||
#define CPN_MAX_MODELS 60
|
||||
|
||||
@@ -1573,14 +1573,14 @@ void unregisterOpenTxFirmwares()
|
||||
}
|
||||
|
||||
template <class T, class M>
|
||||
bool loadFromByteArray(T & dest, const QByteArray & data)
|
||||
OpenTxEepromInterface * loadFromByteArray(T & dest, const QByteArray & data)
|
||||
{
|
||||
foreach(OpenTxEepromInterface * eepromInterface, opentxEEpromInterfaces) {
|
||||
if (eepromInterface->loadFromByteArray<T, M>(dest, data)) {
|
||||
return true;
|
||||
return eepromInterface;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template <class T, class M>
|
||||
@@ -1595,12 +1595,12 @@ bool saveToByteArray(const T & dest, QByteArray & data)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool loadModelFromByteArray(ModelData & model, const QByteArray & data)
|
||||
OpenTxEepromInterface * loadModelFromByteArray(ModelData & model, const QByteArray & 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);
|
||||
}
|
||||
|
||||
@@ -150,8 +150,8 @@ void unregisterOpenTxFirmwares();
|
||||
|
||||
extern QList<OpenTxEepromInterface *> opentxEEpromInterfaces;
|
||||
|
||||
bool loadModelFromByteArray(ModelData & model, const QByteArray & data);
|
||||
bool loadRadioSettingsFromByteArray(GeneralSettings & settings, const QByteArray & data);
|
||||
OpenTxEepromInterface * loadModelFromByteArray(ModelData & model, const QByteArray & data);
|
||||
OpenTxEepromInterface * loadRadioSettingsFromByteArray(GeneralSettings & settings, const QByteArray & data);
|
||||
|
||||
bool writeModelToByteArray(const ModelData & model, QByteArray & data);
|
||||
bool writeRadioSettingsToByteArray(const GeneralSettings & settings, QByteArray & data);
|
||||
|
||||
+29
-12
@@ -152,13 +152,28 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos)
|
||||
contextMenu.exec(globalPos);
|
||||
}
|
||||
|
||||
void MdiChild::setCurrentFileExtension(const QString & ext)
|
||||
{
|
||||
QFileInfo info(curFile);
|
||||
curFile = info.path() + "/" + info.baseName() + ext;
|
||||
}
|
||||
|
||||
void MdiChild::onFirmwareChanged()
|
||||
{
|
||||
Firmware * previous = firmware;
|
||||
firmware = getCurrentFirmware();
|
||||
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();
|
||||
fileChanged = true;
|
||||
documentWasModified();
|
||||
}
|
||||
|
||||
void MdiChild::initModelsList()
|
||||
@@ -491,6 +506,10 @@ bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile)
|
||||
setCurrentFile(filename);
|
||||
}
|
||||
|
||||
if (storage.getBoard() != getCurrentBoard()) {
|
||||
convertStorage(storage.getBoard(), getCurrentBoard());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -535,21 +554,19 @@ bool MdiChild::saveAs(bool isNew)
|
||||
|
||||
bool MdiChild::saveFile(const QString & filename, bool setCurrent)
|
||||
{
|
||||
BoardEnum board = getCurrentBoard();
|
||||
QString path = filename;
|
||||
if (IS_SKY9X(board)) {
|
||||
path.replace(".eepe", ".bin");
|
||||
}
|
||||
|
||||
radioData.fixModelFilenames();
|
||||
Storage storage(path);
|
||||
Storage storage(filename);
|
||||
bool result = storage.write(radioData);
|
||||
|
||||
if (result && setCurrent) {
|
||||
setCurrentFile(path);
|
||||
if (!result) {
|
||||
QMessageBox::warning(this, "Companion", tr("Cannot save file"), QMessageBox::Ok);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
if (setCurrent) {
|
||||
setCurrentFile(filename);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString MdiChild::userFriendlyCurrentFile() const
|
||||
|
||||
@@ -59,6 +59,8 @@ class MdiChild : public QWidget
|
||||
void copyAvailable(bool val);
|
||||
|
||||
protected:
|
||||
void convertStorage(BoardEnum from, BoardEnum to);
|
||||
void setCurrentFileExtension(const QString & ext);
|
||||
void closeEvent(QCloseEvent * event);
|
||||
|
||||
protected slots:
|
||||
|
||||
@@ -23,17 +23,17 @@
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void RadioData::convert(Firmware * before, Firmware * after)
|
||||
void RadioData::convert(BoardEnum before, BoardEnum after)
|
||||
{
|
||||
generalSettings.convert(before, after);
|
||||
for (unsigned i=0; i<models.size(); i++) {
|
||||
|
||||
@@ -1007,7 +1007,7 @@ class ModelData {
|
||||
ModelData(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);
|
||||
void removeInput(const int idx);
|
||||
@@ -1148,7 +1148,7 @@ class GeneralSettings {
|
||||
};
|
||||
|
||||
GeneralSettings();
|
||||
void convert(Firmware * before, Firmware * after);
|
||||
void convert(BoardEnum before, BoardEnum after);
|
||||
|
||||
int getDefaultStick(unsigned int channel) const;
|
||||
RawSource getDefaultSource(unsigned int channel) const;
|
||||
@@ -1275,7 +1275,7 @@ class RadioData {
|
||||
std::vector<CategoryData> categories;
|
||||
std::vector<ModelData> models;
|
||||
|
||||
void convert(Firmware * before, Firmware * after);
|
||||
void convert(BoardEnum before, BoardEnum after);
|
||||
|
||||
void setCurrentModel(unsigned int index)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,11 @@ bool BinEepromFormat::write(const RadioData & radioData)
|
||||
{
|
||||
bool result;
|
||||
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());
|
||||
if (eeprom_size) {
|
||||
result = writeToFile(eeprom, eeprom_size);
|
||||
@@ -91,6 +95,7 @@ bool BinEepromFormat::extract(RadioData & radioData, const QByteArray & eeprom)
|
||||
if (errors.test(HAS_WARNINGS)) {
|
||||
// TODO ShowEepromWarnings(this, QObject::tr("Warning"), errors.to_ulong());
|
||||
}
|
||||
board = eepromInterface->getBoard();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -29,9 +29,12 @@ bool CategorizedStorageFormat::load(RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loadRadioSettingsFromByteArray(radioData.generalSettings, radioSettingsBuffer)) {
|
||||
OpenTxEepromInterface * loadInterface = loadRadioSettingsFromByteArray(radioData.generalSettings, radioSettingsBuffer);
|
||||
if (!loadInterface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
board = loadInterface->getBoard();
|
||||
|
||||
QByteArray modelsListBuffer;
|
||||
if (!loadFile(modelsListBuffer, "RADIO/models.txt")) {
|
||||
|
||||
@@ -75,6 +75,7 @@ bool Storage::load(RadioData & radioData)
|
||||
foreach(StorageFactory * factory, registeredStorageFactories) {
|
||||
StorageFormat * format = factory->instance(filename);
|
||||
if (format->load(radioData)) {
|
||||
board = format->getBoard();
|
||||
setWarning(format->warning());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ class StorageFormat
|
||||
public:
|
||||
StorageFormat(const QString & filename, uint8_t version=0):
|
||||
filename(filename),
|
||||
version(version)
|
||||
version(version),
|
||||
board(BOARD_UNKNOWN)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -61,6 +62,10 @@ class StorageFormat
|
||||
|
||||
virtual QString name() = 0;
|
||||
|
||||
virtual BoardEnum getBoard() {
|
||||
return board;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setError(const QString & error)
|
||||
{
|
||||
@@ -78,6 +83,7 @@ class StorageFormat
|
||||
uint8_t version;
|
||||
QString _error;
|
||||
QString _warning;
|
||||
BoardEnum board;
|
||||
};
|
||||
|
||||
class StorageFactory
|
||||
|
||||
Reference in New Issue
Block a user