2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-07-15 21:37:52 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
|
|
|
#include <mtx/events/mscs/image_packs.hpp>
|
|
|
|
|
2022-10-10 15:38:29 +03:00
|
|
|
class CombinedImagePackModel final : public QAbstractListModel
|
2021-07-15 21:37:52 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_OBJECT
|
2021-07-15 21:37:52 +03:00
|
|
|
public:
|
2021-09-18 01:22:33 +03:00
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
Url = Qt::UserRole,
|
|
|
|
ShortCode,
|
|
|
|
Body,
|
|
|
|
PackName,
|
|
|
|
OriginalRow,
|
|
|
|
};
|
|
|
|
|
|
|
|
CombinedImagePackModel(const std::string &roomId, bool stickers, 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;
|
|
|
|
|
|
|
|
mtx::events::msc2545::PackImage imageAt(int row)
|
|
|
|
{
|
|
|
|
if (row < 0 || static_cast<size_t>(row) >= images.size())
|
|
|
|
return {};
|
|
|
|
return images.at(static_cast<size_t>(row)).image;
|
|
|
|
}
|
2022-03-22 21:45:25 +03:00
|
|
|
QString shortcodeAt(int row)
|
|
|
|
{
|
|
|
|
if (row < 0 || static_cast<size_t>(row) >= images.size())
|
|
|
|
return {};
|
|
|
|
return images.at(static_cast<size_t>(row)).shortcode;
|
|
|
|
}
|
2021-07-15 21:37:52 +03:00
|
|
|
|
|
|
|
private:
|
2021-09-18 01:22:33 +03:00
|
|
|
std::string room_id;
|
2021-07-15 21:37:52 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
struct ImageDesc
|
|
|
|
{
|
|
|
|
QString shortcode;
|
|
|
|
QString packname;
|
2021-07-15 21:37:52 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
mtx::events::msc2545::PackImage image;
|
|
|
|
};
|
2021-07-15 21:37:52 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
std::vector<ImageDesc> images;
|
2021-07-15 21:37:52 +03:00
|
|
|
};
|