mirror-chatterino2/src/settingsmanager.cpp

139 lines
5 KiB
C++
Raw Normal View History

2017-06-11 09:31:45 +02:00
#include "settingsmanager.hpp"
#include "appdatapath.hpp"
2017-04-12 17:46:44 +02:00
#include <QDebug>
#include <QDir>
#include <QStandardPaths>
2017-04-14 17:52:22 +02:00
using namespace chatterino::messages;
2017-04-12 17:46:44 +02:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
2017-04-12 17:46:44 +02:00
SettingsManager::SettingsManager()
: _settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat)
2017-04-12 17:46:44 +02:00
, theme(_settingsItems, "theme", "dark")
, themeHue(_settingsItems, "themeHue", 0)
, selectedUser(_settingsItems, "selectedUser", "")
, emoteScale(_settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0)
, scaleEmotesByLineHeight(_settingsItems, "scaleEmotesByLineHeight", false)
, showTimestamps("/appearance/messages/showTimestamps", true)
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
, showBadges("/appearance/messages/showBadges", true)
2017-04-12 17:46:44 +02:00
, showLastMessageIndicator(_settingsItems, "showLastMessageIndicator", false)
, allowDouplicateMessages(_settingsItems, "allowDouplicateMessages", true)
, linksDoubleClickOnly(_settingsItems, "linksDoubleClickOnly", false)
, hideEmptyInput(_settingsItems, "hideEmptyInput", false)
, showMessageLength(_settingsItems, "showMessageLength", false)
, seperateMessages(_settingsItems, "seperateMessages", false)
, mentionUsersWithAt(_settingsItems, "mentionUsersWithAt", false)
, allowCommandsAtEnd(_settingsItems, "allowCommandsAtEnd", false)
, enableHighlights(_settingsItems, "enableHighlights", true)
, enableHighlightSound(_settingsItems, "enableHighlightSound", true)
, enableHighlightTaskbar(_settingsItems, "enableHighlightTaskbar", true)
, customHighlightSound(_settingsItems, "customHighlightSound", false)
, enableTwitchEmotes(_settingsItems, "enableTwitchEmotes", true)
, enableBttvEmotes(_settingsItems, "enableBttvEmotes", true)
, enableFfzEmotes(_settingsItems, "enableFfzEmotes", true)
, enableEmojis(_settingsItems, "enableEmojis", true)
, enableGifAnimations(_settingsItems, "enableGifAnimations", true)
, enableGifs(_settingsItems, "enableGifs", true)
, inlineWhispers(_settingsItems, "inlineWhispers", true)
, windowTopMost(_settingsItems, "windowTopMost", false)
, hideTabX(_settingsItems, "hideTabX", false)
, hidePreferencesButton(_settingsItems, "hidePreferencesButton", false)
, hideUserButton(_settingsItems, "hideUserButton", false)
, useCustomWindowFrame(_settingsItems, "useCustomWindowFrame", true)
{
this->showTimestamps.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); });
this->showTimestampSeconds.valueChanged.connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->showBadges.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); });
2017-04-12 17:46:44 +02:00
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(); });
}
void SettingsManager::save()
{
for (auto &item : _settingsItems) {
_settings.setValue(item.get().getName(), item.get().getVariant());
}
}
void SettingsManager::load()
{
for (auto &item : _settingsItems) {
item.get().setVariant(_settings.value(item.get().getName()));
}
}
Word::Type SettingsManager::getWordTypeMask()
{
return _wordTypeMask;
}
bool SettingsManager::isIgnoredEmote(const QString &)
{
return false;
}
QSettings &SettingsManager::getQSettings()
{
return _settings;
}
void SettingsManager::updateWordTypeMask()
{
uint32_t newMaskUint = Word::Text;
if (this->showTimestamps) {
if (this->showTimestampSeconds) {
newMaskUint |= Word::TimestampWithSeconds;
} else {
newMaskUint |= Word::TimestampNoSeconds;
}
2017-04-12 17:46:44 +02:00
}
newMaskUint |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage : Word::TwitchEmoteText;
newMaskUint |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText;
newMaskUint |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText;
newMaskUint |=
2017-04-12 17:46:44 +02:00
(enableBttvEmotes.get() && enableGifs.get()) ? Word::BttvEmoteImage : Word::BttvEmoteText;
newMaskUint |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText;
newMaskUint |= Word::BitsAmount;
newMaskUint |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic;
2017-04-12 17:46:44 +02:00
if (this->showBadges) {
newMaskUint |= Word::Badges;
}
2017-04-12 17:46:44 +02:00
newMaskUint |= Word::Username;
2017-04-12 17:46:44 +02:00
Word::Type newMask = static_cast<Word::Type>(newMaskUint);
2017-04-12 17:46:44 +02:00
if (newMask != _wordTypeMask) {
_wordTypeMask = newMask;
2017-04-12 17:46:44 +02:00
emit wordTypeMaskChanged();
}
}
SettingsSnapshot SettingsManager::createSnapshot()
{
SettingsSnapshot snapshot;
for (auto &item : this->_settingsItems) {
snapshot.addItem(item, item.get().getVariant());
}
return snapshot;
}
2017-04-14 17:52:22 +02:00
} // namespace chatterino