Add C++ Model for DeviceList
This commit is contained in:
parent
a54a973ad6
commit
f9c0f4dd54
@ -277,6 +277,7 @@ set(SRC_FILES
|
|||||||
src/ui/Theme.cpp
|
src/ui/Theme.cpp
|
||||||
src/ui/ThemeManager.cpp
|
src/ui/ThemeManager.cpp
|
||||||
src/ui/UserProfile.cpp
|
src/ui/UserProfile.cpp
|
||||||
|
src/ui/UserProfileModel.cpp
|
||||||
|
|
||||||
src/AvatarProvider.cpp
|
src/AvatarProvider.cpp
|
||||||
src/BlurhashProvider.cpp
|
src/BlurhashProvider.cpp
|
||||||
@ -482,6 +483,7 @@ qt5_wrap_cpp(MOC_HEADERS
|
|||||||
src/ui/Theme.h
|
src/ui/Theme.h
|
||||||
src/ui/ThemeManager.h
|
src/ui/ThemeManager.h
|
||||||
src/ui/UserProfile.h
|
src/ui/UserProfile.h
|
||||||
|
src/ui/UserProfileModel.h
|
||||||
|
|
||||||
src/notifications/Manager.h
|
src/notifications/Manager.h
|
||||||
|
|
||||||
|
@ -273,6 +273,9 @@ Page {
|
|||||||
color: colors.base
|
color: colors.base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property variant userProfile
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
height: userName.height
|
height: userName.height
|
||||||
spacing: 8
|
spacing: 8
|
||||||
@ -287,8 +290,10 @@ Page {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
userProfile.user_data = modelData
|
if(userProfile) userProfile.destroy()
|
||||||
userProfile.show()
|
var component = Qt.createComponent("UserProfile.qml");
|
||||||
|
userProfile = component.createObject(timelineRoot,{user_data : modelData});
|
||||||
|
userProfile.show();
|
||||||
}
|
}
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
propagateComposedEvents: true
|
propagateComposedEvents: true
|
||||||
@ -303,26 +308,17 @@ Page {
|
|||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
onClicked: {
|
onClicked: {
|
||||||
userProfile.user_data = modelData
|
if(userProfile) userProfile.destroy()
|
||||||
userProfile.show()
|
var component = Qt.createComponent("UserProfile.qml")
|
||||||
|
userProfile = component.createObject(timelineRoot,{user_data : modelData})
|
||||||
|
userProfile.show()
|
||||||
}
|
}
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
propagateComposedEvents: true
|
propagateComposedEvents: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
|
||||||
color: colors.buttonText
|
|
||||||
text: timelineManager.userStatus(modelData.userId)
|
|
||||||
textFormat: Text.PlainText
|
|
||||||
elide: Text.ElideRight
|
|
||||||
width: chat.delegateMaxWidth - parent.spacing*2 - userName.implicitWidth - avatarSize
|
|
||||||
font.italic: true
|
|
||||||
}
|
|
||||||
UserProfile{
|
|
||||||
id: userProfile
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,25 +16,16 @@ ApplicationWindow{
|
|||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
palette: colors
|
palette: colors
|
||||||
|
|
||||||
onAfterRendering: {
|
UserProfileList{
|
||||||
userProfileAvatar.url = chat.model.avatarUrl(user_data.userId).replace("mxc://", "image://MxcImage/")
|
id: userProfileList
|
||||||
userProfileName.text = user_data.userName
|
userId: user_data.userId
|
||||||
matrixUserID.text = user_data.userId
|
onUserIdChanged : {
|
||||||
userProfile.userId = user_data.userId
|
console.log(userId)
|
||||||
log_devices()
|
userProfileList.updateDeviceList()
|
||||||
}
|
}
|
||||||
|
onDeviceListUpdated : {
|
||||||
function log_devices()
|
modelDeviceList.deviceList = userProfileList
|
||||||
{
|
}
|
||||||
console.log(userProfile.deviceList);
|
|
||||||
userProfile.deviceList.forEach((item,index)=>{
|
|
||||||
console.log(item.device_id)
|
|
||||||
console.log(item.display_name)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
UserProfileContent{
|
|
||||||
id: userProfile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
background: Item{
|
background: Item{
|
||||||
@ -52,6 +43,7 @@ ApplicationWindow{
|
|||||||
|
|
||||||
Avatar{
|
Avatar{
|
||||||
id: userProfileAvatar
|
id: userProfileAvatar
|
||||||
|
url:chat.model.avatarUrl(user_data.userId).replace("mxc://", "image://MxcImage/")
|
||||||
height: 130
|
height: 130
|
||||||
width: 130
|
width: 130
|
||||||
displayName: modelData.userName
|
displayName: modelData.userName
|
||||||
@ -60,12 +52,14 @@ ApplicationWindow{
|
|||||||
|
|
||||||
Label{
|
Label{
|
||||||
id: userProfileName
|
id: userProfileName
|
||||||
|
text: user_data.userName
|
||||||
fontSizeMode: Text.HorizontalFit
|
fontSizeMode: Text.HorizontalFit
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
Label{
|
Label{
|
||||||
id: matrixUserID
|
id: matrixUserID
|
||||||
|
text: user_data.userId
|
||||||
fontSizeMode: Text.HorizontalFit
|
fontSizeMode: Text.HorizontalFit
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
}
|
}
|
||||||
@ -78,9 +72,29 @@ ApplicationWindow{
|
|||||||
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
|
||||||
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
|
||||||
|
|
||||||
Label {
|
ListView{
|
||||||
text: "ABC"
|
id: deviceList
|
||||||
font.pixelSize: 700
|
anchors.fill: parent
|
||||||
|
clip: true
|
||||||
|
spacing: 10
|
||||||
|
|
||||||
|
model: UserProfileModel{
|
||||||
|
id: modelDeviceList
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: RowLayout{
|
||||||
|
width: parent.width
|
||||||
|
Text{
|
||||||
|
Layout.fillWidth: true
|
||||||
|
color: colors.text
|
||||||
|
text: deviceID
|
||||||
|
}
|
||||||
|
Text{
|
||||||
|
Layout.fillWidth: true
|
||||||
|
color:colors.text
|
||||||
|
text: displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ handle_to_device_messages(const std::vector<mtx::events::collections::DeviceEven
|
|||||||
nhlog::crypto()->warn("validation error for olm message: {} {}",
|
nhlog::crypto()->warn("validation error for olm message: {} {}",
|
||||||
e.what(),
|
e.what(),
|
||||||
j_msg.dump(2));
|
j_msg.dump(2));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (msg_type == to_string(mtx::events::EventType::RoomKeyRequest)) {
|
} else if (msg_type == to_string(mtx::events::EventType::RoomKeyRequest)) {
|
||||||
@ -399,7 +398,6 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!utils::respondsToKeyRequests(req.content.room_id)) {
|
if (!utils::respondsToKeyRequests(req.content.room_id)) {
|
||||||
|
|
||||||
nhlog::crypto()->debug("ignoring all key requests for room {}",
|
nhlog::crypto()->debug("ignoring all key requests for room {}",
|
||||||
req.content.room_id);
|
req.content.room_id);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
#include "BlurhashProvider.h"
|
#include "BlurhashProvider.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
@ -16,6 +17,8 @@
|
|||||||
#include "emoji/EmojiModel.h"
|
#include "emoji/EmojiModel.h"
|
||||||
#include "emoji/Provider.h"
|
#include "emoji/Provider.h"
|
||||||
#include "../ui/UserProfile.h"
|
#include "../ui/UserProfile.h"
|
||||||
|
#include "src/ui/UserProfile.h"
|
||||||
|
#include "src/ui/UserProfileModel.h"
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)
|
Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)
|
||||||
|
|
||||||
@ -87,8 +90,9 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
|
|||||||
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
|
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
|
||||||
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
|
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
|
||||||
qmlRegisterType<DeviceVerificationFlow>("im.nheko", 1, 0, "DeviceVerificationFlow");
|
qmlRegisterType<DeviceVerificationFlow>("im.nheko", 1, 0, "DeviceVerificationFlow");
|
||||||
qmlRegisterType<UserProfile>("im.nheko",1,0,"UserProfileContent");
|
qmlRegisterType<UserProfileModel>("im.nheko", 1, 0, "UserProfileModel");
|
||||||
qRegisterMetaType<DeviceInfo>();
|
qmlRegisterType<UserProfile>("im.nheko", 1, 0, "UserProfileList");
|
||||||
|
|
||||||
qRegisterMetaType<mtx::events::collections::TimelineEvents>();
|
qRegisterMetaType<mtx::events::collections::TimelineEvents>();
|
||||||
qmlRegisterType<emoji::EmojiModel>("im.nheko.EmojiModel", 1, 0, "EmojiModel");
|
qmlRegisterType<emoji::EmojiModel>("im.nheko.EmojiModel", 1, 0, "EmojiModel");
|
||||||
qmlRegisterType<emoji::EmojiProxyModel>("im.nheko.EmojiModel", 1, 0, "EmojiProxyModel");
|
qmlRegisterType<emoji::EmojiProxyModel>("im.nheko.EmojiModel", 1, 0, "EmojiProxyModel");
|
||||||
|
@ -2,29 +2,32 @@
|
|||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "mtx/responses/crypto.hpp"
|
#include "mtx/responses/crypto.hpp"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
UserProfile::UserProfile(QObject *parent)
|
UserProfile::UserProfile(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QVector<DeviceInfo>
|
QVector<DeviceInfo>
|
||||||
UserProfile::getDeviceList(){
|
UserProfile::getDeviceList()
|
||||||
UserProfile::fetchDeviceList(this->userId);
|
{
|
||||||
return this->deviceList;
|
return this->deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
UserProfile::getUserId (){
|
UserProfile::getUserId()
|
||||||
|
{
|
||||||
return this->userId;
|
return this->userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserProfile::setUserId (const QString &user_id){
|
UserProfile::setUserId(const QString &user_id)
|
||||||
if(this->userId != userId)
|
{
|
||||||
|
if (this->userId != userId)
|
||||||
return;
|
return;
|
||||||
else
|
else {
|
||||||
this->userId = user_id;
|
this->userId = user_id;
|
||||||
|
emit UserProfile::userIdChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -37,11 +40,11 @@ UserProfile::fetchDeviceList(const QString &userID)
|
|||||||
|
|
||||||
http::client()->query_keys(
|
http::client()->query_keys(
|
||||||
req,
|
req,
|
||||||
[user_id = userID.toStdString(),this](const mtx::responses::QueryKeys &res,
|
[user_id = userID.toStdString(), this](const mtx::responses::QueryKeys &res,
|
||||||
mtx::http::RequestErr err) {
|
mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
nhlog::net()->warn("failed to query device keys: {} {}",
|
nhlog::net()->warn("failed to query device keys: {},{}",
|
||||||
err->matrix_error.error,
|
err->matrix_error.errcode,
|
||||||
static_cast<int>(err->status_code));
|
static_cast<int>(err->status_code));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -53,17 +56,16 @@ UserProfile::fetchDeviceList(const QString &userID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto devices = res.device_keys.at(user_id);
|
auto devices = res.device_keys.at(user_id);
|
||||||
|
|
||||||
QVector<DeviceInfo> deviceInfo;
|
QVector<DeviceInfo> deviceInfo;
|
||||||
|
|
||||||
for (const auto &d : devices) {
|
for (const auto &d : devices) {
|
||||||
auto device = d.second;
|
auto device = d.second;
|
||||||
|
|
||||||
// TODO: Verify signatures and ignore those that don't pass.
|
// TODO: Verify signatures and ignore those that don't pass.
|
||||||
// std::cout<<d.first<<std::endl;
|
DeviceInfo newdevice(
|
||||||
// std::cout<<device.unsigned_info.device_display_name<<std::endl;
|
QString::fromStdString(d.first),
|
||||||
DeviceInfo newdevice(QString::fromStdString(d.first),QString::fromStdString(device.unsigned_info.device_display_name))
|
QString::fromStdString(device.unsigned_info.device_display_name));
|
||||||
newdevice->device_id = QString::fromStdString(d.first);
|
QString::fromStdString(device.unsigned_info.device_display_name);
|
||||||
newdevice->display_name = QString::fromStdString(device.unsigned_info.device_display_name)
|
|
||||||
|
|
||||||
deviceInfo.append(std::move(newdevice));
|
deviceInfo.append(std::move(newdevice));
|
||||||
}
|
}
|
||||||
@ -74,7 +76,13 @@ UserProfile::fetchDeviceList(const QString &userID)
|
|||||||
return a.device_id > b.device_id;
|
return a.device_id > b.device_id;
|
||||||
});
|
});
|
||||||
|
|
||||||
this->deviceList = deviceInfo;
|
this->deviceList = std::move(deviceInfo);
|
||||||
emit UserProfile::deviceListUpdated();
|
emit UserProfile::deviceListUpdated();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserProfile::updateDeviceList()
|
||||||
|
{
|
||||||
|
fetchDeviceList(this->userId);
|
||||||
|
}
|
||||||
|
@ -2,33 +2,29 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
|
||||||
class DeviceInfo
|
class DeviceInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit DeviceInfo(QString device_id,QString display_name){
|
DeviceInfo(const QString deviceID, const QString displayName)
|
||||||
this->device_id = device_id;
|
: device_id(deviceID)
|
||||||
this->display_name = display_name;
|
, display_name(displayName)
|
||||||
}
|
{}
|
||||||
~DeviceInfo() = default;
|
|
||||||
DeviceInfo(const DeviceInfo &device){
|
DeviceInfo() {}
|
||||||
this->device_id = device.device_id;
|
|
||||||
this->display_name = device.display_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString device_id;
|
QString device_id;
|
||||||
QString display_name;
|
QString display_name;
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(DeviceInfo);
|
|
||||||
|
|
||||||
class UserProfile : public QObject
|
class UserProfile : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString userId READ getUserId WRITE setUserId NOTIFY userIdChanged)
|
||||||
Q_PROPERTY(QVector<DeviceInfo> deviceList READ getDeviceList NOTIFY deviceListUpdated)
|
Q_PROPERTY(QVector<DeviceInfo> deviceList READ getDeviceList NOTIFY deviceListUpdated)
|
||||||
Q_PROPERTY(QString userId READ getUserId WRITE setUserId)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
explicit UserProfile(QObject *parent = 0);
|
explicit UserProfile(QObject *parent = 0);
|
||||||
@ -39,8 +35,10 @@ public:
|
|||||||
void setUserId(const QString &userId);
|
void setUserId(const QString &userId);
|
||||||
|
|
||||||
Q_INVOKABLE void fetchDeviceList(const QString &userID);
|
Q_INVOKABLE void fetchDeviceList(const QString &userID);
|
||||||
|
Q_INVOKABLE void updateDeviceList();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void userIdChanged();
|
||||||
void deviceListUpdated();
|
void deviceListUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
66
src/ui/UserProfileModel.cpp
Normal file
66
src/ui/UserProfileModel.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "UserProfileModel.h"
|
||||||
|
#include "UserProfile.h"
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
UserProfileModel::UserProfileModel(QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
, deviceList(nullptr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int
|
||||||
|
UserProfileModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
if (parent.isValid() || !this->deviceList)
|
||||||
|
return 0;
|
||||||
|
return this->deviceList->getDeviceList().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
UserProfileModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid() || !this->deviceList)
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const DeviceInfo device = this->deviceList->getDeviceList().at(index.row());
|
||||||
|
switch (role) {
|
||||||
|
case DEVICEID:
|
||||||
|
return QVariant(device.device_id);
|
||||||
|
case DISPLAYNAME:
|
||||||
|
return QVariant(device.display_name);
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray>
|
||||||
|
UserProfileModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> names;
|
||||||
|
names[DEVICEID] = "deviceID";
|
||||||
|
names[DISPLAYNAME] = "displayName";
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserProfile *
|
||||||
|
UserProfileModel::getList() const
|
||||||
|
{
|
||||||
|
return (this->deviceList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserProfileModel::setList(UserProfile *devices)
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
|
||||||
|
if (devices)
|
||||||
|
devices->disconnect(this);
|
||||||
|
|
||||||
|
if (this->deviceList) {
|
||||||
|
const int index = this->deviceList->getDeviceList().size();
|
||||||
|
beginInsertRows(QModelIndex(), index, index);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->deviceList = devices;
|
||||||
|
|
||||||
|
endResetModel();
|
||||||
|
}
|
29
src/ui/UserProfileModel.h
Normal file
29
src/ui/UserProfileModel.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
class UserProfile; // forward declaration of the class UserProfile
|
||||||
|
|
||||||
|
class UserProfileModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(UserProfile *deviceList READ getList WRITE setList)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit UserProfileModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
DEVICEID,
|
||||||
|
DISPLAYNAME
|
||||||
|
};
|
||||||
|
UserProfile *getList() const;
|
||||||
|
void setList(UserProfile *devices);
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
virtual QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UserProfile *deviceList;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user