| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QAbstractListModel> |
| 8 |
#include <QQmlEngine> |
| 9 |
#include <QVector> |
| 10 |
|
| 11 |
#include <mtx/events/canonical_alias.hpp> |
| 12 |
|
| 13 |
class FetchPublishedAliasesJob final : public QObject |
| 14 |
{ |
| 15 |
Q_OBJECT |
| 16 |
|
| 17 |
public: |
| 18 |
explicit FetchPublishedAliasesJob(QObject *p = nullptr) |
| 19 |
: QObject(p) |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 23 |
signals: |
| 24 |
void aliasFetched(std::string alias, std::string target); |
| 25 |
void advertizedAliasesFetched(std::vector<std::string> aliases); |
| 26 |
}; |
| 27 |
|
| 28 |
class AliasEditingModel final : public QAbstractListModel |
| 29 |
{ |
| 30 |
Q_OBJECT |
| 31 |
QML_ELEMENT |
| 32 |
QML_UNCREATABLE("Please use editAliases to create the models") |
| 33 |
|
| 34 |
Q_PROPERTY(bool canAdvertize READ canAdvertize CONSTANT) |
| 35 |
|
| 36 |
public: |
| 37 |
enum Roles |
| 38 |
{ |
| 39 |
Name, |
| 40 |
IsPublished, |
| 41 |
IsCanonical, |
| 42 |
IsAdvertized, |
| 43 |
}; |
| 44 |
|
| 45 |
explicit AliasEditingModel(const std::string &room_id_, QObject *parent = nullptr); |
| 46 |
|
| 47 |
QHash<int, QByteArray> roleNames() const override; |
| 48 |
int rowCount(const QModelIndex &) const override { return static_cast<int>(aliases.size()); } |
| 49 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 50 |
|
| 51 |
bool canAdvertize() const { return canSendStateEvent; } |
| 52 |
|
| 53 |
Q_INVOKABLE bool deleteAlias(int row); |
| 54 |
Q_INVOKABLE void addAlias(QString newAlias); |
| 55 |
Q_INVOKABLE void makeCanonical(int row); |
| 56 |
Q_INVOKABLE void togglePublish(int row); |
| 57 |
Q_INVOKABLE void toggleAdvertize(int row); |
| 58 |
Q_INVOKABLE void commit(); |
| 59 |
|
| 60 |
private slots: |
| 61 |
void updateAlias(std::string alias, std::string target); |
| 62 |
void updatePublishedAliases(std::vector<std::string> aliases); |
| 63 |
|
| 64 |
private: |
| 65 |
void fetchAliasesStatus(const std::string &alias); |
| 66 |
void fetchPublishedAliases(); |
| 67 |
|
| 68 |
struct Entry |
| 69 |
{ |
| 70 |
~Entry() = default; |
| 71 |
|
| 72 |
std::string alias; |
| 73 |
bool canonical = false; |
| 74 |
bool advertized = false; |
| 75 |
bool published = false; |
| 76 |
}; |
| 77 |
|
| 78 |
std::string room_id; |
| 79 |
QVector<Entry> aliases; |
| 80 |
mtx::events::state::CanonicalAlias aliasEvent; |
| 81 |
bool canSendStateEvent = false; |
| 82 |
}; |