Continuing my personal crusade against Buffer.
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 12 Aug 2008 15:10:37 +0000 (17:10 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 12 Aug 2008 15:10:37 +0000 (17:10 +0200)
 - activity changes are now handled purely in the NetworkModel
 - Sput: I can only hope for you that there are no conflicts with your local repo :)

24 files changed:
src/client/CMakeLists.txt
src/client/abstractmessageprocessor.cpp
src/client/abstractmessageprocessor.h
src/client/buffer.cpp
src/client/buffer.h
src/client/buffermodel.cpp
src/client/buffermodel.h
src/client/client.cpp
src/client/client.h
src/client/networkmodel.cpp
src/client/networkmodel.h
src/client/quasselui.cpp [new file with mode: 0644]
src/client/quasselui.h
src/qtui/bufferwidget.cpp
src/qtui/bufferwidget.h
src/qtui/chatline.cpp
src/qtui/chatline.h
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/chatview.cpp
src/qtui/chatview.h
src/qtui/mainwin.h
src/uisupport/abstractbuffercontainer.cpp
src/uisupport/abstractbuffercontainer.h

index ecb34dd..f6651ae 100644 (file)
@@ -21,6 +21,7 @@ set(SOURCES
     messagemodel.cpp
     mappedselectionmodel.cpp
     networkmodel.cpp
     messagemodel.cpp
     mappedselectionmodel.cpp
     networkmodel.cpp
+    quasselui.cpp
     selectionmodelsynchronizer.cpp
     treemodel.cpp)
 
     selectionmodelsynchronizer.cpp
     treemodel.cpp)
 
index 0f692af..89ce4f0 100644 (file)
 
 #include "client.h"
 
 
 #include "client.h"
 
-AbstractMessageProcessor::AbstractMessageProcessor(QObject *parent) : QObject(parent) {
-
-
-
+AbstractMessageProcessor::AbstractMessageProcessor(QObject *parent)
+  : QObject(parent)
+{
 }
 
 }
 
-void AbstractMessageProcessor::postProcess(Message &msg) {
-  Client::buffer(msg.bufferInfo())->updateActivityLevel(msg);
-}
+// void AbstractMessageProcessor::postProcess(Message &msg) {
+//   Client::buffer(msg.bufferInfo())->updateActivityLevel(msg);
+// }
index ecbca38..50247a8 100644 (file)
@@ -21,7 +21,9 @@
 #ifndef ABSTRACTMESSAGEPROCESSOR_H_
 #define ABSTRACTMESSAGEPROCESSOR_H_
 
 #ifndef ABSTRACTMESSAGEPROCESSOR_H_
 #define ABSTRACTMESSAGEPROCESSOR_H_
 
+#include "client.h"
 #include "message.h"
 #include "message.h"
+#include "networkmodel.h"
 
 class AbstractMessageProcessor : public QObject {
   Q_OBJECT
 
 class AbstractMessageProcessor : public QObject {
   Q_OBJECT
@@ -38,7 +40,7 @@ class AbstractMessageProcessor : public QObject {
     void progressUpdated(int value, int maximum);
 
   protected:
     void progressUpdated(int value, int maximum);
 
   protected:
-    void postProcess(Message &msg);
+    inline void postProcess(Message &msg) { Client::networkModel()->updateBufferActivity(msg); }
 
 };
 
 
 };
 
index df78639..9108d69 100644 (file)
 
 Buffer::Buffer(BufferInfo bufferid, QObject *parent)
   : QObject(parent),
 
 Buffer::Buffer(BufferInfo bufferid, QObject *parent)
   : QObject(parent),
-    _bufferInfo(bufferid),
-    _isVisible(false),
-    _activityLevel(NoActivity)
+    _bufferInfo(bufferid)
 {
 {
-
 }
 
 BufferInfo Buffer::bufferInfo() const {
 }
 
 BufferInfo Buffer::bufferInfo() const {
@@ -42,49 +39,3 @@ BufferInfo Buffer::bufferInfo() const {
   return _bufferInfo;
 }
 
   return _bufferInfo;
 }
 
-void Buffer::setVisible(bool visible) {
-  _isVisible = visible;
-  setActivityLevel(NoActivity);
-  if(_lastRcvdMsg.msgId() > 0) setLastSeenMsg(_lastRcvdMsg.msgId());
-}
-
-void Buffer::setLastSeenMsg(const MsgId &msgId) {
-  const MsgId oldLastSeen = lastSeenMsg();
-  if(!oldLastSeen.isValid() || (msgId.isValid() && msgId > oldLastSeen)) {
-    _lastSeenMsg = msgId;
-    Client::setBufferLastSeenMsg(bufferInfo().bufferId(), msgId);
-    setActivityLevel(NoActivity);
-  }
-}
-
-void Buffer::setActivityLevel(ActivityLevel level) {
-  _activityLevel = level;
-  if(bufferInfo().bufferId() > 0) {
-    Client::networkModel()->setBufferActivity(bufferInfo(), level);
-  }
-}
-
-void Buffer::updateActivityLevel(const Message &msg) {
-  // FIXME dirty hack to allow the lastSeen stuff to continue to work
-  //       will be made much nicer once Buffer dies, I hope...
-  if(msg.msgId() > _lastRcvdMsg.msgId()) _lastRcvdMsg = msg;
-
-  if(isVisible())
-    return;
-
-  if(msg.flags() & Message::Self)      // don't update activity for our own messages
-    return;
-
-  if(lastSeenMsg().isValid() && lastSeenMsg() >= msg.msgId())
-    return;
-
-  ActivityLevel level = activityLevel() | OtherActivity;
-  if(msg.type() & (Message::Plain | Message::Notice | Message::Action))
-    level |= NewMessage;
-
-  if(msg.flags() & Message::Highlight)
-    level |= Highlight;
-
-  if(level != activityLevel())
-    setActivityLevel(level);
-}
index 72a30f1..84f34a3 100644 (file)
@@ -49,23 +49,9 @@ public:
   Buffer(BufferInfo, QObject *parent = 0);
 
   BufferInfo bufferInfo() const;
   Buffer(BufferInfo, QObject *parent = 0);
 
   BufferInfo bufferInfo() const;
-  inline bool isVisible() const { return _isVisible; }
-  inline MsgId lastSeenMsg() const { return _lastSeenMsg; }
-  inline ActivityLevel activityLevel() const { return _activityLevel; }
-
-public slots:
-  void setVisible(bool visible);
-  void setLastSeenMsg(const MsgId &msgId);
-  void setActivityLevel(ActivityLevel level);
-  void updateActivityLevel(const Message &msg);
 
 private:
   BufferInfo _bufferInfo;
 
 private:
   BufferInfo _bufferInfo;
-  bool _isVisible;
-  MsgId _lastSeenMsg;
-  Message _lastRcvdMsg;
-  ActivityLevel _activityLevel;
-
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel)
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(Buffer::ActivityLevel)
index a03ae5b..594dc83 100644 (file)
@@ -61,10 +61,6 @@ void BufferModel::synchronizeView(QAbstractItemView *view) {
   view->setSelectionModel(mappedSelectionModel);
 }
 
   view->setSelectionModel(mappedSelectionModel);
 }
 
-QModelIndex BufferModel::currentIndex() {
-  return standardSelectionModel()->currentIndex();
-}
-
 void BufferModel::setCurrentIndex(const QModelIndex &newCurrent) {
   _selectionModelSynchronizer.selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Current);
   _selectionModelSynchronizer.selectionModel()->select(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
 void BufferModel::setCurrentIndex(const QModelIndex &newCurrent) {
   _selectionModelSynchronizer.selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Current);
   _selectionModelSynchronizer.selectionModel()->select(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
index 7bd3fc9..4794afe 100644 (file)
@@ -45,7 +45,7 @@ public:
   void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
   void synchronizeView(QAbstractItemView *view);
 
   void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
   void synchronizeView(QAbstractItemView *view);
 
-  QModelIndex currentIndex();
+  inline QModelIndex currentIndex() { return standardSelectionModel()->currentIndex(); }
   void setCurrentIndex(const QModelIndex &newCurrent);
 
 private slots:
   void setCurrentIndex(const QModelIndex &newCurrent);
 
 private slots:
index faddce7..7cf25c1 100644 (file)
@@ -77,7 +77,6 @@ Client::Client(QObject *parent)
     _connectedToCore(false),
     _syncedToCore(false)
 {
     _connectedToCore(false),
     _syncedToCore(false)
 {
-  _monitorBuffer = new Buffer(BufferInfo(), this);
   _signalProxy->synchronize(_ircListHelper);
 
   connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)),
   _signalProxy->synchronize(_ircListHelper);
 
   connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)),
@@ -309,7 +308,7 @@ void Client::setSyncedToCore() {
   // create buffersyncer
   Q_ASSERT(!_bufferSyncer);
   _bufferSyncer = new BufferSyncer(this);
   // create buffersyncer
   Q_ASSERT(!_bufferSyncer);
   _bufferSyncer = new BufferSyncer(this);
-  connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), this, SLOT(updateLastSeenMsg(BufferId, MsgId)));
+  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)));
   signalProxy()->synchronize(bufferSyncer());
   connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId)));
   connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString)));
   signalProxy()->synchronize(bufferSyncer());
@@ -458,15 +457,6 @@ void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) {
   //qDebug() << "processed" << msgs.count() << "backlog lines in" << start.msecsTo(QTime::currentTime());
 }
 
   //qDebug() << "processed" << msgs.count() << "backlog lines in" << start.msecsTo(QTime::currentTime());
 }
 
-void Client::updateLastSeenMsg(BufferId id, const MsgId &msgId) {
-  Buffer *b = buffer(id);
-  if(!b) {
-    qWarning() << "Client::updateLastSeen(): Unknown buffer" << id;
-    return;
-  }
-  b->setLastSeenMsg(msgId);
-}
-
 void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) {
   if(!bufferSyncer())
     return;
 void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) {
   if(!bufferSyncer())
     return;
index 112a6a2..d8a2b4c 100644 (file)
@@ -66,7 +66,6 @@ public:
   static QList<Buffer *> buffers();
   static Buffer *buffer(BufferId bufferUid);
   static Buffer *buffer(BufferInfo);
   static QList<Buffer *> buffers();
   static Buffer *buffer(BufferId bufferUid);
   static Buffer *buffer(BufferInfo);
-  static inline Buffer *monitorBuffer() { return instance()->_monitorBuffer; }
 
   static QList<NetworkId> networkIds();
   static const Network * network(NetworkId);
 
   static QList<NetworkId> networkIds();
   static const Network * network(NetworkId);
@@ -178,7 +177,6 @@ private slots:
   void recvStatusMsg(QString network, QString message);
   void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
   void updateBufferInfo(BufferInfo);
   void recvStatusMsg(QString network, QString message);
   void receiveBacklog(BufferId bufferId, const QVariantList &msgs);
   void updateBufferInfo(BufferInfo);
-  void updateLastSeenMsg(BufferId id, const MsgId &msgId);
 
   void bufferDestroyed();
   void networkDestroyed();
 
   void bufferDestroyed();
   void networkDestroyed();
@@ -228,8 +226,6 @@ private:
   QHash<NetworkId, Network *> _networks;
   QHash<IdentityId, Identity *> _identities;
 
   QHash<NetworkId, Network *> _networks;
   QHash<IdentityId, Identity *> _identities;
 
-  Buffer *_monitorBuffer;
-
   static AccountId _currentCoreAccount;
 
   friend class ClientSyncer;
   static AccountId _currentCoreAccount;
 
   friend class ClientSyncer;
index 777e809..793f5ae 100644 (file)
@@ -23,6 +23,7 @@
 #include <QAbstractItemView>
 
 #include "bufferinfo.h"
 #include <QAbstractItemView>
 
 #include "bufferinfo.h"
+#include "buffermodel.h"
 #include "client.h"
 #include "signalproxy.h"
 #include "network.h"
 #include "client.h"
 #include "signalproxy.h"
 #include "network.h"
@@ -185,10 +186,27 @@ void BufferItem::setActivityLevel(Buffer::ActivityLevel level) {
   }
 }
 
   }
 }
 
-void BufferItem::updateActivityLevel(Buffer::ActivityLevel level) {
-  Buffer::ActivityLevel oldActivity = _activity;
-  _activity |= level;
-  if(oldActivity != _activity)
+//void BufferItem::updateActivityLevel(Buffer::ActivityLevel level) {
+void BufferItem::updateActivityLevel(const Message &msg) {
+  if(isCurrentBuffer())
+    return;
+
+  if(msg.flags() & Message::Self)      // don't update activity for our own messages
+    return;
+
+  if(lastSeenMsgId() >= msg.msgId())
+    return;
+
+  Buffer::ActivityLevel oldLevel = activityLevel();
+
+  _activity |= Buffer::OtherActivity;
+  if(msg.type() & (Message::Plain | Message::Notice | Message::Action))
+    _activity |= Buffer::NewMessage;
+
+  if(msg.flags() & Message::Highlight)
+    _activity |= Buffer::Highlight;
+
+  if(oldLevel != _activity)
     emit dataChanged();
 }
 
     emit dataChanged();
 }
 
@@ -230,33 +248,15 @@ void BufferItem::setBufferName(const QString &name) {
   emit dataChanged(0);
 }
 
   emit dataChanged(0);
 }
 
+bool BufferItem::isCurrentBuffer() const {
+  return _bufferInfo.bufferId() == Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>();
+}
+
 QString BufferItem::toolTip(int column) const {
   Q_UNUSED(column);
   return tr("<p> %1 - %2 </p>").arg(bufferInfo().bufferId().toInt()).arg(bufferName());
 }
 
 QString BufferItem::toolTip(int column) const {
   Q_UNUSED(column);
   return tr("<p> %1 - %2 </p>").arg(bufferInfo().bufferId().toInt()).arg(bufferName());
 }
 
-/*
-void BufferItem::setLastMsgInsert(QDateTime msgDate) {
-  if(msgDate.isValid() && msgDate > _lastMsgInsert)
-    _lastMsgInsert = msgDate;
-}
-*/
-/*
-// FIXME emit dataChanged()
-bool BufferItem::setLastSeen() {
-  if(_lastSeen > _lastMsgInsert)
-    return false;
-  
-  _lastSeen = _lastMsgInsert;
-  BufferSettings(bufferInfo().bufferId()).setLastSeen(_lastSeen);
-  return true;
-}
-
-QDateTime BufferItem::lastSeen() {
-  return _lastSeen;
-}
-*/
-
 /*****************************************
 *  StatusBufferItem
 *****************************************/
 /*****************************************
 *  StatusBufferItem
 *****************************************/
@@ -721,13 +721,6 @@ bool NetworkModel::isBufferIndex(const QModelIndex &index) const {
   return index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType;
 }
 
   return index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType;
 }
 
-/*
-Buffer *NetworkModel::getBufferByIndex(const QModelIndex &index) const {
-  BufferItem *item = static_cast<BufferItem *>(index.internalPointer());
-  return Client::instance()->buffer(item->id());
-}
-*/
-
 int NetworkModel::networkRow(NetworkId networkId) {
   NetworkItem *netItem = 0;
   for(int i = 0; i < rootItem->childCount(); i++) {
 int NetworkModel::networkRow(NetworkId networkId) {
   NetworkItem *netItem = 0;
   for(int i = 0; i < rootItem->childCount(); i++) {
@@ -780,28 +773,17 @@ QModelIndex NetworkModel::bufferIndex(BufferId bufferId) {
   return indexByItem(_bufferItemCache[bufferId]);
 }
 
   return indexByItem(_bufferItemCache[bufferId]);
 }
 
-BufferItem *NetworkModel::findBufferItem(const BufferInfo &bufferInfo) {
-  NetworkItem *netItem = findNetworkItem(bufferInfo.networkId());
-  if(!netItem)
-    return 0;
-
-  BufferItem *bufferItem = netItem->findBufferItem(bufferInfo);
-  return bufferItem;
-}
-
 BufferItem *NetworkModel::findBufferItem(BufferId bufferId) {
 BufferItem *NetworkModel::findBufferItem(BufferId bufferId) {
-  NetworkItem *netItem;
-  BufferItem *bufferItem;
-  
-  for(int i = 0; i < rootItem->childCount(); i++) {
-    netItem = qobject_cast<NetworkItem *>(rootItem->child(i));
-    if((bufferItem = netItem->findBufferItem(bufferId)))
-      return bufferItem;
-  }
-  return 0;
+  if(_bufferItemCache.contains(bufferId))
+    return _bufferItemCache[bufferId];
+  else
+    return 0;
 }
 
 BufferItem *NetworkModel::bufferItem(const BufferInfo &bufferInfo) {
 }
 
 BufferItem *NetworkModel::bufferItem(const BufferInfo &bufferInfo) {
+  if(_bufferItemCache.contains(bufferInfo.bufferId()))
+    return _bufferItemCache[bufferInfo.bufferId()];
+
   NetworkItem *netItem = networkItem(bufferInfo.networkId());
   return netItem->bufferItem(bufferInfo);
 }
   NetworkItem *netItem = networkItem(bufferInfo.networkId());
   return netItem->bufferItem(bufferInfo);
 }
@@ -912,37 +894,38 @@ void NetworkModel::bufferUpdated(BufferInfo bufferInfo) {
 }
 
 void NetworkModel::removeBuffer(BufferId bufferId) {
 }
 
 void NetworkModel::removeBuffer(BufferId bufferId) {
+  BufferItem *buffItem = findBufferItem(bufferId);
+  if(!buffItem)
+    return;
+
+  buffItem->parent()->removeChild(buffItem);
+}
+
+void NetworkModel::setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId) {
   BufferItem *bufferItem = findBufferItem(bufferId);
   BufferItem *bufferItem = findBufferItem(bufferId);
-  if(bufferItem)
-    bufferItem->parent()->removeChild(bufferItem);
+  if(!bufferItem) {
+    qDebug() << "NetworkModel::setLastSeenMsgId(): buffer is unknown:" << bufferId;
+    return;
+  }
+  bufferItem->setLastSeenMsgId(msgId);
 }
 
 }
 
-/*
 void NetworkModel::updateBufferActivity(const Message &msg) {
 void NetworkModel::updateBufferActivity(const Message &msg) {
-  BufferItem *buff = bufferItem(msg.bufferInfo());
-  Q_ASSERT(buff);
-
-  buff->setLastMsgInsert(msg.timestamp());
-
-  if(buff->lastSeen() >= msg.timestamp())
+  BufferItem *bufferItem = findBufferItem(msg.bufferInfo());
+  if(!bufferItem) {
+    qDebug() << "NetworkModel::updateBufferActivity(): buffer is unknown:" << msg.bufferInfo();
     return;
     return;
-
-  BufferItem::ActivityLevel level = BufferItem::OtherActivity;
-  if(msg.type() == Message::Plain || msg.type() == Message::Notice)
-    level |= BufferItem::NewMessage;
-
-  if(msg.flags() & Message::Highlight) 
-      level |= BufferItem::Highlight;
-
-  bufferItem(msg.bufferInfo())->updateActivity(level);
+  }
+  bufferItem->updateActivityLevel(msg);
 }
 }
-*/
 
 
-void NetworkModel::setBufferActivity(const BufferInfo &info, Buffer::ActivityLevel level) {
-  BufferItem *buff = bufferItem(info);
-  Q_ASSERT(buff);
-
-  buff->setActivityLevel(level);
+void NetworkModel::setBufferActivity(const BufferId &bufferId, Buffer::ActivityLevel level) {
+  BufferItem *bufferItem = findBufferItem(bufferId);
+  if(!bufferItem) {
+    qDebug() << "NetworkModel::setBufferActivity(): buffer is unknown:" << bufferId;
+    return;
+  }
+  bufferItem->setActivityLevel(level);
 }
 
 const Network *NetworkModel::networkByIndex(const QModelIndex &index) const {
 }
 
 const Network *NetworkModel::networkByIndex(const QModelIndex &index) const {
@@ -954,8 +937,6 @@ const Network *NetworkModel::networkByIndex(const QModelIndex &index) const {
   return Client::network(networkId);
 }
 
   return Client::network(networkId);
 }
 
-
-
 void NetworkModel::checkForRemovedBuffers(const QModelIndex &parent, int start, int end) {
   if(parent.data(ItemTypeRole) != NetworkItemType)
     return;
 void NetworkModel::checkForRemovedBuffers(const QModelIndex &parent, int start, int end) {
   if(parent.data(ItemTypeRole) != NetworkItemType)
     return;
index 07b2190..c564d7e 100644 (file)
@@ -108,14 +108,14 @@ public:
 
   virtual inline bool isActive() const { return qobject_cast<NetworkItem *>(parent())->isActive(); }
 
 
   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 Buffer::ActivityLevel activityLevel() const { return _activity; }
   void setActivityLevel(Buffer::ActivityLevel level);
   inline Buffer::ActivityLevel activityLevel() const { return _activity; }
   void setActivityLevel(Buffer::ActivityLevel level);
-  void updateActivityLevel(Buffer::ActivityLevel level);
-
-  void setLastMsgInsert(QDateTime msgDate);
-  bool setLastSeen();
-  QDateTime lastSeen();
+  //void updateActivityLevel(Buffer::ActivityLevel level);
+  void updateActivityLevel(const Message &msg);
 
 
+  bool isCurrentBuffer() const;
   virtual QString toolTip(int column) const;
 
 public slots:
   virtual QString toolTip(int column) const;
 
 public slots:
@@ -124,6 +124,7 @@ public slots:
 private:
   BufferInfo _bufferInfo;
   Buffer::ActivityLevel _activity;
 private:
   BufferInfo _bufferInfo;
   Buffer::ActivityLevel _activity;
+  MsgId _lastSeenMsgId;
 };
 
 /*****************************************
 };
 
 /*****************************************
@@ -296,6 +297,7 @@ public:
   Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
 
   QString bufferName(BufferId bufferId);
   Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
 
   QString bufferName(BufferId bufferId);
+  MsgId lastSeenMsgId(BufferId BufferId);
   NetworkId networkId(BufferId bufferId);
   QString networkName(BufferId bufferId);
   BufferInfo::Type bufferType(BufferId bufferId);
   NetworkId networkId(BufferId bufferId);
   QString networkName(BufferId bufferId);
   BufferInfo::Type bufferType(BufferId bufferId);
@@ -303,7 +305,9 @@ public:
 public slots:
   void bufferUpdated(BufferInfo bufferInfo);
   void removeBuffer(BufferId bufferId);
 public slots:
   void bufferUpdated(BufferInfo bufferInfo);
   void removeBuffer(BufferId bufferId);
-  void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity);
+  void setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId);
+  void setBufferActivity(const BufferId &bufferId, Buffer::ActivityLevel activity);
+  void updateBufferActivity(const Message &msg);
   void networkRemoved(const NetworkId &networkId);
 
 private slots:
   void networkRemoved(const NetworkId &networkId);
 
 private slots:
@@ -314,7 +318,7 @@ private:
   int networkRow(NetworkId networkId);
   NetworkItem *findNetworkItem(NetworkId networkId);
   NetworkItem *networkItem(NetworkId networkId);
   int networkRow(NetworkId networkId);
   NetworkItem *findNetworkItem(NetworkId networkId);
   NetworkItem *networkItem(NetworkId networkId);
-  BufferItem *findBufferItem(const BufferInfo &bufferInfo);
+  inline BufferItem *findBufferItem(const BufferInfo &bufferInfo) { return findBufferItem(bufferInfo.bufferId()); }
   BufferItem *findBufferItem(BufferId bufferId);
   BufferItem *bufferItem(const BufferInfo &bufferInfo);
 
   BufferItem *findBufferItem(BufferId bufferId);
   BufferItem *bufferItem(const BufferInfo &bufferInfo);
 
diff --git a/src/client/quasselui.cpp b/src/client/quasselui.cpp
new file mode 100644 (file)
index 0000000..6e0e0aa
--- /dev/null
@@ -0,0 +1,23 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+
+#include "quasselui.h"
+
+bool AbstractUi::_visible = false;
index a278def..dac64be 100644 (file)
@@ -18,8 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _QUASSELUI_H_
-#define _QUASSELUI_H_
+#ifndef QUASSELUI_H
+#define QUASSELUI_H
 
 #include <QObject>
 #include "message.h"
 
 #include <QObject>
 #include "message.h"
@@ -35,6 +35,9 @@ class AbstractUi : public QObject {
     virtual MessageModel *createMessageModel(QObject *parent) = 0;
     virtual AbstractMessageProcessor *createMessageProcessor(QObject *parent) = 0;
 
     virtual MessageModel *createMessageModel(QObject *parent) = 0;
     virtual AbstractMessageProcessor *createMessageProcessor(QObject *parent) = 0;
 
+  inline static bool isVisible() { return _visible; }
+  inline static void setVisible(bool visible) { _visible = visible; }
+
   protected slots:
     virtual void connectedToCore() {}
     virtual void disconnectedFromCore() {}
   protected slots:
     virtual void connectedToCore() {}
     virtual void disconnectedFromCore() {}
@@ -43,6 +46,8 @@ class AbstractUi : public QObject {
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
 
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
 
+private:
+  static bool _visible;
 };
 
 #endif
 };
 
 #endif
index c1e992d..a18a18c 100644 (file)
@@ -29,10 +29,6 @@ BufferWidget::BufferWidget(QWidget *parent) : AbstractBufferContainer(parent) {
   ui.setupUi(this);
 }
 
   ui.setupUi(this);
 }
 
-BufferWidget::~BufferWidget() {
-
-}
-
 AbstractChatView *BufferWidget::createChatView(BufferId id) {
   ChatView *chatView;
   chatView = new ChatView(Client::buffer(id), this);
 AbstractChatView *BufferWidget::createChatView(BufferId id) {
   ChatView *chatView;
   chatView = new ChatView(Client::buffer(id), this);
index 4d9bf56..e2876ad 100644 (file)
@@ -30,7 +30,6 @@ class BufferWidget : public AbstractBufferContainer {
 
   public:
     BufferWidget(QWidget *parent);
 
   public:
     BufferWidget(QWidget *parent);
-    virtual ~BufferWidget();
 
   protected:
     virtual AbstractChatView *createChatView(BufferId);
 
   protected:
     virtual AbstractChatView *createChatView(BufferId);
index 0e4df22..3e7167b 100644 (file)
 #include <QtGui>
 
 #include "bufferinfo.h"
 #include <QtGui>
 
 #include "bufferinfo.h"
+#include "buffersyncer.h"
+#include "client.h"
 #include "chatitem.h"
 #include "chatline.h"
 #include "chatitem.h"
 #include "chatline.h"
+#include "messagemodel.h"
 #include "qtui.h"
 
 ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
 #include "qtui.h"
 
 ChatLine::ChatLine(int row, QAbstractItemModel *model, QGraphicsItem *parent)
@@ -106,6 +109,12 @@ void ChatLine::setHighlighted(bool highlighted) {
 }
 
 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
 }
 
 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+//   const QAbstractItemModel *model_ = model();
+//   if(model_ && row() > 0) {
+//     MsgId msgId = model_->data(model_->index(row() - 1, 0), MessageModel::MsgIdRole).value<MsgId>();
+//     BufferId bufferId = model_->data(model_->index(row() - 1, 0), MessageModel::BufferIdRole).value<BufferId>();
+//     qDebug() << msgId;
+//   }
   if(_selection & Highlighted) {
     painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
   }
   if(_selection & Highlighted) {
     painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
   }
index 724be7d..15805cc 100644 (file)
@@ -35,6 +35,8 @@ class ChatLine : public QGraphicsItem {
 
   inline int row() { return _row; }
   inline void setRow(int row) { _row = row; }
 
   inline int row() { return _row; }
   inline void setRow(int row) { _row = row; }
+  inline const QAbstractItemModel *model() const { return chatScene() ? chatScene()->model() : 0; }
+  inline ChatScene *chatScene() const { return qobject_cast<ChatScene *>(scene()); }
     inline qreal width() const { return _width; }
     inline qreal height() const { return _height; }
     ChatItem &item(ChatLineModel::ColumnType);
     inline qreal width() const { return _width; }
     inline qreal height() const { return _height; }
     ChatItem &item(ChatLineModel::ColumnType);
index aeac420..9ac7974 100644 (file)
@@ -23,7 +23,6 @@
 #include <QGraphicsSceneMouseEvent>
 #include <QPersistentModelIndex>
 
 #include <QGraphicsSceneMouseEvent>
 #include <QPersistentModelIndex>
 
-#include "buffer.h"
 #include "chatitem.h"
 #include "chatline.h"
 #include "chatlinemodelitem.h"
 #include "chatitem.h"
 #include "chatline.h"
 #include "chatlinemodelitem.h"
index c69f0e1..f44e20b 100644 (file)
@@ -28,7 +28,6 @@
 #include "types.h"
 
 class AbstractUiMsg;
 #include "types.h"
 
 class AbstractUiMsg;
-class Buffer;
 class BufferId;
 class ChatItem;
 class ChatLine;
 class BufferId;
 class ChatItem;
 class ChatLine;
index dbddaaa..6e40c09 100644 (file)
@@ -102,3 +102,15 @@ void ChatView::verticalScrollbarChanged(int newPos) {
     scene()->setIsFetchingBacklog(vbar->value() == vbar->minimum());
   }
 }
     scene()->setIsFetchingBacklog(vbar->value() == vbar->minimum());
   }
 }
+
+MsgId ChatView::lastMsgId() const {
+  if(!scene())
+    return MsgId();
+
+  QAbstractItemModel *model = scene()->model();
+  if(!model || model->rowCount() == 0)
+    return MsgId();
+
+  
+  return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value<MsgId>();
+}
index 6da995e..244b5f4 100644 (file)
@@ -38,6 +38,7 @@ public:
   ChatView(MessageFilter *, QWidget *parent = 0);
   ChatView(Buffer *, QWidget *parent = 0);
 
   ChatView(MessageFilter *, QWidget *parent = 0);
   ChatView(Buffer *, QWidget *parent = 0);
 
+  virtual MsgId lastMsgId() const;
   inline ChatScene *scene() const { return _scene; }
 
 public slots:
   inline ChatScene *scene() const { return _scene; }
 
 public slots:
index 080e78f..28c94d1 100644 (file)
@@ -32,7 +32,6 @@
 class Buffer;
 class BufferViewConfig;
 class MsgProcessorStatusWidget;
 class Buffer;
 class BufferViewConfig;
 class MsgProcessorStatusWidget;
-class QtUi;
 class Message;
 class NickListWidget;
 
 class Message;
 class NickListWidget;
 
@@ -44,115 +43,115 @@ class NickListWidget;
 class MainWin : public QMainWindow {
   Q_OBJECT
 
 class MainWin : public QMainWindow {
   Q_OBJECT
 
-  public:
-    MainWin(QWidget *parent = 0);
-    virtual ~MainWin();
+public:
+  MainWin(QWidget *parent = 0);
+  virtual ~MainWin();
 
 
-    void init();
-    void addBufferView(BufferViewConfig *config = 0);
+  void init();
+  void addBufferView(BufferViewConfig *config = 0);
 
 
-    void displayTrayIconMessage(const QString &title, const QString &message);
+  void displayTrayIconMessage(const QString &title, const QString &message);
 
 #ifdef HAVE_DBUS
 
 #ifdef HAVE_DBUS
-    void sendDesktopNotification(const QString &title, const QString &message);
+  void sendDesktopNotification(const QString &title, const QString &message);
 #endif
 
 #endif
 
-    virtual bool event(QEvent *event);
-
-  public slots:
-    void setTrayIconActivity(bool active = false);
-
-  protected:
-    void closeEvent(QCloseEvent *event);
-    virtual void changeEvent(QEvent *event);
-
-  protected slots:
-    void connectedToCore();
-    void setConnectedState();
-    void updateLagIndicator(int lag);
-    void securedConnection();
-    void disconnectedFromCore();
-    void setDisconnectedState();
-    void systrayActivated( QSystemTrayIcon::ActivationReason );
-
-  private slots:
-    void addBufferView(int bufferViewConfigId);
-    void removeBufferView(int bufferViewConfigId);
-    void messagesInserted(const QModelIndex &parent, int start, int end);
-    void showChannelList(NetworkId netId = NetworkId());
-    void showCoreInfoDlg();
-    void showSettingsDlg();
-    void on_actionEditNetworks_triggered();
-    void on_actionManageViews_triggered();
-    void on_actionLockDockPositions_toggled(bool lock);
-    void showAboutDlg();
-    void on_actionDebugNetworkModel_triggered(bool);
-
-    void showCoreConnectionDlg(bool autoConnect = false);
-
-    void clientNetworkCreated(NetworkId);
-    void clientNetworkRemoved(NetworkId);
-    void clientNetworkUpdated();
-    void connectOrDisconnectFromNet();
-
-    void makeTrayIconBlink();
-    void saveStatusBarStatus(bool enabled);
-
-    void loadLayout();
-    void saveLayout();
-
+  virtual bool event(QEvent *event);
+
+public slots:
+  void setTrayIconActivity(bool active = false);
+
+protected:
+  void closeEvent(QCloseEvent *event);
+  virtual void changeEvent(QEvent *event);
+                                        
+protected slots:
+  void connectedToCore();
+  void setConnectedState();
+  void updateLagIndicator(int lag);
+  void securedConnection();
+  void disconnectedFromCore();
+  void setDisconnectedState();
+  void systrayActivated( QSystemTrayIcon::ActivationReason );
+                                                           
+private slots:
+  void addBufferView(int bufferViewConfigId);
+  void removeBufferView(int bufferViewConfigId);
+  void messagesInserted(const QModelIndex &parent, int start, int end);
+  void showChannelList(NetworkId netId = NetworkId());
+  void showCoreInfoDlg();
+  void showSettingsDlg();
+  void on_actionEditNetworks_triggered();
+  void on_actionManageViews_triggered();
+  void on_actionLockDockPositions_toggled(bool lock);
+  void showAboutDlg();
+  void on_actionDebugNetworkModel_triggered(bool);
+  
+  void showCoreConnectionDlg(bool autoConnect = false);
+  
+  void clientNetworkCreated(NetworkId);
+  void clientNetworkRemoved(NetworkId);
+  void clientNetworkUpdated();
+  void connectOrDisconnectFromNet();
+  
+  void makeTrayIconBlink();
+  void saveStatusBarStatus(bool enabled);
+
+  void loadLayout();
+  void saveLayout();
+  
 #ifdef HAVE_DBUS
 #ifdef HAVE_DBUS
-    void desktopNotificationClosed(uint id, uint reason);
-    void desktopNotificationInvoked(uint id, const QString & action);
+  void desktopNotificationClosed(uint id, uint reason);
+  void desktopNotificationInvoked(uint id, const QString & action);
 #endif
 #endif
-
-  signals:
-    void connectToCore(const QVariantMap &connInfo);
-    void disconnectFromCore();
-    void requestBacklog(BufferInfo, QVariant, QVariant);
-
-  private:
-    Ui::MainWin ui;
-
-    QMenu *systrayMenu;
-    QLabel *coreLagLabel;
-    QLabel *sslLabel;
-    MsgProcessorStatusWidget *msgProcessorStatusWidget;
-
-    TitleSetter _titleSetter;
-
-    void setupMenus();
-    void setupViews();
-    void setupNickWidget();
-    void setupChatMonitor();
-    void setupInputWidget();
-    void setupTopicWidget();
-    void setupStatusBar();
-    void setupSystray();
-
-    void toggleVisibility();
-
-    void enableMenus();
-
-    QSystemTrayIcon *systray;
-    QIcon activeTrayIcon;
-    QIcon onlineTrayIcon;
-    QIcon offlineTrayIcon;
-    bool trayIconActive;
-    QTimer *timer;
-
-    BufferId currentBuffer;
-    QString currentProfile;
-
-    QList<QDockWidget *> _netViews;
-    NickListWidget *nickListWidget;
-
+  
+signals:
+  void connectToCore(const QVariantMap &connInfo);
+  void disconnectFromCore();
+  void requestBacklog(BufferInfo, QVariant, QVariant);
+  
+private:
+  Ui::MainWin ui;
+  
+  QMenu *systrayMenu;
+  QLabel *coreLagLabel;
+  QLabel *sslLabel;
+  MsgProcessorStatusWidget *msgProcessorStatusWidget;
+  
+  TitleSetter _titleSetter;
+  
+  void setupMenus();
+  void setupViews();
+  void setupNickWidget();
+  void setupChatMonitor();
+  void setupInputWidget();
+  void setupTopicWidget();
+  void setupStatusBar();
+  void setupSystray();
+  
+  void toggleVisibility();
+  
+  void enableMenus();
+  
+  QSystemTrayIcon *systray;
+  QIcon activeTrayIcon;
+  QIcon onlineTrayIcon;
+  QIcon offlineTrayIcon;
+  bool trayIconActive;
+  QTimer *timer;
+
+  BufferId currentBuffer;
+  QString currentProfile;
+  
+  QList<QDockWidget *> _netViews;
+  NickListWidget *nickListWidget;
+  
 #ifdef HAVE_DBUS
 #ifdef HAVE_DBUS
-    org::freedesktop::Notifications *desktopNotifications;
-    quint32 notificationId;
+  org::freedesktop::Notifications *desktopNotifications;
+  quint32 notificationId;
 #endif
 #endif
-
-    friend class QtUi;
+  
+  friend class QtUi;
 };
 
 #endif
 };
 
 #endif
index a12b031..e6b1f14 100644 (file)
@@ -19,7 +19,6 @@
  ***************************************************************************/
 
 #include "abstractbuffercontainer.h"
  ***************************************************************************/
 
 #include "abstractbuffercontainer.h"
-#include "buffer.h"
 #include "client.h"
 #include "networkmodel.h"
 
 #include "client.h"
 #include "networkmodel.h"
 
@@ -32,7 +31,6 @@ AbstractBufferContainer::AbstractBufferContainer(QWidget *parent)
 AbstractBufferContainer::~AbstractBufferContainer() {
 }
 
 AbstractBufferContainer::~AbstractBufferContainer() {
 }
 
-
 void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
   Q_ASSERT(model());
   if(!parent.isValid()) {
 void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
   Q_ASSERT(model());
   if(!parent.isValid()) {
@@ -60,7 +58,6 @@ void AbstractBufferContainer::rowsAboutToBeRemoved(const QModelIndex &parent, in
 }
 
 void AbstractBufferContainer::removeBuffer(BufferId bufferId) {
 }
 
 void AbstractBufferContainer::removeBuffer(BufferId bufferId) {
-  if(Client::buffer(bufferId)) Client::buffer(bufferId)->setVisible(false);
   if(!_chatViews.contains(bufferId))
     return;
 
   if(!_chatViews.contains(bufferId))
     return;
 
@@ -78,26 +75,24 @@ void AbstractBufferContainer::currentChanged(const QModelIndex &current, const Q
 }
 
 void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
 }
 
 void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) {
-  AbstractChatView *chatView = 0;
-  Buffer *prevBuffer = Client::buffer(currentBuffer());
-  if(prevBuffer) prevBuffer->setVisible(false);
+  BufferId prevBufferId = currentBuffer();
+  if(prevBufferId.isValid() && _chatViews.contains(prevBufferId)) {
+    Client::setBufferLastSeenMsg(prevBufferId, _chatViews[prevBufferId]->lastMsgId());
+  }
 
 
-  Buffer *buf;
-  if(!bufferId.isValid() || !(buf = Client::buffer(bufferId))) {
-    if(bufferId.isValid())
-      qWarning() << "AbstractBufferContainer::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
+  if(!bufferId.isValid()) {
+    qWarning() << "AbstractBufferContainer::setBuffer(BufferId): invalid BufferId:" << bufferId;
     _currentBuffer = 0;
     showChatView(0);
     return;
   }
     _currentBuffer = 0;
     showChatView(0);
     return;
   }
-  if(_chatViews.contains(bufferId)) {
-    chatView = _chatViews[bufferId];
-  } else {
-    chatView = createChatView(bufferId);
-    _chatViews[bufferId] = chatView;
-  }
+
+  if(!_chatViews.contains(bufferId))
+    _chatViews[bufferId] = createChatView(bufferId);
+
   _currentBuffer = bufferId;
   showChatView(bufferId);
   _currentBuffer = bufferId;
   showChatView(bufferId);
-  buf->setVisible(true);
+  Client::networkModel()->setBufferActivity(bufferId, Buffer::NoActivity);
+  Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId());
   setFocus();
 }
   setFocus();
 }
index bf8a34c..0e46627 100644 (file)
@@ -75,7 +75,7 @@ class AbstractChatView {
 
   public:
     virtual ~AbstractChatView() {};
 
   public:
     virtual ~AbstractChatView() {};
-
+    virtual MsgId lastMsgId() const = 0;
 };
 
 #endif
 };
 
 #endif