2021-07-21 14:37:57 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2021-08-06 04:28:56 +03:00
|
|
|
#include <QList>
|
|
|
|
#include <QUrl>
|
2021-07-21 14:37:57 +03:00
|
|
|
|
|
|
|
#include <mtx/events/mscs/image_packs.hpp>
|
|
|
|
|
|
|
|
#include "CacheStructs.h"
|
|
|
|
|
|
|
|
class SingleImagePackModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QString roomid READ roomid CONSTANT)
|
2021-08-06 02:45:47 +03:00
|
|
|
Q_PROPERTY(QString statekey READ statekey WRITE setStatekey NOTIFY statekeyChanged)
|
|
|
|
Q_PROPERTY(
|
|
|
|
QString attribution READ attribution WRITE setAttribution NOTIFY attributionChanged)
|
|
|
|
Q_PROPERTY(QString packname READ packname WRITE setPackname NOTIFY packnameChanged)
|
|
|
|
Q_PROPERTY(QString avatarUrl READ avatarUrl WRITE setAvatarUrl NOTIFY avatarUrlChanged)
|
|
|
|
Q_PROPERTY(
|
|
|
|
bool isStickerPack READ isStickerPack WRITE setIsStickerPack NOTIFY isStickerPackChanged)
|
|
|
|
Q_PROPERTY(bool isEmotePack READ isEmotePack WRITE setIsEmotePack NOTIFY isEmotePackChanged)
|
2021-07-21 14:37:57 +03:00
|
|
|
Q_PROPERTY(bool isGloballyEnabled READ isGloballyEnabled WRITE setGloballyEnabled NOTIFY
|
|
|
|
globallyEnabledChanged)
|
2021-08-06 02:45:47 +03:00
|
|
|
Q_PROPERTY(bool canEdit READ canEdit CONSTANT)
|
|
|
|
|
2021-07-21 14:37:57 +03:00
|
|
|
public:
|
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
Url = Qt::UserRole,
|
|
|
|
ShortCode,
|
|
|
|
Body,
|
|
|
|
IsEmote,
|
|
|
|
IsSticker,
|
|
|
|
};
|
2021-08-06 02:45:47 +03:00
|
|
|
Q_ENUM(Roles);
|
2021-07-21 14:37:57 +03:00
|
|
|
|
|
|
|
SingleImagePackModel(ImagePackInfo pack_, QObject *parent = nullptr);
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2021-08-06 02:45:47 +03:00
|
|
|
bool setData(const QModelIndex &index,
|
|
|
|
const QVariant &value,
|
|
|
|
int role = Qt::EditRole) override;
|
2021-07-21 14:37:57 +03:00
|
|
|
|
|
|
|
QString roomid() const { return QString::fromStdString(roomid_); }
|
|
|
|
QString statekey() const { return QString::fromStdString(statekey_); }
|
|
|
|
QString packname() const { return QString::fromStdString(pack.pack->display_name); }
|
|
|
|
QString attribution() const { return QString::fromStdString(pack.pack->attribution); }
|
|
|
|
QString avatarUrl() const { return QString::fromStdString(pack.pack->avatar_url); }
|
|
|
|
bool isStickerPack() const { return pack.pack->is_sticker(); }
|
|
|
|
bool isEmotePack() const { return pack.pack->is_emoji(); }
|
|
|
|
|
|
|
|
bool isGloballyEnabled() const;
|
2021-08-06 02:45:47 +03:00
|
|
|
bool canEdit() const;
|
2021-07-21 14:37:57 +03:00
|
|
|
void setGloballyEnabled(bool enabled);
|
|
|
|
|
2021-08-06 02:45:47 +03:00
|
|
|
void setPackname(QString val);
|
|
|
|
void setAttribution(QString val);
|
|
|
|
void setAvatarUrl(QString val);
|
|
|
|
void setStatekey(QString val);
|
|
|
|
void setIsStickerPack(bool val);
|
|
|
|
void setIsEmotePack(bool val);
|
|
|
|
|
|
|
|
Q_INVOKABLE void save();
|
2021-08-06 04:28:56 +03:00
|
|
|
Q_INVOKABLE void addStickers(QList<QUrl> files);
|
2021-08-29 18:22:49 +03:00
|
|
|
Q_INVOKABLE void remove(int index);
|
2021-08-06 02:45:47 +03:00
|
|
|
|
2021-07-21 14:37:57 +03:00
|
|
|
signals:
|
|
|
|
void globallyEnabledChanged();
|
2021-08-06 02:45:47 +03:00
|
|
|
void statekeyChanged();
|
|
|
|
void attributionChanged();
|
|
|
|
void packnameChanged();
|
|
|
|
void avatarUrlChanged();
|
|
|
|
void isEmotePackChanged();
|
|
|
|
void isStickerPackChanged();
|
2021-07-21 14:37:57 +03:00
|
|
|
|
2021-08-06 04:28:56 +03:00
|
|
|
void addImage(std::string uri, std::string filename, mtx::common::ImageInfo info);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void addImageCb(std::string uri, std::string filename, mtx::common::ImageInfo info);
|
|
|
|
|
2021-07-21 14:37:57 +03:00
|
|
|
private:
|
|
|
|
std::string roomid_;
|
2021-08-06 02:45:47 +03:00
|
|
|
std::string statekey_, old_statekey_;
|
2021-07-21 14:37:57 +03:00
|
|
|
|
|
|
|
mtx::events::msc2545::ImagePack pack;
|
|
|
|
std::vector<std::string> shortcodes;
|
|
|
|
};
|