Skip to content

Commit

Permalink
chore(cpn): add Accept and Decline buttons to yaml decode unsupported…
Browse files Browse the repository at this point in the history
… versions dialogs (EdgeTX#4801)
  • Loading branch information
Neil Horne authored and felipemanga committed Mar 29, 2024
1 parent 692ecd4 commit 8400323
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions companion/src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading
#define CPN_STR_TTL_WARNING QCoreApplication::translate("Companion", "Warning")
#define CPN_STR_TTL_ERROR QCoreApplication::translate("Companion", "Error")
#define CPN_STR_TTL_ACCEPT QCoreApplication::translate("Companion", "Accept")
#define CPN_STR_TTL_DECLINE QCoreApplication::translate("Companion", "Decline")

#define CPN_STR_FILES QCoreApplication::translate("Companion", "files")
#define CPN_STR_RAD_MOD_SETTINGS QCoreApplication::translate("Companion", "Radio and Models settings")
Expand Down
18 changes: 14 additions & 4 deletions companion/src/firmwares/edgetx/yaml_generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "helpers.h"

#include <QMessageBox>
#include <QPushButton>

void YamlValidateNames(GeneralSettings& gs, Board::Type board)
{
Expand Down Expand Up @@ -363,11 +364,20 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
qDebug() << "Settings version:" << radioSettingsVersion.toString();

if (radioSettingsVersion > SemanticVersion(VERSION)) {
QString prmpt = QCoreApplication::translate("YamlGeneralSettings", "Warning: Radio settings file version %1 is not supported by this version of Companion!\n\nModel and radio settings may be corrupted if you continue.\n\nI acknowledge and accept the consequences.");
if (QMessageBox::warning(NULL, CPN_STR_APP_NAME, prmpt.arg(radioSettingsVersion.toString()), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) {
// TODO: this triggers an error in the calling code so we need a graceful way to handle
QString prmpt = QCoreApplication::translate("YamlGeneralSettings", "Warning: File version %1 is not supported by this version of Companion!\n\nModel and radio settings may be corrupted if you continue.");
prmpt = prmpt.arg(radioSettingsVersion.toString());
QMessageBox msgBox;
msgBox.setWindowTitle(QCoreApplication::translate("YamlGeneralSettings", "Read Radio Settings"));
msgBox.setText(prmpt);
msgBox.setIcon(QMessageBox::Warning);
QPushButton *pbAccept = new QPushButton(CPN_STR_TTL_ACCEPT);
QPushButton *pbDecline = new QPushButton(CPN_STR_TTL_DECLINE);
msgBox.addButton(pbAccept, QMessageBox::AcceptRole);
msgBox.addButton(pbDecline, QMessageBox::RejectRole);
msgBox.setDefaultButton(pbDecline);
msgBox.exec();
if (msgBox.clickedButton() == pbDecline)
return false;
}
}

rhs.version = CPN_CURRENT_SETTINGS_VERSION; // depreciated in EdgeTX however data conversions use
Expand Down
18 changes: 14 additions & 4 deletions companion/src/firmwares/edgetx/yaml_modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <string>
#include <QMessageBox>
#include <QPushButton>

void YamlValidateLabelsNames(ModelData& model, Board::Type board)
{
Expand Down Expand Up @@ -1174,11 +1175,20 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)

// TODO display model filename in preference to model name as easier for user
if (modelSettingsVersion > SemanticVersion(VERSION)) {
QString prmpt = QCoreApplication::translate("YamlModelSettings", "Warning: Model '%1' has settings version %2 that is not supported by this version of Companion!\n\nModel and radio settings may be corrupted if you continue.\n\nI acknowledge and accept the consequences.");
if (QMessageBox::warning(NULL, CPN_STR_APP_NAME, prmpt.arg(rhs.name).arg(modelSettingsVersion.toString()), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) {
// TODO: this triggers an error in the calling code so we need a graceful way to handle
QString prmpt = QCoreApplication::translate("YamlModelSettings", "Warning: '%1' has settings version %2 that is not supported by this version of Companion!\n\nModel settings may be corrupted if you continue.");
prmpt = prmpt.arg(rhs.name).arg(modelSettingsVersion.toString());
QMessageBox msgBox;
msgBox.setWindowTitle(QCoreApplication::translate("YamlModelSettings", "Read Model Settings"));
msgBox.setText(prmpt);
msgBox.setIcon(QMessageBox::Warning);
QPushButton *pbAccept = new QPushButton(CPN_STR_TTL_ACCEPT);
QPushButton *pbDecline = new QPushButton(CPN_STR_TTL_DECLINE);
msgBox.addButton(pbAccept, QMessageBox::AcceptRole);
msgBox.addButton(pbDecline, QMessageBox::RejectRole);
msgBox.setDefaultButton(pbDecline);
msgBox.exec();
if (msgBox.clickedButton() == pbDecline)
return false;
}
}

if (node["timers"]) {
Expand Down

0 comments on commit 8400323

Please sign in to comment.