Changeset View
Changeset View
Standalone View
Standalone View
applets/kimpanel/backend/ibus/emojier/emojier.cpp
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | |||||
124 | { | 124 | { | ||
125 | Q_OBJECT | 125 | Q_OBJECT | ||
126 | Q_PROPERTY(QStringList categories MEMBER m_categories CONSTANT) | 126 | Q_PROPERTY(QStringList categories MEMBER m_categories CONSTANT) | ||
127 | public: | 127 | public: | ||
128 | enum EmojiRole { CategoryRole = Qt::UserRole + 1 }; | 128 | enum EmojiRole { CategoryRole = Qt::UserRole + 1 }; | ||
129 | 129 | | |||
130 | EmojiModel() { | 130 | EmojiModel() { | ||
131 | QLocale locale; | 131 | QLocale locale; | ||
132 | const QString dictName = "ibus/dicts/emoji-" + locale.bcp47Name().replace(QLatin1Char('-'), QLatin1Char('_')) + ".dict"; | 132 | const auto bcp = locale.bcp47Name(); | ||
133 | const QString dictName = "ibus/dicts/emoji-" + QString(bcp).replace(QLatin1Char('-'), QLatin1Char('_')) + ".dict"; | ||||
133 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, dictName); | 134 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, dictName); | ||
134 | if (path.isEmpty()) { | 135 | if (path.isEmpty()) { | ||
135 | qWarning() << "could not find" << dictName; | 136 | qWarning() << "could not find" << dictName; | ||
136 | return; | 137 | return; | ||
137 | } | 138 | } | ||
138 | 139 | | |||
139 | GSList *list = ibus_emoji_data_load (path.toUtf8().constData()); | 140 | const QString genericDictName = "ibus/dicts/emoji-" + bcp.left(bcp.indexOf(QLatin1Char('-'))) + ".dict"; | ||
140 | m_emoji.reserve(g_slist_length(list)); | 141 | const QString genericPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, genericDictName); | ||
142 | | ||||
143 | QVector<QString> dicts = {path}; | ||||
144 | if (!genericPath.isEmpty()) { | ||||
145 | dicts << genericPath; | ||||
146 | } | ||||
147 | | ||||
141 | QSet<QString> categories; | 148 | QSet<QString> categories; | ||
149 | QSet<QString> processedEmoji; | ||||
150 | for (const auto &dictPath : qAsConst(dicts)) { | ||||
151 | GSList *list = ibus_emoji_data_load (dictPath.toUtf8().constData()); | ||||
152 | m_emoji.reserve(g_slist_length(list)); | ||||
142 | for (GSList *l = list; l; l = l->next) { | 153 | for (GSList *l = list; l; l = l->next) { | ||
143 | IBusEmojiData *data = (IBusEmojiData *) l->data; | 154 | IBusEmojiData *data = (IBusEmojiData *) l->data; | ||
144 | if (!IBUS_IS_EMOJI_DATA (data)) { | 155 | if (!IBUS_IS_EMOJI_DATA (data)) { | ||
145 | qWarning() << "Your dict format is no longer supported.\n" | 156 | qWarning() << "Your dict format is no longer supported.\n" | ||
146 | "Need to create the dictionaries again."; | 157 | "Need to create the dictionaries again."; | ||
147 | g_slist_free (list); | 158 | g_slist_free (list); | ||
148 | return; | 159 | return; | ||
149 | } | 160 | } | ||
150 | 161 | | |||
162 | const QString emoji = QString::fromUtf8(ibus_emoji_data_get_emoji(data)); | ||||
163 | const QString description = ibus_emoji_data_get_description(data); | ||||
164 | qDebug() << "ooo" << dictPath << emoji << description << processedEmoji.contains(emoji); | ||||
165 | if (description == QString::fromUtf8("↑↑↑") || description.isEmpty() || processedEmoji.contains(emoji)) { | ||||
166 | continue; | ||||
167 | } | ||||
168 | | ||||
151 | const QString category = QString::fromUtf8(ibus_emoji_data_get_category(data)); | 169 | const QString category = QString::fromUtf8(ibus_emoji_data_get_category(data)); | ||
152 | categories.insert(category); | 170 | categories.insert(category); | ||
153 | m_emoji += { QString::fromUtf8(ibus_emoji_data_get_emoji(data)), ibus_emoji_data_get_description(data), category }; | 171 | m_emoji += { emoji, description, category }; | ||
172 | processedEmoji << emoji; | ||||
173 | } | ||||
174 | g_slist_free (list); | ||||
154 | } | 175 | } | ||
176 | | ||||
155 | categories.remove({}); | 177 | categories.remove({}); | ||
156 | m_categories = categories.values(); | 178 | m_categories = categories.values(); | ||
157 | m_categories.sort(); | 179 | m_categories.sort(); | ||
158 | m_categories.prepend({}); | 180 | m_categories.prepend({}); | ||
159 | m_categories.prepend(QStringLiteral(":recent:")); | 181 | m_categories.prepend(QStringLiteral(":recent:")); | ||
160 | g_slist_free (list); | | |||
161 | } | 182 | } | ||
162 | 183 | | |||
163 | Q_SCRIPTABLE QString findFirstEmojiForCategory(const QString &category) { | 184 | Q_SCRIPTABLE QString findFirstEmojiForCategory(const QString &category) { | ||
164 | for (const Emoji &emoji : m_emoji) { | 185 | for (const Emoji &emoji : m_emoji) { | ||
165 | if (emoji.category == category) | 186 | if (emoji.category == category) | ||
166 | return emoji.content; | 187 | return emoji.content; | ||
167 | } | 188 | } | ||
168 | return {}; | 189 | return {}; | ||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |