mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
* [Client] Show localized card names, texts and pictures
Localization wiring now runs end to end: the oracle importer collects
foreignData for the configured language and the client renders it.
- [Oracle] Import localized names and rules texts for the selected cardLang
- single-face cards store their foreignData name and full text
- multi-face (split/adventure/aftermath/prepare) cards collect the joined
name once and join each face's translated text with the same separator
as the English merge; an incomplete translation falls back to English;
the joined text follows the same highest-priority-set policy as the
single-face path and is only collected when localization is enabled
- the wizard switching languages re-imports the card database
- [Client] Display localized card info throughout the client
- card info text/picture widgets and the game board re-render on language
change
- pictures resolve cardLang art through Scryfall's named endpoint using the
localized name, falling back to id-based art when no match exists
- deck editor keeps canonical English names as card identity (EditRole)
while showing localized names (DisplayRole), so decks and wire names
stay stable
- [Card] Add CardLocalization-backed name/text lookup and cards.xml v4
localization elements with a bounded-size translation cache
- [Tests] Cover oracle foreignData import (incl. multi-face joins, priority
and fallback paths), XML v4 localization parsing, deck model localized
display and the language-aware settings default
Existing installations need to re-run Oracle to see translations: localized
data only lands in cards.xml when the Oracle app is started with the
preferred language selected — launch the separate "Oracle" program that
ships with Cockatrice, pick the language in the wizard and let it re-import
the card database.
The client's database cache (cards.xml.cache) is invalidated by the cache
format bump and the source-hash checks, but a cache written before the
re-import can still hold English-only entries (the hash uses file size and
mtime, so a same-size/same-timestamp rewrite may be served as-is); delete
cards.xml.cache and relaunch if no localized names/texts show up after
re-importing.
* [Card] Pass localized card names and texts into CardInfo construction
Address review: instead of constructing the card and then calling
setLocalizedName/setLocalizedText (which emit a cardInfoChanged signal per
language), both constructors, both newInstance overloads and their callers
(cards.xml v4 parser and the binary cache reader) now pass the localized maps
as constructor arguments.
* [Client] Rename LocalizedCard:: helpers namespace to CardLocalization
The namespace now matches its header file name, as the review pointed out;
LocalizedCard reads more like a class or struct. Callers (card info text
widget, board card name rendering) are updated to match.
* [Client] Drop unused info member from the card info text widget
The CardInfoPtr member was only ever initialized to nullptr and never read;
remove it together with its initializer.
* [PictureLoader] Add the localized picture URL explicitly, not implicitly
Address review: silently prepending the Scryfall named-picture URL to the
download list whenever a non-English card language was active was surprising,
consumed quota per card when it failed, and could grab the wrong (canon) art on
name collisions, with no way to turn it off.
The insert is now opt-in and user-controlled: changing the card language adds
the template to the top of the download URLs once (persisted, documented in the
re-import prompt, and editable/removable in the deck editor settings), while the
picture loader no longer injects it at request time.
* [Card] Show card languages in the same native (English) format as the UI
Address review: the card text & images language dropdown listed bare native
names, some in inconsistent lowercase (e.g. "čeština", "español de España"),
which makes the languages easy to mix up for users that do not read the script
(e.g. 日本語 vs 한국어). It now mirrors the UI language dropdown and always pairs
the native name with its English name (e.g. "Deutsch (German)",
"日本語 (Japanese)"), using the same fixed casing.
---------
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
574 lines
20 KiB
C++
574 lines
20 KiB
C++
/**
|
|
* @file dlg_settings.cpp
|
|
* @brief Implementation of the main settings dialog
|
|
* @ingroup Dialogs
|
|
*/
|
|
#include "dlg_settings.h"
|
|
|
|
#include "../../../client/settings/cache_settings.h"
|
|
#include "../../pixel_map_generator.h"
|
|
#include "../main.h"
|
|
#include "../settings_page/appearance_settings_page.h"
|
|
#include "../settings_page/deck_editor_settings_page.h"
|
|
#include "../settings_page/general_settings_page.h"
|
|
#include "../settings_page/messages_settings_page.h"
|
|
#include "../settings_page/settings_search_delegate.h"
|
|
#include "../settings_page/settings_search_model.h"
|
|
#include "../settings_page/shortcut_settings_page.h"
|
|
#include "../settings_page/sound_settings_page.h"
|
|
#include "../settings_page/storage_settings_page.h"
|
|
#include "../settings_page/user_interface_settings_page.h"
|
|
#include "libcockatrice/card/database/card_database_loader.h"
|
|
#include "libcockatrice/card/database/card_database_manager.h"
|
|
|
|
#include <QAbstractItemView>
|
|
#include <QCloseEvent>
|
|
#include <QDir>
|
|
#include <QFrame>
|
|
#include <QGraphicsOpacityEffect>
|
|
#include <QGuiApplication>
|
|
#include <QHBoxLayout>
|
|
#include <QKeyEvent>
|
|
#include <QLineEdit>
|
|
#include <QListView>
|
|
#include <QMessageBox>
|
|
#include <QPropertyAnimation>
|
|
#include <QPushButton>
|
|
#include <QScreen>
|
|
#include <QScrollArea>
|
|
#include <QScrollBar>
|
|
#include <QSequentialAnimationGroup>
|
|
#include <QShortcut>
|
|
#include <QStackedLayout>
|
|
#include <QStackedWidget>
|
|
#include <QToolButton>
|
|
#include <QVBoxLayout>
|
|
#include <libcockatrice/settings/paths_settings.h>
|
|
#include <libcockatrice/settings/personal_settings.h>
|
|
|
|
/**
|
|
* @brief Wraps a widget in a scroll area for long settings pages
|
|
* @param widget The widget to wrap
|
|
* @return The scroll area containing the widget
|
|
*/
|
|
static QScrollArea *makeScrollable(QWidget *widget)
|
|
{
|
|
widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Maximum);
|
|
|
|
auto *scrollArea = new QScrollArea;
|
|
scrollArea->setWidgetResizable(true);
|
|
scrollArea->setContentsMargins(0, 0, 0, 0);
|
|
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
scrollArea->horizontalScrollBar()->setEnabled(false);
|
|
scrollArea->setWidget(widget);
|
|
return scrollArea;
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the theme icon resources for each settings page, indexed by SettingsPage order
|
|
*/
|
|
static QStringList pageIconResources()
|
|
{
|
|
return {QStringLiteral("theme:config/general"), QStringLiteral("theme:config/appearance"),
|
|
QStringLiteral("theme:config/interface"), QStringLiteral("theme:config/deckeditor"),
|
|
QStringLiteral("theme:config/storage"), QStringLiteral("theme:config/messages"),
|
|
QStringLiteral("theme:config/sound"), QStringLiteral("theme:config/shorcuts")};
|
|
}
|
|
|
|
DlgSettings::DlgSettings(QWidget *parent) : QDialog(parent), currentTabIndex(0), searchActive(false)
|
|
{
|
|
auto rec = QGuiApplication::primaryScreen()->availableGeometry();
|
|
setMinimumSize(qMin(750, rec.width()), qMin(700, rec.height()));
|
|
|
|
connect(&SettingsCache::instance().personal(), &PersonalSettings::langChanged, this, &DlgSettings::updateLanguage);
|
|
|
|
setupUi();
|
|
|
|
connect(&SettingsCache::instance().personal(), &PersonalSettings::langChanged, this, &DlgSettings::retranslateUi);
|
|
retranslateUi();
|
|
|
|
searchEdit->setFocus();
|
|
|
|
adjustSize();
|
|
}
|
|
|
|
void DlgSettings::setupUi()
|
|
{
|
|
// Search bar
|
|
searchEdit = new QLineEdit;
|
|
searchEdit->setClearButtonEnabled(true);
|
|
searchEdit->addAction(themePixmap(QStringLiteral("icons/search")), QLineEdit::LeadingPosition);
|
|
searchEdit->installEventFilter(this);
|
|
connect(searchEdit, &QLineEdit::textChanged, this, &DlgSettings::onSearchTextChanged);
|
|
|
|
auto *searchLayout = new QHBoxLayout;
|
|
searchLayout->addWidget(searchEdit);
|
|
|
|
// Tab bar (built in setupTabBar)
|
|
setupTabBar();
|
|
|
|
// Pages stacked widget
|
|
pagesWidget = new QStackedWidget;
|
|
|
|
auto *generalPage = new GeneralSettingsPage;
|
|
auto *appearancePage = new AppearanceSettingsPage;
|
|
auto *userInterfacePage = new UserInterfaceSettingsPage;
|
|
auto *deckEditorPage = new DeckEditorSettingsPage;
|
|
auto *storagePage = new StorageSettingsPage;
|
|
auto *messagesPage = new MessagesSettingsPage;
|
|
auto *soundPage = new SoundSettingsPage;
|
|
auto *shortcutsPage = new ShortcutSettingsPage;
|
|
|
|
pages.append(generalPage);
|
|
pages.append(appearancePage);
|
|
pages.append(userInterfacePage);
|
|
pages.append(deckEditorPage);
|
|
pages.append(storagePage);
|
|
pages.append(messagesPage);
|
|
pages.append(soundPage);
|
|
pages.append(shortcutsPage);
|
|
|
|
pagesWidget->addWidget(makeScrollable(generalPage));
|
|
pagesWidget->addWidget(makeScrollable(appearancePage));
|
|
pagesWidget->addWidget(makeScrollable(userInterfacePage));
|
|
pagesWidget->addWidget(makeScrollable(deckEditorPage));
|
|
pagesWidget->addWidget(makeScrollable(storagePage));
|
|
pagesWidget->addWidget(makeScrollable(messagesPage));
|
|
pagesWidget->addWidget(soundPage);
|
|
pagesWidget->addWidget(shortcutsPage);
|
|
|
|
Q_ASSERT(pages.size() == NumPages);
|
|
|
|
// Search results view (hidden by default)
|
|
searchResultsView = new QListView;
|
|
searchResultsView->setUniformItemSizes(false);
|
|
searchResultsView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
searchResultsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
searchResultsView->setVisible(false);
|
|
searchResultsView->setStyleSheet(
|
|
"QListView::item:selected { background: palette(highlight); color: palette(highlighted-text); }");
|
|
|
|
searchModel = new SettingsSearchModel(this);
|
|
searchDelegate = new SettingsSearchDelegate(this);
|
|
searchResultsView->setModel(searchModel);
|
|
searchResultsView->setItemDelegate(searchDelegate);
|
|
connect(searchResultsView, &QListView::clicked, this, &DlgSettings::onSearchResultClicked);
|
|
|
|
connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this, [this] {
|
|
const QStringList icons = pageIconResources();
|
|
for (int i = 0; i < tabButtons.size() && i < icons.size(); ++i) {
|
|
tabButtons[i]->setIcon(QPixmap(icons[i]));
|
|
}
|
|
searchDelegate->setPageIcons(icons);
|
|
searchResultsView->viewport()->update();
|
|
});
|
|
|
|
// Build search index after pages are created
|
|
buildSearchIndex();
|
|
|
|
// Pages container (stacked widget + search results overlay)
|
|
pagesContainer = new QWidget;
|
|
auto *containerLayout = new QStackedLayout;
|
|
containerLayout->setStackingMode(QStackedLayout::StackAll);
|
|
containerLayout->addWidget(pagesWidget);
|
|
containerLayout->addWidget(searchResultsView);
|
|
pagesContainer->setLayout(containerLayout);
|
|
|
|
// Bottom buttons
|
|
auto *buttonBox = new QHBoxLayout;
|
|
buttonBox->addStretch();
|
|
okButton = new QPushButton;
|
|
okButton->setDefault(true);
|
|
connect(okButton, &QPushButton::clicked, this, &DlgSettings::close);
|
|
buttonBox->addWidget(okButton);
|
|
|
|
// Main layout
|
|
auto *mainLayout = new QVBoxLayout;
|
|
mainLayout->addLayout(searchLayout);
|
|
mainLayout->addWidget(tabBarWidget);
|
|
auto *separator = new QFrame;
|
|
separator->setFrameShape(QFrame::HLine);
|
|
separator->setFrameShadow(QFrame::Sunken);
|
|
mainLayout->addWidget(separator);
|
|
mainLayout->addWidget(pagesContainer);
|
|
mainLayout->addSpacing(4);
|
|
mainLayout->addLayout(buttonBox);
|
|
setLayout(mainLayout);
|
|
|
|
// Keyboard shortcuts
|
|
auto *searchShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_F), this);
|
|
connect(searchShortcut, &QShortcut::activated, searchEdit, qOverload<>(&QLineEdit::setFocus));
|
|
|
|
auto *nextTabShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Tab), this);
|
|
connect(nextTabShortcut, &QShortcut::activated, this, [this] {
|
|
int next = (currentTabIndex + 1) % tabButtons.size();
|
|
setActiveTab(next);
|
|
});
|
|
|
|
auto *prevTabShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab), this);
|
|
connect(prevTabShortcut, &QShortcut::activated, this, [this] {
|
|
int prev = (currentTabIndex - 1 + tabButtons.size()) % tabButtons.size();
|
|
setActiveTab(prev);
|
|
});
|
|
|
|
// Initialize to first tab
|
|
setActiveTab(0);
|
|
}
|
|
|
|
void DlgSettings::setupTabBar()
|
|
{
|
|
tabBarWidget = new QWidget;
|
|
auto *tabLayout = new QHBoxLayout;
|
|
tabLayout->setContentsMargins(0, 0, 0, 0);
|
|
tabLayout->setSpacing(2);
|
|
|
|
const QStringList iconResources = pageIconResources();
|
|
|
|
for (int i = 0; i < iconResources.size(); ++i) {
|
|
auto *tabButton = new QToolButton;
|
|
tabButton->setCheckable(true);
|
|
tabButton->setIcon(QPixmap(iconResources[i]));
|
|
tabButton->setIconSize(QSize(48, 48));
|
|
tabButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
tabButton->setAutoExclusive(true);
|
|
tabButton->setMinimumHeight(85);
|
|
tabButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
connect(tabButton, &QToolButton::clicked, this, [this, idx = i] { onTabClicked(idx); });
|
|
|
|
tabButtons.append(tabButton);
|
|
tabLayout->addWidget(tabButton);
|
|
}
|
|
|
|
tabBarWidget->setLayout(tabLayout);
|
|
}
|
|
|
|
void DlgSettings::buildSearchIndex()
|
|
{
|
|
QList<SettingsSearchEntry> allEntries;
|
|
|
|
const QStringList pageNames = translatedPageNames();
|
|
searchDelegate->setPageNames(pageNames);
|
|
searchDelegate->setPageIcons(pageIconResources());
|
|
|
|
for (int i = 0; i < pages.size(); ++i) {
|
|
QList<SettingsSearchEntry> pageEntries = pages[i]->getSearchEntries();
|
|
for (auto &entry : pageEntries) {
|
|
if (entry.pageIndex == -1) {
|
|
entry.pageIndex = i;
|
|
}
|
|
}
|
|
allEntries.append(pageEntries);
|
|
}
|
|
|
|
searchModel->setSourceEntries(allEntries);
|
|
}
|
|
|
|
void DlgSettings::onTabClicked(int index)
|
|
{
|
|
if (searchActive) {
|
|
switchToTabMode();
|
|
}
|
|
setActiveTab(index);
|
|
}
|
|
|
|
void DlgSettings::setActiveTab(int index)
|
|
{
|
|
if (index < 0 || index >= tabButtons.size()) {
|
|
return;
|
|
}
|
|
|
|
currentTabIndex = index;
|
|
pagesWidget->setCurrentIndex(index);
|
|
|
|
for (int i = 0; i < tabButtons.size(); ++i) {
|
|
tabButtons[i]->setChecked(i == index);
|
|
}
|
|
|
|
// Style active tab with a thick accent border + subtle background tint
|
|
for (int i = 0; i < tabButtons.size(); ++i) {
|
|
if (i == index) {
|
|
tabButtons[i]->setStyleSheet("QToolButton { border: none; border-bottom: 3px solid palette(highlight); "
|
|
"border-top-left-radius: 4px; border-top-right-radius: 4px; "
|
|
"background: palette(window); padding-bottom: 1px; }");
|
|
} else {
|
|
tabButtons[i]->setStyleSheet("QToolButton { border: none; border-bottom: 1px solid transparent; "
|
|
"border-top-left-radius: 4px; border-top-right-radius: 4px; "
|
|
"background: transparent; }");
|
|
}
|
|
}
|
|
}
|
|
|
|
void DlgSettings::flashWidget(QWidget *widget)
|
|
{
|
|
auto *overlay = new QWidget(widget);
|
|
overlay->setGeometry(widget->rect());
|
|
overlay->setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
|
|
QPalette pal = overlay->palette();
|
|
QColor flashColor = pal.color(QPalette::Highlight);
|
|
flashColor.setAlpha(100);
|
|
pal.setBrush(QPalette::Window, flashColor);
|
|
overlay->setPalette(pal);
|
|
overlay->setAutoFillBackground(true);
|
|
|
|
auto *effect = new QGraphicsOpacityEffect(overlay);
|
|
effect->setOpacity(0.0);
|
|
overlay->setGraphicsEffect(effect);
|
|
overlay->show();
|
|
overlay->raise();
|
|
|
|
auto *flashIn = new QPropertyAnimation(effect, "opacity");
|
|
flashIn->setDuration(120);
|
|
flashIn->setStartValue(0.0);
|
|
flashIn->setEndValue(0.6);
|
|
flashIn->setEasingCurve(QEasingCurve::OutCubic);
|
|
|
|
auto *fadeOut = new QPropertyAnimation(effect, "opacity");
|
|
fadeOut->setDuration(900);
|
|
fadeOut->setStartValue(0.6);
|
|
fadeOut->setEndValue(0.0);
|
|
fadeOut->setEasingCurve(QEasingCurve::InCubic);
|
|
|
|
auto *group = new QSequentialAnimationGroup(overlay);
|
|
group->addAnimation(flashIn);
|
|
group->addAnimation(fadeOut);
|
|
|
|
connect(group, &QSequentialAnimationGroup::finished, overlay, &QWidget::deleteLater);
|
|
|
|
group->start(QAbstractAnimation::DeleteWhenStopped);
|
|
}
|
|
|
|
void DlgSettings::onSearchTextChanged(const QString &text)
|
|
{
|
|
searchModel->setFilterString(text);
|
|
|
|
if (searchModel->isFilterActive() && !text.trimmed().isEmpty()) {
|
|
if (!searchActive) {
|
|
switchToSearchMode();
|
|
}
|
|
if (searchModel->rowCount(QModelIndex()) > 0) {
|
|
searchResultsView->setCurrentIndex(searchModel->index(0));
|
|
}
|
|
} else if (searchActive) {
|
|
switchToTabMode();
|
|
}
|
|
}
|
|
|
|
void DlgSettings::switchToSearchMode()
|
|
{
|
|
searchActive = true;
|
|
tabBarWidget->setVisible(false);
|
|
pagesWidget->setVisible(false);
|
|
searchResultsView->setVisible(true);
|
|
if (searchModel->rowCount(QModelIndex()) > 0) {
|
|
searchResultsView->setCurrentIndex(searchModel->index(0));
|
|
}
|
|
}
|
|
|
|
void DlgSettings::switchToTabMode()
|
|
{
|
|
searchActive = false;
|
|
tabBarWidget->setVisible(true);
|
|
pagesWidget->setVisible(true);
|
|
searchResultsView->setVisible(false);
|
|
searchEdit->blockSignals(true);
|
|
searchEdit->clear();
|
|
searchEdit->blockSignals(false);
|
|
setActiveTab(currentTabIndex);
|
|
}
|
|
|
|
void DlgSettings::onSearchResultClicked(const QModelIndex &index)
|
|
{
|
|
navigateToSearchResult(index);
|
|
}
|
|
|
|
void DlgSettings::navigateToSearchResult(const QModelIndex &index)
|
|
{
|
|
SettingsSearchEntry entry = searchModel->entryForIndex(index);
|
|
if (entry.pageIndex < 0 || entry.pageIndex >= pages.size()) {
|
|
return;
|
|
}
|
|
|
|
// Switch to the page
|
|
switchToTabMode();
|
|
setActiveTab(entry.pageIndex);
|
|
|
|
// Scroll to the widget, focus it, and flash to highlight it
|
|
if (entry.widget) {
|
|
QWidget *widget = entry.widget;
|
|
while (widget) {
|
|
if (auto *scrollArea = qobject_cast<QScrollArea *>(widget)) {
|
|
scrollArea->ensureWidgetVisible(entry.widget);
|
|
break;
|
|
}
|
|
widget = widget->parentWidget();
|
|
}
|
|
entry.widget->setFocus();
|
|
flashWidget(entry.widget);
|
|
}
|
|
}
|
|
|
|
void DlgSettings::setTab(int index)
|
|
{
|
|
if (index >= 0 && index < tabButtons.size()) {
|
|
setActiveTab(index);
|
|
}
|
|
}
|
|
|
|
AbstractSettingsPage *DlgSettings::page(SettingsPage which) const
|
|
{
|
|
return pages.value(static_cast<int>(which));
|
|
}
|
|
|
|
void DlgSettings::updateLanguage()
|
|
{
|
|
qApp->removeTranslator(translator); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
|
|
installNewTranslator();
|
|
}
|
|
|
|
bool DlgSettings::eventFilter(QObject *watched, QEvent *event)
|
|
{
|
|
if (watched == searchEdit && event->type() == QEvent::KeyPress) {
|
|
auto *keyEvent = static_cast<QKeyEvent *>(event);
|
|
if (keyEvent->key() == Qt::Key_Escape) {
|
|
if (searchActive) {
|
|
switchToTabMode();
|
|
return true;
|
|
}
|
|
} else if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
|
|
if (searchActive) {
|
|
if (searchResultsView->currentIndex().isValid()) {
|
|
navigateToSearchResult(searchResultsView->currentIndex());
|
|
}
|
|
return true;
|
|
}
|
|
} else if (keyEvent->key() == Qt::Key_Down) {
|
|
if (searchActive) {
|
|
int nextRow = searchResultsView->currentIndex().row() + 1;
|
|
if (nextRow >= searchModel->rowCount()) {
|
|
nextRow = 0;
|
|
}
|
|
searchResultsView->setCurrentIndex(searchModel->index(nextRow));
|
|
searchResultsView->scrollTo(searchModel->index(nextRow));
|
|
return true;
|
|
}
|
|
} else if (keyEvent->key() == Qt::Key_Up) {
|
|
if (searchActive) {
|
|
int prevRow = searchResultsView->currentIndex().row() - 1;
|
|
if (prevRow < 0) {
|
|
prevRow = searchModel->rowCount() - 1;
|
|
}
|
|
if (prevRow >= 0) {
|
|
searchResultsView->setCurrentIndex(searchModel->index(prevRow));
|
|
searchResultsView->scrollTo(searchModel->index(prevRow));
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return QDialog::eventFilter(watched, event);
|
|
}
|
|
|
|
void DlgSettings::closeEvent(QCloseEvent *event)
|
|
{
|
|
bool showLoadError = true;
|
|
QString loadErrorMessage = tr("Unknown Error loading card database");
|
|
LoadStatus loadStatus = CardDatabaseManager::getInstance()->getLoadStatus();
|
|
qCInfo(DlgSettingsLog) << "Card Database load status: " << loadStatus;
|
|
switch (loadStatus) {
|
|
case Ok:
|
|
showLoadError = false;
|
|
break;
|
|
case Invalid:
|
|
loadErrorMessage = tr("Your card database is invalid.\n\n"
|
|
"Cockatrice may not function correctly with an invalid database\n\n"
|
|
"You may need to rerun Oracle to update your card database.\n\n"
|
|
"Would you like to change your database location setting?");
|
|
break;
|
|
case VersionTooOld:
|
|
loadErrorMessage = tr("Your card database version is too old.\n\n"
|
|
"This can cause problems loading card information or images\n\n"
|
|
"Usually this can be fixed by rerunning Oracle to to update your card database.\n\n"
|
|
"Would you like to change your database location setting?");
|
|
break;
|
|
case NotLoaded:
|
|
loadErrorMessage = tr("Your card database did not finish loading\n\n"
|
|
"Please file a ticket at https://github.com/Cockatrice/Cockatrice/issues with your "
|
|
"cards.xml attached\n\n"
|
|
"Would you like to change your database location setting?");
|
|
break;
|
|
case FileError:
|
|
loadErrorMessage = tr("File Error loading your card database.\n\n"
|
|
"Would you like to change your database location setting?");
|
|
break;
|
|
case NoCards:
|
|
loadErrorMessage = tr("Your card database was loaded but contains no cards.\n\n"
|
|
"Would you like to change your database location setting?");
|
|
break;
|
|
default:
|
|
loadErrorMessage = tr("Unknown card database load status\n\n"
|
|
"Please file a ticket at https://github.com/Cockatrice/Cockatrice/issues\n\n"
|
|
"Would you like to change your database location setting?");
|
|
|
|
break;
|
|
}
|
|
|
|
if (showLoadError) {
|
|
if (QMessageBox::critical(this, tr("Error"), loadErrorMessage, QMessageBox::Yes | QMessageBox::No) ==
|
|
QMessageBox::Yes) {
|
|
event->ignore();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!QDir(SettingsCache::instance().paths().getDeckPath()).exists() ||
|
|
SettingsCache::instance().paths().getDeckPath().isEmpty()) {
|
|
if (QMessageBox::critical(
|
|
this, tr("Error"),
|
|
tr("The path to your deck directory is invalid. Would you like to go back and set the correct path?"),
|
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
|
event->ignore();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!QDir(SettingsCache::instance().paths().getPicsPath()).exists() ||
|
|
SettingsCache::instance().paths().getPicsPath().isEmpty()) {
|
|
if (QMessageBox::critical(this, tr("Error"),
|
|
tr("The path to your card pictures directory is invalid. Would you like to go back "
|
|
"and set the correct path?"),
|
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
|
event->ignore();
|
|
return;
|
|
}
|
|
}
|
|
event->accept();
|
|
}
|
|
|
|
void DlgSettings::retranslateUi()
|
|
{
|
|
setWindowTitle(tr("Settings"));
|
|
retranslateTabNames();
|
|
|
|
searchEdit->setPlaceholderText(tr("Search settings..."));
|
|
okButton->setText(tr("OK"));
|
|
|
|
// Rebuild search index for translated text
|
|
buildSearchIndex();
|
|
}
|
|
|
|
QStringList DlgSettings::translatedPageNames()
|
|
{
|
|
return {tr("General"), tr("Appearance"), tr("User Interface"), tr("Card Sources"),
|
|
tr("Storage"), tr("Chat"), tr("Sound"), tr("Shortcuts")};
|
|
}
|
|
|
|
void DlgSettings::retranslateTabNames()
|
|
{
|
|
const QStringList tabLabels = translatedPageNames();
|
|
|
|
for (int i = 0; i < tabButtons.size() && i < tabLabels.size(); ++i) {
|
|
tabButtons[i]->setText(tabLabels[i]);
|
|
}
|
|
}
|