From 9e084614c0316dab64c5c3baa30d22c1f854fd1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Mon, 3 Aug 2026 12:56:21 +0200 Subject: [PATCH] Comments and fixes Took 9 seconds Took 1 minute --- .../widgets/dialogs/dlg_register.cpp | 22 +++++++++ .../onboarding/pages/theme_setup_page.cpp | 45 +++++++++++++++---- .../onboarding/pages/theme_setup_page.h | 7 ++- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_register.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_register.cpp index 0e338eed7..6ae8c9adb 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_register.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_register.cpp @@ -480,6 +480,10 @@ void DlgRegister::newHostSelected(bool state) portEdit->setPlaceholderText(tr("Communication Port")); playernameEdit->setDisabled(false); playernameEdit->clear(); + } else { + // Rebuild the list so the previously selected host's details are + // repopulated (mirrors DlgConnect::newHostSelected). + preRebuildComboBoxList(); } } @@ -519,6 +523,24 @@ void DlgRegister::actOk() return; } + ServersSettings &servers = SettingsCache::instance().servers(); + + if (newHostButton->isChecked()) { + // Persist the new host so it shows up in the Connect dialog later. + // The password is never stored: the account is not verified yet. + const QString host = hostEdit->text().trimmed(); + if (!host.isEmpty()) { + servers.addNewServer(host, host, portEdit->text().trimmed(), playernameEdit->text().trimmed(), QString(), + false); + servers.setPrevioushostName(host); + } + } else { + const QString saveName = previousHosts->currentText(); + if (!saveName.isEmpty() && saveName != placeHolderText) { + servers.setPrevioushostName(saveName); + } + } + accept(); } diff --git a/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.cpp b/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.cpp index 9baa3f1f3..a775d6d19 100644 --- a/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.cpp +++ b/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.cpp @@ -7,10 +7,14 @@ #include "../../interface/widgets/general/background_sources.h" #include +#include +#include #include #include #include +#include #include +#include #include ThemeSetupPage::ThemeSetupPage(QWidget *parent) : FirstRunWizardPage(parent) @@ -96,8 +100,10 @@ void ThemeSetupPage::initializePage() homeTabBackgroundCombo->setCurrentIndex(homeTabIdx >= 0 ? homeTabIdx : 0); homeTabBackgroundCombo->blockSignals(false); + // Opening the page must not touch the running application's palette: + // previews and auto-generation only happen in response to the user + // actually changing a control, never on mere page visibility. paletteDirty = false; - maybeAutoGeneratePalette(); } QString ThemeSetupPage::currentScheme() const @@ -156,11 +162,12 @@ void ThemeSetupPage::maybeAutoGeneratePalette() return; // theme already has something real to show -- leave it alone } - // Nothing saved, nothing shipped. Rather than showing flat native Qt - // colours during the very first thing a new user sees, seed one from - // whatever accent QuickSetupPanel currently holds (its own built-in - // default the first time through), and mark it dirty so it's written to - // disk if the user moves on without touching the accent controls. + // The theme+scheme combination has nothing saved and nothing shipped, and + // the user just switched to it. Rather than leaving a flat, unstyled look, + // seed one from whatever accent QuickSetupPanel currently holds and mark + // it dirty so it's written to disk if the user moves on. Only ever reached + // through user interaction (theme/scheme change, accent drag) -- never on + // page open. PaletteConfig generated = PaletteGenerator::fromAccent(quickSetupPanel->accentColor(), quickSetupPanel->intensity(), scheme); themeManager->previewPalette(generated, scheme); @@ -170,16 +177,38 @@ void ThemeSetupPage::maybeAutoGeneratePalette() bool ThemeSetupPage::validatePage() { if (paletteDirty) { - const QString dirPath = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName()); const QString scheme = resolvedScheme(); PaletteConfig cfg = PaletteGenerator::fromAccent(quickSetupPanel->accentColor(), quickSetupPanel->intensity(), scheme); - ThemeManager::commitPalette(dirPath, scheme, cfg); + if (!ThemeManager::commitPalette(writableThemeDir(), scheme, cfg)) { + QMessageBox::warning(this, tr("Save failed"), + tr("Could not write the theme palette to:\n%1").arg(writableThemeDir())); + return false; + } themeManager->reloadCurrentTheme(); } return true; } +QString ThemeSetupPage::writableThemeDir() const +{ + // Built-in themes resolve to the read-only system themes directory; + // palette edits must go to the user themes directory instead, exactly + // as PaletteEditorDialog does. + const QString dirPath = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName()); + if (!dirPath.isEmpty()) { + const QString probe = QDir(dirPath).absoluteFilePath(".cockatrice_write_test"); + QFile f(probe); + if (f.open(QIODevice::WriteOnly)) { + f.close(); + f.remove(); + return dirPath; + } + } + return QDir(SettingsCache::instance().paths().getThemesPath()) + .absoluteFilePath(SettingsCache::instance().getThemeName()); +} + bool ThemeSetupPage::isSkippable() const { return true; diff --git a/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.h b/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.h index f0b336510..d1f84c1b9 100644 --- a/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.h +++ b/cockatrice/src/interface/widgets/onboarding/pages/theme_setup_page.h @@ -14,9 +14,11 @@ class QuickSetupPanel; * * Behavior specific to this page (deliberately not pushed down into * ThemeManager, to avoid changing app-wide behaviour for existing installs): - * - If the selected theme+scheme has no saved palette and no shipped + * - Opening the page never changes the running palette; previews and + * auto-generation only happen when the user actually changes a control. + * - If a theme+scheme the user selects has no saved palette and no shipped * default, one is generated from the QuickSetupPanel's current accent so - * onboarding never shows a flat, unstyled look. */ + * the preview doesn't fall back to a flat, unstyled look. */ class ThemeSetupPage : public FirstRunWizardPage { Q_OBJECT @@ -41,6 +43,7 @@ private: QString currentScheme() const; QString resolvedScheme() const; // "System" -> actual Light/Dark void maybeAutoGeneratePalette(); + QString writableThemeDir() const; QComboBox *themeCombo; QComboBox *schemeCombo;