Add menu to enable or disable stickers globally
This commit is contained in:
parent
0c798554b5
commit
eafbab6ae1
16 changed files with 674 additions and 17 deletions
76
src/ImagePackListModel.cpp
Normal file
76
src/ImagePackListModel.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "ImagePackListModel.h"
|
||||
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "Cache_p.h"
|
||||
#include "SingleImagePackModel.h"
|
||||
|
||||
ImagePackListModel::ImagePackListModel(const std::string &roomId, QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
, room_id(roomId)
|
||||
{
|
||||
auto packs_ = cache::client()->getImagePacks(room_id, std::nullopt);
|
||||
|
||||
for (const auto &pack : packs_) {
|
||||
packs.push_back(
|
||||
QSharedPointer<SingleImagePackModel>(new SingleImagePackModel(pack)));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ImagePackListModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return (int)packs.size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray>
|
||||
ImagePackListModel::roleNames() const
|
||||
{
|
||||
return {
|
||||
{Roles::DisplayName, "displayName"},
|
||||
{Roles::AvatarUrl, "avatarUrl"},
|
||||
{Roles::FromAccountData, "fromAccountData"},
|
||||
{Roles::FromCurrentRoom, "fromCurrentRoom"},
|
||||
{Roles::StateKey, "statekey"},
|
||||
{Roles::RoomId, "roomid"},
|
||||
};
|
||||
}
|
||||
|
||||
QVariant
|
||||
ImagePackListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (hasIndex(index.row(), index.column(), index.parent())) {
|
||||
const auto &pack = packs.at(index.row());
|
||||
switch (role) {
|
||||
case Roles::DisplayName:
|
||||
return pack->packname();
|
||||
case Roles::AvatarUrl:
|
||||
return pack->avatarUrl();
|
||||
case Roles::FromAccountData:
|
||||
return pack->roomid().isEmpty();
|
||||
case Roles::FromCurrentRoom:
|
||||
return pack->roomid().toStdString() == this->room_id;
|
||||
case Roles::StateKey:
|
||||
return pack->statekey();
|
||||
case Roles::RoomId:
|
||||
return pack->roomid();
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
SingleImagePackModel *
|
||||
ImagePackListModel::packAt(int row)
|
||||
{
|
||||
if (row < 0 || static_cast<size_t>(row) >= packs.size())
|
||||
return {};
|
||||
auto e = packs.at(row).get();
|
||||
QQmlEngine::setObjectOwnership(e, QQmlEngine::CppOwnership);
|
||||
return e;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue