#include "client.h"
+#include "abstractmessageprocessor.h"
#include "bufferinfo.h"
#include "buffermodel.h"
#include "buffersettings.h"
_bufferViewManager(0),
_ircListHelper(new ClientIrcListHelper(this)),
_messageModel(0),
+ _messageProcessor(0),
_connectedToCore(false),
_syncedToCore(false)
{
_monitorBuffer = new Buffer(BufferInfo(), this);
_signalProxy->synchronize(_ircListHelper);
-
+
connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)),
this, SLOT(receiveBacklog(BufferId, const QVariantList &)));
}
_bufferModel = new BufferModel(_networkModel);
_messageModel = mainUi->createMessageModel(this);
+ _messageProcessor = mainUi->createMessageProcessor(this);
SignalProxy *p = signalProxy();
connect(this, SIGNAL(connected()), mainUi, SLOT(connectedToCore()));
connect(this, SIGNAL(disconnected()), mainUi, SLOT(disconnectedFromCore()));
- layoutTimer = new QTimer(this);
- layoutTimer->setInterval(0);
- layoutTimer->setSingleShot(false);
- connect(layoutTimer, SIGNAL(timeout()), this, SLOT(layoutMsg()));
-
}
/*** public static methods ***/
_bufferViewManager = 0;
}
+ _messageModel->clear();
_networkModel->clear();
QHash<BufferId, Buffer *>::iterator bufferIter = _buffers.begin();
}
Q_ASSERT(_identities.isEmpty());
- layoutQueue.clear();
- layoutTimer->stop();
}
void Client::setCoreConfiguration(const QVariantMap &settings) {
}
}
-void Client::recvMessage(const Message &msg_) {
- Message msg = msg_;
- checkForHighlight(msg);
- _messageModel->insertMessage(msg);
-}
-
+// Hmm... we never used this...
void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) {
//recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg)));
}
+void Client::recvMessage(const Message &msg_) {
+ Message msg = msg_;
+ messageProcessor()->process(msg);
+}
+
void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) {
//QTime start = QTime::currentTime();
+ QList<Message> msglist;
foreach(QVariant v, msgs) {
- Message msg = v.value<Message>();
- checkForHighlight(msg);
- _messageModel->insertMessage(msg);
+ msglist << v.value<Message>();
}
+ messageProcessor()->process(msglist);
//qDebug() << "processed" << msgs.count() << "backlog lines in" << start.msecsTo(QTime::currentTime());
}
-void Client::layoutMsg() {
- if(layoutQueue.isEmpty()) {
- layoutTimer->stop();
- return;
- }
-
- Buffer *buffer = layoutQueue.takeFirst();
- if(buffer->layoutMsg()) {
- layoutQueue.append(buffer); // Buffer has more messages in its queue --> Round Robin
- return;
- }
-
- if(layoutQueue.isEmpty())
- layoutTimer->stop();
-}
-
-AbstractUiMsg *Client::layoutMsg(const Message &msg) {
- return instance()->mainUi->layoutMsg(msg);
-}
-
-// TODO optimize checkForHighlight
-void Client::checkForHighlight(Message &msg) {
- if(!((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self)))
- return;
-
- NotificationSettings notificationSettings;
- const Network *net = network(msg.bufferInfo().networkId());
- if(net && !net->myNick().isEmpty()) {
- QStringList nickList;
- if(notificationSettings.highlightNick() == NotificationSettings::CurrentNick) {
- nickList << net->myNick();
- } else if(notificationSettings.highlightNick() == NotificationSettings::AllNicks) {
- const Identity *myIdentity = identity(net->identity());
- if(myIdentity)
- nickList = myIdentity->nicks();
- }
- foreach(QString nickname, nickList) {
- QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$");
- if(nickRegExp.exactMatch(msg.contents())) {
- msg.setFlags(msg.flags() | Message::Highlight);
- return;
- }
- }
-
- foreach(QVariant highlight, notificationSettings.highlightList()) {
- QVariantMap highlightRule = highlight.toMap();
- if(!highlightRule["enable"].toBool())
- continue;
- Qt::CaseSensitivity caseSensitivity = highlightRule["cs"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive;
- QString name = highlightRule["name"].toString();
- QRegExp userRegExp;
- if(highlightRule["regex"].toBool()) {
- userRegExp = QRegExp(name, caseSensitivity);
- } else {
- userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$", caseSensitivity);
- }
- if(userRegExp.exactMatch(msg.contents())) {
- msg.setFlags(msg.flags() | Message::Highlight);
- return;
- }
- }
- }
-}
-
void Client::updateLastSeenMsg(BufferId id, const MsgId &msgId) {
Buffer *b = buffer(id);
if(!b) {
Buffer *buff = 0;
if(_buffers.contains(bufferId)) {
buff = _buffers.take(bufferId);
- layoutQueue.removeAll(buff);
disconnect(buff, 0, this, 0);
}