mirror-chatterino2/src/settingsmanager.cpp

174 lines
6.7 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)
, showTimestamps("/appearance/messages/showTimestamps", true)
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
, showBadges("/appearance/messages/showBadges", true)
, streamlinkPath("/behaviour/streamlink/path", "")
, preferredQuality("/behaviour/streamlink/quality", "Choose")
2017-04-12 17:46:44 +02:00
, emoteScale(_settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0)
, scaleEmotesByLineHeight(_settingsItems, "scaleEmotesByLineHeight", false)
, 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)
2017-07-31 00:57:42 +02:00
, enableHighlightsSelf(_settingsItems, "enableHighlightsSelf", true)
2017-04-12 17:46:44 +02:00
, enableHighlightSound(_settingsItems, "enableHighlightSound", true)
, enableHighlightTaskbar(_settingsItems, "enableHighlightTaskbar", true)
, customHighlightSound(_settingsItems, "customHighlightSound", false)
, pathHighlightSound(_settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav")
2017-07-31 00:57:42 +02:00
, highlightProperties(_settingsItems, "highlightProperties", QMap<QString, QPair<bool, bool>>())
2017-04-12 17:46:44 +02:00
, 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)
{
2017-06-17 15:15:58 +02:00
this->showTimestamps.getValueChangedSignal().connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->showTimestampSeconds.getValueChangedSignal().connect(
[this](const auto &) { this->updateWordTypeMask(); });
this->showBadges.getValueChangedSignal().connect(
2017-04-12 17:46:44 +02:00
[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(); });
}
void SettingsManager::save()
{
for (auto &item : _settingsItems) {
2017-07-31 00:57:42 +02:00
if (item.get().getName() != "highlightProperties") {
_settings.setValue(item.get().getName(), item.get().getVariant());
} else {
_settings.beginGroup("Highlights");
QStringList list = highlightProperties.get().keys();
list.removeAll("");
_settings.remove("");
2017-07-31 00:57:42 +02:00
for (auto string : list) {
_settings.beginGroup(string);
2017-07-31 00:57:42 +02:00
_settings.setValue("highlightSound", highlightProperties.get().value(string).first);
_settings.setValue("highlightTask", highlightProperties.get().value(string).second);
_settings.endGroup();
}
_settings.endGroup();
}
2017-04-12 17:46:44 +02:00
}
}
void SettingsManager::load()
{
for (auto &item : _settingsItems) {
2017-07-31 00:57:42 +02:00
if (item.get().getName() != "highlightProperties") {
item.get().setVariant(_settings.value(item.get().getName()));
} else {
_settings.beginGroup("Highlights");
QStringList list = _settings.childGroups();
qDebug() << list.join(",");
2017-07-31 00:57:42 +02:00
for (auto string : list) {
_settings.beginGroup(string);
2017-07-31 00:57:42 +02:00
highlightProperties.insertMap(string, _settings.value("highlightSound").toBool(),
_settings.value("highlightTask").toBool());
_settings.endGroup();
}
_settings.endGroup();
}
2017-04-12 17:46:44 +02:00
}
}
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) {
2017-07-31 00:57:42 +02:00
if (item.get().getName() != "highlightProperties") {
snapshot.addItem(item, item.get().getVariant());
} else {
snapshot._mapItems = highlightProperties.get();
}
2017-04-12 17:46:44 +02:00
}
return snapshot;
}
2017-04-14 17:52:22 +02:00
} // namespace chatterino