From 5319f3fbe69a63d1599107e0fc77ae325e4a9b6d Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Tue, 18 Mar 2008 00:40:21 +0000 Subject: [PATCH] Backlog is dynamically called and replayed from the core. Just scroll further to the top of a buffer and more messages will be replayed from the backlog. (breaking protocol) --- .../SQL/SQLite/10/select_messagesOffset.sql | 2 +- src/core/sqlitestorage.cpp | 18 +++++---- src/qtui/chatwidget.cpp | 37 ++++++++++++++++++- src/qtui/chatwidget.h | 3 ++ src/qtui/mainwin.cpp | 3 +- version.inc | 8 ++-- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/core/SQL/SQLite/10/select_messagesOffset.sql b/src/core/SQL/SQLite/10/select_messagesOffset.sql index 7c8795f2..22d39986 100644 --- a/src/core/SQL/SQLite/10/select_messagesOffset.sql +++ b/src/core/SQL/SQLite/10/select_messagesOffset.sql @@ -1,3 +1,3 @@ SELECT count(*) FROM backlog -WHERE bufferid = :bufferid AND messageid < :messageid +WHERE bufferid = :bufferid AND messageid >= :messageid diff --git a/src/core/sqlitestorage.cpp b/src/core/sqlitestorage.cpp index 3176ec4b..fb904524 100644 --- a/src/core/sqlitestorage.cpp +++ b/src/core/sqlitestorage.cpp @@ -619,13 +619,17 @@ QList 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"); diff --git a/src/qtui/chatwidget.cpp b/src/qtui/chatwidget.cpp index 8a9b7a2f..566de0d8 100644 --- a/src/qtui/chatwidget.cpp +++ b/src/qtui/chatwidget.cpp @@ -23,8 +23,15 @@ #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(); + } + } +} diff --git a/src/qtui/chatwidget.h b/src/qtui/chatwidget.h index 801203c3..e7d1782b 100644 --- a/src/qtui/chatwidget.h +++ b/src/qtui/chatwidget.h @@ -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 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index d916771a..1d1372da 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -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); diff --git a/version.inc b/version.inc index 9130de4f..123dcfc2 100644 --- a/version.inc +++ b/version.inc @@ -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; } -- 2.20.1