mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [Client] Settings: extract SettingsView from DlgSettings Move the search bar, tab bar, stacked pages and search results out of DlgSettings into a reusable SettingsView widget. The dialog becomes a thin frame (title, OK button, close validation) delegating to the view. No visual or behavior change; tr() contexts preserved as DlgSettings. * [Client] Settings: match CI clang-format-18 line breaking --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
157 lines
5.9 KiB
C++
157 lines
5.9 KiB
C++
/**
|
|
* @file dlg_settings.cpp
|
|
* @brief Implementation of the main settings dialog (thin frame around SettingsView)
|
|
* @ingroup Dialogs
|
|
*/
|
|
#include "dlg_settings.h"
|
|
|
|
#include "../../../client/settings/cache_settings.h"
|
|
#include "../main.h"
|
|
#include "../settings_page/abstract_settings_page.h"
|
|
#include "libcockatrice/card/database/card_database.h"
|
|
#include "libcockatrice/card/database/card_database_loader.h"
|
|
#include "libcockatrice/card/database/card_database_manager.h"
|
|
|
|
#include <QApplication>
|
|
#include <QCloseEvent>
|
|
#include <QDir>
|
|
#include <QGuiApplication>
|
|
#include <QHBoxLayout>
|
|
#include <QMessageBox>
|
|
#include <QMessageLogger>
|
|
#include <QPushButton>
|
|
#include <QScreen>
|
|
#include <QSize>
|
|
#include <QVBoxLayout>
|
|
#include <QWidget>
|
|
#include <QtGlobal>
|
|
#include <libcockatrice/settings/paths_settings.h>
|
|
#include <libcockatrice/settings/personal_settings.h>
|
|
|
|
DlgSettings::DlgSettings(QWidget *parent) : QDialog(parent)
|
|
{
|
|
auto rec = QGuiApplication::primaryScreen()->availableGeometry();
|
|
setMinimumSize(qMin(750, rec.width()), qMin(700, rec.height()));
|
|
|
|
connect(&SettingsCache::instance().personal(), &PersonalSettings::langChanged, this, &DlgSettings::updateLanguage);
|
|
|
|
settingsView = new SettingsView(this);
|
|
|
|
// 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->addWidget(settingsView);
|
|
mainLayout->addSpacing(4);
|
|
mainLayout->addLayout(buttonBox);
|
|
setLayout(mainLayout);
|
|
|
|
connect(&SettingsCache::instance().personal(), &PersonalSettings::langChanged, this, &DlgSettings::retranslateUi);
|
|
retranslateUi();
|
|
|
|
adjustSize();
|
|
}
|
|
|
|
void DlgSettings::setTab(int index)
|
|
{
|
|
settingsView->setTab(index);
|
|
}
|
|
|
|
AbstractSettingsPage *DlgSettings::page(SettingsPage which) const
|
|
{
|
|
return settingsView->page(which);
|
|
}
|
|
|
|
void DlgSettings::updateLanguage()
|
|
{
|
|
qApp->removeTranslator(translator); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
|
|
installNewTranslator();
|
|
}
|
|
|
|
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"));
|
|
okButton->setText(tr("OK"));
|
|
}
|