Changeset View
Changeset View
Standalone View
Standalone View
applets/kimpanel/backend/ibus/emojier/emojier.cpp
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 131 | EmojiModel() { | |||
---|---|---|---|---|---|
133 | const auto bcp = locale.bcp47Name(); | 133 | const auto bcp = locale.bcp47Name(); | ||
134 | const QString dictName = "ibus/dicts/emoji-" + QString(bcp).replace(QLatin1Char('-'), QLatin1Char('_')) + ".dict"; | 134 | const QString dictName = "ibus/dicts/emoji-" + QString(bcp).replace(QLatin1Char('-'), QLatin1Char('_')) + ".dict"; | ||
135 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, dictName); | 135 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, dictName); | ||
136 | if (path.isEmpty()) { | 136 | if (path.isEmpty()) { | ||
137 | qWarning() << "could not find" << dictName; | 137 | qWarning() << "could not find" << dictName; | ||
138 | return; | 138 | return; | ||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | const QString genericDictName = "ibus/dicts/emoji-" + bcp.left(bcp.indexOf(QLatin1Char('-'))) + ".dict"; | 141 | QVector<QString> dicts = {path}; | ||
142 | const auto idxSpecific = bcp.indexOf(QLatin1Char('-')); | ||||
143 | if (idxSpecific > 0) { | ||||
144 | const QString genericDictName = "ibus/dicts/emoji-" + bcp.left(idxSpecific) + ".dict"; | ||||
142 | const QString genericPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, genericDictName); | 145 | const QString genericPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, genericDictName); | ||
143 | 146 | | |||
144 | QVector<QString> dicts = {path}; | | |||
145 | if (!genericPath.isEmpty()) { | 147 | if (!genericPath.isEmpty()) { | ||
146 | dicts << genericPath; | 148 | dicts << genericPath; | ||
147 | } | 149 | } | ||
150 | } | ||||
148 | 151 | | |||
149 | QSet<QString> categories; | 152 | QSet<QString> categories; | ||
150 | QSet<QString> processedEmoji; | 153 | QSet<QString> processedEmoji; | ||
151 | for (const auto &dictPath : qAsConst(dicts)) { | 154 | for (const auto &dictPath : qAsConst(dicts)) { | ||
152 | GSList *list = ibus_emoji_data_load (dictPath.toUtf8().constData()); | 155 | GSList *list = ibus_emoji_data_load (dictPath.toUtf8().constData()); | ||
153 | m_emoji.reserve(g_slist_length(list)); | 156 | m_emoji.reserve(g_slist_length(list)); | ||
154 | for (GSList *l = list; l; l = l->next) { | 157 | for (GSList *l = list; l; l = l->next) { | ||
155 | IBusEmojiData *data = (IBusEmojiData *) l->data; | 158 | IBusEmojiData *data = (IBusEmojiData *) l->data; | ||
156 | if (!IBUS_IS_EMOJI_DATA (data)) { | 159 | if (!IBUS_IS_EMOJI_DATA (data)) { | ||
157 | qWarning() << "Your dict format is no longer supported.\n" | 160 | qWarning() << "Your dict format is no longer supported.\n" | ||
158 | "Need to create the dictionaries again."; | 161 | "Need to create the dictionaries again."; | ||
159 | g_slist_free (list); | 162 | g_slist_free (list); | ||
160 | return; | 163 | return; | ||
161 | } | 164 | } | ||
162 | 165 | | |||
163 | const QString emoji = QString::fromUtf8(ibus_emoji_data_get_emoji(data)); | 166 | const QString emoji = QString::fromUtf8(ibus_emoji_data_get_emoji(data)); | ||
164 | const QString description = ibus_emoji_data_get_description(data); | 167 | const QString description = ibus_emoji_data_get_description(data); | ||
165 | qDebug() << "ooo" << dictPath << emoji << description << processedEmoji.contains(emoji); | | |||
166 | if (description == QString::fromUtf8("↑↑↑") || description.isEmpty() || processedEmoji.contains(emoji)) { | 168 | if (description == QString::fromUtf8("↑↑↑") || description.isEmpty() || processedEmoji.contains(emoji)) { | ||
167 | continue; | 169 | continue; | ||
168 | } | 170 | } | ||
169 | 171 | | |||
170 | const QString category = QString::fromUtf8(ibus_emoji_data_get_category(data)); | 172 | const QString category = QString::fromUtf8(ibus_emoji_data_get_category(data)); | ||
171 | categories.insert(category); | 173 | categories.insert(category); | ||
172 | m_emoji += { emoji, description, category }; | 174 | m_emoji += { emoji, description, category }; | ||
173 | processedEmoji << emoji; | 175 | processedEmoji << emoji; | ||
174 | } | 176 | } | ||
175 | g_slist_free (list); | 177 | g_slist_free (list); | ||
176 | } | 178 | } | ||
177 | 179 | | |||
178 | categories.remove({}); | 180 | categories.remove({}); | ||
179 | m_categories = categories.values(); | 181 | m_categories = categories.values(); | ||
180 | m_categories.sort(); | 182 | m_categories.sort(); | ||
181 | m_categories.prepend({}); | 183 | m_categories.prepend({}); | ||
184 | m_categories.prepend(QStringLiteral(":find:")); | ||||
182 | m_categories.prepend(QStringLiteral(":recent:")); | 185 | m_categories.prepend(QStringLiteral(":recent:")); | ||
183 | } | 186 | } | ||
184 | 187 | | |||
185 | Q_SCRIPTABLE QString findFirstEmojiForCategory(const QString &category) { | 188 | Q_SCRIPTABLE QString findFirstEmojiForCategory(const QString &category) { | ||
186 | for (const Emoji &emoji : m_emoji) { | 189 | for (const Emoji &emoji : m_emoji) { | ||
187 | if (emoji.category == category) | 190 | if (emoji.category == category) | ||
188 | return emoji.content; | 191 | return emoji.content; | ||
189 | } | 192 | } | ||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | |||||
330 | { | 333 | { | ||
331 | QGuiApplication::setFallbackSessionManagementEnabled(false); | 334 | QGuiApplication::setFallbackSessionManagementEnabled(false); | ||
332 | QApplication app(argc, argv); | 335 | QApplication app(argc, argv); | ||
333 | app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); | 336 | app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); | ||
334 | app.setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-emoticons"))); | 337 | app.setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-emoticons"))); | ||
335 | KCrash::initialize(); | 338 | KCrash::initialize(); | ||
336 | KQuickAddons::QtQuickSettings::init(); | 339 | KQuickAddons::QtQuickSettings::init(); | ||
337 | 340 | | |||
338 | KLocalizedString::setApplicationDomain("plasma.emojier"); | 341 | KLocalizedString::setApplicationDomain("org.kde.plasma.emojier"); | ||
339 | 342 | | |||
340 | KAboutData about(QStringLiteral("plasma.emojier"), i18n("Emoji Picker"), QStringLiteral(WORKSPACE_VERSION_STRING), i18n("Emoji Picker"), | 343 | KAboutData about(QStringLiteral("org.kde.plasma.emojier"), i18n("Emoji Picker"), QStringLiteral(WORKSPACE_VERSION_STRING), i18n("Emoji Picker"), | ||
341 | KAboutLicense::GPL, i18n("(C) 2019 Aleix Pol i Gonzalez")); | 344 | KAboutLicense::GPL, i18n("(C) 2019 Aleix Pol i Gonzalez")); | ||
342 | about.addAuthor( QStringLiteral("Aleix Pol i Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org") ); | 345 | about.addAuthor( QStringLiteral("Aleix Pol i Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org") ); | ||
343 | about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails")); | 346 | about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails")); | ||
344 | // about.setProductName(""); | 347 | // about.setProductName(""); | ||
345 | about.setProgramLogo(app.windowIcon()); | 348 | about.setProgramLogo(app.windowIcon()); | ||
346 | KAboutData::setApplicationData(about); | 349 | KAboutData::setApplicationData(about); | ||
347 | 350 | | |||
348 | auto disableSessionManagement = [](QSessionManager &sm) { | 351 | auto disableSessionManagement = [](QSessionManager &sm) { | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |