Introduce QtUiStyleSettings and make highlight color configurable again
[quassel.git] / src / uisupport / abstractbuffercontainer.cpp
index 78ead27..a12b031 100644 (file)
 #include "client.h"
 #include "networkmodel.h"
 
-AbstractBufferContainer::AbstractBufferContainer(QWidget *parent) : AbstractItemView(parent), _currentBuffer(0)
+AbstractBufferContainer::AbstractBufferContainer(QWidget *parent)
+  : AbstractItemView(parent),
+    _currentBuffer(0)
 {
-
 }
 
 AbstractBufferContainer::~AbstractBufferContainer() {
-
 }
 
 
@@ -42,13 +42,10 @@ void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, in
     if(model()->rowCount(parent) != end - start + 1)
       return;
 
-    AbstractChatView *chatView;
-    QHash<BufferId, AbstractChatView *>::iterator iter = _chatViews.begin();
-    while(iter != _chatViews.end()) {
-      chatView = *iter;
-      iter = _chatViews.erase(iter);
-      removeChatView(chatView);
+    foreach(BufferId id, _chatViews.keys()) {
+      removeChatView(id);
     }
+    _chatViews.clear();
   } else {
     // check if there are explicitly buffers removed
     for(int i = start; i <= end; i++) {
@@ -63,74 +60,44 @@ void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, in
 }
 
 void AbstractBufferContainer::removeBuffer(BufferId bufferId) {
+  if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
   if(!_chatViews.contains(bufferId))
     return;
 
-  if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
-  AbstractChatView *chatView = _chatViews.take(bufferId);
-  removeChatView(chatView);
+  removeChatView(bufferId);
+  _chatViews.take(bufferId);
 }
 
 void AbstractBufferContainer::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
   BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
   BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
-  if(newBufferId != oldBufferId)
+  if(newBufferId != oldBufferId) {
     setCurrentBuffer(newBufferId);
+    emit currentChanged(newBufferId);
+  }
 }
 
 void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
-  if(!bufferId.isValid()) {
-    showChatView(0);
-    return;
-  }
-
   AbstractChatView *chatView = 0;
-  Buffer *buf = Client::buffer(bufferId);
-  if(!buf) {
-    qWarning() << "AbstractBufferContainer::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
-    return;
-  }
   Buffer *prevBuffer = Client::buffer(currentBuffer());
   if(prevBuffer) prevBuffer->setVisible(false);
+
+  Buffer *buf;
+  if(!bufferId.isValid() || !(buf = Client::buffer(bufferId))) {
+    if(bufferId.isValid())
+      qWarning() << "AbstractBufferContainer::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
+    _currentBuffer = 0;
+    showChatView(0);
+    return;
+  }
   if(_chatViews.contains(bufferId)) {
     chatView = _chatViews[bufferId];
   } else {
     chatView = createChatView(bufferId);
-    chatView->setContents(buf->contents());
-    connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), this, SLOT(appendMsg(AbstractUiMsg *)));
-    connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), this, SLOT(prependMsg(AbstractUiMsg *)));
     _chatViews[bufferId] = chatView;
   }
   _currentBuffer = bufferId;
-  showChatView(chatView);
+  showChatView(bufferId);
   buf->setVisible(true);
   setFocus();
 }
-
-void AbstractBufferContainer::appendMsg(AbstractUiMsg *msg) {
-  Buffer *buf = qobject_cast<Buffer *>(sender());
-  if(!buf) {
-    qWarning() << "AbstractBufferContainer::appendMsg(): Invalid slot caller!";
-    return;
-  }
-  BufferId id = buf->bufferInfo().bufferId();
-  if(!_chatViews.contains(id)) {
-    qWarning() << "AbstractBufferContainer::appendMsg(): Received message for unknown buffer!";
-    return;
-  }
-  _chatViews[id]->appendMsg(msg);
-}
-
-void AbstractBufferContainer::prependMsg(AbstractUiMsg *msg) {
-  Buffer *buf = qobject_cast<Buffer *>(sender());
-  if(!buf) {
-    qWarning() << "AbstractBufferContainer:prependMsg(): Invalid slot caller!";
-    return;
-  }
-  BufferId id = buf->bufferInfo().bufferId();
-  if(!_chatViews.contains(id)) {
-    qWarning() << "AbstractBufferContainer::prependMsg(): Received message for unknown buffer!";
-    return;
-  }
-  _chatViews[id]->prependMsg(msg);
-}