From 7cb04bf58b73e43c3bc407607c8dc5993be1c344 Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 28 Aug 2023 17:51:28 +0200 Subject: [PATCH] Remove BaseSettings & merge ConcurrentSettings (#4775) --- CHANGELOG.md | 1 + src/BaseSettings.cpp | 128 ------------ src/BaseSettings.hpp | 47 ----- src/CMakeLists.txt | 2 - src/common/ChatterinoSetting.cpp | 2 +- src/controllers/filters/FilterSet.cpp | 8 +- .../highlights/HighlightController.cpp | 6 +- src/controllers/ignores/IgnoreController.cpp | 2 +- src/messages/MessageElement.cpp | 2 +- src/messages/SharedMessageBuilder.cpp | 6 +- src/providers/twitch/TwitchMessageBuilder.cpp | 2 +- src/singletons/Settings.cpp | 197 +++++++++++++----- src/singletons/Settings.hpp | 112 ++++++---- src/widgets/BaseWidget.cpp | 1 - src/widgets/BaseWindow.cpp | 2 +- .../dialogs/SelectChannelFiltersDialog.cpp | 2 +- tests/src/HighlightController.cpp | 1 - tests/src/InputCompletion.cpp | 1 - 18 files changed, 238 insertions(+), 284 deletions(-) delete mode 100644 src/BaseSettings.cpp delete mode 100644 src/BaseSettings.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index e458407801b..71106eabfa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) - Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767) - Dev: Tests now run on Ubuntu 22.04 instead of 20.04 to loosen C++ restrictions in tests. (#4774) +- Dev: Do a pretty major refactor of the Settings classes. List settings (e.g. highlights) are most heavily modified, and should have an extra eye kept on them. (#4775) ## 2.4.5 diff --git a/src/BaseSettings.cpp b/src/BaseSettings.cpp deleted file mode 100644 index 441ed08b499..00000000000 --- a/src/BaseSettings.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "BaseSettings.hpp" - -#include "util/Clamp.hpp" - -#include - -namespace chatterino { - -std::vector> _settings; - -AB_SETTINGS_CLASS *AB_SETTINGS_CLASS::instance = nullptr; - -void _actuallyRegisterSetting( - std::weak_ptr setting) -{ - _settings.push_back(std::move(setting)); -} - -AB_SETTINGS_CLASS::AB_SETTINGS_CLASS(const QString &settingsDirectory) -{ - AB_SETTINGS_CLASS::instance = this; - - QString settingsPath = settingsDirectory + "/settings.json"; - - // get global instance of the settings library - auto settingsInstance = pajlada::Settings::SettingManager::getInstance(); - - settingsInstance->load(qPrintable(settingsPath)); - - settingsInstance->setBackupEnabled(true); - settingsInstance->setBackupSlots(9); - settingsInstance->saveMethod = - pajlada::Settings::SettingManager::SaveMethod::SaveOnExit; -} - -void AB_SETTINGS_CLASS::saveSnapshot() -{ - rapidjson::Document *d = new rapidjson::Document(rapidjson::kObjectType); - rapidjson::Document::AllocatorType &a = d->GetAllocator(); - - for (const auto &weakSetting : _settings) - { - auto setting = weakSetting.lock(); - if (!setting) - { - continue; - } - - rapidjson::Value key(setting->getPath().c_str(), a); - auto curVal = setting->unmarshalJSON(); - if (curVal == nullptr) - { - continue; - } - - rapidjson::Value val; - val.CopyFrom(*curVal, a); - d->AddMember(key.Move(), val.Move(), a); - } - - // log("Snapshot state: {}", rj::stringify(*d)); - - this->snapshot_.reset(d); -} - -void AB_SETTINGS_CLASS::restoreSnapshot() -{ - if (!this->snapshot_) - { - return; - } - - const auto &snapshot = *(this->snapshot_.get()); - - if (!snapshot.IsObject()) - { - return; - } - - for (const auto &weakSetting : _settings) - { - auto setting = weakSetting.lock(); - if (!setting) - { - continue; - } - - const char *path = setting->getPath().c_str(); - - if (!snapshot.HasMember(path)) - { - continue; - } - - setting->marshalJSON(snapshot[path]); - } -} - -float AB_SETTINGS_CLASS::getClampedUiScale() const -{ - return clamp(this->uiScale.getValue(), 0.2f, 10); -} - -void AB_SETTINGS_CLASS::setClampedUiScale(float value) -{ - this->uiScale.setValue(clamp(value, 0.2f, 10)); -} - -#ifndef AB_CUSTOM_SETTINGS -Settings *getSettings() -{ - static_assert(std::is_same_v, - "`AB_SETTINGS_CLASS` must be the same as `Settings`"); - - assert(AB_SETTINGS_CLASS::instance != nullptr); - - return AB_SETTINGS_CLASS::instance; -} -#endif - -AB_SETTINGS_CLASS *getABSettings() -{ - assert(AB_SETTINGS_CLASS::instance); - - return AB_SETTINGS_CLASS::instance; -} - -} // namespace chatterino diff --git a/src/BaseSettings.hpp b/src/BaseSettings.hpp deleted file mode 100644 index 89ce45d06cf..00000000000 --- a/src/BaseSettings.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "common/ChatterinoSetting.hpp" - -#include -#include -#include - -#include - -#ifdef AB_CUSTOM_SETTINGS -# define AB_SETTINGS_CLASS ABSettings -#else -# define AB_SETTINGS_CLASS Settings -#endif - -namespace chatterino { - -class Settings; - -void _actuallyRegisterSetting( - std::weak_ptr setting); - -class AB_SETTINGS_CLASS -{ -public: - AB_SETTINGS_CLASS(const QString &settingsDirectory); - - void saveSnapshot(); - void restoreSnapshot(); - - static AB_SETTINGS_CLASS *instance; - - FloatSetting uiScale = {"/appearance/uiScale2", 1}; - BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false}; - - float getClampedUiScale() const; - void setClampedUiScale(float value); - -private: - std::unique_ptr snapshot_; -}; - -Settings *getSettings(); -AB_SETTINGS_CLASS *getABSettings(); - -} // namespace chatterino diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 388b725b164..416b7996d6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,8 +9,6 @@ option(CHATTERINO_DEBUG_NATIVE_MESSAGES "Debug native messages" OFF) set(SOURCE_FILES Application.cpp Application.hpp - BaseSettings.cpp - BaseSettings.hpp BrowserExtension.cpp BrowserExtension.hpp RunGui.cpp diff --git a/src/common/ChatterinoSetting.cpp b/src/common/ChatterinoSetting.cpp index b0acb854ae5..284033a6227 100644 --- a/src/common/ChatterinoSetting.cpp +++ b/src/common/ChatterinoSetting.cpp @@ -1,6 +1,6 @@ #include "common/ChatterinoSetting.hpp" -#include "BaseSettings.hpp" +#include "singletons/Settings.hpp" namespace chatterino { diff --git a/src/controllers/filters/FilterSet.cpp b/src/controllers/filters/FilterSet.cpp index a6dbc1059d6..66e54dd0157 100644 --- a/src/controllers/filters/FilterSet.cpp +++ b/src/controllers/filters/FilterSet.cpp @@ -8,14 +8,14 @@ namespace chatterino { FilterSet::FilterSet() { this->listener_ = - getCSettings().filterRecords.delayedItemsChanged.connect([this] { + getSettings()->filterRecords.delayedItemsChanged.connect([this] { this->reloadFilters(); }); } FilterSet::FilterSet(const QList &filterIds) { - auto filters = getCSettings().filterRecords.readOnly(); + auto filters = getSettings()->filterRecords.readOnly(); for (const auto &f : *filters) { if (filterIds.contains(f->getId())) @@ -23,7 +23,7 @@ FilterSet::FilterSet(const QList &filterIds) } this->listener_ = - getCSettings().filterRecords.delayedItemsChanged.connect([this] { + getSettings()->filterRecords.delayedItemsChanged.connect([this] { this->reloadFilters(); }); } @@ -55,7 +55,7 @@ const QList FilterSet::filterIds() const void FilterSet::reloadFilters() { - auto filters = getCSettings().filterRecords.readOnly(); + auto filters = getSettings()->filterRecords.readOnly(); for (const auto &key : this->filters_.keys()) { bool found = false; diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 8f7958dc670..91999c82f88 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -441,7 +441,7 @@ void HighlightController::initialize(Settings &settings, Paths & /*paths*/) }); this->signalHolder_.managedConnect( - getCSettings().highlightedBadges.delayedItemsChanged, + getSettings()->highlightedBadges.delayedItemsChanged, [this, &settings] { qCDebug(chatterinoHighlights) << "Rebuild checks because highlight badges changed"; @@ -449,14 +449,14 @@ void HighlightController::initialize(Settings &settings, Paths & /*paths*/) }); this->signalHolder_.managedConnect( - getCSettings().highlightedUsers.delayedItemsChanged, [this, &settings] { + getSettings()->highlightedUsers.delayedItemsChanged, [this, &settings] { qCDebug(chatterinoHighlights) << "Rebuild checks because highlight users changed"; this->rebuildChecks(settings); }); this->signalHolder_.managedConnect( - getCSettings().highlightedMessages.delayedItemsChanged, + getSettings()->highlightedMessages.delayedItemsChanged, [this, &settings] { qCDebug(chatterinoHighlights) << "Rebuild checks because highlight messages changed"; diff --git a/src/controllers/ignores/IgnoreController.cpp b/src/controllers/ignores/IgnoreController.cpp index 6f387640176..e49e8a8218b 100644 --- a/src/controllers/ignores/IgnoreController.cpp +++ b/src/controllers/ignores/IgnoreController.cpp @@ -14,7 +14,7 @@ bool isIgnoredMessage(IgnoredMessageParameters &¶ms) if (!params.message.isEmpty()) { // TODO(pajlada): Do we need to check if the phrase is valid first? - auto phrases = getCSettings().ignoredMessages.readOnly(); + auto phrases = getSettings()->ignoredMessages.readOnly(); for (const auto &phrase : *phrases) { if (phrase.isBlock() && phrase.isMatch(params.message)) diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 63d274713ee..8f6dd2ccdd0 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -806,7 +806,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container, { QSize size(int(container.getScale() * 16), int(container.getScale() * 16)); - auto actions = getCSettings().moderationActions.readOnly(); + auto actions = getSettings()->moderationActions.readOnly(); for (const auto &action : *actions) { if (auto image = action.getImage()) diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index 97c795c3a83..b54147c3048 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -147,7 +147,7 @@ void SharedMessageBuilder::parseUsername() void SharedMessageBuilder::parseHighlights() { - if (getCSettings().isBlacklistedUser(this->ircMessage->nick())) + if (getSettings()->isBlacklistedUser(this->ircMessage->nick())) { // Do nothing. We ignore highlights from this user. return; @@ -206,7 +206,7 @@ void SharedMessageBuilder::triggerHighlights() return; } - if (getCSettings().isMutedChannel(this->channel->getName())) + if (getSettings()->isMutedChannel(this->channel->getName())) { // Do nothing. Pings are muted in this channel. return; @@ -270,7 +270,7 @@ QString SharedMessageBuilder::stylizeUsername(const QString &username, break; } - if (auto nicknameText = getCSettings().matchNickname(usernameText)) + if (auto nicknameText = getSettings()->matchNickname(usernameText)) { usernameText = *nicknameText; } diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 69bb5ed69ce..ae58d917860 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -834,7 +834,7 @@ void TwitchMessageBuilder::appendUsername() void TwitchMessageBuilder::runIgnoreReplaces( std::vector &twitchEmotes) { - auto phrases = getCSettings().ignoredMessages.readOnly(); + auto phrases = getSettings()->ignoredMessages.readOnly(); auto removeEmotesInRange = [](int pos, int len, auto &twitchEmotes) mutable { auto it = std::partition( diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index e01f316a135..a56db4ffa16 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -8,40 +8,46 @@ #include "controllers/ignores/IgnorePhrase.hpp" #include "controllers/moderationactions/ModerationAction.hpp" #include "controllers/nicknames/Nickname.hpp" +#include "util/Clamp.hpp" #include "util/PersistSignalVector.hpp" #include "util/WindowsHelper.hpp" +#include + +namespace { + +using namespace chatterino; + +template +void initializeSignalVector(pajlada::Signals::SignalHolder &signalHolder, + ChatterinoSetting> &setting, + SignalVector &vec) +{ + // Fill the SignalVector up with initial values + for (auto &&item : setting.getValue()) + { + vec.append(item); + } + + // Set up a signal to + signalHolder.managedConnect(vec.delayedItemsChanged, [&] { + setting.setValue(vec.raw()); + }); +} + +} // namespace + namespace chatterino { -ConcurrentSettings *concurrentInstance_{}; - -ConcurrentSettings::ConcurrentSettings() - // NOTE: these do not get deleted - : highlightedMessages(*new SignalVector()) - , highlightedUsers(*new SignalVector()) - , highlightedBadges(*new SignalVector()) - , blacklistedUsers(*new SignalVector()) - , ignoredMessages(*new SignalVector()) - , mutedChannels(*new SignalVector()) - , filterRecords(*new SignalVector()) - , nicknames(*new SignalVector()) - , moderationActions(*new SignalVector) - , loggedChannels(*new SignalVector) -{ - persist(this->highlightedMessages, "/highlighting/highlights"); - persist(this->blacklistedUsers, "/highlighting/blacklist"); - persist(this->highlightedBadges, "/highlighting/badges"); - persist(this->highlightedUsers, "/highlighting/users"); - persist(this->ignoredMessages, "/ignore/phrases"); - persist(this->mutedChannels, "/pings/muted"); - persist(this->filterRecords, "/filtering/filters"); - persist(this->nicknames, "/nicknames"); - // tagged users? - persist(this->moderationActions, "/moderation/actions"); - persist(this->loggedChannels, "/logging/channels"); -} - -bool ConcurrentSettings::isHighlightedUser(const QString &username) +std::vector> _settings; + +void _actuallyRegisterSetting( + std::weak_ptr setting) +{ + _settings.push_back(std::move(setting)); +} + +bool Settings::isHighlightedUser(const QString &username) { auto items = this->highlightedUsers.readOnly(); @@ -54,7 +60,7 @@ bool ConcurrentSettings::isHighlightedUser(const QString &username) return false; } -bool ConcurrentSettings::isBlacklistedUser(const QString &username) +bool Settings::isBlacklistedUser(const QString &username) { auto items = this->blacklistedUsers.readOnly(); @@ -67,7 +73,7 @@ bool ConcurrentSettings::isBlacklistedUser(const QString &username) return false; } -bool ConcurrentSettings::isMutedChannel(const QString &channelName) +bool Settings::isMutedChannel(const QString &channelName) { auto items = this->mutedChannels.readOnly(); @@ -81,10 +87,9 @@ bool ConcurrentSettings::isMutedChannel(const QString &channelName) return false; } -boost::optional ConcurrentSettings::matchNickname( - const QString &usernameText) +boost::optional Settings::matchNickname(const QString &usernameText) { - auto nicknames = getCSettings().nicknames.readOnly(); + auto nicknames = this->nicknames.readOnly(); for (const auto &nickname : *nicknames) { @@ -97,12 +102,12 @@ boost::optional ConcurrentSettings::matchNickname( return boost::none; } -void ConcurrentSettings::mute(const QString &channelName) +void Settings::mute(const QString &channelName) { mutedChannels.append(channelName); } -void ConcurrentSettings::unmute(const QString &channelName) +void Settings::unmute(const QString &channelName) { for (std::vector::size_type i = 0; i != mutedChannels.raw().size(); i++) @@ -115,7 +120,7 @@ void ConcurrentSettings::unmute(const QString &channelName) } } -bool ConcurrentSettings::toggleMutedChannel(const QString &channelName) +bool Settings::toggleMutedChannel(const QString &channelName) { if (this->isMutedChannel(channelName)) { @@ -129,21 +134,44 @@ bool ConcurrentSettings::toggleMutedChannel(const QString &channelName) } } -ConcurrentSettings &getCSettings() -{ - // `concurrentInstance_` gets assigned in Settings ctor. - assert(concurrentInstance_); - - return *concurrentInstance_; -} - Settings *Settings::instance_ = nullptr; Settings::Settings(const QString &settingsDirectory) - : ABSettings(settingsDirectory) { + QString settingsPath = settingsDirectory + "/settings.json"; + + // get global instance of the settings library + auto settingsInstance = pajlada::Settings::SettingManager::getInstance(); + + settingsInstance->load(qPrintable(settingsPath)); + + settingsInstance->setBackupEnabled(true); + settingsInstance->setBackupSlots(9); + settingsInstance->saveMethod = + pajlada::Settings::SettingManager::SaveMethod::SaveOnExit; + + initializeSignalVector(this->signalHolder, this->highlightedMessagesSetting, + this->highlightedMessages); + initializeSignalVector(this->signalHolder, this->highlightedUsersSetting, + this->highlightedUsers); + initializeSignalVector(this->signalHolder, this->highlightedBadgesSetting, + this->highlightedBadges); + initializeSignalVector(this->signalHolder, this->blacklistedUsersSetting, + this->blacklistedUsers); + initializeSignalVector(this->signalHolder, this->ignoredMessagesSetting, + this->ignoredMessages); + initializeSignalVector(this->signalHolder, this->mutedChannelsSetting, + this->mutedChannels); + initializeSignalVector(this->signalHolder, this->filterRecordsSetting, + this->filterRecords); + initializeSignalVector(this->signalHolder, this->nicknamesSetting, + this->nicknames); + initializeSignalVector(this->signalHolder, this->moderationActionsSetting, + this->moderationActions); + initializeSignalVector(this->signalHolder, this->loggedChannelsSetting, + this->loggedChannels); + instance_ = this; - concurrentInstance_ = this; #ifdef USEWINSDK this->autorun = isRegisteredForStartup(); @@ -160,6 +188,81 @@ Settings::Settings(const QString &settingsDirectory) false); } +Settings::~Settings() = default; + +void Settings::saveSnapshot() +{ + rapidjson::Document *d = new rapidjson::Document(rapidjson::kObjectType); + rapidjson::Document::AllocatorType &a = d->GetAllocator(); + + for (const auto &weakSetting : _settings) + { + auto setting = weakSetting.lock(); + if (!setting) + { + continue; + } + + rapidjson::Value key(setting->getPath().c_str(), a); + auto curVal = setting->unmarshalJSON(); + if (curVal == nullptr) + { + continue; + } + + rapidjson::Value val; + val.CopyFrom(*curVal, a); + d->AddMember(key.Move(), val.Move(), a); + } + + // log("Snapshot state: {}", rj::stringify(*d)); + + this->snapshot_.reset(d); +} + +void Settings::restoreSnapshot() +{ + if (!this->snapshot_) + { + return; + } + + const auto &snapshot = *(this->snapshot_.get()); + + if (!snapshot.IsObject()) + { + return; + } + + for (const auto &weakSetting : _settings) + { + auto setting = weakSetting.lock(); + if (!setting) + { + continue; + } + + const char *path = setting->getPath().c_str(); + + if (!snapshot.HasMember(path)) + { + continue; + } + + setting->marshalJSON(snapshot[path]); + } +} + +float Settings::getClampedUiScale() const +{ + return clamp(this->uiScale.getValue(), 0.2f, 10); +} + +void Settings::setClampedUiScale(float value) +{ + this->uiScale.setValue(clamp(value, 0.2f, 10)); +} + Settings &Settings::instance() { assert(instance_ != nullptr); diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index d3a1e3894c2..27d2b8cbc9b 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -1,10 +1,17 @@ #pragma once -#include "BaseSettings.hpp" #include "common/Channel.hpp" +#include "common/ChatterinoSetting.hpp" #include "common/enums/MessageOverflow.hpp" #include "common/SignalVector.hpp" +#include "controllers/filters/FilterRecord.hpp" +#include "controllers/highlights/HighlightBadge.hpp" +#include "controllers/highlights/HighlightBlacklistUser.hpp" +#include "controllers/highlights/HighlightPhrase.hpp" +#include "controllers/ignores/IgnorePhrase.hpp" #include "controllers/logging/ChannelLog.hpp" +#include "controllers/moderationactions/ModerationAction.hpp" +#include "controllers/nicknames/Nickname.hpp" #include "singletons/Toasts.hpp" #include "util/RapidJsonSerializeQString.hpp" #include "util/StreamerMode.hpp" @@ -12,49 +19,14 @@ #include #include +#include using TimeoutButton = std::pair; namespace chatterino { -class HighlightPhrase; -class HighlightBlacklistUser; -class IgnorePhrase; -class FilterRecord; -using FilterRecordPtr = std::shared_ptr; -class Nickname; -class HighlightBadge; -class ModerationAction; - -/// Settings which are available for reading on all threads. -class ConcurrentSettings -{ -public: - ConcurrentSettings(); - - SignalVector &highlightedMessages; - SignalVector &highlightedUsers; - SignalVector &highlightedBadges; - SignalVector &blacklistedUsers; - SignalVector &ignoredMessages; - SignalVector &mutedChannels; - SignalVector &filterRecords; - SignalVector &nicknames; - SignalVector &moderationActions; - SignalVector &loggedChannels; - - bool isHighlightedUser(const QString &username); - bool isBlacklistedUser(const QString &username); - bool isMutedChannel(const QString &channelName); - bool toggleMutedChannel(const QString &channelName); - boost::optional matchNickname(const QString &username); - -private: - void mute(const QString &channelName); - void unmute(const QString &channelName); -}; - -ConcurrentSettings &getCSettings(); +void _actuallyRegisterSetting( + std::weak_ptr setting); enum UsernameDisplayMode : int { Username = 1, // Username @@ -91,15 +63,25 @@ enum UsernameRightClickBehavior : int { /// Settings which are availlable for reading and writing on the gui thread. // These settings are still accessed concurrently in the code but it is bad practice. -class Settings : public ABSettings, public ConcurrentSettings +class Settings { static Settings *instance_; public: Settings(const QString &settingsDirectory); + ~Settings(); static Settings &instance(); + void saveSnapshot(); + void restoreSnapshot(); + + FloatSetting uiScale = {"/appearance/uiScale2", 1}; + BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false}; + + float getClampedUiScale() const; + void setClampedUiScale(float value); + /// Appearance BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true}; BoolSetting animationsWhenFocused = { @@ -209,7 +191,7 @@ class Settings : public ABSettings, public ConcurrentSettings { "/behaviour/usernameRightClickBehaviorWithModifier", UsernameRightClickBehavior::Reply, - }; + }; EnumSetting usernameRightClickModifier = { "/behaviour/usernameRightClickModifier", Qt::KeyboardModifier::ShiftModifier}; @@ -575,7 +557,55 @@ class Settings : public ABSettings, public ConcurrentSettings "/plugins/enabledPlugins", {}}; private: + ChatterinoSetting> highlightedMessagesSetting = + {"/highlighting/highlights"}; + ChatterinoSetting> highlightedUsersSetting = { + "/highlighting/users"}; + ChatterinoSetting> highlightedBadgesSetting = { + "/highlighting/badges"}; + ChatterinoSetting> + blacklistedUsersSetting = {"/highlighting/blacklist"}; + ChatterinoSetting> ignoredMessagesSetting = { + "/ignore/phrases"}; + ChatterinoSetting> mutedChannelsSetting = { + "/pings/muted"}; + ChatterinoSetting> filterRecordsSetting = { + "/filtering/filters"}; + ChatterinoSetting> nicknamesSetting = {"/nicknames"}; + ChatterinoSetting> moderationActionsSetting = + {"/moderation/actions"}; + ChatterinoSetting> loggedChannelsSetting = { + "/logging/channels"}; + +public: + SignalVector highlightedMessages; + SignalVector highlightedUsers; + SignalVector highlightedBadges; + SignalVector blacklistedUsers; + SignalVector ignoredMessages; + SignalVector mutedChannels; + SignalVector filterRecords; + SignalVector nicknames; + SignalVector moderationActions; + SignalVector loggedChannels; + + bool isHighlightedUser(const QString &username); + bool isBlacklistedUser(const QString &username); + bool isMutedChannel(const QString &channelName); + bool toggleMutedChannel(const QString &channelName); + boost::optional matchNickname(const QString &username); + +private: + void mute(const QString &channelName); + void unmute(const QString &channelName); + void updateModerationActions(); + + std::unique_ptr snapshot_; + + pajlada::Signals::SignalHolder signalHolder; }; +Settings *getSettings(); + } // namespace chatterino diff --git a/src/widgets/BaseWidget.cpp b/src/widgets/BaseWidget.cpp index c98c425c3c3..5be0e8c2619 100644 --- a/src/widgets/BaseWidget.cpp +++ b/src/widgets/BaseWidget.cpp @@ -1,6 +1,5 @@ #include "widgets/BaseWidget.hpp" -#include "BaseSettings.hpp" #include "common/QLogging.hpp" #include "controllers/hotkeys/HotkeyController.hpp" #include "singletons/Theme.hpp" diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index f02cdf472ec..9f1acddcc12 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -710,7 +710,7 @@ void BaseWindow::updateScale() auto scale = this->nativeScale_ * (this->flags_.has(DisableCustomScaling) ? 1 - : getABSettings()->getClampedUiScale()); + : getSettings()->getClampedUiScale()); this->setScale(scale); diff --git a/src/widgets/dialogs/SelectChannelFiltersDialog.cpp b/src/widgets/dialogs/SelectChannelFiltersDialog.cpp index 3b31f17abb7..beb4f992caa 100644 --- a/src/widgets/dialogs/SelectChannelFiltersDialog.cpp +++ b/src/widgets/dialogs/SelectChannelFiltersDialog.cpp @@ -49,7 +49,7 @@ SelectChannelFiltersDialog::SelectChannelFiltersDialog( (this->windowFlags() & ~(Qt::WindowContextHelpButtonHint)) | Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); - auto availableFilters = getCSettings().filterRecords.readOnly(); + auto availableFilters = getSettings()->filterRecords.readOnly(); if (availableFilters->size() == 0) { diff --git a/tests/src/HighlightController.cpp b/tests/src/HighlightController.cpp index c129ecfdf5b..a682a1419e3 100644 --- a/tests/src/HighlightController.cpp +++ b/tests/src/HighlightController.cpp @@ -1,6 +1,5 @@ #include "controllers/highlights/HighlightController.hpp" -#include "BaseSettings.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/highlights/HighlightPhrase.hpp" #include "messages/MessageBuilder.hpp" // for MessageParseArgs diff --git a/tests/src/InputCompletion.cpp b/tests/src/InputCompletion.cpp index 0985ca48965..c1489059a4d 100644 --- a/tests/src/InputCompletion.cpp +++ b/tests/src/InputCompletion.cpp @@ -1,5 +1,4 @@ #include "Application.hpp" -#include "BaseSettings.hpp" #include "common/Aliases.hpp" #include "common/CompletionModel.hpp" #include "controllers/accounts/AccountController.hpp"