reverting the backlog request to how it was in the old chatwidget
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 18 Aug 2008 12:31:57 +0000 (14:31 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Mon, 18 Aug 2008 12:31:57 +0000 (14:31 +0200)
src/client/messagefilter.cpp
src/client/messagefilter.h
src/qtui/bufferwidget.cpp
src/qtui/chatmonitorfilter.cpp
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/chatview.cpp
src/qtui/chatview.h

index 543d1fc..1700672 100644 (file)
 
 #include "messagefilter.h"
 
-MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent) : QSortFilterProxyModel(parent) {
+MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent)
+  : QSortFilterProxyModel(parent)
+{
   setSourceModel(source);
 }
 
 MessageFilter::MessageFilter(MessageModel *source, const QList<BufferId> &buffers, QObject *parent)
   : QSortFilterProxyModel(parent),
-    _bufferList(buffers)
+    _validBuffers(buffers.toSet())
 {
   setSourceModel(source);
 }
 
 QString MessageFilter::idString() const {
-  if(_bufferList.isEmpty()) return "*";
-  QString idstr;
-  QStringList bufids;
-  foreach(BufferId id, _bufferList) bufids << QString::number(id.toInt());
-  bufids.sort();
-  foreach(QString id, bufids) idstr += id + '|';
-  idstr.chop(1);
-  return idstr;
+  if(_validBuffers.isEmpty())
+    return "*";
+
+  QList<BufferId> bufferIds = _validBuffers.toList();;
+  qSort(bufferIds);
+  
+  QStringList bufferIdStrings;
+  foreach(BufferId id, bufferIds)
+    bufferIdStrings << QString::number(id.toInt());
+
+  return bufferIdStrings.join("|");
 }
 
 bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
   Q_UNUSED(sourceParent);
-  if(_bufferList.isEmpty()) return true;
+  if(_validBuffers.isEmpty())
+    return true;
+
   BufferId id = sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value<BufferId>();
-  return _bufferList.contains(id);
+  return _validBuffers.contains(id);
 }
index e767a95..eeca964 100644 (file)
 class MessageFilter : public QSortFilterProxyModel {
   Q_OBJECT
 
-  protected:
-    MessageFilter(QAbstractItemModel *source, QObject *parent = 0);
-
-  public:
-    MessageFilter(MessageModel *, const QList<BufferId> &buffers = QList<BufferId>(), QObject *parent = 0);
-
-    virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
-    virtual QString idString() const;
-    inline bool isSingleBufferFilter() const { return _bufferList.count() == 1; }
-                           
-  private:
-    QList<BufferId> _bufferList;
+protected:
+  MessageFilter(QAbstractItemModel *source, QObject *parent = 0);
+
+public:
+  MessageFilter(MessageModel *, const QList<BufferId> &buffers = QList<BufferId>(), QObject *parent = 0);
+
+  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+  virtual QString idString() const;
+  inline bool isSingleBufferFilter() const { return _validBuffers.count() == 1; }
+  
+private:
+  QSet<BufferId> _validBuffers;
 };
 
 #endif
index a0f71c6..e16735e 100644 (file)
@@ -66,7 +66,6 @@ AbstractChatView *BufferWidget::createChatView(BufferId id) {
   _chatViews[id] = chatView;
   ui.stackedWidget->addWidget(chatView);
   chatView->setFocusProxy(this);
-  chatView->setBufferForBacklogFetching(id);
   return chatView;
 }
 
index 1fbab84..6bec8c3 100644 (file)
@@ -26,7 +26,7 @@
 #include "networkmodel.h"
 
 ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent)
-  : MessageFilter(model, QList<BufferId>(), parent)
+  : MessageFilter(model, parent)
 {
 }
 
index 681996a..67ce63c 100644 (file)
@@ -45,8 +45,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject
     _singleBufferScene(false),
     _selectingItem(0),
     _selectionStart(-1),
-    _isSelecting(false),
-    _fetchingBacklog(false)
+    _isSelecting(false)
 {
   MessageFilter *filter = qobject_cast<MessageFilter*>(model);
   if(filter) {
@@ -129,8 +128,6 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
     setSceneRect(QRectF(0, 0, _width, _height));
     emit heightChanged(_height);
   }
-
-  requestBacklogIfNeeded();
 }
 
 void ChatScene::modelReset() {
@@ -308,27 +305,15 @@ QString ChatScene::selectionToString() const {
   return result;
 }
 
-void ChatScene::setIsFetchingBacklog(bool fetch) {
-  if(!isBacklogFetchingEnabled()) return;
-
-  if(!fetch) {
-    _fetchingBacklog = false;
-  } else {
-    _fetchingBacklog = true;
-    requestBacklogIfNeeded();
-  }
-}
-
-void ChatScene::requestBacklogIfNeeded() {
-  const int REQUEST_COUNT = 50;
-
-  if(!isBacklogFetchingEnabled() || !isFetchingBacklog() || !model()->rowCount()) return;
-
-  MsgId msgId = model()->data(model()->index(0, 0), ChatLineModel::MsgIdRole).value<MsgId>();
-  if(!_lastBacklogOffset.isValid() || (msgId < _lastBacklogOffset && _lastBacklogSize + REQUEST_COUNT <= model()->rowCount())) {
-    Client::backlogManager()->requestBacklog(bufferForBacklogFetching(), REQUEST_COUNT, msgId.toInt());
-    _lastBacklogOffset = msgId;
-    _lastBacklogSize = model()->rowCount();
+void ChatScene::requestBacklog() {
+  static const int REQUEST_COUNT = 50;
+  int backlogSize = model()->rowCount();
+  if(isSingleBufferScene() && backlogSize != 0 && _lastBacklogSize + REQUEST_COUNT <= backlogSize) {
+    QModelIndex msgIdx = model()->index(0, 0);
+    MsgId msgId = model()->data(msgIdx, ChatLineModel::MsgIdRole).value<MsgId>();
+    BufferId bufferId = model()->data(msgIdx, ChatLineModel::BufferIdRole).value<BufferId>();
+    _lastBacklogSize = backlogSize;
+    Client::backlogManager()->requestBacklog(bufferId, REQUEST_COUNT, msgId.toInt());
   }
 }
 
index 1b31d1f..1fee5c2 100644 (file)
@@ -18,8 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _CHATSCENE_H_
-#define _CHATSCENE_H_
+#ifndef CHATSCENE_H_
+#define CHATSCENE_H_
 
 #include <QAbstractItemModel>
 #include <QGraphicsScene>
@@ -44,9 +44,6 @@ class ChatScene : public QGraphicsScene {
     inline QAbstractItemModel *model() const { return _model; }
     inline QString idString() const { return _idString; }
 
-    inline bool isFetchingBacklog() const;
-    inline bool isBacklogFetchingEnabled() const;
-    inline BufferId bufferForBacklogFetching() const;
     int sectionByScenePos(int x);
     inline int sectionByScenePos(const QPoint &pos) { return sectionByScenePos(pos.x()); }
     inline bool isSingleBufferScene() const { return _singleBufferScene; }
@@ -61,8 +58,7 @@ class ChatScene : public QGraphicsScene {
     void startGlobalSelection(ChatItem *item, const QPointF &itemPos);
     void putToClipboard(const QString &);
 
-    void setIsFetchingBacklog(bool);
-    inline void setBufferForBacklogFetching(BufferId buffer);
+    void requestBacklog();
 
   signals:
     void heightChanged(qreal height);
@@ -83,7 +79,6 @@ class ChatScene : public QGraphicsScene {
   private:
     void updateSelection(const QPointF &pos);
     QString selectionToString() const;
-    void requestBacklogIfNeeded();
 
     QString _idString;
     qreal _width, _height;
@@ -101,26 +96,7 @@ class ChatScene : public QGraphicsScene {
     int _firstSelectionRow, _lastSelectionRow;
     bool _isSelecting;
 
-    bool _fetchingBacklog;
-    BufferId _backlogFetchingBuffer;
-    MsgId _lastBacklogOffset;
     int _lastBacklogSize;
 };
 
-bool ChatScene::isFetchingBacklog() const {
-  return _fetchingBacklog;
-}
-
-bool ChatScene::isBacklogFetchingEnabled() const {
-  return _backlogFetchingBuffer.isValid();
-}
-
-BufferId ChatScene::bufferForBacklogFetching() const {
-  return _backlogFetchingBuffer;
-}
-
-void ChatScene::setBufferForBacklogFetching(BufferId buf) {
-  _backlogFetchingBuffer = buf;
-}
-
 #endif
index 77a0976..20557e2 100644 (file)
@@ -37,7 +37,6 @@ ChatView::ChatView(BufferId bufferId, QWidget *parent)
   filterList.append(bufferId);
   MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this);
   init(filter);
-
 }
 
 ChatView::ChatView(MessageFilter *filter, QWidget *parent)
@@ -56,8 +55,6 @@ void ChatView::init(MessageFilter *filter) {
   connect(_scene, SIGNAL(heightChanged(qreal)), this, SLOT(sceneHeightChanged(qreal)));
   setScene(_scene);
 
-  connect(verticalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(sliderPressed()));
-  connect(verticalScrollBar(), SIGNAL(sliderReleased()), this, SLOT(sliderReleased()));
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
 }
 
@@ -73,33 +70,16 @@ void ChatView::sceneHeightChanged(qreal h) {
   if(scrollable) verticalScrollBar()->setValue(verticalScrollBar()->maximum());
 }
 
-void ChatView::setBufferForBacklogFetching(BufferId id) {
-  scene()->setBufferForBacklogFetching(id);
-}
-
-void ChatView::sliderPressed() {
-  verticalScrollbarChanged(verticalScrollBar()->value());
-}
-
-void ChatView::sliderReleased() {
-  if(scene()->isFetchingBacklog()) scene()->setIsFetchingBacklog(false);
-}
-
 void ChatView::verticalScrollbarChanged(int newPos) {
-  Q_UNUSED(newPos);
-  if(!scene()->isBacklogFetchingEnabled()) return;
-
   QAbstractSlider *vbar = verticalScrollBar();
-  if(!vbar)
-    return;
-  if(vbar->isSliderDown()) {
-    /*
-    int relativePos = 100;
-    if(vbar->maximum() - vbar->minimum() != 0)
-      relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum());
-    scene()->setIsFetchingBacklog(relativePos < 20);
-    */
-    scene()->setIsFetchingBacklog(vbar->value() == vbar->minimum());
+  Q_ASSERT(vbar);
+
+  int relativePos = 100;
+  if(vbar->maximum() - vbar->minimum() != 0)
+    relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum());
+
+  if(relativePos < 20) {
+    scene()->requestBacklog();
   }
 }
 
@@ -111,6 +91,5 @@ MsgId ChatView::lastMsgId() const {
   if(!model || model->rowCount() == 0)
     return MsgId();
 
-  
   return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value<MsgId>();
 }
index 998d9fc..21367fe 100644 (file)
@@ -43,7 +43,6 @@ public:
 
 public slots:
   inline virtual void clear() {}
-  void setBufferForBacklogFetching(BufferId buffer);
 
 protected:
   virtual void resizeEvent(QResizeEvent *event);
@@ -51,8 +50,6 @@ protected:
 protected slots:
   virtual void sceneHeightChanged(qreal height);
   virtual void verticalScrollbarChanged(int);
-  virtual void sliderPressed();
-  virtual void sliderReleased();
   
 private:
   void init(MessageFilter *filter);