refactored HighlightController

This commit is contained in:
fourtf
2020-02-23 19:31:43 +01:00
parent 4a5dc80bc6
commit 843e2ad994
17 changed files with 34 additions and 100 deletions
@@ -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