[Companion] Improve first use of Companion & upgrade notice (#4940)
* [Companion] On first use of Companion show preferences dialog and new welcome message (closes #4731); Improve detection of new version upgrade & reformat message; Add download link URL to Linux update notice (closes #4774); Fix issue with leftover top-level settings categories when checking for older versions which don't exist; Introduce basic structure for warnings/messages to be suppressed by user preferences (eg. "don't show this message again" option). * Welcome msg typo fix.
This commit is contained in:
committed by
Bertrand Songis
parent
69576cb17d
commit
0fc1681d5c
@@ -53,6 +53,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#define OPENTX_DOWNLOADS_PAGE_URL "http://www.open-tx.org/downloads"
|
||||
#define OPENTX_COMPANION_DOWNLOADS "http://downloads-22.open-tx.org/companion"
|
||||
#define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2"
|
||||
|
||||
@@ -114,7 +115,16 @@ MainWindow::MainWindow():
|
||||
if (showSplash) {
|
||||
updateDelay += (SPLASH_TIME*1000);
|
||||
}
|
||||
QTimer::singleShot(updateDelay, this, SLOT(doAutoUpdates()));
|
||||
|
||||
if (g.isFirstUse()) {
|
||||
g.warningId(g.warningId() | AppMessages::MSG_WELCOME);
|
||||
QTimer::singleShot(updateDelay-500, this, SLOT(appPrefs())); // must be shown before warnings dialog but after splash
|
||||
}
|
||||
else {
|
||||
if (!g.previousVersion().isEmpty())
|
||||
g.warningId(g.warningId() | AppMessages::MSG_UPGRADED);
|
||||
QTimer::singleShot(updateDelay, this, SLOT(doAutoUpdates()));
|
||||
}
|
||||
QTimer::singleShot(updateDelay, this, SLOT(displayWarnings()));
|
||||
|
||||
QStringList strl = QApplication::arguments();
|
||||
@@ -167,21 +177,39 @@ MainWindow::~MainWindow()
|
||||
|
||||
void MainWindow::displayWarnings()
|
||||
{
|
||||
int warnId = g.warningId();
|
||||
if (warnId<WARNING_ID && warnId!=0) {
|
||||
int res=0;
|
||||
if (WARNING_LEVEL>0)
|
||||
QMessageBox::warning(this, "Companion", WARNING);
|
||||
else
|
||||
QMessageBox::about(this, "Companion", WARNING);
|
||||
res = QMessageBox::question(this, "Companion", tr("Display previous warning again at startup ?"), QMessageBox::Yes | QMessageBox::No);
|
||||
if (res == QMessageBox::No) {
|
||||
g.warningId(WARNING_ID);
|
||||
}
|
||||
using namespace AppMessages;
|
||||
static uint shownMsgs = 0;
|
||||
int showMsgs = g.warningId();
|
||||
int msgId;
|
||||
QString infoTxt;
|
||||
|
||||
if ((showMsgs & MSG_WELCOME) && !(shownMsgs & MSG_WELCOME)) {
|
||||
infoTxt = CPN_STR_MSG_WELCOME.arg(VERSION);
|
||||
msgId = MSG_WELCOME;
|
||||
}
|
||||
else if (warnId==0) {
|
||||
g.warningId(WARNING_ID);
|
||||
else if ((showMsgs & MSG_UPGRADED) && !(shownMsgs & MSG_UPGRADED)) {
|
||||
infoTxt = CPN_STR_MSG_UPGRADED.arg(VERSION);
|
||||
msgId = MSG_UPGRADED;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setWindowTitle(tr("Companion"));
|
||||
msgBox.setIcon(QMessageBox::Information);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setInformativeText(infoTxt);
|
||||
QCheckBox * cb = new QCheckBox(tr("Show this message again at next startup?"), &msgBox);
|
||||
msgBox.setCheckBox(cb);
|
||||
|
||||
msgBox.exec();
|
||||
|
||||
shownMsgs |= msgId;
|
||||
if (!cb->isChecked())
|
||||
g.warningId(showMsgs & ~msgId);
|
||||
|
||||
displayWarnings(); // in case more warnings need showing
|
||||
}
|
||||
|
||||
void MainWindow::doAutoUpdates()
|
||||
@@ -317,7 +345,7 @@ void MainWindow::checkForCompanionUpdateFinished(QNetworkReply * reply)
|
||||
}
|
||||
}
|
||||
#else
|
||||
QMessageBox::warning(this, tr("New release available"), tr("A new release of Companion is available, please check the OpenTX website!"));
|
||||
QMessageBox::warning(this, tr("New release available"), tr("A new release of Companion is available, please check the <a href='%1'>OpenTX website!</a>").arg(OPENTX_DOWNLOADS_PAGE_URL));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -557,9 +557,15 @@ void AppData::init()
|
||||
{
|
||||
qRegisterMetaTypeStreamOperators<SimulatorOptions>("SimulatorOptions");
|
||||
|
||||
firstUse = false;
|
||||
upgradeFromVersion = "";
|
||||
|
||||
QSettings settings(COMPANY, PRODUCT);
|
||||
if (!settings.contains("settings_version"))
|
||||
importSettings(settings);
|
||||
if (!settings.contains("settings_version")) {
|
||||
if (!importSettings(settings))
|
||||
firstUse = true;
|
||||
}
|
||||
convertSettings(settings);
|
||||
|
||||
// Initialize the profiles
|
||||
for (int i=0; i<MAX_PROFILES; i++)
|
||||
@@ -649,23 +655,69 @@ QMap<int, QString> AppData::getActiveProfiles()
|
||||
return active;
|
||||
}
|
||||
|
||||
void AppData::convertSettings(QSettings & settings)
|
||||
{
|
||||
// convert old settings to new
|
||||
if (settings.contains("useWizard")) {
|
||||
if (!settings.contains("newModelAction")) {
|
||||
newModelAction(settings.value("useWizard").toBool() ? 1 : 2);
|
||||
}
|
||||
settings.remove("useWizard");
|
||||
}
|
||||
if (settings.contains("warningId") && settings.value("warningId").toInt() == 7) {
|
||||
// meaning of warningId changed during v2.2 development but value of "7" indicates old setting, removing it will restore defaults
|
||||
settings.remove("warningId");
|
||||
}
|
||||
}
|
||||
|
||||
bool AppData::importSettings(QSettings & toSettings)
|
||||
{
|
||||
QSettings * fromSettings = NULL;
|
||||
|
||||
QSettings settings21("OpenTX", "Companion 2.1");
|
||||
QSettings settings20("OpenTX", "Companion 2.0");
|
||||
QSettings settings16("OpenTX", "OpenTX Companion");
|
||||
QSettings settings9x("companion9x", "companion9x");
|
||||
|
||||
if (settings21.contains("settings_version"))
|
||||
if (settings21.contains("settings_version")) {
|
||||
fromSettings = &settings21;
|
||||
else if (settings20.contains("settings_version"))
|
||||
fromSettings = &settings20;
|
||||
else if (settings16.contains("settings_version"))
|
||||
fromSettings = &settings16;
|
||||
else if (settings9x.contains("default_mode"))
|
||||
fromSettings = &settings9x;
|
||||
upgradeFromVersion = "2.1";
|
||||
}
|
||||
else {
|
||||
settings21.clear();
|
||||
}
|
||||
|
||||
if (!fromSettings) {
|
||||
QSettings settings20("OpenTX", "Companion 2.0");
|
||||
if (settings20.contains("settings_version")) {
|
||||
fromSettings = &settings20;
|
||||
upgradeFromVersion = "2.0";
|
||||
}
|
||||
else {
|
||||
settings20.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromSettings) {
|
||||
QSettings settings16("OpenTX", "OpenTX Companion");
|
||||
if (settings16.contains("settings_version")) {
|
||||
fromSettings = &settings16;
|
||||
upgradeFromVersion = "1.x";
|
||||
}
|
||||
else {
|
||||
settings16.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromSettings) {
|
||||
QSettings settings9x("companion9x", "companion9x");
|
||||
if (settings9x.contains("default_mode")) {
|
||||
fromSettings = &settings9x;
|
||||
upgradeFromVersion = "Companion9X";
|
||||
}
|
||||
else {
|
||||
settings9x.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromSettings)
|
||||
return false;
|
||||
|
||||
// do not copy these settings
|
||||
QStringList excludeKeys = QStringList() << "compilation-server";
|
||||
@@ -677,16 +729,14 @@ bool AppData::importSettings(QSettings & toSettings)
|
||||
#endif
|
||||
|
||||
// import settings
|
||||
if (fromSettings) {
|
||||
foreach (const QString & key, fromSettings->allKeys()) {
|
||||
if (fromSettings->value(key).isValid() && !excludeKeys.contains(key)) {
|
||||
toSettings.setValue(key, fromSettings->value(key));
|
||||
}
|
||||
foreach (const QString & key, fromSettings->allKeys()) {
|
||||
if (fromSettings->value(key).isValid() && !excludeKeys.contains(key)) {
|
||||
toSettings.setValue(key, fromSettings->value(key));
|
||||
}
|
||||
}
|
||||
|
||||
// Additional adjustments for companion9x settings
|
||||
if (fromSettings && fromSettings->applicationName() == "companion9x") {
|
||||
if (fromSettings->applicationName() == "companion9x") {
|
||||
// Store old values in new locations
|
||||
autoCheckApp(toSettings.value("startup_check_companion9x", true).toBool());
|
||||
toSettings.setValue("useWizard", toSettings.value("wizardEnable", true));
|
||||
@@ -726,20 +776,12 @@ bool AppData::importSettings(QSettings & toSettings)
|
||||
toSettings.remove("sdPath");
|
||||
toSettings.remove("SplashFileName");
|
||||
toSettings.remove("startup_check_companion9x");
|
||||
toSettings.remove("warningId");
|
||||
toSettings.remove("wizardEnable");
|
||||
|
||||
// Select the new default profile as current profile
|
||||
id( 0 );
|
||||
}
|
||||
|
||||
// convert old settings to new
|
||||
|
||||
if (toSettings.contains("useWizard")) {
|
||||
if (!toSettings.contains("newModelAction")) {
|
||||
newModelAction(toSettings.value("useWizard").toBool() ? 1 : 2);
|
||||
}
|
||||
toSettings.remove("useWizard");
|
||||
}
|
||||
|
||||
return fromSettings ? true : false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -429,10 +429,15 @@ class AppData: protected CompStoreObj
|
||||
void init();
|
||||
|
||||
QMap<int, QString> getActiveProfiles();
|
||||
inline bool isFirstUse() const { return firstUse; }
|
||||
inline QString previousVersion() const { return upgradeFromVersion; }
|
||||
|
||||
protected:
|
||||
void convertSettings(QSettings & settings);
|
||||
bool importSettings(QSettings & toSettings);
|
||||
|
||||
bool firstUse;
|
||||
QString upgradeFromVersion;
|
||||
};
|
||||
|
||||
extern AppData g;
|
||||
|
||||
@@ -20,9 +20,33 @@
|
||||
|
||||
#ifndef _WARNINGS_H_
|
||||
#define _WARNINGS_H_
|
||||
#define WARNING_LEVEL 0
|
||||
#define WARNING_ID 7
|
||||
#define WARNING QObject::tr("Thank you for upgrading to OpenTX 2.0. This is a major upgrade that adds and modifies a lot of things, so please make sure that you read release notes carefully to learn about the changes, and thoroughly check each of your models for proper function.\n\nThe OpenTX Team.")
|
||||
|
||||
#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>" \
|
||||
"<p>You may also want to take this time to review the other available options in the displayed Settings dialog.</p>" \
|
||||
"<p>After saving your settings, we recommend you download the latest firmware for your radio by using the <i>File -> Download</i> menu option.</p>" \
|
||||
"<p>Please visit <a href='http://www.open-tx.org'>open-tx.org</a> for latest news, updates and documentation. Thank you for choosing OpenTX!</p>" \
|
||||
"- The OpenTX Team.")
|
||||
|
||||
#define CPN_STR_MSG_UPGRADED QCoreApplication::translate("Companion", \
|
||||
"<p><b>Thank you for upgrading to OpenTX v%1.</b></p>" \
|
||||
"<p>This is a major upgrade that adds and modifies a lot of things, so please make sure that you read release notes carefully" \
|
||||
" to learn about the changes, and thoroughly check each of your models for proper function.</p>" \
|
||||
"<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 {
|
||||
|
||||
// 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_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user