From 8687d01ceada10fed0ad430755cacc64cb12430b Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 17 Dec 2017 00:56:33 +0100 Subject: [PATCH 1/2] fix ParseTagString function --- src/util/irchelpers.hpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/util/irchelpers.hpp b/src/util/irchelpers.hpp index 353707fe7..09845137d 100644 --- a/src/util/irchelpers.hpp +++ b/src/util/irchelpers.hpp @@ -15,19 +15,32 @@ QString ParseTagString(const QString &input) if (output[i] == '\\') { QChar c = output[i + 1]; - if (c == 'n') { - output[i] == '\n'; - } else if (c == 'r') { - output[i] == '\r'; - } else if (c == 's') { - output[i] == ' '; - } else if (c == '\\') { - output[i] == '\\'; - } else if (c == ':') { - output[i] == ';'; - } else { - output[i] = output[i + 1]; + switch (c.cell()) { + case 'n': { + output[i] = '\n'; + } break; + + case 'r': { + output[i] = '\r'; + } break; + + case 's': { + output[i] = ' '; + } break; + + case '\\': { + output[i] = '\\'; + } break; + + case ':': { + output[i] = ';'; + } break; + + default: { + output[i] = output[i + 1]; + } break; } + output[i + 1] = '\0'; changed = true; i++; From eb8e14b8fee931cf2fa3421e4fab3f9e1f3f7047 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 17 Dec 2017 01:19:56 +0100 Subject: [PATCH 2/2] Move more settings over to pajlada settings system --- src/messages/messageref.cpp | 3 +- src/settingsmanager.cpp | 82 ++++++++++++----------------- src/settingsmanager.hpp | 77 ++++++++++++++++----------- src/twitch/twitchmessagebuilder.cpp | 10 ++-- src/widgets/helper/notebooktab.cpp | 15 +++--- src/widgets/helper/notebooktab.hpp | 3 +- src/widgets/helper/splitinput.cpp | 7 +-- src/widgets/helper/splitinput.hpp | 2 +- src/widgets/notebook.cpp | 8 +-- src/widgets/settingsdialog.cpp | 2 +- 10 files changed, 104 insertions(+), 105 deletions(-) diff --git a/src/messages/messageref.cpp b/src/messages/messageref.cpp index 49da574cf..d8311ba7f 100644 --- a/src/messages/messageref.cpp +++ b/src/messages/messageref.cpp @@ -233,8 +233,7 @@ void MessageRef::updateImageSizes() const int mediumTextLineHeight = FontManager::getInstance().getFontMetrics(FontManager::Medium).height(); const qreal emoteScale = SettingsManager::getInstance().emoteScale.get() * this->dpiMultiplyer; - const bool scaleEmotesByLineHeight = - SettingsManager::getInstance().scaleEmotesByLineHeight.get(); + const bool scaleEmotesByLineHeight = SettingsManager::getInstance().scaleEmotesByLineHeight; for (auto &word : this->message->getWords()) { if (!word.isImage()) diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp index 4d18dd636..f0ea616c3 100644 --- a/src/settingsmanager.cpp +++ b/src/settingsmanager.cpp @@ -11,58 +11,42 @@ namespace chatterino { SettingsManager::SettingsManager() : settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat) - , showTimestamps("/appearance/messages/showTimestamps", true) - , showTimestampSeconds("/appearance/messages/showTimestampSeconds", true) - , showBadges("/appearance/messages/showBadges", true) , streamlinkPath("/behaviour/streamlink/path", "") , preferredQuality("/behaviour/streamlink/quality", "Choose") , emoteScale(this->settingsItems, "emoteScale", 1.0) , mouseScrollMultiplier(this->settingsItems, "mouseScrollMultiplier", 1.0) - , scaleEmotesByLineHeight(this->settingsItems, "scaleEmotesByLineHeight", false) - , showLastMessageIndicator(this->settingsItems, "showLastMessageIndicator", false) - , allowDouplicateMessages(this->settingsItems, "allowDouplicateMessages", true) - , linksDoubleClickOnly(this->settingsItems, "linksDoubleClickOnly", false) - , hideEmptyInput(this->settingsItems, "hideEmptyInput", false) - , showMessageLength(this->settingsItems, "showMessageLength", false) - , seperateMessages(this->settingsItems, "seperateMessages", false) - , mentionUsersWithAt(this->settingsItems, "mentionUsersWithAt", false) - , allowCommandsAtEnd(this->settingsItems, "allowCommandsAtEnd", false) - , enableHighlights(this->settingsItems, "enableHighlights", true) - , enableHighlightsSelf(this->settingsItems, "enableHighlightsSelf", true) - , enableHighlightSound(this->settingsItems, "enableHighlightSound", true) - , enableHighlightTaskbar(this->settingsItems, "enableHighlightTaskbar", true) - , customHighlightSound(this->settingsItems, "customHighlightSound", false) , pathHighlightSound(this->settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav") , highlightProperties(this->settingsItems, "highlightProperties", QMap>()) , highlightUserBlacklist(this->settingsItems, "highlightUserBlacklist", "") - , highlightAlwaysPlaySound("/highlighting/alwaysPlaySound", false) - , enableTwitchEmotes(this->settingsItems, "enableTwitchEmotes", true) - , enableBttvEmotes(this->settingsItems, "enableBttvEmotes", true) - , enableFfzEmotes(this->settingsItems, "enableFfzEmotes", true) - , enableEmojis(this->settingsItems, "enableEmojis", true) - , enableGifAnimations(this->settingsItems, "enableGifAnimations", true) - , enableGifs(this->settingsItems, "enableGifs", true) - , inlineWhispers(this->settingsItems, "inlineWhispers", true) - , windowTopMost(this->settingsItems, "windowTopMost", false) - , hideTabX(this->settingsItems, "hideTabX", false) - , hidePreferencesButton(this->settingsItems, "hidePreferencesButton", false) - , hideUserButton(this->settingsItems, "hideUserButton", false) - , useCustomWindowFrame(this->settingsItems, "useCustomWindowFrame", true) { - this->showTimestamps.getValueChangedSignal().connect( - [this](const auto &) { this->updateWordTypeMask(); }); - this->showTimestampSeconds.getValueChangedSignal().connect( - [this](const auto &) { this->updateWordTypeMask(); }); - this->showBadges.getValueChangedSignal().connect( - [this](const auto &) { this->updateWordTypeMask(); }); - this->enableBttvEmotes.valueChanged.connect( - [this](const auto &) { this->updateWordTypeMask(); }); - this->enableEmojis.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); }); - this->enableFfzEmotes.valueChanged.connect( - [this](const auto &) { this->updateWordTypeMask(); }); - this->enableTwitchEmotes.valueChanged.connect( - [this](const auto &) { this->updateWordTypeMask(); }); + this->showTimestamps.getValueChangedSignal().connect([this](const auto &) { + this->updateWordTypeMask(); // + }); + + this->showTimestampSeconds.getValueChangedSignal().connect([this](const auto &) { + this->updateWordTypeMask(); // + }); + + this->showBadges.getValueChangedSignal().connect([this](const auto &) { + this->updateWordTypeMask(); // + }); + + this->enableBttvEmotes.getValueChangedSignal().connect([this](const auto &) { + this->updateWordTypeMask(); // + }); + + this->enableEmojis.getValueChangedSignal().connect([this](const auto &) { + this->updateWordTypeMask(); // + }); + + this->enableFfzEmotes.getValueChangedSignal().connect([this](const auto &) { + this->updateWordTypeMask(); // + }); + + this->enableTwitchEmotes.getValueChangedSignal().connect([this](const auto &) { + this->updateWordTypeMask(); // + }); } void SettingsManager::save() @@ -136,15 +120,15 @@ void SettingsManager::updateWordTypeMask() } } - newMaskUint |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage : Word::TwitchEmoteText; - newMaskUint |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText; - newMaskUint |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText; + newMaskUint |= enableTwitchEmotes ? Word::TwitchEmoteImage : Word::TwitchEmoteText; + newMaskUint |= enableFfzEmotes ? Word::FfzEmoteImage : Word::FfzEmoteText; + newMaskUint |= enableBttvEmotes ? Word::BttvEmoteImage : Word::BttvEmoteText; newMaskUint |= - (enableBttvEmotes.get() && enableGifs.get()) ? Word::BttvEmoteImage : Word::BttvEmoteText; - newMaskUint |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText; + (enableBttvEmotes && enableGifAnimations) ? Word::BttvEmoteImage : Word::BttvEmoteText; + newMaskUint |= enableEmojis ? Word::EmojiImage : Word::EmojiText; newMaskUint |= Word::BitsAmount; - newMaskUint |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic; + newMaskUint |= enableGifAnimations ? Word::BitsAnimated : Word::BitsStatic; if (this->showBadges) { newMaskUint |= Word::Badges; diff --git a/src/settingsmanager.hpp b/src/settingsmanager.hpp index 7f8263e47..ebeba9578 100644 --- a/src/settingsmanager.hpp +++ b/src/settingsmanager.hpp @@ -13,6 +13,8 @@ class SettingsManager : public QObject { Q_OBJECT + using BoolSetting = pajlada::Settings::Setting; + public: void load(); void save(); @@ -22,47 +24,58 @@ public: QSettings &getQSettings(); SettingsSnapshot createSnapshot(); - // new pajlada settings BBaper - pajlada::Settings::Setting showTimestamps; - pajlada::Settings::Setting showTimestampSeconds; - pajlada::Settings::Setting showBadges; + /// Appearance + BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true}; + BoolSetting showTimestampSeconds = {"/appearance/messages/showTimestampSeconds", true}; + BoolSetting showBadges = {"/appearance/messages/showBadges", true}; + BoolSetting showLastMessageIndicator = {"/appearance/messages/showLastMessageIndicator", false}; + BoolSetting hideEmptyInput = {"/appearance/hideEmptyInputBox", false}; + BoolSetting showMessageLength = {"/appearance/messages/showMessageLength", false}; + BoolSetting seperateMessages = {"/appearance/messages/separateMessages", false}; + BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false}; + BoolSetting hideTabX = {"/appearance/hideTabX", false}; + BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false}; + BoolSetting hideUserButton = {"/appearance/hideUserButton", false}; + // BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false}; + + /// Behaviour + BoolSetting allowDouplicateMessages = {"/behaviour/allowDuplicateMessages", true}; + BoolSetting mentionUsersWithAt = {"/behaviour/mentionUsersWithAt", false}; + + /// Commands + BoolSetting allowCommandsAtEnd = {"/commands/allowCommandsAtEnd", false}; + + /// Emotes + BoolSetting scaleEmotesByLineHeight = {"/emotes/scaleEmotesByLineHeight", false}; + BoolSetting enableTwitchEmotes = {"/emotes/enableTwitchEmotes", true}; + BoolSetting enableBttvEmotes = {"/emotes/enableBTTVEmotes", true}; + BoolSetting enableFfzEmotes = {"/emotes/enableFFZEmotes", true}; + BoolSetting enableEmojis = {"/emotes/enableEmojis", true}; + BoolSetting enableGifAnimations = {"/emotes/enableGifAnimations", true}; + + /// Links + BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false}; + + /// Highlighting + BoolSetting enableHighlights = {"/highlighting/enabled", true}; + BoolSetting enableHighlightsSelf = {"/highlighting/nameIsHighlightKeyword", true}; + BoolSetting enableHighlightSound = {"/highlighting/enableSound", true}; + BoolSetting enableHighlightTaskbar = {"/highlighting/enableTaskbarFlashing", true}; + BoolSetting customHighlightSound = {"/highlighting/useCustomSound", false}; pajlada::Settings::Setting streamlinkPath; pajlada::Settings::Setting preferredQuality; - // Settings Setting emoteScale; Setting mouseScrollMultiplier; - Setting scaleEmotesByLineHeight; - Setting showLastMessageIndicator; - Setting allowDouplicateMessages; - Setting linksDoubleClickOnly; - Setting hideEmptyInput; - Setting showMessageLength; - Setting seperateMessages; - Setting mentionUsersWithAt; - Setting allowCommandsAtEnd; - Setting enableHighlights; - Setting enableHighlightsSelf; - Setting enableHighlightSound; - Setting enableHighlightTaskbar; - Setting customHighlightSound; + Setting pathHighlightSound; Setting>> highlightProperties; Setting highlightUserBlacklist; - pajlada::Settings::Setting highlightAlwaysPlaySound; - Setting enableTwitchEmotes; - Setting enableBttvEmotes; - Setting enableFfzEmotes; - Setting enableEmojis; - Setting enableGifAnimations; - Setting enableGifs; - Setting inlineWhispers; - Setting windowTopMost; - Setting hideTabX; - Setting hidePreferencesButton; - Setting hideUserButton; - Setting useCustomWindowFrame; + + BoolSetting highlightAlwaysPlaySound = {"/highlighting/alwaysPlaySound", false}; + + BoolSetting inlineWhispers = {"/whispers/enableInlineWhispers", true}; static SettingsManager &getInstance() { diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index 245ced8a8..6391b1dee 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -63,7 +63,7 @@ SharedMessage TwitchMessageBuilder::parse() this->appendUsername(); // highlights - if (settings.enableHighlights.get()) { + if (settings.enableHighlights) { this->parseHighlights(); } @@ -372,7 +372,7 @@ void TwitchMessageBuilder::parseHighlights() return; } - if (settings.customHighlightSound.get()) { + if (settings.customHighlightSound) { player->setMedia(QUrl(settings.pathHighlightSound.get())); } else { player->setMedia(QUrl("qrc:/sounds/ping2.wav")); @@ -397,9 +397,9 @@ void TwitchMessageBuilder::parseHighlights() // TODO: This vector should only be rebuilt upon highlights being changed std::vector activeHighlights; - if (settings.enableHighlightsSelf.get() && currentUsername.size() > 0) { - activeHighlights.emplace_back(currentUsername, settings.enableHighlightSound.get(), - settings.enableHighlightTaskbar.get()); + if (settings.enableHighlightsSelf && currentUsername.size() > 0) { + activeHighlights.emplace_back(currentUsername, settings.enableHighlightSound, + settings.enableHighlightTaskbar); } const auto &highlightProperties = settings.highlightProperties.get(); diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 0af4f1e78..8b37ed30c 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -22,7 +22,7 @@ NotebookTab::NotebookTab(Notebook *_notebook) this->positionChangedAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic)); - this->hideXConnection = SettingsManager::getInstance().hideTabX.valueChanged.connect( + this->hideXConnection = SettingsManager::getInstance().hideTabX.getValueChangedSignal().connect( boost::bind(&NotebookTab::hideTabXChanged, this, _1)); this->setMouseTracking(true); @@ -62,14 +62,15 @@ NotebookTab::NotebookTab(Notebook *_notebook) NotebookTab::~NotebookTab() { - this->hideXConnection.disconnect(); + SettingsManager::getInstance().hideTabX.getValueChangedSignal().disconnect( + this->hideXConnection); } void NotebookTab::calcSize() { float scale = getDpiMultiplier(); - if (SettingsManager::getInstance().hideTabX.get()) { + if (SettingsManager::getInstance().hideTabX) { this->resize(static_cast((fontMetrics().width(title) + 16) * scale), static_cast(24 * scale)); } else { @@ -184,12 +185,12 @@ void NotebookTab::paintEvent(QPaintEvent *) painter.setPen(fg); float scale = this->getDpiMultiplier(); - int rectW = (SettingsManager::getInstance().hideTabX.get() ? 0 : static_cast(16) * scale); + int rectW = (SettingsManager::getInstance().hideTabX ? 0 : static_cast(16) * scale); QRect rect(0, 0, this->width() - rectW, this->height()); painter.drawText(rect, title, QTextOption(Qt::AlignCenter)); - if (!SettingsManager::getInstance().hideTabX.get() && (mouseOver || selected)) { + if (!SettingsManager::getInstance().hideTabX && (mouseOver || selected)) { QRect xRect = this->getXRect(); if (mouseOverX) { painter.fillRect(xRect, QColor(0, 0, 0, 64)); @@ -231,7 +232,7 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event) this->notebook->removePage(this->page); } } else { - if (!SettingsManager::getInstance().hideTabX.get() && this->mouseDownX && + if (!SettingsManager::getInstance().hideTabX && this->mouseDownX && this->getXRect().contains(event->pos())) { this->mouseDownX = false; @@ -264,7 +265,7 @@ void NotebookTab::dragEnterEvent(QDragEnterEvent *) void NotebookTab::mouseMoveEvent(QMouseEvent *event) { - if (!SettingsManager::getInstance().hideTabX.get()) { + if (!SettingsManager::getInstance().hideTabX) { bool overX = this->getXRect().contains(event->pos()); if (overX != this->mouseOverX) { diff --git a/src/widgets/helper/notebooktab.hpp b/src/widgets/helper/notebooktab.hpp index b70b43aa2..ce189460b 100644 --- a/src/widgets/helper/notebooktab.hpp +++ b/src/widgets/helper/notebooktab.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace chatterino { @@ -57,7 +58,7 @@ protected: void mouseMoveEvent(QMouseEvent *event) override; private: - boost::signals2::connection hideXConnection; + pajlada::Signals::Signal::Connection hideXConnection; QPropertyAnimation positionChangedAnimation; bool positionChangedAnimationRunning = false; diff --git a/src/widgets/helper/splitinput.cpp b/src/widgets/helper/splitinput.cpp index 78da3b6ee..d80d05df4 100644 --- a/src/widgets/helper/splitinput.cpp +++ b/src/widgets/helper/splitinput.cpp @@ -67,7 +67,7 @@ SplitInput::SplitInput(Split *_chatWidget, EmoteManager &emoteManager, WindowMan connect(&textInput, &ResizingTextEdit::textChanged, this, &SplitInput::editTextChanged); this->refreshTheme(); - textLengthLabel.setHidden(!SettingsManager::getInstance().showMessageLength.get()); + textLengthLabel.setHidden(!SettingsManager::getInstance().showMessageLength); auto completer = new QCompleter( this->chatWidget->completionManager.createModel(this->chatWidget->channelName)); @@ -181,7 +181,7 @@ SplitInput::SplitInput(Split *_chatWidget, EmoteManager &emoteManager, WindowMan }); this->textLengthVisibleChangedConnection = - SettingsManager::getInstance().showMessageLength.valueChanged.connect( + SettingsManager::getInstance().showMessageLength.getValueChangedSignal().connect( [this](const bool &value) { this->textLengthLabel.setHidden(!value); }); QObject::connect(&this->textInput, &QTextEdit::copyAvailable, [this](bool available) { @@ -193,7 +193,8 @@ SplitInput::SplitInput(Split *_chatWidget, EmoteManager &emoteManager, WindowMan SplitInput::~SplitInput() { - this->textLengthVisibleChangedConnection.disconnect(); + SettingsManager::getInstance().showMessageLength.getValueChangedSignal().disconnect( + this->textLengthVisibleChangedConnection); } void SplitInput::clearSelection() diff --git a/src/widgets/helper/splitinput.hpp b/src/widgets/helper/splitinput.hpp index 7a5a70e01..278f2e4da 100644 --- a/src/widgets/helper/splitinput.hpp +++ b/src/widgets/helper/splitinput.hpp @@ -43,7 +43,7 @@ private: EmoteManager &emoteManager; WindowManager &windowManager; - boost::signals2::connection textLengthVisibleChangedConnection; + pajlada::Signals::Signal::Connection textLengthVisibleChangedConnection; QHBoxLayout hbox; QVBoxLayout vbox; QHBoxLayout editContainer; diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index aa068787d..fc220adf0 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -37,9 +37,9 @@ Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showBu this->userButton.move(24, 0); this->userButton.icon = NotebookButton::IconUser; - SettingsManager::getInstance().hidePreferencesButton.valueChanged.connect( + SettingsManager::getInstance().hidePreferencesButton.getValueChangedSignal().connect( [this](const bool &) { this->performLayout(); }); - SettingsManager::getInstance().hideUserButton.valueChanged.connect( + SettingsManager::getInstance().hideUserButton.getValueChangedSignal().connect( [this](const bool &) { this->performLayout(); }); } @@ -167,13 +167,13 @@ void Notebook::performLayout(bool animated) int x = 0, y = 0; float scale = this->getDpiMultiplier(); - if (!showButtons || SettingsManager::getInstance().hidePreferencesButton.get()) { + if (!showButtons || SettingsManager::getInstance().hidePreferencesButton) { this->settingsButton.hide(); } else { this->settingsButton.show(); x += settingsButton.width(); } - if (!showButtons || SettingsManager::getInstance().hideUserButton.get()) { + if (!showButtons || SettingsManager::getInstance().hideUserButton) { this->userButton.hide(); } else { this->userButton.move(x, 0); diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 75e234b67..997d312ad 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -371,7 +371,7 @@ QVBoxLayout *SettingsDialog::createEmotesTab() layout->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes)); layout->addWidget(createCheckbox("Enable BetterTTV Emotes", settings.enableBttvEmotes)); layout->addWidget(createCheckbox("Enable FrankerFaceZ Emotes", settings.enableFfzEmotes)); - layout->addWidget(createCheckbox("Enable Gif Emotes", settings.enableGifs)); + layout->addWidget(createCheckbox("Enable Gif Emotes", settings.enableGifAnimations)); layout->addWidget(createCheckbox("Enable Emojis", settings.enableEmojis)); layout->addWidget(createCheckbox("Enable Twitch Emotes", settings.enableTwitchEmotes));