damn... now it's fixed...
[quassel.git] / src / client / client.cpp
index 6e0baf3..1cd8939 100644 (file)
@@ -34,6 +34,7 @@
 #include "util.h"
 
 QPointer<Client> Client::instanceptr = 0;
+AccountId Client::_currentCoreAccount = 0;
 
 /*** Initialization/destruction ***/
 
@@ -71,7 +72,7 @@ Client::~Client() {
 }
 
 void Client::init() {
-
+  _currentCoreAccount = 0;
   _networkModel = new NetworkModel(this);
   connect(this, SIGNAL(bufferUpdated(BufferInfo)),
           _networkModel, SLOT(bufferUpdated(BufferInfo)));
@@ -80,7 +81,7 @@ void Client::init() {
 
   SignalProxy *p = signalProxy();
 
-  p->attachSlot(SIGNAL(displayMsg(const Message &)), this, SLOT(recvMessage(const Message &)));
+  p->attachSlot(SIGNAL(displayMsg(Message &)), this, SLOT(recvMessage(Message &)));
   p->attachSlot(SIGNAL(displayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
 
   p->attachSlot(SIGNAL(backlogData(BufferInfo, const QVariantList &, bool)), this, SLOT(recvBacklogData(BufferInfo, const QVariantList &, bool)));
@@ -116,6 +117,14 @@ void Client::init() {
 
 /*** public static methods ***/
 
+AccountId Client::currentCoreAccount() {
+  return _currentCoreAccount;
+}
+
+void Client::setCurrentCoreAccount(AccountId id) {
+  _currentCoreAccount = id;
+}
+
 QList<BufferInfo> Client::allBufferInfos() {
   QList<BufferInfo> bufferids;
   foreach(Buffer *buffer, buffers()) {
@@ -276,10 +285,11 @@ void Client::userInput(BufferInfo bufferInfo, QString message) {
 
 /*** core connection stuff ***/
 
-void Client::setConnectedToCore(QIODevice *sock) {
+void Client::setConnectedToCore(QIODevice *sock, AccountId id) {
   socket = sock;
   signalProxy()->addPeer(socket);
   _connectedToCore = true;
+  setCurrentCoreAccount(id);
 }
 
 void Client::setSyncedToCore() {
@@ -295,6 +305,7 @@ void Client::disconnectFromCore() {
   }
   _connectedToCore = false;
   _syncedToCore = false;
+  setCurrentCoreAccount(0);
   emit disconnected();
   emit coreConnectionStateChanged(false);
 
@@ -368,14 +379,29 @@ void Client::networkDestroyed() {
   }
 }
 
-void Client::recvMessage(const Message &msg) {
-  Buffer *b = buffer(msg.bufferInfo());
+void Client::recvMessage(Message &msg) {
+  Buffer *b;
+  
+  if(msg.type() == Message::Error) {
+    b = buffer(msg.bufferInfo().bufferId());
+    if(!b) {
+      // FIXME: if buffer doesn't exist, forward the message to the status or current buffer
+      b = buffer(msg.bufferInfo());
+    }
+  } else {
+    b = buffer(msg.bufferInfo());
+  }
+  
+  checkForHighlight(msg);
   b->appendMsg(msg);
   networkModel()->updateBufferActivity(msg);
-
+  
   if(msg.type() == Message::Plain || msg.type() == Message::Notice || msg.type() == Message::Action) {
-    // FIXME: fetch networkName();
-    QString sender = ":" + msg.bufferInfo().bufferName() + ":" + msg.sender();
+    const Network *net = network(msg.bufferInfo().networkId());
+    QString networkName = net != 0
+      ? net->networkName() + ":"
+      : QString();
+    QString sender = networkName + msg.bufferInfo().bufferName() + ":" + msg.sender();
     Message mmsg = Message(msg.timestamp(), msg.bufferInfo(), msg.type(), msg.text(), sender, msg.flags());
     monitorBuffer()->appendMsg(mmsg);
   }
@@ -390,8 +416,9 @@ void Client::recvBacklogData(BufferInfo id, QVariantList msgs, bool /*done*/) {
   Buffer *b = buffer(id);
   foreach(QVariant v, msgs) {
     Message msg = v.value<Message>();
+    checkForHighlight(msg);
     b->prependMsg(msg);
-    // networkModel()->updateBufferActivity(msg);
+    networkModel()->updateBufferActivity(msg);
     if(!layoutQueue.contains(b)) layoutQueue.append(b);
   }
   if(layoutQueue.count() && !layoutTimer->isActive()) layoutTimer->start();
@@ -412,3 +439,11 @@ AbstractUiMsg *Client::layoutMsg(const Message &msg) {
   return instance()->mainUi->layoutMsg(msg);
 }
 
+void Client::checkForHighlight(Message &msg) const {
+  const Network *net = network(msg.bufferInfo().networkId());
+  if(net && !net->myNick().isEmpty()) {
+    QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(net->myNick()) + "(\\W.*)?$");
+    if((msg.type() == Message::Plain || msg.type() == Message::Notice || msg.type() == Message::Action) && nickRegExp.exactMatch(msg.text()))
+      msg.setFlags(msg.flags() | Message::Highlight);
+  }
+}