Move highlight phrases to new settings system
Add a setting serialize/deserializer for QString Add constructor to ChatterinoSetting that doesn't take a default value
This commit is contained in:
@@ -8,6 +8,12 @@ template <typename Type>
|
||||
class ChatterinoSetting : public pajlada::Settings::Setting<Type>
|
||||
{
|
||||
public:
|
||||
ChatterinoSetting(const std::string &_path)
|
||||
: pajlada::Settings::Setting<Type>(_path)
|
||||
{
|
||||
_registerSetting(this->data);
|
||||
}
|
||||
|
||||
ChatterinoSetting(const std::string &_path, const Type &_defaultValue)
|
||||
: pajlada::Settings::Setting<Type>(_path, _defaultValue)
|
||||
{
|
||||
|
||||
@@ -22,8 +22,6 @@ SettingManager::SettingManager()
|
||||
, preferredQuality("/behaviour/streamlink/quality", "Choose")
|
||||
, emoteScale(this->settingsItems, "emoteScale", 1.0)
|
||||
, pathHighlightSound(this->settingsItems, "pathHighlightSound", "qrc:/sounds/ping2.wav")
|
||||
, highlightProperties(this->settingsItems, "highlightProperties",
|
||||
QMap<QString, QPair<bool, bool>>())
|
||||
, highlightUserBlacklist(this->settingsItems, "highlightUserBlacklist", "")
|
||||
, snapshot(nullptr)
|
||||
, settings(Path::getAppdataPath() + "settings.ini", QSettings::IniFormat)
|
||||
@@ -40,49 +38,6 @@ SettingManager::SettingManager()
|
||||
};
|
||||
}
|
||||
|
||||
void SettingManager::save()
|
||||
{
|
||||
for (auto &item : this->settingsItems) {
|
||||
if (item.get().getName() != "highlightProperties") {
|
||||
this->settings.setValue(item.get().getName(), item.get().getVariant());
|
||||
} else {
|
||||
this->settings.beginGroup("Highlights");
|
||||
QStringList list = highlightProperties.get().keys();
|
||||
list.removeAll("");
|
||||
this->settings.remove("");
|
||||
for (auto string : list) {
|
||||
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();
|
||||
}
|
||||
this->settings.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingManager::load()
|
||||
{
|
||||
for (auto &item : this->settingsItems) {
|
||||
if (item.get().getName() != "highlightProperties") {
|
||||
item.get().setVariant(this->settings.value(item.get().getName()));
|
||||
} else {
|
||||
this->settings.beginGroup("Highlights");
|
||||
QStringList list = this->settings.childGroups();
|
||||
for (auto string : list) {
|
||||
this->settings.beginGroup(string);
|
||||
highlightProperties.insertMap(string,
|
||||
this->settings.value("highlightSound").toBool(),
|
||||
this->settings.value("highlightTask").toBool());
|
||||
this->settings.endGroup();
|
||||
}
|
||||
this->settings.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Word::Flags SettingManager::getWordTypeMask()
|
||||
{
|
||||
return this->wordTypeMask;
|
||||
@@ -98,6 +53,12 @@ QSettings &SettingManager::getQSettings()
|
||||
return this->settings;
|
||||
}
|
||||
|
||||
void SettingManager::load()
|
||||
{
|
||||
// Just to make sure the singleton is initialized
|
||||
debug::Log(".");
|
||||
}
|
||||
|
||||
void SettingManager::updateWordTypeMask()
|
||||
{
|
||||
uint32_t newMaskUint = Word::Text;
|
||||
@@ -184,5 +145,5 @@ void SettingManager::recallSnapshot()
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/highlightphrase.hpp"
|
||||
#include "messages/word.hpp"
|
||||
#include "setting.hpp"
|
||||
#include "singletons/helper/chatterinosetting.hpp"
|
||||
@@ -21,13 +22,12 @@ class SettingManager : public QObject
|
||||
using FloatSetting = ChatterinoSetting<float>;
|
||||
|
||||
public:
|
||||
void load();
|
||||
void save();
|
||||
|
||||
messages::Word::Flags getWordTypeMask();
|
||||
bool isIgnoredEmote(const QString &emote);
|
||||
QSettings &getQSettings();
|
||||
|
||||
void load();
|
||||
|
||||
/// Appearance
|
||||
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};
|
||||
BoolSetting showTimestampSeconds = {"/appearance/messages/showTimestampSeconds", true};
|
||||
@@ -73,9 +73,10 @@ public:
|
||||
pajlada::Settings::Setting<std::string> preferredQuality;
|
||||
|
||||
Setting<float> emoteScale;
|
||||
ChatterinoSetting<std::vector<messages::HighlightPhrase>> highlightProperties = {
|
||||
"/highlighting/highlights"};
|
||||
|
||||
Setting<QString> pathHighlightSound;
|
||||
Setting<QMap<QString, QPair<bool, bool>>> highlightProperties;
|
||||
Setting<QString> highlightUserBlacklist;
|
||||
|
||||
BoolSetting highlightAlwaysPlaySound = {"/highlighting/alwaysPlaySound", false};
|
||||
@@ -107,5 +108,5 @@ private:
|
||||
pajlada::Settings::SettingListener wordMaskListener;
|
||||
};
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user