diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-07-21 01:03:38 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-07-22 20:05:25 +0200 |
commit | 0c798554b54e25e03cd7a211f278362bd3dc2630 (patch) | |
tree | 7c3e8fb51362e97e42d8b4f4043624e457a64e05 /src/CombinedImagePackModel.cpp | |
parent | Fix emoji picker not connected to input (diff) | |
download | nheko-0c798554b54e25e03cd7a211f278362bd3dc2630.tar.xz |
Rename image pack model
Diffstat (limited to 'src/CombinedImagePackModel.cpp')
-rw-r--r-- | src/CombinedImagePackModel.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/CombinedImagePackModel.cpp b/src/CombinedImagePackModel.cpp new file mode 100644 index 00000000..c5b5b886 --- /dev/null +++ b/src/CombinedImagePackModel.cpp @@ -0,0 +1,76 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "CombinedImagePackModel.h" + +#include "Cache_p.h" +#include "CompletionModelRoles.h" + +CombinedImagePackModel::CombinedImagePackModel(const std::string &roomId, + bool stickers, + QObject *parent) + : QAbstractListModel(parent) + , room_id(roomId) +{ + auto packs = cache::client()->getImagePacks(room_id, stickers); + + for (const auto &pack : packs) { + QString packname = QString::fromStdString(pack.packname); + + for (const auto &img : pack.images) { + ImageDesc i{}; + i.shortcode = QString::fromStdString(img.first); + i.packname = packname; + i.image = img.second; + images.push_back(std::move(i)); + } + } +} + +int +CombinedImagePackModel::rowCount(const QModelIndex &) const +{ + return (int)images.size(); +} + +QHash<int, QByteArray> +CombinedImagePackModel::roleNames() const +{ + return { + {CompletionModel::CompletionRole, "completionRole"}, + {CompletionModel::SearchRole, "searchRole"}, + {CompletionModel::SearchRole2, "searchRole2"}, + {Roles::Url, "url"}, + {Roles::ShortCode, "shortcode"}, + {Roles::Body, "body"}, + {Roles::PackName, "packname"}, + {Roles::OriginalRow, "originalRow"}, + }; +} + +QVariant +CombinedImagePackModel::data(const QModelIndex &index, int role) const +{ + if (hasIndex(index.row(), index.column(), index.parent())) { + switch (role) { + case CompletionModel::CompletionRole: + return QString::fromStdString(images[index.row()].image.url); + case Roles::Url: + return QString::fromStdString(images[index.row()].image.url); + case CompletionModel::SearchRole: + case Roles::ShortCode: + return images[index.row()].shortcode; + case CompletionModel::SearchRole2: + case Roles::Body: + return QString::fromStdString(images[index.row()].image.body); + case Roles::PackName: + return images[index.row()].packname; + case Roles::OriginalRow: + return index.row(); + default: + return {}; + } + } + return {}; +} |