From 50d5627b282f063e755f44f02a74aeddd1d07538 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 13 Nov 2008 15:41:46 +0100 Subject: [PATCH] Activity level is now properly handled for the currently selected buffer. This has two effects: - previously the activity lvl wasn't cleared for the last selected buffer when closing / disconnecting quasselclient - in a multi client environment the activity level is immediately reflected on the other clients --- src/client/client.cpp | 1 + src/client/networkmodel.cpp | 18 ++++- src/client/networkmodel.h | 8 ++- src/qtui/chatline.cpp | 2 +- src/uisupport/abstractbuffercontainer.cpp | 2 +- src/uisupport/abstractbuffercontainer.h | 82 +++++++++++------------ 6 files changed, 66 insertions(+), 47 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index b61ebd7e..bac736b0 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -280,6 +280,7 @@ void Client::setSyncedToCore() { connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), _networkModel, SLOT(setLastSeenMsgId(BufferId, MsgId))); connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId))); connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString))); + connect(networkModel(), SIGNAL(setLastSeenMsg(BufferId, MsgId)), bufferSyncer(), SLOT(requestSetLastSeenMsg(BufferId, const MsgId &))); signalProxy()->synchronize(bufferSyncer()); // create a new BufferViewManager diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 0ffd9c0a..29ebfc9d 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -191,8 +191,9 @@ void BufferItem::setActivityLevel(BufferInfo::ActivityLevel level) { } void BufferItem::updateActivityLevel(const Message &msg) { - if(isCurrentBuffer()) + if(isCurrentBuffer()) { return; + } if(msg.flags() & Message::Self) // don't update activity for our own messages return; @@ -253,6 +254,9 @@ void BufferItem::setBufferName(const QString &name) { void BufferItem::setLastSeenMsgId(const MsgId &msgId) { _lastSeenMsgId = msgId; + if(!isCurrentBuffer()) { + _lastSeenMarkerMsgId = msgId; + } setActivityLevel(BufferInfo::NoActivity); } @@ -916,6 +920,13 @@ MsgId NetworkModel::lastSeenMsgId(BufferId bufferId) { return _bufferItemCache[bufferId]->lastSeenMsgId(); } +MsgId NetworkModel::lastSeenMarkerMsgId(BufferId bufferId) { + if(!_bufferItemCache.contains(bufferId)) + return MsgId(); + + return _bufferItemCache[bufferId]->lastSeenMarkerMsgId(); +} + void NetworkModel::setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId) { BufferItem *bufferItem = findBufferItem(bufferId); if(!bufferItem) { @@ -926,7 +937,10 @@ void NetworkModel::setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId } void NetworkModel::updateBufferActivity(const Message &msg) { - bufferItem(msg.bufferInfo())->updateActivityLevel(msg); + BufferItem *item = bufferItem(msg.bufferInfo()); + item->updateActivityLevel(msg); + if(item->isCurrentBuffer()) + emit setLastSeenMsg(item->bufferId(), msg.msgId()); } void NetworkModel::setBufferActivity(const BufferId &bufferId, BufferInfo::ActivityLevel level) { diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index fcaa0f22..2c329035 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -110,11 +110,10 @@ public: virtual inline bool isActive() const { return qobject_cast(parent())->isActive(); } inline const MsgId &lastSeenMsgId() const { return _lastSeenMsgId; } - //inline void setLastSeenMsgId(const MsgId &msgId) { _lastSeenMsgId = msgId; } + inline const MsgId &lastSeenMarkerMsgId() const { return _lastSeenMarkerMsgId; } void setLastSeenMsgId(const MsgId &msgId); inline BufferInfo::ActivityLevel activityLevel() const { return _activity; } void setActivityLevel(BufferInfo::ActivityLevel level); - //void updateActivityLevel(BufferInfo::ActivityLevel level); void updateActivityLevel(const Message &msg); bool isCurrentBuffer() const; @@ -127,6 +126,7 @@ private: BufferInfo _bufferInfo; BufferInfo::ActivityLevel _activity; MsgId _lastSeenMsgId; + MsgId _lastSeenMarkerMsgId; }; /***************************************** @@ -302,6 +302,7 @@ public: BufferInfo::Type bufferType(BufferId bufferId); BufferInfo bufferInfo(BufferId bufferId); MsgId lastSeenMsgId(BufferId bufferId); + MsgId lastSeenMarkerMsgId(BufferId bufferId); NetworkId networkId(BufferId bufferId); QString networkName(BufferId bufferId); @@ -315,6 +316,9 @@ public slots: void updateBufferActivity(const Message &msg); void networkRemoved(const NetworkId &networkId); +signals: + void setLastSeenMsg(BufferId bufferId, MsgId msgId); + private slots: void checkForRemovedBuffers(const QModelIndex &parent, int start, int end); void checkForNewBuffers(const QModelIndex &parent, int start, int end); diff --git a/src/qtui/chatline.cpp b/src/qtui/chatline.cpp index 1351ee5b..6ccb9f70 100644 --- a/src/qtui/chatline.cpp +++ b/src/qtui/chatline.cpp @@ -181,7 +181,7 @@ void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, // don't show the marker if we wrote that new line if(!(flags & Message::Self)) { BufferId bufferId = BufferId(chatScene()->idString().toInt()); - MsgId lastSeenMsgId = Client::networkModel()->lastSeenMsgId(bufferId); + MsgId lastSeenMsgId = Client::networkModel()->lastSeenMarkerMsgId(bufferId); if(lastSeenMsgId < myMsgId && lastSeenMsgId >= prevMsgId) { QtUiStyleSettings s("Colors"); QLinearGradient gradient(0, 0, 0, contentsItem().fontMetrics()->lineSpacing()); diff --git a/src/uisupport/abstractbuffercontainer.cpp b/src/uisupport/abstractbuffercontainer.cpp index 8b89e8c4..c4cbb197 100644 --- a/src/uisupport/abstractbuffercontainer.cpp +++ b/src/uisupport/abstractbuffercontainer.cpp @@ -92,6 +92,6 @@ void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) { _currentBuffer = bufferId; showChatView(bufferId); Client::networkModel()->setBufferActivity(bufferId, BufferInfo::NoActivity); - // Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId()); + Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId()); setFocus(); } diff --git a/src/uisupport/abstractbuffercontainer.h b/src/uisupport/abstractbuffercontainer.h index 0e466277..2c89e6fe 100644 --- a/src/uisupport/abstractbuffercontainer.h +++ b/src/uisupport/abstractbuffercontainer.h @@ -31,51 +31,51 @@ class Buffer; class AbstractBufferContainer : public AbstractItemView { Q_OBJECT - public: - AbstractBufferContainer(QWidget *parent); - virtual ~AbstractBufferContainer(); - - inline BufferId currentBuffer() const { return _currentBuffer; } - - signals: - void currentChanged(BufferId); - - protected: - //! Create an AbstractChatView for the given BufferId and add it to the UI if necessary - virtual AbstractChatView *createChatView(BufferId) = 0; - - //! Remove a chat view from the UI and delete it - /** This method shall remove the view from the UI (for example, from a QStackedWidget) if appropriate. - * It also shall delete the object afterwards. - * \param view The chat view to be removed and deleted - */ - virtual void removeChatView(BufferId) = 0; - - protected slots: - virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); - virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); - - //! Show the given chat view - /** This method is called when the given chat view should be displayed. Use this e.g. for - * selecting the appropriate page in a QStackedWidget. - * \param view The chat view to be displayed. May be 0 if no chat view is selected. - */ - virtual void showChatView(BufferId) = 0; - - private slots: - void removeBuffer(BufferId bufferId); - void setCurrentBuffer(BufferId bufferId); - - private: - BufferId _currentBuffer; - QHash _chatViews; +public: + AbstractBufferContainer(QWidget *parent); + virtual ~AbstractBufferContainer(); + + inline BufferId currentBuffer() const { return _currentBuffer; } + +signals: + void currentChanged(BufferId); + +protected: + //! Create an AbstractChatView for the given BufferId and add it to the UI if necessary + virtual AbstractChatView *createChatView(BufferId) = 0; + + //! Remove a chat view from the UI and delete it + /** This method shall remove the view from the UI (for example, from a QStackedWidget) if appropriate. + * It also shall delete the object afterwards. + * \param view The chat view to be removed and deleted + */ + virtual void removeChatView(BufferId) = 0; + +protected slots: + virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); + virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); + + //! Show the given chat view + /** This method is called when the given chat view should be displayed. Use this e.g. for + * selecting the appropriate page in a QStackedWidget. + * \param view The chat view to be displayed. May be 0 if no chat view is selected. + */ + virtual void showChatView(BufferId) = 0; + +private slots: + void removeBuffer(BufferId bufferId); + void setCurrentBuffer(BufferId bufferId); + +private: + BufferId _currentBuffer; + QHash _chatViews; }; class AbstractChatView { - public: - virtual ~AbstractChatView() {}; - virtual MsgId lastMsgId() const = 0; +public: + virtual ~AbstractChatView() {}; + virtual MsgId lastMsgId() const = 0; }; #endif -- 2.20.1