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()
|
2017-09-21 12:15:01 +02:00
|
|
|
: settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat)
|
2017-06-26 16:41:20 +02:00
|
|
|
, showTimestamps("/appearance/messages/showTimestamps", true)
|
|
|
|
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
|
|
|
|
, showBadges("/appearance/messages/showBadges", true)
|
2017-09-11 23:35:59 +02:00
|
|
|
, streamlinkPath("/behaviour/streamlink/path", "")
|
|
|
|
, preferredQuality("/behaviour/streamlink/quality", "Choose")
|
2017-09-21 12:15:01 +02:00
|
|
|
, 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<QString, QPair<bool, bool>>())
|
2017-09-23 19:23:10 +02:00
|
|
|
, highlightUserBlacklist(this->settingsItems, "highlightUserBlacklist", "")
|
2017-10-08 15:58:28 +02:00
|
|
|
, highlightAlwaysPlaySound("/highlighting/alwaysPlaySound", false)
|
2017-09-21 12:15:01 +02:00
|
|
|
, 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)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
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()
|
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
for (auto &item : this->settingsItems) {
|
2017-07-31 00:57:42 +02:00
|
|
|
if (item.get().getName() != "highlightProperties") {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.setValue(item.get().getName(), item.get().getVariant());
|
2017-07-31 00:37:22 +02:00
|
|
|
} else {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.beginGroup("Highlights");
|
2017-07-31 00:37:22 +02:00
|
|
|
QStringList list = highlightProperties.get().keys();
|
|
|
|
list.removeAll("");
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.remove("");
|
2017-07-31 00:57:42 +02:00
|
|
|
for (auto string : list) {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.beginGroup(string);
|
|
|
|
this->settings.setValue("highlightSound",
|
|
|
|
highlightProperties.get().value(string).first);
|
|
|
|
this->settings.setValue("highlightTask",
|
|
|
|
highlightProperties.get().value(string).second);
|
|
|
|
this->settings.endGroup();
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.endGroup();
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsManager::load()
|
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
for (auto &item : this->settingsItems) {
|
2017-07-31 00:57:42 +02:00
|
|
|
if (item.get().getName() != "highlightProperties") {
|
2017-09-21 12:15:01 +02:00
|
|
|
item.get().setVariant(this->settings.value(item.get().getName()));
|
2017-07-31 00:37:22 +02:00
|
|
|
} else {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.beginGroup("Highlights");
|
|
|
|
QStringList list = this->settings.childGroups();
|
2017-07-31 00:37:22 +02:00
|
|
|
qDebug() << list.join(",");
|
2017-07-31 00:57:42 +02:00
|
|
|
for (auto string : list) {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.beginGroup(string);
|
|
|
|
highlightProperties.insertMap(string,
|
|
|
|
this->settings.value("highlightSound").toBool(),
|
|
|
|
this->settings.value("highlightTask").toBool());
|
|
|
|
this->settings.endGroup();
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2017-09-21 12:15:01 +02:00
|
|
|
this->settings.endGroup();
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Word::Type SettingsManager::getWordTypeMask()
|
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
return this->wordTypeMask;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsManager::isIgnoredEmote(const QString &)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSettings &SettingsManager::getQSettings()
|
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
return this->settings;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsManager::updateWordTypeMask()
|
|
|
|
{
|
2017-06-11 20:53:43 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-06-11 20:53:43 +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;
|
2017-06-11 20:53:43 +02:00
|
|
|
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
|
|
|
|
2017-06-11 20:53:43 +02:00
|
|
|
if (this->showBadges) {
|
|
|
|
newMaskUint |= Word::Badges;
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-06-11 20:53:43 +02:00
|
|
|
newMaskUint |= Word::Username;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
newMaskUint |= Word::AlwaysShow;
|
|
|
|
|
2017-06-11 20:53:43 +02:00
|
|
|
Word::Type newMask = static_cast<Word::Type>(newMaskUint);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
if (newMask != this->wordTypeMask) {
|
|
|
|
this->wordTypeMask = newMask;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
emit wordTypeMaskChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsSnapshot SettingsManager::createSnapshot()
|
|
|
|
{
|
|
|
|
SettingsSnapshot snapshot;
|
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
for (auto &item : this->settingsItems) {
|
2017-07-31 00:57:42 +02:00
|
|
|
if (item.get().getName() != "highlightProperties") {
|
|
|
|
snapshot.addItem(item, item.get().getVariant());
|
2017-07-31 00:37:22 +02:00
|
|
|
} else {
|
2017-09-21 12:15:01 +02:00
|
|
|
snapshot.mapItems = highlightProperties.get();
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|