From 7c426e254b72e3d335c6d260bc55ae0b95d57218 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 9 Sep 2018 18:35:37 +0800 Subject: [PATCH] Update libqmatrixclient && fix broken avatar && fix broken image provider. --- include/libqmatrixclient | 2 +- qml/component/RoomDrawer.qml | 6 +++--- qml/main.qml | 9 +++++---- src/accountlistmodel.cpp | 17 +++++++++++++++-- src/imageitem.h | 2 +- src/roomlistmodel.cpp | 6 +++--- src/userlistmodel.cpp | 6 ++++-- 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/libqmatrixclient b/include/libqmatrixclient index d9ff200..3dfcd0f 160000 --- a/include/libqmatrixclient +++ b/include/libqmatrixclient @@ -1 +1 @@ -Subproject commit d9ff200ff62fb7f5b6b51082dc3979d5454a1bec +Subproject commit 3dfcd0f4f4501dba5925d894b7f0fbc9414549c8 diff --git a/qml/component/RoomDrawer.qml b/qml/component/RoomDrawer.qml index e852bd9..fe3ba39 100644 --- a/qml/component/RoomDrawer.qml +++ b/qml/component/RoomDrawer.qml @@ -103,12 +103,12 @@ Drawer { anchors.margins: 8 spacing: 12 - ImageStatus { + ImageItem { Layout.preferredWidth: height Layout.fillHeight: true - source: avatar != "" ? "image://mxc/" + avatar : "" - displayText: name + image: avatar + hint: name } Label { diff --git a/qml/main.qml b/qml/main.qml index 58bd27f..419e898 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -112,12 +112,13 @@ ApplicationWindow { width: parent.width height: width - ImageStatus { + ImageItem { anchors.fill: parent anchors.margins: 12 -// source: matriqueController.isLogin ? connection.localUser && connection.localUser.avatarUrl ? "image://mxc/" + connection.localUser.avatarUrl : "" : "qrc:/asset/img/avatar.png" - displayText: name + hint: name + image: avatar + defaultColor: Material.accent } page: roomPage @@ -289,6 +290,6 @@ ApplicationWindow { Binding { target: imageProvider property: "connection" - value: matriqueController.connection + value: accountListView.currentConnection } } diff --git a/src/accountlistmodel.cpp b/src/accountlistmodel.cpp index e54c0e7..35ba133 100644 --- a/src/accountlistmodel.cpp +++ b/src/accountlistmodel.cpp @@ -1,5 +1,7 @@ #include "accountlistmodel.h" +#include "room.h" + AccountListModel::AccountListModel(QObject* parent) : QAbstractListModel(parent) {} @@ -10,7 +12,18 @@ void AccountListModel::setController(Controller* value) { m_controller = value; - for (auto c : m_controller->connections()) m_connections.append(c); + for (auto c : m_controller->connections()) { + connect(c->user(), &User::avatarChanged, [=] { + const auto it = + std::find(m_connections.begin(), m_connections.end(), c); + if (it == m_connections.end()) { + return; + } + const auto idx = index(it - m_connections.begin()); + emit dataChanged(idx, idx, {AvatarRole}); + }); + m_connections.append(c); + }; connect(m_controller, &Controller::connectionAdded, this, [=](Connection* conn) { @@ -59,7 +72,7 @@ QVariant AccountListModel::data(const QModelIndex& index, int role) const { int AccountListModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) return 0; - return m_controller->connections().count(); + return m_connections.count(); } QHash AccountListModel::roleNames() const { diff --git a/src/imageitem.h b/src/imageitem.h index b743f0e..cda0471 100644 --- a/src/imageitem.h +++ b/src/imageitem.h @@ -35,7 +35,7 @@ class ImageItem : public QQuickPaintedItem { private: QImage m_image; - QString m_hint; + QString m_hint = "H"; QString m_color = "#000000"; }; diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index 5fa027a..7623d9b 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -19,8 +19,6 @@ void RoomListModel::setConnection(Connection* connection) { using QMatrixClient::Room; m_connection = connection; - doResetModel(); - connect(connection, &Connection::connected, this, &RoomListModel::doResetModel); connect(connection, &Connection::invitedRoom, this, @@ -30,6 +28,8 @@ void RoomListModel::setConnection(Connection* connection) { connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom); connect(connection, &Connection::aboutToDeleteRoom, this, &RoomListModel::deleteRoom); + + doResetModel(); } void RoomListModel::doResetModel() { @@ -139,7 +139,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const { MatriqueRoom* room = m_rooms.at(index.row()); if (role == NameRole) return room->displayName(); if (role == AvatarRole) { - if (room->avatarUrl().toString() != "") return room->avatar(64, 64); + if (!room->avatarUrl().isEmpty()) return room->avatar(64, 64); return QImage(); } if (role == TopicRole) return room->topic(); diff --git a/src/userlistmodel.cpp b/src/userlistmodel.cpp index 7157196..eac3523 100644 --- a/src/userlistmodel.cpp +++ b/src/userlistmodel.cpp @@ -68,7 +68,9 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const { return user->displayname(m_currentRoom); } if (role == AvatarRole) { - return user->avatarUrl(m_currentRoom); + if (!user->avatarUrl(m_currentRoom).isEmpty()) + return user->avatar(32, m_currentRoom); + return QImage(); } return QVariant(); @@ -110,7 +112,7 @@ void UserListModel::refresh(QMatrixClient::User* user, QVector roles) { void UserListModel::avatarChanged(QMatrixClient::User* user, const QMatrixClient::Room* context) { - if (context == m_currentRoom) refresh(user, {Qt::DecorationRole}); + if (context == m_currentRoom) refresh(user, {AvatarRole}); } int UserListModel::findUserPos(User* user) const {