mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
refactored HighlightController
This commit is contained in:
parent
4a5dc80bc6
commit
843e2ad994
17 changed files with 34 additions and 100 deletions
|
@ -25,7 +25,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void init(BaseSignalVector<TVectorItem> *vec)
|
||||
void initialize(BaseSignalVector<TVectorItem> *vec)
|
||||
{
|
||||
this->vector_ = vec;
|
||||
|
||||
|
@ -89,6 +89,13 @@ public:
|
|||
this->afterInit();
|
||||
}
|
||||
|
||||
SignalVectorModel<TVectorItem> *initialized(
|
||||
BaseSignalVector<TVectorItem> *vec)
|
||||
{
|
||||
this->initialize(vec);
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual ~SignalVectorModel()
|
||||
{
|
||||
for (Row &row : this->rows_)
|
||||
|
@ -272,8 +279,8 @@ public:
|
|||
int from = data->data("chatterino_row_id").toInt();
|
||||
int to = parent.row();
|
||||
|
||||
if (from < 0 || from > this->vector_->raw().size() ||
|
||||
to < 0 || to > this->vector_->raw().size())
|
||||
if (from < 0 || from > this->vector_->raw().size() || to < 0 ||
|
||||
to > this->vector_->raw().size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ AccountModel *AccountController::createModel(QObject *parent)
|
|||
{
|
||||
AccountModel *model = new AccountModel(parent);
|
||||
|
||||
model->init(&this->accounts_);
|
||||
model->initialize(&this->accounts_);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ void CommandController::save()
|
|||
CommandModel *CommandController::createModel(QObject *parent)
|
||||
{
|
||||
CommandModel *model = new CommandModel(parent);
|
||||
model->init(&this->items_);
|
||||
model->initialize(&this->items_);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
@ -245,8 +245,6 @@ QString CommandController::execCommand(const QString &textNoEmoji,
|
|||
QString text = getApp()->emotes->emojis.replaceShortCodes(textNoEmoji);
|
||||
QStringList words = text.split(' ', QString::SkipEmptyParts);
|
||||
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
if (words.length() == 0)
|
||||
{
|
||||
return text;
|
||||
|
|
|
@ -39,8 +39,6 @@ private:
|
|||
QMap<QString, Command> commandsMap_;
|
||||
int maxSpaces_ = 0;
|
||||
|
||||
std::mutex mutex_;
|
||||
|
||||
std::shared_ptr<pajlada::Settings::SettingManager> sm_;
|
||||
// Because the setting manager is not initialized until the initialize
|
||||
// function is called (and not in the constructor), we have to
|
||||
|
|
|
@ -11,9 +11,9 @@ class HighlightController;
|
|||
|
||||
class HighlightBlacklistModel : public SignalVectorModel<HighlightBlacklistUser>
|
||||
{
|
||||
public:
|
||||
explicit HighlightBlacklistModel(QObject *parent);
|
||||
|
||||
public:
|
||||
enum Column {
|
||||
Pattern = 0,
|
||||
UseRegex = 1,
|
||||
|
@ -28,8 +28,6 @@ protected:
|
|||
// turns a row in the model into a vector item
|
||||
virtual void getRowFromItem(const HighlightBlacklistUser &item,
|
||||
std::vector<QStandardItem *> &row) override;
|
||||
|
||||
friend class HighlightController;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
#include "HighlightController.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistModel.hpp"
|
||||
#include "controllers/highlights/HighlightModel.hpp"
|
||||
#include "controllers/highlights/UserHighlightModel.hpp"
|
||||
#include "widgets/dialogs/NotificationPopup.hpp"
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
HighlightController::HighlightController()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void persist(SignalVector<T> &vec, const std::string &name)
|
||||
{
|
||||
|
@ -24,7 +17,7 @@ inline void persist(SignalVector<T> &vec, const std::string &name)
|
|||
setting->setValue(vec->raw());
|
||||
});
|
||||
|
||||
// TODO
|
||||
// TODO: Delete when appropriate.
|
||||
setting.release();
|
||||
}
|
||||
|
||||
|
@ -38,65 +31,26 @@ void HighlightController::initialize(Settings &settings, Paths &paths)
|
|||
persist(this->highlightedUsers, "/highlighting/users");
|
||||
}
|
||||
|
||||
HighlightModel *HighlightController::createModel(QObject *parent)
|
||||
{
|
||||
HighlightModel *model = new HighlightModel(parent);
|
||||
model->init(&this->phrases);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
UserHighlightModel *HighlightController::createUserModel(QObject *parent)
|
||||
{
|
||||
auto *model = new UserHighlightModel(parent);
|
||||
model->init(&this->highlightedUsers);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
bool HighlightController::isHighlightedUser(const QString &username)
|
||||
{
|
||||
const auto &userItems = this->highlightedUsers;
|
||||
for (const auto &highlightedUser : userItems)
|
||||
for (const auto &highlightedUser : this->highlightedUsers)
|
||||
{
|
||||
if (highlightedUser.isMatch(username))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
HighlightBlacklistModel *HighlightController::createBlacklistModel(
|
||||
QObject *parent)
|
||||
{
|
||||
auto *model = new HighlightBlacklistModel(parent);
|
||||
model->init(&this->blacklistedUsers);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
bool HighlightController::blacklistContains(const QString &username)
|
||||
{
|
||||
for (const auto &blacklistedUser : *this->blacklistedUsers.readOnly())
|
||||
{
|
||||
if (blacklistedUser.isMatch(username))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void HighlightController::addHighlight(const MessagePtr &msg)
|
||||
{
|
||||
// static NotificationPopup popup;
|
||||
|
||||
// popup.updatePosition();
|
||||
// popup.addMessage(msg);
|
||||
// popup.show();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||
|
@ -8,36 +7,18 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
struct Message;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class UserHighlightModel;
|
||||
class HighlightModel;
|
||||
class HighlightBlacklistModel;
|
||||
|
||||
class HighlightController final : public Singleton
|
||||
{
|
||||
public:
|
||||
HighlightController();
|
||||
|
||||
virtual void initialize(Settings &settings, Paths &paths) override;
|
||||
|
||||
UnsortedSignalVector<HighlightPhrase> phrases;
|
||||
UnsortedSignalVector<HighlightBlacklistUser> blacklistedUsers;
|
||||
UnsortedSignalVector<HighlightPhrase> highlightedUsers;
|
||||
|
||||
HighlightModel *createModel(QObject *parent);
|
||||
HighlightBlacklistModel *createBlacklistModel(QObject *parent);
|
||||
UserHighlightModel *createUserModel(QObject *parent);
|
||||
|
||||
bool isHighlightedUser(const QString &username);
|
||||
bool blacklistContains(const QString &username);
|
||||
|
||||
void addHighlight(const MessagePtr &msg);
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
};
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
class HighlightController;
|
||||
|
||||
class HighlightModel : public SignalVectorModel<HighlightPhrase>
|
||||
{
|
||||
public:
|
||||
explicit HighlightModel(QObject *parent);
|
||||
|
||||
public:
|
||||
// Used here, in HighlightingPage and in UserHighlightModel
|
||||
enum Column {
|
||||
Pattern = 0,
|
||||
|
@ -40,8 +38,6 @@ protected:
|
|||
virtual void customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
int column, const QVariant &value, int role,
|
||||
int rowIndex) override;
|
||||
|
||||
friend class HighlightController;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -11,6 +11,7 @@ class HighlightController;
|
|||
|
||||
class UserHighlightModel : public SignalVectorModel<HighlightPhrase>
|
||||
{
|
||||
public:
|
||||
explicit UserHighlightModel(QObject *parent);
|
||||
|
||||
protected:
|
||||
|
@ -21,8 +22,6 @@ protected:
|
|||
|
||||
virtual void getRowFromItem(const HighlightPhrase &item,
|
||||
std::vector<QStandardItem *> &row) override;
|
||||
|
||||
friend class HighlightController;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -25,7 +25,7 @@ void IgnoreController::initialize(Settings &, Paths &)
|
|||
IgnoreModel *IgnoreController::createModel(QObject *parent)
|
||||
{
|
||||
IgnoreModel *model = new IgnoreModel(parent);
|
||||
model->init(&this->phrases);
|
||||
model->initialize(&this->phrases);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ void ModerationActions::initialize(Settings &settings, Paths &paths)
|
|||
ModerationActionModel *ModerationActions::createModel(QObject *parent)
|
||||
{
|
||||
ModerationActionModel *model = new ModerationActionModel(parent);
|
||||
model->init(&this->items);
|
||||
model->initialize(&this->items);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ NotificationModel *NotificationController::createModel(QObject *parent,
|
|||
Platform p)
|
||||
{
|
||||
NotificationModel *model = new NotificationModel(parent);
|
||||
model->init(&this->channelMap[p]);
|
||||
model->initialize(&this->channelMap[p]);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ void PingController::initialize(Settings &settings, Paths &paths)
|
|||
PingModel *PingController::createModel(QObject *parent)
|
||||
{
|
||||
PingModel *model = new PingModel(parent);
|
||||
model->init(&this->channelVector);
|
||||
model->initialize(&this->channelVector);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ TaggedUsersController::TaggedUsersController()
|
|||
TaggedUsersModel *TaggedUsersController::createModel(QObject *parent)
|
||||
{
|
||||
TaggedUsersModel *model = new TaggedUsersModel(parent);
|
||||
model->init(&this->users);
|
||||
model->initialize(&this->users);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ Irc::Irc()
|
|||
QAbstractTableModel *Irc::newConnectionModel(QObject *parent)
|
||||
{
|
||||
auto model = new Model(parent);
|
||||
model->init(&this->connections);
|
||||
model->initialize(&this->connections);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
@ -241,7 +241,6 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message,
|
|||
if (highlighted)
|
||||
{
|
||||
server.mentionsChannel->addMessage(msg);
|
||||
getApp()->highlights->addHighlight(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,12 +49,12 @@ HighlightingPage::HighlightingPage()
|
|||
"Play notification sounds and highlight messages based on "
|
||||
"certain patterns.");
|
||||
|
||||
EditableModelView *view =
|
||||
auto view =
|
||||
highlights
|
||||
.emplace<EditableModelView>(
|
||||
app->highlights->createModel(nullptr))
|
||||
(new HighlightModel(nullptr))
|
||||
->initialized(&app->highlights->phrases))
|
||||
.getElement();
|
||||
|
||||
view->addRegexHelpLink();
|
||||
view->setTitles({"Pattern", "Flash\ntaskbar", "Play\nsound",
|
||||
"Enable\nregex", "Case-\nsensitive",
|
||||
|
@ -94,7 +94,9 @@ HighlightingPage::HighlightingPage()
|
|||
EditableModelView *view =
|
||||
pingUsers
|
||||
.emplace<EditableModelView>(
|
||||
app->highlights->createUserModel(nullptr))
|
||||
(new UserHighlightModel(nullptr))
|
||||
->initialized(
|
||||
&app->highlights->highlightedUsers))
|
||||
.getElement();
|
||||
|
||||
view->addRegexHelpLink();
|
||||
|
@ -140,7 +142,9 @@ HighlightingPage::HighlightingPage()
|
|||
EditableModelView *view =
|
||||
disabledUsers
|
||||
.emplace<EditableModelView>(
|
||||
app->highlights->createBlacklistModel(nullptr))
|
||||
(new HighlightBlacklistModel(nullptr))
|
||||
->initialized(
|
||||
&app->highlights->blacklistedUsers))
|
||||
.getElement();
|
||||
|
||||
view->addRegexHelpLink();
|
||||
|
@ -205,7 +209,7 @@ HighlightingPage::HighlightingPage()
|
|||
|
||||
// ---- misc
|
||||
this->disabledUsersChangedTimer_.setSingleShot(true);
|
||||
}
|
||||
} // namespace chatterino
|
||||
|
||||
void HighlightingPage::tableCellClicked(const QModelIndex &clicked,
|
||||
EditableModelView *view)
|
||||
|
|
Loading…
Reference in a new issue