Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(linux): Simplify adding keyboard #9734

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 deletions linux/ibus-keyman/src/keymanutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,8 @@ void
keyman_add_keyboard(gpointer data, gpointer user_data) {
kmp_keyboard *keyboard = (kmp_keyboard *)data;
add_keyboard_data *kb_data = (add_keyboard_data *)user_data;
gboolean alreadyexists = FALSE;

for (GList *e = kb_data->engines_list; e != NULL && alreadyexists == FALSE; e = e->next) {
for (GList *e = kb_data->engines_list; e != NULL; e = e->next) {
IBusEngineDesc *engine_desc = (IBusEngineDesc *)e->data;
const gchar *version = ibus_engine_desc_get_version(engine_desc);
const gchar *engine_name = ibus_engine_desc_get_name(engine_desc);
Expand All @@ -215,42 +214,40 @@ keyman_add_keyboard(gpointer data, gpointer user_data) {
// if it's the same version
// TODO: fix version comparison (#9593)
if (g_strcmp0(kmx_file, keyboard->kmx_file) == 0 && g_strcmp0(version, keyboard->version) >= 0) {
alreadyexists = TRUE;
g_debug("keyboard %s already exists at version %s which is newer or same as %s", kmx_file, version, keyboard->version);
return;
}
}

if (!alreadyexists) {
g_autofree gchar *json_file = g_strjoin(".", keyboard->id, "json", NULL);
g_autoptr(keyboard_details) kbd_details = g_new0(keyboard_details, 1);
get_keyboard_details(kb_data->kmp_dir, json_file, kbd_details);

if (keyboard->languages != NULL) {
for (GList *l = keyboard->languages; l != NULL; l = l->next) {
kmp_language *language = (kmp_language *)l->data;
IBusEngineDesc *engine_desc =
get_engine_for_language(keyboard, kb_data->info, kbd_details, kb_data->kmp_dir, language->id, language->name);
if (engine_desc) {
kb_data->engines_list = g_list_append(kb_data->engines_list, engine_desc);
}
g_autofree gchar *json_file = g_strjoin(".", keyboard->id, "json", NULL);
g_autoptr(keyboard_details) kbd_details = g_new0(keyboard_details, 1);
get_keyboard_details(kb_data->kmp_dir, json_file, kbd_details);
g_autofree gchar *abs_kmx = g_strjoin("/", kb_data->kmp_dir, keyboard->kmx_file, NULL);

if (keyboard->languages != NULL) {
for (GList *l = keyboard->languages; l != NULL; l = l->next) {
kmp_language *language = (kmp_language *)l->data;
IBusEngineDesc *engine_desc =
get_engine_for_language(keyboard, kb_data->info, kbd_details, kb_data->kmp_dir, language->id, language->name);
if (engine_desc) {
kb_data->engines_list = g_list_append(kb_data->engines_list, engine_desc);
}
} else {
g_autofree gchar *abs_kmx = g_strjoin("/", kb_data->kmp_dir, keyboard->kmx_file, NULL);
g_message("adding engine %s", abs_kmx);
kb_data->engines_list = g_list_append(
kb_data->engines_list,
ibus_keyman_engine_desc_new(
abs_kmx, // kmx full path
keyboard->name, // longname
kbd_details->description, // description
kb_data->info->copyright, // copyright if available
NULL, // language, most are ignored by ibus except major languages
kbd_details->license, // license
kb_data->info->author_desc, // author name only, not email
keyman_get_icon_file(abs_kmx), // icon full path
"us", // layout defaulting to us (en-US)
keyboard->version));
}
} else {
g_message("adding engine %s", abs_kmx);
kb_data->engines_list = g_list_append(
kb_data->engines_list,
ibus_keyman_engine_desc_new(
abs_kmx, // kmx full path
keyboard->name, // longname
kbd_details->description, // description
kb_data->info->copyright, // copyright if available
NULL, // language, most are ignored by ibus except major languages
kbd_details->license, // license
kb_data->info->author_desc, // author name only, not email
keyman_get_icon_file(abs_kmx), // icon full path
"us", // layout defaulting to us (en-US)
keyboard->version));
}
}

Expand Down