Force Oracle run on new install/update (#3497)

* Force Oracle run on new install/update

Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com>

* Add settings option to disable such a check

Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com>
This commit is contained in:
Zach H 2019-01-14 01:11:05 -05:00 committed by GitHub
parent 273d5d89b7
commit 41bfbf2e83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 5 deletions

View file

@ -53,6 +53,7 @@ GeneralSettingsPage::GeneralSettingsPage()
updateReleaseChannelBox.setCurrentIndex(settingsCache->getUpdateReleaseChannel()->getIndex()); updateReleaseChannelBox.setCurrentIndex(settingsCache->getUpdateReleaseChannel()->getIndex());
updateNotificationCheckBox.setChecked(settingsCache->getNotifyAboutUpdates()); updateNotificationCheckBox.setChecked(settingsCache->getNotifyAboutUpdates());
newVersionOracleCheckBox.setChecked(settingsCache->getNotifyAboutNewVersion());
// pixmap cache // pixmap cache
pixmapCacheEdit.setMinimum(PIXMAPCACHE_SIZE_MIN); pixmapCacheEdit.setMinimum(PIXMAPCACHE_SIZE_MIN);
@ -69,6 +70,7 @@ GeneralSettingsPage::GeneralSettingsPage()
connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), settingsCache, connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), settingsCache,
SLOT(setUpdateReleaseChannel(int))); SLOT(setUpdateReleaseChannel(int)));
connect(&updateNotificationCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setNotifyAboutUpdate(int))); connect(&updateNotificationCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setNotifyAboutUpdate(int)));
connect(&newVersionOracleCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setNotifyAboutNewVersion(int)));
connect(&showTipsOnStartup, SIGNAL(clicked(bool)), settingsCache, SLOT(setShowTipsOnStartup(bool))); connect(&showTipsOnStartup, SIGNAL(clicked(bool)), settingsCache, SLOT(setShowTipsOnStartup(bool)));
auto *personalGrid = new QGridLayout; auto *personalGrid = new QGridLayout;
@ -79,7 +81,8 @@ GeneralSettingsPage::GeneralSettingsPage()
personalGrid->addWidget(&pixmapCacheLabel, 2, 0); personalGrid->addWidget(&pixmapCacheLabel, 2, 0);
personalGrid->addWidget(&pixmapCacheEdit, 2, 1); personalGrid->addWidget(&pixmapCacheEdit, 2, 1);
personalGrid->addWidget(&updateNotificationCheckBox, 3, 0); personalGrid->addWidget(&updateNotificationCheckBox, 3, 0);
personalGrid->addWidget(&showTipsOnStartup, 4, 0); personalGrid->addWidget(&newVersionOracleCheckBox, 4, 0);
personalGrid->addWidget(&showTipsOnStartup, 5, 0);
personalGroupBox = new QGroupBox; personalGroupBox = new QGroupBox;
personalGroupBox->setLayout(personalGrid); personalGroupBox->setLayout(personalGrid);
@ -242,6 +245,7 @@ void GeneralSettingsPage::retranslateUi()
pixmapCacheLabel.setText(tr("Picture cache size:")); pixmapCacheLabel.setText(tr("Picture cache size:"));
updateReleaseChannelLabel.setText(tr("Update channel")); updateReleaseChannelLabel.setText(tr("Update channel"));
updateNotificationCheckBox.setText(tr("Notify if a feature supported by the server is missing in my client")); updateNotificationCheckBox.setText(tr("Notify if a feature supported by the server is missing in my client"));
newVersionOracleCheckBox.setText(tr("Automatically run Oracle when running a new version of Cockatrice"));
showTipsOnStartup.setText(tr("Show tips on startup")); showTipsOnStartup.setText(tr("Show tips on startup"));
} }

View file

@ -60,6 +60,7 @@ private:
QGroupBox *pathsGroupBox; QGroupBox *pathsGroupBox;
QComboBox languageBox; QComboBox languageBox;
QCheckBox updateNotificationCheckBox; QCheckBox updateNotificationCheckBox;
QCheckBox newVersionOracleCheckBox;
QComboBox updateReleaseChannelBox; QComboBox updateReleaseChannelBox;
QLabel languageLabel; QLabel languageLabel;
QLabel pixmapCacheLabel; QLabel pixmapCacheLabel;

View file

@ -177,6 +177,7 @@ SettingsCache::SettingsCache()
mbDownloadSpoilers = settings->value("personal/downloadspoilers", false).toBool(); mbDownloadSpoilers = settings->value("personal/downloadspoilers", false).toBool();
notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool(); notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool();
notifyAboutNewVersion = settings->value("personal/newversionnotification", true).toBool();
updateReleaseChannel = settings->value("personal/updatereleasechannel", 0).toInt(); updateReleaseChannel = settings->value("personal/updatereleasechannel", 0).toInt();
lang = settings->value("personal/lang").toString(); lang = settings->value("personal/lang").toString();
@ -275,6 +276,7 @@ SettingsCache::SettingsCache()
spectatorsCanSeeEverything = settings->value("game/spectatorscanseeeverything", false).toBool(); spectatorsCanSeeEverything = settings->value("game/spectatorscanseeeverything", false).toBool();
rememberGameSettings = settings->value("game/remembergamesettings", true).toBool(); rememberGameSettings = settings->value("game/remembergamesettings", true).toBool();
clientID = settings->value("personal/clientid", "notset").toString(); clientID = settings->value("personal/clientid", "notset").toString();
clientVersion = settings->value("personal/clientversion", "notset").toString();
knownMissingFeatures = settings->value("interface/knownmissingfeatures", "").toString(); knownMissingFeatures = settings->value("interface/knownmissingfeatures", "").toString();
} }
@ -589,6 +591,12 @@ void SettingsCache::setClientID(QString _clientID)
settings->setValue("personal/clientid", clientID); settings->setValue("personal/clientid", clientID);
} }
void SettingsCache::setClientVersion(QString _clientVersion)
{
clientVersion = std::move(_clientVersion);
settings->setValue("personal/clientversion", clientVersion);
}
QStringList SettingsCache::getCountries() const QStringList SettingsCache::getCountries() const
{ {
static QStringList countries = QStringList() << "ad" static QStringList countries = QStringList() << "ad"
@ -910,6 +918,12 @@ void SettingsCache::setNotifyAboutUpdate(int _notifyaboutupdate)
settings->setValue("personal/updatenotification", notifyAboutUpdates); settings->setValue("personal/updatenotification", notifyAboutUpdates);
} }
void SettingsCache::setNotifyAboutNewVersion(int _notifyaboutnewversion)
{
notifyAboutNewVersion = static_cast<bool>(_notifyaboutnewversion);
settings->setValue("personal/newversionnotification", notifyAboutNewVersion);
}
void SettingsCache::setDownloadSpoilerStatus(bool _spoilerStatus) void SettingsCache::setDownloadSpoilerStatus(bool _spoilerStatus)
{ {
mbDownloadSpoilers = _spoilerStatus; mbDownloadSpoilers = _spoilerStatus;

View file

@ -66,6 +66,7 @@ private:
QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath, QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath,
spoilerDatabasePath, tokenDatabasePath, themeName; spoilerDatabasePath, tokenDatabasePath, themeName;
bool notifyAboutUpdates; bool notifyAboutUpdates;
bool notifyAboutNewVersion;
bool showTipsOnStartup; bool showTipsOnStartup;
QList<int> seenTips; QList<int> seenTips;
bool mbDownloadSpoilers; bool mbDownloadSpoilers;
@ -97,6 +98,7 @@ private:
QString picUrl; QString picUrl;
QString picUrlFallback; QString picUrlFallback;
QString clientID; QString clientID;
QString clientVersion;
QString knownMissingFeatures; QString knownMissingFeatures;
int pixmapCacheSize; int pixmapCacheSize;
bool scaleCards; bool scaleCards;
@ -200,6 +202,10 @@ public:
{ {
return notifyAboutUpdates; return notifyAboutUpdates;
} }
bool getNotifyAboutNewVersion() const
{
return notifyAboutNewVersion;
}
bool getShowTipsOnStartup() const bool getShowTipsOnStartup() const
{ {
return showTipsOnStartup; return showTipsOnStartup;
@ -387,11 +393,16 @@ public:
return maxFontSize; return maxFontSize;
} }
void setClientID(QString clientID); void setClientID(QString clientID);
void setClientVersion(QString clientVersion);
void setKnownMissingFeatures(QString _knownMissingFeatures); void setKnownMissingFeatures(QString _knownMissingFeatures);
QString getClientID() QString getClientID()
{ {
return clientID; return clientID;
} }
QString getClientVersion()
{
return clientVersion;
}
QString getKnownMissingFeatures() QString getKnownMissingFeatures()
{ {
return knownMissingFeatures; return knownMissingFeatures;
@ -492,6 +503,7 @@ public slots:
void setSpectatorsCanSeeEverything(const bool _spectatorsCanSeeEverything); void setSpectatorsCanSeeEverything(const bool _spectatorsCanSeeEverything);
void setRememberGameSettings(const bool _rememberGameSettings); void setRememberGameSettings(const bool _rememberGameSettings);
void setNotifyAboutUpdate(int _notifyaboutupdate); void setNotifyAboutUpdate(int _notifyaboutupdate);
void setNotifyAboutNewVersion(int _notifyaboutnewversion);
void setUpdateReleaseChannel(int _updateReleaseChannel); void setUpdateReleaseChannel(int _updateReleaseChannel);
void setMaxFontSize(int _max); void setMaxFontSize(int _max);
}; };

View file

@ -317,9 +317,9 @@ void MainWindow::actAbout()
void MainWindow::actTips() void MainWindow::actTips()
{ {
if (tip != NULL) { if (tip != nullptr) {
delete tip; delete tip;
tip = NULL; tip = nullptr;
} }
tip = new DlgTipOfTheDay(); tip = new DlgTipOfTheDay();
if (tip->successfulInit) { if (tip->successfulInit) {
@ -828,13 +828,30 @@ MainWindow::MainWindow(QWidget *parent)
if (tip->successfulInit && settingsCache->getShowTipsOnStartup() && tip->newTipsAvailable) { if (tip->successfulInit && settingsCache->getShowTipsOnStartup() && tip->newTipsAvailable) {
tip->show(); tip->show();
} }
// Only run the check updater if the user wants it (defaults to on)
if (settingsCache->getNotifyAboutNewVersion()) {
auto versionUpdater = new MainUpdateHelper();
connect(versionUpdater, SIGNAL(newVersionDetected(QString)), this, SLOT(alertForcedOracleRun(QString)));
QtConcurrent::run(versionUpdater, &MainUpdateHelper::testForNewVersion);
}
}
void MainWindow::alertForcedOracleRun(const QString &newVersion)
{
settingsCache->setClientVersion(newVersion);
QMessageBox::information(this, tr("New Version"),
tr("Congratulations on updating to Cockatrice %1!\n"
"Oracle will now launch to update your card database.")
.arg(newVersion));
actCheckCardUpdates();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
if (tip != NULL) { if (tip != nullptr) {
delete tip; delete tip;
tip = NULL; tip = nullptr;
} }
if (trayIcon) { if (trayIcon) {
trayIcon->hide(); trayIcon->hide();
@ -1271,3 +1288,10 @@ void MainWindow::promptForgotPasswordReset()
dlg.getPlayerName(), dlg.getToken(), dlg.getPassword()); dlg.getPlayerName(), dlg.getToken(), dlg.getPassword());
} }
} }
void MainUpdateHelper::testForNewVersion()
{
if (settingsCache->getClientVersion() != VERSION_STRING) {
emit newVersionDetected(VERSION_STRING);
}
}

View file

@ -101,6 +101,8 @@ private slots:
void actManageSets(); void actManageSets();
void actEditTokens(); void actEditTokens();
void alertForcedOracleRun(const QString &);
private: private:
static const QString appName; static const QString appName;
static const QStringList fileNameFilters; static const QStringList fileNameFilters;
@ -146,4 +148,17 @@ protected:
QString extractInvalidUsernameMessage(QString &in); QString extractInvalidUsernameMessage(QString &in);
}; };
class MainUpdateHelper : public QObject
{
Q_OBJECT
signals:
void newVersionDetected(QString);
public:
explicit MainUpdateHelper() = default;
~MainUpdateHelper() override = default;
void testForNewVersion();
};
#endif #endif