X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fabstractbuffercontainer.cpp;h=3d93702497ae4ff6c7326798b6575775fb1afb25;hp=9861d14b35eb72515925fc2b7dd2f299d8e395c8;hb=c64a887d0f05222590299fb2bb8d56fa9fadb16d;hpb=ab16c77fe03b73a863d9b52b11919bcbac903f58 diff --git a/src/uisupport/abstractbuffercontainer.cpp b/src/uisupport/abstractbuffercontainer.cpp index 9861d14b..3d937024 100644 --- a/src/uisupport/abstractbuffercontainer.cpp +++ b/src/uisupport/abstractbuffercontainer.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2012 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,7 +15,7 @@ * 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" @@ -24,76 +24,110 @@ #include "networkmodel.h" AbstractBufferContainer::AbstractBufferContainer(QWidget *parent) - : AbstractItemView(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; - - foreach(BufferId id, _chatViews.keys()) { - removeChatView(id); + +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(); } - _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; - removeChatView(bufferId); - _chatViews.take(bufferId); -} +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); - emit currentChanged(newBufferId); - emit currentChanged(current); - } + removeChatView(bufferId); + _chatViews.take(bufferId); } -void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) { - BufferId prevBufferId = currentBuffer(); - if(prevBufferId.isValid() && _chatViews.contains(prevBufferId)) { - Client::setBufferLastSeenMsg(prevBufferId, _chatViews[prevBufferId]->lastMsgId()); - } - if(!bufferId.isValid()) { - _currentBuffer = 0; - showChatView(0); +/* + 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); } +} +*/ + +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::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); + if (!_chatViews.contains(bufferId)) + _chatViews[bufferId] = createChatView(bufferId); - _currentBuffer = bufferId; - showChatView(bufferId); - Client::networkModel()->clearBufferActivity(bufferId); - Client::backlogManager()->checkForBacklog(bufferId); - setFocus(); + _currentBuffer = bufferId; + showChatView(bufferId); + Client::networkModel()->clearBufferActivity(bufferId); + Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId()); + Client::backlogManager()->checkForBacklog(bufferId); + setFocus(); }