From afed3853a5269ab3cfee1fca386c9a08810c62c7 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Fri, 23 Jan 2026 23:14:46 -0800 Subject: [PATCH] extract warning message to separate file --- cockatrice/CMakeLists.txt | 1 + .../widgets/dialogs/dlg_settings.cpp | 28 ++------------ .../dialogs/override_printing_warning.cpp | 38 +++++++++++++++++++ .../dialogs/override_printing_warning.h | 20 ++++++++++ 4 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 cockatrice/src/interface/widgets/dialogs/override_printing_warning.cpp create mode 100644 cockatrice/src/interface/widgets/dialogs/override_printing_warning.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 54e61ed77..6f3ab38a4 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -47,6 +47,7 @@ set(cockatrice_SOURCES src/interface/widgets/dialogs/dlg_tip_of_the_day.cpp src/interface/widgets/dialogs/dlg_update.cpp src/interface/widgets/dialogs/dlg_view_log.cpp + src/interface/widgets/dialogs/override_printing_warning.cpp src/interface/widgets/dialogs/tip_of_the_day.cpp src/filters/deck_filter_string.cpp src/filters/filter_builder.cpp diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp index e97ca8921..e7286f078 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp @@ -13,6 +13,7 @@ #include "../interface/widgets/utility/get_text_with_max.h" #include "../interface/widgets/utility/sequence_edit.h" #include "../main.h" +#include "override_printing_warning.h" #include <../../client/settings/card_counter_settings.h> #include @@ -680,32 +681,9 @@ void AppearanceSettingsPage::overrideAllCardArtWithPersonalPreferenceToggled(QT_ { bool enable = static_cast(value); - QString message; - if (enable) { - message = tr("Enabling this feature will disable the use of the Printing Selector.\n\n" - "You will not be able to manage printing preferences on a per-deck basis, " - "or see printings other people have selected for their decks.\n\n" - "You will have to use the Set Manager, available through Card Database -> Manage Sets.\n\n" - "Are you sure you would like to enable this feature?"); - } else { - message = - tr("Disabling this feature will enable the Printing Selector.\n\n" - "You can now choose printings on a per-deck basis in the Deck Editor and configure which printing " - "gets added to a deck by default by pinning it in the Printing Selector.\n\n" - "You can also use the Set Manager to adjust custom sort order for printings in the Printing Selector" - " (other sort orders like alphabetical or release date are available).\n\n" - "Are you sure you would like to disable this feature?"); - } + bool accepted = OverridePrintingWarning::execMessageBox(this, enable); - QMessageBox::StandardButton result = - QMessageBox::question(this, tr("Confirm Change"), message, QMessageBox::Yes | QMessageBox::No); - - if (result == QMessageBox::Yes) { - SettingsCache::instance().setOverrideAllCardArtWithPersonalPreference(value); - // Caches are now invalid. - CardPictureLoader::clearPixmapCache(); - CardPictureLoader::clearNetworkCache(); - } else { + if (!accepted) { // If user cancels, revert the checkbox/state back QTimer::singleShot(0, this, [this, enable]() { overrideAllCardArtWithPersonalPreferenceCheckBox.blockSignals(true); diff --git a/cockatrice/src/interface/widgets/dialogs/override_printing_warning.cpp b/cockatrice/src/interface/widgets/dialogs/override_printing_warning.cpp new file mode 100644 index 000000000..d7699fbe4 --- /dev/null +++ b/cockatrice/src/interface/widgets/dialogs/override_printing_warning.cpp @@ -0,0 +1,38 @@ +#include "override_printing_warning.h" + +#include "../../card_picture_loader/card_picture_loader.h" +#include "../../client/settings/cache_settings.h" + +bool OverridePrintingWarning::execMessageBox(QWidget *parent, bool enable) +{ + QString message; + if (enable) { + message = + QObject::tr("Enabling this feature will disable the use of the Printing Selector.\n\n" + "You will not be able to manage printing preferences on a per-deck basis, " + "or see printings other people have selected for their decks.\n\n" + "You will have to use the Set Manager, available through Card Database -> Manage Sets.\n\n" + "Are you sure you would like to enable this feature?"); + } else { + message = QObject::tr( + "Disabling this feature will enable the Printing Selector.\n\n" + "You can now choose printings on a per-deck basis in the Deck Editor and configure which printing " + "gets added to a deck by default by pinning it in the Printing Selector.\n\n" + "You can also use the Set Manager to adjust custom sort order for printings in the Printing Selector" + " (other sort orders like alphabetical or release date are available).\n\n" + "Are you sure you would like to disable this feature?"); + } + + QMessageBox::StandardButton result = + QMessageBox::question(parent, QObject::tr("Confirm Change"), message, QMessageBox::Yes | QMessageBox::No); + + if (result == QMessageBox::Yes) { + SettingsCache::instance().setOverrideAllCardArtWithPersonalPreference(static_cast(enable)); + // Caches are now invalid. + CardPictureLoader::clearPixmapCache(); + CardPictureLoader::clearNetworkCache(); + return true; + } + + return false; +} \ No newline at end of file diff --git a/cockatrice/src/interface/widgets/dialogs/override_printing_warning.h b/cockatrice/src/interface/widgets/dialogs/override_printing_warning.h new file mode 100644 index 000000000..f2c926fc3 --- /dev/null +++ b/cockatrice/src/interface/widgets/dialogs/override_printing_warning.h @@ -0,0 +1,20 @@ +#ifndef COCKATRICE_OVERRIDE_PRINTING_WARN_H +#define COCKATRICE_OVERRIDE_PRINTING_WARN_H +#include + +namespace OverridePrintingWarning +{ + +/** + * @brief Pops up the warning message for the changing the override printing setting. + * If the user clicks accept, then this also handles changing the setting and resetting the card image cache. + * + * @param parent The parent widget + * @param enable Whether the user is trying to enable or disable the setting + * @return Whether the user clicked accept. All other ways of closing the window returns false. + */ +bool execMessageBox(QWidget *parent, bool enable); + +} // namespace OverridePrintingWarning + +#endif // COCKATRICE_OVERRIDE_PRINTING_WARN_H