From 0fc1681d5ce0ab2589cf27b861e1a97a76f2a7ad Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Tue, 23 May 2017 03:44:47 -0400 Subject: [PATCH] [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. --- companion/src/mainwindow.cpp | 58 ++++++++++++----- companion/src/storage/appdata.cpp | 100 +++++++++++++++++++++--------- companion/src/storage/appdata.h | 5 ++ companion/src/warnings.h | 30 ++++++++- 4 files changed, 146 insertions(+), 47 deletions(-) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 610a34f90..319b8db03 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -53,6 +53,7 @@ #include #include +#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 (warnId0) - 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 OpenTX website!").arg(OPENTX_DOWNLOADS_PAGE_URL)); #endif } else { diff --git a/companion/src/storage/appdata.cpp b/companion/src/storage/appdata.cpp index e6feb194c..d047ad0f1 100644 --- a/companion/src/storage/appdata.cpp +++ b/companion/src/storage/appdata.cpp @@ -557,9 +557,15 @@ void AppData::init() { qRegisterMetaTypeStreamOperators("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 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; } diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 2f85e50e8..e966a091c 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -429,10 +429,15 @@ class AppData: protected CompStoreObj void init(); QMap 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; diff --git a/companion/src/warnings.h b/companion/src/warnings.h index f17436dda..118b0cf87 100644 --- a/companion/src/warnings.h +++ b/companion/src/warnings.h @@ -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", \ + "

Welcome to OpenTX v%1.

" \ + "

As the first step, please configure the initial Radio Profile by selecting your Radio Type, Menu Language, and Build Options.

" \ + "

You may also want to take this time to review the other available options in the displayed Settings dialog.

" \ + "

After saving your settings, we recommend you download the latest firmware for your radio by using the File -> Download menu option.

" \ + "

Please visit open-tx.org for latest news, updates and documentation. Thank you for choosing OpenTX!

" \ + "- The OpenTX Team.") + +#define CPN_STR_MSG_UPGRADED QCoreApplication::translate("Companion", \ + "

Thank you for upgrading to OpenTX v%1.

" \ + "

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.

" \ + "

Please visit open-tx.org for release notes and other documentation.

" \ + "- 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_