-void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
- AbstractChatView *chatView = 0;
- 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(bufferId);
- buf->setVisible(true);
- setFocus();
+void AbstractBufferContainer::currentChanged(const QModelIndex& current, const QModelIndex& previous)
+{
+ Q_UNUSED(previous)
+
+ BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
+ // To be able to reset the selected buffer, we don't check if buffer/index is valid here
+ if (currentBuffer() != newBufferId) {
+ setCurrentBuffer(newBufferId);
+ emit currentChanged(newBufferId);
+ emit currentChanged(current);
+ }