From 567fe81ad78e707a4b914976a92c855d4ac8fc45 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 14 May 2021 23:35:34 +0200 Subject: [PATCH] Basic header and footer of room list --- resources/qml/ChatPage.qml | 17 +-- resources/qml/RoomList.qml | 183 +++++++++++++++++++++++++++++++++ resources/qml/TimelineView.qml | 4 +- resources/qml/TopBar.qml | 4 +- resources/res.qrc | 1 + src/Cache.cpp | 29 ++++-- src/Cache_p.h | 3 + src/CommunitiesList.h | 1 - src/CommunitiesListItem.h | 1 - src/MainWindow.cpp | 1 + src/MainWindow.h | 1 + src/UserSettingsPage.cpp | 37 +------ src/ui/NhekoGlobalObject.cpp | 33 +++++- src/ui/NhekoGlobalObject.h | 16 ++- src/ui/Theme.cpp | 119 ++++++++++----------- src/ui/Theme.h | 38 ++----- src/ui/ThemeManager.cpp | 39 +++++-- src/ui/ThemeManager.h | 5 - src/ui/UserProfile.cpp | 28 +++-- 19 files changed, 385 insertions(+), 175 deletions(-) create mode 100644 resources/qml/RoomList.qml diff --git a/resources/qml/ChatPage.qml b/resources/qml/ChatPage.qml index a02f0ca9..fc6137a6 100644 --- a/resources/qml/ChatPage.qml +++ b/resources/qml/ChatPage.qml @@ -19,14 +19,14 @@ Rectangle { SplitView.minimumWidth: Nheko.avatarSize + Nheko.paddingSmall * 2 SplitView.preferredWidth: Nheko.avatarSize + Nheko.paddingSmall * 2 SplitView.maximumWidth: Nheko.avatarSize + Nheko.paddingSmall * 2 - color: "blue" + color: Nheko.theme.sidebarBackground } - Rectangle { - SplitView.minimumWidth: Nheko.avatarSize * 3 + Nheko.paddingSmall * 2 - SplitView.preferredWidth: Nheko.avatarSize * 3 + Nheko.paddingSmall * 2 - SplitView.maximumWidth: Nheko.avatarSize * 7 + Nheko.paddingSmall * 2 - color: "red" + RoomList { + //SplitView.maximumWidth: Nheko.avatarSize * 7 + Nheko.paddingSmall * 2 + + SplitView.minimumWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2 + SplitView.preferredWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2 } TimelineView { @@ -36,6 +36,11 @@ Rectangle { SplitView.minimumWidth: 400 } + handle: Rectangle { + implicitWidth: 2 + color: SplitHandle.pressed ? Nheko.colors.highlight : (SplitHandle.hovered ? Nheko.colors.light : Nheko.theme.separator) + } + } PrivacyScreen { diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml new file mode 100644 index 00000000..25abb4d1 --- /dev/null +++ b/resources/qml/RoomList.qml @@ -0,0 +1,183 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import QtQuick 2.9 +import QtQuick.Controls 2.13 +import QtQuick.Layouts 1.3 +import im.nheko 1.0 + +Page { + + background: Rectangle { + color: Nheko.theme.sidebarBackground + } + + header: ColumnLayout { + spacing: 0 + + Rectangle { + color: Nheko.colors.window + Layout.fillWidth: true + Layout.alignment: Qt.AlignBottom + Layout.preferredHeight: userInfoGrid.implicitHeight + 2 * Nheko.paddingMedium + Layout.minimumHeight: 40 + + RowLayout { + id: userInfoGrid + + spacing: Nheko.paddingMedium + anchors.fill: parent + anchors.margins: Nheko.paddingMedium + + Avatar { + id: avatar + + Layout.alignment: Qt.AlignVCenter + Layout.preferredWidth: Nheko.avatarSize + Layout.preferredHeight: Nheko.avatarSize + url: Nheko.currentUser.avatarUrl.replace("mxc://", "image://MxcImage/") + displayName: Nheko.currentUser.displayName + userid: Nheko.currentUser.userid + } + + ColumnLayout { + id: col + + Layout.alignment: Qt.AlignLeft + Layout.fillWidth: true + Layout.minimumWidth: 100 + width: parent.width - avatar.width - logoutButton.width + Layout.preferredWidth: parent.width - avatar.width - logoutButton.width + spacing: 0 + + Label { + Layout.alignment: Qt.AlignBottom + color: Nheko.colors.text + font.pointSize: fontMetrics.font.pointSize * 1.1 + font.weight: Font.DemiBold + text: userNameText.elidedText + maximumLineCount: 1 + elide: Text.ElideRight + textFormat: Text.PlainText + + TextMetrics { + id: userNameText + + font.pointSize: fontMetrics.font.pointSize * 1.1 + elide: Text.ElideRight + elideWidth: col.width + text: Nheko.currentUser.displayName + } + + } + + Label { + Layout.alignment: Qt.AlignTop + color: Nheko.colors.buttonText + font.weight: Font.Thin + text: userIdText.elidedText + maximumLineCount: 1 + textFormat: Text.PlainText + font.pointSize: fontMetrics.font.pointSize * 0.9 + + TextMetrics { + id: userIdText + + font.pointSize: fontMetrics.font.pointSize * 0.9 + elide: Text.ElideRight + elideWidth: col.width + text: Nheko.currentUser.userid + } + + } + + } + + Item { + } + + ImageButton { + id: logoutButton + + Layout.alignment: Qt.AlignVCenter + image: ":/icons/icons/ui/power-button-off.png" + ToolTip.visible: hovered + ToolTip.text: qsTr("Logout") + } + + } + + } + + Rectangle { + color: Nheko.theme.separator + height: 2 + Layout.fillWidth: true + } + + } + + footer: ColumnLayout { + spacing: 0 + + Rectangle { + color: Nheko.theme.separator + height: 1 + Layout.fillWidth: true + } + + Rectangle { + color: Nheko.colors.window + Layout.fillWidth: true + Layout.alignment: Qt.AlignBottom + Layout.preferredHeight: buttonRow.implicitHeight + Layout.minimumHeight: 40 + + RowLayout { + id: buttonRow + + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: Nheko.paddingMedium + + ImageButton { + Layout.alignment: Qt.AlignBottom | Qt.AlignLeft + hoverEnabled: true + width: 22 + height: 22 + image: ":/icons/icons/ui/plus-black-symbol.png" + ToolTip.visible: hovered + ToolTip.text: qsTr("Start a new chat") + Layout.margins: Nheko.paddingMedium + } + + ImageButton { + Layout.alignment: Qt.AlignBottom | Qt.AlignHCenter + hoverEnabled: true + width: 22 + height: 22 + image: ":/icons/icons/ui/speech-bubbles-comment-option.png" + ToolTip.visible: hovered + ToolTip.text: qsTr("Room directory") + Layout.margins: Nheko.paddingMedium + } + + ImageButton { + Layout.alignment: Qt.AlignBottom | Qt.AlignRight + hoverEnabled: true + width: 22 + height: 22 + image: ":/icons/icons/ui/settings.png" + ToolTip.visible: hovered + ToolTip.text: qsTr("User settings") + Layout.margins: Nheko.paddingMedium + } + + } + + } + + } + +} diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 0d0e286d..257d670d 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -49,7 +49,7 @@ Item { Layout.fillWidth: true height: 1 z: 3 - color: Nheko.colors.mid + color: Nheko.theme.separator } Rectangle { @@ -112,7 +112,7 @@ Item { Layout.fillWidth: true z: 3 height: 1 - color: Nheko.colors.mid + color: Nheko.theme.separator } ReplyPopup { diff --git a/resources/qml/TopBar.qml b/resources/qml/TopBar.qml index d5bcb3a8..bda5ce14 100644 --- a/resources/qml/TopBar.qml +++ b/resources/qml/TopBar.qml @@ -14,7 +14,7 @@ Rectangle { property var room: TimelineManager.timeline Layout.fillWidth: true - implicitHeight: topLayout.height + 16 + implicitHeight: topLayout.height + Nheko.paddingMedium * 2 z: 3 color: Nheko.colors.window @@ -33,7 +33,7 @@ Rectangle { anchors.left: parent.left anchors.right: parent.right - anchors.margins: 8 + anchors.margins: Nheko.paddingMedium anchors.verticalCenter: parent.verticalCenter ImageButton { diff --git a/resources/res.qrc b/resources/res.qrc index 8105e966..c146f2d9 100644 --- a/resources/res.qrc +++ b/resources/res.qrc @@ -125,6 +125,7 @@ qml/Root.qml qml/ChatPage.qml + qml/RoomList.qml qml/TimelineView.qml qml/Avatar.qml qml/Completer.qml diff --git a/src/Cache.cpp b/src/Cache.cpp index 24b2bc24..d8c78381 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -253,6 +253,8 @@ Cache::setup() outboundMegolmSessionDb_ = lmdb::dbi::open(txn, OUTBOUND_MEGOLM_SESSIONS_DB, MDB_CREATE); txn.commit(); + + databaseReady_ = true; } void @@ -788,6 +790,7 @@ Cache::nextBatchToken() void Cache::deleteData() { + this->databaseReady_ = false; // TODO: We need to remove the env_ while not accepting new requests. lmdb::dbi_close(env_, syncStateDb_); lmdb::dbi_close(env_, roomsDb_); @@ -2426,7 +2429,7 @@ Cache::joinedRooms() std::optional Cache::getMember(const std::string &room_id, const std::string &user_id) { - if (user_id.empty()) + if (user_id.empty() || !env_.handle()) return std::nullopt; try { @@ -3551,8 +3554,8 @@ Cache::query_keys(const std::string &user_id, http::client()->query_keys( req, - [cb, user_id, last_changed](const mtx::responses::QueryKeys &res, - mtx::http::RequestErr err) { + [cb, user_id, last_changed, this](const mtx::responses::QueryKeys &res, + mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to query device keys: {},{}", mtx::errors::to_string(err->matrix_error.errcode), @@ -3561,10 +3564,22 @@ Cache::query_keys(const std::string &user_id, return; } - cache::updateUserKeys(last_changed, res); + emit userKeysUpdate(last_changed, res); - auto keys = cache::userKeys(user_id); - cb(keys.value_or(UserKeyCache{}), err); + // use context object so that we can disconnect again + std::unique_ptr context{new QObject}; + QObject *pcontext = context.get(); + QObject::connect( + this, + &Cache::verificationStatusChanged, + pcontext, + [cb, user_id, context_ = std::move(context)](std::string updated_user) mutable { + if (user_id == updated_user) { + context_.release(); + auto keys = cache::userKeys(user_id); + cb(keys.value_or(UserKeyCache{}), {}); + } + }); }); } @@ -3999,6 +4014,8 @@ avatarUrl(const QString &room_id, const QString &user_id) mtx::presence::PresenceState presenceState(const std::string &user_id) { + if (!instance_) + return {}; return instance_->presenceState(user_id); } std::string diff --git a/src/Cache_p.h b/src/Cache_p.h index 356c6e42..c55fa601 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -100,6 +100,7 @@ public: void saveState(const mtx::responses::Sync &res); bool isInitialized(); + bool isDatabaseReady() { return databaseReady_ && isInitialized(); } std::string nextBatchToken(); @@ -620,6 +621,8 @@ private: QString cacheDirectory_; VerificationStorage verification_storage; + + bool databaseReady_ = false; }; namespace cache { diff --git a/src/CommunitiesList.h b/src/CommunitiesList.h index 2586f6f5..12b275b0 100644 --- a/src/CommunitiesList.h +++ b/src/CommunitiesList.h @@ -10,7 +10,6 @@ #include "CacheStructs.h" #include "CommunitiesListItem.h" -#include "ui/Theme.h" namespace mtx::responses { struct GroupProfile; diff --git a/src/CommunitiesListItem.h b/src/CommunitiesListItem.h index 006511c8..e7468611 100644 --- a/src/CommunitiesListItem.h +++ b/src/CommunitiesListItem.h @@ -10,7 +10,6 @@ #include #include "Config.h" -#include "ui/Theme.h" class RippleOverlay; class QMouseEvent; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 92f43e03..e2b625b0 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -295,6 +295,7 @@ MainWindow::showChatPage() &Cache::secretChanged, userSettingsPage_, &UserSettingsPage::updateSecretStatus); + emit reload(); } void diff --git a/src/MainWindow.h b/src/MainWindow.h index 4122e4c1..69d07e62 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -109,6 +109,7 @@ private slots: signals: void focusChanged(const bool focused); + void reload(); private: bool loadJdenticonPlugin(); diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 0edc1288..99560678 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -545,49 +545,14 @@ UserSettings::applyTheme() { QFile stylefile; - static QPalette original; if (this->theme() == "light") { stylefile.setFileName(":/styles/styles/nheko.qss"); - QPalette lightActive( - /*windowText*/ QColor("#333"), - /*button*/ QColor("white"), - /*light*/ QColor(0xef, 0xef, 0xef), - /*dark*/ QColor(110, 110, 110), - /*mid*/ QColor(220, 220, 220), - /*text*/ QColor("#333"), - /*bright_text*/ QColor("#333"), - /*base*/ QColor("#fff"), - /*window*/ QColor("white")); - lightActive.setColor(QPalette::AlternateBase, QColor("#eee")); - lightActive.setColor(QPalette::Highlight, QColor("#38a3d8")); - lightActive.setColor(QPalette::ToolTipBase, lightActive.base().color()); - lightActive.setColor(QPalette::ToolTipText, lightActive.text().color()); - lightActive.setColor(QPalette::Link, QColor("#0077b5")); - lightActive.setColor(QPalette::ButtonText, QColor("#333")); - QApplication::setPalette(lightActive); } else if (this->theme() == "dark") { stylefile.setFileName(":/styles/styles/nheko-dark.qss"); - QPalette darkActive( - /*windowText*/ QColor("#caccd1"), - /*button*/ QColor(0xff, 0xff, 0xff), - /*light*/ QColor("#caccd1"), - /*dark*/ QColor(110, 110, 110), - /*mid*/ QColor("#202228"), - /*text*/ QColor("#caccd1"), - /*bright_text*/ QColor(0xff, 0xff, 0xff), - /*base*/ QColor("#202228"), - /*window*/ QColor("#2d3139")); - darkActive.setColor(QPalette::AlternateBase, QColor("#2d3139")); - darkActive.setColor(QPalette::Highlight, QColor("#38a3d8")); - darkActive.setColor(QPalette::ToolTipBase, darkActive.base().color()); - darkActive.setColor(QPalette::ToolTipText, darkActive.text().color()); - darkActive.setColor(QPalette::Link, QColor("#38a3d8")); - darkActive.setColor(QPalette::ButtonText, "#727274"); - QApplication::setPalette(darkActive); } else { stylefile.setFileName(":/styles/styles/system.qss"); - QApplication::setPalette(original); } + QApplication::setPalette(Theme::paletteFromTheme(this->theme().toStdString())); stylefile.open(QFile::ReadOnly); QString stylesheet = QString(stylefile.readAll()); diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp index e5e6825e..70abfbb8 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp @@ -7,29 +7,50 @@ #include #include +#include "Cache_p.h" #include "ChatPage.h" +#include "Logging.h" #include "UserSettingsPage.h" +#include "Utils.h" Nheko::Nheko() { connect( UserSettings::instance().get(), &UserSettings::themeChanged, this, &Nheko::colorsChanged); + connect(ChatPage::instance(), &ChatPage::contentLoaded, this, &Nheko::updateUserProfile); +} + +void +Nheko::updateUserProfile() +{ + if (cache::client() && cache::client()->isInitialized()) + currentUser_.reset( + new UserProfile("", utils::localUser(), ChatPage::instance()->timelineManager())); + else + currentUser_.reset(); + emit profileChanged(); } QPalette Nheko::colors() const { - return QPalette(); + return Theme::paletteFromTheme(UserSettings::instance()->theme().toStdString()); } QPalette Nheko::inactiveColors() const { - QPalette p; + auto p = colors(); p.setCurrentColorGroup(QPalette::ColorGroup::Inactive); return p; } +Theme +Nheko::theme() const +{ + return Theme(UserSettings::instance()->theme().toStdString()); +} + void Nheko::openLink(QString link) const { @@ -79,3 +100,11 @@ Nheko::openLink(QString link) const QDesktopServices::openUrl(url); } } + +UserProfile * +Nheko::currentUser() const +{ + nhlog::ui()->debug("Profile requested"); + + return currentUser_.get(); +} diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index d952c266..fe645a34 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -7,32 +7,46 @@ #include #include +#include "Theme.h" +#include "UserProfile.h" + class Nheko : public QObject { Q_OBJECT Q_PROPERTY(QPalette colors READ colors NOTIFY colorsChanged) Q_PROPERTY(QPalette inactiveColors READ inactiveColors NOTIFY colorsChanged) + Q_PROPERTY(Theme theme READ theme NOTIFY colorsChanged) Q_PROPERTY(int avatarSize READ avatarSize CONSTANT) Q_PROPERTY(int paddingSmall READ paddingSmall CONSTANT) Q_PROPERTY(int paddingMedium READ paddingMedium CONSTANT) Q_PROPERTY(int paddingLarge READ paddingLarge CONSTANT) + Q_PROPERTY(UserProfile *currentUser READ currentUser NOTIFY profileChanged) + public: Nheko(); QPalette colors() const; QPalette inactiveColors() const; + Theme theme() const; int avatarSize() const { return 40; } int paddingSmall() const { return 4; } int paddingMedium() const { return 8; } int paddingLarge() const { return 20; } + UserProfile *currentUser() const; Q_INVOKABLE void openLink(QString link) const; +private slots: + void updateUserProfile(); + signals: void colorsChanged(); -}; + void profileChanged(); +private: + QScopedPointer currentUser_; +}; diff --git a/src/ui/Theme.cpp b/src/ui/Theme.cpp index 4341bd63..ca2a4ce0 100644 --- a/src/ui/Theme.cpp +++ b/src/ui/Theme.cpp @@ -2,76 +2,65 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -#include - #include "Theme.h" -Theme::Theme(QObject *parent) - : QObject(parent) +Q_DECLARE_METATYPE(Theme) + +QPalette +Theme::paletteFromTheme(std::string_view theme) { - setColor("Black", ui::Color::Black); - - setColor("BrightWhite", ui::Color::BrightWhite); - setColor("FadedWhite", ui::Color::FadedWhite); - setColor("MediumWhite", ui::Color::MediumWhite); - - setColor("BrightGreen", ui::Color::BrightGreen); - setColor("DarkGreen", ui::Color::DarkGreen); - setColor("LightGreen", ui::Color::LightGreen); - - setColor("Gray", ui::Color::Gray); - setColor("Red", ui::Color::Red); - setColor("Blue", ui::Color::Blue); - - setColor("Transparent", ui::Color::Transparent); -} - -QColor -Theme::rgba(int r, int g, int b, qreal a) const -{ - QColor color(r, g, b); - color.setAlphaF(a); - - return color; -} - -QColor -Theme::getColor(const QString &key) const -{ - if (!colors_.contains(key)) { - qWarning() << "Color with key" << key << "could not be found"; - return QColor(); + [[maybe_unused]] static auto meta = qRegisterMetaType("Theme"); + static QPalette original; + if (theme == "light") { + QPalette lightActive( + /*windowText*/ QColor("#333"), + /*button*/ QColor("white"), + /*light*/ QColor(0xef, 0xef, 0xef), + /*dark*/ QColor(110, 110, 110), + /*mid*/ QColor(220, 220, 220), + /*text*/ QColor("#333"), + /*bright_text*/ QColor("#333"), + /*base*/ QColor("#fff"), + /*window*/ QColor("white")); + lightActive.setColor(QPalette::AlternateBase, QColor("#eee")); + lightActive.setColor(QPalette::Highlight, QColor("#38a3d8")); + lightActive.setColor(QPalette::ToolTipBase, lightActive.base().color()); + lightActive.setColor(QPalette::ToolTipText, lightActive.text().color()); + lightActive.setColor(QPalette::Link, QColor("#0077b5")); + lightActive.setColor(QPalette::ButtonText, QColor("#555459")); + return lightActive; + } else if (theme == "dark") { + QPalette darkActive( + /*windowText*/ QColor("#caccd1"), + /*button*/ QColor(0xff, 0xff, 0xff), + /*light*/ QColor("#caccd1"), + /*dark*/ QColor(110, 110, 110), + /*mid*/ QColor("#202228"), + /*text*/ QColor("#caccd1"), + /*bright_text*/ QColor(0xff, 0xff, 0xff), + /*base*/ QColor("#202228"), + /*window*/ QColor("#2d3139")); + darkActive.setColor(QPalette::AlternateBase, QColor("#2d3139")); + darkActive.setColor(QPalette::Highlight, QColor("#38a3d8")); + darkActive.setColor(QPalette::ToolTipBase, darkActive.base().color()); + darkActive.setColor(QPalette::ToolTipText, darkActive.text().color()); + darkActive.setColor(QPalette::Link, QColor("#38a3d8")); + darkActive.setColor(QPalette::ButtonText, "#727274"); + return darkActive; + } else { + return original; } - - return colors_.value(key); } -void -Theme::setColor(const QString &key, const QColor &color) +Theme::Theme(std::string_view theme) { - colors_.insert(key, color); -} - -void -Theme::setColor(const QString &key, ui::Color color) -{ - static const QColor palette[] = { - QColor("#171919"), - - QColor("#EBEBEB"), - QColor("#C9C9C9"), - QColor("#929292"), - - QColor("#1C3133"), - QColor("#577275"), - QColor("#46A451"), - - QColor("#5D6565"), - QColor("#E22826"), - QColor("#81B3A9"), - - rgba(0, 0, 0, 0), - }; - - colors_.insert(key, palette[static_cast(color)]); + auto p = paletteFromTheme(theme); + separator_ = p.mid().color(); + if (theme == "light") { + sidebarBackground_ = QColor("#233649"); + } else if (theme == "dark") { + sidebarBackground_ = QColor("#2d3139"); + } else { + sidebarBackground_ = p.window().color(); + } } diff --git a/src/ui/Theme.h b/src/ui/Theme.h index 3243c076..64bc8273 100644 --- a/src/ui/Theme.h +++ b/src/ui/Theme.h @@ -5,8 +5,7 @@ #pragma once #include -#include -#include +#include namespace ui { enum class AvatarType @@ -60,36 +59,21 @@ enum class ProgressType IndeterminateProgress }; -enum class Color -{ - Black, - BrightWhite, - FadedWhite, - MediumWhite, - DarkGreen, - LightGreen, - BrightGreen, - Gray, - Red, - Blue, - Transparent -}; - } // namespace ui -class Theme : public QObject +class Theme : public QPalette { - Q_OBJECT + Q_GADGET + Q_PROPERTY(QColor sidebarBackground READ sidebarBackground CONSTANT) + Q_PROPERTY(QColor separator READ separator CONSTANT) public: - explicit Theme(QObject *parent = nullptr); + Theme() {} + explicit Theme(std::string_view theme); + static QPalette paletteFromTheme(std::string_view theme); - QColor getColor(const QString &key) const; - - void setColor(const QString &key, const QColor &color); - void setColor(const QString &key, ui::Color color); + QColor sidebarBackground() const { return sidebarBackground_; } + QColor separator() const { return separator_; } private: - QColor rgba(int r, int g, int b, qreal a) const; - - QHash colors_; + QColor sidebarBackground_, separator_; }; diff --git a/src/ui/ThemeManager.cpp b/src/ui/ThemeManager.cpp index 834f5083..b7b3df40 100644 --- a/src/ui/ThemeManager.cpp +++ b/src/ui/ThemeManager.cpp @@ -6,18 +6,37 @@ #include "ThemeManager.h" -ThemeManager::ThemeManager() { setTheme(new Theme); } - -void -ThemeManager::setTheme(Theme *theme) -{ - theme_ = theme; - theme_->setParent(this); -} +ThemeManager::ThemeManager() {} QColor ThemeManager::themeColor(const QString &key) const { - Q_ASSERT(theme_); - return theme_->getColor(key); + if (key == "Black") + return QColor("#171919"); + + else if (key == "BrightWhite") + return QColor("#EBEBEB"); + else if (key == "FadedWhite") + return QColor("#C9C9C9"); + else if (key == "MediumWhite") + return QColor("#929292"); + + else if (key == "BrightGreen") + return QColor("#1C3133"); + else if (key == "DarkGreen") + return QColor("#577275"); + else if (key == "LightGreen") + return QColor("#46A451"); + + else if (key == "Gray") + return QColor("#5D6565"); + else if (key == "Red") + return QColor("#E22826"); + else if (key == "Blue") + return QColor("#81B3A9"); + + else if (key == "Transparent") + return QColor(0, 0, 0, 0); + + return (QColor(0, 0, 0, 0)); } diff --git a/src/ui/ThemeManager.h b/src/ui/ThemeManager.h index f2099730..cbb355fd 100644 --- a/src/ui/ThemeManager.h +++ b/src/ui/ThemeManager.h @@ -6,8 +6,6 @@ #include -#include "Theme.h" - class ThemeManager : public QCommonStyle { Q_OBJECT @@ -15,7 +13,6 @@ class ThemeManager : public QCommonStyle public: inline static ThemeManager &instance(); - void setTheme(Theme *theme); QColor themeColor(const QString &key) const; private: @@ -23,8 +20,6 @@ private: ThemeManager(ThemeManager const &); void operator=(ThemeManager const &); - - Theme *theme_; }; inline ThemeManager & diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 0f330964..cef8bd85 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -27,9 +27,22 @@ UserProfile::UserProfile(QString roomid, , manager(manager_) , model(parent) { - fetchDeviceList(this->userid_); globalAvatarUrl = ""; + connect(this, + &UserProfile::globalUsernameRetrieved, + this, + &UserProfile::setGlobalUsername, + Qt::QueuedConnection); + + if (isGlobalUserProfile()) { + getGlobalProfileData(); + } + + if (!cache::client() || !cache::client()->isDatabaseReady()) + return; + + fetchDeviceList(this->userid_); connect(cache::client(), &Cache::verificationStatusChanged, this, @@ -54,16 +67,6 @@ UserProfile::UserProfile(QString roomid, } deviceList_.reset(deviceList_.deviceList_); }); - - connect(this, - &UserProfile::globalUsernameRetrieved, - this, - &UserProfile::setGlobalUsername, - Qt::QueuedConnection); - - if (isGlobalUserProfile()) { - getGlobalProfileData(); - } } QHash @@ -157,6 +160,9 @@ UserProfile::fetchDeviceList(const QString &userID) { auto localUser = utils::localUser(); + if (!cache::client() || !cache::client()->isDatabaseReady()) + return; + cache::client()->query_keys( userID.toStdString(), [other_user_id = userID.toStdString(), this](const UserKeyCache &other_user_keys,