Fix formatting and const-correctness.
#include "highlightrulemanager.h"
-#include "util.h"
-
#include <QDebug>
+#include "util.h"
+
INIT_SYNCABLE_OBJECT(HighlightRuleManager)
-HighlightRuleManager &HighlightRuleManager::operator=(const HighlightRuleManager &other) {
+
+HighlightRuleManager &HighlightRuleManager::operator=(const HighlightRuleManager &other)
+{
if (this == &other)
return *this;
}
-int HighlightRuleManager::indexOf(int id) const {
+int HighlightRuleManager::indexOf(int id) const
+{
for (int i = 0; i < _highlightRuleList.count(); i++) {
if (_highlightRuleList[i].id == id)
return i;
return -1;
}
-int HighlightRuleManager::nextId() {
+
+int HighlightRuleManager::nextId()
+{
int max = 0;
for (int i = 0; i < _highlightRuleList.count(); i++) {
int id = _highlightRuleList[i].id;
max = id;
}
}
- return max+1;
+ return max + 1;
}
-QVariantMap HighlightRuleManager::initHighlightRuleList() const {
+QVariantMap HighlightRuleManager::initHighlightRuleList() const
+{
QVariantList id;
QVariantMap highlightRuleListMap;
QStringList name;
}
-void HighlightRuleManager::initSetHighlightRuleList(const QVariantMap &highlightRuleList) {
+void HighlightRuleManager::initSetHighlightRuleList(const QVariantMap &highlightRuleList)
+{
QVariantList id = highlightRuleList["id"].toList();
QStringList name = highlightRuleList["name"].toStringList();
QVariantList isRegEx = highlightRuleList["isRegEx"].toList();
}
}
+
void HighlightRuleManager::addHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive,
bool isActive, bool isInverse, const QString &sender,
- const QString &channel) {
+ const QString &channel)
+{
if (contains(id)) {
return;
}
Message::Flags msgFlags,
const QString &bufferName,
const QString ¤tNick,
- const QStringList identityNicks) {
+ const QStringList identityNicks)
+{
if (!((msgType & (Message::Plain | Message::Notice | Message::Action)) && !(msgFlags & Message::Self))) {
return false;
}
return false;
}
-void HighlightRuleManager::removeHighlightRule(int highlightRule) {
+
+void HighlightRuleManager::removeHighlightRule(int highlightRule)
+{
removeAt(indexOf(highlightRule));
SYNC(ARG(highlightRule))
}
-void HighlightRuleManager::toggleHighlightRule(int highlightRule) {
+void HighlightRuleManager::toggleHighlightRule(int highlightRule)
+{
int idx = indexOf(highlightRule);
if (idx == -1)
return;
SYNC(ARG(highlightRule))
}
-bool HighlightRuleManager::match(const Message &msg, const QString ¤tNick, const QStringList &identityNicks) {
+
+bool HighlightRuleManager::match(const Message &msg, const QString ¤tNick, const QStringList &identityNicks)
+{
return match(msg.contents(), msg.sender(), msg.type(), msg.flags(), msg.bufferInfo().bufferName(), currentNick, identityNicks);
}
Q_PROPERTY(int highlightNick READ highlightNick WRITE setHighlightNick)
Q_PROPERTY(bool nicksCaseSensitive READ nicksCaseSensitive WRITE setNicksCaseSensitive)
+
public:
enum HighlightNickType {
NoNick = 0x00,
inline HighlightRuleManager(QObject *parent = nullptr) : SyncableObject(parent) { setAllowClientUpdates(true); }
HighlightRuleManager &operator=(const HighlightRuleManager &other);
- struct HighlightRule {
+ struct HighlightRule
+ {
int id;
QString name;
bool isRegEx = false;
HighlightRule(int id_, QString name_, bool isRegEx_, bool isCaseSensitive_, bool isEnabled_, bool isInverse_,
QString sender_, QString chanName_)
: id(id_), name(std::move(name_)), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_),
- isEnabled(isEnabled_), isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_)) {
- }
+ isEnabled(isEnabled_), isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_))
+ {}
- bool operator!=(const HighlightRule &other) {
+ bool operator!=(const HighlightRule &other) const
+ {
return (id != other.id ||
name != other.name ||
isRegEx != other.isRegEx ||
chanName != other.chanName);
}
};
- typedef QList<HighlightRule> HighlightRuleList;
+
+ using HighlightRuleList = QList<HighlightRule>;
int indexOf(int rule) const;
inline bool contains(int rule) const { return indexOf(rule) != -1; }
{
REQUEST(ARG(highlightNick))
}
+
inline void setHighlightNick(int highlightNick) { _highlightNick = static_cast<HighlightNickType>(highlightNick); }
virtual inline void requestSetNicksCaseSensitive(bool nicksCaseSensitive)
{
REQUEST(ARG(nicksCaseSensitive))
}
+
inline void setNicksCaseSensitive(bool nicksCaseSensitive) { _nicksCaseSensitive = nicksCaseSensitive; }
protected:
public:
explicit CoreHighlightRuleManager(CoreSession *parent);
- inline virtual const QMetaObject *syncMetaObject() const { return &HighlightRuleManager::staticMetaObject; }
+ virtual const QMetaObject *syncMetaObject() const override { return &HighlightRuleManager::staticMetaObject; }
bool match(const RawMessage &msg, const QString ¤tNick, const QStringList &identityNicks);
public slots:
- virtual inline void requestToggleHighlightRule(int highlightRule) { toggleHighlightRule(highlightRule); }
- virtual inline void requestRemoveHighlightRule(int highlightRule) { removeHighlightRule(highlightRule); }
- virtual inline void requestAddHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive,
+ inline void requestToggleHighlightRule(int highlightRule) override { toggleHighlightRule(highlightRule); }
+ inline void requestRemoveHighlightRule(int highlightRule) override { removeHighlightRule(highlightRule); }
+ inline void requestAddHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive,
bool isEnabled, bool isInverse, const QString &sender,
- const QString &chanName) {
+ const QString &chanName) override
+ {
addHighlightRule(id, name, isRegEx, isCaseSensitive, isEnabled, isInverse, sender, chanName);
}
-
private slots:
void save() const;
};
}
}
+
void CoreHighlightSettingsPage::coreConnectionStateChanged(bool state)
{
updateCoreSupportStatus(state);
}
}
+
void CoreHighlightSettingsPage::setupRuleTable(QTableWidget *table) const
{
table->verticalHeader()->hide();
#endif
}
+
void CoreHighlightSettingsPage::updateCoreSupportStatus(bool state)
{
// Assume connected state as enforced by the settings page UI
}
}
+
void CoreHighlightSettingsPage::clientConnected()
{
connect(Client::highlightRuleManager(), SIGNAL(updated()), SLOT(revert()));
}
+
void CoreHighlightSettingsPage::revert()
{
if (!hasChanged())
load();
}
+
bool CoreHighlightSettingsPage::hasDefaults() const
{
return true;
}
+
void CoreHighlightSettingsPage::defaults()
{
int highlightNickType = HighlightRuleManager::HighlightNickType::CurrentNick;
widgetHasChanged();
}
+
void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QString &name, bool regex, bool cs,
const QString &sender, const QString &chanName, bool self)
{
highlightList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, false, sender, chanName);
}
+
void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QString &name, bool regex, bool cs,
const QString &sender, const QString &chanName, bool self)
{
ignoredList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, true, sender, chanName);
}
+
void CoreHighlightSettingsPage::removeSelectedHighlightRows()
{
QList<int> selectedRows;
}
}
+
void CoreHighlightSettingsPage::removeSelectedIgnoredRows()
{
QList<int> selectedRows;
}
}
-void CoreHighlightSettingsPage::highlightNicksChanged(const int index) {
+
+void CoreHighlightSettingsPage::highlightNicksChanged(const int index)
+{
// Only allow toggling "Case sensitive" when a nickname will be highlighted
auto highlightNickType = ui.highlightNicksComboBox->itemData(index).value<int>();
ui.nicksCaseSensitive->setEnabled(highlightNickType != HighlightRuleManager::NoNick);
}
+
void CoreHighlightSettingsPage::selectHighlightRow(QTableWidgetItem *item)
{
int row = item->row();
selected);
}
+
void CoreHighlightSettingsPage::selectIgnoredRow(QTableWidgetItem *item)
{
int row = item->row();
selected);
}
+
void CoreHighlightSettingsPage::emptyHighlightTable()
{
// ui.highlight and highlightList should have the same size, but just to make sure.
highlightList.clear();
}
+
void CoreHighlightSettingsPage::emptyIgnoredTable()
{
// ui.highlight and highlightList should have the same size, but just to make sure.
ignoredList.clear();
}
+
void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item)
{
if (item->row() + 1 > highlightList.size())
emit widgetHasChanged();
}
+
void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item)
{
if (item->row() + 1 > ignoredList.size())
emit widgetHasChanged();
}
+
void CoreHighlightSettingsPage::load()
{
emptyHighlightTable();
}
}
+
void CoreHighlightSettingsPage::save()
{
if (!hasChanged())
load();
}
-int CoreHighlightSettingsPage::nextId() {
+
+int CoreHighlightSettingsPage::nextId()
+{
int max = 0;
for (int i = 0; i < highlightList.count(); i++) {
int id = highlightList[i].id;
max = id;
}
}
- return max+1;
+ return max + 1;
}
+
void CoreHighlightSettingsPage::widgetHasChanged()
{
setChangedState(true);
}
+
void CoreHighlightSettingsPage::on_coreUnsupportedDetails_clicked()
{
// Re-use translations of "Local Highlights" as this is a word-for-word reference, forcing all
remoteHighlightsMsgText);
}
-void CoreHighlightSettingsPage::importRules() {
+
+void CoreHighlightSettingsPage::importRules()
+{
NotificationSettings notificationSettings;
const auto localHighlightList = notificationSettings.highlightList();
).arg(QString::number(localHighlightList.count())));
}
-bool CoreHighlightSettingsPage::isSelectable() const {
+
+bool CoreHighlightSettingsPage::isSelectable() const
+{
return Client::isConnected();
// We check for Quassel::Feature::CoreSideHighlights when loading this page, allowing us to show
// a friendly error message.