From 0dcd189331899bdec4866778cce7bb14046106e0 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 15 Jan 2024 22:51:17 +0100 Subject: [PATCH] Make all uses/storages of Paths const --- src/Application.cpp | 7 ++++--- src/Application.hpp | 6 +++--- src/RunGui.cpp | 3 ++- src/RunGui.hpp | 2 +- src/common/Singleton.hpp | 2 +- src/controllers/accounts/AccountController.cpp | 2 +- src/controllers/accounts/AccountController.hpp | 2 +- src/controllers/commands/CommandController.cpp | 2 +- src/controllers/commands/CommandController.hpp | 2 +- src/controllers/highlights/HighlightController.cpp | 3 ++- src/controllers/highlights/HighlightController.hpp | 2 +- src/controllers/notifications/NotificationController.cpp | 2 +- src/controllers/notifications/NotificationController.hpp | 2 +- src/controllers/sound/MiniaudioBackend.cpp | 2 +- src/controllers/sound/MiniaudioBackend.hpp | 2 +- src/providers/chatterino/ChatterinoBadges.cpp | 2 +- src/providers/chatterino/ChatterinoBadges.hpp | 2 +- src/providers/ffz/FfzBadges.cpp | 2 +- src/providers/ffz/FfzBadges.hpp | 2 +- src/providers/twitch/TwitchIrcServer.cpp | 2 +- src/providers/twitch/TwitchIrcServer.hpp | 2 +- src/singletons/CrashHandler.cpp | 2 +- src/singletons/CrashHandler.hpp | 2 +- src/singletons/Emotes.cpp | 2 +- src/singletons/Emotes.hpp | 2 +- src/singletons/Fonts.cpp | 2 +- src/singletons/Fonts.hpp | 2 +- src/singletons/Paths.cpp | 2 +- src/singletons/Paths.hpp | 2 +- src/singletons/Theme.cpp | 2 +- src/singletons/Theme.hpp | 2 +- src/singletons/WindowManager.cpp | 2 +- src/singletons/WindowManager.hpp | 2 +- 33 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index eb181b9b0..be052d4a9 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -107,7 +107,8 @@ IApplication::IApplication() // It will create the instances of the major classes, and connect their signals // to each other -Application::Application(Settings &_settings, Paths &_paths, const Args &_args) +Application::Application(Settings &_settings, const Paths &_paths, + const Args &_args) : args_(_args) , themes(&this->emplace()) , fonts(&this->emplace()) @@ -152,7 +153,7 @@ void Application::fakeDtor() this->twitchPubSub.reset(); } -void Application::initialize(Settings &settings, Paths &paths) +void Application::initialize(Settings &settings, const Paths &paths) { assert(isAppInitialized == false); isAppInitialized = true; @@ -340,7 +341,7 @@ void Application::save() } } -void Application::initNm(Paths &paths) +void Application::initNm(const Paths &paths) { (void)paths; diff --git a/src/Application.hpp b/src/Application.hpp index fb84d7f50..60af329f0 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -90,7 +90,7 @@ class Application : public IApplication public: static Application *instance; - Application(Settings &_settings, Paths &_paths, const Args &_args); + Application(Settings &_settings, const Paths &_paths, const Args &_args); ~Application() override; Application(const Application &) = delete; @@ -104,7 +104,7 @@ public: */ void fakeDtor(); - void initialize(Settings &settings, Paths &paths); + void initialize(Settings &settings, const Paths &paths); void load(); void save(); @@ -222,7 +222,7 @@ private: void initPubSub(); void initBttvLiveUpdates(); void initSeventvEventAPI(); - void initNm(Paths &paths); + void initNm(const Paths &paths); template ::value>> diff --git a/src/RunGui.cpp b/src/RunGui.cpp index 91f2f2985..99d8a4bb6 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -223,7 +223,8 @@ namespace { } } // namespace -void runGui(QApplication &a, Paths &paths, Settings &settings, const Args &args) +void runGui(QApplication &a, const Paths &paths, Settings &settings, + const Args &args) { initQt(); initResources(); diff --git a/src/RunGui.hpp b/src/RunGui.hpp index 61bd41f0b..7efbea89d 100644 --- a/src/RunGui.hpp +++ b/src/RunGui.hpp @@ -8,7 +8,7 @@ class Args; class Paths; class Settings; -void runGui(QApplication &a, Paths &paths, Settings &settings, +void runGui(QApplication &a, const Paths &paths, Settings &settings, const Args &args); } // namespace chatterino diff --git a/src/common/Singleton.hpp b/src/common/Singleton.hpp index 2e47dec3f..f94d7152a 100644 --- a/src/common/Singleton.hpp +++ b/src/common/Singleton.hpp @@ -17,7 +17,7 @@ public: Singleton(Singleton &&) = delete; Singleton &operator=(Singleton &&) = delete; - virtual void initialize(Settings &settings, Paths &paths) + virtual void initialize(Settings &settings, const Paths &paths) { (void)(settings); (void)(paths); diff --git a/src/controllers/accounts/AccountController.cpp b/src/controllers/accounts/AccountController.cpp index 8191cea40..d0643cdef 100644 --- a/src/controllers/accounts/AccountController.cpp +++ b/src/controllers/accounts/AccountController.cpp @@ -47,7 +47,7 @@ AccountController::AccountController() }); } -void AccountController::initialize(Settings &settings, Paths &paths) +void AccountController::initialize(Settings &settings, const Paths &paths) { this->twitch.load(); } diff --git a/src/controllers/accounts/AccountController.hpp b/src/controllers/accounts/AccountController.hpp index ce63ba1ee..726719f5c 100644 --- a/src/controllers/accounts/AccountController.hpp +++ b/src/controllers/accounts/AccountController.hpp @@ -21,7 +21,7 @@ public: AccountModel *createModel(QObject *parent); - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; TwitchAccountManager twitch; diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 9d66afd47..823e8f393 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -261,7 +261,7 @@ const std::unordered_map COMMAND_VARS{ namespace chatterino { -void CommandController::initialize(Settings &, Paths &paths) +void CommandController::initialize(Settings &, const Paths &paths) { // Update commands map when the vector of commands has been updated auto addFirstMatchToMap = [this](auto args) { diff --git a/src/controllers/commands/CommandController.hpp b/src/controllers/commands/CommandController.hpp index f5ba40b24..d13197e4f 100644 --- a/src/controllers/commands/CommandController.hpp +++ b/src/controllers/commands/CommandController.hpp @@ -33,7 +33,7 @@ public: bool dryRun); QStringList getDefaultChatterinoCommandList(); - void initialize(Settings &, Paths &paths) override; + void initialize(Settings &, const Paths &paths) override; void save() override; CommandModel *createModel(QObject *parent); diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 9dee55047..53062d08c 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -440,7 +440,8 @@ std::ostream &operator<<(std::ostream &os, const HighlightResult &result) return os; } -void HighlightController::initialize(Settings &settings, Paths & /*paths*/) +void HighlightController::initialize(Settings &settings, + const Paths & /*paths*/) { this->rebuildListener_.addSetting(settings.enableSelfHighlight); this->rebuildListener_.addSetting(settings.enableSelfHighlightSound); diff --git a/src/controllers/highlights/HighlightController.hpp b/src/controllers/highlights/HighlightController.hpp index 9f3951ba0..e05986a0e 100644 --- a/src/controllers/highlights/HighlightController.hpp +++ b/src/controllers/highlights/HighlightController.hpp @@ -86,7 +86,7 @@ struct HighlightCheck { class HighlightController final : public Singleton { public: - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; /** * @brief Checks the given message parameters if it matches our internal checks, and returns a result diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index cc356e650..6ea48d2ce 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -26,7 +26,7 @@ namespace chatterino { -void NotificationController::initialize(Settings &settings, Paths &paths) +void NotificationController::initialize(Settings &settings, const Paths &paths) { this->initialized_ = true; for (const QString &channelName : this->twitchSetting_.getValue()) diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp index 6d3dab7f9..ad70e029f 100644 --- a/src/controllers/notifications/NotificationController.hpp +++ b/src/controllers/notifications/NotificationController.hpp @@ -20,7 +20,7 @@ enum class Platform : uint8_t { class NotificationController final : public Singleton, private QObject { public: - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; bool isChannelNotified(const QString &channelName, Platform p); void updateChannelNotification(const QString &channelName, Platform p); diff --git a/src/controllers/sound/MiniaudioBackend.cpp b/src/controllers/sound/MiniaudioBackend.cpp index d9afa6c6c..f84ee8991 100644 --- a/src/controllers/sound/MiniaudioBackend.cpp +++ b/src/controllers/sound/MiniaudioBackend.cpp @@ -68,7 +68,7 @@ namespace chatterino { // NUM_SOUNDS specifies how many simultaneous default ping sounds & decoders to create constexpr const auto NUM_SOUNDS = 4; -void MiniaudioBackend::initialize(Settings &settings, Paths &paths) +void MiniaudioBackend::initialize(Settings &settings, const Paths &paths) { (void)(settings); (void)(paths); diff --git a/src/controllers/sound/MiniaudioBackend.hpp b/src/controllers/sound/MiniaudioBackend.hpp index ef730a06f..18ef9ed00 100644 --- a/src/controllers/sound/MiniaudioBackend.hpp +++ b/src/controllers/sound/MiniaudioBackend.hpp @@ -25,7 +25,7 @@ namespace chatterino { **/ class MiniaudioBackend : public ISoundController { - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; public: MiniaudioBackend(); diff --git a/src/providers/chatterino/ChatterinoBadges.cpp b/src/providers/chatterino/ChatterinoBadges.cpp index 131d3a7f5..5582d925a 100644 --- a/src/providers/chatterino/ChatterinoBadges.cpp +++ b/src/providers/chatterino/ChatterinoBadges.cpp @@ -11,7 +11,7 @@ #include namespace chatterino { -void ChatterinoBadges::initialize(Settings &settings, Paths &paths) +void ChatterinoBadges::initialize(Settings &settings, const Paths &paths) { this->loadChatterinoBadges(); } diff --git a/src/providers/chatterino/ChatterinoBadges.hpp b/src/providers/chatterino/ChatterinoBadges.hpp index 6d36940c1..0cba176f0 100644 --- a/src/providers/chatterino/ChatterinoBadges.hpp +++ b/src/providers/chatterino/ChatterinoBadges.hpp @@ -18,7 +18,7 @@ using EmotePtr = std::shared_ptr; class ChatterinoBadges : public Singleton { public: - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; ChatterinoBadges(); std::optional getBadge(const UserId &id); diff --git a/src/providers/ffz/FfzBadges.cpp b/src/providers/ffz/FfzBadges.cpp index d731f2a8c..557481835 100644 --- a/src/providers/ffz/FfzBadges.cpp +++ b/src/providers/ffz/FfzBadges.cpp @@ -16,7 +16,7 @@ namespace chatterino { -void FfzBadges::initialize(Settings &settings, Paths &paths) +void FfzBadges::initialize(Settings &settings, const Paths &paths) { this->load(); } diff --git a/src/providers/ffz/FfzBadges.hpp b/src/providers/ffz/FfzBadges.hpp index 1bf660200..a2fde9c8a 100644 --- a/src/providers/ffz/FfzBadges.hpp +++ b/src/providers/ffz/FfzBadges.hpp @@ -21,7 +21,7 @@ using EmotePtr = std::shared_ptr; class FfzBadges : public Singleton { public: - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; FfzBadges() = default; struct Badge { diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 6f5bbe095..111660aa2 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -64,7 +64,7 @@ TwitchIrcServer::TwitchIrcServer() // false); } -void TwitchIrcServer::initialize(Settings &settings, Paths &paths) +void TwitchIrcServer::initialize(Settings &settings, const Paths &paths) { getApp()->accounts->twitch.currentUserChanged.connect([this]() { postToThread([this] { diff --git a/src/providers/twitch/TwitchIrcServer.hpp b/src/providers/twitch/TwitchIrcServer.hpp index 8ddb713a4..d00f8e40b 100644 --- a/src/providers/twitch/TwitchIrcServer.hpp +++ b/src/providers/twitch/TwitchIrcServer.hpp @@ -43,7 +43,7 @@ public: TwitchIrcServer(); ~TwitchIrcServer() override = default; - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; void forEachChannelAndSpecialChannels(std::function func); diff --git a/src/singletons/CrashHandler.cpp b/src/singletons/CrashHandler.cpp index ea77b09a1..6d54212d4 100644 --- a/src/singletons/CrashHandler.cpp +++ b/src/singletons/CrashHandler.cpp @@ -128,7 +128,7 @@ namespace chatterino { using namespace std::string_literals; -void CrashHandler::initialize(Settings & /*settings*/, Paths &paths) +void CrashHandler::initialize(Settings & /*settings*/, const Paths &paths) { auto optSettings = readRecoverySettings(paths); if (optSettings) diff --git a/src/singletons/CrashHandler.hpp b/src/singletons/CrashHandler.hpp index 058e46aed..0398077a4 100644 --- a/src/singletons/CrashHandler.hpp +++ b/src/singletons/CrashHandler.hpp @@ -25,7 +25,7 @@ public: /// Sets and saves whether Chatterino should restart on a crash void saveShouldRecover(bool value); - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; private: bool shouldRecover_ = false; diff --git a/src/singletons/Emotes.cpp b/src/singletons/Emotes.cpp index 5b30faad3..5051dab69 100644 --- a/src/singletons/Emotes.cpp +++ b/src/singletons/Emotes.cpp @@ -6,7 +6,7 @@ Emotes::Emotes() { } -void Emotes::initialize(Settings &settings, Paths &paths) +void Emotes::initialize(Settings &settings, const Paths &paths) { this->emojis.load(); diff --git a/src/singletons/Emotes.hpp b/src/singletons/Emotes.hpp index 26286f34d..3ffeb6d7a 100644 --- a/src/singletons/Emotes.hpp +++ b/src/singletons/Emotes.hpp @@ -25,7 +25,7 @@ class Emotes final : public IEmotes, public Singleton public: Emotes(); - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; bool isIgnoredEmote(const QString &emote); diff --git a/src/singletons/Fonts.cpp b/src/singletons/Fonts.cpp index 79f1319f7..9705cbace 100644 --- a/src/singletons/Fonts.cpp +++ b/src/singletons/Fonts.cpp @@ -79,7 +79,7 @@ Fonts::Fonts() this->fontsByType_.resize(size_t(FontStyle::EndType)); } -void Fonts::initialize(Settings &, Paths &) +void Fonts::initialize(Settings &, const Paths &) { this->chatFontFamily.connect( [this]() { diff --git a/src/singletons/Fonts.hpp b/src/singletons/Fonts.hpp index 93529eb41..1f0704d99 100644 --- a/src/singletons/Fonts.hpp +++ b/src/singletons/Fonts.hpp @@ -43,7 +43,7 @@ class Fonts final : public Singleton public: Fonts(); - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; // font data gets set in createFontData(...) diff --git a/src/singletons/Paths.cpp b/src/singletons/Paths.cpp index 9d32acfdc..7c510bad3 100644 --- a/src/singletons/Paths.cpp +++ b/src/singletons/Paths.cpp @@ -38,7 +38,7 @@ bool Paths::isPortable() return Modes::instance().isPortable; } -QString Paths::cacheDirectory() +QString Paths::cacheDirectory() const { static const auto pathSetting = [] { QStringSetting cachePathSetting("/cache/path"); diff --git a/src/singletons/Paths.hpp b/src/singletons/Paths.hpp index 1974a79d6..50af83650 100644 --- a/src/singletons/Paths.hpp +++ b/src/singletons/Paths.hpp @@ -44,7 +44,7 @@ public: bool createFolder(const QString &folderPath); bool isPortable(); - QString cacheDirectory(); + QString cacheDirectory() const; private: void initAppFilePathHash(); diff --git a/src/singletons/Theme.cpp b/src/singletons/Theme.cpp index 45c4ff7f0..88f0252a6 100644 --- a/src/singletons/Theme.cpp +++ b/src/singletons/Theme.cpp @@ -219,7 +219,7 @@ bool Theme::isLightTheme() const return this->isLight_; } -void Theme::initialize(Settings &settings, Paths &paths) +void Theme::initialize(Settings &settings, const Paths &paths) { this->themeName.connect( [this](auto themeName) { diff --git a/src/singletons/Theme.hpp b/src/singletons/Theme.hpp index d2165543c..46ecea571 100644 --- a/src/singletons/Theme.hpp +++ b/src/singletons/Theme.hpp @@ -43,7 +43,7 @@ public: static const int AUTO_RELOAD_INTERVAL_MS = 500; - void initialize(Settings &settings, Paths &paths) final; + void initialize(Settings &settings, const Paths &paths) final; bool isLightTheme() const; diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index db51c69ed..516d7c502 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -338,7 +338,7 @@ void WindowManager::setEmotePopupPos(QPoint pos) this->emotePopupPos_ = pos; } -void WindowManager::initialize(Settings &settings, Paths &paths) +void WindowManager::initialize(Settings &settings, const Paths &paths) { (void)paths; assertInGuiThread(); diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index 4e3ed7d37..ee052479e 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -93,7 +93,7 @@ public: QPoint emotePopupPos(); void setEmotePopupPos(QPoint pos); - void initialize(Settings &settings, Paths &paths) override; + void initialize(Settings &settings, const Paths &paths) override; void save() override; void closeAll();