From 5deec1f02f0ef00bcd187d06b14ba2a43847f732 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 21 Jul 2024 15:09:59 +0200 Subject: [PATCH] chore: remove Singleton & replace getIApp with getApp (#5514) --- benchmarks/src/Highlights.cpp | 10 +- benchmarks/src/RecentMessages.cpp | 9 +- mocks/include/mocks/BaseApplication.hpp | 37 +++++ mocks/include/mocks/EmptyApplication.hpp | 13 +- src/Application.cpp | 137 +++++++++++------- src/Application.hpp | 59 +++----- src/CMakeLists.txt | 2 - src/RunGui.cpp | 2 +- src/common/Channel.cpp | 6 +- src/common/Credentials.cpp | 2 +- src/common/Singleton.hpp | 31 ---- src/common/network/NetworkPrivate.cpp | 2 +- src/common/network/NetworkTask.cpp | 2 +- .../accounts/AccountController.cpp | 2 +- .../accounts/AccountController.hpp | 8 +- .../commands/CommandController.cpp | 12 +- .../commands/CommandController.hpp | 7 +- src/controllers/commands/builtin/Misc.cpp | 23 ++- .../commands/builtin/twitch/AddModerator.cpp | 2 +- .../commands/builtin/twitch/AddVIP.cpp | 2 +- .../commands/builtin/twitch/Announce.cpp | 2 +- .../commands/builtin/twitch/Ban.cpp | 6 +- .../commands/builtin/twitch/Block.cpp | 8 +- .../commands/builtin/twitch/ChatSettings.cpp | 20 +-- .../commands/builtin/twitch/Chatters.cpp | 4 +- .../builtin/twitch/DeleteMessages.cpp | 2 +- .../commands/builtin/twitch/GetVIPs.cpp | 2 +- .../commands/builtin/twitch/Raid.cpp | 4 +- .../builtin/twitch/RemoveModerator.cpp | 2 +- .../commands/builtin/twitch/RemoveVIP.cpp | 2 +- .../commands/builtin/twitch/SendWhisper.cpp | 10 +- .../commands/builtin/twitch/ShieldMode.cpp | 2 +- .../commands/builtin/twitch/Shoutout.cpp | 2 +- .../builtin/twitch/StartCommercial.cpp | 2 +- .../commands/builtin/twitch/Unban.cpp | 2 +- .../commands/builtin/twitch/UpdateColor.cpp | 2 +- .../commands/builtin/twitch/Warn.cpp | 2 +- .../completion/TabCompletionModel.cpp | 2 +- .../completion/sources/CommandSource.cpp | 6 +- .../completion/sources/EmoteSource.cpp | 2 +- src/controllers/filters/lang/Filter.cpp | 2 +- .../highlights/BadgeHighlightModel.cpp | 2 +- .../highlights/HighlightController.cpp | 16 +- .../highlights/HighlightController.hpp | 9 +- src/controllers/highlights/HighlightModel.cpp | 2 +- .../highlights/UserHighlightModel.cpp | 2 +- src/controllers/hotkeys/Hotkey.cpp | 2 +- src/controllers/hotkeys/HotkeyController.hpp | 5 +- src/controllers/ignores/IgnoreController.cpp | 2 +- src/controllers/ignores/IgnorePhrase.cpp | 2 +- .../notifications/NotificationController.cpp | 24 +-- .../notifications/NotificationController.hpp | 8 +- src/controllers/plugins/LuaAPI.cpp | 14 +- src/controllers/plugins/Plugin.cpp | 2 +- src/controllers/plugins/PluginController.cpp | 6 +- src/controllers/plugins/PluginController.hpp | 5 +- src/controllers/plugins/api/ChannelRef.cpp | 6 +- src/controllers/plugins/api/HTTPRequest.cpp | 2 +- src/controllers/twitch/LiveController.hpp | 3 +- src/messages/Image.cpp | 6 +- src/messages/MessageBuilder.cpp | 12 +- src/messages/MessageElement.cpp | 4 +- src/messages/SharedMessageBuilder.cpp | 8 +- src/messages/layouts/MessageLayout.cpp | 4 +- .../layouts/MessageLayoutContainer.cpp | 2 +- src/providers/ffz/FfzBadges.cpp | 7 +- src/providers/ffz/FfzBadges.hpp | 6 +- src/providers/irc/Irc2.cpp | 2 +- src/providers/irc/IrcServer.cpp | 2 +- src/providers/seventv/SeventvAPI.hpp | 6 +- src/providers/seventv/SeventvBadges.hpp | 3 +- src/providers/seventv/SeventvEmotes.cpp | 6 +- src/providers/seventv/SeventvEventAPI.cpp | 6 +- src/providers/twitch/IrcMessageHandler.cpp | 53 ++++--- src/providers/twitch/TwitchAccount.cpp | 6 +- src/providers/twitch/TwitchChannel.cpp | 74 +++++----- src/providers/twitch/TwitchIrcServer.cpp | 12 +- src/providers/twitch/TwitchMessageBuilder.cpp | 29 ++-- src/singletons/Badges.cpp | 9 -- src/singletons/Badges.hpp | 13 -- src/singletons/CrashHandler.cpp | 4 - src/singletons/CrashHandler.hpp | 6 +- src/singletons/Emotes.cpp | 9 -- src/singletons/Emotes.hpp | 10 +- src/singletons/ImageUploader.cpp | 6 +- src/singletons/ImageUploader.hpp | 5 +- src/singletons/NativeMessaging.cpp | 11 +- src/singletons/StreamerMode.cpp | 4 +- src/singletons/Theme.cpp | 6 +- src/singletons/Theme.hpp | 6 +- src/singletons/Toasts.cpp | 4 +- src/singletons/Toasts.hpp | 4 +- src/singletons/WindowManager.cpp | 27 ++-- src/singletons/WindowManager.hpp | 11 +- src/singletons/helper/GifTimer.cpp | 2 +- src/singletons/helper/LoggingChannel.cpp | 2 +- src/util/InitUpdateButton.cpp | 10 +- src/util/StreamLink.cpp | 2 +- src/widgets/BaseWidget.cpp | 2 +- src/widgets/BaseWindow.cpp | 6 +- src/widgets/FramelessEmbedWindow.cpp | 2 +- src/widgets/Label.cpp | 8 +- src/widgets/Notebook.cpp | 34 ++--- src/widgets/TooltipWidget.cpp | 8 +- src/widgets/Window.cpp | 51 ++++--- src/widgets/dialogs/BadgePickerDialog.cpp | 2 +- src/widgets/dialogs/EditHotkeyDialog.cpp | 17 +-- src/widgets/dialogs/EmotePopup.cpp | 34 ++--- src/widgets/dialogs/LoginDialog.cpp | 4 +- src/widgets/dialogs/QualityPopup.cpp | 2 +- src/widgets/dialogs/ReplyThreadPopup.cpp | 8 +- src/widgets/dialogs/SelectChannelDialog.cpp | 14 +- src/widgets/dialogs/SettingsDialog.cpp | 8 +- src/widgets/dialogs/UpdateDialog.cpp | 14 +- src/widgets/dialogs/UserInfoPopup.cpp | 38 ++--- src/widgets/dialogs/switcher/NewPopupItem.cpp | 8 +- src/widgets/dialogs/switcher/NewTabItem.cpp | 6 +- .../dialogs/switcher/SwitchSplitItem.cpp | 10 +- src/widgets/helper/ChannelView.cpp | 71 +++++---- src/widgets/helper/NotebookTab.cpp | 12 +- src/widgets/helper/SearchPopup.cpp | 4 +- src/widgets/settingspages/AccountsPage.cpp | 2 +- src/widgets/settingspages/CommandPage.cpp | 6 +- src/widgets/settingspages/GeneralPage.cpp | 32 ++-- src/widgets/settingspages/GeneralPageView.cpp | 2 +- src/widgets/settingspages/GeneralPageView.hpp | 6 +- .../settingspages/KeyboardSettingsPage.cpp | 14 +- src/widgets/settingspages/ModerationPage.cpp | 26 ++-- .../settingspages/NotificationPage.cpp | 2 +- src/widgets/settingspages/PluginsPage.cpp | 8 +- src/widgets/settingspages/SettingsPage.cpp | 2 +- src/widgets/splits/Split.cpp | 45 +++--- src/widgets/splits/SplitContainer.cpp | 26 ++-- src/widgets/splits/SplitHeader.cpp | 16 +- src/widgets/splits/SplitInput.cpp | 16 +- src/widgets/splits/SplitOverlay.cpp | 4 +- tests/src/Commands.cpp | 23 ++- tests/src/Filters.cpp | 7 + tests/src/HighlightController.cpp | 49 ++----- tests/src/InputCompletion.cpp | 4 +- tests/src/MessageLayout.cpp | 14 +- tests/src/NotebookTab.cpp | 1 + tests/src/Scrollbar.cpp | 7 +- tests/src/SplitInput.cpp | 11 +- tests/src/TwitchMessageBuilder.cpp | 7 + 145 files changed, 802 insertions(+), 856 deletions(-) create mode 100644 mocks/include/mocks/BaseApplication.hpp delete mode 100644 src/common/Singleton.hpp delete mode 100644 src/singletons/Badges.cpp delete mode 100644 src/singletons/Badges.hpp diff --git a/benchmarks/src/Highlights.cpp b/benchmarks/src/Highlights.cpp index c363e508c..12b70d33a 100644 --- a/benchmarks/src/Highlights.cpp +++ b/benchmarks/src/Highlights.cpp @@ -5,7 +5,7 @@ #include "controllers/highlights/HighlightPhrase.hpp" #include "messages/Message.hpp" #include "messages/SharedMessageBuilder.hpp" -#include "mocks/EmptyApplication.hpp" +#include "mocks/BaseApplication.hpp" #include "singletons/Settings.hpp" #include "util/Helpers.hpp" @@ -47,9 +47,14 @@ public: } }; -class MockApplication : mock::EmptyApplication +class MockApplication : public mock::BaseApplication { public: + MockApplication() + : highlights(this->settings, &this->accounts) + { + } + AccountController *getAccounts() override { return &this->accounts; @@ -61,7 +66,6 @@ public: AccountController accounts; HighlightController highlights; - // TODO: Figure this out }; static void BM_HighlightTest(benchmark::State &state) diff --git a/benchmarks/src/RecentMessages.cpp b/benchmarks/src/RecentMessages.cpp index 7f2c0c7ac..24ebd127f 100644 --- a/benchmarks/src/RecentMessages.cpp +++ b/benchmarks/src/RecentMessages.cpp @@ -2,8 +2,8 @@ #include "controllers/accounts/AccountController.hpp" #include "controllers/highlights/HighlightController.hpp" #include "messages/Emote.hpp" +#include "mocks/BaseApplication.hpp" #include "mocks/DisabledStreamerMode.hpp" -#include "mocks/EmptyApplication.hpp" #include "mocks/LinkResolver.hpp" #include "mocks/TwitchIrcServer.hpp" #include "mocks/UserData.hpp" @@ -32,9 +32,14 @@ using namespace literals; namespace { -class MockApplication : mock::EmptyApplication +class MockApplication : public mock::BaseApplication { public: + MockApplication() + : highlights(this->settings, &this->accounts) + { + } + IEmotes *getEmotes() override { return &this->emotes; diff --git a/mocks/include/mocks/BaseApplication.hpp b/mocks/include/mocks/BaseApplication.hpp new file mode 100644 index 000000000..720d1f684 --- /dev/null +++ b/mocks/include/mocks/BaseApplication.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include "mocks/DisabledStreamerMode.hpp" +#include "mocks/EmptyApplication.hpp" +#include "singletons/Settings.hpp" + +#include + +namespace chatterino::mock { + +/** + * BaseApplication intends to be a mock application with a few more sane defaults, but with less configurability + */ +class BaseApplication : public EmptyApplication +{ +public: + BaseApplication() + : settings(this->settingsDir.filePath("settings.json")) + { + } + + explicit BaseApplication(const QString &settingsData) + : EmptyApplication(settingsData) + , settings(this->settingsDir.filePath("settings.json")) + { + } + + IStreamerMode *getStreamerMode() override + { + return &this->streamerMode; + } + + Settings settings; + DisabledStreamerMode streamerMode; +}; + +} // namespace chatterino::mock diff --git a/mocks/include/mocks/EmptyApplication.hpp b/mocks/include/mocks/EmptyApplication.hpp index 233211bfa..e293a56e4 100644 --- a/mocks/include/mocks/EmptyApplication.hpp +++ b/mocks/include/mocks/EmptyApplication.hpp @@ -17,7 +17,17 @@ public: { } - virtual ~EmptyApplication() = default; + explicit EmptyApplication(const QString &settingsData) + : EmptyApplication() + { + QFile settingsFile(this->settingsDir.filePath("settings.json")); + settingsFile.open(QIODevice::WriteOnly | QIODevice::Text); + settingsFile.write(settingsData.toUtf8()); + settingsFile.flush(); + settingsFile.close(); + } + + ~EmptyApplication() override = default; bool isTest() const override { @@ -249,7 +259,6 @@ public: return nullptr; } -protected: QTemporaryDir settingsDir; Paths paths_; Args args_; diff --git a/src/Application.cpp b/src/Application.cpp index 30e7cdb26..6020fb865 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -118,26 +118,26 @@ Application::Application(Settings &_settings, const Paths &paths, const Args &_args, Updates &_updates) : paths_(paths) , args_(_args) - , themes(&this->emplace()) + , themes(new Theme(paths)) , fonts(new Fonts(_settings)) - , emotes(&this->emplace()) - , accounts(&this->emplace()) - , hotkeys(&this->emplace()) - , windows(&this->emplace(new WindowManager(paths))) - , toasts(&this->emplace()) - , imageUploader(&this->emplace()) - , seventvAPI(&this->emplace()) - , crashHandler(&this->emplace(new CrashHandler(paths))) + , emotes(new Emotes) + , accounts(new AccountController) + , hotkeys(new HotkeyController) + , windows(new WindowManager(paths)) + , toasts(new Toasts) + , imageUploader(new ImageUploader) + , seventvAPI(new SeventvAPI) + , crashHandler(new CrashHandler(paths)) - , commands(&this->emplace()) - , notifications(&this->emplace()) - , highlights(&this->emplace()) + , commands(new CommandController(paths)) + , notifications(new NotificationController) + , highlights(new HighlightController(_settings, this->accounts.get())) , twitch(new TwitchIrcServer) - , ffzBadges(&this->emplace()) - , seventvBadges(&this->emplace()) + , ffzBadges(new FfzBadges) + , seventvBadges(new SeventvBadges) , userData(new UserDataController(paths)) , sound(makeSoundController(_settings)) - , twitchLiveController(&this->emplace()) + , twitchLiveController(new TwitchLiveController) , twitchPubSub(new PubSub(TWITCH_PUBSUB_URL)) , twitchBadges(new TwitchBadges) , chatterinoBadges(new ChatterinoBadges) @@ -148,7 +148,7 @@ Application::Application(Settings &_settings, const Paths &paths, , linkResolver(new LinkResolver) , streamerMode(new StreamerMode) #ifdef CHATTERINO_HAVE_PLUGINS - , plugins(&this->emplace(new PluginController(paths))) + , plugins(new PluginController(paths)) #endif , updates(_updates) { @@ -165,16 +165,35 @@ Application::~Application() = default; void Application::fakeDtor() { +#ifdef CHATTERINO_HAVE_PLUGINS + this->plugins.reset(); +#endif this->twitchPubSub.reset(); this->twitchBadges.reset(); + this->twitchLiveController.reset(); this->chatterinoBadges.reset(); this->bttvEmotes.reset(); this->ffzEmotes.reset(); this->seventvEmotes.reset(); + this->notifications.reset(); + this->commands.reset(); + // If a crash happens after crashHandler has been reset, we'll assert + // This isn't super different from before, where if the app is already killed, the getApp() portion of it is already dead + this->crashHandler.reset(); + this->seventvAPI.reset(); + this->highlights.reset(); + this->seventvBadges.reset(); + this->ffzBadges.reset(); // this->twitch.reset(); + this->imageUploader.reset(); + this->hotkeys.reset(); this->fonts.reset(); this->sound.reset(); this->userData.reset(); + this->toasts.reset(); + this->accounts.reset(); + this->emotes.reset(); + this->themes.reset(); } void Application::initialize(Settings &settings, const Paths &paths) @@ -208,17 +227,24 @@ void Application::initialize(Settings &settings, const Paths &paths) } } - for (auto &singleton : this->singletons_) - { - singleton->initialize(settings, paths); - } + this->accounts->load(); + this->windows->initialize(settings); + + this->ffzBadges->load(); this->twitch->initialize(); + // Load live status + this->notifications->initialize(); + // XXX: Loading Twitch badges after Helix has been initialized, which only happens after // the AccountController initialize has been called this->twitchBadges->loadTwitchBadges(); +#ifdef CHATTERINO_HAVE_PLUGINS + this->plugins->initialize(settings); +#endif + // Show crash message. // On Windows, the crash message was already shown. #ifndef Q_OS_WIN @@ -335,8 +361,9 @@ int Application::run(QApplication &qtApp) Theme *Application::getThemes() { assertInGuiThread(); + assert(this->themes); - return this->themes; + return this->themes.get(); } Fonts *Application::getFonts() @@ -350,22 +377,25 @@ Fonts *Application::getFonts() IEmotes *Application::getEmotes() { assertInGuiThread(); + assert(this->emotes); - return this->emotes; + return this->emotes.get(); } AccountController *Application::getAccounts() { assertInGuiThread(); + assert(this->accounts); - return this->accounts; + return this->accounts.get(); } HotkeyController *Application::getHotkeys() { assertInGuiThread(); + assert(this->hotkeys); - return this->hotkeys; + return this->hotkeys.get(); } WindowManager *Application::getWindows() @@ -373,56 +403,63 @@ WindowManager *Application::getWindows() assertInGuiThread(); assert(this->windows); - return this->windows; + return this->windows.get(); } Toasts *Application::getToasts() { assertInGuiThread(); + assert(this->toasts); - return this->toasts; + return this->toasts.get(); } CrashHandler *Application::getCrashHandler() { assertInGuiThread(); + assert(this->crashHandler); - return this->crashHandler; + return this->crashHandler.get(); } CommandController *Application::getCommands() { assertInGuiThread(); + assert(this->commands); - return this->commands; + return this->commands.get(); } NotificationController *Application::getNotifications() { assertInGuiThread(); + assert(this->notifications); - return this->notifications; + return this->notifications.get(); } HighlightController *Application::getHighlights() { assertInGuiThread(); + assert(this->highlights); - return this->highlights; + return this->highlights.get(); } FfzBadges *Application::getFfzBadges() { assertInGuiThread(); + assert(this->ffzBadges); - return this->ffzBadges; + return this->ffzBadges.get(); } SeventvBadges *Application::getSeventvBadges() { // SeventvBadges handles its own locks, so we don't need to assert that this is called in the GUI thread + assert(this->seventvBadges); - return this->seventvBadges; + return this->seventvBadges.get(); } IUserDataController *Application::getUserData() @@ -442,8 +479,9 @@ ISoundController *Application::getSound() ITwitchLiveController *Application::getTwitchLiveController() { assertInGuiThread(); + assert(this->twitchLiveController); - return this->twitchLiveController; + return this->twitchLiveController.get(); } TwitchBadges *Application::getTwitchBadges() @@ -465,23 +503,26 @@ IChatterinoBadges *Application::getChatterinoBadges() ImageUploader *Application::getImageUploader() { assertInGuiThread(); + assert(this->imageUploader); - return this->imageUploader; + return this->imageUploader.get(); } SeventvAPI *Application::getSeventvAPI() { assertInGuiThread(); + assert(this->seventvAPI); - return this->seventvAPI; + return this->seventvAPI.get(); } #ifdef CHATTERINO_HAVE_PLUGINS PluginController *Application::getPlugins() { assertInGuiThread(); + assert(this->plugins); - return this->plugins; + return this->plugins.get(); } #endif @@ -551,10 +592,9 @@ SeventvEmotes *Application::getSeventvEmotes() void Application::save() { - for (auto &singleton : this->singletons_) - { - singleton->save(); - } + this->commands->save(); + this->hotkeys->save(); + this->windows->save(); } void Application::initNm(const Paths &paths) @@ -896,11 +936,11 @@ void Application::initPubSub() chan->addMessage(p.second, MessageContext::Original); - getIApp() + getApp() ->getTwitch() ->getAutomodChannel() ->addMessage(p.first, MessageContext::Original); - getIApp() + getApp() ->getTwitch() ->getAutomodChannel() ->addMessage(p.second, @@ -908,12 +948,12 @@ void Application::initPubSub() if (getSettings()->showAutomodInMentions) { - getIApp() + getApp() ->getTwitch() ->getMentionsChannel() ->addMessage(p.first, MessageContext::Original); - getIApp() + getApp() ->getTwitch() ->getMentionsChannel() ->addMessage(p.second, @@ -1124,14 +1164,7 @@ void Application::initSeventvEventAPI() seventvEventAPI->start(); } -Application *getApp() -{ - assert(Application::instance != nullptr); - - return Application::instance; -} - -IApplication *getIApp() +IApplication *getApp() { assert(IApplication::instance != nullptr); diff --git a/src/Application.hpp b/src/Application.hpp index af1c563a8..59ca9b1a3 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -1,6 +1,5 @@ #pragma once -#include "common/Singleton.hpp" #include "debug/AssertInGuiThread.hpp" #include "singletons/NativeMessaging.hpp" @@ -108,7 +107,6 @@ class Application : public IApplication { const Paths &paths_; const Args &args_; - std::vector> singletons_; int argc_{}; char **argv_{}; @@ -144,25 +142,25 @@ public: friend void test(); private: - Theme *const themes{}; - std::unique_ptr fonts{}; - Emotes *const emotes{}; - AccountController *const accounts{}; - HotkeyController *const hotkeys{}; - WindowManager *const windows{}; - Toasts *const toasts{}; - ImageUploader *const imageUploader{}; - SeventvAPI *const seventvAPI{}; - CrashHandler *const crashHandler{}; - CommandController *const commands{}; - NotificationController *const notifications{}; - HighlightController *const highlights{}; + std::unique_ptr themes; + std::unique_ptr fonts; + std::unique_ptr emotes; + std::unique_ptr accounts; + std::unique_ptr hotkeys; + std::unique_ptr windows; + std::unique_ptr toasts; + std::unique_ptr imageUploader; + std::unique_ptr seventvAPI; + std::unique_ptr crashHandler; + std::unique_ptr commands; + std::unique_ptr notifications; + std::unique_ptr highlights; std::unique_ptr twitch; - FfzBadges *const ffzBadges{}; - SeventvBadges *const seventvBadges{}; + std::unique_ptr ffzBadges; + std::unique_ptr seventvBadges; std::unique_ptr userData; std::unique_ptr sound; - TwitchLiveController *const twitchLiveController{}; + std::unique_ptr twitchLiveController; std::unique_ptr twitchPubSub; std::unique_ptr twitchBadges; std::unique_ptr chatterinoBadges; @@ -173,7 +171,7 @@ private: std::unique_ptr linkResolver; std::unique_ptr streamerMode; #ifdef CHATTERINO_HAVE_PLUGINS - PluginController *const plugins{}; + std::unique_ptr plugins; #endif public: @@ -227,36 +225,15 @@ public: IStreamerMode *getStreamerMode() override; private: - void addSingleton(Singleton *singleton); void initPubSub(); void initBttvLiveUpdates(); void initSeventvEventAPI(); void initNm(const Paths &paths); - template ::value>> - T &emplace() - { - auto t = new T; - this->singletons_.push_back(std::unique_ptr(t)); - return *t; - } - - template ::value>> - T &emplace(T *t) - { - this->singletons_.push_back(std::unique_ptr(t)); - return *t; - } - NativeMessagingServer nmServer{}; Updates &updates; }; -Application *getApp(); - -// Get an interface version of the Application class - should be preferred when possible for new code -IApplication *getIApp(); +IApplication *getApp(); } // namespace chatterino diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e6f0939b..42823b259 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -444,8 +444,6 @@ set(SOURCE_FILES providers/twitch/api/Helix.cpp providers/twitch/api/Helix.hpp - singletons/Badges.cpp - singletons/Badges.hpp singletons/CrashHandler.cpp singletons/CrashHandler.hpp singletons/Emotes.cpp diff --git a/src/RunGui.cpp b/src/RunGui.cpp index 6fba9c6af..06e9a7b94 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -131,7 +131,7 @@ namespace { using namespace std::chrono_literals; if (std::chrono::steady_clock::now() - signalsInitTime > 30s && - getIApp()->getCrashHandler()->shouldRecover()) + getApp()->getCrashHandler()->shouldRecover()) { QProcess proc; diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 76dd8bb86..bbf58f0a7 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -100,9 +100,9 @@ void Channel::addMessage(MessagePtr message, MessageContext context, if (!isDoNotLogSet) { // Only log messages where the `DoNotLog` flag is not set - getIApp()->getChatLogger()->addMessage(this->name_, message, - this->platform_, - this->getCurrentStreamID()); + getApp()->getChatLogger()->addMessage(this->name_, message, + this->platform_, + this->getCurrentStreamID()); } } diff --git a/src/common/Credentials.cpp b/src/common/Credentials.cpp index 5fffe013f..68c9cdd59 100644 --- a/src/common/Credentials.cpp +++ b/src/common/Credentials.cpp @@ -56,7 +56,7 @@ bool useKeyring() // Insecure storage: QString insecurePath() { - return combinePath(getIApp()->getPaths().settingsDirectory, + return combinePath(getApp()->getPaths().settingsDirectory, "credentials.json"); } diff --git a/src/common/Singleton.hpp b/src/common/Singleton.hpp deleted file mode 100644 index f94d7152a..000000000 --- a/src/common/Singleton.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -namespace chatterino { - -class Settings; -class Paths; - -class Singleton -{ -public: - Singleton() = default; - virtual ~Singleton() = default; - - Singleton(const Singleton &) = delete; - Singleton &operator=(const Singleton &) = delete; - - Singleton(Singleton &&) = delete; - Singleton &operator=(Singleton &&) = delete; - - virtual void initialize(Settings &settings, const Paths &paths) - { - (void)(settings); - (void)(paths); - } - - virtual void save() - { - } -}; - -} // namespace chatterino diff --git a/src/common/network/NetworkPrivate.cpp b/src/common/network/NetworkPrivate.cpp index ed81dd9e6..425a1f5f2 100644 --- a/src/common/network/NetworkPrivate.cpp +++ b/src/common/network/NetworkPrivate.cpp @@ -59,7 +59,7 @@ void loadUncached(std::shared_ptr &&data) void loadCached(std::shared_ptr &&data) { - QFile cachedFile(getIApp()->getPaths().cacheDirectory() + "/" + + QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" + data->getHash()); if (!cachedFile.exists() || !cachedFile.open(QIODevice::ReadOnly)) diff --git a/src/common/network/NetworkTask.cpp b/src/common/network/NetworkTask.cpp index 256743a4f..bebe34051 100644 --- a/src/common/network/NetworkTask.cpp +++ b/src/common/network/NetworkTask.cpp @@ -118,7 +118,7 @@ void NetworkTask::logReply() void NetworkTask::writeToCache(const QByteArray &bytes) const { std::ignore = QtConcurrent::run([data = this->data_, bytes] { - QFile cachedFile(getIApp()->getPaths().cacheDirectory() + "/" + + QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" + data->getHash()); if (cachedFile.open(QIODevice::WriteOnly)) diff --git a/src/controllers/accounts/AccountController.cpp b/src/controllers/accounts/AccountController.cpp index d0643cdef..414cb8b56 100644 --- a/src/controllers/accounts/AccountController.cpp +++ b/src/controllers/accounts/AccountController.cpp @@ -47,7 +47,7 @@ AccountController::AccountController() }); } -void AccountController::initialize(Settings &settings, const Paths &paths) +void AccountController::load() { this->twitch.load(); } diff --git a/src/controllers/accounts/AccountController.hpp b/src/controllers/accounts/AccountController.hpp index 726719f5c..d84e2b9cc 100644 --- a/src/controllers/accounts/AccountController.hpp +++ b/src/controllers/accounts/AccountController.hpp @@ -1,7 +1,6 @@ #pragma once #include "common/SignalVector.hpp" -#include "common/Singleton.hpp" #include "providers/twitch/TwitchAccountManager.hpp" #include @@ -14,14 +13,17 @@ class Paths; class AccountModel; -class AccountController final : public Singleton +class AccountController final { public: AccountController(); AccountModel *createModel(QObject *parent); - void initialize(Settings &settings, const Paths &paths) override; + /** + * Load current user & send off a signal to subscribers about any potential changes + */ + void load(); TwitchAccountManager twitch; diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 4742088e4..397e36d95 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -121,7 +121,7 @@ const std::unordered_map COMMAND_VARS{ (void)(channel); //unused (void)(message); //unused auto uid = - getIApp()->getAccounts()->twitch.getCurrent()->getUserId(); + getApp()->getAccounts()->twitch.getCurrent()->getUserId(); return uid.isEmpty() ? altText : uid; }, }, @@ -131,7 +131,7 @@ const std::unordered_map COMMAND_VARS{ (void)(channel); //unused (void)(message); //unused auto name = - getIApp()->getAccounts()->twitch.getCurrent()->getUserName(); + getApp()->getAccounts()->twitch.getCurrent()->getUserName(); return name.isEmpty() ? altText : name; }, }, @@ -263,7 +263,7 @@ const std::unordered_map COMMAND_VARS{ namespace chatterino { -void CommandController::initialize(Settings &, const Paths &paths) +CommandController::CommandController(const Paths &paths) { // Update commands map when the vector of commands has been updated auto addFirstMatchToMap = [this](auto args) { @@ -485,7 +485,7 @@ QString CommandController::execCommand(const QString &textNoEmoji, ChannelPtr channel, bool dryRun) { QString text = - getIApp()->getEmotes()->getEmojis()->replaceShortCodes(textNoEmoji); + getApp()->getEmotes()->getEmojis()->replaceShortCodes(textNoEmoji); QStringList words = text.split(' ', Qt::SkipEmptyParts); if (words.length() == 0) @@ -500,7 +500,7 @@ QString CommandController::execCommand(const QString &textNoEmoji, const auto it = this->userCommands_.find(commandName); if (it != this->userCommands_.end()) { - text = getIApp()->getEmotes()->getEmojis()->replaceShortCodes( + text = getApp()->getEmotes()->getEmojis()->replaceShortCodes( this->execCustomCommand(words, it.value(), dryRun, channel)); words = text.split(' ', Qt::SkipEmptyParts); @@ -570,7 +570,7 @@ bool CommandController::registerPluginCommand(const QString &commandName) } this->commands_[commandName] = [commandName](const CommandContext &ctx) { - return getIApp()->getPlugins()->tryExecPluginCommand(commandName, ctx); + return getApp()->getPlugins()->tryExecPluginCommand(commandName, ctx); }; this->pluginCommands_.append(commandName); return true; diff --git a/src/controllers/commands/CommandController.hpp b/src/controllers/commands/CommandController.hpp index d13197e4f..d730c671d 100644 --- a/src/controllers/commands/CommandController.hpp +++ b/src/controllers/commands/CommandController.hpp @@ -1,7 +1,6 @@ #pragma once #include "common/SignalVector.hpp" -#include "common/Singleton.hpp" #include "util/QStringHash.hpp" #include @@ -24,7 +23,7 @@ struct Command; class CommandModel; struct CommandContext; -class CommandController final : public Singleton +class CommandController final { public: SignalVector items; @@ -33,8 +32,8 @@ public: bool dryRun); QStringList getDefaultChatterinoCommandList(); - void initialize(Settings &, const Paths &paths) override; - void save() override; + CommandController(const Paths &paths); + void save(); CommandModel *createModel(QObject *parent); diff --git a/src/controllers/commands/builtin/Misc.cpp b/src/controllers/commands/builtin/Misc.cpp index 9be6438ce..0b34dc5b4 100644 --- a/src/controllers/commands/builtin/Misc.cpp +++ b/src/controllers/commands/builtin/Misc.cpp @@ -220,7 +220,7 @@ QString marker(const CommandContext &ctx) } // Avoid Helix calls without Client ID and/or OAuth Token - if (getIApp()->getAccounts()->twitch.getCurrent()->isAnon()) + if (getApp()->getAccounts()->twitch.getCurrent()->isAnon()) { ctx.channel->addSystemMessage( "You need to be logged in to create stream markers!"); @@ -367,7 +367,7 @@ QString popup(const CommandContext &ctx) if (target.isEmpty()) { auto *currentPage = - dynamic_cast(getIApp() + dynamic_cast(getApp() ->getWindows() ->getMainWindow() .getNotebook() @@ -388,9 +388,8 @@ QString popup(const CommandContext &ctx) } // Open channel passed as argument in a popup - auto targetChannel = - getIApp()->getTwitchAbstract()->getOrAddChannel(target); - getIApp()->getWindows()->openInPopup(targetChannel); + auto targetChannel = getApp()->getTwitchAbstract()->getOrAddChannel(target); + getApp()->getWindows()->openInPopup(targetChannel); return ""; } @@ -399,7 +398,7 @@ QString clearmessages(const CommandContext &ctx) { (void)ctx; - auto *currentPage = getIApp() + auto *currentPage = getApp() ->getWindows() ->getLastSelectedWindow() ->getNotebook() @@ -531,7 +530,7 @@ QString sendRawMessage(const CommandContext &ctx) if (ctx.channel->isTwitchChannel()) { - getIApp()->getTwitchAbstract()->sendRawMessage( + getApp()->getTwitchAbstract()->sendRawMessage( ctx.words.mid(1).join(" ")); } else @@ -565,7 +564,7 @@ QString injectFakeMessage(const CommandContext &ctx) } auto ircText = ctx.words.mid(1).join(" "); - getIApp()->getTwitchAbstract()->addFakeMessage(ircText); + getApp()->getTwitchAbstract()->addFakeMessage(ircText); return ""; } @@ -634,7 +633,7 @@ QString unstableSetUserClientSideColor(const CommandContext &ctx) auto color = ctx.words.value(2); - getIApp()->getUserData()->setUserColor(userID, color); + getApp()->getUserData()->setUserColor(userID, color); return ""; } @@ -664,7 +663,7 @@ QString openUsercard(const CommandContext &ctx) stripChannelName(channelName); ChannelPtr channelTemp = - getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); + getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); if (channelTemp->isEmpty()) { @@ -679,7 +678,7 @@ QString openUsercard(const CommandContext &ctx) // try to link to current split if possible Split *currentSplit = nullptr; - auto *currentPage = dynamic_cast(getIApp() + auto *currentPage = dynamic_cast(getApp() ->getWindows() ->getMainWindow() .getNotebook() @@ -695,7 +694,7 @@ QString openUsercard(const CommandContext &ctx) { // not possible to use current split, try searching for one const auto ¬ebook = - getIApp()->getWindows()->getMainWindow().getNotebook(); + getApp()->getWindows()->getMainWindow().getNotebook(); auto count = notebook.getPageCount(); for (int i = 0; i < count; i++) { diff --git a/src/controllers/commands/builtin/twitch/AddModerator.cpp b/src/controllers/commands/builtin/twitch/AddModerator.cpp index 6d06d9f82..bedd74631 100644 --- a/src/controllers/commands/builtin/twitch/AddModerator.cpp +++ b/src/controllers/commands/builtin/twitch/AddModerator.cpp @@ -32,7 +32,7 @@ QString addModerator(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage("You must be logged in to mod someone!"); diff --git a/src/controllers/commands/builtin/twitch/AddVIP.cpp b/src/controllers/commands/builtin/twitch/AddVIP.cpp index 26d374192..9a50e8313 100644 --- a/src/controllers/commands/builtin/twitch/AddVIP.cpp +++ b/src/controllers/commands/builtin/twitch/AddVIP.cpp @@ -32,7 +32,7 @@ QString addVIP(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage("You must be logged in to VIP someone!"); diff --git a/src/controllers/commands/builtin/twitch/Announce.cpp b/src/controllers/commands/builtin/twitch/Announce.cpp index 67212858e..250b239f4 100644 --- a/src/controllers/commands/builtin/twitch/Announce.cpp +++ b/src/controllers/commands/builtin/twitch/Announce.cpp @@ -50,7 +50,7 @@ QString sendAnnouncementColor(const CommandContext &ctx, return ""; } - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); if (user->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/Ban.cpp b/src/controllers/commands/builtin/twitch/Ban.cpp index d2a77486f..819231524 100644 --- a/src/controllers/commands/builtin/twitch/Ban.cpp +++ b/src/controllers/commands/builtin/twitch/Ban.cpp @@ -141,7 +141,7 @@ QString sendBan(const CommandContext &ctx) assert(!actions.value().empty()); - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage("You must be logged in to ban someone!"); @@ -252,7 +252,7 @@ QString sendBanById(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { channel->addSystemMessage("You must be logged in to ban someone!"); @@ -292,7 +292,7 @@ QString sendTimeout(const CommandContext &ctx) assert(!actions.value().empty()); - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/Block.cpp b/src/controllers/commands/builtin/twitch/Block.cpp index 3a0419d5a..7e0423d44 100644 --- a/src/controllers/commands/builtin/twitch/Block.cpp +++ b/src/controllers/commands/builtin/twitch/Block.cpp @@ -36,7 +36,7 @@ QString blockUser(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { @@ -52,7 +52,7 @@ QString blockUser(const CommandContext &ctx) target, [currentUser, channel{ctx.channel}, target](const HelixUser &targetUser) { - getIApp()->getAccounts()->twitch.getCurrent()->blockUser( + getApp()->getAccounts()->twitch.getCurrent()->blockUser( targetUser.id, nullptr, [channel, target, targetUser] { channel->addSystemMessage( @@ -109,7 +109,7 @@ QString unblockUser(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { @@ -124,7 +124,7 @@ QString unblockUser(const CommandContext &ctx) getHelix()->getUserByName( target, [currentUser, channel{ctx.channel}, target](const auto &targetUser) { - getIApp()->getAccounts()->twitch.getCurrent()->unblockUser( + getApp()->getAccounts()->twitch.getCurrent()->unblockUser( targetUser.id, nullptr, [channel, target, targetUser] { channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/ChatSettings.cpp b/src/controllers/commands/builtin/twitch/ChatSettings.cpp index 1e166193b..cc0f311a9 100644 --- a/src/controllers/commands/builtin/twitch/ChatSettings.cpp +++ b/src/controllers/commands/builtin/twitch/ChatSettings.cpp @@ -100,7 +100,7 @@ namespace chatterino::commands { QString emoteOnly(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -130,7 +130,7 @@ QString emoteOnly(const CommandContext &ctx) QString emoteOnlyOff(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -158,7 +158,7 @@ QString emoteOnlyOff(const CommandContext &ctx) QString subscribers(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -188,7 +188,7 @@ QString subscribers(const CommandContext &ctx) QString subscribersOff(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -218,7 +218,7 @@ QString subscribersOff(const CommandContext &ctx) QString slow(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -265,7 +265,7 @@ QString slow(const CommandContext &ctx) QString slowOff(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -294,7 +294,7 @@ QString slowOff(const CommandContext &ctx) QString followers(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -342,7 +342,7 @@ QString followers(const CommandContext &ctx) QString followersOff(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -372,7 +372,7 @@ QString followersOff(const CommandContext &ctx) QString uniqueChat(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); @@ -402,7 +402,7 @@ QString uniqueChat(const CommandContext &ctx) QString uniqueChatOff(const CommandContext &ctx) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage(P_NOT_LOGGED_IN); diff --git a/src/controllers/commands/builtin/twitch/Chatters.cpp b/src/controllers/commands/builtin/twitch/Chatters.cpp index 602da9cc9..7c5f21fb8 100644 --- a/src/controllers/commands/builtin/twitch/Chatters.cpp +++ b/src/controllers/commands/builtin/twitch/Chatters.cpp @@ -77,7 +77,7 @@ QString chatters(const CommandContext &ctx) // Refresh chatter list via helix api for mods getHelix()->getChatters( ctx.twitchChannel->roomId(), - getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 1, + getApp()->getAccounts()->twitch.getCurrent()->getUserId(), 1, [channel{ctx.channel}](auto result) { channel->addSystemMessage(QString("Chatter count: %1.") .arg(localizeNumbers(result.total))); @@ -106,7 +106,7 @@ QString testChatters(const CommandContext &ctx) getHelix()->getChatters( ctx.twitchChannel->roomId(), - getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 5000, + getApp()->getAccounts()->twitch.getCurrent()->getUserId(), 5000, [channel{ctx.channel}, twitchChannel{ctx.twitchChannel}](auto result) { QStringList entries; for (const auto &username : result.chatters) diff --git a/src/controllers/commands/builtin/twitch/DeleteMessages.cpp b/src/controllers/commands/builtin/twitch/DeleteMessages.cpp index e0fe3e069..ab3b61a8e 100644 --- a/src/controllers/commands/builtin/twitch/DeleteMessages.cpp +++ b/src/controllers/commands/builtin/twitch/DeleteMessages.cpp @@ -21,7 +21,7 @@ QString deleteMessages(TwitchChannel *twitchChannel, const QString &messageID) { const auto *commandName = messageID.isEmpty() ? "/clear" : "/delete"; - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); // Avoid Helix calls without Client ID and/or OAuth Token if (user->isAnon()) diff --git a/src/controllers/commands/builtin/twitch/GetVIPs.cpp b/src/controllers/commands/builtin/twitch/GetVIPs.cpp index 3b6b98e01..794c5c0b9 100644 --- a/src/controllers/commands/builtin/twitch/GetVIPs.cpp +++ b/src/controllers/commands/builtin/twitch/GetVIPs.cpp @@ -81,7 +81,7 @@ QString getVIPs(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/Raid.cpp b/src/controllers/commands/builtin/twitch/Raid.cpp index 3f01f153e..57fb3c011 100644 --- a/src/controllers/commands/builtin/twitch/Raid.cpp +++ b/src/controllers/commands/builtin/twitch/Raid.cpp @@ -136,7 +136,7 @@ QString startRaid(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage("You must be logged in to start a raid!"); @@ -192,7 +192,7 @@ QString cancelRaid(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/RemoveModerator.cpp b/src/controllers/commands/builtin/twitch/RemoveModerator.cpp index 65611ff3e..3d6d8e365 100644 --- a/src/controllers/commands/builtin/twitch/RemoveModerator.cpp +++ b/src/controllers/commands/builtin/twitch/RemoveModerator.cpp @@ -32,7 +32,7 @@ QString removeModerator(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/RemoveVIP.cpp b/src/controllers/commands/builtin/twitch/RemoveVIP.cpp index 2703418f9..22e0a709c 100644 --- a/src/controllers/commands/builtin/twitch/RemoveVIP.cpp +++ b/src/controllers/commands/builtin/twitch/RemoveVIP.cpp @@ -34,7 +34,7 @@ QString removeVIP(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/SendWhisper.cpp b/src/controllers/commands/builtin/twitch/SendWhisper.cpp index 483f72853..3a33ee973 100644 --- a/src/controllers/commands/builtin/twitch/SendWhisper.cpp +++ b/src/controllers/commands/builtin/twitch/SendWhisper.cpp @@ -92,7 +92,7 @@ QString formatWhisperError(HelixWhisperError error, const QString &message) bool appendWhisperMessageWordsLocally(const QStringList &words) { - auto *app = getIApp(); + auto *app = getApp(); MessageBuilder b; @@ -102,7 +102,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) MessageElementFlag::Text, MessageColor::Text, FontStyle::ChatMediumBold); b.emplace("->", MessageElementFlag::Text, - getIApp()->getThemes()->messages.textColors.system); + getApp()->getThemes()->messages.textColors.system); b.emplace(words[1] + ":", MessageElementFlag::Text, MessageColor::Text, FontStyle::ChatMediumBold); @@ -177,12 +177,12 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) b->flags.set(MessageFlag::Whisper); auto messagexD = b.release(); - getIApp()->getTwitch()->getWhispersChannel()->addMessage( + getApp()->getTwitch()->getWhispersChannel()->addMessage( messagexD, MessageContext::Original); if (getSettings()->inlineWhispers && !(getSettings()->streamerModeSuppressInlineWhispers && - getIApp()->getStreamerMode()->isEnabled())) + getApp()->getStreamerMode()->isEnabled())) { app->getTwitchAbstract()->forEachChannel( [&messagexD](ChannelPtr _channel) { @@ -210,7 +210,7 @@ QString sendWhisper(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/ShieldMode.cpp b/src/controllers/commands/builtin/twitch/ShieldMode.cpp index 1a7bf3a32..93c3d9c68 100644 --- a/src/controllers/commands/builtin/twitch/ShieldMode.cpp +++ b/src/controllers/commands/builtin/twitch/ShieldMode.cpp @@ -22,7 +22,7 @@ QString toggleShieldMode(const CommandContext &ctx, bool isActivating) return {}; } - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); // Avoid Helix calls without Client ID and/or OAuth Token if (user->isAnon()) diff --git a/src/controllers/commands/builtin/twitch/Shoutout.cpp b/src/controllers/commands/builtin/twitch/Shoutout.cpp index 8d9b65617..7a79b5a3e 100644 --- a/src/controllers/commands/builtin/twitch/Shoutout.cpp +++ b/src/controllers/commands/builtin/twitch/Shoutout.cpp @@ -23,7 +23,7 @@ QString sendShoutout(const CommandContext &ctx) return ""; } - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { channel->addSystemMessage("You must be logged in to send shoutout."); diff --git a/src/controllers/commands/builtin/twitch/StartCommercial.cpp b/src/controllers/commands/builtin/twitch/StartCommercial.cpp index f09316416..15b620440 100644 --- a/src/controllers/commands/builtin/twitch/StartCommercial.cpp +++ b/src/controllers/commands/builtin/twitch/StartCommercial.cpp @@ -98,7 +98,7 @@ QString startCommercial(const CommandContext &ctx) return ""; } - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); // Avoid Helix calls without Client ID and/or OAuth Token if (user->isAnon()) diff --git a/src/controllers/commands/builtin/twitch/Unban.cpp b/src/controllers/commands/builtin/twitch/Unban.cpp index 950af39b9..35f29f5de 100644 --- a/src/controllers/commands/builtin/twitch/Unban.cpp +++ b/src/controllers/commands/builtin/twitch/Unban.cpp @@ -108,7 +108,7 @@ QString unbanUser(const CommandContext &ctx) assert(!actions.value().empty()); - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage( diff --git a/src/controllers/commands/builtin/twitch/UpdateColor.cpp b/src/controllers/commands/builtin/twitch/UpdateColor.cpp index b0fb8e71f..15680c276 100644 --- a/src/controllers/commands/builtin/twitch/UpdateColor.cpp +++ b/src/controllers/commands/builtin/twitch/UpdateColor.cpp @@ -25,7 +25,7 @@ QString updateUserColor(const CommandContext &ctx) "The /color command only works in Twitch channels."); return ""; } - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); // Avoid Helix calls without Client ID and/or OAuth Token if (user->isAnon()) diff --git a/src/controllers/commands/builtin/twitch/Warn.cpp b/src/controllers/commands/builtin/twitch/Warn.cpp index c36ab681c..2a3cb1fa5 100644 --- a/src/controllers/commands/builtin/twitch/Warn.cpp +++ b/src/controllers/commands/builtin/twitch/Warn.cpp @@ -104,7 +104,7 @@ QString sendWarn(const CommandContext &ctx) assert(!actions.value().empty()); - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (currentUser->isAnon()) { ctx.channel->addSystemMessage("You must be logged in to warn someone!"); diff --git a/src/controllers/completion/TabCompletionModel.cpp b/src/controllers/completion/TabCompletionModel.cpp index 202cc9ec8..585fe3a08 100644 --- a/src/controllers/completion/TabCompletionModel.cpp +++ b/src/controllers/completion/TabCompletionModel.cpp @@ -39,7 +39,7 @@ void TabCompletionModel::updateResults(const QString &query, // Try plugins first bool done{}; std::tie(done, results) = - getIApp()->getPlugins()->updateCustomCompletions( + getApp()->getPlugins()->updateCustomCompletions( query, fullTextContent, cursorPosition, isFirstWord); if (done) { diff --git a/src/controllers/completion/sources/CommandSource.cpp b/src/controllers/completion/sources/CommandSource.cpp index 9eedaf622..29deff932 100644 --- a/src/controllers/completion/sources/CommandSource.cpp +++ b/src/controllers/completion/sources/CommandSource.cpp @@ -71,20 +71,20 @@ void CommandSource::initializeItems() std::vector commands; #ifdef CHATTERINO_HAVE_PLUGINS - for (const auto &command : getIApp()->getCommands()->pluginCommands()) + for (const auto &command : getApp()->getCommands()->pluginCommands()) { addCommand(command, commands); } #endif // Custom Chatterino commands - for (const auto &command : getIApp()->getCommands()->items) + for (const auto &command : getApp()->getCommands()->items) { addCommand(command.name, commands); } // Default Chatterino commands - auto x = getIApp()->getCommands()->getDefaultChatterinoCommandList(); + auto x = getApp()->getCommands()->getDefaultChatterinoCommandList(); for (const auto &command : x) { addCommand(command, commands); diff --git a/src/controllers/completion/sources/EmoteSource.cpp b/src/controllers/completion/sources/EmoteSource.cpp index ded6d72be..f5d04c9e0 100644 --- a/src/controllers/completion/sources/EmoteSource.cpp +++ b/src/controllers/completion/sources/EmoteSource.cpp @@ -88,7 +88,7 @@ void EmoteSource::addToStringList(QStringList &list, size_t maxCount, void EmoteSource::initializeFromChannel(const Channel *channel) { - auto *app = getIApp(); + auto *app = getApp(); std::vector emotes; const auto *tc = dynamic_cast(channel); diff --git a/src/controllers/filters/lang/Filter.cpp b/src/controllers/filters/lang/Filter.cpp index 1a2461661..2cda8a13b 100644 --- a/src/controllers/filters/lang/Filter.cpp +++ b/src/controllers/filters/lang/Filter.cpp @@ -12,7 +12,7 @@ namespace chatterino::filters { ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel) { - auto watchingChannel = getIApp()->getTwitch()->getWatchingChannel().get(); + auto watchingChannel = getApp()->getTwitch()->getWatchingChannel().get(); /* * Looking to add a new identifier to filters? Here's what to do: diff --git a/src/controllers/highlights/BadgeHighlightModel.cpp b/src/controllers/highlights/BadgeHighlightModel.cpp index e1d93c3bc..3b61a01bf 100644 --- a/src/controllers/highlights/BadgeHighlightModel.cpp +++ b/src/controllers/highlights/BadgeHighlightModel.cpp @@ -53,7 +53,7 @@ void BadgeHighlightModel::getRowFromItem(const HighlightBadge &item, setFilePathItem(row[Column::SoundPath], item.getSoundUrl()); setColorItem(row[Column::Color], *item.getColor()); - getIApp()->getTwitchBadges()->getBadgeIcon( + getApp()->getTwitchBadges()->getBadgeIcon( item.badgeName(), [item, row](QString /*name*/, const QIconPtr pixmap) { row[Column::Badge]->setData(QVariant(*pixmap), Qt::DecorationRole); }); diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 3e15d7580..78d072a32 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -183,7 +183,7 @@ void rebuildReplyThreadHighlight(Settings &settings, void rebuildMessageHighlights(Settings &settings, std::vector &checks) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); QString currentUsername = currentUser->getUserName(); if (settings.enableSelfHighlight && !currentUsername.isEmpty() && @@ -442,9 +442,11 @@ std::ostream &operator<<(std::ostream &os, const HighlightResult &result) return os; } -void HighlightController::initialize(Settings &settings, - const Paths & /*paths*/) +HighlightController::HighlightController(Settings &settings, + AccountController *accounts) { + assert(accounts != nullptr); + this->rebuildListener_.addSetting(settings.enableSelfHighlight); this->rebuildListener_.addSetting(settings.enableSelfHighlightSound); this->rebuildListener_.addSetting(settings.enableSelfHighlightTaskbar); @@ -507,12 +509,12 @@ void HighlightController::initialize(Settings &settings, this->rebuildChecks(settings); }); - getIApp()->getAccounts()->twitch.currentUserChanged.connect( - [this, &settings] { + this->bConnections.emplace_back( + accounts->twitch.currentUserChanged.connect([this, &settings] { qCDebug(chatterinoHighlights) << "Rebuild checks because user swapped accounts"; this->rebuildChecks(settings); - }); + })); this->rebuildChecks(settings); } @@ -550,7 +552,7 @@ std::pair HighlightController::check( // Access for checking const auto checks = this->checks_.accessConst(); - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); auto self = (senderName == currentUser->getUserName()); for (const auto &check : *checks) diff --git a/src/controllers/highlights/HighlightController.hpp b/src/controllers/highlights/HighlightController.hpp index e05986a0e..c217f7bb2 100644 --- a/src/controllers/highlights/HighlightController.hpp +++ b/src/controllers/highlights/HighlightController.hpp @@ -1,9 +1,10 @@ #pragma once #include "common/FlagsEnum.hpp" -#include "common/Singleton.hpp" #include "common/UniqueAccess.hpp" +#include "singletons/Settings.hpp" +#include #include #include #include @@ -20,6 +21,7 @@ class Badge; struct MessageParseArgs; enum class MessageFlag : int64_t; using MessageFlags = FlagsEnum; +class AccountController; struct HighlightResult { HighlightResult(bool _alert, bool _playSound, @@ -83,10 +85,10 @@ struct HighlightCheck { Checker cb; }; -class HighlightController final : public Singleton +class HighlightController final { public: - void initialize(Settings &settings, const Paths &paths) override; + HighlightController(Settings &settings, AccountController *accounts); /** * @brief Checks the given message parameters if it matches our internal checks, and returns a result @@ -108,6 +110,7 @@ private: pajlada::SettingListener rebuildListener_; pajlada::Signals::SignalHolder signalHolder_; + std::vector bConnections; }; } // namespace chatterino diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index 974653115..52f679375 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -519,7 +519,7 @@ void HighlightModel::customRowSetData(const std::vector &row, break; } - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); } } // namespace chatterino diff --git a/src/controllers/highlights/UserHighlightModel.cpp b/src/controllers/highlights/UserHighlightModel.cpp index b28866e6d..2c5bfec35 100644 --- a/src/controllers/highlights/UserHighlightModel.cpp +++ b/src/controllers/highlights/UserHighlightModel.cpp @@ -109,7 +109,7 @@ void UserHighlightModel::customRowSetData( break; } - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); } // row into vector item diff --git a/src/controllers/hotkeys/Hotkey.cpp b/src/controllers/hotkeys/Hotkey.cpp index 9a2392d13..557decd70 100644 --- a/src/controllers/hotkeys/Hotkey.cpp +++ b/src/controllers/hotkeys/Hotkey.cpp @@ -58,7 +58,7 @@ std::vector Hotkey::arguments() const QString Hotkey::getCategory() const { - return getIApp()->getHotkeys()->categoryDisplayName(this->category_); + return getApp()->getHotkeys()->categoryDisplayName(this->category_); } Qt::ShortcutContext Hotkey::getContext() const diff --git a/src/controllers/hotkeys/HotkeyController.hpp b/src/controllers/hotkeys/HotkeyController.hpp index 57187ca8b..f5d5842ef 100644 --- a/src/controllers/hotkeys/HotkeyController.hpp +++ b/src/controllers/hotkeys/HotkeyController.hpp @@ -1,7 +1,6 @@ #pragma once #include "common/SignalVector.hpp" -#include "common/Singleton.hpp" #include "controllers/hotkeys/HotkeyCategory.hpp" #include @@ -18,7 +17,7 @@ class Hotkey; class HotkeyModel; -class HotkeyController final : public Singleton +class HotkeyController final { public: using HotkeyFunction = std::function)>; @@ -31,7 +30,7 @@ public: HotkeyMap actionMap, QWidget *parent); - void save() override; + void save(); std::shared_ptr getHotkeyByName(QString name); /** * @brief returns a QKeySequence that perfoms the actions requested. diff --git a/src/controllers/ignores/IgnoreController.cpp b/src/controllers/ignores/IgnoreController.cpp index 8d064ca8e..7922b16dd 100644 --- a/src/controllers/ignores/IgnoreController.cpp +++ b/src/controllers/ignores/IgnoreController.cpp @@ -32,7 +32,7 @@ bool isIgnoredMessage(IgnoredMessageParameters &¶ms) { auto sourceUserID = params.twitchUserID; - bool isBlocked = getIApp() + bool isBlocked = getApp() ->getAccounts() ->twitch.getCurrent() ->blockedUserIds() diff --git a/src/controllers/ignores/IgnorePhrase.cpp b/src/controllers/ignores/IgnorePhrase.cpp index 735e87745..eacd7e4bd 100644 --- a/src/controllers/ignores/IgnorePhrase.cpp +++ b/src/controllers/ignores/IgnorePhrase.cpp @@ -95,7 +95,7 @@ bool IgnorePhrase::containsEmote() const { if (!this->emotesChecked_) { - const auto &accvec = getIApp()->getAccounts()->twitch.accounts; + const auto &accvec = getApp()->getAccounts()->twitch.accounts; for (const auto &acc : accvec) { const auto &accemotes = *acc->accessEmotes(); diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 1fe0036a7..b3800dd21 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -17,9 +17,10 @@ #include namespace ranges = std::ranges; + namespace chatterino { -void NotificationController::initialize(Settings &settings, const Paths &paths) +NotificationController::NotificationController() { for (const QString &channelName : this->twitchSetting_.getValue()) { @@ -34,14 +35,17 @@ void NotificationController::initialize(Settings &settings, const Paths &paths) this->channelMap[Platform::Twitch].raw()); }); - this->fetchFakeChannels(); - QObject::connect(&this->liveStatusTimer_, &QTimer::timeout, [this] { this->fetchFakeChannels(); }); this->liveStatusTimer_.start(60 * 1000); } +void NotificationController::initialize() +{ + this->fetchFakeChannels(); +} + void NotificationController::updateChannelNotification( const QString &channelName, Platform p) { @@ -92,7 +96,7 @@ void NotificationController::playSound() const getSettings()->notificationPathSound.getValue()) : QUrl("qrc:/sounds/ping2.wav"); - getIApp()->getSound()->play(highlightSoundUrl); + getApp()->getSound()->play(highlightSoundUrl); } NotificationModel *NotificationController::createModel(QObject *parent, @@ -109,7 +113,7 @@ void NotificationController::notifyTwitchChannelLive( bool showNotification = !(getSettings()->suppressInitialLiveNotification && payload.isInitialUpdate) && - !(getIApp()->getStreamerMode()->isEnabled() && + !(getApp()->getStreamerMode()->isEnabled() && getSettings()->streamerModeSuppressLiveNotifications); bool playedSound = false; @@ -118,7 +122,7 @@ void NotificationController::notifyTwitchChannelLive( { if (Toasts::isEnabled()) { - getIApp()->getToasts()->sendChannelNotification( + getApp()->getToasts()->sendChannelNotification( payload.channelName, payload.title, Platform::Twitch); } if (getSettings()->notificationPlaySound) @@ -128,7 +132,7 @@ void NotificationController::notifyTwitchChannelLive( } if (getSettings()->notificationFlashTaskbar) { - getIApp()->getWindows()->sendAlert(); + getApp()->getWindows()->sendAlert(); } } @@ -136,7 +140,7 @@ void NotificationController::notifyTwitchChannelLive( MessageBuilder builder; TwitchMessageBuilder::liveMessage(payload.displayName, &builder); builder.message().id = payload.channelId; - getIApp()->getTwitch()->getLiveChannel()->addMessage( + getApp()->getTwitch()->getLiveChannel()->addMessage( builder.release(), MessageContext::Original); // Notify on all channels with a ping sound @@ -152,7 +156,7 @@ void NotificationController::notifyTwitchChannelOffline(const QString &id) const { // "delete" old 'CHANNEL is live' message LimitedQueueSnapshot snapshot = - getIApp()->getTwitch()->getLiveChannel()->getMessageSnapshot(); + getApp()->getTwitch()->getLiveChannel()->getMessageSnapshot(); int snapshotLength = static_cast(snapshot.size()); int end = std::max(0, snapshotLength - 200); @@ -177,7 +181,7 @@ void NotificationController::fetchFakeChannels() for (size_t i = 0; i < channelMap[Platform::Twitch].raw().size(); i++) { const auto &name = channelMap[Platform::Twitch].raw()[i]; - auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(name); + auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(name); if (chan->isEmpty()) { channels.push_back(name); diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp index fa802c1ec..e7ad1731f 100644 --- a/src/controllers/notifications/NotificationController.hpp +++ b/src/controllers/notifications/NotificationController.hpp @@ -2,7 +2,6 @@ #include "common/ChatterinoSetting.hpp" #include "common/SignalVector.hpp" -#include "common/Singleton.hpp" #include "util/QCompareCaseInsensitive.hpp" #include @@ -19,10 +18,13 @@ enum class Platform : uint8_t { Twitch, // 0 }; -class NotificationController final : public Singleton +class NotificationController final { public: - void initialize(Settings &settings, const Paths &paths) override; + NotificationController(); + + // Perform an initial load so we don't have to wait for the timer + void initialize(); bool isChannelNotified(const QString &channelName, Platform p) const; void updateChannelNotification(const QString &channelName, Platform p); diff --git a/src/controllers/plugins/LuaAPI.cpp b/src/controllers/plugins/LuaAPI.cpp index d70be6489..03d11750a 100644 --- a/src/controllers/plugins/LuaAPI.cpp +++ b/src/controllers/plugins/LuaAPI.cpp @@ -65,7 +65,7 @@ namespace chatterino::lua::api { int c2_register_command(lua_State *L) { - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (pl == nullptr) { luaL_error(L, "internal error: no plugin"); @@ -99,7 +99,7 @@ int c2_register_command(lua_State *L) int c2_register_callback(lua_State *L) { - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (pl == nullptr) { luaL_error(L, "internal error: no plugin"); @@ -133,7 +133,7 @@ int c2_register_callback(lua_State *L) int c2_log(lua_State *L) { - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (pl == nullptr) { luaL_error(L, "c2_log: internal error: no plugin?"); @@ -154,7 +154,7 @@ int c2_log(lua_State *L) int c2_later(lua_State *L) { - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (pl == nullptr) { return luaL_error(L, "c2.later: internal error: no plugin?"); @@ -257,7 +257,7 @@ int g_load(lua_State *L) int loadfile(lua_State *L, const QString &str) { - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (pl == nullptr) { return luaL_error(L, "loadfile: internal error: no plugin?"); @@ -307,7 +307,7 @@ int searcherAbsolute(lua_State *L) name = name.replace('.', QDir::separator()); QString filename; - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (pl == nullptr) { return luaL_error(L, "searcherAbsolute: internal error: no plugin?"); @@ -348,7 +348,7 @@ int searcherRelative(lua_State *L) int g_print(lua_State *L) { - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (pl == nullptr) { luaL_error(L, "c2_print: internal error: no plugin?"); diff --git a/src/controllers/plugins/Plugin.cpp b/src/controllers/plugins/Plugin.cpp index 4a8f89f09..dcf7357e8 100644 --- a/src/controllers/plugins/Plugin.cpp +++ b/src/controllers/plugins/Plugin.cpp @@ -197,7 +197,7 @@ bool Plugin::registerCommand(const QString &name, const QString &functionName) return false; } - auto ok = getIApp()->getCommands()->registerPluginCommand(name); + auto ok = getApp()->getCommands()->registerPluginCommand(name); if (!ok) { return false; diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index 64e2a96b0..5ca77ed40 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -35,10 +35,8 @@ PluginController::PluginController(const Paths &paths_) { } -void PluginController::initialize(Settings &settings, const Paths &paths) +void PluginController::initialize(Settings &settings) { - (void)paths; - // actuallyInitialize will be called by this connection settings.pluginsEnabled.connect([this](bool enabled) { if (enabled) @@ -354,7 +352,7 @@ bool PluginController::reload(const QString &id) } for (const auto &[cmd, _] : it->second->ownedCommands) { - getIApp()->getCommands()->unregisterPluginCommand(cmd); + getApp()->getCommands()->unregisterPluginCommand(cmd); } it->second->ownedCommands.clear(); QDir loadDir = it->second->loadDirectory_; diff --git a/src/controllers/plugins/PluginController.hpp b/src/controllers/plugins/PluginController.hpp index 099c40a70..50bc88c7e 100644 --- a/src/controllers/plugins/PluginController.hpp +++ b/src/controllers/plugins/PluginController.hpp @@ -2,7 +2,6 @@ #ifdef CHATTERINO_HAVE_PLUGINS -# include "common/Singleton.hpp" # include "controllers/commands/CommandContext.hpp" # include "controllers/plugins/Plugin.hpp" @@ -24,14 +23,14 @@ namespace chatterino { class Paths; -class PluginController : public Singleton +class PluginController { const Paths &paths; public: explicit PluginController(const Paths &paths_); - void initialize(Settings &settings, const Paths &paths) override; + void initialize(Settings &settings); QString tryExecPluginCommand(const QString &commandName, const CommandContext &ctx); diff --git a/src/controllers/plugins/api/ChannelRef.cpp b/src/controllers/plugins/api/ChannelRef.cpp index 64b146f55..68cf15980 100644 --- a/src/controllers/plugins/api/ChannelRef.cpp +++ b/src/controllers/plugins/api/ChannelRef.cpp @@ -174,7 +174,7 @@ int ChannelRef::send_message(lua_State *L) text = text.replace('\n', ' '); if (execcmds) { - text = getIApp()->getCommands()->execCommand(text, that, false); + text = getApp()->getCommands()->execCommand(text, that, false); } that->sendMessage(text); return 0; @@ -300,7 +300,7 @@ int ChannelRef::get_by_name(lua_State *L) lua_pushnil(L); return 1; } - auto chn = getIApp()->getTwitchAbstract()->getChannelOrEmpty(name); + auto chn = getApp()->getTwitchAbstract()->getChannelOrEmpty(name); lua::push(L, chn); return 1; } @@ -324,7 +324,7 @@ int ChannelRef::get_by_twitch_id(lua_State *L) lua_pushnil(L); return 1; } - auto chn = getIApp()->getTwitch()->getChannelOrEmptyByID(id); + auto chn = getApp()->getTwitch()->getChannelOrEmptyByID(id); lua::push(L, chn); return 1; diff --git a/src/controllers/plugins/api/HTTPRequest.cpp b/src/controllers/plugins/api/HTTPRequest.cpp index 6defabb38..eba2773ad 100644 --- a/src/controllers/plugins/api/HTTPRequest.cpp +++ b/src/controllers/plugins/api/HTTPRequest.cpp @@ -309,7 +309,7 @@ int HTTPRequest::create(lua_State *L) L, "cannot get method (1st argument of HTTPRequest.create, " "expected a string)"); } - auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L); + auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L); if (!pl->hasHTTPPermissionFor(parsedurl)) { return luaL_error( diff --git a/src/controllers/twitch/LiveController.hpp b/src/controllers/twitch/LiveController.hpp index 94b538957..767004061 100644 --- a/src/controllers/twitch/LiveController.hpp +++ b/src/controllers/twitch/LiveController.hpp @@ -1,6 +1,5 @@ #pragma once -#include "common/Singleton.hpp" #include "util/QStringHash.hpp" #include @@ -26,7 +25,7 @@ public: virtual void add(const std::shared_ptr &newChannel) = 0; }; -class TwitchLiveController : public ITwitchLiveController, public Singleton +class TwitchLiveController : public ITwitchLiveController { public: // Controls how often all channels have their stream status refreshed diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index 307069691..f74bba164 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -50,7 +50,7 @@ Frames::Frames(QList &&frames) DebugCount::increase("animated images"); this->gifTimerConnection_ = - getIApp()->getEmotes()->getGIFTimer().signal.connect([this] { + getApp()->getEmotes()->getGIFTimer().signal.connect([this] { this->advance(); }); } @@ -67,7 +67,7 @@ Frames::Frames(QList &&frames) else { this->durationOffset_ = std::min( - int(getIApp()->getEmotes()->getGIFTimer().position() % totalLength), + int(getApp()->getEmotes()->getGIFTimer().position() % totalLength), 60000); } this->processOffset(); @@ -242,7 +242,7 @@ void assignFrames(std::weak_ptr weak, QList parsed) isPushQueued = true; postToThread([] { isPushQueued = false; - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); }); } }; diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index c7959da93..3e91d04dd 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -203,7 +203,7 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username, MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count) : MessageBuilder() { - auto current = getIApp()->getAccounts()->twitch.getCurrent(); + auto current = getApp()->getAccounts()->twitch.getCurrent(); this->emplace(); this->message().flags.set(MessageFlag::System); @@ -676,7 +676,7 @@ void MessageBuilder::addLink(const linkparser::Parsed &parsedLink, MessageElementFlag::Text, this->textColor_); } - getIApp()->getLinkResolver()->resolve(el->linkInfo()); + getApp()->getLinkResolver()->resolve(el->linkInfo()); } void MessageBuilder::addIrcMessageText(const QString &text) @@ -686,7 +686,7 @@ void MessageBuilder::addIrcMessageText(const QString &text) auto words = text.split(' '); MessageColor defaultColorType = MessageColor::Text; const auto &defaultColor = - defaultColorType.getColor(*getIApp()->getThemes()); + defaultColorType.getColor(*getApp()->getThemes()); QColor textColor = defaultColor; int fg = -1; int bg = -1; @@ -728,7 +728,7 @@ void MessageBuilder::addIrcMessageText(const QString &text) if (fg >= 0 && fg <= 98) { textColor = IRC_COLORS[fg]; - getIApp()->getThemes()->normalizeColor(textColor); + getApp()->getThemes()->normalizeColor(textColor); } else { @@ -768,7 +768,7 @@ void MessageBuilder::addIrcMessageText(const QString &text) if (fg >= 0 && fg <= 98) { textColor = IRC_COLORS[fg]; - getIApp()->getThemes()->normalizeColor(textColor); + getApp()->getThemes()->normalizeColor(textColor); } else { @@ -810,7 +810,7 @@ void MessageBuilder::addIrcWord(const QString &text, const QColor &color, bool addSpace) { this->textColor_ = color; - for (auto &variant : getIApp()->getEmotes()->getEmojis()->parse(text)) + for (auto &variant : getApp()->getEmotes()->getEmojis()->parse(text)) { boost::apply_visitor( [&](auto &&arg) { diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index c49e53802..8d994ef22 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -454,7 +454,7 @@ TextElement::TextElement(const QString &text, MessageElementFlags flags, void TextElement::addToContainer(MessageLayoutContainer &container, MessageElementFlags flags) { - auto *app = getIApp(); + auto *app = getApp(); if (flags.hasAny(this->getFlags())) { @@ -566,7 +566,7 @@ SingleLineTextElement::SingleLineTextElement(const QString &text, void SingleLineTextElement::addToContainer(MessageLayoutContainer &container, MessageElementFlags flags) { - auto *app = getIApp(); + auto *app = getApp(); if (flags.hasAny(this->getFlags())) { diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index 52349107f..69a216502 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -156,7 +156,7 @@ void SharedMessageBuilder::parseHighlights() } auto badges = SharedMessageBuilder::parseBadgeTag(this->tags); - auto [highlighted, highlightResult] = getIApp()->getHighlights()->check( + auto [highlighted, highlightResult] = getApp()->getHighlights()->check( this->args, badges, this->message().loginName, this->originalMessage_, this->message().flags); @@ -203,7 +203,7 @@ void SharedMessageBuilder::triggerHighlights( const QString &channelName, bool playSound, const std::optional &customSoundUrl, bool windowAlert) { - if (getIApp()->getStreamerMode()->isEnabled() && + if (getApp()->getStreamerMode()->isEnabled() && getSettings()->streamerModeMuteMentions) { // We are in streamer mode with muting mention sounds enabled. Do nothing. @@ -232,12 +232,12 @@ void SharedMessageBuilder::triggerHighlights( { soundUrl = getFallbackHighlightSound(); } - getIApp()->getSound()->play(soundUrl); + getApp()->getSound()->play(soundUrl); } if (windowAlert) { - getIApp()->getWindows()->sendAlert(); + getApp()->getWindows()->sendAlert(); } } diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index 8a20b05cc..10397d93c 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -88,7 +88,7 @@ bool MessageLayout::layout(int width, float scale, float imageScale, this->currentLayoutWidth_ = width; // check if layout state changed - const auto layoutGeneration = getIApp()->getWindows()->getGeneration(); + const auto layoutGeneration = getApp()->getWindows()->getGeneration(); if (this->layoutState_ != layoutGeneration) { layoutRequired = true; @@ -166,7 +166,7 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags flags) { if (hideModerationActions || (getSettings()->streamerModeHideModActions && - getIApp()->getStreamerMode()->isEnabled())) + getApp()->getStreamerMode()->isEnabled())) { continue; } diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index 5c3942763..a4abee58d 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -48,7 +48,7 @@ void MessageLayoutContainer::beginLayout(int width, float scale, this->imageScale_ = imageScale; this->flags_ = flags; auto mediumFontMetrics = - getIApp()->getFonts()->getFontMetrics(FontStyle::ChatMedium, scale); + getApp()->getFonts()->getFontMetrics(FontStyle::ChatMedium, scale); this->textLineHeight_ = mediumFontMetrics.height(); this->spaceWidth_ = mediumFontMetrics.horizontalAdvance(' '); this->dotdotdotWidth_ = mediumFontMetrics.horizontalAdvance("..."); diff --git a/src/providers/ffz/FfzBadges.cpp b/src/providers/ffz/FfzBadges.cpp index 561f47ea3..574d27787 100644 --- a/src/providers/ffz/FfzBadges.cpp +++ b/src/providers/ffz/FfzBadges.cpp @@ -1,4 +1,4 @@ -#include "FfzBadges.hpp" +#include "providers/ffz/FfzBadges.hpp" #include "common/network/NetworkRequest.hpp" #include "common/network/NetworkResult.hpp" @@ -17,11 +17,6 @@ namespace chatterino { -void FfzBadges::initialize(Settings &settings, const Paths &paths) -{ - this->load(); -} - std::vector FfzBadges::getUserBadges(const UserId &id) { std::vector badges; diff --git a/src/providers/ffz/FfzBadges.hpp b/src/providers/ffz/FfzBadges.hpp index 8d021624a..d24579451 100644 --- a/src/providers/ffz/FfzBadges.hpp +++ b/src/providers/ffz/FfzBadges.hpp @@ -1,7 +1,6 @@ #pragma once #include "common/Aliases.hpp" -#include "common/Singleton.hpp" #include "util/QStringHash.hpp" #include "util/ThreadGuard.hpp" @@ -19,10 +18,9 @@ namespace chatterino { struct Emote; using EmotePtr = std::shared_ptr; -class FfzBadges : public Singleton +class FfzBadges { public: - void initialize(Settings &settings, const Paths &paths) override; FfzBadges() = default; struct Badge { @@ -33,9 +31,9 @@ public: std::vector getUserBadges(const UserId &id); std::optional getBadge(int badgeID) const; -private: void load(); +private: std::shared_mutex mutex_; // userBadges points a user ID to the list of badges they have diff --git a/src/providers/irc/Irc2.cpp b/src/providers/irc/Irc2.cpp index 385c76bae..c51a5f323 100644 --- a/src/providers/irc/Irc2.cpp +++ b/src/providers/irc/Irc2.cpp @@ -22,7 +22,7 @@ namespace { QString configPath() { - return combinePath(getIApp()->getPaths().settingsDirectory, "irc.json"); + return combinePath(getApp()->getPaths().settingsDirectory, "irc.json"); } class Model : public SignalVectorModel diff --git a/src/providers/irc/IrcServer.cpp b/src/providers/irc/IrcServer.cpp index 24b8c39e1..a5148c9c7 100644 --- a/src/providers/irc/IrcServer.cpp +++ b/src/providers/irc/IrcServer.cpp @@ -245,7 +245,7 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message) if (highlighted && showInMentions) { - getIApp()->getTwitch()->getMentionsChannel()->addMessage( + getApp()->getTwitch()->getMentionsChannel()->addMessage( msg, MessageContext::Original); } } diff --git a/src/providers/seventv/SeventvAPI.hpp b/src/providers/seventv/SeventvAPI.hpp index c47f9dd33..5ee5d9b61 100644 --- a/src/providers/seventv/SeventvAPI.hpp +++ b/src/providers/seventv/SeventvAPI.hpp @@ -1,7 +1,5 @@ #pragma once -#include "common/Singleton.hpp" - #include class QString; @@ -11,7 +9,7 @@ namespace chatterino { class NetworkResult; -class SeventvAPI : public Singleton +class SeventvAPI final { using ErrorCallback = std::function; template @@ -19,7 +17,7 @@ class SeventvAPI : public Singleton public: SeventvAPI() = default; - ~SeventvAPI() override = default; + ~SeventvAPI() = default; SeventvAPI(const SeventvAPI &) = delete; SeventvAPI(SeventvAPI &&) = delete; diff --git a/src/providers/seventv/SeventvBadges.hpp b/src/providers/seventv/SeventvBadges.hpp index 725528916..c9d0efad5 100644 --- a/src/providers/seventv/SeventvBadges.hpp +++ b/src/providers/seventv/SeventvBadges.hpp @@ -1,7 +1,6 @@ #pragma once #include "common/Aliases.hpp" -#include "common/Singleton.hpp" #include "util/QStringHash.hpp" #include @@ -16,7 +15,7 @@ namespace chatterino { struct Emote; using EmotePtr = std::shared_ptr; -class SeventvBadges : public Singleton +class SeventvBadges { public: // Return the badge, if any, that is assigned to the user diff --git a/src/providers/seventv/SeventvEmotes.cpp b/src/providers/seventv/SeventvEmotes.cpp index ae9376c01..896a50e1b 100644 --- a/src/providers/seventv/SeventvEmotes.cpp +++ b/src/providers/seventv/SeventvEmotes.cpp @@ -217,7 +217,7 @@ void SeventvEmotes::loadGlobalEmotes() qCDebug(chatterinoSeventv) << "Loading 7TV Global Emotes"; - getIApp()->getSeventvAPI()->getEmoteSet( + getApp()->getSeventvAPI()->getEmoteSet( u"global"_s, [this](const auto &json) { QJsonArray parsedEmotes = json["emotes"].toArray(); @@ -246,7 +246,7 @@ void SeventvEmotes::loadChannelEmotes( qCDebug(chatterinoSeventv) << "Reloading 7TV Channel Emotes" << channelId << manualRefresh; - getIApp()->getSeventvAPI()->getUserByTwitchID( + getApp()->getSeventvAPI()->getUserByTwitchID( channelId, [callback = std::move(callback), channel, channelId, manualRefresh](const auto &json) { @@ -405,7 +405,7 @@ void SeventvEmotes::getEmoteSet( { qCDebug(chatterinoSeventv) << "Loading 7TV Emote Set" << emoteSetId; - getIApp()->getSeventvAPI()->getEmoteSet( + getApp()->getSeventvAPI()->getEmoteSet( emoteSetId, [callback = std::move(successCallback), emoteSetId](const auto &json) { auto parsedEmotes = json["emotes"].toArray(); diff --git a/src/providers/seventv/SeventvEventAPI.cpp b/src/providers/seventv/SeventvEventAPI.cpp index 82234a99c..294f95ee2 100644 --- a/src/providers/seventv/SeventvEventAPI.cpp +++ b/src/providers/seventv/SeventvEventAPI.cpp @@ -348,7 +348,7 @@ void SeventvEventAPI::onUserUpdate(const Dispatch &dispatch) void SeventvEventAPI::onCosmeticCreate(const CosmeticCreateDispatch &cosmetic) { - auto *badges = getIApp()->getSeventvBadges(); + auto *badges = getApp()->getSeventvBadges(); switch (cosmetic.kind) { case CosmeticKind::Badge: { @@ -363,7 +363,7 @@ void SeventvEventAPI::onCosmeticCreate(const CosmeticCreateDispatch &cosmetic) void SeventvEventAPI::onEntitlementCreate( const EntitlementCreateDeleteDispatch &entitlement) { - auto *badges = getIApp()->getSeventvBadges(); + auto *badges = getApp()->getSeventvBadges(); switch (entitlement.kind) { case CosmeticKind::Badge: { @@ -379,7 +379,7 @@ void SeventvEventAPI::onEntitlementCreate( void SeventvEventAPI::onEntitlementDelete( const EntitlementCreateDeleteDispatch &entitlement) { - auto *badges = getIApp()->getSeventvBadges(); + auto *badges = getApp()->getSeventvBadges(); switch (entitlement.kind) { case CosmeticKind::Badge: { diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 74bc00035..7660cd115 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -132,7 +132,7 @@ void updateReplyParticipatedStatus(const QVariantMap &tags, bool isNew) { const auto ¤tLogin = - getIApp()->getAccounts()->twitch.getCurrent()->getUserName(); + getApp()->getAccounts()->twitch.getCurrent()->getUserName(); if (thread->subscribed()) { @@ -390,7 +390,7 @@ std::vector parseNoticeMessage(Communi::IrcNoticeMessage *message) { const auto linkColor = MessageColor(MessageColor::Link); const auto accountsLink = Link(Link::OpenAccountsPage, QString()); - const auto curUser = getIApp()->getAccounts()->twitch.getCurrent(); + const auto curUser = getApp()->getAccounts()->twitch.getCurrent(); const auto expirationText = QString("Login expired for user \"%1\"!") .arg(curUser->getUserName()); const auto loginPromptText = QString("Try adding your account again."); @@ -692,7 +692,7 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, if (twitchChannel != nullptr) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (message->tag("user-id") == currentUser->getUserId()) { auto badgesTag = message->tag("badges"); @@ -736,7 +736,7 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message) { return; } - auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); + auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); auto *twitchChannel = dynamic_cast(chan.get()); if (!twitchChannel) @@ -798,7 +798,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) } // get channel - auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); + auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); if (chan->isEmpty()) { @@ -821,10 +821,10 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) chan->addOrReplaceTimeout(std::move(clearChat.message)); // refresh all - getIApp()->getWindows()->repaintVisibleChatWidgets(chan.get()); + getApp()->getWindows()->repaintVisibleChatWidgets(chan.get()); if (getSettings()->hideModerated) { - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); } } @@ -843,7 +843,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) } // get channel - auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); + auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); if (chan->isEmpty()) { @@ -875,7 +875,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); // set received emote-sets, used in TwitchAccount::loadUserstateEmotes bool emoteSetsChanged = currentUser->setUserstateEmoteSets( @@ -892,7 +892,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) return; } - auto c = getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); + auto c = getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); if (c->isEmpty()) { return; @@ -927,7 +927,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) void IrcMessageHandler::handleGlobalUserStateMessage( Communi::IrcMessage *message) { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); // set received emote-sets, this time used to initially load emotes // NOTE: this should always return true unless we reconnect @@ -947,7 +947,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) args.isReceivedWhisper = true; - auto *c = getIApp()->getTwitch()->getWhispersChannel().get(); + auto *c = getApp()->getTwitch()->getWhispersChannel().get(); TwitchMessageBuilder builder( c, ircMessage, args, @@ -963,11 +963,11 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) MessagePtr message = builder.build(); builder.triggerHighlights(); - getIApp()->getTwitch()->setLastUserThatWhisperedMe(builder.userName); + getApp()->getTwitch()->setLastUserThatWhisperedMe(builder.userName); if (message->flags.has(MessageFlag::ShowInMentions)) { - getIApp()->getTwitch()->getMentionsChannel()->addMessage( + getApp()->getTwitch()->getMentionsChannel()->addMessage( message, MessageContext::Original); } @@ -979,13 +979,12 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) if (getSettings()->inlineWhispers && !(getSettings()->streamerModeSuppressInlineWhispers && - getIApp()->getStreamerMode()->isEnabled())) + getApp()->getStreamerMode()->isEnabled())) { - getIApp()->getTwitchAbstract()->forEachChannel( - [&message, overrideFlags](ChannelPtr channel) { - channel->addMessage(message, MessageContext::Repost, - overrideFlags); - }); + getApp()->getTwitchAbstract()->forEachChannel([&message, overrideFlags]( + ChannelPtr channel) { + channel->addMessage(message, MessageContext::Repost, overrideFlags); + }); } } @@ -1118,7 +1117,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) { // Notice wasn't targeted at a single channel, send to all twitch // channels - getIApp()->getTwitch()->forEachChannelAndSpecialChannels( + getApp()->getTwitch()->forEachChannelAndSpecialChannels( [msg](const auto &c) { c->addMessage(msg, MessageContext::Original); }); @@ -1127,7 +1126,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) } auto channel = - getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); + getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); if (channel->isEmpty()) { @@ -1210,7 +1209,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) { - auto channel = getIApp()->getTwitchAbstract()->getChannelOrEmpty( + auto channel = getApp()->getTwitchAbstract()->getChannelOrEmpty( message->parameter(0).remove(0, 1)); auto *twitchChannel = dynamic_cast(channel.get()); @@ -1220,7 +1219,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) } if (message->nick() == - getIApp()->getAccounts()->twitch.getCurrent()->getUserName()) + getApp()->getAccounts()->twitch.getCurrent()->getUserName()) { twitchChannel->addSystemMessage("joined channel"); twitchChannel->joined.invoke(); @@ -1233,7 +1232,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message) { - auto channel = getIApp()->getTwitchAbstract()->getChannelOrEmpty( + auto channel = getApp()->getTwitchAbstract()->getChannelOrEmpty( message->parameter(0).remove(0, 1)); auto *twitchChannel = dynamic_cast(channel.get()); @@ -1243,7 +1242,7 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message) } const auto selfAccountName = - getIApp()->getAccounts()->twitch.getCurrent()->getUserName(); + getApp()->getAccounts()->twitch.getCurrent()->getUserName(); if (message->nick() != selfAccountName && getSettings()->showParts.getValue()) { @@ -1296,7 +1295,7 @@ void IrcMessageHandler::setSimilarityFlags(const MessagePtr &message, { bool isMyself = message->loginName == - getIApp()->getAccounts()->twitch.getCurrent()->getUserName(); + getApp()->getAccounts()->twitch.getCurrent()->getUserName(); bool hideMyself = getSettings()->hideSimilarMyself; if (isMyself && !hideMyself) diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index 0fed7548d..eb07bd6ba 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -109,7 +109,7 @@ void TwitchAccount::loadBlocks() this->ignoresUserIds_.clear(); getHelix()->loadBlocks( - getIApp()->getAccounts()->twitch.getCurrent()->userId_, + getApp()->getAccounts()->twitch.getCurrent()->userId_, [this](const std::vector &blocks) { assertInGuiThread(); @@ -325,7 +325,7 @@ void TwitchAccount::loadUserstateEmotes(std::weak_ptr weakChannel) emoteSet->emotes.push_back(TwitchEmote{id, code}); - auto emote = getIApp() + auto emote = getApp() ->getEmotes() ->getTwitchEmotes() ->getOrCreateEmote(id, code); @@ -493,7 +493,7 @@ void TwitchAccount::loadSeventvUserID() return; } - auto *seventv = getIApp()->getSeventvAPI(); + auto *seventv = getApp()->getSeventvAPI(); if (!seventv) { qCWarning(chatterinoSeventv) diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 4f553f039..cfb046a4d 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -91,7 +91,7 @@ TwitchChannel::TwitchChannel(const QString &name) qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened"; this->bSignals_.emplace_back( - getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] { + getApp()->getAccounts()->twitch.currentUserChanged.connect([this] { this->setMod(false); this->refreshPubSub(); })); @@ -143,18 +143,18 @@ TwitchChannel::TwitchChannel(const QString &name) TwitchChannel::~TwitchChannel() { - getIApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_, - this->seventvEmoteSetID_); + getApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_, + this->seventvEmoteSetID_); - if (getIApp()->getTwitch()->getBTTVLiveUpdates()) + if (getApp()->getTwitch()->getBTTVLiveUpdates()) { - getIApp()->getTwitch()->getBTTVLiveUpdates()->partChannel( + getApp()->getTwitch()->getBTTVLiveUpdates()->partChannel( this->roomId()); } - if (getIApp()->getTwitch()->getSeventvEventAPI()) + if (getApp()->getTwitch()->getSeventvEventAPI()) { - getIApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel( + getApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel( this->roomId()); } } @@ -332,7 +332,7 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward) << "] Channel point reward added:" << reward.id << "," << reward.title << "," << reward.isUserInputRequired; - auto *server = getIApp()->getTwitch(); + auto *server = getApp()->getTwitch(); auto it = std::remove_if( this->waitingRedemptions_.begin(), this->waitingRedemptions_.end(), [&](const QueuedRedemption &msg) { @@ -426,7 +426,7 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate) qCDebug(chatterinoTwitch).nospace().noquote() << "[TwitchChannel " << this->getName() << "] Online"; - getIApp()->getNotifications()->notifyTwitchChannelLive({ + getApp()->getNotifications()->notifyTwitchChannelLive({ .channelId = this->roomId(), .channelName = this->getName(), .displayName = this->getDisplayName(), @@ -452,7 +452,7 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate) &builder); this->addMessage(builder.release(), MessageContext::Original); - getIApp()->getNotifications()->notifyTwitchChannelOffline( + getApp()->getNotifications()->notifyTwitchChannelOffline( this->roomId()); } }; @@ -509,7 +509,7 @@ void TwitchChannel::showLoginMessage() { const auto linkColor = MessageColor(MessageColor::Link); const auto accountsLink = Link(Link::OpenAccountsPage, QString()); - const auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + const auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); const auto expirationText = QStringLiteral("You need to log in to send messages. You can link your " "Twitch account"); @@ -532,7 +532,7 @@ void TwitchChannel::showLoginMessage() void TwitchChannel::roomIdChanged() { - if (getIApp()->isTest()) + if (getApp()->isTest()) { return; } @@ -544,7 +544,7 @@ void TwitchChannel::roomIdChanged() this->refreshSevenTVChannelEmotes(false); this->joinBttvChannel(); this->listenSevenTVCosmetics(); - getIApp()->getTwitchLiveController()->add( + getApp()->getTwitchLiveController()->add( std::dynamic_pointer_cast(shared_from_this())); } @@ -710,7 +710,7 @@ void TwitchChannel::setStaff(bool value) bool TwitchChannel::isBroadcaster() const { - auto *app = getIApp(); + auto *app = getApp(); return this->getName() == app->getAccounts()->twitch.getCurrent()->getUserName(); @@ -728,7 +728,7 @@ bool TwitchChannel::canReconnect() const void TwitchChannel::reconnect() { - getIApp()->getTwitchAbstract()->connect(); + getApp()->getTwitchAbstract()->connect(); } QString TwitchChannel::getCurrentStreamID() const @@ -753,7 +753,7 @@ void TwitchChannel::setRoomId(const QString &id) { *this->roomID_.access() = id; // This is intended for tests and benchmarks. See comment in constructor. - if (!getIApp()->isTest()) + if (!getApp()->isTest()) { this->roomIdChanged(); this->loadRecentMessages(); @@ -854,17 +854,17 @@ const QString &TwitchChannel::seventvEmoteSetID() const void TwitchChannel::joinBttvChannel() const { - if (getIApp()->getTwitch()->getBTTVLiveUpdates()) + if (getApp()->getTwitch()->getBTTVLiveUpdates()) { const auto currentAccount = - getIApp()->getAccounts()->twitch.getCurrent(); + getApp()->getAccounts()->twitch.getCurrent(); QString userName; if (currentAccount && !currentAccount->isAnon()) { userName = currentAccount->getUserName(); } - getIApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel( - this->roomId(), userName); + getApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel(this->roomId(), + userName); } } @@ -1012,14 +1012,14 @@ void TwitchChannel::updateSeventvData(const QString &newUserID, this->seventvUserID_ = newUserID; this->seventvEmoteSetID_ = newEmoteSetID; runInGuiThread([this, oldUserID, oldEmoteSetID]() { - if (getIApp()->getTwitch()->getSeventvEventAPI()) + if (getApp()->getTwitch()->getSeventvEventAPI()) { - getIApp()->getTwitch()->getSeventvEventAPI()->subscribeUser( + getApp()->getTwitch()->getSeventvEventAPI()->subscribeUser( this->seventvUserID_, this->seventvEmoteSetID_); if (oldUserID || oldEmoteSetID) { - getIApp()->getTwitch()->dropSeventvChannel( + getApp()->getTwitch()->dropSeventvChannel( oldUserID.value_or(QString()), oldEmoteSetID.value_or(QString())); } @@ -1215,7 +1215,7 @@ void TwitchChannel::loadRecentMessages() tc->addRecentChatter(msg->displayName); } - getIApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages( + getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages( msgs); }, [weak]() { @@ -1303,7 +1303,7 @@ void TwitchChannel::loadRecentMessagesReconnect() void TwitchChannel::refreshPubSub() { - if (getIApp()->isTest()) + if (getApp()->isTest()) { return; } @@ -1314,17 +1314,17 @@ void TwitchChannel::refreshPubSub() return; } - auto currentAccount = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentAccount = getApp()->getAccounts()->twitch.getCurrent(); - getIApp()->getTwitchPubSub()->setAccount(currentAccount); + getApp()->getTwitchPubSub()->setAccount(currentAccount); - getIApp()->getTwitchPubSub()->listenToChannelModerationActions(roomId); + getApp()->getTwitchPubSub()->listenToChannelModerationActions(roomId); if (this->hasModRights()) { - getIApp()->getTwitchPubSub()->listenToAutomod(roomId); - getIApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId); + getApp()->getTwitchPubSub()->listenToAutomod(roomId); + getApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId); } - getIApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId); + getApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId); } void TwitchChannel::refreshChatters() @@ -1350,7 +1350,7 @@ void TwitchChannel::refreshChatters() // Get chatter list via helix api getHelix()->getChatters( this->roomId(), - getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), + getApp()->getAccounts()->twitch.getCurrent()->getUserId(), MAX_CHATTERS_TO_FETCH, [this, weak = weakOf(this)](auto result) { if (auto shared = weak.lock()) @@ -1710,7 +1710,7 @@ std::vector TwitchChannel::ffzChannelBadges( std::vector badges; - const auto *ffzBadges = getIApp()->getFfzBadges(); + const auto *ffzBadges = getApp()->getFfzBadges(); for (const auto &badgeID : it->second) { @@ -1769,7 +1769,7 @@ void TwitchChannel::updateSevenTVActivity() QStringLiteral("https://7tv.io/v3/users/%1/presences"); const auto currentSeventvUserID = - getIApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID(); + getApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID(); if (currentSeventvUserID.isEmpty()) { return; @@ -1791,7 +1791,7 @@ void TwitchChannel::updateSevenTVActivity() qCDebug(chatterinoSeventv) << "Sending activity in" << this->getName(); - getIApp()->getSeventvAPI()->updatePresence( + getApp()->getSeventvAPI()->updatePresence( this->roomId(), currentSeventvUserID, [chan = weakOf(this)]() { const auto self = @@ -1811,9 +1811,9 @@ void TwitchChannel::updateSevenTVActivity() void TwitchChannel::listenSevenTVCosmetics() const { - if (getIApp()->getTwitch()->getSeventvEventAPI()) + if (getApp()->getTwitch()->getSeventvEventAPI()) { - getIApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel( + getApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel( this->roomId()); } } diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 28d4ad4b4..dc12d562b 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -51,7 +51,7 @@ void sendHelixMessage(const std::shared_ptr &channel, { .broadcasterID = broadcasterID, .senderID = - getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), + getApp()->getAccounts()->twitch.getCurrent()->getUserId(), .message = message, .replyParentMessageID = replyParentId, }, @@ -167,7 +167,7 @@ TwitchIrcServer::TwitchIrcServer() void TwitchIrcServer::initialize() { - getIApp()->getAccounts()->twitch.currentUserChanged.connect([this]() { + getApp()->getAccounts()->twitch.currentUserChanged.connect([this]() { postToThread([this] { this->connect(); }); @@ -182,7 +182,7 @@ void TwitchIrcServer::initializeConnection(IrcConnection *connection, ConnectionType type) { std::shared_ptr account = - getIApp()->getAccounts()->twitch.getCurrent(); + getApp()->getAccounts()->twitch.getCurrent(); qCDebug(chatterinoTwitch) << "logging in as" << account->getUserName(); @@ -690,7 +690,7 @@ void TwitchIrcServer::setLastUserThatWhisperedMe(const QString &user) void TwitchIrcServer::reloadBTTVGlobalEmotes() { - getIApp()->getBttvEmotes()->loadEmotes(); + getApp()->getBttvEmotes()->loadEmotes(); } void TwitchIrcServer::reloadAllBTTVChannelEmotes() @@ -705,7 +705,7 @@ void TwitchIrcServer::reloadAllBTTVChannelEmotes() void TwitchIrcServer::reloadFFZGlobalEmotes() { - getIApp()->getFfzEmotes()->loadEmotes(); + getApp()->getFfzEmotes()->loadEmotes(); } void TwitchIrcServer::reloadAllFFZChannelEmotes() @@ -720,7 +720,7 @@ void TwitchIrcServer::reloadAllFFZChannelEmotes() void TwitchIrcServer::reloadSevenTVGlobalEmotes() { - getIApp()->getSeventvEmotes()->loadGlobalEmotes(); + getApp()->getSeventvEmotes()->loadGlobalEmotes(); } void TwitchIrcServer::reloadAllSevenTVChannelEmotes() diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index a5fa340b7..066ee9bca 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -92,7 +92,7 @@ namespace { const QString &originalMessage, int messageOffset) { - auto *app = getIApp(); + auto *app = getApp(); if (!emote.contains(':')) { return; @@ -167,7 +167,7 @@ namespace { } if (auto globalBadge = - getIApp()->getTwitchBadges()->badge(badge.key_, badge.value_)) + getApp()->getTwitchBadges()->badge(badge.key_, badge.value_)) { return globalBadge; } @@ -673,7 +673,7 @@ void TwitchMessageBuilder::addWords( // 1. Add text before the emote QString preText = word.left(currentTwitchEmote.start - cursor); for (auto &variant : - getIApp()->getEmotes()->getEmojis()->parse(preText)) + getApp()->getEmotes()->getEmojis()->parse(preText)) { boost::apply_visitor( [&](auto &&arg) { @@ -693,7 +693,7 @@ void TwitchMessageBuilder::addWords( } // split words - for (auto &variant : getIApp()->getEmotes()->getEmojis()->parse(word)) + for (auto &variant : getApp()->getEmotes()->getEmojis()->parse(word)) { boost::apply_visitor( [&](auto &&arg) { @@ -937,7 +937,7 @@ void TwitchMessageBuilder::parseThread() void TwitchMessageBuilder::parseUsernameColor() { - const auto *userData = getIApp()->getUserData(); + const auto *userData = getApp()->getUserData(); assert(userData != nullptr); if (const auto &user = userData->getUser(this->userId_)) @@ -991,7 +991,7 @@ void TwitchMessageBuilder::parseUsername() } // Update current user color if this is our message - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); if (this->ircMessage->nick() == currentUser->getUserName()) { currentUser->setColor(this->usernameColor_); @@ -1000,7 +1000,7 @@ void TwitchMessageBuilder::parseUsername() void TwitchMessageBuilder::appendUsername() { - auto *app = getIApp(); + auto *app = getApp(); QString username = this->userName; this->message().loginName = username; @@ -1256,7 +1256,7 @@ void TwitchMessageBuilder::processIgnorePhrases( Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) { - auto *app = getIApp(); + auto *app = getApp(); const auto *globalBttvEmotes = app->getBttvEmotes(); const auto *globalFfzEmotes = app->getFfzEmotes(); @@ -1410,8 +1410,7 @@ void TwitchMessageBuilder::appendTwitchBadges() void TwitchMessageBuilder::appendChatterinoBadges() { - if (auto badge = - getIApp()->getChatterinoBadges()->getBadge({this->userId_})) + if (auto badge = getApp()->getChatterinoBadges()->getBadge({this->userId_})) { this->emplace(*badge, MessageElementFlag::BadgeChatterino); @@ -1421,7 +1420,7 @@ void TwitchMessageBuilder::appendChatterinoBadges() void TwitchMessageBuilder::appendFfzBadges() { for (const auto &badge : - getIApp()->getFfzBadges()->getUserBadges({this->userId_})) + getApp()->getFfzBadges()->getUserBadges({this->userId_})) { this->emplace( badge.emote, MessageElementFlag::BadgeFfz, badge.color); @@ -1442,7 +1441,7 @@ void TwitchMessageBuilder::appendFfzBadges() void TwitchMessageBuilder::appendSeventvBadges() { - if (auto badge = getIApp()->getSeventvBadges()->getBadge({this->userId_})) + if (auto badge = getApp()->getSeventvBadges()->getBadge({this->userId_})) { this->emplace(*badge, MessageElementFlag::BadgeSevenTV); } @@ -1585,7 +1584,7 @@ void TwitchMessageBuilder::appendChannelPointRewardMessage( if (reward.id == "CELEBRATION") { const auto emotePtr = - getIApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote( + getApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote( EmoteId{reward.emoteId}, EmoteName{reward.emoteName}); builder->emplace(emotePtr, MessageElementFlag::ChannelPointReward, @@ -2060,7 +2059,7 @@ std::pair TwitchMessageBuilder::makeAutomodMessage( // Normally highlights would be checked & triggered during the builder parse steps // and when the message is added to the channel // We do this a bit weird since the message comes in from PubSub and not the normal message route - auto [highlighted, highlightResult] = getIApp()->getHighlights()->check( + auto [highlighted, highlightResult] = getApp()->getHighlights()->check( {}, {}, action.target.login, action.message, message2->flags); if (highlighted) { @@ -2256,7 +2255,7 @@ std::pair TwitchMessageBuilder::makeLowTrustUserMessage( else { const auto emotePtr = - getIApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote( + getApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote( EmoteId{fragment.emoteID}, EmoteName{fragment.text}); builder2.emplace( emotePtr, MessageElementFlag::TwitchEmote, MessageColor::Text); diff --git a/src/singletons/Badges.cpp b/src/singletons/Badges.cpp deleted file mode 100644 index da38def4f..000000000 --- a/src/singletons/Badges.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Badges.hpp" - -namespace chatterino { - -Badges::Badges() -{ -} - -} // namespace chatterino diff --git a/src/singletons/Badges.hpp b/src/singletons/Badges.hpp deleted file mode 100644 index e7288ac5c..000000000 --- a/src/singletons/Badges.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "common/Singleton.hpp" - -namespace chatterino { - -class Badges : public Singleton -{ -public: - Badges(); -}; - -} // namespace chatterino diff --git a/src/singletons/CrashHandler.cpp b/src/singletons/CrashHandler.cpp index 84f19793c..ca9ea915c 100644 --- a/src/singletons/CrashHandler.cpp +++ b/src/singletons/CrashHandler.cpp @@ -130,10 +130,6 @@ using namespace std::string_literals; CrashHandler::CrashHandler(const Paths &paths_) : 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 9fbdf358c..3f2a45262 100644 --- a/src/singletons/CrashHandler.hpp +++ b/src/singletons/CrashHandler.hpp @@ -1,7 +1,5 @@ #pragma once -#include "common/Singleton.hpp" - #include #ifdef CHATTERINO_WITH_CRASHPAD @@ -15,7 +13,7 @@ namespace chatterino { class Args; class Paths; -class CrashHandler : public Singleton +class CrashHandler { const Paths &paths; @@ -30,8 +28,6 @@ public: /// Sets and saves whether Chatterino should restart on a crash void saveShouldRecover(bool value); - 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 5051dab69..a5b169902 100644 --- a/src/singletons/Emotes.cpp +++ b/src/singletons/Emotes.cpp @@ -3,19 +3,10 @@ namespace chatterino { Emotes::Emotes() -{ -} - -void Emotes::initialize(Settings &settings, const Paths &paths) { this->emojis.load(); this->gifTimer.initialize(); } -bool Emotes::isIgnoredEmote(const QString &) -{ - return false; -} - } // namespace chatterino diff --git a/src/singletons/Emotes.hpp b/src/singletons/Emotes.hpp index 3ffeb6d7a..9b2520391 100644 --- a/src/singletons/Emotes.hpp +++ b/src/singletons/Emotes.hpp @@ -1,15 +1,11 @@ #pragma once -#include "common/Singleton.hpp" #include "providers/emoji/Emojis.hpp" #include "providers/twitch/TwitchEmotes.hpp" #include "singletons/helper/GifTimer.hpp" namespace chatterino { -class Settings; -class Paths; - class IEmotes { public: @@ -20,15 +16,11 @@ public: virtual GIFTimer &getGIFTimer() = 0; }; -class Emotes final : public IEmotes, public Singleton +class Emotes final : public IEmotes { public: Emotes(); - void initialize(Settings &settings, const Paths &paths) override; - - bool isIgnoredEmote(const QString &emote); - ITwitchEmotes *getTwitchEmotes() final { return &this->twitch; diff --git a/src/singletons/ImageUploader.cpp b/src/singletons/ImageUploader.cpp index b6a191e85..b5fe9c43a 100644 --- a/src/singletons/ImageUploader.cpp +++ b/src/singletons/ImageUploader.cpp @@ -54,7 +54,7 @@ void ImageUploader::logToFile(const QString &originalFilePath, { const QString logFileName = combinePath((getSettings()->logPath.getValue().isEmpty() - ? getIApp()->getPaths().messageLogDirectory + ? getApp()->getPaths().messageLogDirectory : getSettings()->logPath), "ImageUploader.json"); @@ -123,10 +123,6 @@ QString getLinkFromResponse(NetworkResult response, QString pattern) return pattern; } -void ImageUploader::save() -{ -} - void ImageUploader::sendImageUploadRequest(RawImageData imageData, ChannelPtr channel, QPointer textEdit) diff --git a/src/singletons/ImageUploader.hpp b/src/singletons/ImageUploader.hpp index 41f4c8b60..80cd4ef1c 100644 --- a/src/singletons/ImageUploader.hpp +++ b/src/singletons/ImageUploader.hpp @@ -1,7 +1,5 @@ #pragma once -#include "common/Singleton.hpp" - #include #include #include @@ -22,7 +20,7 @@ struct RawImageData { QString filePath; }; -class ImageUploader final : public Singleton +class ImageUploader final { public: /** @@ -33,7 +31,6 @@ public: std::pair, QString> getImages( const QMimeData *source) const; - void save() override; void upload(std::queue images, ChannelPtr channel, QPointer outputTextEdit); diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index 524913ef8..58dfd1b2b 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -238,11 +238,10 @@ void NativeMessagingServer::ReceiverThread::handleSelect( postToThread([=] { if (!name.isEmpty()) { - auto channel = - getIApp()->getTwitchAbstract()->getOrAddChannel(name); - if (getIApp()->getTwitch()->getWatchingChannel().get() != channel) + auto channel = getApp()->getTwitchAbstract()->getOrAddChannel(name); + if (getApp()->getTwitch()->getWatchingChannel().get() != channel) { - getIApp()->getTwitch()->setWatchingChannel(channel); + getApp()->getTwitch()->setWatchingChannel(channel); } } @@ -253,7 +252,7 @@ void NativeMessagingServer::ReceiverThread::handleSelect( if (!name.isEmpty()) { window->setChannel( - getIApp()->getTwitchAbstract()->getOrAddChannel(name)); + getApp()->getTwitchAbstract()->getOrAddChannel(name)); } #endif } @@ -305,7 +304,7 @@ void NativeMessagingServer::syncChannels(const QJsonArray &twitchChannels) } // the deduping is done on the extension side updated.emplace_back( - getIApp()->getTwitchAbstract()->getOrAddChannel(name)); + getApp()->getTwitchAbstract()->getOrAddChannel(name)); } // This will destroy channels that aren't used anymore. diff --git a/src/singletons/StreamerMode.cpp b/src/singletons/StreamerMode.cpp index 5b8b4402b..659bfd9ea 100644 --- a/src/singletons/StreamerMode.cpp +++ b/src/singletons/StreamerMode.cpp @@ -74,7 +74,7 @@ bool isBroadcasterSoftwareActive() shouldShowTimeoutWarning = false; postToThread([] { - getIApp()->getTwitchAbstract()->addGlobalSystemMessage( + getApp()->getTwitchAbstract()->addGlobalSystemMessage( "Streamer Mode is set to Automatic, but pgrep timed " "out. This can happen if your system lagged at the " "wrong moment. If Streamer Mode continues to not work, " @@ -94,7 +94,7 @@ bool isBroadcasterSoftwareActive() shouldShowWarning = false; postToThread([] { - getIApp()->getTwitchAbstract()->addGlobalSystemMessage( + getApp()->getTwitchAbstract()->addGlobalSystemMessage( "Streamer Mode is set to Automatic, but pgrep is " "missing. " "Install it to fix the issue or set Streamer Mode to " diff --git a/src/singletons/Theme.cpp b/src/singletons/Theme.cpp index 2441e3652..bbd29abf9 100644 --- a/src/singletons/Theme.cpp +++ b/src/singletons/Theme.cpp @@ -282,7 +282,7 @@ bool Theme::isSystemTheme() const return this->themeName == u"System"_s; } -void Theme::initialize(Settings &settings, const Paths &paths) +Theme::Theme(const Paths &paths) { this->themeName.connect( [this](auto themeName) { @@ -307,7 +307,7 @@ void Theme::initialize(Settings &settings, const Paths &paths) if (this->isSystemTheme()) { this->update(); - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); } }); #endif @@ -597,7 +597,7 @@ void Theme::normalizeColor(QColor &color) const Theme *getTheme() { - return getIApp()->getThemes(); + return getApp()->getThemes(); } } // namespace chatterino diff --git a/src/singletons/Theme.hpp b/src/singletons/Theme.hpp index d64172e45..cb811e2db 100644 --- a/src/singletons/Theme.hpp +++ b/src/singletons/Theme.hpp @@ -1,7 +1,7 @@ #pragma once #include "common/ChatterinoSetting.hpp" -#include "common/Singleton.hpp" +#include "singletons/Paths.hpp" #include "util/RapidJsonSerializeQString.hpp" #include @@ -33,7 +33,7 @@ struct ThemeDescriptor { bool custom{}; }; -class Theme final : public Singleton +class Theme final { public: static const std::vector builtInThemes; @@ -43,7 +43,7 @@ public: static const int AUTO_RELOAD_INTERVAL_MS = 500; - void initialize(Settings &settings, const Paths &paths) final; + Theme(const Paths &paths); bool isLightTheme() const; bool isSystemTheme() const; diff --git a/src/singletons/Toasts.cpp b/src/singletons/Toasts.cpp index 3ca5b6e0c..26a82543a 100644 --- a/src/singletons/Toasts.cpp +++ b/src/singletons/Toasts.cpp @@ -35,7 +35,7 @@ using namespace literals; QString avatarFilePath(const QString &channelName) { // TODO: cleanup channel (to be used as a file) and use combinePath - return getIApp()->getPaths().twitchProfileAvatars % '/' % channelName % + return getApp()->getPaths().twitchProfileAvatars % '/' % channelName % u".png"; } @@ -74,7 +74,7 @@ bool Toasts::isEnabled() { #ifdef Q_OS_WIN return WinToast::isCompatible() && getSettings()->notificationToast && - !(getIApp()->getStreamerMode()->isEnabled() && + !(getApp()->getStreamerMode()->isEnabled() && getSettings()->streamerModeSuppressLiveNotifications); #else return false; diff --git a/src/singletons/Toasts.hpp b/src/singletons/Toasts.hpp index 83e64a081..e4c2ad234 100644 --- a/src/singletons/Toasts.hpp +++ b/src/singletons/Toasts.hpp @@ -1,7 +1,5 @@ #pragma once -#include "common/Singleton.hpp" - #include #include @@ -16,7 +14,7 @@ enum class ToastReaction { DontOpen = 3 }; -class Toasts final : public Singleton +class Toasts final { public: void sendChannelNotification(const QString &channelName, diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index 66a0f606e..cb5630c25 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -118,7 +118,7 @@ WindowManager::WindowManager(const Paths &paths) this->saveTimer->setSingleShot(true); QObject::connect(this->saveTimer, &QTimer::timeout, [] { - getIApp()->getWindows()->save(); + getApp()->getWindows()->save(); }); } @@ -341,21 +341,18 @@ void WindowManager::setEmotePopupBounds(QRect bounds) } } -void WindowManager::initialize(Settings &settings, const Paths &paths) +void WindowManager::initialize(Settings &settings) { - (void)paths; assertInGuiThread(); // We can safely ignore this signal connection since both Themes and WindowManager // share the Application state lifetime // NOTE: APPLICATION_LIFETIME std::ignore = - getIApp()->getThemes()->repaintVisibleChatWidgets_.connect([this] { + getApp()->getThemes()->repaintVisibleChatWidgets_.connect([this] { this->repaintVisibleChatWidgets(); }); - assert(!this->initialized_); - { WindowLayout windowLayout; @@ -368,7 +365,7 @@ void WindowManager::initialize(Settings &settings, const Paths &paths) windowLayout = this->loadWindowLayoutFromFile(); } - auto desired = getIApp()->getArgs().activateChannel; + auto desired = getApp()->getArgs().activateChannel; if (desired) { windowLayout.activateOrAddChannel(desired->provider, desired->name); @@ -428,8 +425,6 @@ void WindowManager::initialize(Settings &settings, const Paths &paths) settings.boldUsernames.connect([this](auto, auto) { this->forceLayoutChannelViews(); }); - - this->initialized_ = true; } void WindowManager::save() @@ -687,28 +682,28 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor) if (descriptor.type_ == "twitch") { - return getIApp()->getTwitchAbstract()->getOrAddChannel( + return getApp()->getTwitchAbstract()->getOrAddChannel( descriptor.channelName_); } else if (descriptor.type_ == "mentions") { - return getIApp()->getTwitch()->getMentionsChannel(); + return getApp()->getTwitch()->getMentionsChannel(); } else if (descriptor.type_ == "watching") { - return getIApp()->getTwitch()->getWatchingChannel(); + return getApp()->getTwitch()->getWatchingChannel(); } else if (descriptor.type_ == "whispers") { - return getIApp()->getTwitch()->getWhispersChannel(); + return getApp()->getTwitch()->getWhispersChannel(); } else if (descriptor.type_ == "live") { - return getIApp()->getTwitch()->getLiveChannel(); + return getApp()->getTwitch()->getLiveChannel(); } else if (descriptor.type_ == "automod") { - return getIApp()->getTwitch()->getAutomodChannel(); + return getApp()->getTwitch()->getAutomodChannel(); } else if (descriptor.type_ == "irc") { @@ -717,7 +712,7 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor) } else if (descriptor.type_ == "misc") { - return getIApp()->getTwitchAbstract()->getChannelOrEmpty( + return getApp()->getTwitchAbstract()->getChannelOrEmpty( descriptor.channelName_); } diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index 21040fab0..49c60d268 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -1,7 +1,6 @@ #pragma once #include "common/FlagsEnum.hpp" -#include "common/Singleton.hpp" #include "widgets/splits/SplitContainer.hpp" #include @@ -32,13 +31,13 @@ enum class WindowType; enum class SettingsDialogPreference; class FramelessEmbedWindow; -class WindowManager final : public Singleton +class WindowManager final { public: static const QString WINDOW_LAYOUT_FILENAME; explicit WindowManager(const Paths &paths); - ~WindowManager() override; + ~WindowManager(); WindowManager(const WindowManager &) = delete; WindowManager(WindowManager &&) = delete; @@ -102,8 +101,9 @@ public: QRect emotePopupBounds() const; void setEmotePopupBounds(QRect bounds); - void initialize(Settings &settings, const Paths &paths) override; - void save() override; + // Set up some final signals & actually show the windows + void initialize(Settings &settings); + void save(); void closeAll(); int getGeneration() const; @@ -151,7 +151,6 @@ private: // Contains the full path to the window layout file, e.g. /home/pajlada/.local/share/Chatterino/Settings/window-layout.json const QString windowLayoutFilePath; - bool initialized_ = false; bool shuttingDown_ = false; QRect emotePopupBounds_; diff --git a/src/singletons/helper/GifTimer.cpp b/src/singletons/helper/GifTimer.cpp index 9eaf1162f..564ec961c 100644 --- a/src/singletons/helper/GifTimer.cpp +++ b/src/singletons/helper/GifTimer.cpp @@ -31,7 +31,7 @@ void GIFTimer::initialize() this->position_ += GIF_FRAME_LENGTH; this->signal.invoke(); - getIApp()->getWindows()->repaintGifEmotes(); + getApp()->getWindows()->repaintGifEmotes(); }); } diff --git a/src/singletons/helper/LoggingChannel.cpp b/src/singletons/helper/LoggingChannel.cpp index ad8cfb9a2..dcce92f23 100644 --- a/src/singletons/helper/LoggingChannel.cpp +++ b/src/singletons/helper/LoggingChannel.cpp @@ -88,7 +88,7 @@ LoggingChannel::LoggingChannel(QString _channelName, QString _platform) getSettings()->logPath.connect([this](const QString &logPath, auto) { this->baseDirectory = logPath.isEmpty() - ? getIApp()->getPaths().messageLogDirectory + ? getApp()->getPaths().messageLogDirectory : logPath; this->openLogFile(); }); diff --git a/src/util/InitUpdateButton.cpp b/src/util/InitUpdateButton.cpp index 349fb78bb..8636a85f1 100644 --- a/src/util/InitUpdateButton.cpp +++ b/src/util/InitUpdateButton.cpp @@ -41,7 +41,7 @@ void initUpdateButton(Button &button, } break; case UpdateDialog::Install: { - getIApp()->getUpdates().installUpdates(); + getApp()->getUpdates().installUpdates(); } break; } @@ -53,17 +53,17 @@ void initUpdateButton(Button &button, // update image when state changes auto updateChange = [&button](auto) { - button.setVisible(getIApp()->getUpdates().shouldShowUpdateButton()); + button.setVisible(getApp()->getUpdates().shouldShowUpdateButton()); - const auto *imageUrl = getIApp()->getUpdates().isError() + const auto *imageUrl = getApp()->getUpdates().isError() ? ":/buttons/updateError.png" : ":/buttons/update.png"; button.setPixmap(QPixmap(imageUrl)); }; - updateChange(getIApp()->getUpdates().getStatus()); + updateChange(getApp()->getUpdates().getStatus()); - signalHolder.managedConnect(getIApp()->getUpdates().statusUpdated, + signalHolder.managedConnect(getApp()->getUpdates().statusUpdated, [updateChange](auto status) { updateChange(status); }); diff --git a/src/util/StreamLink.cpp b/src/util/StreamLink.cpp index b4e4370d2..f9869ce4d 100644 --- a/src/util/StreamLink.cpp +++ b/src/util/StreamLink.cpp @@ -183,7 +183,7 @@ void openStreamlinkForChannel(const QString &channel) { static const QString INFO_TEMPLATE("Opening %1 in Streamlink ..."); - auto *currentPage = dynamic_cast(getIApp() + auto *currentPage = dynamic_cast(getApp() ->getWindows() ->getMainWindow() .getNotebook() diff --git a/src/widgets/BaseWidget.cpp b/src/widgets/BaseWidget.cpp index 564ba5963..f2a6160d6 100644 --- a/src/widgets/BaseWidget.cpp +++ b/src/widgets/BaseWidget.cpp @@ -18,7 +18,7 @@ namespace chatterino { BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) - , theme(getIApp()->getThemes()) + , theme(getApp()->getThemes()) { this->signalHolder_.managedConnect(this->theme->updated, [this]() { this->themeChangedEvent(); diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 6d636b9d6..12e87ff73 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -712,7 +712,7 @@ void BaseWindow::resizeEvent(QResizeEvent *) // Queue up save because: Window resized if (!flags_.has(DisableLayoutSave)) { - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); } #ifdef USEWINSDK @@ -727,7 +727,7 @@ void BaseWindow::moveEvent(QMoveEvent *event) #ifdef CHATTERINO if (!flags_.has(DisableLayoutSave)) { - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); } #endif @@ -909,7 +909,7 @@ void BaseWindow::scaleChangedEvent(float scale) #endif this->setFont( - getIApp()->getFonts()->getFont(FontStyle::UiTabs, this->scale())); + getApp()->getFonts()->getFont(FontStyle::UiTabs, this->scale())); } void BaseWindow::paintEvent(QPaintEvent *) diff --git a/src/widgets/FramelessEmbedWindow.cpp b/src/widgets/FramelessEmbedWindow.cpp index 9735edcee..109a8bd55 100644 --- a/src/widgets/FramelessEmbedWindow.cpp +++ b/src/widgets/FramelessEmbedWindow.cpp @@ -54,7 +54,7 @@ bool FramelessEmbedWindow::nativeEvent(const QByteArray &eventType, auto channelName = root.value("channel-name").toString(); this->split_->setChannel( - getIApp()->getTwitchAbstract()->getOrAddChannel( + getApp()->getTwitchAbstract()->getOrAddChannel( channelName)); } } diff --git a/src/widgets/Label.cpp b/src/widgets/Label.cpp index 529fb7575..6f56acb27 100644 --- a/src/widgets/Label.cpp +++ b/src/widgets/Label.cpp @@ -16,7 +16,7 @@ Label::Label(BaseWidget *parent, QString text, FontStyle style) , text_(std::move(text)) , fontStyle_(style) { - this->connections_.managedConnect(getIApp()->getFonts()->fontChanged, + this->connections_.managedConnect(getApp()->getFonts()->fontChanged, [this] { this->updateSize(); }); @@ -89,10 +89,10 @@ void Label::paintEvent(QPaintEvent *) { QPainter painter(this); - QFontMetrics metrics = getIApp()->getFonts()->getFontMetrics( + QFontMetrics metrics = getApp()->getFonts()->getFontMetrics( this->getFontStyle(), this->scale()); painter.setFont( - getIApp()->getFonts()->getFont(this->getFontStyle(), this->scale())); + getApp()->getFonts()->getFont(this->getFontStyle(), this->scale())); int offset = this->getOffset(); @@ -119,7 +119,7 @@ void Label::paintEvent(QPaintEvent *) void Label::updateSize() { QFontMetrics metrics = - getIApp()->getFonts()->getFontMetrics(this->fontStyle_, this->scale()); + getApp()->getFonts()->getFontMetrics(this->fontStyle_, this->scale()); int width = metrics.horizontalAdvance(this->text_) + (2 * this->getOffset()); diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index a3871eee9..0f4fa3597 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -97,7 +97,7 @@ NotebookTab *Notebook::addPageAt(QWidget *page, int position, QString title, bool select) { // Queue up save because: Tab added - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); auto *tab = new NotebookTab(this); tab->page = page; @@ -134,7 +134,7 @@ NotebookTab *Notebook::addPageAt(QWidget *page, int position, QString title, void Notebook::removePage(QWidget *page) { // Queue up save because: Tab removed - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); int removingIndex = this->indexOf(page); assert(removingIndex != -1); @@ -567,7 +567,7 @@ void Notebook::rearrangePage(QWidget *page, int index) } // Queue up save because: Tab rearranged - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); this->items_.move(this->indexOf(page), index); @@ -608,16 +608,16 @@ void Notebook::setShowTabs(bool value) void Notebook::showTabVisibilityInfoPopup() { - auto unhideSeq = getIApp()->getHotkeys()->getDisplaySequence( + auto unhideSeq = getApp()->getHotkeys()->getDisplaySequence( HotkeyCategory::Window, "setTabVisibility", {std::vector()}); if (unhideSeq.isEmpty()) { - unhideSeq = getIApp()->getHotkeys()->getDisplaySequence( + unhideSeq = getApp()->getHotkeys()->getDisplaySequence( HotkeyCategory::Window, "setTabVisibility", {{"toggle"}}); } if (unhideSeq.isEmpty()) { - unhideSeq = getIApp()->getHotkeys()->getDisplaySequence( + unhideSeq = getApp()->getHotkeys()->getDisplaySequence( HotkeyCategory::Window, "setTabVisibility", {{"on"}}); } QString hotkeyInfo = "(currently unbound)"; @@ -670,7 +670,7 @@ void Notebook::updateTabVisibility() void Notebook::updateTabVisibilityMenuAction() { - const auto *hotkeys = getIApp()->getHotkeys(); + const auto *hotkeys = getApp()->getHotkeys(); auto toggleSeq = hotkeys->getDisplaySequence( HotkeyCategory::Window, "setTabVisibility", {std::vector()}); @@ -1400,7 +1400,7 @@ SplitNotebook::SplitNotebook(Window *parent) this->signalHolder_, true); this->signalHolder_.managedConnect( - getIApp()->getWindows()->selectSplit, [this](Split *split) { + getApp()->getWindows()->selectSplit, [this](Split *split) { for (auto &&item : this->items()) { if (auto *sc = dynamic_cast(item.page)) @@ -1418,13 +1418,13 @@ SplitNotebook::SplitNotebook(Window *parent) }); this->signalHolder_.managedConnect( - getIApp()->getWindows()->selectSplitContainer, + getApp()->getWindows()->selectSplitContainer, [this](SplitContainer *sc) { this->select(sc); }); this->signalHolder_.managedConnect( - getIApp()->getWindows()->scrollToMessageSignal, + getApp()->getWindows()->scrollToMessageSignal, [this](const MessagePtr &message) { for (auto &&item : this->items()) { @@ -1515,7 +1515,7 @@ void SplitNotebook::addCustomButtons() settingsBtn->setIcon(NotebookButton::Settings); QObject::connect(settingsBtn, &NotebookButton::leftClicked, [this] { - getIApp()->getWindows()->showSettingsDialog(this); + getApp()->getWindows()->showSettingsDialog(this); }); // account @@ -1529,7 +1529,7 @@ void SplitNotebook::addCustomButtons() userBtn->setIcon(NotebookButton::User); QObject::connect(userBtn, &NotebookButton::leftClicked, [this, userBtn] { - getIApp()->getWindows()->showAccountSelectPopup( + getApp()->getWindows()->showAccountSelectPopup( this->mapToGlobal(userBtn->rect().bottomRight())); }); @@ -1542,18 +1542,18 @@ void SplitNotebook::addCustomButtons() this->streamerModeIcon_ = this->addCustomButton(); QObject::connect(this->streamerModeIcon_, &NotebookButton::leftClicked, [this] { - getIApp()->getWindows()->showSettingsDialog( + getApp()->getWindows()->showSettingsDialog( this, SettingsDialogPreference::StreamerMode); }); - QObject::connect(getIApp()->getStreamerMode(), &IStreamerMode::changed, - this, &SplitNotebook::updateStreamerModeIcon); + QObject::connect(getApp()->getStreamerMode(), &IStreamerMode::changed, this, + &SplitNotebook::updateStreamerModeIcon); this->updateStreamerModeIcon(); } void SplitNotebook::updateToggleOfflineTabsHotkey( NotebookTabVisibility newTabVisibility) { - auto *hotkeys = getIApp()->getHotkeys(); + auto *hotkeys = getApp()->getHotkeys(); auto getKeySequence = [&](auto argument) { return hotkeys->getDisplaySequence(HotkeyCategory::Window, "setTabVisibility", {{argument}}); @@ -1606,7 +1606,7 @@ void SplitNotebook::updateStreamerModeIcon() getResources().buttons.streamerModeEnabledDark); } this->streamerModeIcon_->setVisible( - getIApp()->getStreamerMode()->isEnabled()); + getApp()->getStreamerMode()->isEnabled()); } void SplitNotebook::themeChangedEvent() diff --git a/src/widgets/TooltipWidget.cpp b/src/widgets/TooltipWidget.cpp index 00f5a2bec..14328e91f 100644 --- a/src/widgets/TooltipWidget.cpp +++ b/src/widgets/TooltipWidget.cpp @@ -47,13 +47,13 @@ TooltipWidget::TooltipWidget(BaseWidget *parent) this->setLayout(this->vLayout_); this->currentStyle_ = TooltipStyle::Vertical; - this->connections_.managedConnect(getIApp()->getFonts()->fontChanged, + this->connections_.managedConnect(getApp()->getFonts()->fontChanged, [this] { this->updateFont(); }); this->updateFont(); - auto *windows = getIApp()->getWindows(); + auto *windows = getApp()->getWindows(); this->connections_.managedConnect(windows->gifRepaintRequested, [this] { if (!this->isVisible()) { @@ -300,8 +300,8 @@ void TooltipWidget::scaleChangedEvent(float) void TooltipWidget::updateFont() { - this->setFont(getIApp()->getFonts()->getFont(FontStyle::ChatMediumSmall, - this->scale())); + this->setFont(getApp()->getFonts()->getFont(FontStyle::ChatMediumSmall, + this->scale())); } void TooltipWidget::setWordWrap(bool wrap) diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index f7df6bcb0..ee836d185 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -64,7 +64,7 @@ Window::Window(WindowType type, QWidget *parent) #endif this->bSignals_.emplace_back( - getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] { + getApp()->getAccounts()->twitch.currentUserChanged.connect([this] { this->onAccountSelected(); })); this->onAccountSelected(); @@ -78,7 +78,7 @@ Window::Window(WindowType type, QWidget *parent) this->resize(int(300 * this->scale()), int(500 * this->scale())); } - this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated, + this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, [this]() { this->clearShortcuts(); this->addShortcuts(); @@ -108,7 +108,7 @@ bool Window::event(QEvent *event) switch (event->type()) { case QEvent::WindowActivate: { - getIApp()->getWindows()->selectedWindow_ = this; + getApp()->getWindows()->selectedWindow_ = this; break; } @@ -145,14 +145,14 @@ void Window::closeEvent(QCloseEvent *) { if (this->type_ == WindowType::Main) { - getIApp()->getWindows()->save(); - getIApp()->getWindows()->closeAll(); + getApp()->getWindows()->save(); + getApp()->getWindows()->closeAll(); } // Ensure selectedWindow_ is never an invalid pointer. // WindowManager will return the main window if no window is pointed to by // `selectedWindow_`. - getIApp()->getWindows()->selectedWindow_ = nullptr; + getApp()->getWindows()->selectedWindow_ = nullptr; this->closed.invoke(); @@ -189,7 +189,7 @@ void Window::addCustomTitlebarButtons() // settings this->addTitleBarButton(TitleBarButtonStyle::Settings, [this] { - getIApp()->getWindows()->showSettingsDialog(this); + getApp()->getWindows()->showSettingsDialog(this); }); // updates @@ -199,7 +199,7 @@ void Window::addCustomTitlebarButtons() // account this->userLabel_ = this->addTitleBarLabel([this] { - getIApp()->getWindows()->showAccountSelectPopup( + getApp()->getWindows()->showAccountSelectPopup( this->userLabel_->mapToGlobal( this->userLabel_->rect().bottomLeft())); }); @@ -208,11 +208,11 @@ void Window::addCustomTitlebarButtons() // streamer mode this->streamerModeTitlebarIcon_ = this->addTitleBarButton(TitleBarButtonStyle::StreamerMode, [this] { - getIApp()->getWindows()->showSettingsDialog( + getApp()->getWindows()->showSettingsDialog( this, SettingsDialogPreference::StreamerMode); }); - QObject::connect(getIApp()->getStreamerMode(), &IStreamerMode::changed, - this, &Window::updateStreamerModeIcon); + QObject::connect(getApp()->getStreamerMode(), &IStreamerMode::changed, this, + &Window::updateStreamerModeIcon); // Update initial state this->updateStreamerModeIcon(); @@ -240,7 +240,7 @@ void Window::updateStreamerModeIcon() getResources().buttons.streamerModeEnabledDark); } this->streamerModeTitlebarIcon_->setVisible( - getIApp()->getStreamerMode()->isEnabled()); + getApp()->getStreamerMode()->isEnabled()); #else // clang-format off assert(false && "Streamer mode TitleBar icon should not exist on non-Windows OSes"); @@ -261,7 +261,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleMiscMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getIApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); @@ -269,7 +269,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleCheerMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getIApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); @@ -277,13 +277,12 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleLinkMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getIApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); actions.emplace("addRewardMessage", [=](std::vector) -> QString { rapidjson::Document doc; - auto app = getApp(); static bool alt = true; if (alt) { @@ -293,9 +292,9 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) oMessage->toInner() ->toInner(); - getIApp()->getTwitchAbstract()->addFakeMessage( + getApp()->getTwitchAbstract()->addFakeMessage( getSampleChannelRewardIRCMessage()); - getIApp()->getTwitchPubSub()->pointReward.redeemed.invoke( + getApp()->getTwitchPubSub()->pointReward.redeemed.invoke( oInnerMessage->data.value("redemption").toObject()); alt = !alt; } @@ -306,7 +305,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) auto oInnerMessage = oMessage->toInner() ->toInner(); - getIApp()->getTwitchPubSub()->pointReward.redeemed.invoke( + getApp()->getTwitchPubSub()->pointReward.redeemed.invoke( oInnerMessage->data.value("redemption").toObject()); alt = !alt; } @@ -317,7 +316,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleEmoteTestMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getIApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); @@ -325,7 +324,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleSubMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getIApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); #endif @@ -488,7 +487,7 @@ void Window::addShortcuts() splitContainer = this->notebook_->getOrAddSelectedPage(); } Split *split = new Split(splitContainer); - split->setChannel(getIApp()->getTwitchAbstract()->getOrAddChannel( + split->setChannel(getApp()->getTwitchAbstract()->getOrAddChannel( si.channelName)); split->setFilters(si.filters); splitContainer->insertSplit(split); @@ -499,7 +498,7 @@ void Window::addShortcuts() {"toggleLocalR9K", [](std::vector) -> QString { getSettings()->hideSimilar.setValue(!getSettings()->hideSimilar); - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); return ""; }}, {"openQuickSwitcher", @@ -619,7 +618,7 @@ void Window::addShortcuts() } else if (mode == 2) { - if (getIApp()->getStreamerMode()->isEnabled()) + if (getApp()->getStreamerMode()->isEnabled()) { getSettings()->enableStreamerMode.setValue( StreamerModeSetting::Disabled); @@ -685,7 +684,7 @@ void Window::addShortcuts() this->addDebugStuff(actions); - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::Window, actions, this); } @@ -756,7 +755,7 @@ void Window::addMenuBar() void Window::onAccountSelected() { - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); // update title (also append username on Linux and MacOS) QString windowTitle = Version::instance().fullVersion(); diff --git a/src/widgets/dialogs/BadgePickerDialog.cpp b/src/widgets/dialogs/BadgePickerDialog.cpp index 143372492..f45dbbbf1 100644 --- a/src/widgets/dialogs/BadgePickerDialog.cpp +++ b/src/widgets/dialogs/BadgePickerDialog.cpp @@ -58,7 +58,7 @@ BadgePickerDialog::BadgePickerDialog(QList badges, updateBadge(0); // Set icons. - getIApp()->getTwitchBadges()->getBadgeIcons( + getApp()->getTwitchBadges()->getBadgeIcons( badges, [&dropdown = this->dropdown_](QString identifier, const QIconPtr icon) { if (!dropdown) diff --git a/src/widgets/dialogs/EditHotkeyDialog.cpp b/src/widgets/dialogs/EditHotkeyDialog.cpp index 8a43c3dba..0bf4a8148 100644 --- a/src/widgets/dialogs/EditHotkeyDialog.cpp +++ b/src/widgets/dialogs/EditHotkeyDialog.cpp @@ -26,8 +26,7 @@ EditHotkeyDialog::EditHotkeyDialog(const std::shared_ptr hotkey, this->ui_->easyArgsPicker->setVisible(false); this->ui_->easyArgsLabel->setVisible(false); // dynamically add category names to the category picker - for (const auto &[_, hotkeyCategory] : - getIApp()->getHotkeys()->categories()) + for (const auto &[_, hotkeyCategory] : getApp()->getHotkeys()->categories()) { this->ui_->categoryPicker->addItem(hotkeyCategory.displayName, hotkeyCategory.name); @@ -154,7 +153,7 @@ void EditHotkeyDialog::afterEdit() auto arguments = parseHotkeyArguments(this->ui_->argumentsEdit->toPlainText()); - auto category = getIApp()->getHotkeys()->hotkeyCategoryFromName( + auto category = getApp()->getHotkeys()->hotkeyCategoryFromName( this->ui_->categoryPicker->currentData().toString()); if (!category) { @@ -166,7 +165,7 @@ void EditHotkeyDialog::afterEdit() // check if another hotkey with this name exists, accounts for editing a hotkey bool isEditing = bool(this->data_); - if (getIApp()->getHotkeys()->getHotkeyByName(nameText)) + if (getApp()->getHotkeys()->getHotkeyByName(nameText)) { // A hotkey with this name already exists if (isEditing && this->data()->name() == nameText) @@ -243,8 +242,8 @@ void EditHotkeyDialog::afterEdit() { if (keyComboWasEdited || nameWasEdited) { - if (getIApp()->getHotkeys()->isDuplicate(hotkey, - this->data()->name())) + if (getApp()->getHotkeys()->isDuplicate(hotkey, + this->data()->name())) { this->showEditError( "Keybinding needs to be unique in the category."); @@ -254,7 +253,7 @@ void EditHotkeyDialog::afterEdit() } else { - if (getIApp()->getHotkeys()->isDuplicate(hotkey, QString())) + if (getApp()->getHotkeys()->isDuplicate(hotkey, QString())) { this->showEditError( "Keybinding needs to be unique in the category."); @@ -268,7 +267,7 @@ void EditHotkeyDialog::afterEdit() void EditHotkeyDialog::updatePossibleActions() { - const auto &hotkeys = getIApp()->getHotkeys(); + const auto &hotkeys = getApp()->getHotkeys(); auto category = hotkeys->hotkeyCategoryFromName( this->ui_->categoryPicker->currentData().toString()); if (!category) @@ -320,7 +319,7 @@ void EditHotkeyDialog::updateArgumentsInput() this->ui_->argumentsEdit->setEnabled(true); return; } - const auto &hotkeys = getIApp()->getHotkeys(); + const auto &hotkeys = getApp()->getHotkeys(); auto category = hotkeys->hotkeyCategoryFromName( this->ui_->categoryPicker->currentData().toString()); if (!category) diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index d771008ca..eb789249a 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -129,7 +129,7 @@ void addTwitchEmoteSets( { builder .emplace( - getIApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote( + getApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote( emote.id, emote.name), MessageElementFlags{MessageElementFlag::AlwaysShow, MessageElementFlag::TwitchEmote}) @@ -211,7 +211,7 @@ EmotePopup::EmotePopup(QWidget *parent) , notebook_(new Notebook(this)) { // this->setStayInScreenRect(true); - auto bounds = getIApp()->getWindows()->emotePopupBounds(); + auto bounds = getApp()->getWindows()->emotePopupBounds(); if (bounds.size().isEmpty()) { bounds.setSize(QSize{300, 500} * this->scale()); @@ -282,7 +282,7 @@ EmotePopup::EmotePopup(QWidget *parent) loadEmojis(*this->viewEmojis_, getApp()->getEmotes()->getEmojis()->getEmojis()); this->addShortcuts(); - this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated, + this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, [this]() { this->clearShortcuts(); this->addShortcuts(); @@ -380,7 +380,7 @@ void EmotePopup::addShortcuts() }}, }; - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::PopupWindow, actions, this); } @@ -403,12 +403,9 @@ void EmotePopup::loadChannel(ChannelPtr channel) auto channelChannel = std::make_shared("", Channel::Type::None); // twitch - addTwitchEmoteSets(getIApp() - ->getAccounts() - ->twitch.getCurrent() - ->accessEmotes() - ->emoteSets, - *globalChannel, *subChannel, this->channel_->getName()); + addTwitchEmoteSets( + getApp()->getAccounts()->twitch.getCurrent()->accessEmotes()->emoteSets, + *globalChannel, *subChannel, this->channel_->getName()); // global if (Settings::instance().enableBTTVGlobalEmotes) @@ -478,11 +475,8 @@ bool EmotePopup::eventFilter(QObject *object, QEvent *event) void EmotePopup::filterTwitchEmotes(std::shared_ptr searchChannel, const QString &searchText) { - auto twitchEmoteSets = getIApp() - ->getAccounts() - ->twitch.getCurrent() - ->accessEmotes() - ->emoteSets; + auto twitchEmoteSets = + getApp()->getAccounts()->twitch.getCurrent()->accessEmotes()->emoteSets; std::vector> twitchGlobalEmotes{}; for (const auto &set : twitchEmoteSets) @@ -503,11 +497,11 @@ void EmotePopup::filterTwitchEmotes(std::shared_ptr searchChannel, } auto bttvGlobalEmotes = - filterEmoteMap(searchText, getIApp()->getBttvEmotes()->emotes()); + filterEmoteMap(searchText, getApp()->getBttvEmotes()->emotes()); auto ffzGlobalEmotes = - filterEmoteMap(searchText, getIApp()->getFfzEmotes()->emotes()); + filterEmoteMap(searchText, getApp()->getFfzEmotes()->emotes()); auto seventvGlobalEmotes = filterEmoteMap( - searchText, getIApp()->getSeventvEmotes()->globalEmotes()); + searchText, getApp()->getSeventvEmotes()->globalEmotes()); // twitch addTwitchEmoteSets(twitchGlobalEmotes, *searchChannel, *searchChannel, @@ -580,7 +574,7 @@ void EmotePopup::filterEmotes(const QString &searchText) std::vector filteredEmojis{}; int emojiCount = 0; - const auto &emojis = getIApp()->getEmotes()->getEmojis()->getEmojis(); + const auto &emojis = getApp()->getEmotes()->getEmojis()->getEmojis(); for (const auto &emoji : emojis) { if (emoji->shortCodes[0].contains(searchText, Qt::CaseInsensitive)) @@ -603,7 +597,7 @@ void EmotePopup::filterEmotes(const QString &searchText) void EmotePopup::saveBounds() const { - getIApp()->getWindows()->setEmotePopupBounds(this->getBounds()); + getApp()->getWindows()->setEmotePopupBounds(this->getBounds()); } void EmotePopup::resizeEvent(QResizeEvent *event) diff --git a/src/widgets/dialogs/LoginDialog.cpp b/src/widgets/dialogs/LoginDialog.cpp index 34ff36776..5664acc35 100644 --- a/src/widgets/dialogs/LoginDialog.cpp +++ b/src/widgets/dialogs/LoginDialog.cpp @@ -66,8 +66,8 @@ namespace { pajlada::Settings::Setting::set(basePath + "/oauthToken", oauthToken); - getIApp()->getAccounts()->twitch.reloadUsers(); - getIApp()->getAccounts()->twitch.currentUsername = username; + getApp()->getAccounts()->twitch.reloadUsers(); + getApp()->getAccounts()->twitch.currentUsername = username; return true; } diff --git a/src/widgets/dialogs/QualityPopup.cpp b/src/widgets/dialogs/QualityPopup.cpp index 0ad5ed9c2..e08d25208 100644 --- a/src/widgets/dialogs/QualityPopup.cpp +++ b/src/widgets/dialogs/QualityPopup.cpp @@ -14,7 +14,7 @@ QualityPopup::QualityPopup(const QString &channelURL, QStringList options) BaseWindow::DisableLayoutSave, BaseWindow::BoundsCheckOnShow, }, - static_cast(&(getIApp()->getWindows()->getMainWindow()))) + static_cast(&(getApp()->getWindows()->getMainWindow()))) , channelURL_(channelURL) { this->ui_.selector = new QComboBox(this); diff --git a/src/widgets/dialogs/ReplyThreadPopup.cpp b/src/widgets/dialogs/ReplyThreadPopup.cpp index fb35e9818..ea014d078 100644 --- a/src/widgets/dialogs/ReplyThreadPopup.cpp +++ b/src/widgets/dialogs/ReplyThreadPopup.cpp @@ -77,7 +77,7 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, Split *split) {"search", nullptr}, }; - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::PopupWindow, actions, this); // initialize UI @@ -98,7 +98,7 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, Split *split) new SplitInput(this, this->split_, this->ui_.threadView, false); this->bSignals_.emplace_back( - getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] { + getApp()->getAccounts()->twitch.currentUserChanged.connect([this] { this->updateInputUI(); })); @@ -287,7 +287,7 @@ void ReplyThreadPopup::updateInputUI() this->ui_.replyInput->setVisible(channel->isWritable()); - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); QString placeholderText; if (user->isAnon()) @@ -297,7 +297,7 @@ void ReplyThreadPopup::updateInputUI() else { placeholderText = QStringLiteral("Reply as %1...") - .arg(getIApp() + .arg(getApp() ->getAccounts() ->twitch.getCurrent() ->getUserName()); diff --git a/src/widgets/dialogs/SelectChannelDialog.cpp b/src/widgets/dialogs/SelectChannelDialog.cpp index d482bb121..1eb33c172 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -380,28 +380,28 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const case TAB_TWITCH: { if (this->ui_.twitch.channel->isChecked()) { - return getIApp()->getTwitchAbstract()->getOrAddChannel( + return getApp()->getTwitchAbstract()->getOrAddChannel( this->ui_.twitch.channelName->text().trimmed()); } else if (this->ui_.twitch.watching->isChecked()) { - return getIApp()->getTwitch()->getWatchingChannel(); + return getApp()->getTwitch()->getWatchingChannel(); } else if (this->ui_.twitch.mentions->isChecked()) { - return getIApp()->getTwitch()->getMentionsChannel(); + return getApp()->getTwitch()->getMentionsChannel(); } else if (this->ui_.twitch.whispers->isChecked()) { - return getIApp()->getTwitch()->getWhispersChannel(); + return getApp()->getTwitch()->getWhispersChannel(); } else if (this->ui_.twitch.live->isChecked()) { - return getIApp()->getTwitch()->getLiveChannel(); + return getApp()->getTwitch()->getLiveChannel(); } else if (this->ui_.twitch.automod->isChecked()) { - return getIApp()->getTwitch()->getAutomodChannel(); + return getApp()->getTwitch()->getAutomodChannel(); } } break; @@ -613,7 +613,7 @@ void SelectChannelDialog::addShortcuts() actions.emplace("openTab", nullptr); } - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::PopupWindow, actions, this); } diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index d9ad48fff..fa0d2bd55 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -57,7 +57,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) this->overrideBackgroundColor_ = QColor("#111111"); this->addShortcuts(); - this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated, + this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, [this]() { this->clearShortcuts(); this->addShortcuts(); @@ -81,13 +81,13 @@ void SettingsDialog::addShortcuts() {"openTab", nullptr}, }; - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::PopupWindow, actions, this); } void SettingsDialog::setSearchPlaceholderText() { QString searchHotkey; - auto searchSeq = getIApp()->getHotkeys()->getDisplaySequence( + auto searchSeq = getApp()->getHotkeys()->getDisplaySequence( HotkeyCategory::PopupWindow, "search"); if (!searchSeq.isEmpty()) { @@ -434,7 +434,7 @@ void SettingsDialog::onOkClicked() { if (!getApp()->getArgs().dontSaveSettings) { - getIApp()->getCommands()->save(); + getApp()->getCommands()->save(); pajlada::Settings::SettingManager::gSave(); } this->close(); diff --git a/src/widgets/dialogs/UpdateDialog.cpp b/src/widgets/dialogs/UpdateDialog.cpp index d9c6869f6..64ec27eec 100644 --- a/src/widgets/dialogs/UpdateDialog.cpp +++ b/src/widgets/dialogs/UpdateDialog.cpp @@ -27,7 +27,7 @@ UpdateDialog::UpdateDialog() auto *dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole); QObject::connect(install, &QPushButton::clicked, this, [this] { - getIApp()->getUpdates().installUpdates(); + getApp()->getUpdates().installUpdates(); this->close(); }); QObject::connect(dismiss, &QPushButton::clicked, this, [this] { @@ -35,8 +35,8 @@ UpdateDialog::UpdateDialog() this->close(); }); - this->updateStatusChanged(getIApp()->getUpdates().getStatus()); - this->connections_.managedConnect(getIApp()->getUpdates().statusUpdated, + this->updateStatusChanged(getApp()->getUpdates().getStatus()); + this->connections_.managedConnect(getApp()->getUpdates().statusUpdated, [this](auto status) { this->updateStatusChanged(status); }); @@ -53,17 +53,17 @@ void UpdateDialog::updateStatusChanged(Updates::Status status) { case Updates::UpdateAvailable: { this->ui_.label->setText(( - getIApp()->getUpdates().isDowngrade() + getApp()->getUpdates().isDowngrade() ? QString( "The version online (%1) seems to be\nlower than the " "current (%2).\nEither a version was reverted or " "you are\nrunning a newer build.\n\nDo you want to " "download and install it?") - .arg(getIApp()->getUpdates().getOnlineVersion(), - getIApp()->getUpdates().getCurrentVersion()) + .arg(getApp()->getUpdates().getOnlineVersion(), + getApp()->getUpdates().getCurrentVersion()) : QString("An update (%1) is available.\n\nDo you want to " "download and install it?") - .arg(getIApp()->getUpdates().getOnlineVersion()))); + .arg(getApp()->getUpdates().getOnlineVersion()))); this->updateGeometry(); } break; diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index afd28d4fb..89d43da37 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -56,7 +56,7 @@ namespace { { button.assign(copyButton); } - button->setPixmap(getIApp()->getThemes()->buttons.copy); + button->setPixmap(getApp()->getThemes()->buttons.copy); button->setScaleIndependantSize(18, 18); button->setDim(Button::Dim::Lots); button->setToolTip(tooltip); @@ -223,7 +223,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) .arg(calculateTimeoutDuration(button)); } - msg = getIApp()->getCommands()->execCommand( + msg = getApp()->getCommands()->execCommand( msg, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(msg); @@ -242,7 +242,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) {"search", nullptr}, }; - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::PopupWindow, actions, this); auto layers = LayoutCreator(this->getLayoutContainer()) @@ -295,7 +295,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) menu->addAction( "Open channel in a new popup window", this, [loginName] { - auto *app = getIApp(); + auto *app = getApp(); auto &window = app->getWindows()->createWindow( WindowType::Popup, true); auto *split = window.getNotebook() @@ -309,7 +309,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) menu->addAction( "Open channel in a new tab", this, [loginName] { ChannelPtr channel = - getIApp() + getApp() ->getTwitchAbstract() ->getOrAddChannel(loginName); auto &nb = getApp() @@ -414,25 +414,25 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) QObject::connect(mod.getElement(), &Button::leftClicked, [this] { QString value = "/mod " + this->userName_; - value = getIApp()->getCommands()->execCommand( + value = getApp()->getCommands()->execCommand( value, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(value); }); QObject::connect(unmod.getElement(), &Button::leftClicked, [this] { QString value = "/unmod " + this->userName_; - value = getIApp()->getCommands()->execCommand( + value = getApp()->getCommands()->execCommand( value, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(value); }); QObject::connect(vip.getElement(), &Button::leftClicked, [this] { QString value = "/vip " + this->userName_; - value = getIApp()->getCommands()->execCommand( + value = getApp()->getCommands()->execCommand( value, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(value); }); QObject::connect(unvip.getElement(), &Button::leftClicked, [this] { QString value = "/unvip " + this->userName_; - value = getIApp()->getCommands()->execCommand( + value = getApp()->getCommands()->execCommand( value, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(value); }); @@ -450,7 +450,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) if (twitchChannel) { bool isMyself = - QString::compare(getIApp() + QString::compare(getApp() ->getAccounts() ->twitch.getCurrent() ->getUserName(), @@ -499,7 +499,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) if (this->underlyingChannel_) { QString value = "/ban " + this->userName_; - value = getIApp()->getCommands()->execCommand( + value = getApp()->getCommands()->execCommand( value, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(value); @@ -510,7 +510,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) if (this->underlyingChannel_) { QString value = "/unban " + this->userName_; - value = getIApp()->getCommands()->execCommand( + value = getApp()->getCommands()->execCommand( value, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(value); @@ -523,7 +523,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) QString value = "/timeout " + this->userName_ + " " + QString::number(arg); - value = getIApp()->getCommands()->execCommand( + value = getApp()->getCommands()->execCommand( value, this->underlyingChannel_, false); this->underlyingChannel_->sendMessage(value); @@ -572,7 +572,7 @@ void UserInfoPopup::themeChangedEvent() for (auto &&child : this->findChildren()) { child->setFont( - getIApp()->getFonts()->getFont(FontStyle::UiMedium, this->scale())); + getApp()->getFonts()->getFont(FontStyle::UiMedium, this->scale())); } } @@ -597,7 +597,7 @@ void UserInfoPopup::installEvents() QObject::connect( this->ui_.block, &QCheckBox::stateChanged, [this](int newState) mutable { - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); const auto reenableBlockCheckbox = [this] { this->ui_.block->setEnabled(true); @@ -614,7 +614,7 @@ void UserInfoPopup::installEvents() case Qt::CheckState::Unchecked: { this->ui_.block->setEnabled(false); - getIApp()->getAccounts()->twitch.getCurrent()->unblockUser( + getApp()->getAccounts()->twitch.getCurrent()->unblockUser( this->userId_, this, [this, reenableBlockCheckbox, currentUser] { this->channel_->addSystemMessage( @@ -641,7 +641,7 @@ void UserInfoPopup::installEvents() case Qt::CheckState::Checked: { this->ui_.block->setEnabled(false); - getIApp()->getAccounts()->twitch.getCurrent()->blockUser( + getApp()->getAccounts()->twitch.getCurrent()->blockUser( this->userId_, this, [this, reenableBlockCheckbox, currentUser] { this->channel_->addSystemMessage( @@ -798,7 +798,7 @@ void UserInfoPopup::updateLatestMessages() void UserInfoPopup::updateUserData() { std::weak_ptr hack = this->lifetimeHack_; - auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + auto currentUser = getApp()->getAccounts()->twitch.getCurrent(); const auto onUserFetchFailed = [this, hack] { if (!hack.lock()) @@ -858,7 +858,7 @@ void UserInfoPopup::updateUserData() this->ui_.userIDLabel->setText(TEXT_USER_ID + user.id); this->ui_.userIDLabel->setProperty("copy-text", user.id); - if (getIApp()->getStreamerMode()->isEnabled() && + if (getApp()->getStreamerMode()->isEnabled() && getSettings()->streamerModeHideUsercardAvatars) { this->ui_.avatarButton->setPixmap(getResources().streamerMode); diff --git a/src/widgets/dialogs/switcher/NewPopupItem.cpp b/src/widgets/dialogs/switcher/NewPopupItem.cpp index d4bc01bbd..2f79693a0 100644 --- a/src/widgets/dialogs/switcher/NewPopupItem.cpp +++ b/src/widgets/dialogs/switcher/NewPopupItem.cpp @@ -22,8 +22,8 @@ NewPopupItem::NewPopupItem(const QString &channelName) void NewPopupItem::action() { auto channel = - getIApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_); - getIApp()->getWindows()->openInPopup(channel); + getApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_); + getApp()->getWindows()->openInPopup(channel); } void NewPopupItem::paint(QPainter *painter, const QRect &rect) const @@ -32,10 +32,10 @@ void NewPopupItem::paint(QPainter *painter, const QRect &rect) const painter->setRenderHint(QPainter::Antialiasing, true); - painter->setPen(getIApp()->getThemes()->splits.header.text); + painter->setPen(getApp()->getThemes()->splits.header.text); painter->setBrush(Qt::SolidPattern); painter->setFont( - getIApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0)); + getApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0)); QRect iconRect(rect.topLeft(), ICON_SIZE); this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter); diff --git a/src/widgets/dialogs/switcher/NewTabItem.cpp b/src/widgets/dialogs/switcher/NewTabItem.cpp index 967c14aca..0ce337e15 100644 --- a/src/widgets/dialogs/switcher/NewTabItem.cpp +++ b/src/widgets/dialogs/switcher/NewTabItem.cpp @@ -27,7 +27,7 @@ void NewTabItem::action() Split *split = new Split(container); split->setChannel( - getIApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_)); + getApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_)); container->insertSplit(split); } @@ -38,10 +38,10 @@ void NewTabItem::paint(QPainter *painter, const QRect &rect) const painter->setRenderHint(QPainter::Antialiasing, true); // TODO(leon): Right pen/brush/font settings? - painter->setPen(getIApp()->getThemes()->splits.header.text); + painter->setPen(getApp()->getThemes()->splits.header.text); painter->setBrush(Qt::SolidPattern); painter->setFont( - getIApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0)); + getApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0)); QRect iconRect(rect.topLeft(), ICON_SIZE); this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter); diff --git a/src/widgets/dialogs/switcher/SwitchSplitItem.cpp b/src/widgets/dialogs/switcher/SwitchSplitItem.cpp index 63c860cc6..f3cb31c5c 100644 --- a/src/widgets/dialogs/switcher/SwitchSplitItem.cpp +++ b/src/widgets/dialogs/switcher/SwitchSplitItem.cpp @@ -21,11 +21,11 @@ void SwitchSplitItem::action() { if (this->split_) { - getIApp()->getWindows()->select(this->split_); + getApp()->getWindows()->select(this->split_); } else if (this->container_) { - getIApp()->getWindows()->select(this->container_); + getApp()->getWindows()->select(this->container_); } } @@ -36,10 +36,10 @@ void SwitchSplitItem::paint(QPainter *painter, const QRect &rect) const painter->setRenderHint(QPainter::Antialiasing, true); // TODO(leon): Right pen/brush/font settings? - painter->setPen(getIApp()->getThemes()->splits.header.text); + painter->setPen(getApp()->getThemes()->splits.header.text); painter->setBrush(Qt::SolidPattern); painter->setFont( - getIApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0)); + getApp()->getFonts()->getFont(FontStyle::UiMediumBold, 1.0)); QRect iconRect(rect.topLeft(), ICON_SIZE); this->icon_.paint(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter); @@ -60,7 +60,7 @@ void SwitchSplitItem::paint(QPainter *painter, const QRect &rect) const QSize(0.7 * availableTextWidth, iconRect.height())); painter->setFont( - getIApp()->getFonts()->getFont(FontStyle::UiMedium, 1.0)); + getApp()->getFonts()->getFont(FontStyle::UiMedium, 1.0)); painter->drawText(rightTextRect, Qt::AlignRight | Qt::AlignVCenter, this->container_->getTab()->getTitle()); } diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 26e31c9bf..7430614a9 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -427,11 +427,11 @@ void ChannelView::initializeScrollbar() void ChannelView::initializeSignals() { - this->signalHolder_.managedConnect( - getIApp()->getWindows()->wordFlagsChanged, [this] { - this->queueLayout(); - this->update(); - }); + this->signalHolder_.managedConnect(getApp()->getWindows()->wordFlagsChanged, + [this] { + this->queueLayout(); + this->update(); + }); getSettings()->showLastMessageIndicator.connect( [this](auto, auto) { @@ -440,7 +440,7 @@ void ChannelView::initializeSignals() this->signalHolder_); this->signalHolder_.managedConnect( - getIApp()->getWindows()->gifRepaintRequested, [&] { + getApp()->getWindows()->gifRepaintRequested, [&] { if (!this->animationArea_.isEmpty()) { this->queueUpdate(this->animationArea_); @@ -448,7 +448,7 @@ void ChannelView::initializeSignals() }); this->signalHolder_.managedConnect( - getIApp()->getWindows()->layoutRequested, [&](Channel *channel) { + getApp()->getWindows()->layoutRequested, [&](Channel *channel) { if (this->isVisible() && (channel == nullptr || this->underlyingChannel_.get() == channel)) @@ -458,7 +458,7 @@ void ChannelView::initializeSignals() }); this->signalHolder_.managedConnect( - getIApp()->getWindows()->invalidateBuffersRequested, + getApp()->getWindows()->invalidateBuffersRequested, [this](Channel *channel) { if (this->isVisible() && (channel == nullptr || @@ -468,7 +468,7 @@ void ChannelView::initializeSignals() } }); - this->signalHolder_.managedConnect(getIApp()->getFonts()->fontChanged, + this->signalHolder_.managedConnect(getApp()->getFonts()->fontChanged, [this] { this->queueLayout(); }); @@ -622,7 +622,7 @@ void ChannelView::scaleChangedEvent(float scale) 0.01, this->logicalDpiX() * this->devicePixelRatioF()); #endif this->goToBottom_->getLabel().setFont( - getIApp()->getFonts()->getFont(FontStyle::UiMedium, factor)); + getApp()->getFonts()->getFont(FontStyle::UiMedium, factor)); } } @@ -1087,11 +1087,8 @@ bool ChannelView::shouldIncludeMessage(const MessagePtr &m) const if (this->channelFilters_) { if (getSettings()->excludeUserMessagesFromFilter && - getIApp() - ->getAccounts() - ->twitch.getCurrent() - ->getUserName() - .compare(m->loginName, Qt::CaseInsensitive) == 0) + getApp()->getAccounts()->twitch.getCurrent()->getUserName().compare( + m->loginName, Qt::CaseInsensitive) == 0) { return true; } @@ -1377,19 +1374,19 @@ MessageElementFlags ChannelView::getFlags() const flags.set(MessageElementFlag::ModeratorTools); } if (this->underlyingChannel_ == - getIApp()->getTwitch()->getMentionsChannel() || + getApp()->getTwitch()->getMentionsChannel() || this->underlyingChannel_ == - getIApp()->getTwitch()->getLiveChannel() || + getApp()->getTwitch()->getLiveChannel() || this->underlyingChannel_ == - getIApp()->getTwitch()->getAutomodChannel()) + getApp()->getTwitch()->getAutomodChannel()) { flags.set(MessageElementFlag::ChannelName); flags.unset(MessageElementFlag::ChannelPointReward); } } - if (this->sourceChannel_ == getIApp()->getTwitch()->getMentionsChannel() || - this->sourceChannel_ == getIApp()->getTwitch()->getAutomodChannel()) + if (this->sourceChannel_ == getApp()->getTwitch()->getMentionsChannel() || + this->sourceChannel_ == getApp()->getTwitch()->getAutomodChannel()) { flags.set(MessageElementFlag::ChannelName); } @@ -1446,7 +1443,7 @@ bool ChannelView::scrollToMessage(const MessagePtr &message) this->scrollToMessageLayout(messagesSnapshot[messageIdx].get(), messageIdx); if (this->split_) { - getIApp()->getWindows()->select(this->split_); + getApp()->getWindows()->select(this->split_); } return true; } @@ -1478,7 +1475,7 @@ bool ChannelView::scrollToMessageId(const QString &messageId) this->scrollToMessageLayout(messagesSnapshot[messageIdx].get(), messageIdx); if (this->split_) { - getIApp()->getWindows()->select(this->split_); + getApp()->getWindows()->select(this->split_); } return true; } @@ -1543,7 +1540,7 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area) .canvasWidth = this->width(), .isWindowFocused = this->window() == QApplication::activeWindow(), .isMentions = this->underlyingChannel_ == - getIApp()->getTwitch()->getMentionsChannel(), + getApp()->getTwitch()->getMentionsChannel(), .y = int(-(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar_->getRelativeCurrentValue(), 1)))), @@ -1968,7 +1965,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) { if (linkElement->linkInfo()->isPending()) { - getIApp()->getLinkResolver()->resolve( + getApp()->getLinkResolver()->resolve( linkElement->linkInfo()); } this->setLinkInfoTooltip(linkElement->linkInfo()); @@ -2479,7 +2476,7 @@ void ChannelView::addMessageContextMenuItems(QMenu *menu, } else if (isMentions || isAutomod) { - getIApp()->getWindows()->scrollToMessage(messagePtr); + getApp()->getWindows()->scrollToMessage(messagePtr); } else if (isReplyOrUserCard) { @@ -2489,7 +2486,7 @@ void ChannelView::addMessageContextMenuItems(QMenu *menu, if (type == Channel::Type::TwitchMentions || type == Channel::Type::TwitchAutomod) { - getIApp()->getWindows()->scrollToMessage(messagePtr); + getApp()->getWindows()->scrollToMessage(messagePtr); } else { @@ -2570,7 +2567,7 @@ void ChannelView::addCommandExecutionContextMenuItems( /* Get commands to be displayed in context menu; * only those that had the showInMsgContextMenu check box marked in the Commands page */ std::vector cmds; - for (const auto &cmd : getIApp()->getCommands()->items) + for (const auto &cmd : getApp()->getCommands()->items) { if (cmd.showInMsgContextMenu) { @@ -2617,14 +2614,13 @@ void ChannelView::addCommandExecutionContextMenuItems( } // Execute command through right-clicking a message -> Execute command - QString value = getIApp()->getCommands()->execCustomCommand( + QString value = getApp()->getCommands()->execCustomCommand( inputText.split(' '), cmd, true, channel, layout->getMessage(), { {"input.text", userText}, }); - value = - getIApp()->getCommands()->execCommand(value, channel, false); + value = getApp()->getCommands()->execCommand(value, channel, false); channel->sendMessage(value); }); @@ -2703,7 +2699,7 @@ void ChannelView::showUserInfoPopup(const QString &userName, auto *userPopup = new UserInfoPopup(getSettings()->autoCloseUserPopup, this->split_); - auto contextChannel = getIApp()->getTwitchAbstract()->getChannelOrEmpty( + auto contextChannel = getApp()->getTwitchAbstract()->getChannelOrEmpty( alternativePopoutChannel); auto openingChannel = this->hasSourceChannel() ? this->sourceChannel_ : this->underlyingChannel_; @@ -2790,25 +2786,24 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, } // Execute command clicking a moderator button - value = getIApp()->getCommands()->execCustomCommand( + value = getApp()->getCommands()->execCustomCommand( QStringList(), Command{"(modaction)", value}, true, channel, layout->getMessage()); - value = - getIApp()->getCommands()->execCommand(value, channel, false); + value = getApp()->getCommands()->execCommand(value, channel, false); channel->sendMessage(value); } break; case Link::AutoModAllow: { - getIApp()->getAccounts()->twitch.getCurrent()->autoModAllow( + getApp()->getAccounts()->twitch.getCurrent()->autoModAllow( link.value, this->channel()); } break; case Link::AutoModDeny: { - getIApp()->getAccounts()->twitch.getCurrent()->autoModDeny( + getApp()->getAccounts()->twitch.getCurrent()->autoModDeny( link.value, this->channel()); } break; @@ -2822,7 +2817,7 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, // Get all currently open pages QList openPages; - auto &nb = getIApp()->getWindows()->getMainWindow().getNotebook(); + auto &nb = getApp()->getWindows()->getMainWindow().getNotebook(); for (int i = 0; i < nb.getPageCount(); ++i) { openPages.push_back( @@ -3095,7 +3090,7 @@ void ChannelView::setLinkInfoTooltip(LinkInfo *info) ImagePtr thumbnail; if (info->hasThumbnail() && thumbnailSize > 0) { - if (getIApp()->getStreamerMode()->isEnabled() && + if (getApp()->getStreamerMode()->isEnabled() && getSettings()->streamerModeHideLinkThumbnails) { thumbnail = Image::fromResourcePixmap(getResources().streamerMode); diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index a5d8cfb69..ea893f6ea 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -86,8 +86,8 @@ NotebookTab::NotebookTab(Notebook *notebook) [this]() { this->notebook_->removePage(this->page); }, - getIApp()->getHotkeys()->getDisplaySequence(HotkeyCategory::Window, - "removeTab")); + getApp()->getHotkeys()->getDisplaySequence(HotkeyCategory::Window, + "removeTab")); this->menu_.addAction( "Popup Tab", @@ -97,8 +97,8 @@ NotebookTab::NotebookTab(Notebook *notebook) container->popup(); } }, - getIApp()->getHotkeys()->getDisplaySequence(HotkeyCategory::Window, - "popup", {{"window"}})); + getApp()->getHotkeys()->getDisplaySequence(HotkeyCategory::Window, + "popup", {{"window"}})); this->menu_.addAction("Duplicate Tab", [this]() { this->notebook_->duplicatePage(this->page); @@ -199,7 +199,7 @@ int NotebookTab::normalTabWidthForHeight(int height) const int width = 0; QFontMetrics metrics = - getIApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale); + getApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale); if (this->hasXButton()) { @@ -291,7 +291,7 @@ const QString &NotebookTab::getTitle() const void NotebookTab::titleUpdated() { // Queue up save because: Tab title changed - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); this->notebook_->refresh(); this->updateSize(); this->update(); diff --git a/src/widgets/helper/SearchPopup.cpp b/src/widgets/helper/SearchPopup.cpp index fb8dfee8b..52138028a 100644 --- a/src/widgets/helper/SearchPopup.cpp +++ b/src/widgets/helper/SearchPopup.cpp @@ -103,7 +103,7 @@ void SearchPopup::addShortcuts() {"scrollPage", nullptr}, }; - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::PopupWindow, actions, this); } @@ -138,7 +138,7 @@ void SearchPopup::goToMessage(const MessagePtr &message) if (type == Channel::Type::TwitchMentions || type == Channel::Type::TwitchAutomod) { - getIApp()->getWindows()->scrollToMessage(message); + getApp()->getWindows()->scrollToMessage(message); return; } diff --git a/src/widgets/settingspages/AccountsPage.cpp b/src/widgets/settingspages/AccountsPage.cpp index c41b149b2..9828ce3e6 100644 --- a/src/widgets/settingspages/AccountsPage.cpp +++ b/src/widgets/settingspages/AccountsPage.cpp @@ -63,7 +63,7 @@ AccountsPage::AccountsPage() // return; // } - // getIApp()->getAccounts()->Twitch.removeUser(selectedUser); + // getApp()->getAccounts()->Twitch.removeUser(selectedUser); // }); } diff --git a/src/widgets/settingspages/CommandPage.cpp b/src/widgets/settingspages/CommandPage.cpp index de94d11d2..5aa0dc3d4 100644 --- a/src/widgets/settingspages/CommandPage.cpp +++ b/src/widgets/settingspages/CommandPage.cpp @@ -87,7 +87,7 @@ CommandPage::CommandPage() auto *view = layout .emplace( - getIApp()->getCommands()->createModel(nullptr)) + getApp()->getCommands()->createModel(nullptr)) .getElement(); view->setTitles({"Trigger", "Command", "Show In\nMessage Menu"}); @@ -95,7 +95,7 @@ CommandPage::CommandPage() 1, QHeaderView::Stretch); // We can safely ignore this signal connection since we own the view std::ignore = view->addButtonPressed.connect([] { - getIApp()->getCommands()->items.append( + getApp()->getCommands()->items.append( Command{"/command", "I made a new command HeyGuys"}); }); @@ -114,7 +114,7 @@ CommandPage::CommandPage() { if (int index = line.indexOf(' '); index != -1) { - getIApp()->getCommands()->items.insert( + getApp()->getCommands()->items.insert( Command(line.mid(0, index), line.mid(index + 1))); } } diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 9d27b5d08..13dcb445a 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -122,7 +122,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) layout.addTitle("Interface"); { - auto *themes = getIApp()->getThemes(); + auto *themes = getApp()->getThemes(); auto available = themes->availableThemes(); #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) available.emplace_back("System", "System"); @@ -273,7 +273,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) layout.addCheckbox("Show message reply button", s.showReplyButton, false, "Show a reply button next to every chat message"); - auto removeTabSeq = getIApp()->getHotkeys()->getDisplaySequence( + auto removeTabSeq = getApp()->getHotkeys()->getDisplaySequence( HotkeyCategory::Window, "removeTab"); QString removeTabShortcut = "an assigned hotkey (Window -> remove tab)"; if (!removeTabSeq.isEmpty()) @@ -294,7 +294,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) #endif if (!BaseWindow::supportsCustomWindowFrame()) { - auto settingsSeq = getIApp()->getHotkeys()->getDisplaySequence( + auto settingsSeq = getApp()->getHotkeys()->getDisplaySequence( HotkeyCategory::Window, "openSettings"); QString shortcut = " (no key bound to open them otherwise)"; // TODO: maybe prevent the user from locking themselves out of the settings? @@ -570,7 +570,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) // as an official description from 7TV devs is best s.showUnlistedSevenTVEmotes.connect( []() { - getIApp()->getTwitch()->forEachChannelAndSpecialChannels( + getApp()->getTwitch()->forEachChannelAndSpecialChannels( [](const auto &c) { if (c->isTwitchChannel()) { @@ -824,9 +824,9 @@ void GeneralPage::initLayout(GeneralPageView &layout) layout.addButton("Open AppData directory", [] { #ifdef Q_OS_DARWIN QDesktopServices::openUrl("file://" + - getIApp()->getPaths().rootAppDataDirectory); + getApp()->getPaths().rootAppDataDirectory); #else - QDesktopServices::openUrl(getIApp()->getPaths().rootAppDataDirectory); + QDesktopServices::openUrl(getApp()->getPaths().rootAppDataDirectory); #endif }); @@ -838,7 +838,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) auto *cachePathLabel = layout.addDescription("placeholder :D"); getSettings()->cachePath.connect([cachePathLabel](const auto &, auto) mutable { - QString newPath = getIApp()->getPaths().cacheDirectory(); + QString newPath = getApp()->getPaths().cacheDirectory(); QString pathShortened = "Cache saved at " + @@ -866,9 +866,9 @@ void GeneralPage::initLayout(GeneralPageView &layout) if (reply == QMessageBox::Yes) { - auto cacheDir = QDir(getIApp()->getPaths().cacheDirectory()); + auto cacheDir = QDir(getApp()->getPaths().cacheDirectory()); cacheDir.removeRecursively(); - cacheDir.mkdir(getIApp()->getPaths().cacheDirectory()); + cacheDir.mkdir(getApp()->getPaths().cacheDirectory()); } })); box->addStretch(1); @@ -890,7 +890,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) "Show the stream title"); layout.addSubtitle("R9K"); - auto toggleLocalr9kSeq = getIApp()->getHotkeys()->getDisplaySequence( + auto toggleLocalr9kSeq = getApp()->getHotkeys()->getDisplaySequence( HotkeyCategory::Window, "toggleLocalR9K"); QString toggleLocalr9kShortcut = "an assigned hotkey (Window -> Toggle local R9K)"; @@ -913,7 +913,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) s.shownSimilarTriggerHighlights); s.hideSimilar.connect( []() { - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); }, false); layout.addDropdown( @@ -981,15 +981,15 @@ void GeneralPage::initLayout(GeneralPageView &layout) layout.addCustomCheckbox( "Restart on crash (requires restart)", [] { - return getIApp()->getCrashHandler()->shouldRecover(); + return getApp()->getCrashHandler()->shouldRecover(); }, [](bool on) { - return getIApp()->getCrashHandler()->saveShouldRecover(on); + return getApp()->getCrashHandler()->saveShouldRecover(on); }, "When possible, restart Chatterino if the program crashes"); #if defined(Q_OS_LINUX) && !defined(NO_QTKEYCHAIN) - if (!getIApp()->getPaths().isPortable()) + if (!getApp()->getPaths().isPortable()) { layout.addCheckbox( "Use libsecret/KWallet/Gnome keychain to secure passwords", @@ -1196,7 +1196,7 @@ void GeneralPage::initExtra() { getSettings()->cachePath.connect( [cachePath = this->cachePath_](const auto &, auto) mutable { - QString newPath = getIApp()->getPaths().cacheDirectory(); + QString newPath = getApp()->getPaths().cacheDirectory(); QString pathShortened = "Current location: " + @@ -1216,7 +1216,7 @@ QString GeneralPage::getFont(const DropdownArgs &args) const auto ok = bool(); auto previousFont = - getIApp()->getFonts()->getFont(FontStyle::ChatMedium, 1.); + getApp()->getFonts()->getFont(FontStyle::ChatMedium, 1.); auto font = QFontDialog::getFont(&ok, previousFont, this->window()); if (ok) diff --git a/src/widgets/settingspages/GeneralPageView.cpp b/src/widgets/settingspages/GeneralPageView.cpp index 94ec3d23c..293992581 100644 --- a/src/widgets/settingspages/GeneralPageView.cpp +++ b/src/widgets/settingspages/GeneralPageView.cpp @@ -197,7 +197,7 @@ ComboBox *GeneralPageView::addDropdown( QObject::connect(combo, &QComboBox::currentTextChanged, [&setting](const QString &newValue) { setting = newValue; - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); }); return combo; diff --git a/src/widgets/settingspages/GeneralPageView.hpp b/src/widgets/settingspages/GeneralPageView.hpp index 7e1625a70..4ce1c5b4e 100644 --- a/src/widgets/settingspages/GeneralPageView.hpp +++ b/src/widgets/settingspages/GeneralPageView.hpp @@ -204,7 +204,7 @@ public: .index = combo->currentIndex(), .combobox = combo, }); - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); }; if (listenToActivated) @@ -268,7 +268,7 @@ public: setValue = std::move(setValue)](const int newIndex) { setting = setValue(DropdownArgs{combo->itemText(newIndex), combo->currentIndex(), combo}); - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); }); return combo; @@ -312,7 +312,7 @@ public: // Instead, it's up to the getters to make sure that the setting is legic - see the enum_cast above // You could also use the settings `getEnum` function setting = newText; - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); }); return combo; diff --git a/src/widgets/settingspages/KeyboardSettingsPage.cpp b/src/widgets/settingspages/KeyboardSettingsPage.cpp index 04bc80abb..9f9ae24e5 100644 --- a/src/widgets/settingspages/KeyboardSettingsPage.cpp +++ b/src/widgets/settingspages/KeyboardSettingsPage.cpp @@ -22,7 +22,7 @@ using namespace chatterino; void tableCellClicked(const QModelIndex &clicked, EditableModelView *view, HotkeyModel *model) { - auto hotkey = getIApp()->getHotkeys()->getHotkeyByName( + auto hotkey = getApp()->getHotkeys()->getHotkeyByName( clicked.siblingAtColumn(0).data(Qt::EditRole).toString()); if (!hotkey) { @@ -34,8 +34,8 @@ void tableCellClicked(const QModelIndex &clicked, EditableModelView *view, if (wasAccepted) { auto newHotkey = dialog.data(); - getIApp()->getHotkeys()->replaceHotkey(hotkey->name(), newHotkey); - getIApp()->getHotkeys()->save(); + getApp()->getHotkeys()->replaceHotkey(hotkey->name(), newHotkey); + getApp()->getHotkeys()->save(); } } @@ -48,7 +48,7 @@ KeyboardSettingsPage::KeyboardSettingsPage() LayoutCreator layoutCreator(this); auto layout = layoutCreator.emplace(); - auto *model = getIApp()->getHotkeys()->createModel(nullptr); + auto *model = getApp()->getHotkeys()->createModel(nullptr); EditableModelView *view = layout.emplace(model).getElement(); @@ -68,8 +68,8 @@ KeyboardSettingsPage::KeyboardSettingsPage() if (wasAccepted) { auto newHotkey = dialog.data(); - getIApp()->getHotkeys()->hotkeys_.append(newHotkey); - getIApp()->getHotkeys()->save(); + getApp()->getHotkeys()->hotkeys_.append(newHotkey); + getApp()->getHotkeys()->save(); } }); @@ -87,7 +87,7 @@ KeyboardSettingsPage::KeyboardSettingsPage() if (reply == QMessageBox::Yes) { - getIApp()->getHotkeys()->resetToDefaults(); + getApp()->getHotkeys()->resetToDefaults(); } }); view->addCustomButton(resetEverything); diff --git a/src/widgets/settingspages/ModerationPage.cpp b/src/widgets/settingspages/ModerationPage.cpp index c00c03667..cb68e825c 100644 --- a/src/widgets/settingspages/ModerationPage.cpp +++ b/src/widgets/settingspages/ModerationPage.cpp @@ -58,7 +58,7 @@ QString formatSize(qint64 size) QString fetchLogDirectorySize() { QString logsDirectoryPath = getSettings()->logPath.getValue().isEmpty() - ? getIApp()->getPaths().messageLogDirectory + ? getApp()->getPaths().messageLogDirectory : getSettings()->logPath; auto logsSize = dirSize(logsDirectoryPath); @@ -83,20 +83,20 @@ ModerationPage::ModerationPage() auto logsPathLabel = logs.emplace(); // Logs (copied from LoggingMananger) - getSettings()->logPath.connect([logsPathLabel](const QString &logPath, - auto) mutable { - QString pathOriginal = - logPath.isEmpty() ? getIApp()->getPaths().messageLogDirectory - : logPath; + getSettings()->logPath.connect( + [logsPathLabel](const QString &logPath, auto) mutable { + QString pathOriginal = + logPath.isEmpty() ? getApp()->getPaths().messageLogDirectory + : logPath; - QString pathShortened = - "Logs are saved at " + - shortenString(pathOriginal, 50) + ""; + QString pathShortened = + "Logs are saved at " + + shortenString(pathOriginal, 50) + ""; - logsPathLabel->setText(pathShortened); - logsPathLabel->setToolTip(pathOriginal); - }); + logsPathLabel->setText(pathShortened); + logsPathLabel->setToolTip(pathOriginal); + }); logsPathLabel->setTextFormat(Qt::RichText); logsPathLabel->setTextInteractionFlags(Qt::TextBrowserInteraction | diff --git a/src/widgets/settingspages/NotificationPage.cpp b/src/widgets/settingspages/NotificationPage.cpp index c306e7176..5d354633b 100644 --- a/src/widgets/settingspages/NotificationPage.cpp +++ b/src/widgets/settingspages/NotificationPage.cpp @@ -97,7 +97,7 @@ NotificationPage::NotificationPage() EditableModelView *view = twitchChannels .emplace( - getIApp()->getNotifications()->createModel( + getApp()->getNotifications()->createModel( nullptr, Platform::Twitch)) .getElement(); view->setTitles({"Twitch channels"}); diff --git a/src/widgets/settingspages/PluginsPage.cpp b/src/widgets/settingspages/PluginsPage.cpp index 05c80a37c..5d87e3ff9 100644 --- a/src/widgets/settingspages/PluginsPage.cpp +++ b/src/widgets/settingspages/PluginsPage.cpp @@ -55,7 +55,7 @@ PluginsPage::PluginsPage() auto *description = new QLabel("You can load plugins by putting them into " + formatRichNamedLink( - "file:///" + getIApp()->getPaths().pluginsDirectory, + "file:///" + getApp()->getPaths().pluginsDirectory, "the Plugins directory") + ". Each one is a new directory."); description->setOpenExternalLinks(true); @@ -95,7 +95,7 @@ void PluginsPage::rebuildContent() this->scrollAreaWidget_.append(this->dataFrame_); auto layout = frame.setLayoutType(); layout->setParent(this->dataFrame_); - for (const auto &[id, plugin] : getIApp()->getPlugins()->plugins()) + for (const auto &[id, plugin] : getApp()->getPlugins()->plugins()) { auto groupHeaderText = QString("%1 (%2, from %3)") @@ -214,7 +214,7 @@ void PluginsPage::rebuildContent() val.push_back(name); } getSettings()->enabledPlugins.setValue(val); - getIApp()->getPlugins()->reload(name); + getApp()->getPlugins()->reload(name); this->rebuildContent(); }); pluginEntry->addRow(toggleButton); @@ -223,7 +223,7 @@ void PluginsPage::rebuildContent() auto *reloadButton = new QPushButton("Reload", this->dataFrame_); QObject::connect(reloadButton, &QPushButton::pressed, [name = id, this]() { - getIApp()->getPlugins()->reload(name); + getApp()->getPlugins()->reload(name); this->rebuildContent(); }); pluginEntry->addRow(reloadButton); diff --git a/src/widgets/settingspages/SettingsPage.cpp b/src/widgets/settingspages/SettingsPage.cpp index 4acf26791..6f2150f1c 100644 --- a/src/widgets/settingspages/SettingsPage.cpp +++ b/src/widgets/settingspages/SettingsPage.cpp @@ -103,7 +103,7 @@ QCheckBox *SettingsPage::createCheckBox( QObject::connect(checkbox, &QCheckBox::toggled, this, [&setting](bool state) { setting = state; - getIApp()->getWindows()->forceLayoutChannelViews(); + getApp()->getWindows()->forceLayoutChannelViews(); }); return checkbox; diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 9d4ff5ed4..f3cfe6422 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -242,7 +242,7 @@ Split::Split(QWidget *parent) // update placeholder text on Twitch account change and channel change this->bSignals_.emplace_back( - getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] { + getApp()->getAccounts()->twitch.currentUserChanged.connect([this] { this->updateInputPlaceholder(); })); this->signalHolder_.managedConnect(channelChanged, [this] { @@ -272,7 +272,7 @@ Split::Split(QWidget *parent) std::ignore = this->view_->openChannelIn.connect( [this](QString twitchChannel, FromTwitchLinkOpenChannelIn openIn) { ChannelPtr channel = - getIApp()->getTwitchAbstract()->getOrAddChannel(twitchChannel); + getApp()->getTwitchAbstract()->getOrAddChannel(twitchChannel); switch (openIn) { case FromTwitchLinkOpenChannelIn::Split: @@ -387,7 +387,7 @@ Split::Split(QWidget *parent) } auto channel = this->getChannel(); - auto *imageUploader = getIApp()->getImageUploader(); + auto *imageUploader = getApp()->getImageUploader(); auto [images, imageProcessError] = imageUploader->getImages(original); @@ -452,7 +452,7 @@ Split::Split(QWidget *parent) }, this->signalHolder_); this->addShortcuts(); - this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated, + this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, [this]() { this->clearShortcuts(); this->addShortcuts(); @@ -708,14 +708,14 @@ void Split::addShortcuts() QString requestedText = arguments.at(0).replace('\n', ' '); QString inputText = this->getInput().getInputText(); - QString message = getIApp()->getCommands()->execCustomCommand( + QString message = getApp()->getCommands()->execCustomCommand( requestedText.split(' '), Command{"(hotkey)", requestedText}, true, this->getChannel(), nullptr, { {"input.text", inputText}, }); - message = getIApp()->getCommands()->execCommand( + message = getApp()->getCommands()->execCommand( message, this->getChannel(), false); this->getChannel()->sendMessage(message); return ""; @@ -750,24 +750,24 @@ void Split::addShortcuts() if (mode == 0) { - getIApp()->getNotifications()->removeChannelNotification( + getApp()->getNotifications()->removeChannelNotification( this->getChannel()->getName(), Platform::Twitch); } else if (mode == 1) { - getIApp()->getNotifications()->addChannelNotification( + getApp()->getNotifications()->addChannelNotification( this->getChannel()->getName(), Platform::Twitch); } else { - getIApp()->getNotifications()->updateChannelNotification( + getApp()->getNotifications()->updateChannelNotification( this->getChannel()->getName(), Platform::Twitch); } return ""; }}, }; - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::Split, actions, this); } @@ -796,7 +796,7 @@ void Split::updateInputPlaceholder() return; } - auto user = getIApp()->getAccounts()->twitch.getCurrent(); + auto user = getApp()->getAccounts()->twitch.getCurrent(); QString placeholderText; if (user->isAnon()) @@ -806,7 +806,7 @@ void Split::updateInputPlaceholder() else { placeholderText = QString("Send message as %1...") - .arg(getIApp() + .arg(getApp() ->getAccounts() ->twitch.getCurrent() ->getUserName()); @@ -817,7 +817,7 @@ void Split::updateInputPlaceholder() void Split::joinChannelInNewTab(ChannelPtr channel) { - auto &nb = getIApp()->getWindows()->getMainWindow().getNotebook(); + auto &nb = getApp()->getWindows()->getMainWindow().getNotebook(); SplitContainer *container = nb.addPage(true); Split *split = new Split(container); @@ -907,7 +907,7 @@ void Split::setChannel(IndirectChannel newChannel) this->actionRequested.invoke(Action::RefreshTab); // Queue up save because: Split channel changed - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); } void Split::setModerationMode(bool value) @@ -1001,7 +1001,7 @@ void Split::keyReleaseEvent(QKeyEvent *event) void Split::resizeEvent(QResizeEvent *event) { // Queue up save because: Split resized - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); BaseWidget::resizeEvent(event); @@ -1122,8 +1122,7 @@ void Split::openInBrowser() void Split::openWhispersInBrowser() { - auto userName = - getIApp()->getAccounts()->twitch.getCurrent()->getUserName(); + auto userName = getApp()->getAccounts()->twitch.getCurrent()->getUserName(); QDesktopServices::openUrl("https://twitch.tv/popout/moderator/" + userName + "/whispers"); } @@ -1211,7 +1210,7 @@ void Split::showChatterList() auto *item = new QListWidgetItem(); item->setText(text); item->setFont( - getIApp()->getFonts()->getFont(FontStyle::ChatMedium, 1.0)); + getApp()->getFonts()->getFont(FontStyle::ChatMedium, 1.0)); return item; }; @@ -1261,7 +1260,7 @@ void Split::showChatterList() auto loadChatters = [=](auto modList, auto vipList, bool isBroadcaster) { getHelix()->getChatters( twitchChannel->roomId(), - getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 50000, + getApp()->getAccounts()->twitch.getCurrent()->getUserId(), 50000, [=](auto chatters) { auto broadcaster = channel->getName().toLower(); QStringList chatterList; @@ -1426,8 +1425,8 @@ void Split::showChatterList() }}, }; - getIApp()->getHotkeys()->shortcutsForCategory(HotkeyCategory::PopupWindow, - actions, chatterDock); + getApp()->getHotkeys()->shortcutsForCategory(HotkeyCategory::PopupWindow, + actions, chatterDock); dockVbox->addWidget(searchBar); dockVbox->addWidget(loadingLabel); @@ -1490,7 +1489,7 @@ void Split::showSearch(bool singleChannel) } // Pass every ChannelView for every Split across the app to the search popup - auto ¬ebook = getIApp()->getWindows()->getMainWindow().getNotebook(); + auto ¬ebook = getApp()->getWindows()->getMainWindow().getNotebook(); for (int i = 0; i < notebook.getPageCount(); ++i) { auto *container = dynamic_cast(notebook.getPageAt(i)); @@ -1509,7 +1508,7 @@ void Split::showSearch(bool singleChannel) void Split::reloadChannelAndSubscriberEmotes() { auto channel = this->getChannel(); - getIApp()->getAccounts()->twitch.getCurrent()->loadEmotes(channel); + getApp()->getAccounts()->twitch.getCurrent()->loadEmotes(channel); if (auto *twitchChannel = dynamic_cast(channel.get())) { diff --git a/src/widgets/splits/SplitContainer.cpp b/src/widgets/splits/SplitContainer.cpp index bee31cd11..57b129931 100644 --- a/src/widgets/splits/SplitContainer.cpp +++ b/src/widgets/splits/SplitContainer.cpp @@ -134,7 +134,7 @@ Split *SplitContainer::appendNewSplit(bool openChannelNameDialog) void SplitContainer::insertSplit(Split *split, InsertOptions &&options) { // Queue up save because: Split added - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); assertInGuiThread(); @@ -348,7 +348,7 @@ SplitContainer::Position SplitContainer::releaseSplit(Split *split) SplitContainer::Position SplitContainer::deleteSplit(Split *split) { // Queue up save because: Split removed - getIApp()->getWindows()->queueSave(); + getApp()->getWindows()->queueSave(); assertInGuiThread(); assert(split != nullptr); @@ -617,8 +617,8 @@ void SplitContainer::paintEvent(QPaintEvent * /*event*/) painter.setPen(this->theme->splits.header.text); - const auto font = getIApp()->getFonts()->getFont(FontStyle::ChatMedium, - this->scale()); + const auto font = + getApp()->getFonts()->getFont(FontStyle::ChatMedium, this->scale()); painter.setFont(font); QString text = "Click to add a split"; @@ -637,7 +637,7 @@ void SplitContainer::paintEvent(QPaintEvent * /*event*/) } else { - if (getIApp()->getThemes()->isLightTheme()) + if (getApp()->getThemes()->isLightTheme()) { painter.fillRect(rect(), QColor("#999")); } @@ -649,8 +649,8 @@ void SplitContainer::paintEvent(QPaintEvent * /*event*/) for (DropRect &dropRect : this->dropRects_) { - QColor border = getIApp()->getThemes()->splits.dropTargetRectBorder; - QColor background = getIApp()->getThemes()->splits.dropTargetRect; + QColor border = getApp()->getThemes()->splits.dropTargetRectBorder; + QColor background = getApp()->getThemes()->splits.dropTargetRect; if (!dropRect.rect.contains(this->mouseOverPoint_)) { @@ -782,7 +782,7 @@ void SplitContainer::applyFromDescriptor(const NodeDescriptor &rootNode) void SplitContainer::popup() { - Window &window = getIApp()->getWindows()->createWindow(WindowType::Popup); + Window &window = getApp()->getWindows()->createWindow(WindowType::Popup); auto *popupContainer = window.getNotebook().getOrAddSelectedPage(); QJsonObject encodedTab; @@ -1494,15 +1494,15 @@ void SplitContainer::DropOverlay::paintEvent(QPaintEvent * /*event*/) { if (!foundMover && rect.rect.contains(this->mouseOverPoint_)) { - painter.setBrush(getIApp()->getThemes()->splits.dropPreview); - painter.setPen(getIApp()->getThemes()->splits.dropPreviewBorder); + painter.setBrush(getApp()->getThemes()->splits.dropPreview); + painter.setPen(getApp()->getThemes()->splits.dropPreviewBorder); foundMover = true; } else { painter.setBrush(QColor(0, 0, 0, 0)); painter.setPen(QColor(0, 0, 0, 0)); - // painter.setPen(getIApp()->getThemes()->splits.dropPreviewBorder); + // painter.setPen(getApp()->getThemes()->splits.dropPreviewBorder); } painter.drawRect(rect.rect); @@ -1584,10 +1584,10 @@ SplitContainer::ResizeHandle::ResizeHandle(SplitContainer *_parent) void SplitContainer::ResizeHandle::paintEvent(QPaintEvent * /*event*/) { QPainter painter(this); - painter.setPen(QPen(getIApp()->getThemes()->splits.resizeHandle, 2)); + painter.setPen(QPen(getApp()->getThemes()->splits.resizeHandle, 2)); painter.fillRect(this->rect(), - getIApp()->getThemes()->splits.resizeHandleBackground); + getApp()->getThemes()->splits.resizeHandleBackground); if (this->vertical_) { diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 35fb1dbde..4d7842125 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -140,7 +140,7 @@ auto formatTooltip(const TwitchChannel::StreamStatus &s, QString thumbnail) }(); auto extraStreamData = [&s]() -> QString { - if (getIApp()->getStreamerMode()->isEnabled() && + if (getApp()->getStreamerMode()->isEnabled() && getSettings()->streamerModeHideViewerCountAndDuration) { return QStringLiteral( @@ -246,7 +246,7 @@ SplitHeader::SplitHeader(Split *split) }); this->bSignals_.emplace_back( - getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] { + getApp()->getAccounts()->twitch.currentUserChanged.connect([this] { this->updateIcons(); })); @@ -311,7 +311,7 @@ void SplitHeader::initializeLayout() case Qt::LeftButton: if (getSettings()->moderationActions.empty()) { - getIApp()->getWindows()->showSettingsDialog( + getApp()->getWindows()->showSettingsDialog( this, SettingsDialogPreference:: ModerationActions); this->split_->setModerationMode(true); @@ -329,7 +329,7 @@ void SplitHeader::initializeLayout() case Qt::RightButton: case Qt::MiddleButton: - getIApp()->getWindows()->showSettingsDialog( + getApp()->getWindows()->showSettingsDialog( this, SettingsDialogPreference::ModerationActions); break; @@ -379,7 +379,7 @@ void SplitHeader::initializeLayout() std::unique_ptr SplitHeader::createMainMenu() { // top level menu - const auto &h = getIApp()->getHotkeys(); + const auto &h = getApp()->getHotkeys(); auto menu = std::make_unique(); menu->addAction( "Change channel", this->split_, &Split::changeChannel, @@ -552,11 +552,11 @@ std::unique_ptr SplitHeader::createMainMenu() action->setShortcut(notifySeq); QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action, this]() { - action->setChecked(getIApp()->getNotifications()->isChannelNotified( + action->setChecked(getApp()->getNotifications()->isChannelNotified( this->split_->getChannel()->getName(), Platform::Twitch)); }); QObject::connect(action, &QAction::triggered, this, [this]() { - getIApp()->getNotifications()->updateChannelNotification( + getApp()->getNotifications()->updateChannelNotification( this->split_->getChannel()->getName(), Platform::Twitch); }); @@ -1078,7 +1078,7 @@ void SplitHeader::reloadSubscriberEmotes() this->lastReloadedSubEmotes_ = now; auto channel = this->split_->getChannel(); - getIApp()->getAccounts()->twitch.getCurrent()->loadEmotes(channel); + getApp()->getAccounts()->twitch.getCurrent()->loadEmotes(channel); } void SplitHeader::reconnect() diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index 17eb40418..85c421be9 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -68,7 +68,7 @@ SplitInput::SplitInput(QWidget *parent, Split *_chatWidget, this->hideCompletionPopup(); }); this->scaleChangedEvent(this->scale()); - this->signalHolder_.managedConnect(getIApp()->getHotkeys()->onItemsUpdated, + this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, [this]() { this->clearShortcuts(); this->addShortcuts(); @@ -77,7 +77,7 @@ SplitInput::SplitInput(QWidget *parent, Split *_chatWidget, void SplitInput::initLayout() { - auto *app = getIApp(); + auto *app = getApp(); LayoutCreator layoutCreator(this); auto layout = @@ -219,7 +219,7 @@ void SplitInput::initLayout() void SplitInput::scaleChangedEvent(float scale) { - auto *app = getIApp(); + auto *app = getApp(); // update the icon size of the buttons this->updateEmoteButton(); this->updateCancelReplyButton(); @@ -352,7 +352,7 @@ QString SplitInput::handleSendMessage(const std::vector &arguments) message = message.replace('\n', ' '); QString sendMessage = - getIApp()->getCommands()->execCommand(message, c, false); + getApp()->getCommands()->execCommand(message, c, false); c->sendMessage(sendMessage); @@ -388,7 +388,7 @@ QString SplitInput::handleSendMessage(const std::vector &arguments) message = message.replace('\n', ' '); QString sendMessage = - getIApp()->getCommands()->execCommand(message, c, false); + getApp()->getCommands()->execCommand(message, c, false); // Reply within TwitchChannel tc->sendReply(sendMessage, this->replyTarget_->id); @@ -413,7 +413,7 @@ QString SplitInput::handleSendMessage(const std::vector &arguments) message = message.replace('\n', ' '); QString sendMessage = - getIApp()->getCommands()->execCommand(message, c, false); + getApp()->getCommands()->execCommand(message, c, false); // Reply within TwitchChannel tc->sendReply(sendMessage, this->replyTarget_->id); @@ -698,7 +698,7 @@ void SplitInput::addShortcuts() }}, }; - this->shortcuts_ = getIApp()->getHotkeys()->shortcutsForCategory( + this->shortcuts_ = getApp()->getHotkeys()->shortcutsForCategory( HotkeyCategory::SplitInput, actions, this->parentWidget()); } @@ -983,7 +983,7 @@ void SplitInput::setInputText(const QString &newInputText) void SplitInput::editTextChanged() { - auto *app = getIApp(); + auto *app = getApp(); // set textLengthLabel value QString text = this->ui_.textEdit->toPlainText(); diff --git a/src/widgets/splits/SplitOverlay.cpp b/src/widgets/splits/SplitOverlay.cpp index e6721d654..f9be1af93 100644 --- a/src/widgets/splits/SplitOverlay.cpp +++ b/src/widgets/splits/SplitOverlay.cpp @@ -268,8 +268,8 @@ void SplitOverlay::paintEvent(QPaintEvent *event) { rect.setRight(rect.right() - 1); rect.setBottom(rect.bottom() - 1); - painter.setPen(getIApp()->getThemes()->splits.dropPreviewBorder); - painter.setBrush(getIApp()->getThemes()->splits.dropPreview); + painter.setPen(getApp()->getThemes()->splits.dropPreviewBorder); + painter.setBrush(getApp()->getThemes()->splits.dropPreview); painter.drawRect(rect); } } diff --git a/tests/src/Commands.cpp b/tests/src/Commands.cpp index f180a7180..2a4d259aa 100644 --- a/tests/src/Commands.cpp +++ b/tests/src/Commands.cpp @@ -27,6 +27,7 @@ class MockApplication : mock::EmptyApplication public: MockApplication() : settings(this->settingsDir.filePath("settings.json")) + , commands(this->paths_) { } @@ -833,8 +834,6 @@ TEST(Commands, E2E) ::testing::InSequence seq; MockApplication app; - app.commands.initialize(*getSettings(), getIApp()->getPaths()); - QJsonObject pajlada; pajlada["id"] = "11148817"; pajlada["login"] = "pajlada"; @@ -879,10 +878,10 @@ TEST(Commands, E2E) auto account = std::make_shared( testaccount420["login"].toString(), "token", "oauthclient", testaccount420["id"].toString()); - getIApp()->getAccounts()->twitch.accounts.append(account); - getIApp()->getAccounts()->twitch.currentUsername = + getApp()->getAccounts()->twitch.accounts.append(account); + getApp()->getAccounts()->twitch.currentUsername = testaccount420["login"].toString(); - getIApp()->getAccounts()->twitch.load(); + getApp()->getAccounts()->twitch.load(); // Simple single-channel ban EXPECT_CALL(mockHelix, fetchUsers(QStringList{"11148817"}, @@ -901,7 +900,7 @@ TEST(Commands, E2E) QString(""), _, _)) .Times(1); - getIApp()->getCommands()->execCommand("/ban forsen", channel, false); + getApp()->getCommands()->execCommand("/ban forsen", channel, false); // Multi-channel ban EXPECT_CALL(mockHelix, fetchUsers(QStringList{"11148817"}, @@ -937,7 +936,7 @@ TEST(Commands, E2E) std::optional{}, QString(""), _, _)) .Times(1); - getIApp()->getCommands()->execCommand( + getApp()->getCommands()->execCommand( "/ban --channel id:11148817 --channel testaccount_420 forsen", channel, false); @@ -948,7 +947,7 @@ TEST(Commands, E2E) QString(""), _, _)) .Times(1); - getIApp()->getCommands()->execCommand("/ban id:22484632", channel, false); + getApp()->getCommands()->execCommand("/ban id:22484632", channel, false); // ID-based redirected ban EXPECT_CALL(mockHelix, @@ -957,7 +956,7 @@ TEST(Commands, E2E) QString(""), _, _)) .Times(1); - getIApp()->getCommands()->execCommand( + getApp()->getCommands()->execCommand( "/ban --channel id:117166826 id:22484632", channel, false); // name-based redirected ban @@ -976,7 +975,7 @@ TEST(Commands, E2E) QString(""), _, _)) .Times(1); - getIApp()->getCommands()->execCommand( + getApp()->getCommands()->execCommand( "/ban --channel testaccount_420 id:22484632", channel, false); // Multi-channel timeout @@ -1013,7 +1012,7 @@ TEST(Commands, E2E) std::optional{600}, QString(""), _, _)) .Times(1); - getIApp()->getCommands()->execCommand( + getApp()->getCommands()->execCommand( "/timeout --channel id:11148817 --channel testaccount_420 forsen", channel, false); @@ -1049,7 +1048,7 @@ TEST(Commands, E2E) forsen["id"].toString(), _, _)) .Times(1); - getIApp()->getCommands()->execCommand( + getApp()->getCommands()->execCommand( "/unban --channel id:11148817 --channel testaccount_420 forsen", channel, false); } diff --git a/tests/src/Filters.cpp b/tests/src/Filters.cpp index 89c0a510f..cb8c07c74 100644 --- a/tests/src/Filters.cpp +++ b/tests/src/Filters.cpp @@ -29,6 +29,12 @@ namespace { class MockApplication : mock::EmptyApplication { public: + MockApplication() + : settings(this->settingsDir.filePath("settings.json")) + , highlights(this->settings, &this->accounts) + { + } + IEmotes *getEmotes() override { return &this->emotes; @@ -69,6 +75,7 @@ public: return &this->highlights; } + Settings settings; AccountController accounts; Emotes emotes; mock::UserDataController userData; diff --git a/tests/src/HighlightController.cpp b/tests/src/HighlightController.cpp index 090acf37b..76f92db18 100644 --- a/tests/src/HighlightController.cpp +++ b/tests/src/HighlightController.cpp @@ -8,7 +8,6 @@ #include "mocks/UserData.hpp" #include "providers/twitch/api/Helix.hpp" #include "providers/twitch/TwitchBadge.hpp" // for Badge -#include "singletons/Paths.hpp" #include "singletons/Settings.hpp" #include "Test.hpp" @@ -23,9 +22,16 @@ using ::testing::Exactly; namespace { -class MockApplication : mock::EmptyApplication +class MockApplication : public mock::EmptyApplication { public: + MockApplication(const QString &settingsBody) + : mock::EmptyApplication(settingsBody) + , settings(this->settingsDir.path()) + , highlights(this->settings, &this->accounts) + { + } + AccountController *getAccounts() override { return &this->accounts; @@ -41,10 +47,10 @@ public: return &this->userData; } + Settings settings; AccountController accounts; HighlightController highlights; mock::UserDataController userData; - // TODO: Figure this out }; } // namespace @@ -180,13 +186,7 @@ protected: void configure(const QString &settings, bool isAnon) { // Write default settings to the mock settings json file - this->settingsDir_ = std::make_unique(); - - QFile settingsFile(this->settingsDir_->filePath("settings.json")); - ASSERT_TRUE(settingsFile.open(QIODevice::WriteOnly | QIODevice::Text)); - ASSERT_GT(settingsFile.write(settings.toUtf8()), 0); - ASSERT_TRUE(settingsFile.flush()); - settingsFile.close(); + this->mockApplication = std::make_unique(settings); this->mockHelix = new mock::Helix; @@ -195,24 +195,17 @@ protected: EXPECT_CALL(*this->mockHelix, loadBlocks).Times(Exactly(1)); EXPECT_CALL(*this->mockHelix, update).Times(Exactly(isAnon ? 0 : 1)); - this->mockApplication = std::make_unique(); - this->settings = std::make_unique(this->settingsDir_->path()); - this->paths = std::make_unique(); - - this->controller = std::make_unique(); - - this->mockApplication->accounts.initialize(*this->settings, - *this->paths); - this->controller->initialize(*this->settings, *this->paths); + this->mockApplication->accounts.load(); } void runTests(const std::vector &tests) { for (const auto &[input, expected] : tests) { - auto [isMatch, matchResult] = this->controller->check( - input.args, input.badges, input.senderName, - input.originalMessage, input.flags); + auto [isMatch, matchResult] = + this->mockApplication->getHighlights()->check( + input.args, input.badges, input.senderName, + input.originalMessage, input.flags); EXPECT_EQ(isMatch, expected.state) << input.senderName << ": " << input.originalMessage; @@ -224,23 +217,11 @@ protected: void TearDown() override { this->mockApplication.reset(); - this->settings.reset(); - this->paths.reset(); - - this->controller.reset(); - - this->settingsDir_.reset(); delete this->mockHelix; } - std::unique_ptr settingsDir_; - std::unique_ptr mockApplication; - std::unique_ptr settings; - std::unique_ptr paths; - - std::unique_ptr controller; mock::Helix *mockHelix; }; diff --git a/tests/src/InputCompletion.cpp b/tests/src/InputCompletion.cpp index 22c42b31c..2b987a5e1 100644 --- a/tests/src/InputCompletion.cpp +++ b/tests/src/InputCompletion.cpp @@ -129,9 +129,7 @@ protected: this->settings = std::make_unique(this->settingsDir_->path()); this->paths = std::make_unique(); - this->mockApplication->accounts.initialize(*this->settings, - *this->paths); - this->mockApplication->emotes.initialize(*this->settings, *this->paths); + this->mockApplication->accounts.load(); this->channelPtr = std::make_shared("icelys"); diff --git a/tests/src/MessageLayout.cpp b/tests/src/MessageLayout.cpp index 8533b87b8..55db48c3b 100644 --- a/tests/src/MessageLayout.cpp +++ b/tests/src/MessageLayout.cpp @@ -4,7 +4,7 @@ #include "controllers/accounts/AccountController.hpp" #include "messages/MessageBuilder.hpp" #include "messages/MessageElement.hpp" -#include "mocks/EmptyApplication.hpp" +#include "mocks/BaseApplication.hpp" #include "singletons/Emotes.hpp" #include "singletons/Fonts.hpp" #include "singletons/Settings.hpp" @@ -21,15 +21,16 @@ using namespace chatterino; namespace { -class MockApplication : mock::EmptyApplication +class MockApplication : mock::BaseApplication { public: MockApplication() - : settings(this->settingsDir.filePath("settings.json")) + : theme(this->paths_) , fonts(this->settings) , windowManager(this->paths_) { } + Theme *getThemes() override { return &this->theme; @@ -45,7 +46,12 @@ public: return &this->windowManager; } - Settings settings; + AccountController *getAccounts() override + { + return &this->accounts; + } + + AccountController accounts; Theme theme; Fonts fonts; WindowManager windowManager; diff --git a/tests/src/NotebookTab.cpp b/tests/src/NotebookTab.cpp index 36133b648..2c6287ba2 100644 --- a/tests/src/NotebookTab.cpp +++ b/tests/src/NotebookTab.cpp @@ -23,6 +23,7 @@ class MockApplication : mock::EmptyApplication public: MockApplication() : settings(this->settingsDir.filePath("settings.json")) + , theme(this->paths_) , fonts(this->settings) { } diff --git a/tests/src/Scrollbar.cpp b/tests/src/Scrollbar.cpp index 98ca9a640..ee143351e 100644 --- a/tests/src/Scrollbar.cpp +++ b/tests/src/Scrollbar.cpp @@ -1,7 +1,7 @@ #include "widgets/Scrollbar.hpp" #include "Application.hpp" -#include "mocks/EmptyApplication.hpp" +#include "mocks/BaseApplication.hpp" #include "singletons/Fonts.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" @@ -17,11 +17,11 @@ using namespace chatterino; namespace { -class MockApplication : mock::EmptyApplication +class MockApplication : mock::BaseApplication { public: MockApplication() - : settings(this->settingsDir.filePath("settings.json")) + : theme(this->paths_) , fonts(this->settings) , windowManager(this->paths_) { @@ -41,7 +41,6 @@ public: return &this->windowManager; } - Settings settings; Theme theme; Fonts fonts; WindowManager windowManager; diff --git a/tests/src/SplitInput.cpp b/tests/src/SplitInput.cpp index d84da8118..d09739dcf 100644 --- a/tests/src/SplitInput.cpp +++ b/tests/src/SplitInput.cpp @@ -5,7 +5,7 @@ #include "controllers/commands/Command.hpp" #include "controllers/commands/CommandController.hpp" #include "controllers/hotkeys/HotkeyController.hpp" -#include "mocks/EmptyApplication.hpp" +#include "mocks/BaseApplication.hpp" #include "singletons/Emotes.hpp" #include "singletons/Fonts.hpp" #include "singletons/Paths.hpp" @@ -24,13 +24,14 @@ using ::testing::Exactly; namespace { -class MockApplication : mock::EmptyApplication +class MockApplication : public mock::BaseApplication { public: MockApplication() - : settings(this->settingsDir.filePath("settings.json")) + : theme(this->paths_) , fonts(this->settings) - , windowManager(this->paths) + , windowManager(this->paths_) + , commands(this->paths_) { } Theme *getThemes() override @@ -68,11 +69,9 @@ public: return &this->emotes; } - Settings settings; Theme theme; HotkeyController hotkeys; Fonts fonts; - Paths paths; WindowManager windowManager; AccountController accounts; CommandController commands; diff --git a/tests/src/TwitchMessageBuilder.cpp b/tests/src/TwitchMessageBuilder.cpp index d9d1d5a62..7c29a4ae4 100644 --- a/tests/src/TwitchMessageBuilder.cpp +++ b/tests/src/TwitchMessageBuilder.cpp @@ -32,6 +32,12 @@ namespace { class MockApplication : mock::EmptyApplication { public: + MockApplication() + : settings(this->settingsDir.filePath("settings.json")) + , highlights(this->settings, &this->accounts) + { + } + IEmotes *getEmotes() override { return &this->emotes; @@ -92,6 +98,7 @@ public: return &this->streamerMode; } + Settings settings; AccountController accounts; Emotes emotes; mock::UserDataController userData;