summary refs log tree commit diff
path: root/src/ui/UserProfileModel.cpp
diff options
context:
space:
mode:
authorCH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com>2020-07-01 17:47:10 +0530
committerCH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com>2020-07-30 22:10:27 +0530
commitac1fbbb69fdd4e313072cbf95eb9288db1257a9d (patch)
tree6050f215caf7104d4e1cea5c6ba1ff53c0b477e2 /src/ui/UserProfileModel.cpp
parent[WIP] Add Caching for users (diff)
downloadnheko-ac1fbbb69fdd4e313072cbf95eb9288db1257a9d.tar.xz
Some issue with UserProfile
Diffstat (limited to 'src/ui/UserProfileModel.cpp')
-rw-r--r--src/ui/UserProfileModel.cpp45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/ui/UserProfileModel.cpp b/src/ui/UserProfileModel.cpp

index ec0456cd..3fa8fe2d 100644 --- a/src/ui/UserProfileModel.cpp +++ b/src/ui/UserProfileModel.cpp
@@ -1,11 +1,23 @@ #include "UserProfileModel.h" -#include "UserProfile.h" #include <QModelIndex> UserProfileModel::UserProfileModel(QObject *parent) : QAbstractListModel(parent) , deviceList(nullptr) -{} +{ + this->deviceList = new UserProfile(this); + + connect(this->deviceList, &UserProfile::userIdChanged, this, [this]() { + emit this->deviceList->updateDeviceList(); + }); + connect(this->deviceList, &UserProfile::deviceListUpdated, this, [this]() { + beginResetModel(); + this->beginInsertRows( + QModelIndex(), 0, this->deviceList->getDeviceList().size() - 1); + this->endInsertRows(); + endResetModel(); + }); +} int UserProfileModel::rowCount(const QModelIndex &parent) const @@ -18,7 +30,8 @@ UserProfileModel::rowCount(const QModelIndex &parent) const QVariant UserProfileModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || !this->deviceList) + if (!index.isValid() && + static_cast<int>(this->deviceList->getDeviceList().size()) <= index.row()) return QVariant(); const DeviceInfo device = this->deviceList->getDeviceList().at(index.row()); @@ -27,6 +40,8 @@ UserProfileModel::data(const QModelIndex &index, int role) const return QVariant(device.device_id); case DISPLAYNAME: return QVariant(device.display_name); + case VERIFIED_STATUS: + return device.verification_status; } return QVariant(); } @@ -35,8 +50,9 @@ QHash<int, QByteArray> UserProfileModel::roleNames() const { QHash<int, QByteArray> names; - names[DEVICEID] = "deviceID"; - names[DISPLAYNAME] = "displayName"; + names[DEVICEID] = "deviceID"; + names[DISPLAYNAME] = "displayName"; + names[VERIFIED_STATUS] = "verified_status"; return names; } @@ -45,22 +61,3 @@ 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(); -} \ No newline at end of file