mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
parent
d1d8b92b37
commit
208f957911
8 changed files with 125 additions and 16 deletions
|
@ -40,6 +40,7 @@ class TimelineViewManager;
|
||||||
class TopRoomBar;
|
class TopRoomBar;
|
||||||
class TypingDisplay;
|
class TypingDisplay;
|
||||||
class UserInfoWidget;
|
class UserInfoWidget;
|
||||||
|
class UserSettings;
|
||||||
|
|
||||||
constexpr int CONSENSUS_TIMEOUT = 1000;
|
constexpr int CONSENSUS_TIMEOUT = 1000;
|
||||||
constexpr int SHOW_CONTENT_TIMEOUT = 3000;
|
constexpr int SHOW_CONTENT_TIMEOUT = 3000;
|
||||||
|
@ -50,7 +51,9 @@ class ChatPage : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
ChatPage(QSharedPointer<MatrixClient> client,
|
||||||
|
QSharedPointer<UserSettings> userSettings,
|
||||||
|
QWidget *parent = 0);
|
||||||
~ChatPage();
|
~ChatPage();
|
||||||
|
|
||||||
// Initialize all the components of the UI.
|
// Initialize all the components of the UI.
|
||||||
|
@ -150,6 +153,9 @@ private:
|
||||||
// Matrix Client API provider.
|
// Matrix Client API provider.
|
||||||
QSharedPointer<MatrixClient> client_;
|
QSharedPointer<MatrixClient> client_;
|
||||||
|
|
||||||
|
// Global user settings.
|
||||||
|
QSharedPointer<UserSettings> userSettings_;
|
||||||
|
|
||||||
// LMDB wrapper.
|
// LMDB wrapper.
|
||||||
QSharedPointer<Cache> cache_;
|
QSharedPointer<Cache> cache_;
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
|
|
||||||
void setAvatar(const QImage &avatar_image);
|
void setAvatar(const QImage &avatar_image);
|
||||||
void setDescriptionMessage(const DescInfo &info);
|
void setDescriptionMessage(const DescInfo &info);
|
||||||
|
DescInfo lastMessageInfo() const { return lastMsgInfo_; }
|
||||||
|
|
||||||
QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
|
QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
|
||||||
QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
|
QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
|
||||||
|
|
|
@ -36,6 +36,7 @@ class RoomInfoListItem;
|
||||||
class RoomSettings;
|
class RoomSettings;
|
||||||
class RoomState;
|
class RoomState;
|
||||||
class Sync;
|
class Sync;
|
||||||
|
class UserSettings;
|
||||||
struct DescInfo;
|
struct DescInfo;
|
||||||
|
|
||||||
class RoomList : public QWidget
|
class RoomList : public QWidget
|
||||||
|
@ -43,7 +44,9 @@ class RoomList : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RoomList(QSharedPointer<MatrixClient> client, QWidget *parent = 0);
|
RoomList(QSharedPointer<MatrixClient> client,
|
||||||
|
QSharedPointer<UserSettings> userSettings,
|
||||||
|
QWidget *parent = 0);
|
||||||
~RoomList();
|
~RoomList();
|
||||||
|
|
||||||
void setCache(QSharedPointer<Cache> cache) { cache_ = cache; }
|
void setCache(QSharedPointer<Cache> cache) { cache_ = cache; }
|
||||||
|
@ -81,6 +84,10 @@ public slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
void leaveEvent(QEvent *event) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void sortRoomsByLastMessage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void calculateUnreadMessageCount();
|
void calculateUnreadMessageCount();
|
||||||
|
@ -101,4 +108,7 @@ private:
|
||||||
|
|
||||||
QSharedPointer<MatrixClient> client_;
|
QSharedPointer<MatrixClient> client_;
|
||||||
QSharedPointer<Cache> cache_;
|
QSharedPointer<Cache> cache_;
|
||||||
|
QSharedPointer<UserSettings> userSettings_;
|
||||||
|
|
||||||
|
bool isSortPending_ = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,14 +38,26 @@ public:
|
||||||
void load();
|
void load();
|
||||||
void applyTheme();
|
void applyTheme();
|
||||||
void setTheme(QString theme);
|
void setTheme(QString theme);
|
||||||
void setTray(bool state);
|
void setTray(bool state)
|
||||||
|
{
|
||||||
|
isTrayEnabled_ = state;
|
||||||
|
save();
|
||||||
|
};
|
||||||
|
|
||||||
|
void setRoomOrdering(bool state)
|
||||||
|
{
|
||||||
|
isOrderingEnabled_ = state;
|
||||||
|
save();
|
||||||
|
};
|
||||||
|
|
||||||
QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; }
|
QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; }
|
||||||
bool isTrayEnabled() const { return isTrayEnabled_; }
|
bool isTrayEnabled() const { return isTrayEnabled_; }
|
||||||
|
bool isOrderingEnabled() const { return isOrderingEnabled_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString theme_;
|
QString theme_;
|
||||||
bool isTrayEnabled_;
|
bool isTrayEnabled_;
|
||||||
|
bool isOrderingEnabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HorizontalLine : public QFrame
|
class HorizontalLine : public QFrame
|
||||||
|
@ -84,6 +96,8 @@ private:
|
||||||
QSharedPointer<UserSettings> settings_;
|
QSharedPointer<UserSettings> settings_;
|
||||||
|
|
||||||
Toggle *trayToggle_;
|
Toggle *trayToggle_;
|
||||||
|
Toggle *roomOrderToggle_;
|
||||||
|
|
||||||
QComboBox *themeCombo_;
|
QComboBox *themeCombo_;
|
||||||
|
|
||||||
int sideMargin_ = 0;
|
int sideMargin_ = 0;
|
||||||
|
|
|
@ -37,15 +37,19 @@
|
||||||
#include "TopRoomBar.h"
|
#include "TopRoomBar.h"
|
||||||
#include "TypingDisplay.h"
|
#include "TypingDisplay.h"
|
||||||
#include "UserInfoWidget.h"
|
#include "UserInfoWidget.h"
|
||||||
|
#include "UserSettingsPage.h"
|
||||||
|
|
||||||
#include "timeline/TimelineViewManager.h"
|
#include "timeline/TimelineViewManager.h"
|
||||||
|
|
||||||
constexpr int MAX_INITIAL_SYNC_FAILURES = 5;
|
constexpr int MAX_INITIAL_SYNC_FAILURES = 5;
|
||||||
constexpr int SYNC_RETRY_TIMEOUT = 10000;
|
constexpr int SYNC_RETRY_TIMEOUT = 10000;
|
||||||
|
|
||||||
ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
|
||||||
|
QSharedPointer<UserSettings> userSettings,
|
||||||
|
QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, client_(client)
|
, client_(client)
|
||||||
|
, userSettings_{userSettings}
|
||||||
{
|
{
|
||||||
setObjectName("chatPage");
|
setObjectName("chatPage");
|
||||||
|
|
||||||
|
@ -74,7 +78,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
sidebarActions_, &SideBarActions::createRoom, client_.data(), &MatrixClient::createRoom);
|
sidebarActions_, &SideBarActions::createRoom, client_.data(), &MatrixClient::createRoom);
|
||||||
|
|
||||||
user_info_widget_ = new UserInfoWidget(sideBar_);
|
user_info_widget_ = new UserInfoWidget(sideBar_);
|
||||||
room_list_ = new RoomList(client, sideBar_);
|
room_list_ = new RoomList(client, userSettings_, sideBar_);
|
||||||
|
|
||||||
sideBarLayout_->addWidget(user_info_widget_);
|
sideBarLayout_->addWidget(user_info_widget_);
|
||||||
sideBarLayout_->addWidget(room_list_);
|
sideBarLayout_->addWidget(room_list_);
|
||||||
|
|
|
@ -58,7 +58,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
welcome_page_ = new WelcomePage(this);
|
welcome_page_ = new WelcomePage(this);
|
||||||
login_page_ = new LoginPage(client_, this);
|
login_page_ = new LoginPage(client_, this);
|
||||||
register_page_ = new RegisterPage(client_, this);
|
register_page_ = new RegisterPage(client_, this);
|
||||||
chat_page_ = new ChatPage(client_, this);
|
chat_page_ = new ChatPage(client_, userSettings_, this);
|
||||||
userSettingsPage_ = new UserSettingsPage(userSettings_, this);
|
userSettingsPage_ = new UserSettingsPage(userSettings_, this);
|
||||||
|
|
||||||
// Initialize sliding widget manager.
|
// Initialize sliding widget manager.
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
@ -27,10 +28,14 @@
|
||||||
#include "RoomList.h"
|
#include "RoomList.h"
|
||||||
#include "RoomSettings.h"
|
#include "RoomSettings.h"
|
||||||
#include "RoomState.h"
|
#include "RoomState.h"
|
||||||
|
#include "UserSettingsPage.h"
|
||||||
|
|
||||||
RoomList::RoomList(QSharedPointer<MatrixClient> client, QWidget *parent)
|
RoomList::RoomList(QSharedPointer<MatrixClient> client,
|
||||||
|
QSharedPointer<UserSettings> userSettings,
|
||||||
|
QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, client_(client)
|
, client_(client)
|
||||||
|
, userSettings_{userSettings}
|
||||||
{
|
{
|
||||||
setStyleSheet("border: none;");
|
setStyleSheet("border: none;");
|
||||||
topLayout_ = new QVBoxLayout(this);
|
topLayout_ = new QVBoxLayout(this);
|
||||||
|
@ -291,6 +296,61 @@ RoomList::updateRoomDescription(const QString &roomid, const DescInfo &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
rooms_.value(roomid)->setDescriptionMessage(info);
|
rooms_.value(roomid)->setDescriptionMessage(info);
|
||||||
|
|
||||||
|
if (underMouse()) {
|
||||||
|
// When the user hover out of the roomlist a sort will be triggered.
|
||||||
|
isSortPending_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isSortPending_ = false;
|
||||||
|
|
||||||
|
emit sortRoomsByLastMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RoomList::sortRoomsByLastMessage()
|
||||||
|
{
|
||||||
|
if (!userSettings_->isOrderingEnabled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
isSortPending_ = false;
|
||||||
|
|
||||||
|
std::multimap<uint64_t, RoomInfoListItem *, std::greater<uint64_t>> times;
|
||||||
|
|
||||||
|
for (int ii = 0; ii < contentsLayout_->count(); ++ii) {
|
||||||
|
auto room = qobject_cast<RoomInfoListItem *>(contentsLayout_->itemAt(ii)->widget());
|
||||||
|
|
||||||
|
if (!room)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Not a room message.
|
||||||
|
if (room->lastMessageInfo().userid.isEmpty())
|
||||||
|
times.emplace(0, room);
|
||||||
|
else
|
||||||
|
times.emplace(room->lastMessageInfo().datetime.toSecsSinceEpoch(), room);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = times.cbegin(); it != times.cend(); ++it) {
|
||||||
|
const auto roomWidget = it->second;
|
||||||
|
const auto currentIndex = contentsLayout_->indexOf(roomWidget);
|
||||||
|
const auto newIndex = std::distance(times.cbegin(), it);
|
||||||
|
|
||||||
|
if (currentIndex == newIndex)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
contentsLayout_->removeWidget(roomWidget);
|
||||||
|
contentsLayout_->insertWidget(newIndex, roomWidget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RoomList::leaveEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if (isSortPending_)
|
||||||
|
QTimer::singleShot(700, this, &RoomList::sortRoomsByLastMessage);
|
||||||
|
|
||||||
|
QWidget::leaveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -34,6 +34,7 @@ UserSettings::load()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
isTrayEnabled_ = settings.value("user/window/tray", true).toBool();
|
isTrayEnabled_ = settings.value("user/window/tray", true).toBool();
|
||||||
|
isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool();
|
||||||
theme_ = settings.value("user/theme", "light").toString();
|
theme_ = settings.value("user/theme", "light").toString();
|
||||||
|
|
||||||
applyTheme();
|
applyTheme();
|
||||||
|
@ -47,12 +48,6 @@ UserSettings::setTheme(QString theme)
|
||||||
applyTheme();
|
applyTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
UserSettings::setTray(bool state)
|
|
||||||
{
|
|
||||||
isTrayEnabled_ = state;
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
void
|
void
|
||||||
UserSettings::applyTheme()
|
UserSettings::applyTheme()
|
||||||
{
|
{
|
||||||
|
@ -86,6 +81,7 @@ UserSettings::save()
|
||||||
settings.setValue("tray", isTrayEnabled_);
|
settings.setValue("tray", isTrayEnabled_);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
|
settings.setValue("room_ordering", isOrderingEnabled_);
|
||||||
settings.setValue("theme", theme());
|
settings.setValue("theme", theme());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
@ -132,6 +128,17 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
trayOptionLayout_->addWidget(trayLabel);
|
trayOptionLayout_->addWidget(trayLabel);
|
||||||
trayOptionLayout_->addWidget(trayToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
|
trayOptionLayout_->addWidget(trayToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||||
|
|
||||||
|
auto orderRoomLayout = new QHBoxLayout;
|
||||||
|
orderRoomLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||||
|
auto orderLabel = new QLabel(tr("Re-order rooms based on activity"), this);
|
||||||
|
roomOrderToggle_ = new Toggle(this);
|
||||||
|
roomOrderToggle_->setActiveColor(QColor("#38A3D8"));
|
||||||
|
roomOrderToggle_->setInactiveColor(QColor("gray"));
|
||||||
|
orderLabel->setStyleSheet("font-size: 15px;");
|
||||||
|
|
||||||
|
orderRoomLayout->addWidget(orderLabel);
|
||||||
|
orderRoomLayout->addWidget(roomOrderToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||||
|
|
||||||
auto themeOptionLayout_ = new QHBoxLayout;
|
auto themeOptionLayout_ = new QHBoxLayout;
|
||||||
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||||
auto themeLabel_ = new QLabel(tr("App theme"), this);
|
auto themeLabel_ = new QLabel(tr("App theme"), this);
|
||||||
|
@ -155,6 +162,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
mainLayout_->addLayout(trayOptionLayout_);
|
mainLayout_->addLayout(trayOptionLayout_);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
mainLayout_->addLayout(orderRoomLayout);
|
||||||
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
mainLayout_->addLayout(themeOptionLayout_);
|
mainLayout_->addLayout(themeOptionLayout_);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
|
||||||
|
@ -171,6 +180,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
emit trayOptionChanged(!isDisabled);
|
emit trayOptionChanged(!isDisabled);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(roomOrderToggle_, &Toggle::toggled, this, [=](bool isDisabled) {
|
||||||
|
settings_->setRoomOrdering(!isDisabled);
|
||||||
|
});
|
||||||
|
|
||||||
connect(backBtn_, &QPushButton::clicked, this, [=]() {
|
connect(backBtn_, &QPushButton::clicked, this, [=]() {
|
||||||
settings_->save();
|
settings_->save();
|
||||||
emit moveBack();
|
emit moveBack();
|
||||||
|
@ -182,6 +195,7 @@ UserSettingsPage::showEvent(QShowEvent *)
|
||||||
{
|
{
|
||||||
restoreThemeCombo();
|
restoreThemeCombo();
|
||||||
trayToggle_->setState(!settings_->isTrayEnabled()); // Treats true as "off"
|
trayToggle_->setState(!settings_->isTrayEnabled()); // Treats true as "off"
|
||||||
|
roomOrderToggle_->setState(!settings_->isOrderingEnabled()); // Treats true as "off"
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue