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

@ -52,6 +52,13 @@
#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"
enum startupCardUpdateCheckBehaviorIndex
{
startupCardUpdateCheckBehaviorIndexNone,
startupCardUpdateCheckBehaviorIndexPrompt,
startupCardUpdateCheckBehaviorIndexAlways
};
GeneralSettingsPage::GeneralSettingsPage()
{
QStringList languageCodes = findQmFiles();
@ -71,7 +78,17 @@ GeneralSettingsPage::GeneralSettingsPage()
// updates
SettingsCache &settings = SettingsCache::instance();
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.setMaximum(30);
cardUpdateCheckIntervalSpinBox.setValue(settings.getCardUpdateCheckInterval());
@ -87,8 +104,13 @@ GeneralSettingsPage::GeneralSettingsPage()
&GeneralSettingsPage::languageBoxChanged);
connect(&startupUpdateCheckCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings,
&SettingsCache::setCheckUpdatesOnStartup);
connect(&startupCardUpdateCheckCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings,
&SettingsCache::setCheckCardUpdatesOnStartup);
connect(&startupCardUpdateCheckBehaviorSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[](int index) {
SettingsCache::instance().setStartupCardUpdateCheckPromptForUpdate(
index == startupCardUpdateCheckBehaviorIndexPrompt);
SettingsCache::instance().setStartupCardUpdateCheckAlwaysUpdate(
index == startupCardUpdateCheckBehaviorIndexAlways);
});
connect(&cardUpdateCheckIntervalSpinBox, qOverload<int>(&QSpinBox::valueChanged), &settings,
&SettingsCache::setCardUpdateCheckInterval);
connect(&updateNotificationCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, &SettingsCache::setNotifyAboutUpdate);
@ -103,7 +125,7 @@ GeneralSettingsPage::GeneralSettingsPage()
personalGrid->addWidget(&updateReleaseChannelLabel, 2, 0);
personalGrid->addWidget(&updateReleaseChannelBox, 2, 1);
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(&cardUpdateCheckIntervalSpinBox, 6, 1);
personalGrid->addWidget(&lastCardUpdateCheckDateLabel, 7, 1);
@ -353,7 +375,11 @@ void GeneralSettingsPage::retranslateUi()
tokenDatabasePathLabel.setText(tr("Token database:"));
updateReleaseChannelLabel.setText(tr("Update channel"));
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"));
cardUpdateCheckIntervalSpinBox.setSuffix(tr(" days"));
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;
QComboBox languageBox;
QCheckBox startupUpdateCheckCheckBox;
QCheckBox startupCardUpdateCheckCheckBox;
QComboBox startupCardUpdateCheckBehaviorSelector;
QLabel cardUpdateCheckIntervalLabel;
QSpinBox cardUpdateCheckIntervalSpinBox;
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