diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index 4fe39eddf..31129769b 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -25,7 +25,7 @@ public: } } - void init(BaseSignalVector *vec) + void initialize(BaseSignalVector *vec) { this->vector_ = vec; @@ -89,6 +89,13 @@ public: this->afterInit(); } + SignalVectorModel *initialized( + BaseSignalVector *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; } diff --git a/src/controllers/accounts/AccountController.cpp b/src/controllers/accounts/AccountController.cpp index db65e9440..6d272cf0c 100644 --- a/src/controllers/accounts/AccountController.cpp +++ b/src/controllers/accounts/AccountController.cpp @@ -50,7 +50,7 @@ AccountModel *AccountController::createModel(QObject *parent) { AccountModel *model = new AccountModel(parent); - model->init(&this->accounts_); + model->initialize(&this->accounts_); return model; } diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 75464bbb7..418612be7 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -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 lock(this->mutex_); - if (words.length() == 0) { return text; diff --git a/src/controllers/commands/CommandController.hpp b/src/controllers/commands/CommandController.hpp index 938fe0f39..5435a60b9 100644 --- a/src/controllers/commands/CommandController.hpp +++ b/src/controllers/commands/CommandController.hpp @@ -39,8 +39,6 @@ private: QMap commandsMap_; int maxSpaces_ = 0; - std::mutex mutex_; - std::shared_ptr sm_; // Because the setting manager is not initialized until the initialize // function is called (and not in the constructor), we have to diff --git a/src/controllers/highlights/HighlightBlacklistModel.hpp b/src/controllers/highlights/HighlightBlacklistModel.hpp index c3420b066..d4acc474d 100644 --- a/src/controllers/highlights/HighlightBlacklistModel.hpp +++ b/src/controllers/highlights/HighlightBlacklistModel.hpp @@ -11,9 +11,9 @@ class HighlightController; class HighlightBlacklistModel : public SignalVectorModel { +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 &row) override; - - friend class HighlightController; }; } // namespace chatterino diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 60df26ff1..f341f3495 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -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 inline void persist(SignalVector &vec, const std::string &name) { @@ -24,7 +17,7 @@ inline void persist(SignalVector &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 diff --git a/src/controllers/highlights/HighlightController.hpp b/src/controllers/highlights/HighlightController.hpp index 2f61b1a49..5f746c8bf 100644 --- a/src/controllers/highlights/HighlightController.hpp +++ b/src/controllers/highlights/HighlightController.hpp @@ -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; - -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 phrases; UnsortedSignalVector blacklistedUsers; UnsortedSignalVector 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; }; diff --git a/src/controllers/highlights/HighlightModel.hpp b/src/controllers/highlights/HighlightModel.hpp index 13b85bca1..aa37b4ffe 100644 --- a/src/controllers/highlights/HighlightModel.hpp +++ b/src/controllers/highlights/HighlightModel.hpp @@ -7,13 +7,11 @@ namespace chatterino { -class HighlightController; - class HighlightModel : public SignalVectorModel { +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 &row, int column, const QVariant &value, int role, int rowIndex) override; - - friend class HighlightController; }; } // namespace chatterino diff --git a/src/controllers/highlights/UserHighlightModel.hpp b/src/controllers/highlights/UserHighlightModel.hpp index dcc42a950..de4332433 100644 --- a/src/controllers/highlights/UserHighlightModel.hpp +++ b/src/controllers/highlights/UserHighlightModel.hpp @@ -11,6 +11,7 @@ class HighlightController; class UserHighlightModel : public SignalVectorModel { +public: explicit UserHighlightModel(QObject *parent); protected: @@ -21,8 +22,6 @@ protected: virtual void getRowFromItem(const HighlightPhrase &item, std::vector &row) override; - - friend class HighlightController; }; } // namespace chatterino diff --git a/src/controllers/ignores/IgnoreController.cpp b/src/controllers/ignores/IgnoreController.cpp index b1028be0a..28b511a36 100644 --- a/src/controllers/ignores/IgnoreController.cpp +++ b/src/controllers/ignores/IgnoreController.cpp @@ -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; } diff --git a/src/controllers/moderationactions/ModerationActions.cpp b/src/controllers/moderationactions/ModerationActions.cpp index cb68174be..d13a71eab 100644 --- a/src/controllers/moderationactions/ModerationActions.cpp +++ b/src/controllers/moderationactions/ModerationActions.cpp @@ -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; } diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index ec2f231c6..59fed3b1f 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -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; } diff --git a/src/controllers/pings/PingController.cpp b/src/controllers/pings/PingController.cpp index 67bd3ad66..36f4b08ad 100644 --- a/src/controllers/pings/PingController.cpp +++ b/src/controllers/pings/PingController.cpp @@ -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; } diff --git a/src/controllers/taggedusers/TaggedUsersController.cpp b/src/controllers/taggedusers/TaggedUsersController.cpp index 2aa82a6c3..095bd779d 100644 --- a/src/controllers/taggedusers/TaggedUsersController.cpp +++ b/src/controllers/taggedusers/TaggedUsersController.cpp @@ -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; } diff --git a/src/providers/irc/Irc2.cpp b/src/providers/irc/Irc2.cpp index 0a8f2ed60..ee59e94ce 100644 --- a/src/providers/irc/Irc2.cpp +++ b/src/providers/irc/Irc2.cpp @@ -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; } diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 7a456ecaf..5b022bc1e 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -241,7 +241,6 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message, if (highlighted) { server.mentionsChannel->addMessage(msg); - getApp()->highlights->addHighlight(msg); } } diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index 2612454be..9b8d1af94 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -49,12 +49,12 @@ HighlightingPage::HighlightingPage() "Play notification sounds and highlight messages based on " "certain patterns."); - EditableModelView *view = + auto view = highlights .emplace( - 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( - app->highlights->createUserModel(nullptr)) + (new UserHighlightModel(nullptr)) + ->initialized( + &app->highlights->highlightedUsers)) .getElement(); view->addRegexHelpLink(); @@ -140,7 +142,9 @@ HighlightingPage::HighlightingPage() EditableModelView *view = disabledUsers .emplace( - 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)