Change to a prompt instead.

This commit is contained in:
Lukas Brübach 2025-06-28 16:12:28 +02:00
parent 18c2155714
commit f10bfa31da
10 changed files with 166 additions and 16 deletions

View file

@ -172,6 +172,7 @@ set(cockatrice_SOURCES
src/dialogs/dlg_roll_dice.cpp src/dialogs/dlg_roll_dice.cpp
src/dialogs/dlg_select_set_for_cards.cpp src/dialogs/dlg_select_set_for_cards.cpp
src/dialogs/dlg_settings.cpp src/dialogs/dlg_settings.cpp
src/dialogs/dlg_startup_card_check.cpp
src/dialogs/dlg_tip_of_the_day.cpp src/dialogs/dlg_tip_of_the_day.cpp
src/dialogs/dlg_update.cpp src/dialogs/dlg_update.cpp
src/dialogs/dlg_view_log.cpp src/dialogs/dlg_view_log.cpp

View file

@ -27,6 +27,7 @@
#include "../../dialogs/dlg_manage_sets.h" #include "../../dialogs/dlg_manage_sets.h"
#include "../../dialogs/dlg_register.h" #include "../../dialogs/dlg_register.h"
#include "../../dialogs/dlg_settings.h" #include "../../dialogs/dlg_settings.h"
#include "../../dialogs/dlg_startup_card_check.h"
#include "../../dialogs/dlg_tip_of_the_day.h" #include "../../dialogs/dlg_tip_of_the_day.h"
#include "../../dialogs/dlg_update.h" #include "../../dialogs/dlg_update.h"
#include "../../dialogs/dlg_view_log.h" #include "../../dialogs/dlg_view_log.h"
@ -62,6 +63,7 @@
#include <QMenuBar> #include <QMenuBar>
#include <QMessageBox> #include <QMessageBox>
#include <QPixmapCache> #include <QPixmapCache>
#include <QRadioButton>
#include <QStatusBar> #include <QStatusBar>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QThread> #include <QThread>
@ -69,6 +71,7 @@
#include <QWindow> #include <QWindow>
#include <QtConcurrent> #include <QtConcurrent>
#include <QtNetwork> #include <QtNetwork>
#include <qbuttongroup.h>
#define GITHUB_PAGES_URL "https://cockatrice.github.io" #define GITHUB_PAGES_URL "https://cockatrice.github.io"
#define GITHUB_CONTRIBUTORS_URL "https://github.com/Cockatrice/Cockatrice/graphs/contributors?type=c" #define GITHUB_CONTRIBUTORS_URL "https://github.com/Cockatrice/Cockatrice/graphs/contributors?type=c"
@ -949,7 +952,33 @@ void MainWindow::startupConfigCheck()
qCInfo(WindowMainStartupVersionLog) << "Startup: found config with current version"; qCInfo(WindowMainStartupVersionLog) << "Startup: found config with current version";
if (SettingsCache::instance().getCardUpdateCheckRequired()) { if (SettingsCache::instance().getCardUpdateCheckRequired()) {
if (SettingsCache::instance().getStartupCardUpdateCheckPromptForUpdate()) {
auto startupCardCheckDialog = new DlgStartupCardCheck(this);
if (startupCardCheckDialog->exec() == QDialog::Accepted) {
switch (startupCardCheckDialog->group->checkedId()) {
case 0: // foreground
actCheckCardUpdates();
break;
case 1: // background
actCheckCardUpdatesBackground(); actCheckCardUpdatesBackground();
break;
case 2: // background + always
SettingsCache::instance().setStartupCardUpdateCheckPromptForUpdate(false);
SettingsCache::instance().setStartupCardUpdateCheckAlwaysUpdate(true);
actCheckCardUpdatesBackground();
break;
case 3: // don't prompt again + don't run
SettingsCache::instance().setStartupCardUpdateCheckPromptForUpdate(false);
SettingsCache::instance().setStartupCardUpdateCheckAlwaysUpdate(false);
break;
default:
break;
}
}
} else if (SettingsCache::instance().getStartupCardUpdateCheckAlwaysUpdate()) {
actCheckCardUpdatesBackground();
}
} }
const auto reloadOk1 = QtConcurrent::run([] { CardDatabaseManager::getInstance()->loadCardDatabases(); }); const auto reloadOk1 = QtConcurrent::run([] { CardDatabaseManager::getInstance()->loadCardDatabases(); });

View file

@ -52,6 +52,13 @@
#define WIKI_CUSTOM_SHORTCUTS "https://github.com/Cockatrice/Cockatrice/wiki/Custom-Keyboard-Shortcuts" #define WIKI_CUSTOM_SHORTCUTS "https://github.com/Cockatrice/Cockatrice/wiki/Custom-Keyboard-Shortcuts"
#define WIKI_TRANSLATION_FAQ "https://github.com/Cockatrice/Cockatrice/wiki/Translation-FAQ" #define WIKI_TRANSLATION_FAQ "https://github.com/Cockatrice/Cockatrice/wiki/Translation-FAQ"
enum startupCardUpdateCheckBehaviorIndex
{
startupCardUpdateCheckBehaviorIndexNone,
startupCardUpdateCheckBehaviorIndexPrompt,
startupCardUpdateCheckBehaviorIndexAlways
};
GeneralSettingsPage::GeneralSettingsPage() GeneralSettingsPage::GeneralSettingsPage()
{ {
QStringList languageCodes = findQmFiles(); QStringList languageCodes = findQmFiles();
@ -71,7 +78,17 @@ GeneralSettingsPage::GeneralSettingsPage()
// updates // updates
SettingsCache &settings = SettingsCache::instance(); SettingsCache &settings = SettingsCache::instance();
startupUpdateCheckCheckBox.setChecked(settings.getCheckUpdatesOnStartup()); startupUpdateCheckCheckBox.setChecked(settings.getCheckUpdatesOnStartup());
startupCardUpdateCheckCheckBox.setChecked(settings.getCheckCardUpdatesOnStartup()); startupCardUpdateCheckBehaviorSelector.addItem(""); // these will be set in retranslateUI
startupCardUpdateCheckBehaviorSelector.addItem("");
startupCardUpdateCheckBehaviorSelector.addItem("");
if (SettingsCache::instance().getStartupCardUpdateCheckPromptForUpdate()) {
startupCardUpdateCheckBehaviorSelector.setCurrentIndex(startupCardUpdateCheckBehaviorIndexPrompt);
} else if (SettingsCache::instance().getStartupCardUpdateCheckAlwaysUpdate()) {
startupCardUpdateCheckBehaviorSelector.setCurrentIndex(startupCardUpdateCheckBehaviorIndexAlways);
} else {
startupCardUpdateCheckBehaviorSelector.setCurrentIndex(startupCardUpdateCheckBehaviorIndexNone);
}
cardUpdateCheckIntervalSpinBox.setMinimum(1); cardUpdateCheckIntervalSpinBox.setMinimum(1);
cardUpdateCheckIntervalSpinBox.setMaximum(30); cardUpdateCheckIntervalSpinBox.setMaximum(30);
cardUpdateCheckIntervalSpinBox.setValue(settings.getCardUpdateCheckInterval()); cardUpdateCheckIntervalSpinBox.setValue(settings.getCardUpdateCheckInterval());
@ -87,8 +104,13 @@ GeneralSettingsPage::GeneralSettingsPage()
&GeneralSettingsPage::languageBoxChanged); &GeneralSettingsPage::languageBoxChanged);
connect(&startupUpdateCheckCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, connect(&startupUpdateCheckCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings,
&SettingsCache::setCheckUpdatesOnStartup); &SettingsCache::setCheckUpdatesOnStartup);
connect(&startupCardUpdateCheckCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, connect(&startupCardUpdateCheckBehaviorSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&SettingsCache::setCheckCardUpdatesOnStartup); [](int index) {
SettingsCache::instance().setStartupCardUpdateCheckPromptForUpdate(
index == startupCardUpdateCheckBehaviorIndexPrompt);
SettingsCache::instance().setStartupCardUpdateCheckAlwaysUpdate(
index == startupCardUpdateCheckBehaviorIndexAlways);
});
connect(&cardUpdateCheckIntervalSpinBox, qOverload<int>(&QSpinBox::valueChanged), &settings, connect(&cardUpdateCheckIntervalSpinBox, qOverload<int>(&QSpinBox::valueChanged), &settings,
&SettingsCache::setCardUpdateCheckInterval); &SettingsCache::setCardUpdateCheckInterval);
connect(&updateNotificationCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, &SettingsCache::setNotifyAboutUpdate); connect(&updateNotificationCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, &SettingsCache::setNotifyAboutUpdate);
@ -103,7 +125,7 @@ GeneralSettingsPage::GeneralSettingsPage()
personalGrid->addWidget(&updateReleaseChannelLabel, 2, 0); personalGrid->addWidget(&updateReleaseChannelLabel, 2, 0);
personalGrid->addWidget(&updateReleaseChannelBox, 2, 1); personalGrid->addWidget(&updateReleaseChannelBox, 2, 1);
personalGrid->addWidget(&startupUpdateCheckCheckBox, 4, 0, 1, 2); personalGrid->addWidget(&startupUpdateCheckCheckBox, 4, 0, 1, 2);
personalGrid->addWidget(&startupCardUpdateCheckCheckBox, 5, 0, 1, 2); personalGrid->addWidget(&startupCardUpdateCheckBehaviorSelector, 5, 0, 1, 2);
personalGrid->addWidget(&cardUpdateCheckIntervalLabel, 6, 0); personalGrid->addWidget(&cardUpdateCheckIntervalLabel, 6, 0);
personalGrid->addWidget(&cardUpdateCheckIntervalSpinBox, 6, 1); personalGrid->addWidget(&cardUpdateCheckIntervalSpinBox, 6, 1);
personalGrid->addWidget(&lastCardUpdateCheckDateLabel, 7, 1); personalGrid->addWidget(&lastCardUpdateCheckDateLabel, 7, 1);
@ -353,7 +375,11 @@ void GeneralSettingsPage::retranslateUi()
tokenDatabasePathLabel.setText(tr("Token database:")); tokenDatabasePathLabel.setText(tr("Token database:"));
updateReleaseChannelLabel.setText(tr("Update channel")); updateReleaseChannelLabel.setText(tr("Update channel"));
startupUpdateCheckCheckBox.setText(tr("Check for client updates on startup")); startupUpdateCheckCheckBox.setText(tr("Check for client updates on startup"));
startupCardUpdateCheckCheckBox.setText(tr("Automatically update card database in the background on startup")); startupCardUpdateCheckBehaviorSelector.setItemText(startupCardUpdateCheckBehaviorIndexNone, tr("Don't check"));
startupCardUpdateCheckBehaviorSelector.setItemText(startupCardUpdateCheckBehaviorIndexPrompt,
tr("Prompt for update"));
startupCardUpdateCheckBehaviorSelector.setItemText(startupCardUpdateCheckBehaviorIndexAlways,
tr("Always update in the background"));
cardUpdateCheckIntervalLabel.setText(tr("Check for card database updates every")); cardUpdateCheckIntervalLabel.setText(tr("Check for card database updates every"));
cardUpdateCheckIntervalSpinBox.setSuffix(tr(" days")); cardUpdateCheckIntervalSpinBox.setSuffix(tr(" days"));
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"));

View file

@ -71,7 +71,7 @@ private:
QGroupBox *pathsGroupBox; QGroupBox *pathsGroupBox;
QComboBox languageBox; QComboBox languageBox;
QCheckBox startupUpdateCheckCheckBox; QCheckBox startupUpdateCheckCheckBox;
QCheckBox startupCardUpdateCheckCheckBox; QComboBox startupCardUpdateCheckBehaviorSelector;
QLabel cardUpdateCheckIntervalLabel; QLabel cardUpdateCheckIntervalLabel;
QSpinBox cardUpdateCheckIntervalSpinBox; QSpinBox cardUpdateCheckIntervalSpinBox;
QLabel lastCardUpdateCheckDateLabel; QLabel lastCardUpdateCheckDateLabel;

View file

@ -0,0 +1,50 @@
#include "dlg_startup_card_check.h"
#include "../settings/cache_settings.h"
#include <QDate>
DlgStartupCardCheck::DlgStartupCardCheck(QWidget *parent) : QDialog(parent)
{
setWindowTitle(tr("Card Update Check"));
layout = new QVBoxLayout(this);
QDate lastCheckDate = SettingsCache::instance().getLastCardUpdateCheck();
int daysAgo = lastCheckDate.daysTo(QDate::currentDate());
instructionLabel = new QLabel(
tr("It has been more than %2 days since you last checked your card database for updates.\nChoose how you would "
"like to run the card database updater.\nYou can always change this behavior in the 'General' settings tab.")
.arg(daysAgo));
layout->addWidget(instructionLabel);
group = new QButtonGroup(this);
foregroundBtn = new QRadioButton(tr("Run in foreground"));
backgroundBtn = new QRadioButton(tr("Run in background"));
backgroundAlwaysBtn = new QRadioButton(tr("Run in background and always from now on"));
dontPromptBtn = new QRadioButton(tr("Don't prompt again and don't run"));
dontRunBtn = new QRadioButton(tr("Don't run this time"));
group->addButton(foregroundBtn, 0);
group->addButton(backgroundBtn, 1);
group->addButton(backgroundAlwaysBtn, 2);
group->addButton(dontPromptBtn, 3);
group->addButton(dontRunBtn, 4);
foregroundBtn->setChecked(true); // default
layout->addWidget(foregroundBtn);
layout->addWidget(backgroundBtn);
layout->addWidget(backgroundAlwaysBtn);
layout->addWidget(dontPromptBtn);
layout->addWidget(dontRunBtn);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}

View file

@ -0,0 +1,24 @@
#ifndef DLG_STARTUP_CARD_CHECK_H
#define DLG_STARTUP_CARD_CHECK_H
#include <QButtonGroup>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLabel>
#include <QRadioButton>
#include <QVBoxLayout>
class DlgStartupCardCheck : public QDialog
{
Q_OBJECT
public:
explicit DlgStartupCardCheck(QWidget *parent);
QVBoxLayout *layout;
QLabel *instructionLabel;
QButtonGroup *group;
QRadioButton *foregroundBtn, *backgroundBtn, *backgroundAlwaysBtn, *dontPromptBtn, *dontRunBtn;
QDialogButtonBox *buttonBox;
};
#endif // DLG_STARTUP_CARD_CHECK_H

View file

@ -194,7 +194,9 @@ SettingsCache::SettingsCache()
mbDownloadSpoilers = settings->value("personal/downloadspoilers", false).toBool(); mbDownloadSpoilers = settings->value("personal/downloadspoilers", false).toBool();
checkUpdatesOnStartup = settings->value("personal/startupUpdateCheck", true).toBool(); checkUpdatesOnStartup = settings->value("personal/startupUpdateCheck", true).toBool();
checkCardUpdatesOnStartup = settings->value("personal/startupCardUpdateCheck", true).toBool(); startupCardUpdateCheckPromptForUpdate =
settings->value("personal/startupCardUpdateCheckPromptForUpdate", true).toBool();
startupCardUpdateCheckAlwaysUpdate = settings->value("personal/startupCardUpdateCheckAlwaysUpdate", false).toBool();
cardUpdateCheckInterval = settings->value("personal/cardUpdateCheckInterval", 7).toInt(); cardUpdateCheckInterval = settings->value("personal/cardUpdateCheckInterval", 7).toInt();
lastCardUpdateCheck = settings->value("personal/lastCardUpdateCheck", QDateTime::currentDateTime().date()).toDate(); lastCardUpdateCheck = settings->value("personal/lastCardUpdateCheck", QDateTime::currentDateTime().date()).toDate();
notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool(); notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool();
@ -1366,10 +1368,15 @@ void SettingsCache::setCheckUpdatesOnStartup(QT_STATE_CHANGED_T value)
settings->setValue("personal/startupUpdateCheck", checkUpdatesOnStartup); settings->setValue("personal/startupUpdateCheck", checkUpdatesOnStartup);
} }
void SettingsCache::setCheckCardUpdatesOnStartup(QT_STATE_CHANGED_T value) void SettingsCache::setStartupCardUpdateCheckPromptForUpdate(bool value)
{ {
checkCardUpdatesOnStartup = static_cast<bool>(value); startupCardUpdateCheckPromptForUpdate = value;
settings->setValue("personal/startupCardUpdateCheck", checkCardUpdatesOnStartup); settings->setValue("personal/startupCardUpdateCheckPromptForUpdate", startupCardUpdateCheckPromptForUpdate);
}
void SettingsCache::setStartupCardUpdateCheckAlwaysUpdate(bool value)
{
startupCardUpdateCheckAlwaysUpdate = value;
settings->setValue("personal/startupCardUpdateCheckAlwaysUpdate", startupCardUpdateCheckAlwaysUpdate);
} }
void SettingsCache::setCardUpdateCheckInterval(int value) void SettingsCache::setCardUpdateCheckInterval(int value)

View file

@ -199,6 +199,8 @@ private:
bool tabVisualDeckStorageOpen, tabServerOpen, tabAccountOpen, tabDeckStorageOpen, tabReplaysOpen, tabAdminOpen, bool tabVisualDeckStorageOpen, tabServerOpen, tabAccountOpen, tabDeckStorageOpen, tabReplaysOpen, tabAdminOpen,
tabLogOpen; tabLogOpen;
bool checkUpdatesOnStartup; bool checkUpdatesOnStartup;
bool startupCardUpdateCheckPromptForUpdate;
bool startupCardUpdateCheckAlwaysUpdate;
bool checkCardUpdatesOnStartup; bool checkCardUpdatesOnStartup;
int cardUpdateCheckInterval; int cardUpdateCheckInterval;
QDate lastCardUpdateCheck; QDate lastCardUpdateCheck;
@ -442,9 +444,13 @@ public:
{ {
return checkUpdatesOnStartup; return checkUpdatesOnStartup;
} }
bool getCheckCardUpdatesOnStartup() const bool getStartupCardUpdateCheckPromptForUpdate()
{ {
return checkCardUpdatesOnStartup; return startupCardUpdateCheckPromptForUpdate;
}
bool getStartupCardUpdateCheckAlwaysUpdate()
{
return startupCardUpdateCheckAlwaysUpdate;
} }
int getCardUpdateCheckInterval() const int getCardUpdateCheckInterval() const
{ {
@ -1028,7 +1034,8 @@ public slots:
void setDefaultStartingLifeTotal(const int _defaultStartingLifeTotal); void setDefaultStartingLifeTotal(const int _defaultStartingLifeTotal);
void setRememberGameSettings(const bool _rememberGameSettings); void setRememberGameSettings(const bool _rememberGameSettings);
void setCheckUpdatesOnStartup(QT_STATE_CHANGED_T value); void setCheckUpdatesOnStartup(QT_STATE_CHANGED_T value);
void setCheckCardUpdatesOnStartup(QT_STATE_CHANGED_T value); void setStartupCardUpdateCheckPromptForUpdate(bool value);
void setStartupCardUpdateCheckAlwaysUpdate(bool value);
void setCardUpdateCheckInterval(int value); void setCardUpdateCheckInterval(int value);
void setLastCardUpdateCheck(QDate value); void setLastCardUpdateCheck(QDate value);
void setNotifyAboutUpdate(QT_STATE_CHANGED_T _notifyaboutupdate); void setNotifyAboutUpdate(QT_STATE_CHANGED_T _notifyaboutupdate);

View file

@ -408,7 +408,10 @@ void SettingsCache::setRememberGameSettings(const bool /* _rememberGameSettings
void SettingsCache::setCheckUpdatesOnStartup(QT_STATE_CHANGED_T /* value */) void SettingsCache::setCheckUpdatesOnStartup(QT_STATE_CHANGED_T /* value */)
{ {
} }
void SettingsCache::setCheckCardUpdatesOnStartup(QT_STATE_CHANGED_T /* value */) void SettingsCache::setStartupCardUpdateCheckPromptForUpdate(bool /* value */)
{
}
void SettingsCache::setStartupCardUpdateCheckAlwaysUpdate(bool /* value */)
{ {
} }
void SettingsCache::setCardUpdateCheckInterval(int /* value */) void SettingsCache::setCardUpdateCheckInterval(int /* value */)

View file

@ -412,7 +412,10 @@ void SettingsCache::setRememberGameSettings(const bool /* _rememberGameSettings
void SettingsCache::setCheckUpdatesOnStartup(QT_STATE_CHANGED_T /* value */) void SettingsCache::setCheckUpdatesOnStartup(QT_STATE_CHANGED_T /* value */)
{ {
} }
void SettingsCache::setCheckCardUpdatesOnStartup(QT_STATE_CHANGED_T /* value */) void SettingsCache::setStartupCardUpdateCheckPromptForUpdate(bool /* value */)
{
}
void SettingsCache::setStartupCardUpdateCheckAlwaysUpdate(bool /* value */)
{ {
} }
void SettingsCache::setCardUpdateCheckInterval(int /* value */) void SettingsCache::setCardUpdateCheckInterval(int /* value */)