7#include "unicodeemoticonmanager.h"
10#include "textemoticonscore_debug.h"
11#include "unicodeemoticonparser.h"
12#include <KLocalizedString>
15#include <QJsonDocument>
17using namespace TextEmoticonsCore;
18class TextEmoticonsCore::UnicodeEmoticonManagerPrivate
21 void loadUnicodeEmoji();
22 [[nodiscard]]
QString i18nUnicodeCategory(
const QString &name)
const;
26void UnicodeEmoticonManagerPrivate::loadUnicodeEmoji()
29 QFile file(QStringLiteral(
":/emoji.json"));
31 qCWarning(TEXTEMOTICONSCORE_LOG) <<
"Impossible to open file: " << file.errorString();
37 mUnicodeEmojiList = unicodeParser.parse(obj);
40QString UnicodeEmoticonManagerPrivate::i18nUnicodeCategory(
const QString &name)
const
43 if (name ==
"symbols"_L1) {
44 return i18n(
"Symbols");
45 }
else if (name ==
"activity"_L1) {
46 return i18n(
"Activity");
47 }
else if (name ==
"objects"_L1) {
48 return i18n(
"Objects");
49 }
else if (name ==
"nature"_L1) {
50 return i18n(
"Nature");
51 }
else if (name ==
"food"_L1) {
53 }
else if (name ==
"people"_L1) {
54 return i18n(
"People");
55 }
else if (name ==
"travel"_L1) {
56 return i18n(
"Travel");
57 }
else if (name ==
"regional"_L1) {
58 return i18n(
"Regional");
59 }
else if (name ==
"flags"_L1) {
62 qCWarning(TEXTEMOTICONSCORE_LOG) <<
"Missing i18n translate " <<
name;
67UnicodeEmoticonManager::UnicodeEmoticonManager(
QObject *parent)
69 , d(new TextEmoticonsCore::UnicodeEmoticonManagerPrivate)
71 d->loadUnicodeEmoji();
74UnicodeEmoticonManager::~UnicodeEmoticonManager() =
default;
84 return d->mUnicodeEmojiList;
87int UnicodeEmoticonManager::count()
const
89 return d->mUnicodeEmojiList.count();
96 for (
const UnicodeEmoticon &emo : std::as_const(d->mUnicodeEmojiList)) {
101 if (category ==
"modifier"_L1) {
105 cat.setCategory(category);
106 cat.setName(emo.unicode());
107 cat.setI18nName(d->i18nUnicodeCategory(category));
108 cat.setOrder(UnicodeEmoticonParser::changeOrder(category));
109 categories.
append(std::move(cat));
112 std::sort(categories.
begin(), categories.
end());
123 std::copy_if(d->mUnicodeEmojiList.begin(), d->mUnicodeEmojiList.end(), std::back_inserter(result), hasRequestedCategory);
130 if (emo.hasEmoji(emojiIdentifier)) {
137#include "moc_unicodeemoticonmanager.cpp"
The EmoticonCategory class.
The UnicodeEmoticonManager class.
The UnicodeEmoticonParser class.
The UnicodeEmoticon class.
QString i18n(const char *text, const TYPE &arg...)
QString name(GameStandardAction id)
Category category(StandardShortcut id)
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonObject object() const const
void append(QList< T > &&value)
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)