Backlog is dynamically called and replayed from the core.
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 18 Mar 2008 00:40:21 +0000 (00:40 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 18 Mar 2008 00:40:21 +0000 (00:40 +0000)
Just scroll further to the top of a buffer and more messages will be
replayed from the backlog. (breaking protocol)

src/core/SQL/SQLite/10/select_messagesOffset.sql
src/core/sqlitestorage.cpp
src/qtui/chatwidget.cpp
src/qtui/chatwidget.h
src/qtui/mainwin.cpp
version.inc

index 7c8795f..22d3998 100644 (file)
@@ -1,3 +1,3 @@
 SELECT count(*)
 FROM backlog
-WHERE bufferid = :bufferid AND messageid < :messageid
+WHERE bufferid = :bufferid AND messageid >= :messageid
index 3176ec4..fb90452 100644 (file)
@@ -619,13 +619,17 @@ QList<Message> SqliteStorage::requestMsgs(UserId user, BufferId bufferId, int la
   if(!bufferInfo.isValid())
     return messagelist;
 
-  // we have to determine the real offset first
-  QSqlQuery *offsetQuery = cachedQuery("select_messagesOffset");
-  offsetQuery->bindValue(":bufferid", bufferId.toInt());
-  offsetQuery->bindValue(":messageid", offset);
-  offsetQuery->exec();
-  offsetQuery->first();
-  offset = offsetQuery->value(0).toInt();
+  if(offset == -1) {
+    offset = 0;
+  } else {
+    // we have to determine the real offset first
+    QSqlQuery *offsetQuery = cachedQuery("select_messagesOffset");
+    offsetQuery->bindValue(":bufferid", bufferId.toInt());
+    offsetQuery->bindValue(":messageid", offset);
+    offsetQuery->exec();
+    offsetQuery->first();
+    offset = offsetQuery->value(0).toInt();
+  }
 
   // now let's select the messages
   QSqlQuery *msgQuery = cachedQuery("select_messages");
index 8a9b7a2..566de0d 100644 (file)
 #include "chatline-old.h"
 #include "qtui.h"
 #include "uisettings.h"
-
-ChatWidget::ChatWidget(QWidget *parent) : QAbstractScrollArea(parent) {
+#include "client.h"
+#include "buffer.h"
+#include "clientbacklogmanager.h"
+
+ChatWidget::ChatWidget(QWidget *parent)
+  : QAbstractScrollArea(parent),
+    lastBacklogOffset(0),
+    lastBacklogSize(0)
+{
   //setAutoFillBackground(false);
   //QPalette palette;
   //palette.setColor(backgroundRole(), QColor(0, 0, 0, 50));
@@ -67,6 +74,9 @@ void ChatWidget::init(BufferId id) {
   mouseMode = Normal;
   selectionMode = NoSelection;
   connect(scrollTimer, SIGNAL(timeout()), this, SLOT(handleScrollTimer()));
+
+  if(bufferId.isValid())
+    connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(viewportChanged(int)));
 }
 
 ChatWidget::~ChatWidget() {
@@ -590,3 +600,26 @@ QString ChatWidget::selectionToString() {
   return lines[selectionLine]->text().mid(selectionStart, selectionEnd - selectionStart);
 }
 
+void ChatWidget::viewportChanged(int newPos) {
+  const int REQUEST_COUNT = 50;
+  QAbstractSlider *vbar = verticalScrollBar();
+  if(!vbar)
+    return;
+
+  int relativePos = 100;
+  if(vbar->maximum() - vbar->minimum() != 0)
+    relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum());
+
+  if(relativePos < 20) {
+    Buffer *buffer = Client::buffer(bufferId);
+    Q_CHECK_PTR(buffer);
+    if(buffer->contents().isEmpty())
+      return;
+    MsgId msgId = buffer->contents().first()->msgId();
+    if(!lastBacklogOffset.isValid() || msgId < lastBacklogOffset && lastBacklogSize + REQUEST_COUNT <= buffer->contents().count()) {
+      Client::backlogManager()->requestBacklog(bufferId, REQUEST_COUNT, msgId.toInt());
+      lastBacklogOffset = msgId;
+      lastBacklogSize = buffer->contents().size();
+    }
+  }
+}
index 801203c..e7d1782 100644 (file)
@@ -76,6 +76,7 @@ class ChatWidget : public QAbstractScrollArea {
     void scrollBarValChanged(int);
     void ensureVisible(int line);
     void handleScrollTimer();
+    void viewportChanged(int newPos);
 
   private:
     BufferId bufferId;
@@ -120,6 +121,8 @@ class ChatWidget : public QAbstractScrollArea {
     QString selectionToString();
     void handleMouseMoveEvent(const QPoint &pos);
 
+    MsgId lastBacklogOffset;
+    int lastBacklogSize;
 };
 
 #endif
index d916771..1d1372d 100644 (file)
@@ -319,8 +319,7 @@ void MainWin::changeTopic(const QString &topic) {
 
 void MainWin::connectedToCore() {
   foreach(BufferInfo id, Client::allBufferInfos()) {
-    // emit requestBacklog(id, 1000, -1);
-    Client::backlogManager()->requestBacklog(id.bufferId(), 1000, -1);
+    Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
   }
 
   ui.menuViews->setEnabled(true);
index 9130de4..123dcfc 100644 (file)
@@ -4,15 +4,15 @@
 { using namespace Global;
 
   quasselVersion = "0.2.0-alpha4-pre";
-  quasselDate = "2008-03-16";
-  quasselBuild = 641;
+  quasselDate = "2008-03-18";
+  quasselBuild = 642;
 
   //! Minimum client build number the core needs
-  clientBuildNeeded = 641;
+  clientBuildNeeded = 642;
   clientVersionNeeded = quasselVersion;
 
   //! Minimum core build number the client needs
-  coreBuildNeeded = 641;
+  coreBuildNeeded = 642;
   coreVersionNeeded = quasselVersion;
 
 }