Skip to content

Commit

Permalink
Add C++ Model for DeviceList
Browse files Browse the repository at this point in the history
  • Loading branch information
Chethan2k1 committed Jun 2, 2020
1 parent e25fc14 commit 621ad4c
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 66 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ set(SRC_FILES
src/ui/Theme.cpp
src/ui/ThemeManager.cpp
src/ui/UserProfile.cpp
src/ui/UserProfileModel.cpp

src/AvatarProvider.cpp
src/BlurhashProvider.cpp
Expand Down Expand Up @@ -475,6 +476,7 @@ qt5_wrap_cpp(MOC_HEADERS
src/ui/Theme.h
src/ui/ThemeManager.h
src/ui/UserProfile.h
src/ui/UserProfileModel.h

src/notifications/Manager.h

Expand Down
20 changes: 12 additions & 8 deletions resources/qml/TimelineView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ Page {
color: colors.base
}
}

property variant userProfile

Row {
height: userName.height
spacing: 4
Expand All @@ -272,8 +275,10 @@ Page {
MouseArea {
anchors.fill: parent
onClicked: {
userProfile.user_data = modelData
userProfile.show()
if(userProfile) userProfile.destroy()
var component = Qt.createComponent("UserProfile.qml");
userProfile = component.createObject(timelineRoot,{user_data : modelData});
userProfile.show();
}
cursorShape: Qt.PointingHandCursor
propagateComposedEvents: true
Expand All @@ -288,18 +293,17 @@ Page {

MouseArea {
anchors.fill: parent
Layout.alignment: Qt.AlignHCenter
onClicked: {
userProfile.user_data = modelData
userProfile.show()
if(userProfile) userProfile.destroy()
var component = Qt.createComponent("UserProfile.qml")
userProfile = component.createObject(timelineRoot,{user_data : modelData})
userProfile.show()
}
cursorShape: Qt.PointingHandCursor
propagateComposedEvents: true
}
}

UserProfile{
id: userProfile
}
}
}
}
Expand Down
58 changes: 36 additions & 22 deletions resources/qml/UserProfile.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@ ApplicationWindow{
Layout.alignment: Qt.AlignHCenter
palette: colors

onAfterRendering: {
userProfileAvatar.url = chat.model.avatarUrl(user_data.userId).replace("mxc://", "image://MxcImage/")
userProfileName.text = user_data.userName
matrixUserID.text = user_data.userId
userProfile.userId = user_data.userId
log_devices()
}

function log_devices()
{
console.log(userProfile.deviceList);
userProfile.deviceList.forEach((item,index)=>{
console.log(item.device_id)
console.log(item.display_name)
})
}

UserProfileContent{
id: userProfile
UserProfileList{
id: userProfileList
userId: user_data.userId
onUserIdChanged : {
console.log(userId)
userProfileList.updateDeviceList()
}
onDeviceListUpdated : {
modelDeviceList.deviceList = userProfileList
}
}

background: Item{
Expand All @@ -52,6 +43,7 @@ ApplicationWindow{

Avatar{
id: userProfileAvatar
url:chat.model.avatarUrl(user_data.userId).replace("mxc://", "image://MxcImage/")
height: 130
width: 130
displayName: modelData.userName
Expand All @@ -60,12 +52,14 @@ ApplicationWindow{

Label{
id: userProfileName
text: user_data.userName
fontSizeMode: Text.HorizontalFit
Layout.alignment: Qt.AlignHCenter
}

Label{
id: matrixUserID
text: user_data.userId
fontSizeMode: Text.HorizontalFit
Layout.alignment: Qt.AlignHCenter
}
Expand All @@ -78,9 +72,29 @@ ApplicationWindow{
ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
ScrollBar.vertical.policy: ScrollBar.AlwaysOn

Label {
text: "ABC"
font.pixelSize: 700
ListView{
id: deviceList
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
}
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Olm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ handle_to_device_messages(const std::vector<mtx::events::collections::DeviceEven
nhlog::crypto()->warn("validation error for olm message: {} {}",
e.what(),
j_msg.dump(2));

}

} else if (msg_type == to_string(mtx::events::EventType::RoomKeyRequest)) {
Expand Down Expand Up @@ -398,7 +397,6 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
}

if (!utils::respondsToKeyRequests(req.content.room_id)) {

nhlog::crypto()->debug("ignoring all key requests for room {}",
req.content.room_id);

Expand Down
9 changes: 6 additions & 3 deletions src/timeline/TimelineViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QMetaType>
#include <QPalette>
#include <QQmlContext>
#include <QQmlEngine>

#include "BlurhashProvider.h"
#include "ChatPage.h"
Expand All @@ -13,7 +14,8 @@
#include "MxcImageProvider.h"
#include "UserSettingsPage.h"
#include "dialogs/ImageOverlay.h"
#include "../ui/UserProfile.h"
#include "src/ui/UserProfile.h"
#include "src/ui/UserProfileModel.h"

Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)

Expand Down Expand Up @@ -73,8 +75,9 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
qmlRegisterType<DeviceVerificationFlow>("im.nheko", 1, 0, "DeviceVerificationFlow");
qmlRegisterType<UserProfile>("im.nheko",1,0,"UserProfileContent");
qRegisterMetaType<DeviceInfo>();
qmlRegisterType<UserProfileModel>("im.nheko", 1, 0, "UserProfileModel");
qmlRegisterType<UserProfile>("im.nheko", 1, 0, "UserProfileList");

qRegisterMetaType<mtx::events::collections::TimelineEvents>();

#ifdef USE_QUICK_VIEW
Expand Down
46 changes: 27 additions & 19 deletions src/ui/UserProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@
#include "Logging.h"
#include "Utils.h"
#include "mtx/responses/crypto.hpp"
#include <iostream>

UserProfile::UserProfile(QObject *parent)
: QObject(parent)
{}

QVector<DeviceInfo>
UserProfile::getDeviceList(){
UserProfile::fetchDeviceList(this->userId);
UserProfile::getDeviceList()
{
return this->deviceList;
}

QString
UserProfile::getUserId (){
UserProfile::getUserId()
{
return this->userId;
}

void
UserProfile::setUserId (const QString &user_id){
if(this->userId != userId)
UserProfile::setUserId(const QString &user_id)
{
if (this->userId != userId)
return;
else
else {
this->userId = user_id;
emit UserProfile::userIdChanged();
}
}

void
Expand All @@ -37,11 +40,11 @@ UserProfile::fetchDeviceList(const QString &userID)

http::client()->query_keys(
req,
[user_id = userID.toStdString(),this](const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err) {
[user_id = userID.toStdString(), this](const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err) {
if (err) {
nhlog::net()->warn("failed to query device keys: {} {}",
err->matrix_error.error,
nhlog::net()->warn("failed to query device keys: {},{}",
err->matrix_error.errcode,
static_cast<int>(err->status_code));
return;
}
Expand All @@ -53,17 +56,16 @@ UserProfile::fetchDeviceList(const QString &userID)
}

auto devices = res.device_keys.at(user_id);

QVector<DeviceInfo> deviceInfo;

for (const auto &d : devices) {
auto device = d.second;

// TODO: Verify signatures and ignore those that don't pass.
// std::cout<<d.first<<std::endl;
// std::cout<<device.unsigned_info.device_display_name<<std::endl;
DeviceInfo newdevice(QString::fromStdString(d.first),QString::fromStdString(device.unsigned_info.device_display_name))
newdevice->device_id = QString::fromStdString(d.first);
newdevice->display_name = QString::fromStdString(device.unsigned_info.device_display_name)
DeviceInfo newdevice(
QString::fromStdString(d.first),
QString::fromStdString(device.unsigned_info.device_display_name));
QString::fromStdString(device.unsigned_info.device_display_name);

deviceInfo.append(std::move(newdevice));
}
Expand All @@ -74,7 +76,13 @@ UserProfile::fetchDeviceList(const QString &userID)
return a.device_id > b.device_id;
});

this->deviceList = deviceInfo;
emit UserProfile::deviceListUpdated();
this->deviceList = std::move(deviceInfo);
emit UserProfile::deviceListUpdated();
});
}

void
UserProfile::updateDeviceList()
{
fetchDeviceList(this->userId);
}
22 changes: 10 additions & 12 deletions src/ui/UserProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@

#include <QObject>
#include <QString>
#include <QVector>

#include "MatrixClient.h"

class DeviceInfo
{
public:
explicit DeviceInfo(QString device_id,QString display_name){
this->device_id = device_id;
this->display_name = display_name;
}
~DeviceInfo() = default;
DeviceInfo(const DeviceInfo &device){
this->device_id = device.device_id;
this->display_name = device.display_name;
}
DeviceInfo(const QString deviceID, const QString displayName)
: device_id(deviceID)
, display_name(displayName)
{}

DeviceInfo() {}

QString device_id;
QString display_name;
};
Q_DECLARE_METATYPE(DeviceInfo);

class UserProfile : public QObject
{
Q_OBJECT
Q_PROPERTY(QString userId READ getUserId WRITE setUserId NOTIFY userIdChanged)
Q_PROPERTY(QVector<DeviceInfo> deviceList READ getDeviceList NOTIFY deviceListUpdated)
Q_PROPERTY(QString userId READ getUserId WRITE setUserId)

public:
// constructor
explicit UserProfile(QObject *parent = 0);
Expand All @@ -39,8 +35,10 @@ class UserProfile : public QObject
void setUserId(const QString &userId);

Q_INVOKABLE void fetchDeviceList(const QString &userID);
Q_INVOKABLE void updateDeviceList();

signals:
void userIdChanged();
void deviceListUpdated();

private:
Expand Down
Loading

0 comments on commit 621ad4c

Please sign in to comment.