some more refactoring

This commit is contained in:
fourtf
2020-02-23 17:45:59 +01:00
parent e1838154ff
commit 4a5dc80bc6
12 changed files with 62 additions and 75 deletions
@@ -16,7 +16,7 @@ AccountController::AccountController()
this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
if (args.caller != this)
{
auto &accs = this->twitch.accounts.getVector();
auto &accs = this->twitch.accounts.raw();
auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end());
@@ -212,7 +212,7 @@ void CommandController::initialize(Settings &, Paths &paths)
// Update the setting when the vector of commands has been updated (most
// likely from the settings dialog)
this->items_.delayedItemsChanged.connect([this] { //
this->commandsSetting_->setValue(this->items_.getVector());
this->commandsSetting_->setValue(this->items_.raw());
});
// Load commands from commands.json
@@ -12,38 +12,30 @@ HighlightController::HighlightController()
{
}
template <typename T>
inline void persist(SignalVector<T> &vec, const std::string &name)
{
auto setting = std::make_unique<ChatterinoSetting<std::vector<T>>>(name);
for (auto &&item : setting->getValue())
vec.append(item);
vec.delayedItemsChanged.connect([setting = setting.get(), vec = &vec] {
setting->setValue(vec->raw());
});
// TODO
setting.release();
}
void HighlightController::initialize(Settings &settings, Paths &paths)
{
assert(!this->initialized_);
this->initialized_ = true;
for (const HighlightPhrase &phrase : this->highlightsSetting_.getValue())
{
this->phrases.appendItem(phrase);
}
this->phrases.delayedItemsChanged.connect([this] { //
this->highlightsSetting_.setValue(this->phrases.getVector());
});
for (const HighlightBlacklistUser &blacklistedUser :
this->blacklistSetting_.getValue())
{
this->blacklistedUsers.appendItem(blacklistedUser);
}
this->blacklistedUsers.delayedItemsChanged.connect([this] {
this->blacklistSetting_.setValue(this->blacklistedUsers.getVector());
});
for (const HighlightPhrase &user : this->userSetting_.getValue())
{
this->highlightedUsers.appendItem(user);
}
this->highlightedUsers.delayedItemsChanged.connect([this] { //
this->userSetting_.setValue(this->highlightedUsers.getVector());
});
persist(this->phrases, "/highlighting/highlights");
persist(this->blacklistedUsers, "/highlighting/blacklist");
persist(this->highlightedUsers, "/highlighting/users");
}
HighlightModel *HighlightController::createModel(QObject *parent)
@@ -40,13 +40,6 @@ public:
private:
bool initialized_ = false;
ChatterinoSetting<std::vector<HighlightPhrase>> highlightsSetting_ = {
"/highlighting/highlights"};
ChatterinoSetting<std::vector<HighlightBlacklistUser>> blacklistSetting_ = {
"/highlighting/blacklist"};
ChatterinoSetting<std::vector<HighlightPhrase>> userSetting_ = {
"/highlighting/users"};
};
} // namespace chatterino
+1 -1
View File
@@ -18,7 +18,7 @@ void IgnoreController::initialize(Settings &, Paths &)
}
this->phrases.delayedItemsChanged.connect([this] { //
this->ignoresSetting_.setValue(this->phrases.getVector());
this->ignoresSetting_.setValue(this->phrases.raw());
});
}
@@ -27,7 +27,7 @@ void ModerationActions::initialize(Settings &settings, Paths &paths)
}
this->items.delayedItemsChanged.connect([this] { //
this->setting_->setValue(this->items.getVector());
this->setting_->setValue(this->items.raw());
});
}
@@ -31,7 +31,7 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] { //
this->twitchSetting_.setValue(
this->channelMap[Platform::Twitch].getVector());
this->channelMap[Platform::Twitch].raw());
});
/*
for (const QString &channelName : this->mixerSetting_.getValue()) {
@@ -88,9 +88,9 @@ void NotificationController::removeChannelNotification(
const QString &channelName, Platform p)
{
for (std::vector<int>::size_type i = 0;
i != channelMap[p].getVector().size(); i++)
i != channelMap[p].raw().size(); i++)
{
if (channelMap[p].getVector()[i].toLower() == channelName.toLower())
if (channelMap[p].raw()[i].toLower() == channelName.toLower())
{
channelMap[p].removeItem(i);
i--;
@@ -128,14 +128,14 @@ NotificationModel *NotificationController::createModel(QObject *parent,
void NotificationController::fetchFakeChannels()
{
for (std::vector<int>::size_type i = 0;
i != channelMap[Platform::Twitch].getVector().size(); i++)
i != channelMap[Platform::Twitch].raw().size(); i++)
{
auto chan = getApp()->twitch.server->getChannelOrEmpty(
channelMap[Platform::Twitch].getVector()[i]);
channelMap[Platform::Twitch].raw()[i]);
if (chan->isEmpty())
{
getFakeTwitchChannelLiveStatus(
channelMap[Platform::Twitch].getVector()[i]);
channelMap[Platform::Twitch].raw()[i]);
}
}
}
+3 -3
View File
@@ -12,7 +12,7 @@ void PingController::initialize(Settings &settings, Paths &paths)
}
this->channelVector.delayedItemsChanged.connect([this] { //
this->pingSetting_.setValue(this->channelVector.getVector());
this->pingSetting_.setValue(this->channelVector.raw());
});
}
@@ -43,9 +43,9 @@ void PingController::muteChannel(const QString &channelName)
void PingController::unmuteChannel(const QString &channelName)
{
for (std::vector<int>::size_type i = 0;
i != channelVector.getVector().size(); i++)
i != channelVector.raw().size(); i++)
{
if (channelVector.getVector()[i].toLower() == channelName.toLower())
if (channelVector.raw()[i].toLower() == channelName.toLower())
{
channelVector.removeItem(i);
i--;