/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * Copyright (C) 2005-2010 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
***************************************************************************/
#include "abstractbuffercontainer.h"
-#include "buffer.h"
#include "client.h"
+#include "clientbacklogmanager.h"
#include "networkmodel.h"
AbstractBufferContainer::AbstractBufferContainer(QWidget *parent)
AbstractBufferContainer::~AbstractBufferContainer() {
}
-
void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
Q_ASSERT(model());
if(!parent.isValid()) {
}
void AbstractBufferContainer::removeBuffer(BufferId bufferId) {
- if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
if(!_chatViews.contains(bufferId))
return;
_chatViews.take(bufferId);
}
+/*
+ Switching to first buffer is now handled in MainWin::clientNetworkUpdated()
+
+void AbstractBufferContainer::rowsInserted(const QModelIndex &parent, int start, int end) {
+ Q_UNUSED(end)
+
+ if(currentBuffer().isValid())
+ return;
+
+ // we want to make sure the very first valid buffer is selected
+ QModelIndex index = model()->index(start, 0, parent);
+ if(index.isValid()) {
+ BufferId id = index.data(NetworkModel::BufferIdRole).value<BufferId>();
+ if(id.isValid())
+ setCurrentBuffer(id);
+ }
+}
+*/
+
void AbstractBufferContainer::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
+ Q_UNUSED(previous)
+
BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
- BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
- if(newBufferId != oldBufferId) {
+ // 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);
}
}
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;
+ BufferId prevBufferId = currentBuffer();
+ if(prevBufferId.isValid() && _chatViews.contains(prevBufferId)) {
+ MsgId msgId = _chatViews.value(prevBufferId)->lastMsgId();
+ Client::setBufferLastSeenMsg(prevBufferId, msgId);
+ }
+
+ if(!bufferId.isValid()) {
_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;
- }
+
+ if(!_chatViews.contains(bufferId))
+ _chatViews[bufferId] = createChatView(bufferId);
+
_currentBuffer = bufferId;
showChatView(bufferId);
- buf->setVisible(true);
+ Client::networkModel()->clearBufferActivity(bufferId);
+ Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId());
+ Client::backlogManager()->checkForBacklog(bufferId);
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);
-}