[Companion] Verify that radio type in chosen profile actually exists, and add warning to the contrary (at startup and also on profile switch); Add/move some functionality to AppMessages and make it classy (todo: rename file).

This commit is contained in:
Max Paperno
2018-09-19 06:47:35 -04:00
parent fdcee1ca9f
commit 13b156402f
3 changed files with 92 additions and 41 deletions
+62 -9
View File
@@ -21,6 +21,12 @@
#ifndef _WARNINGS_H_
#define _WARNINGS_H_
#include "appdata.h"
#include <QtCore>
#include <QCheckBox>
#include <QMessageBox>
#define CPN_STR_MSG_WELCOME QCoreApplication::translate("Companion", \
"<p><b>Welcome to OpenTX v%1.</b></p>" \
"<p>As the first step, please configure the initial Radio Profile by selecting your Radio Type, Menu Language, and Build Options.</p>" \
@@ -36,17 +42,64 @@
"<p>Please visit <a href='http://www.open-tx.org'>open-tx.org</a> for release notes and other documentation.</p>" \
"- The OpenTX Team.")
namespace AppMessages {
#define CPN_STR_MSG_NO_RADIO_TYPE QCoreApplication::translate("Companion", \
"<p>The radio type in the selected profile does not exist. Using the default type instead.</p> <p><b>Please update your profile settings!</b></p>")
class AppMessages
{
Q_DECLARE_TR_FUNCTIONS("AppMessages")
public:
// These are used for saving "[don't] show this message again" user preferences.
enum MessageCodes {
MSG_NONE = 0,
MSG_WELCOME = 0x01,
MSG_UPGRADED = 0x02,
MSG_RESERVED = 0x04, // reserved due to legacy code
MSG_NO_RADIO_TYPE = 0x08,
MSG_ENUM_END
};
static void displayMessage(int id, QWidget * parent = nullptr)
{
QString infoTxt;
QMessageBox::Icon icon = QMessageBox::Information;
bool transient = false;
switch (id) {
case MSG_WELCOME:
infoTxt = CPN_STR_MSG_WELCOME.arg(VERSION);
break;
case MSG_UPGRADED:
infoTxt = CPN_STR_MSG_UPGRADED.arg(VERSION);
break;
case MSG_NO_RADIO_TYPE:
infoTxt = CPN_STR_MSG_NO_RADIO_TYPE;
icon = QMessageBox::Warning;
transient = true;
break;
default:
return;
}
QMessageBox msgBox(parent);
msgBox.setWindowTitle(CPN_STR_APP_NAME);
msgBox.setIcon(icon);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(infoTxt);
if (!transient)
msgBox.setCheckBox(new QCheckBox(tr("Show this message again at next startup?")));
msgBox.exec();
if (transient || (msgBox.checkBox() && !msgBox.checkBox()->isChecked()))
g.warningId(g.warningId() & ~id);
}
// These are used for saving "[don't] show this message again" user preferences.
enum MessageCodes {
MSG_NONE = 0,
MSG_WELCOME = 0x01,
MSG_UPGRADED = 0x02,
MSG_RESERVED = 0x04, // reserved due to legacy code
};
} // namespace AppWarnings
#endif // _WARNINGS_H_