mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
SettingsCache owns the stable and beta update channels as raw pointers, and each owns a QNetworkAccessManager, so the process leaves QtNetwork objects alive past QApplication teardown. Delete them from a QCoreApplication::aboutToQuit handler instead of the destructor: SettingsCache is a Q_GLOBAL_STATIC, so ~SettingsCache() runs during static teardown, after QApplication is gone, and destroying the network managers at that point is the post-application window that ASan reports. The hook is installed on the first instance() call that has an application object, since the first access may predate it.
178 lines
6.2 KiB
C++
178 lines
6.2 KiB
C++
/**
|
|
* @file cache_settings.h
|
|
* @ingroup Settings
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef SETTINGSCACHE_H
|
|
#define SETTINGSCACHE_H
|
|
|
|
#include <QList>
|
|
#include <QLoggingCategory>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <libcockatrice/interfaces/interface_card_database_path_provider.h>
|
|
#include <libcockatrice/interfaces/interface_network_settings_provider.h>
|
|
#include <qtmetamacros.h>
|
|
|
|
inline Q_LOGGING_CATEGORY(SettingsCacheLog, "settings_cache");
|
|
|
|
class ReleaseChannel;
|
|
|
|
#define DEFAULT_LANG_NAME "English"
|
|
#define CLIENT_INFO_NOT_SET "notset"
|
|
|
|
#define DEFAULT_FONT_SIZE 12
|
|
|
|
class CacheStorageSettings;
|
|
class CardCounterSettings;
|
|
class CardDatabaseSettings;
|
|
class CardOverrideSettings;
|
|
class CardsDisplaySettings;
|
|
class ChatSettings;
|
|
class CommanderBracketSettings;
|
|
class DebugSettings;
|
|
class DeckEditorSettings;
|
|
class DownloadSettings;
|
|
class GameFiltersSettings;
|
|
class GameSettings;
|
|
class InterfaceSettings;
|
|
class LayoutsSettings;
|
|
class MessageSettings;
|
|
class PathsSettings;
|
|
class PersonalSettings;
|
|
class RecentsSettings;
|
|
class ServersSettings;
|
|
class ShortcutsSettings;
|
|
class SoundSettings;
|
|
class TabsSettings;
|
|
class UpdatesSettings;
|
|
class VisualDeckStorageSettings;
|
|
class AppearanceSettings;
|
|
class NetworkSettings;
|
|
class QSettings;
|
|
|
|
class SettingsCache : public ICardDatabasePathProvider, public INetworkSettingsProvider
|
|
{
|
|
Q_OBJECT
|
|
|
|
signals:
|
|
void themeChanged();
|
|
|
|
private:
|
|
QSettings *settings = nullptr;
|
|
ShortcutsSettings *shortcutsSettings = nullptr;
|
|
CardDatabaseSettings *cardDatabaseSettings = nullptr;
|
|
ServersSettings *serversSettings = nullptr;
|
|
MessageSettings *messageSettings = nullptr;
|
|
GameFiltersSettings *gameFiltersSettings = nullptr;
|
|
LayoutsSettings *layoutsSettings = nullptr;
|
|
DownloadSettings *downloadSettings = nullptr;
|
|
RecentsSettings *recentsSettings = nullptr;
|
|
CardOverrideSettings *cardOverrideSettings = nullptr;
|
|
DebugSettings *debugSettings = nullptr;
|
|
CardCounterSettings *cardCounterSettings = nullptr;
|
|
TabsSettings *tabsSettings = nullptr;
|
|
SoundSettings *soundSettings = nullptr;
|
|
GameSettings *gameSettings = nullptr;
|
|
ChatSettings *chatSettings = nullptr;
|
|
CacheStorageSettings *cacheStorageSettings = nullptr;
|
|
UpdatesSettings *updatesSettings = nullptr;
|
|
PersonalSettings *personalSettings = nullptr;
|
|
CardsDisplaySettings *cardsDisplaySettings = nullptr;
|
|
InterfaceSettings *interfaceSettings = nullptr;
|
|
DeckEditorSettings *deckEditorSettings = nullptr;
|
|
PathsSettings *pathsSettings = nullptr;
|
|
VisualDeckStorageSettings *visualDeckStorageSettings = nullptr;
|
|
AppearanceSettings *appearanceSettings = nullptr;
|
|
NetworkSettings *networkSettings = nullptr;
|
|
CommanderBracketSettings *commanderBracketSettings = nullptr;
|
|
|
|
QString themeName;
|
|
|
|
QList<ReleaseChannel *> releaseChannels;
|
|
bool shutdownHookInstalled = false;
|
|
bool isPortableBuild;
|
|
|
|
// Connects the aboutToQuit handler that deletes the release channels while
|
|
// the application object is still alive; a no-op before it exists.
|
|
void installShutdownHook();
|
|
|
|
[[nodiscard]] QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
|
|
[[nodiscard]] QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
|
|
void loadPaths();
|
|
|
|
public:
|
|
SettingsCache();
|
|
QString getDataPath();
|
|
QString getSettingsPath();
|
|
[[nodiscard]] QString getCachePath() const;
|
|
[[nodiscard]] QString getNetworkCachePath() const;
|
|
|
|
// ICardDatabasePathProvider - delegate to pathsSettings
|
|
[[nodiscard]] QString getCustomCardDatabasePath() const override;
|
|
[[nodiscard]] QString getCardDatabasePath() const override;
|
|
[[nodiscard]] QString getSpoilerCardDatabasePath() const override;
|
|
[[nodiscard]] QString getTokenDatabasePath() const override;
|
|
|
|
// INetworkSettingsProvider - delegate to sub-objects
|
|
[[nodiscard]] int getKeepAlive() const override;
|
|
[[nodiscard]] int getTimeOut() const override;
|
|
[[nodiscard]] bool getNotifyAboutUpdates() const override;
|
|
void setKnownMissingFeatures(const QString &_knownMissingFeatures) override;
|
|
[[nodiscard]] QString getKnownMissingFeatures() override;
|
|
QString getClientID() override;
|
|
|
|
[[nodiscard]] QString getThemeName() const
|
|
{
|
|
return themeName;
|
|
}
|
|
|
|
[[nodiscard]] ReleaseChannel *getUpdateReleaseChannel() const;
|
|
[[nodiscard]] QList<ReleaseChannel *> getUpdateReleaseChannels() const;
|
|
[[nodiscard]] int getUpdateReleaseChannelIndex() const;
|
|
|
|
[[nodiscard]] QStringList getCountries() const;
|
|
|
|
[[nodiscard]] ShortcutsSettings &shortcuts() const;
|
|
[[nodiscard]] CardDatabaseSettings &cardDatabase() const;
|
|
[[nodiscard]] ServersSettings &servers() const;
|
|
[[nodiscard]] MessageSettings &messages() const;
|
|
[[nodiscard]] GameFiltersSettings &gameFilters() const;
|
|
[[nodiscard]] LayoutsSettings &layouts() const;
|
|
[[nodiscard]] DownloadSettings &downloads() const;
|
|
[[nodiscard]] RecentsSettings &recents() const;
|
|
[[nodiscard]] CardOverrideSettings &cardOverrides() const;
|
|
[[nodiscard]] DebugSettings &debug() const;
|
|
[[nodiscard]] CardCounterSettings &cardCounters() const;
|
|
[[nodiscard]] TabsSettings &tabs() const;
|
|
[[nodiscard]] SoundSettings &sound() const;
|
|
[[nodiscard]] GameSettings &game() const;
|
|
[[nodiscard]] ChatSettings &chat() const;
|
|
[[nodiscard]] CacheStorageSettings &cacheStorage() const;
|
|
[[nodiscard]] UpdatesSettings &updates() const;
|
|
[[nodiscard]] PersonalSettings &personal() const;
|
|
[[nodiscard]] CardsDisplaySettings &cardsDisplay() const;
|
|
[[nodiscard]] InterfaceSettings &userInterface() const;
|
|
[[nodiscard]] DeckEditorSettings &deckEditor() const;
|
|
[[nodiscard]] PathsSettings &paths() const;
|
|
[[nodiscard]] VisualDeckStorageSettings &visualDeckStorage() const;
|
|
[[nodiscard]] AppearanceSettings &appearance() const;
|
|
[[nodiscard]] NetworkSettings &network() const;
|
|
[[nodiscard]] CommanderBracketSettings &commanderBrackets() const
|
|
{
|
|
return *commanderBracketSettings;
|
|
}
|
|
|
|
[[nodiscard]] bool getIsPortableBuild() const
|
|
{
|
|
return isPortableBuild;
|
|
}
|
|
|
|
static SettingsCache &instance();
|
|
void resetPaths();
|
|
|
|
public slots:
|
|
void setThemeName(const QString &_themeName);
|
|
};
|
|
#endif
|