Commit f7f68c67 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Support locales with fallbacks

Summary: Jonathan uses en_GB.dict that diverges slightly from en.dict. They both should be taken into account properly.

Test Plan: Used Jon's env var

Reviewers: #plasma, jriddell

Reviewed By: #plasma, jriddell

Subscribers: jriddell, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25823
parent 0ecff2e5
...@@ -129,16 +129,27 @@ public: ...@@ -129,16 +129,27 @@ public:
EmojiModel() { EmojiModel() {
QLocale locale; QLocale locale;
const QString dictName = "ibus/dicts/emoji-" + locale.bcp47Name().replace(QLatin1Char('-'), QLatin1Char('_')) + ".dict"; const auto bcp = locale.bcp47Name();
const QString dictName = "ibus/dicts/emoji-" + QString(bcp).replace(QLatin1Char('-'), QLatin1Char('_')) + ".dict";
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, dictName); const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, dictName);
if (path.isEmpty()) { if (path.isEmpty()) {
qWarning() << "could not find" << dictName; qWarning() << "could not find" << dictName;
return; return;
} }
GSList *list = ibus_emoji_data_load (path.toUtf8().constData()); const QString genericDictName = "ibus/dicts/emoji-" + bcp.left(bcp.indexOf(QLatin1Char('-'))) + ".dict";
m_emoji.reserve(g_slist_length(list)); const QString genericPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, genericDictName);
QVector<QString> dicts = {path};
if (!genericPath.isEmpty()) {
dicts << genericPath;
}
QSet<QString> categories; QSet<QString> categories;
QSet<QString> processedEmoji;
for (const auto &dictPath : qAsConst(dicts)) {
GSList *list = ibus_emoji_data_load (dictPath.toUtf8().constData());
m_emoji.reserve(g_slist_length(list));
for (GSList *l = list; l; l = l->next) { for (GSList *l = list; l; l = l->next) {
IBusEmojiData *data = (IBusEmojiData *) l->data; IBusEmojiData *data = (IBusEmojiData *) l->data;
if (!IBUS_IS_EMOJI_DATA (data)) { if (!IBUS_IS_EMOJI_DATA (data)) {
...@@ -148,16 +159,26 @@ public: ...@@ -148,16 +159,26 @@ public:
return; return;
} }
const QString emoji = QString::fromUtf8(ibus_emoji_data_get_emoji(data));
const QString description = ibus_emoji_data_get_description(data);
qDebug() << "ooo" << dictPath << emoji << description << processedEmoji.contains(emoji);
if (description == QString::fromUtf8("↑↑↑") || description.isEmpty() || processedEmoji.contains(emoji)) {
continue;
}
const QString category = QString::fromUtf8(ibus_emoji_data_get_category(data)); const QString category = QString::fromUtf8(ibus_emoji_data_get_category(data));
categories.insert(category); categories.insert(category);
m_emoji += { QString::fromUtf8(ibus_emoji_data_get_emoji(data)), ibus_emoji_data_get_description(data), category }; m_emoji += { emoji, description, category };
processedEmoji << emoji;
}
g_slist_free (list);
} }
categories.remove({}); categories.remove({});
m_categories = categories.values(); m_categories = categories.values();
m_categories.sort(); m_categories.sort();
m_categories.prepend({}); m_categories.prepend({});
m_categories.prepend(QStringLiteral(":recent:")); m_categories.prepend(QStringLiteral(":recent:"));
g_slist_free (list);
} }
Q_SCRIPTABLE QString findFirstEmojiForCategory(const QString &category) { Q_SCRIPTABLE QString findFirstEmojiForCategory(const QString &category) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment