#include <QDebug>
INIT_SYNCABLE_OBJECT(HighlightRuleManager)
-HighlightRuleManager &HighlightRuleManager::operator=(const HighlightRuleManager &other)
-{
+HighlightRuleManager &HighlightRuleManager::operator=(const HighlightRuleManager &other) {
if (this == &other)
return *this;
}
-int HighlightRuleManager::indexOf(const QString &name) const
-{
+int HighlightRuleManager::indexOf(int id) const {
for (int i = 0; i < _highlightRuleList.count(); i++) {
- if (_highlightRuleList[i].name == name)
+ if (_highlightRuleList[i].id == id)
return i;
}
return -1;
}
+int HighlightRuleManager::nextId() {
+ int max = 0;
+ for (int i = 0; i < _highlightRuleList.count(); i++) {
+ int id = _highlightRuleList[i].id;
+ if (id > max) {
+ max = id;
+ }
+ }
+ return max+1;
+}
-QVariantMap HighlightRuleManager::initHighlightRuleList() const
-{
+
+QVariantMap HighlightRuleManager::initHighlightRuleList() const {
+ QVariantList id;
QVariantMap highlightRuleListMap;
QStringList name;
QVariantList isRegEx;
QStringList channel;
for (int i = 0; i < _highlightRuleList.count(); i++) {
+ id << _highlightRuleList[i].id;
name << _highlightRuleList[i].name;
isRegEx << _highlightRuleList[i].isRegEx;
isCaseSensitive << _highlightRuleList[i].isCaseSensitive;
channel << _highlightRuleList[i].chanName;
}
+ highlightRuleListMap["id"] = id;
highlightRuleListMap["name"] = name;
highlightRuleListMap["isRegEx"] = isRegEx;
highlightRuleListMap["isCaseSensitive"] = isCaseSensitive;
highlightRuleListMap["isInverse"] = isInverse;
highlightRuleListMap["sender"] = sender;
highlightRuleListMap["channel"] = channel;
- highlightRuleListMap["highlightNick"] = _highlightNick;
- highlightRuleListMap["nicksCaseSensitive"] = _nicksCaseSensitive;
return highlightRuleListMap;
}
-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();
QVariantList isCaseSensitive = highlightRuleList["isCaseSensitive"].toList();
QStringList sender = highlightRuleList["sender"].toStringList();
QStringList channel = highlightRuleList["channel"].toStringList();
- int count = name.count();
- if (count != isRegEx.count() || count != isCaseSensitive.count() || count != isActive.count() ||
- count != isInverse.count() || count != sender.count() || count != channel.count()) {
+ int count = id.count();
+ if (count != name.count() || count != isRegEx.count() || count != isCaseSensitive.count() ||
+ count != isActive.count() || count != isInverse.count() || count != sender.count() ||
+ count != channel.count()) {
qWarning() << "Corrupted HighlightRuleList settings! (Count mismatch)";
return;
}
_highlightRuleList.clear();
for (int i = 0; i < name.count(); i++) {
- _highlightRuleList << HighlightRule(name[i], isRegEx[i].toBool(), isCaseSensitive[i].toBool(),
+ _highlightRuleList << HighlightRule(id[i].toInt(), name[i], isRegEx[i].toBool(), isCaseSensitive[i].toBool(),
isActive[i].toBool(), isInverse[i].toBool(), sender[i], channel[i]);
}
-
- // Make sure the default for _highlightNick is "CurrentNick" if not set
- _highlightNick = HighlightNickType(
- highlightRuleList.value("highlightNick", HighlightNickType::CurrentNick).toInt());
-
- _nicksCaseSensitive = highlightRuleList["nicksCaseSensitive"].toBool();
}
-void HighlightRuleManager::addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isActive,
- bool isInverse, const QString &sender, const QString &channel)
-{
- if (contains(name)) {
+void HighlightRuleManager::addHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive,
+ bool isActive, bool isInverse, const QString &sender,
+ const QString &channel) {
+ if (contains(id)) {
return;
}
- HighlightRule newItem = HighlightRule(name, isRegEx, isCaseSensitive, isActive, isInverse, sender, channel);
+ HighlightRule newItem = HighlightRule(id, name, isRegEx, isCaseSensitive, isActive, isInverse, sender, channel);
_highlightRuleList << newItem;
- SYNC(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isActive), ARG(isInverse), ARG(sender), ARG(channel))
+ SYNC(ARG(id), ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isActive), ARG(isInverse), ARG(sender),
+ ARG(channel))
}
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(const QString &highlightRule)
-{
+void HighlightRuleManager::removeHighlightRule(int highlightRule) {
removeAt(indexOf(highlightRule));
SYNC(ARG(highlightRule))
}
-void HighlightRuleManager::toggleHighlightRule(const QString &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);
}
class HighlightRuleManager : public SyncableObject
{
SYNCABLE_OBJECT
- Q_OBJECT
+ Q_OBJECT
+
+ Q_PROPERTY(int highlightNick READ highlightNick WRITE setHighlightNick)
+ Q_PROPERTY(bool nicksCaseSensitive READ nicksCaseSensitive WRITE setNicksCaseSensitive)
public:
enum HighlightNickType {
NoNick = 0x00,
HighlightRuleManager &operator=(const HighlightRuleManager &other);
struct HighlightRule {
+ int id;
QString name;
bool isRegEx = false;
bool isCaseSensitive = false;
QString sender;
QString chanName;
HighlightRule() {}
- HighlightRule(QString name_, bool isRegEx_, bool isCaseSensitive_, bool isEnabled_, bool isInverse_,
+ HighlightRule(int id_, QString name_, bool isRegEx_, bool isCaseSensitive_, bool isEnabled_, bool isInverse_,
QString sender_, QString chanName_)
- : name(std::move(name_)), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_), isEnabled(isEnabled_),
- isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_)) {
+ : id(id_), name(std::move(name_)), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_),
+ isEnabled(isEnabled_), isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_)) {
}
- bool operator!=(const HighlightRule &other)
- {
- return (name != other.name ||
+
+ bool operator!=(const HighlightRule &other) {
+ return (id != other.id ||
+ name != other.name ||
isRegEx != other.isRegEx ||
isCaseSensitive != other.isCaseSensitive ||
isEnabled != other.isEnabled ||
};
typedef QList<HighlightRule> HighlightRuleList;
- int indexOf(const QString &rule) const;
- inline bool contains(const QString &rule) const { return indexOf(rule) != -1; }
+ int indexOf(int rule) const;
+ inline bool contains(int rule) const { return indexOf(rule) != -1; }
inline bool isEmpty() const { return _highlightRuleList.isEmpty(); }
inline int count() const { return _highlightRuleList.count(); }
inline void removeAt(int index) { _highlightRuleList.removeAt(index); }
inline const HighlightRule &operator[](int i) const { return _highlightRuleList.at(i); }
inline const HighlightRuleList &highlightRuleList() const { return _highlightRuleList; }
- inline HighlightNickType highlightNick() { return _highlightNick; }
+ int nextId();
+
+ inline int highlightNick() { return _highlightNick; }
inline bool nicksCaseSensitive() { return _nicksCaseSensitive; }
//! Check if a message matches the HighlightRule
* and get that synced with the core immediately.
* \param highlightRule A valid ignore rule
*/
- virtual inline void requestRemoveHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
- virtual void removeHighlightRule(const QString &highlightRule);
+ virtual inline void requestRemoveHighlightRule(int highlightRule) { REQUEST(ARG(highlightRule)) }
+ virtual void removeHighlightRule(int highlightRule);
//! Request toggling of "isEnabled" flag of a given ignore rule.
/** Use this method if you want to toggle the "isEnabled" flag of a single ignore rule
* and get that synced with the core immediately.
* \param highlightRule A valid ignore rule
*/
- virtual inline void requestToggleHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
- virtual void toggleHighlightRule(const QString &highlightRule);
+ virtual inline void requestToggleHighlightRule(int highlightRule) { REQUEST(ARG(highlightRule)) }
+ virtual void toggleHighlightRule(int highlightRule);
//! Request an HighlightRule to be added to the ignore list
/** Items added to the list with this method, get immediately synced with the core
* \param isEnabled If the rule is active
* @param chanName The channel in which the rule should apply
*/
- virtual inline void requestAddHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
+ virtual inline void requestAddHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
bool isInverse, const QString &sender, const QString &chanName)
{
- REQUEST(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(isInverse), ARG(sender), ARG(chanName))
+ REQUEST(ARG(id), ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(isInverse), ARG(sender),
+ ARG(chanName))
}
- virtual void addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
+ virtual void addHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
bool isInverse, const QString &sender, const QString &chanName);
virtual inline void requestSetHighlightNick(int highlightNick)
bool match(const RawMessage &msg, const QString ¤tNick, const QStringList &identityNicks);
public slots:
- virtual inline void requestToggleHighlightRule(const QString &highlightRule) { toggleHighlightRule(highlightRule); }
- virtual inline void requestRemoveHighlightRule(const QString &highlightRule) { removeHighlightRule(highlightRule); }
- virtual inline void requestAddHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
- bool isInverse, const QString &sender, const QString &chanName)
- {
- addHighlightRule(name, isRegEx, isCaseSensitive, isEnabled, isInverse, sender, chanName);
+ 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,
+ bool isEnabled, bool isInverse, const QString &sender,
+ const QString &chanName) {
+ addHighlightRule(id, name, isRegEx, isCaseSensitive, isEnabled, isInverse, sender, chanName);
}
widgetHasChanged();
}
-void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, const QString &name, bool regex, bool cs,
+void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QString &name, bool regex, bool cs,
const QString &sender, const QString &chanName, bool self)
{
ui.highlightTable->setRowCount(ui.highlightTable->rowCount() + 1);
+ if (id < 0) {
+ id = nextId();
+ }
+
auto *nameItem = new QTableWidgetItem(name);
auto *regexItem = new QTableWidgetItem("");
if (!self)
ui.highlightTable->setCurrentItem(nameItem);
- highlightList << HighlightRuleManager::HighlightRule(name, regex, cs, enable, false, sender, chanName);
+ highlightList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, false, sender, chanName);
}
-void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, const QString &name, bool regex, bool cs,
+void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QString &name, bool regex, bool cs,
const QString &sender, const QString &chanName, bool self)
{
ui.ignoredTable->setRowCount(ui.ignoredTable->rowCount() + 1);
+ if (id < 0) {
+ id = nextId();
+ }
+
auto *nameItem = new QTableWidgetItem(name);
auto *regexItem = new QTableWidgetItem("");
if (!self)
ui.ignoredTable->setCurrentItem(nameItem);
- ignoredList << HighlightRuleManager::HighlightRule(name, regex, cs, enable, true, sender, chanName);
+ ignoredList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, true, sender, chanName);
}
void CoreHighlightSettingsPage::removeSelectedHighlightRows()
for (auto &rule : ruleManager->highlightRuleList()) {
if (rule.isInverse) {
addNewIgnoredRow(rule.isEnabled,
+ rule.id,
rule.name,
rule.isRegEx,
rule.isCaseSensitive,
rule.chanName);
}
else {
- addNewHighlightRow(rule.isEnabled, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.sender,
+ addNewHighlightRow(rule.isEnabled, rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.sender,
rule.chanName);
}
}
clonedManager.clear();
for (auto &rule : highlightList) {
- clonedManager.addHighlightRule(rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, false,
+ clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, false,
rule.sender, rule.chanName);
}
for (auto &rule : ignoredList) {
- clonedManager.addHighlightRule(rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, true,
+ clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, true,
rule.sender, rule.chanName);
}
load();
}
+int CoreHighlightSettingsPage::nextId() {
+ int max = 0;
+ for (int i = 0; i < highlightList.count(); i++) {
+ int id = highlightList[i].id;
+ if (id > max) {
+ max = id;
+ }
+ }
+ for (int i = 0; i < ignoredList.count(); i++) {
+ int id = ignoredList[i].id;
+ if (id > max) {
+ max = id;
+ }
+ }
+ return max+1;
+}
+
void CoreHighlightSettingsPage::widgetHasChanged()
{
setChangedState(true);
auto highlightRule = variant.toMap();
clonedManager.addHighlightRule(
+ clonedManager.nextId(),
highlightRule["Name"].toString(),
highlightRule["RegEx"].toBool(),
highlightRule["CS"].toBool(),
private slots:
void coreConnectionStateChanged(bool state);
void widgetHasChanged();
- void addNewHighlightRow(bool enable = true, const QString &name = tr("highlight rule"), bool regex = false,
+ void addNewHighlightRow(bool enable = true, int id = -1, const QString &name = tr("highlight rule"), bool regex = false,
bool cs = false, const QString &sender = "", const QString &chanName = "",
bool self = false);
- void addNewIgnoredRow(bool enable = true, const QString &name = tr("highlight rule"), bool regex = false,
+ void addNewIgnoredRow(bool enable = true, int id = -1, const QString &name = tr("highlight rule"), bool regex = false,
bool cs = false, const QString &sender = "", const QString &chanName = "", bool self = false);
void removeSelectedHighlightRows();
void removeSelectedIgnoredRows();
- void highlightNicksChanged(const int index);
+ void highlightNicksChanged(int index);
void selectHighlightRow(QTableWidgetItem *item);
void selectIgnoredRow(QTableWidgetItem *item);
void highlightTableChanged(QTableWidgetItem *item);
*/
void updateCoreSupportStatus(bool state);
+ int nextId();
+
bool _initialized;
};