dccconfig.cpp
event.cpp
eventmanager.cpp
+ highlightrulemanager.cpp
identity.cpp
ignorelistmanager.cpp
internalpeer.cpp
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-2016 by the Quassel Project *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "highlightrulemanager.h"
+#include "util.h"
+
+#include <QtCore>
+#include <QDebug>
+#include <QStringList>
+
+INIT_SYNCABLE_OBJECT(HighlightRuleManager)
+HighlightRuleManager &HighlightRuleManager::operator=(const HighlightRuleManager &other)
+{
+ if (this == &other)
+ return *this;
+
+ SyncableObject::operator=(other);
+ _highlightRuleList = other._highlightRuleList;
+ return *this;
+}
+
+
+int HighlightRuleManager::indexOf(const QString &name) const
+{
+ for (int i = 0; i < _highlightRuleList.count(); i++) {
+ if (_highlightRuleList[i].name == name)
+ return i;
+ }
+ return -1;
+}
+
+
+QVariantMap HighlightRuleManager::initHighlightRuleList() const
+{
+ QVariantMap highlightRuleListMap;
+ QStringList name;
+ QVariantList isRegEx;
+ QVariantList isCaseSensitive;
+ QVariantList isActive;
+ QStringList channel;
+
+ for (int i = 0; i < _highlightRuleList.count(); i++) {
+ name << _highlightRuleList[i].name;
+ isRegEx << _highlightRuleList[i].isRegEx;
+ isCaseSensitive << _highlightRuleList[i].isCaseSensitive;
+ isActive << _highlightRuleList[i].isEnabled;
+ channel << _highlightRuleList[i].chanName;
+ }
+
+ highlightRuleListMap["name"] = name;
+ highlightRuleListMap["isRegEx"] = isRegEx;
+ highlightRuleListMap["isCaseSensitive"] = isCaseSensitive;
+ highlightRuleListMap["isEnabled"] = isActive;
+ highlightRuleListMap["channel"] = channel;
+ return highlightRuleListMap;
+}
+
+
+void HighlightRuleManager::initSetHighlightRuleList(const QVariantMap &highlightRuleList)
+{
+ QStringList name = highlightRuleList["name"].toStringList();
+ QVariantList isRegEx = highlightRuleList["isRegEx"].toList();
+ QVariantList isCaseSensitive = highlightRuleList["isCaseSensitive"].toList();
+ QVariantList isActive = highlightRuleList["isEnabled"].toList();
+ QStringList channel = highlightRuleList["channel"].toStringList();
+
+ int count = name.count();
+ if (count != isRegEx.count() || count != isCaseSensitive.count() ||
+ count != isActive.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(),
+ isActive[i].toBool(), channel[i]);
+ }
+}
+
+void HighlightRuleManager::addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isActive,
+ const QString &channel)
+{
+ if (contains(name)) {
+ return;
+ }
+
+ HighlightRule newItem = HighlightRule(name, isRegEx, isCaseSensitive, isActive, channel);
+ _highlightRuleList << newItem;
+
+ SYNC(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isActive), ARG(channel))
+}
+
+
+bool HighlightRuleManager::_match(const QString &msgContents, const QString &msgSender, Message::Type msgType, Message::Flags msgFlags, const QString &bufferName, const QString ¤tNick, const QStringList identityNicks)
+{
+ if (!((msgType & (Message::Plain | Message::Notice | Message::Action)) && !(msgFlags & Message::Self))) {
+ return false;
+ }
+
+ if (!currentNick.isEmpty()) {
+ QStringList nickList;
+ if (_highlightNick == CurrentNick) {
+ nickList << currentNick;
+ }
+ else if (_highlightNick == AllNicks) {
+ nickList = identityNicks;
+ if (!nickList.contains(currentNick))
+ nickList.prepend(currentNick);
+ }
+ foreach(QString nickname, nickList) {
+ QRegExp nickRegExp("(^|\\W)" + QRegExp::escape(nickname) + "(\\W|$)", _nicksCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+ if (nickRegExp.indexIn(stripFormatCodes(msgContents)) >= 0) {
+ return true;
+ }
+ }
+
+ for (int i = 0; i < _highlightRuleList.count(); i++) {
+ const HighlightRule &rule = _highlightRuleList.at(i);
+ if (!rule.isEnabled)
+ continue;
+
+ if (rule.chanName.size() > 0 && rule.chanName.compare(".*") != 0) {
+ if (rule.chanName.startsWith("!")) {
+ QRegExp rx(rule.chanName.mid(1), Qt::CaseInsensitive);
+ if (rx.exactMatch(bufferName))
+ continue;
+ }
+ else {
+ QRegExp rx(rule.chanName, Qt::CaseInsensitive);
+ if (!rx.exactMatch(bufferName))
+ continue;
+ }
+ }
+
+ QRegExp rx;
+ if (rule.isRegEx) {
+ rx = QRegExp(rule.name, rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+ }
+ else {
+ rx = QRegExp("(^|\\W)" + QRegExp::escape(rule.name) + "(\\W|$)", rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+ }
+ bool match = (rx.indexIn(stripFormatCodes(msgContents)) >= 0);
+ if (match) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+void HighlightRuleManager::removeHighlightRule(const QString &highlightRule)
+{
+ removeAt(indexOf(highlightRule));
+ SYNC(ARG(highlightRule))
+}
+
+
+void HighlightRuleManager::toggleHighlightRule(const QString &highlightRule)
+{
+ int idx = indexOf(highlightRule);
+ if (idx == -1)
+ return;
+ _highlightRuleList[idx].isEnabled = !_highlightRuleList[idx].isEnabled;
+ SYNC(ARG(highlightRule))
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-2016 by the Quassel Project *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef HIGHLIGHTRULELISTMANAGER_H
+#define HIGHLIGHTRULELISTMANAGER_H
+
+#include <QString>
+#include <QRegExp>
+
+#include "message.h"
+#include "syncableobject.h"
+
+class HighlightRuleManager : public SyncableObject
+{
+ SYNCABLE_OBJECT
+ Q_OBJECT
+public:
+ enum HighlightNickType {
+ NoNick = 0x00,
+ CurrentNick = 0x01,
+ AllNicks = 0x02
+ };
+
+ inline HighlightRuleManager(QObject *parent = nullptr) : SyncableObject(parent) { setAllowClientUpdates(true); }
+ HighlightRuleManager &operator=(const HighlightRuleManager &other);
+
+ struct HighlightRule {
+ QString name;
+ bool isRegEx = false;
+ bool isCaseSensitive = false;
+ bool isEnabled = true;
+ QString chanName;
+ HighlightRule() {}
+ HighlightRule(const QString &name_, bool isRegEx_, bool isCaseSensitive_,
+ bool isEnabled_, const QString &chanName_)
+ : name(name_), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_), isEnabled(isEnabled_), chanName(chanName_) {
+ }
+ bool operator!=(const HighlightRule &other)
+ {
+ return (name != other.name ||
+ isRegEx != other.isRegEx ||
+ isCaseSensitive != other.isCaseSensitive ||
+ isEnabled != other.isEnabled ||
+ chanName != other.chanName);
+ }
+ };
+ typedef QList<HighlightRule> HighlightRuleList;
+
+ int indexOf(const QString &rule) const;
+ inline bool contains(const QString &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 HighlightRule &operator[](int i) { return _highlightRuleList[i]; }
+ inline const HighlightRule &operator[](int i) const { return _highlightRuleList.at(i); }
+ inline const HighlightRuleList &highlightRuleList() const { return _highlightRuleList; }
+
+ //! Check if a message matches the HighlightRule
+ /** This method checks if a message matches the users highlight rules.
+ * \param msg The Message that should be checked
+ */
+ inline bool 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); }
+
+public slots:
+ virtual QVariantMap initHighlightRuleList() const;
+ virtual void initSetHighlightRuleList(const QVariantMap &HighlightRuleList);
+
+ //! Request removal of an ignore rule based on the rule itself.
+ /** Use this method if you want to remove a single ignore rule
+ * 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);
+
+ //! 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);
+
+ //! 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 name The rule
+ * \param isRegEx If the rule should be interpreted as a nickname, or a regex
+ * \param isCaseSensitive If the rule should be interpreted as case-sensitive
+ * \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,
+ const QString &chanName)
+ {
+ REQUEST(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(chanName))
+ }
+
+
+ virtual void addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive,
+ bool isEnabled, const QString &chanName);
+
+ virtual inline void requestSetHighlightNick(HighlightNickType highlightNick)
+ {
+ REQUEST(ARG(highlightNick))
+ }
+ inline void setHighlightNick(HighlightNickType highlightNick) { _highlightNick = highlightNick; }
+
+ virtual inline void requestSetNicksCaseSensitive(bool nicksCaseSensitive)
+ {
+ REQUEST(ARG(nicksCaseSensitive))
+ }
+ inline void setNicksCaseSensitive(bool nicksCaseSensitive) { _nicksCaseSensitive = nicksCaseSensitive; }
+
+protected:
+ void setHighlightRuleList(const QList<HighlightRule> &HighlightRuleList) { _highlightRuleList = HighlightRuleList; }
+
+ bool _match(const QString &msgContents, const QString &msgSender, Message::Type msgType, Message::Flags msgFlags, const QString &bufferName, const QString ¤tNick, const QStringList identityNicks);
+
+signals:
+ void ruleAdded(QString name, bool isRegEx, bool isCaseSensitive, bool isEnabled, QString chanName);
+
+private:
+ HighlightRuleList _highlightRuleList;
+ HighlightNickType _highlightNick = HighlightNickType::CurrentNick;
+ bool _nicksCaseSensitive = false;
+};
+
+
+#endif // HIGHLIGHTRULELISTMANAGER_H
AwayFormatTimestamp = 0x0200, /// Timestamp formatting in away (e.g. %%hh:mm%%)
Authenticators = 0x0400, /// Whether or not the core supports auth backends.
BufferActivitySync = 0x0800, /// Sync buffer activity status
+ CoreSideHighlights = 0x1000, /// Core-Side highlight configuration and matching
- NumFeatures = 0x0800
+ NumFeatures = 0x1000
};
Q_DECLARE_FLAGS(Features, Feature)
corebufferviewmanager.cpp
corecoreinfo.cpp
coredccconfig.cpp
+ corehighlightrulemanager.cpp
coreidentity.cpp
coreignorelistmanager.cpp
coreircchannel.cpp
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-2016 by the Quassel Project *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "corehighlightrulemanager.h"
+
+#include "core.h"
+#include "coresession.h"
+
+INIT_SYNCABLE_OBJECT(CoreHighlightRuleManager)
+CoreHighlightRuleManager::CoreHighlightRuleManager(CoreSession *parent)
+ : HighlightRuleManager(parent)
+{
+ CoreSession *session = qobject_cast<CoreSession*>(parent);
+ if (!session) {
+ qWarning() << "CoreHighlightRuleManager: unable to load HighlightRuleList. Parent is not a Coresession!";
+ //loadDefaults();
+ return;
+ }
+
+ initSetHighlightRuleList(Core::getUserSetting(session->user(), "HighlightRuleList").toMap());
+
+ // we store our settings whenever they change
+ connect(this, SIGNAL(updatedRemotely()), SLOT(save()));
+}
+
+void CoreHighlightRuleManager::save() const
+{
+ CoreSession *session = qobject_cast<CoreSession *>(parent());
+ if (!session) {
+ qWarning() << "CoreHighlightRuleManager: unable to save HighlightRuleList. Parent is not a Coresession!";
+ return;
+ }
+
+ Core::setUserSetting(session->user(), "HighlightRuleList", initHighlightRuleList());
+}
+
+bool CoreHighlightRuleManager::match(const RawMessage &msg, const QString ¤tNick, const QStringList &identityNicks)
+{
+ return _match(msg.text, msg.sender, msg.type, msg.flags, msg.target, currentNick, identityNicks);
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005-2016 by the Quassel Project *
+ * devel@quassel-irc.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) version 3. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef COREHIGHLIGHTRULEMANAHER_H
+#define COREHIGHLIGHTRULEMANAHER_H
+
+#include "highlightrulemanager.h"
+
+class CoreSession;
+struct RawMessage;
+
+class CoreHighlightRuleManager : public HighlightRuleManager
+{
+ SYNCABLE_OBJECT
+ Q_OBJECT
+
+public:
+ explicit CoreHighlightRuleManager(CoreSession *parent);
+
+ inline virtual const QMetaObject *syncMetaObject() const { return &HighlightRuleManager::staticMetaObject; }
+
+ 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, const QString &chanName)
+ {
+ addHighlightRule(name, isRegEx, isCaseSensitive, isEnabled, chanName);
+ }
+
+
+private slots:
+ void save() const;
+};
+
+
+#endif //COREHIGHLIGHTRULEMANAHER_H
_ircParser(new IrcParser(this)),
scriptEngine(new QScriptEngine(this)),
_processMessages(false),
- _ignoreListManager(this)
+ _ignoreListManager(this),
+ _highlightRuleManager(this)
{
SignalProxy *p = signalProxy();
p->setHeartBeatInterval(30);
p->synchronize(networkConfig());
p->synchronize(&_coreInfo);
p->synchronize(&_ignoreListManager);
+ p->synchronize(&_highlightRuleManager);
p->synchronize(transferManager());
// Restore session state
if (restoreState)
if (_ignoreListManager.match(rawMsg, networkName) == IgnoreListManager::HardStrictness)
return;
+ if (_highlightRuleManager.match(rawMsg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
+ rawMsg.flags |= Message::Flag::Highlight;
+
_messageQueue << rawMsg;
if (!_processMessages) {
_processMessages = true;
#include "protocol.h"
#include "message.h"
#include "storage.h"
+#include "corehighlightrulemanager.h"
class CoreBacklogManager;
class CoreBufferSyncer;
inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
inline CoreIgnoreListManager *ignoreListManager() { return &_ignoreListManager; }
+ inline HighlightRuleManager *highlightRuleManager() { return &_highlightRuleManager; }
inline CoreTransferManager *transferManager() const { return _transferManager; }
inline CoreDccConfig *dccConfig() const { return _dccConfig; }
QList<RawMessage> _messageQueue;
bool _processMessages;
CoreIgnoreListManager _ignoreListManager;
+ CoreHighlightRuleManager _highlightRuleManager;
};
void QtUiMessageProcessor::process(Message &msg)
{
- checkForHighlight(msg);
+ if (!Client::coreFeatures().testFlag(Quassel::Feature::CoreSideHighlights))
+ checkForHighlight(msg);
preProcess(msg);
Client::messageModel()->insertMessage(msg);
}
QList<Message>::iterator msgIter = msgs.begin();
QList<Message>::iterator msgIterEnd = msgs.end();
while (msgIter != msgIterEnd) {
- checkForHighlight(*msgIter);
+ if (!Client::coreFeatures().testFlag(Quassel::Feature::CoreSideHighlights))
+ checkForHighlight(*msgIter);
preProcess(*msgIter);
++msgIter;
}