Rework to use controllers

This commit is contained in:
datguy 2018-07-04 18:59:48 +03:00
parent b54c68d746
commit 971326212c
3 changed files with 31 additions and 14 deletions

View file

@ -8,7 +8,7 @@ namespace chatterino {
// commandmodel
UserHighlightModel::UserHighlightModel(QObject *parent)
: SignalVectorModel<UserHighlight>(2, parent)
: SignalVectorModel<UserHighlight>(4, parent)
{
}
@ -18,8 +18,9 @@ UserHighlight UserHighlightModel::getItemFromRow(std::vector<QStandardItem *> &r
{
// key, regex
return UserHighlight{row[0]->data(Qt::DisplayRole).toString(),
row[1]->data(Qt::CheckStateRole).toBool()};
return UserHighlight{
row[0]->data(Qt::DisplayRole).toString(), row[1]->data(Qt::CheckStateRole).toBool(),
row[2]->data(Qt::CheckStateRole).toBool(), row[3]->data(Qt::CheckStateRole).toBool()};
}
// row into vector item
@ -27,7 +28,9 @@ void UserHighlightModel::getRowFromItem(const UserHighlight &item,
std::vector<QStandardItem *> &row)
{
setStringItem(row[0], item.getPattern());
setBoolItem(row[1], item.isRegex());
setBoolItem(row[1], item.getAlert());
setBoolItem(row[2], item.getSound());
setBoolItem(row[3], item.isRegex());
}
} // namespace chatterino

View file

@ -443,6 +443,7 @@ void TwitchMessageBuilder::parseHighlights()
// TODO: This vector should only be rebuilt upon highlights being changed
// fourtf: should be implemented in the HighlightsController
std::vector<HighlightPhrase> activeHighlights = app->highlights->phrases.getVector();
std::vector<UserHighlight> userHighlights = app->highlights->highlightedUsers.getVector();
if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) {
HighlightPhrase selfHighlight(currentUsername, app->settings->enableHighlightTaskbar,
@ -458,14 +459,9 @@ void TwitchMessageBuilder::parseHighlights()
if (!app->highlights->blacklistContains(this->ircMessage->nick())) {
for (const HighlightPhrase &highlight : activeHighlights) {
if (highlight.isMatch(this->originalMessage) ||
app->highlights->userContains(this->ircMessage->nick())) {
if (app->highlights->userContains(this->ircMessage->nick())) {
Log("Highlight because user {} sent a message", this->ircMessage->nick());
} else {
Log("Highlight because {} matches {}", this->originalMessage,
highlight.getPattern());
}
if (highlight.isMatch(this->originalMessage)) {
Log("Highlight because {} matches {}", this->originalMessage,
highlight.getPattern());
doHighlight = true;
if (highlight.getAlert()) {
@ -483,6 +479,24 @@ void TwitchMessageBuilder::parseHighlights()
}
}
}
for (const UserHighlight &userHighlight : userHighlights) {
if (userHighlight.isMatch(this->ircMessage->nick())) {
Log("Highlight because user {} sent a message", this->ircMessage->nick());
if (userHighlight.getAlert()) {
doAlert = true;
}
if (userHighlight.getSound()) {
playSound = true;
}
if (playSound && doAlert) {
// Break if no further action can be taken from other usernames
// Mostly used for regex stuff
break;
}
}
}
this->setHighlight(doHighlight);

View file

@ -96,7 +96,7 @@ HighlightingPage::HighlightingPage()
pingUsers.emplace<EditableModelView>(app->highlights->createUserModel(nullptr))
.getElement();
view->setTitles({"Username", "Regex"});
view->setTitles({"Username", "Flash taskbar", "Play sound", "Regex"});
view->getTableView()->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
view->getTableView()->horizontalHeader()->setSectionResizeMode(
0, QHeaderView::Stretch);
@ -109,7 +109,7 @@ HighlightingPage::HighlightingPage()
view->addButtonPressed.connect([] {
getApp()->highlights->highlightedUsers.appendItem(
UserHighlight{"highlighted user", false});
UserHighlight{"highlighted user", true, false, false});
});
}
}