Activity level is now properly handled for the currently selected buffer.
authorMarcus Eggenberger <egs@quassel-irc.org>
Thu, 13 Nov 2008 14:41:46 +0000 (15:41 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Thu, 13 Nov 2008 14:41:46 +0000 (15:41 +0100)
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
src/client/networkmodel.cpp
src/client/networkmodel.h
src/qtui/chatline.cpp
src/uisupport/abstractbuffercontainer.cpp
src/uisupport/abstractbuffercontainer.h

index b61ebd7..bac736b 100644 (file)
@@ -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
index 0ffd9c0..29ebfc9 100644 (file)
@@ -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) {
index fcaa0f2..2c32903 100644 (file)
@@ -110,11 +110,10 @@ public:
   virtual inline bool isActive() const { return qobject_cast<NetworkItem *>(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);
index 1351ee5..6ccb9f7 100644 (file)
@@ -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());
index 8b89e8c..c4cbb19 100644 (file)
@@ -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();
 }
index 0e46627..2c89e6f 100644 (file)
@@ -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 &current, 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<BufferId, AbstractChatView *> _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 &current, 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<BufferId, AbstractChatView *> _chatViews;
 };
 
 class AbstractChatView {
 
-  public:
-    virtual ~AbstractChatView() {};
-    virtual MsgId lastMsgId() const = 0;
+public:
+  virtual ~AbstractChatView() {};
+  virtual MsgId lastMsgId() const = 0;
 };
 
 #endif