From 56b820e1a88c4d56dd9547a921f676bcfc7fb49e Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 30 Sep 2018 22:13:54 +0800 Subject: [PATCH] Update libqmatrixclient && add a progress bar. --- include/libqmatrixclient | 2 +- qml/form/RoomForm.qml | 18 ++++++++++++------ src/spectralroom.cpp | 7 +++++++ src/spectralroom.h | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/include/libqmatrixclient b/include/libqmatrixclient index f5651c7..5f2b4ca 160000 --- a/include/libqmatrixclient +++ b/include/libqmatrixclient @@ -1 +1 @@ -Subproject commit f5651c74ddddd8c66b3b42b471fbe2ff278c0d9a +Subproject commit 5f2b4caa9b9cd63e1652d6550ceebecdb52df424 diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index 57df8dd..6afc2d1 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -100,6 +100,14 @@ Item { } } + ProgressBar { + Layout.fillWidth: true + z: 10 + + visible: currentRoom && currentRoom.busy + indeterminate: true + } + ListView { Layout.fillWidth: true Layout.fillHeight: true @@ -122,11 +130,9 @@ Item { onContentYChanged: { // Check whether we're about to bump into the ceiling in 2 seconds var curVelocity = verticalVelocity // Snapshot the current speed - if(curVelocity < 0 && contentY + curVelocity*2 < originY) + if(curVelocity < 0 && contentY + curVelocity * 2 < originY) { - // Request the amount of messages enough to scroll at this - // rate for 3 more seconds - currentRoom.getPreviousContent(20); + currentRoom.getPreviousContent(50); } } @@ -159,8 +165,8 @@ Item { console.log("Scrolling to position", lastScrollPosition) messageListView.currentIndex = lastScrollPosition } - if (messageListView.contentY < messageListView.originY + 10) - currentRoom.getPreviousContent(100) + if (messageListView.contentY < messageListView.originY + 10 || currentRoom.timelineSize === 0) + currentRoom.getPreviousContent(50) } console.log("Model timeline reset") } diff --git a/src/spectralroom.cpp b/src/spectralroom.cpp index 151b9ba..1a5526d 100644 --- a/src/spectralroom.cpp +++ b/src/spectralroom.cpp @@ -17,6 +17,8 @@ SpectralRoom::SpectralRoom(Connection* connection, QString roomId, &SpectralRoom::countChanged); connect(this, &SpectralRoom::highlightCountChanged, this, &SpectralRoom::countChanged); + connect(this, &Room::addedMessages, this, + [=] { setBusy(false); }); } void SpectralRoom::chooseAndUploadFile() { @@ -175,3 +177,8 @@ void SpectralRoom::saveViewport(int topIndex, int bottomIndex) { setFirstDisplayedEvent(maxTimelineIndex() - topIndex); setLastDisplayedEvent(maxTimelineIndex() - bottomIndex); } + +void SpectralRoom::getPreviousContent(int limit) { + setBusy(true); + Room::getPreviousContent(limit); +} diff --git a/src/spectralroom.h b/src/spectralroom.h index 52f812e..75441a1 100644 --- a/src/spectralroom.h +++ b/src/spectralroom.h @@ -15,6 +15,8 @@ class SpectralRoom : public Room { Q_PROPERTY(QString usersTyping READ getUsersTyping NOTIFY typingChanged) Q_PROPERTY(QString cachedInput READ cachedInput WRITE setCachedInput NOTIFY cachedInputChanged) + Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) + public: explicit SpectralRoom(Connection* connection, QString roomId, JoinState joinState = {}); @@ -29,6 +31,14 @@ class SpectralRoom : public Room { } } + bool busy() { return m_busy; } + void setBusy(bool value) { + if (m_busy != value) { + m_busy = value; + emit busyChanged(); + } + } + bool hasUsersTyping(); QString getUsersTyping(); @@ -42,10 +52,14 @@ class SpectralRoom : public Room { Q_INVOKABLE int savedBottomVisibleIndex() const; Q_INVOKABLE void saveViewport(int topIndex, int bottomIndex); + Q_INVOKABLE void getPreviousContent(int limit = 10); + private: QString m_cachedInput; QSet highlights; + bool m_busy; + QString getMIME(const QUrl& fileUrl) const; void postFile(const QUrl& localFile, const QUrl& mxcUrl); @@ -59,6 +73,7 @@ class SpectralRoom : public Room { signals: void cachedInputChanged(); + void busyChanged(); public slots: void chooseAndUploadFile();