Rework to use controllers

This commit is contained in:
datguy 2018-07-04 15:38:16 +03:00
parent 4ea613503e
commit b54c68d746
6 changed files with 94 additions and 3 deletions

View file

@ -113,6 +113,7 @@ SOURCES += \
src/controllers/highlights/HighlightController.cpp \
src/controllers/highlights/HighlightModel.cpp \
src/controllers/highlights/HighlightBlacklistModel.cpp \
src/controllers/highlights/UserHighlightModel.cpp \
src/controllers/ignores/IgnoreController.cpp \
src/controllers/ignores/IgnoreModel.cpp \
src/controllers/taggedusers/TaggedUser.cpp \
@ -258,6 +259,8 @@ HEADERS += \
src/controllers/highlights/HighlightBlacklistModel.hpp \
src/controllers/highlights/HighlightPhrase.hpp \
src/controllers/highlights/HighlightBlacklistUser.hpp \
src/controllers/highlights/UserHighlightModel.hpp \
src/controllers/highlights/UserHighlight.hpp \
src/controllers/ignores/IgnoreController.hpp \
src/controllers/ignores/IgnoreModel.hpp \
src/controllers/ignores/IgnorePhrase.hpp \

View file

@ -3,6 +3,7 @@
#include "Application.hpp"
#include "controllers/highlights/HighlightBlacklistModel.hpp"
#include "controllers/highlights/HighlightModel.hpp"
#include "controllers/highlights/UserHighlightModel.hpp"
#include "widgets/dialogs/NotificationPopup.hpp"
namespace chatterino {
@ -33,6 +34,26 @@ HighlightModel *HighlightController::createModel(QObject *parent)
return model;
}
UserHighlightModel *HighlightController::createUserModel(QObject *parent)
{
auto *model = new UserHighlightModel(parent);
model->init(&this->highlightedUsers);
return model;
}
bool HighlightController::userContains(const QString &username)
{
std::vector<UserHighlight> userItems = this->highlightedUsers.getVector();
for (const auto &highlightedUser : userItems) {
if (highlightedUser.isMatch(username)) {
return true;
}
}
return false;
}
HighlightBlacklistModel *HighlightController::createBlacklistModel(QObject *parent)
{
auto *model = new HighlightBlacklistModel(parent);

View file

@ -3,11 +3,13 @@
#include "common/SignalVector.hpp"
#include "controllers/highlights/HighlightBlacklistUser.hpp"
#include "controllers/highlights/HighlightPhrase.hpp"
#include "controllers/highlights/UserHighlight.hpp"
#include "messages/Message.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {
class UserHighlightModel;
class HighlightModel;
class HighlightBlacklistModel;
@ -20,10 +22,13 @@ public:
UnsortedSignalVector<HighlightPhrase> phrases;
UnsortedSignalVector<HighlightBlacklistUser> blacklistedUsers;
UnsortedSignalVector<UserHighlight> highlightedUsers;
HighlightModel *createModel(QObject *parent);
HighlightBlacklistModel *createBlacklistModel(QObject *parent);
UserHighlightModel *createUserModel(QObject *parent);
bool userContains(const QString &username);
bool blacklistContains(const QString &username);
void addHighlight(const MessagePtr &msg);

View file

@ -0,0 +1,33 @@
#include "UserHighlightModel.hpp"
#include "Application.hpp"
#include "singletons/Settings.hpp"
#include "util/StandardItemHelper.hpp"
namespace chatterino {
// commandmodel
UserHighlightModel::UserHighlightModel(QObject *parent)
: SignalVectorModel<UserHighlight>(2, parent)
{
}
// turn vector item into model row
UserHighlight UserHighlightModel::getItemFromRow(std::vector<QStandardItem *> &row,
const UserHighlight &original)
{
// key, regex
return UserHighlight{row[0]->data(Qt::DisplayRole).toString(),
row[1]->data(Qt::CheckStateRole).toBool()};
}
// row into vector item
void UserHighlightModel::getRowFromItem(const UserHighlight &item,
std::vector<QStandardItem *> &row)
{
setStringItem(row[0], item.getPattern());
setBoolItem(row[1], item.isRegex());
}
} // namespace chatterino

View file

@ -458,9 +458,14 @@ void TwitchMessageBuilder::parseHighlights()
if (!app->highlights->blacklistContains(this->ircMessage->nick())) {
for (const HighlightPhrase &highlight : activeHighlights) {
if (highlight.isMatch(this->originalMessage)) {
Log("Highlight because {} matches {}", this->originalMessage,
highlight.getPattern());
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());
}
doHighlight = true;
if (highlight.getAlert()) {

View file

@ -4,6 +4,7 @@
#include "controllers/highlights/HighlightBlacklistModel.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "controllers/highlights/HighlightModel.hpp"
#include "controllers/highlights/UserHighlightModel.hpp"
#include "debug/Log.hpp"
#include "singletons/Settings.hpp"
#include "util/LayoutCreator.hpp"
@ -88,6 +89,29 @@ HighlightingPage::HighlightingPage()
HighlightBlacklistUser{"blacklisted user", false});
});
}
auto pingUsers = tabs.appendTab(new QVBoxLayout, "Highlight on message");
{
EditableModelView *view =
pingUsers.emplace<EditableModelView>(app->highlights->createUserModel(nullptr))
.getElement();
view->setTitles({"Username", "Regex"});
view->getTableView()->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
view->getTableView()->horizontalHeader()->setSectionResizeMode(
0, QHeaderView::Stretch);
// fourtf: make class extrend BaseWidget and add this to dpiChanged
QTimer::singleShot(1, [view] {
view->getTableView()->resizeColumnsToContents();
view->getTableView()->setColumnWidth(0, 200);
});
view->addButtonPressed.connect([] {
getApp()->highlights->highlightedUsers.appendItem(
UserHighlight{"highlighted user", false});
});
}
}
// MISC