matrixion/src/InviteesModel.h

67 lines
1.3 KiB
C
Raw Normal View History

2021-07-17 20:31:38 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-07-17 20:31:38 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
2021-06-11 03:13:12 +03:00
#ifndef INVITEESMODEL_H
#define INVITEESMODEL_H
#include <QAbstractListModel>
#include <QVector>
2022-10-10 15:38:29 +03:00
class Invitee final : public QObject
2021-06-11 03:13:12 +03:00
{
2021-09-18 01:22:33 +03:00
Q_OBJECT
2021-06-11 03:13:12 +03:00
public:
Invitee(QString mxid, QObject *parent = nullptr);
2021-06-11 03:13:12 +03:00
signals:
2021-09-18 01:22:33 +03:00
void userInfoLoaded();
2021-06-11 03:13:12 +03:00
private:
2021-09-18 01:22:33 +03:00
const QString mxid_;
QString displayName_;
QString avatarUrl_;
2021-06-11 03:13:12 +03:00
2021-09-18 01:22:33 +03:00
friend class InviteesModel;
2021-06-11 03:13:12 +03:00
};
2022-10-10 15:38:29 +03:00
class InviteesModel final : public QAbstractListModel
2021-06-11 03:13:12 +03:00
{
2021-09-18 01:22:33 +03:00
Q_OBJECT
2021-06-11 03:13:12 +03:00
2021-09-18 01:22:33 +03:00
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
2021-06-11 03:13:12 +03:00
public:
2021-09-18 01:22:33 +03:00
enum Roles
{
Mxid,
DisplayName,
AvatarUrl,
};
2021-06-11 03:13:12 +03:00
2021-09-18 01:22:33 +03:00
InviteesModel(QObject *parent = nullptr);
2021-06-11 03:13:12 +03:00
2021-09-18 01:22:33 +03:00
Q_INVOKABLE void addUser(QString mxid);
Q_INVOKABLE void removeUser(QString mxid);
2021-06-11 03:13:12 +03:00
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] int rowCount(const QModelIndex & = QModelIndex()) const override
2021-09-18 01:22:33 +03:00
{
return (int)invitees_.size();
}
[[nodiscard]] QVariant
data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
2021-09-18 01:22:33 +03:00
QStringList mxids();
2021-06-11 03:13:12 +03:00
signals:
2021-09-18 01:22:33 +03:00
void accept();
void countChanged();
2021-06-11 03:13:12 +03:00
private:
2021-09-18 01:22:33 +03:00
QVector<Invitee *> invitees_;
2021-06-11 03:13:12 +03:00
};
#endif // INVITEESMODEL_H