| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QAbstractListModel> |
| 8 |
#include <QList> |
| 9 |
#include <QQmlEngine> |
| 10 |
#include <QUrl> |
| 11 |
|
| 12 |
#include <mtx/events/mscs/image_packs.hpp> |
| 13 |
|
| 14 |
#include "CacheStructs.h" |
| 15 |
|
| 16 |
class SingleImagePackModel final : public QAbstractListModel |
| 17 |
{ |
| 18 |
Q_OBJECT |
| 19 |
QML_ELEMENT |
| 20 |
QML_UNCREATABLE("") |
| 21 |
|
| 22 |
Q_PROPERTY(QString roomid READ roomid CONSTANT) |
| 23 |
Q_PROPERTY(bool fromSpace READ fromSpace CONSTANT) |
| 24 |
Q_PROPERTY(QString statekey READ statekey WRITE setStatekey NOTIFY statekeyChanged) |
| 25 |
Q_PROPERTY(QString attribution READ attribution WRITE setAttribution NOTIFY attributionChanged) |
| 26 |
Q_PROPERTY(QString packname READ packname WRITE setPackname NOTIFY packnameChanged) |
| 27 |
Q_PROPERTY(QString avatarUrl READ avatarUrl WRITE setAvatarUrl NOTIFY avatarUrlChanged) |
| 28 |
Q_PROPERTY( |
| 29 |
bool isStickerPack READ isStickerPack WRITE setIsStickerPack NOTIFY isStickerPackChanged) |
| 30 |
Q_PROPERTY(bool isEmotePack READ isEmotePack WRITE setIsEmotePack NOTIFY isEmotePackChanged) |
| 31 |
Q_PROPERTY(bool isGloballyEnabled READ isGloballyEnabled WRITE setGloballyEnabled NOTIFY |
| 32 |
globallyEnabledChanged) |
| 33 |
Q_PROPERTY(bool canEdit READ canEdit CONSTANT) |
| 34 |
|
| 35 |
public: |
| 36 |
enum Roles |
| 37 |
{ |
| 38 |
Url = Qt::UserRole, |
| 39 |
ShortCode, |
| 40 |
Body, |
| 41 |
IsEmote, |
| 42 |
IsSticker, |
| 43 |
}; |
| 44 |
Q_ENUM(Roles); |
| 45 |
|
| 46 |
SingleImagePackModel(ImagePackInfo pack_, QObject *parent = nullptr); |
| 47 |
QHash<int, QByteArray> roleNames() const override; |
| 48 |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 49 |
QVariant data(const QModelIndex &index, int role) const override; |
| 50 |
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; |
| 51 |
|
| 52 |
QString roomid() const { return QString::fromStdString(roomid_); } |
| 53 |
bool fromSpace() const { return fromSpace_; } |
| 54 |
QString statekey() const { return QString::fromStdString(statekey_); } |
| 55 |
QString packname() const { return QString::fromStdString(pack.pack->display_name); } |
| 56 |
QString attribution() const { return QString::fromStdString(pack.pack->attribution); } |
| 57 |
QString avatarUrl() const; |
| 58 |
bool isStickerPack() const { return pack.pack->is_sticker(); } |
| 59 |
bool isEmotePack() const { return pack.pack->is_emoji(); } |
| 60 |
|
| 61 |
bool isGloballyEnabled() const; |
| 62 |
bool canEdit() const; |
| 63 |
void setGloballyEnabled(bool enabled); |
| 64 |
|
| 65 |
void setPackname(QString val); |
| 66 |
void setAttribution(QString val); |
| 67 |
void setAvatarUrl(QString val); |
| 68 |
void setStatekey(QString val); |
| 69 |
void setIsStickerPack(bool val); |
| 70 |
void setIsEmotePack(bool val); |
| 71 |
|
| 72 |
Q_INVOKABLE void save(); |
| 73 |
Q_INVOKABLE void remove(); |
| 74 |
Q_INVOKABLE void addStickers(QList<QUrl> files); |
| 75 |
Q_INVOKABLE void remove(int index); |
| 76 |
Q_INVOKABLE void setAvatar(QUrl file); |
| 77 |
|
| 78 |
static std::string unconflictingStatekey(const std::string &roomid, const std::string &key); |
| 79 |
|
| 80 |
signals: |
| 81 |
void globallyEnabledChanged(); |
| 82 |
void statekeyChanged(); |
| 83 |
void attributionChanged(); |
| 84 |
void packnameChanged(); |
| 85 |
void avatarUrlChanged(); |
| 86 |
void isEmotePackChanged(); |
| 87 |
void isStickerPackChanged(); |
| 88 |
|
| 89 |
void addImage(std::string uri, std::string filename, mtx::common::ImageInfo info); |
| 90 |
void avatarUploaded(QString uri); |
| 91 |
|
| 92 |
private slots: |
| 93 |
void addImageCb(std::string uri, std::string filename, mtx::common::ImageInfo info); |
| 94 |
|
| 95 |
private: |
| 96 |
std::string unconflictingShortcode(const std::string &shortcode); |
| 97 |
|
| 98 |
std::string roomid_; |
| 99 |
std::string statekey_, old_statekey_; |
| 100 |
|
| 101 |
mtx::events::msc2545::ImagePack pack; |
| 102 |
std::vector<std::string> shortcodes; |
| 103 |
|
| 104 |
bool fromSpace_ = false; |
| 105 |
}; |