X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fabstractbuffercontainer.cpp;h=4527563e132017c5952fc0fcb3f09ade069274c1;hp=78ead2738f8ec9a209974883200e2d76c2eca497;hb=695758015a80eb8c158a9ac4c0f1c0b547e70df3;hpb=2684aa5295d12e4f7c66b3011fc8b1819f3d1cbb diff --git a/src/uisupport/abstractbuffercontainer.cpp b/src/uisupport/abstractbuffercontainer.cpp index 78ead273..4527563e 100644 --- a/src/uisupport/abstractbuffercontainer.cpp +++ b/src/uisupport/abstractbuffercontainer.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-2015 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,122 +15,119 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "abstractbuffercontainer.h" -#include "buffer.h" #include "client.h" +#include "clientbacklogmanager.h" #include "networkmodel.h" -AbstractBufferContainer::AbstractBufferContainer(QWidget *parent) : AbstractItemView(parent), _currentBuffer(0) +AbstractBufferContainer::AbstractBufferContainer(QWidget *parent) + : AbstractItemView(parent), + _currentBuffer(0) { - } -AbstractBufferContainer::~AbstractBufferContainer() { +AbstractBufferContainer::~AbstractBufferContainer() +{ } -void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { - Q_ASSERT(model()); - if(!parent.isValid()) { - // ok this means that whole networks are about to be removed - // we can't determine which buffers are affect, so we hope that all nets are removed - // this is the most common case (for example disconnecting from the core or terminating the client) - if(model()->rowCount(parent) != end - start + 1) - return; - - AbstractChatView *chatView; - QHash::iterator iter = _chatViews.begin(); - while(iter != _chatViews.end()) { - chatView = *iter; - iter = _chatViews.erase(iter); - removeChatView(chatView); +void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) +{ + Q_ASSERT(model()); + if (!parent.isValid()) { + // ok this means that whole networks are about to be removed + // we can't determine which buffers are affect, so we hope that all nets are removed + // this is the most common case (for example disconnecting from the core or terminating the client) + if (model()->rowCount(parent) != end - start + 1) + return; + + foreach(BufferId id, _chatViews.keys()) { + removeChatView(id); + } + _chatViews.clear(); } - } else { - // check if there are explicitly buffers removed - for(int i = start; i <= end; i++) { - QVariant variant = parent.child(i,0).data(NetworkModel::BufferIdRole); - if(!variant.isValid()) - continue; - - BufferId bufferId = variant.value(); - removeBuffer(bufferId); + else { + // check if there are explicitly buffers removed + for (int i = start; i <= end; i++) { + QVariant variant = parent.child(i, 0).data(NetworkModel::BufferIdRole); + if (!variant.isValid()) + continue; + + BufferId bufferId = variant.value(); + removeBuffer(bufferId); + } } - } } -void AbstractBufferContainer::removeBuffer(BufferId bufferId) { - if(!_chatViews.contains(bufferId)) - return; - if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false); - AbstractChatView *chatView = _chatViews.take(bufferId); - removeChatView(chatView); -} +void AbstractBufferContainer::removeBuffer(BufferId bufferId) +{ + if (!_chatViews.contains(bufferId)) + return; -void AbstractBufferContainer::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { - BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value(); - BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value(); - if(newBufferId != oldBufferId) - setCurrentBuffer(newBufferId); + removeChatView(bufferId); + _chatViews.take(bufferId); } -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; +/* + 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(); + if(id.isValid()) + setCurrentBuffer(id); } - Buffer *prevBuffer = Client::buffer(currentBuffer()); - if(prevBuffer) prevBuffer->setVisible(false); - 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); - buf->setVisible(true); - setFocus(); } +*/ -void AbstractBufferContainer::appendMsg(AbstractUiMsg *msg) { - Buffer *buf = qobject_cast(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::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) +{ + Q_UNUSED(previous) + + BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value(); + // 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::prependMsg(AbstractUiMsg *msg) { - Buffer *buf = qobject_cast(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); + +void AbstractBufferContainer::setCurrentBuffer(BufferId 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)) + _chatViews[bufferId] = createChatView(bufferId); + + _currentBuffer = bufferId; + showChatView(bufferId); + Client::networkModel()->clearBufferActivity(bufferId); + Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId()); + Client::backlogManager()->checkForBacklog(bufferId); + setFocus(); }