[Settings] Split Paths from SettingsCache into PathSettings

This commit is contained in:
Lukas Brübach 2026-07-01 23:30:51 -04:00
parent baddbfae14
commit 21f57b1acb
31 changed files with 350 additions and 254 deletions

View file

@ -150,31 +150,6 @@ void SettingsCache::translateLegacySettings()
}
}
QString SettingsCache::getSafeConfigPath(QString configEntry, QString defaultPath) const
{
QString tmp = settings->value(configEntry).toString();
// if the config settings is empty or refers to a not-existing folder,
// ensure that the defaut path exists and return it
if (tmp.isEmpty() || !QDir(tmp).exists()) {
if (!QDir().mkpath(defaultPath)) {
qCInfo(SettingsCacheLog) << "[SettingsCache] Could not create folder:" << defaultPath;
}
tmp = defaultPath;
}
return tmp;
}
QString SettingsCache::getSafeConfigFilePath(QString configEntry, QString defaultPath) const
{
QString tmp = settings->value(configEntry).toString();
// if the config settings is empty or refers to a not-existing file,
// return the default Path
if (!QFile::exists(tmp) || tmp.isEmpty()) {
tmp = std::move(defaultPath);
}
return tmp;
}
SettingsCache::SettingsCache()
{
// first, figure out if we are running in portable mode
@ -188,6 +163,8 @@ SettingsCache::SettingsCache()
QString settingsPath = getSettingsPath();
settings = new QSettings(settingsPath + "global.ini", QSettings::IniFormat, this);
pathsSettings = new PathSettings(settingsPath, this);
pathsSettings->load(getDataPath(), getCachePath());
shortcutsSettings = new ShortcutsSettings(settingsPath, this);
cardDatabaseSettings = new CardDatabaseSettings(settingsPath, this);
serversSettings = new ServersSettings(settingsPath, this);
@ -247,8 +224,6 @@ SettingsCache::SettingsCache()
seenTips.append(tipNumber.toInt());
}
loadPaths();
themeName = settings->value("theme/name").toString();
homeTabBackgroundSource = settings->value("home/background", "themed").toString();
@ -552,72 +527,6 @@ void SettingsCache::setSeenTips(const QList<int> &_seenTips)
settings->setValue("tipOfDay/seenTips", storedTipList);
}
void SettingsCache::setDeckPath(const QString &_deckPath)
{
deckPath = _deckPath;
settings->setValue("paths/decks", deckPath);
}
void SettingsCache::setFiltersPath(const QString &_filtersPath)
{
filtersPath = _filtersPath;
settings->setValue("paths/filters", filtersPath);
}
void SettingsCache::setReplaysPath(const QString &_replaysPath)
{
replaysPath = _replaysPath;
settings->setValue("paths/replays", replaysPath);
}
void SettingsCache::setThemesPath(const QString &_themesPath)
{
themesPath = _themesPath;
settings->setValue("paths/themes", themesPath);
emit themeChanged();
}
void SettingsCache::setCustomCardDatabasePath(const QString &_customCardDatabasePath)
{
customCardDatabasePath = _customCardDatabasePath;
settings->setValue("paths/customsets", customCardDatabasePath);
emit cardDatabasePathChanged();
}
void SettingsCache::setPicsPath(const QString &_picsPath)
{
picsPath = _picsPath;
settings->setValue("paths/pics", picsPath);
// get a new value for customPicsPath, currently derived from picsPath
if (picsPath.endsWith("/")) {
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");
} else {
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "/CUSTOM/");
}
emit picsPathChanged();
}
void SettingsCache::setCardDatabasePath(const QString &_cardDatabasePath)
{
cardDatabasePath = _cardDatabasePath;
settings->setValue("paths/carddatabase", cardDatabasePath);
emit cardDatabasePathChanged();
}
void SettingsCache::setSpoilerDatabasePath(const QString &_spoilerDatabasePath)
{
spoilerDatabasePath = _spoilerDatabasePath;
settings->setValue("paths/spoilerdatabase", spoilerDatabasePath);
emit cardDatabasePathChanged();
}
void SettingsCache::setTokenDatabasePath(const QString &_tokenDatabasePath)
{
tokenDatabasePath = _tokenDatabasePath;
settings->setValue("paths/tokendatabase", tokenDatabasePath);
emit cardDatabasePathChanged();
}
void SettingsCache::setThemeName(const QString &_themeName)
{
themeName = _themeName;
@ -1402,43 +1311,6 @@ void SettingsCache::setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtype
settings->setValue("interface/showsubtypeselectiontally", showSubtypeSelectionTally);
}
void SettingsCache::loadPaths()
{
QString dataPath = getDataPath();
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
filtersPath = getSafeConfigPath("paths/filters", dataPath + "/filters/");
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
redirectCachePath = getSafeConfigPath("paths/redirects", getCachePath() + "/redirects/");
// this has never been exposed as an user-configurable setting
if (picsPath.endsWith("/")) {
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");
} else {
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "/CUSTOM/");
}
customCardDatabasePath = getSafeConfigPath("paths/customsets", dataPath + "/customsets/");
cardDatabasePath = getSafeConfigFilePath("paths/carddatabase", dataPath + "/cards.xml");
tokenDatabasePath = getSafeConfigFilePath("paths/tokendatabase", dataPath + "/tokens.xml");
spoilerDatabasePath = getSafeConfigFilePath("paths/spoilerdatabase", dataPath + "/spoiler.xml");
}
void SettingsCache::resetPaths()
{
QStringList databasePaths{customCardDatabasePath, cardDatabasePath, spoilerDatabasePath, tokenDatabasePath};
QString picsPath_ = picsPath;
settings->remove("paths"); // removes all keys in paths/*
loadPaths();
if (databasePaths !=
QStringList{customCardDatabasePath, cardDatabasePath, spoilerDatabasePath, tokenDatabasePath}) {
emit cardDatabasePathChanged();
}
if (picsPath_ != picsPath) {
emit picsPathChanged();
}
}
CardCounterSettings &SettingsCache::cardCounters() const
{
return *cardCounterSettings;

View file

@ -10,6 +10,7 @@
#include "../../interface/card_picture_loader/card_picture_loader_cache_method.h"
#include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h"
#include "shortcuts_settings.h"
#include <libcockatrice/settings/path_settings.h>
#include <QDate>
#include <QLoggingCategory>
@ -135,7 +136,7 @@ inline QStringList defaultTags = {
class QSettings;
class CardCounterSettings;
class SettingsCache : public ICardDatabasePathProvider, public INetworkSettingsProvider
class SettingsCache : public QObject, public INetworkSettingsProvider
{
Q_OBJECT
@ -211,10 +212,10 @@ private:
CardOverrideSettings *cardOverrideSettings;
DebugSettings *debugSettings;
CardCounterSettings *cardCounterSettings;
PathSettings *pathsSettings;
QString lang;
QString deckPath, filtersPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath,
customCardDatabasePath, themesPath, spoilerDatabasePath, tokenDatabasePath, themeName, homeTabBackgroundSource;
QString themeName, homeTabBackgroundSource;
bool tabVisualDeckStorageOpen, tabServerOpen, tabAccountOpen, tabDeckStorageOpen, tabReplaysOpen, tabAdminOpen,
tabLogOpen;
bool checkUpdatesOnStartup;
@ -339,9 +340,6 @@ private:
int keepalive;
int timeout;
void translateLegacySettings();
[[nodiscard]] QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
[[nodiscard]] QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
void loadPaths();
bool rememberGameSettings;
// Local game settings (separate from server game settings in game/*)
@ -367,50 +365,6 @@ public:
{
return lang;
}
[[nodiscard]] QString getDeckPath() const
{
return deckPath;
}
[[nodiscard]] QString getFiltersPath() const
{
return filtersPath;
}
[[nodiscard]] QString getReplaysPath() const
{
return replaysPath;
}
[[nodiscard]] QString getThemesPath() const
{
return themesPath;
}
[[nodiscard]] QString getPicsPath() const
{
return picsPath;
}
[[nodiscard]] QString getRedirectCachePath() const
{
return redirectCachePath;
}
[[nodiscard]] QString getCustomPicsPath() const
{
return customPicsPath;
}
[[nodiscard]] QString getCustomCardDatabasePath() const override
{
return customCardDatabasePath;
}
[[nodiscard]] QString getCardDatabasePath() const override
{
return cardDatabasePath;
}
[[nodiscard]] QString getSpoilerCardDatabasePath() const override
{
return spoilerDatabasePath;
}
[[nodiscard]] QString getTokenDatabasePath() const override
{
return tokenDatabasePath;
}
[[nodiscard]] QString getThemeName() const
{
return themeName;
@ -985,6 +939,10 @@ public:
{
return keepGameChatFocus;
}
[[nodiscard]] PathSettings &paths() const
{
return *pathsSettings;
}
[[nodiscard]] ShortcutsSettings &shortcuts() const
{
return *shortcutsSettings;
@ -1049,15 +1007,6 @@ public slots:
void setLang(const QString &_lang);
void setShowTipsOnStartup(bool _showTipsOnStartup);
void setSeenTips(const QList<int> &_seenTips);
void setDeckPath(const QString &_deckPath);
void setFiltersPath(const QString &_filtersPath);
void setReplaysPath(const QString &_replaysPath);
void setThemesPath(const QString &_themesPath);
void setCustomCardDatabasePath(const QString &_customCardDatabasePath);
void setPicsPath(const QString &_picsPath);
void setCardDatabasePath(const QString &_cardDatabasePath);
void setSpoilerDatabasePath(const QString &_spoilerDatabasePath);
void setTokenDatabasePath(const QString &_tokenDatabasePath);
void setThemeName(const QString &_themeName);
void setHomeTabBackgroundSource(const QString &_backgroundSource);
void setHomeTabBackgroundShuffleFrequency(int _frequency);
@ -1183,4 +1132,4 @@ public slots:
void setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount);
void setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally);
};
#endif
#endif