Skip to content

Commit 9aa2aa5

Browse files
author
Neil Horne
authored
chore(cpn): add Accept and Decline buttons to yaml decode unsupported versions dialogs (#4801)
1 parent 4362181 commit 9aa2aa5

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

companion/src/constants.h

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
#define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading
6262
#define CPN_STR_TTL_WARNING QCoreApplication::translate("Companion", "Warning")
6363
#define CPN_STR_TTL_ERROR QCoreApplication::translate("Companion", "Error")
64+
#define CPN_STR_TTL_ACCEPT QCoreApplication::translate("Companion", "Accept")
65+
#define CPN_STR_TTL_DECLINE QCoreApplication::translate("Companion", "Decline")
6466

6567
#define CPN_STR_FILES QCoreApplication::translate("Companion", "files")
6668
#define CPN_STR_RAD_MOD_SETTINGS QCoreApplication::translate("Companion", "Radio and Models settings")

companion/src/firmwares/edgetx/yaml_generalsettings.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "helpers.h"
3232

3333
#include <QMessageBox>
34+
#include <QPushButton>
3435

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

365366
if (radioSettingsVersion > SemanticVersion(VERSION)) {
366-
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.");
367-
if (QMessageBox::warning(NULL, CPN_STR_APP_NAME, prmpt.arg(radioSettingsVersion.toString()), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) {
368-
// TODO: this triggers an error in the calling code so we need a graceful way to handle
367+
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.");
368+
prmpt = prmpt.arg(radioSettingsVersion.toString());
369+
QMessageBox msgBox;
370+
msgBox.setWindowTitle(QCoreApplication::translate("YamlGeneralSettings", "Read Radio Settings"));
371+
msgBox.setText(prmpt);
372+
msgBox.setIcon(QMessageBox::Warning);
373+
QPushButton *pbAccept = new QPushButton(CPN_STR_TTL_ACCEPT);
374+
QPushButton *pbDecline = new QPushButton(CPN_STR_TTL_DECLINE);
375+
msgBox.addButton(pbAccept, QMessageBox::AcceptRole);
376+
msgBox.addButton(pbDecline, QMessageBox::RejectRole);
377+
msgBox.setDefaultButton(pbDecline);
378+
msgBox.exec();
379+
if (msgBox.clickedButton() == pbDecline)
369380
return false;
370-
}
371381
}
372382

373383
rhs.version = CPN_CURRENT_SETTINGS_VERSION; // depreciated in EdgeTX however data conversions use

companion/src/firmwares/edgetx/yaml_modeldata.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include <string>
4141
#include <QMessageBox>
42+
#include <QPushButton>
4243

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

11751176
// TODO display model filename in preference to model name as easier for user
11761177
if (modelSettingsVersion > SemanticVersion(VERSION)) {
1177-
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.");
1178-
if (QMessageBox::warning(NULL, CPN_STR_APP_NAME, prmpt.arg(rhs.name).arg(modelSettingsVersion.toString()), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) {
1179-
// TODO: this triggers an error in the calling code so we need a graceful way to handle
1178+
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.");
1179+
prmpt = prmpt.arg(rhs.name).arg(modelSettingsVersion.toString());
1180+
QMessageBox msgBox;
1181+
msgBox.setWindowTitle(QCoreApplication::translate("YamlModelSettings", "Read Model Settings"));
1182+
msgBox.setText(prmpt);
1183+
msgBox.setIcon(QMessageBox::Warning);
1184+
QPushButton *pbAccept = new QPushButton(CPN_STR_TTL_ACCEPT);
1185+
QPushButton *pbDecline = new QPushButton(CPN_STR_TTL_DECLINE);
1186+
msgBox.addButton(pbAccept, QMessageBox::AcceptRole);
1187+
msgBox.addButton(pbDecline, QMessageBox::RejectRole);
1188+
msgBox.setDefaultButton(pbDecline);
1189+
msgBox.exec();
1190+
if (msgBox.clickedButton() == pbDecline)
11801191
return false;
1181-
}
11821192
}
11831193

11841194
if (node["timers"]) {

0 commit comments

Comments
 (0)