mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-19 14:17:40 +00:00
refactor(linux): Use auto cleanup
This commit is contained in:
parent
405f2e8243
commit
22126a0eef
9 changed files with 114 additions and 141 deletions
|
|
@ -246,7 +246,8 @@ reset_context(IBusEngine *engine) {
|
|||
|
||||
if (client_supports_surrounding_text(engine)) {
|
||||
IBusText *text;
|
||||
gchar *surrounding_text, *current_context_utf8;
|
||||
g_autofree gchar *surrounding_text = NULL;
|
||||
g_autofree gchar *current_context_utf8 = NULL;
|
||||
guint cursor_pos, anchor_pos, context_start, context_end;
|
||||
km_core_context_item *context_items;
|
||||
|
||||
|
|
@ -270,8 +271,6 @@ reset_context(IBusEngine *engine) {
|
|||
g_message("%s: setting context failed with status code %d", __FUNCTION__, status);
|
||||
}
|
||||
}
|
||||
g_free(surrounding_text);
|
||||
g_free(current_context_utf8);
|
||||
} else {
|
||||
km_core_context_clear(context);
|
||||
g_message("%s: client does not support surrounding text", __FUNCTION__);
|
||||
|
|
@ -362,9 +361,19 @@ setup_environment(IBusKeymanEngine *keyman)
|
|||
return status;
|
||||
}
|
||||
|
||||
void
|
||||
free_km_core_option_item(gpointer data) {
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
km_core_option_item *opt = (km_core_option_item *)data;
|
||||
g_free((km_core_cp *)opt->key);
|
||||
g_free((km_core_cp *)opt->value);
|
||||
g_free(opt);
|
||||
}
|
||||
|
||||
static km_core_status
|
||||
load_keyboard_options(IBusKeymanEngine *keyman)
|
||||
{
|
||||
load_keyboard_options(IBusKeymanEngine *keyman) {
|
||||
g_assert(keyman);
|
||||
|
||||
// Retrieve keyboard options from DConf
|
||||
|
|
@ -373,7 +382,7 @@ load_keyboard_options(IBusKeymanEngine *keyman)
|
|||
GQueue *queue_options = keyman_get_options_queue_fromdconf(keyman->kb_name, keyman->kb_name);
|
||||
int num_options = g_queue_get_length(queue_options);
|
||||
if (num_options < 1) {
|
||||
g_queue_free_full(queue_options, NULL);
|
||||
g_queue_free_full(queue_options, free_km_core_option_item);
|
||||
return KM_CORE_STATUS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -387,18 +396,13 @@ load_keyboard_options(IBusKeymanEngine *keyman)
|
|||
keyboard_opts[i].value = item->value;
|
||||
}
|
||||
|
||||
|
||||
// once we have the option list we can then update the options using the public api call
|
||||
km_core_status status = km_core_state_options_update(keyman->state, keyboard_opts);
|
||||
|
||||
if (status != KM_CORE_STATUS_OK) {
|
||||
g_warning("%s: problem creating km_core_state. Status is %u.", __FUNCTION__, status);
|
||||
}
|
||||
for (int i = 0; i < num_options; i++) {
|
||||
g_free((km_core_cp *)keyboard_opts[i].key);
|
||||
g_free((km_core_cp *)keyboard_opts[i].value);
|
||||
}
|
||||
g_queue_free_full(queue_options, NULL);
|
||||
g_queue_free_full(queue_options, free_km_core_option_item);
|
||||
g_free(keyboard_opts);
|
||||
return status;
|
||||
}
|
||||
|
|
@ -412,7 +416,8 @@ ibus_keyman_engine_constructor(
|
|||
IBusKeymanEngine *keyman;
|
||||
IBusEngine *engine;
|
||||
const gchar *engine_name;
|
||||
gchar *p, *abs_kmx_path;
|
||||
gchar *p;
|
||||
g_autofree gchar *abs_kmx_path = NULL;
|
||||
|
||||
g_debug("DAR: %s", __FUNCTION__);
|
||||
|
||||
|
|
@ -451,29 +456,25 @@ ibus_keyman_engine_constructor(
|
|||
|
||||
g_strfreev(split_name);
|
||||
|
||||
gchar *kmx_file = g_path_get_basename(abs_kmx_path);
|
||||
g_autofree gchar *kmx_file = g_path_get_basename(abs_kmx_path);
|
||||
p = rindex(kmx_file, '.'); // get id to use as dbus service name
|
||||
if (p) {
|
||||
keyman->kb_name = g_strndup(kmx_file, p-kmx_file);
|
||||
p = rindex(abs_kmx_path, '.');
|
||||
if (p)
|
||||
{
|
||||
gchar *dir = g_path_get_dirname(abs_kmx_path);
|
||||
gchar *ldmlfile = g_strdup_printf("%s/%s.ldml", dir, keyman->kb_name);
|
||||
g_autofree gchar *dir = g_path_get_dirname(abs_kmx_path);
|
||||
g_autofree gchar *ldmlfile = g_strdup_printf("%s/%s.ldml", dir, keyman->kb_name);
|
||||
if (g_file_test(ldmlfile, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
keyman->ldmlfile = g_strdup(ldmlfile);
|
||||
}
|
||||
g_free(dir);
|
||||
g_free(ldmlfile);
|
||||
}
|
||||
}
|
||||
g_free(kmx_file);
|
||||
|
||||
km_core_status status;
|
||||
|
||||
status = km_core_keyboard_load(abs_kmx_path, &(keyman->keyboard));
|
||||
g_free(abs_kmx_path);
|
||||
|
||||
if (status != KM_CORE_STATUS_OK) {
|
||||
g_warning("%s: problem creating km_core_keyboard. Status is %u.", __FUNCTION__, status);
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ GList * keyman_get_kmpdirs_fromdir(GList *kmpdir_list, const gchar * path)
|
|||
struct dirent *file = readdir(dir);
|
||||
while (file != NULL) {
|
||||
struct stat filestat;
|
||||
gchar * absfn = g_strdup_printf("%s/%s", path, file->d_name);
|
||||
g_autofree gchar *absfn = g_strdup_printf("%s/%s", path, file->d_name);
|
||||
stat(absfn, &filestat);
|
||||
|
||||
if (S_ISDIR(filestat.st_mode))
|
||||
|
|
@ -89,7 +89,6 @@ GList * keyman_get_kmpdirs_fromdir(GList *kmpdir_list, const gchar * path)
|
|||
g_message("adding kmp path %s", path);
|
||||
kmpdir_list=g_list_append(kmpdir_list, g_strdup(path));
|
||||
}
|
||||
g_free(absfn);
|
||||
|
||||
file = readdir(dir);
|
||||
}
|
||||
|
|
@ -102,12 +101,12 @@ gchar * keyman_get_icon_file(const gchar *kmx_file)
|
|||
{
|
||||
// Now there will only be the .png
|
||||
// which at some point will get extracted from the .kmx during installation
|
||||
gchar *filename, *full_path_to_icon_file, *p;
|
||||
gchar *full_path_to_icon_file, *p;
|
||||
g_autofree gchar *filename;
|
||||
|
||||
p=rindex(kmx_file,'.');
|
||||
p = rindex(kmx_file, '.');
|
||||
filename = g_strndup(kmx_file, p-kmx_file);
|
||||
full_path_to_icon_file=g_strdup_printf("%s.bmp.png", filename);
|
||||
g_free(filename);
|
||||
|
||||
if (!g_file_test(full_path_to_icon_file, G_FILE_TEST_EXISTS)) {
|
||||
g_free(full_path_to_icon_file);
|
||||
|
|
@ -117,40 +116,33 @@ gchar * keyman_get_icon_file(const gchar *kmx_file)
|
|||
}
|
||||
|
||||
IBusEngineDesc *
|
||||
ibus_keyman_engine_desc_new (gchar * file_name,
|
||||
gchar *name,
|
||||
gchar *description,
|
||||
gchar *copyright,
|
||||
gchar *lang,
|
||||
gchar *license,
|
||||
gchar *author,
|
||||
gchar *icon,
|
||||
gchar *layout,
|
||||
gchar *version)
|
||||
{
|
||||
IBusEngineDesc *engine_desc;
|
||||
gchar * desc;
|
||||
ibus_keyman_engine_desc_new(
|
||||
gchar *file_name,
|
||||
gchar *name,
|
||||
gchar *description,
|
||||
gchar *copyright,
|
||||
gchar *lang,
|
||||
gchar *license,
|
||||
gchar *author,
|
||||
gchar *icon,
|
||||
gchar *layout,
|
||||
gchar *version
|
||||
) {
|
||||
IBusEngineDesc *engine_desc;
|
||||
g_autofree gchar *desc;
|
||||
|
||||
if (description == NULL) {
|
||||
desc = g_strdup_printf("%s", copyright);
|
||||
}
|
||||
else {
|
||||
desc = g_strdup_printf("%s\n%s", description, copyright);
|
||||
}
|
||||
if (description == NULL) {
|
||||
desc = g_strdup_printf("%s", copyright);
|
||||
} else {
|
||||
desc = g_strdup_printf("%s\n%s", description, copyright);
|
||||
}
|
||||
|
||||
engine_desc = ibus_engine_desc_new_varargs ("name", file_name,
|
||||
"longname", name,
|
||||
"description", desc,
|
||||
"language", lang ? lang : "other",
|
||||
"license", license ? license : "",
|
||||
"author", author ? author : "",
|
||||
"icon", icon,
|
||||
"layout", layout,
|
||||
"version", version ? version : "",
|
||||
NULL);
|
||||
g_free(desc);
|
||||
|
||||
return engine_desc;
|
||||
engine_desc = ibus_engine_desc_new_varargs(
|
||||
"name", file_name, "longname", name, "description", desc, "language", lang ? lang : "other", "license",
|
||||
license ? license : "", "author", author ? author : "", "icon", icon, "layout", layout, "version", version ? version : "",
|
||||
NULL);
|
||||
g_object_ref(engine_desc);
|
||||
return engine_desc;
|
||||
}
|
||||
|
||||
IBusEngineDesc *
|
||||
|
|
@ -166,14 +158,14 @@ get_engine_for_language(
|
|||
return engine_desc;
|
||||
|
||||
int capacity = 255;
|
||||
gchar *name_with_lang = NULL;
|
||||
gchar *minimized_tag = g_new0(gchar, capacity);
|
||||
g_autofree gchar *name_with_lang = NULL;
|
||||
g_autofree gchar *minimized_tag = g_new0(gchar, capacity);
|
||||
int result = bcp47_minimize(lang_id, minimized_tag, capacity);
|
||||
if (result < 0) {
|
||||
g_strlcpy(minimized_tag, lang_id, capacity);
|
||||
}
|
||||
|
||||
gchar *lang_code = g_new0(gchar, capacity);
|
||||
g_autofree gchar *lang_code = g_new0(gchar, capacity);
|
||||
if (!bcp47_get_language_code(minimized_tag, lang_code, capacity)) {
|
||||
g_strlcpy(lang_code, minimized_tag, capacity);
|
||||
}
|
||||
|
|
@ -181,16 +173,15 @@ get_engine_for_language(
|
|||
// If ibus doesn't know about the language then append the
|
||||
// language name to the keyboard name
|
||||
if (lang_name != NULL) {
|
||||
gchar *ibus_lang = ibus_get_untranslated_language_name(lang_code);
|
||||
g_autofree gchar *ibus_lang = ibus_get_untranslated_language_name(lang_code);
|
||||
g_debug("%s: untranslated ibus language for %s: %s", __FUNCTION__, minimized_tag, ibus_lang);
|
||||
if (g_strcmp0(ibus_lang, "Other") == 0) {
|
||||
name_with_lang = g_strjoin(" - ", keyboard->name, lang_name, NULL);
|
||||
}
|
||||
g_free(ibus_lang);
|
||||
}
|
||||
|
||||
gchar *abs_kmx = g_strjoin("/", kmp_dir, keyboard->kmx_file, NULL);
|
||||
gchar *id_with_lang = g_strjoin(":", minimized_tag, abs_kmx, NULL);
|
||||
g_autofree gchar *abs_kmx = g_strjoin("/", kmp_dir, keyboard->kmx_file, NULL);
|
||||
g_autofree gchar *id_with_lang = g_strjoin(":", minimized_tag, abs_kmx, NULL);
|
||||
|
||||
g_message("adding engine %s", id_with_lang);
|
||||
engine_desc = ibus_keyman_engine_desc_new(
|
||||
|
|
@ -204,11 +195,6 @@ get_engine_for_language(
|
|||
keyman_get_icon_file(abs_kmx), // icon full path
|
||||
"us", // layout defaulting to us (en-US)
|
||||
keyboard->version);
|
||||
g_free(abs_kmx);
|
||||
g_free(lang_code);
|
||||
g_free(minimized_tag);
|
||||
g_free(id_with_lang);
|
||||
g_free(name_with_lang);
|
||||
return engine_desc;
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +209,7 @@ keyman_add_keyboard(gpointer data, gpointer user_data) {
|
|||
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);
|
||||
gchar *kmx_file = g_path_get_basename(engine_name);
|
||||
g_autofree gchar *kmx_file = g_path_get_basename(engine_name);
|
||||
// If we already have an engine for this keyboard (in a different area), we
|
||||
// don't want to add it again since we wouldn't add anything new
|
||||
// if it's the same version
|
||||
|
|
@ -232,14 +218,12 @@ keyman_add_keyboard(gpointer data, gpointer user_data) {
|
|||
alreadyexists = TRUE;
|
||||
g_debug("keyboard %s already exists at version %s which is newer or same as %s", kmx_file, version, keyboard->version);
|
||||
}
|
||||
g_free(kmx_file);
|
||||
}
|
||||
|
||||
if (!alreadyexists) {
|
||||
gchar *json_file = g_strjoin(".", keyboard->id, "json", NULL);
|
||||
keyboard_details *kbd_details = g_new0(keyboard_details, 1);
|
||||
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_free(json_file);
|
||||
|
||||
if (keyboard->languages != NULL) {
|
||||
for (GList *l = keyboard->languages; l != NULL; l = l->next) {
|
||||
|
|
@ -251,7 +235,7 @@ keyman_add_keyboard(gpointer data, gpointer user_data) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
gchar *abs_kmx = g_strjoin("/", kb_data->kmp_dir, keyboard->kmx_file, NULL);
|
||||
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,
|
||||
|
|
@ -266,10 +250,7 @@ keyman_add_keyboard(gpointer data, gpointer user_data) {
|
|||
keyman_get_icon_file(abs_kmx), // icon full path
|
||||
"us", // layout defaulting to us (en-US)
|
||||
keyboard->version));
|
||||
g_free(abs_kmx);
|
||||
}
|
||||
free_keyboard_details(kbd_details);
|
||||
g_free(kbd_details);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +260,7 @@ keyman_add_keyboards_from_dir(gpointer data, gpointer user_data) {
|
|||
gchar * kmp_dir = (gchar *) data;
|
||||
GList ** engines_list = (GList **)user_data;
|
||||
|
||||
kmp_details *details = g_new0(kmp_details, 1);
|
||||
g_autoptr(kmp_details) details = g_new0(kmp_details, 1);
|
||||
if (get_kmp_details(kmp_dir, details) == JSON_OK) {
|
||||
add_keyboard_data kb_data;
|
||||
kb_data.engines_list = *engines_list;
|
||||
|
|
@ -289,8 +270,6 @@ keyman_add_keyboards_from_dir(gpointer data, gpointer user_data) {
|
|||
g_list_foreach(details->keyboards, keyman_add_keyboard, &kb_data);
|
||||
*engines_list = kb_data.engines_list;
|
||||
}
|
||||
free_kmp_details(details);
|
||||
g_free(details);
|
||||
}
|
||||
|
||||
GList *
|
||||
|
|
@ -298,7 +277,8 @@ ibus_keyman_list_engines (void)
|
|||
{
|
||||
GList *engines = NULL;
|
||||
GList *kmpdir_list;
|
||||
gchar *local_keyboard_path, *xdgenv;
|
||||
gchar *xdgenv;
|
||||
g_autofree gchar *local_keyboard_path;
|
||||
|
||||
g_debug("adding from /usr/share/keyman");
|
||||
kmpdir_list = keyman_get_kmpdirs_fromdir(NULL, "/usr/share/keyman");
|
||||
|
|
@ -314,9 +294,8 @@ ibus_keyman_list_engines (void)
|
|||
}
|
||||
g_debug("adding from %s", local_keyboard_path);
|
||||
kmpdir_list = keyman_get_kmpdirs_fromdir(kmpdir_list, local_keyboard_path);
|
||||
g_free(local_keyboard_path);
|
||||
g_list_foreach(kmpdir_list, keyman_add_keyboards_from_dir, &engines);
|
||||
g_list_free(kmpdir_list);
|
||||
g_list_free_full(kmpdir_list, g_free);
|
||||
|
||||
return engines;
|
||||
}
|
||||
|
|
@ -325,13 +304,12 @@ void
|
|||
add_engine(gpointer data, gpointer user_data) {
|
||||
IBusEngineDesc *desc = IBUS_ENGINE_DESC(data);
|
||||
IBusComponent *component = IBUS_COMPONENT(user_data);
|
||||
ibus_component_add_engine(component, desc);
|
||||
ibus_component_add_engine(component, g_object_ref(desc));
|
||||
}
|
||||
|
||||
IBusComponent *
|
||||
ibus_keyman_get_component (void)
|
||||
{
|
||||
GList *engines;
|
||||
IBusComponent *component;
|
||||
|
||||
component = ibus_component_new ("org.freedesktop.IBus.Keyman",
|
||||
|
|
@ -343,9 +321,8 @@ ibus_keyman_get_component (void)
|
|||
"",
|
||||
"ibus-keyman");
|
||||
|
||||
engines = ibus_keyman_list_engines ();
|
||||
g_autolist(IBusEngineDesc) engines = ibus_keyman_list_engines();
|
||||
g_list_foreach(engines, add_engine, component);
|
||||
g_list_free (engines);
|
||||
|
||||
return component;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,4 +36,7 @@ IBusEngineDesc *get_engine_for_language(
|
|||
void keyman_add_keyboard(gpointer data, gpointer user_data);
|
||||
void keyman_add_keyboards_from_dir(gpointer data, gpointer user_data);
|
||||
|
||||
#endif // __KEYMANUTIL_INTERNAL_H__
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(IBusEngineDesc, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(IBusComponent, g_object_unref)
|
||||
|
||||
#endif // __KEYMANUTIL_INTERNAL_H__
|
||||
|
|
|
|||
|
|
@ -158,7 +158,8 @@ void kmp_keyboards_foreach (JsonArray *array,
|
|||
JsonObject *keyboard_object;
|
||||
JsonNode *languages_node;
|
||||
GList *l;
|
||||
gchar *l_kmx_file, *l_kvk_file;
|
||||
g_autofree gchar *l_kmx_file = NULL;
|
||||
g_autofree gchar *l_kvk_file = NULL;
|
||||
kmp_fileinfo *fileinfo;
|
||||
kmp_details *details;
|
||||
kmp_keyboard *keyboard;
|
||||
|
|
@ -201,8 +202,6 @@ void kmp_keyboards_foreach (JsonArray *array,
|
|||
}
|
||||
}
|
||||
}
|
||||
g_free(l_kmx_file);
|
||||
g_free(l_kvk_file);
|
||||
}
|
||||
details->keyboards = g_list_append(details->keyboards, keyboard);
|
||||
}
|
||||
|
|
@ -232,17 +231,16 @@ void kmp_files_foreach (JsonArray *array,
|
|||
|
||||
kmp_json_status get_keyboard_details(const char *kmp_dir, const char *id, keyboard_details *keyboard)
|
||||
{
|
||||
JsonParser *parser;
|
||||
g_autoptr(JsonParser) parser;
|
||||
JsonObject *object;
|
||||
JsonNode *root;
|
||||
gchar *json_file;
|
||||
GError *error = NULL;
|
||||
g_autofree gchar *json_file;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
parser = json_parser_new ();
|
||||
json_file = g_strjoin("/", kmp_dir, id, NULL);
|
||||
|
||||
if (!g_file_test(json_file, G_FILE_TEST_EXISTS)) {
|
||||
g_free(json_file);
|
||||
return JSON_FILE_NOT_EXISTS;
|
||||
}
|
||||
|
||||
|
|
@ -252,12 +250,8 @@ kmp_json_status get_keyboard_details(const char *kmp_dir, const char *id, keyboa
|
|||
if (error)
|
||||
{
|
||||
g_warning ("Unable to parse `%s': %s\n", json_file, error->message);
|
||||
g_free(json_file);
|
||||
g_error_free (error);
|
||||
g_object_unref (parser);
|
||||
return JSON_PARSE_ERROR;
|
||||
}
|
||||
g_free(json_file);
|
||||
|
||||
root = json_parser_get_root (parser);
|
||||
|
||||
|
|
@ -270,25 +264,23 @@ kmp_json_status get_keyboard_details(const char *kmp_dir, const char *id, keyboa
|
|||
get_detail_from_object(object, "license",
|
||||
&(keyboard->license));
|
||||
}
|
||||
g_object_unref(parser);
|
||||
return JSON_OK;
|
||||
}
|
||||
|
||||
kmp_json_status get_kmp_details(const char *kmp_dir, kmp_details *details)
|
||||
{
|
||||
JsonParser *parser;
|
||||
g_autoptr(JsonParser) parser;
|
||||
JsonNode *root;
|
||||
JsonObject *root_object, *object;
|
||||
JsonArray *array;
|
||||
JsonNode *kmp_system, *kmp_info, *kmp_options, *kmp_files, *kmp_keyboards;
|
||||
gchar *kmp_json;
|
||||
GError *error = NULL;
|
||||
g_autofree gchar *kmp_json;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
parser = json_parser_new ();
|
||||
kmp_json = g_strdup_printf("%s/kmp.json", kmp_dir);
|
||||
|
||||
if (!g_file_test(kmp_json, G_FILE_TEST_EXISTS)) {
|
||||
g_free(kmp_json);
|
||||
return JSON_FILE_NOT_EXISTS;
|
||||
}
|
||||
|
||||
|
|
@ -298,12 +290,8 @@ kmp_json_status get_kmp_details(const char *kmp_dir, kmp_details *details)
|
|||
if (error)
|
||||
{
|
||||
g_warning ("Unable to parse `%s': %s\n", kmp_json, error->message);
|
||||
g_free(kmp_json);
|
||||
g_error_free (error);
|
||||
g_object_unref (parser);
|
||||
return JSON_PARSE_ERROR;
|
||||
}
|
||||
g_free(kmp_json);
|
||||
|
||||
root = json_parser_get_root (parser);
|
||||
|
||||
|
|
@ -369,7 +357,6 @@ kmp_json_status get_kmp_details(const char *kmp_dir, kmp_details *details)
|
|||
}
|
||||
}
|
||||
}
|
||||
g_object_unref(parser);
|
||||
return JSON_OK;
|
||||
}
|
||||
|
||||
|
|
@ -425,6 +412,7 @@ void free_language(gpointer data)
|
|||
kmp_language *language = (kmp_language *) data;
|
||||
g_free(language->name);
|
||||
g_free(language->id);
|
||||
g_free(language);
|
||||
}
|
||||
|
||||
void free_keyboard(gpointer data)
|
||||
|
|
@ -438,6 +426,7 @@ void free_keyboard(gpointer data)
|
|||
if (keyboard->languages != NULL) {
|
||||
g_list_free_full(keyboard->languages, (GDestroyNotify)free_language);
|
||||
}
|
||||
g_free(keyboard);
|
||||
}
|
||||
|
||||
void free_fileinfo(gpointer data)
|
||||
|
|
@ -445,6 +434,7 @@ void free_fileinfo(gpointer data)
|
|||
kmp_fileinfo *fileinfo = (kmp_fileinfo *) data;
|
||||
g_free(fileinfo->name);
|
||||
g_free(fileinfo->description);
|
||||
g_free(fileinfo);
|
||||
}
|
||||
|
||||
kmp_json_status free_keyboard_details(keyboard_details *kbd_details)
|
||||
|
|
@ -452,6 +442,7 @@ kmp_json_status free_keyboard_details(keyboard_details *kbd_details)
|
|||
g_free(kbd_details->id);
|
||||
g_free(kbd_details->description);
|
||||
g_free(kbd_details->license);
|
||||
g_free(kbd_details);
|
||||
return JSON_OK;
|
||||
}
|
||||
|
||||
|
|
@ -475,7 +466,9 @@ void free_info(gpointer data) {
|
|||
|
||||
kmp_json_status free_kmp_details(kmp_details * details)
|
||||
{
|
||||
g_assert(details != NULL);
|
||||
if (details == NULL)
|
||||
return JSON_OK;
|
||||
|
||||
g_free(details->system.fileVersion);
|
||||
g_free(details->system.keymanDeveloperVersion);
|
||||
g_free(details->options.readmeFile);
|
||||
|
|
@ -487,5 +480,6 @@ kmp_json_status free_kmp_details(kmp_details * details)
|
|||
if (details->files != NULL) {
|
||||
g_list_free_full(details->files, (GDestroyNotify)free_fileinfo);
|
||||
}
|
||||
g_free(details);
|
||||
return JSON_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,5 +79,12 @@ kmp_json_status free_kmp_details(kmp_details * details);
|
|||
kmp_json_status get_keyboard_details(const gchar *kmp_dir, const gchar *id, keyboard_details *details);
|
||||
kmp_json_status free_keyboard_details(keyboard_details * details);
|
||||
kmp_json_status print_kmp_details(kmp_details * details);
|
||||
void free_keyboard(gpointer data);
|
||||
void free_info(gpointer data);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(kmp_keyboard, free_keyboard)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(kmp_info, free_info)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(kmp_details, free_kmp_details)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(keyboard_details, free_keyboard_details)
|
||||
|
||||
#endif // __KMPDETAILS_H__
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "engine.h"
|
||||
#include "keyman-service.h"
|
||||
#include "keymanutil.h"
|
||||
#include "keymanutil_internal.h"
|
||||
|
||||
static IBusBus *bus = NULL;
|
||||
static IBusFactory *factory = NULL;
|
||||
|
|
@ -52,8 +53,8 @@ ibus_disconnected_cb(IBusBus *unused_bus, gpointer unused_data) {
|
|||
KeymanService *service = km_service_get_default(NULL);
|
||||
g_clear_object(&service);
|
||||
|
||||
g_object_unref(factory);
|
||||
g_object_unref(bus);
|
||||
if (factory) g_object_unref(factory);
|
||||
if (bus) g_object_unref(bus);
|
||||
|
||||
ibus_quit();
|
||||
}
|
||||
|
|
@ -66,26 +67,29 @@ add_single_keyboard(gpointer data, gpointer user_data) {
|
|||
#else
|
||||
const gchar *engine_name = engine->name;
|
||||
#endif /* !IBUS_CHECK_VERSION(1,3,99) */
|
||||
ibus_factory_add_engine(factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE);
|
||||
if (engine_name) {
|
||||
ibus_factory_add_engine(factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE);
|
||||
} else {
|
||||
g_error("%s: Trying to add NULL engine", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_keyboards(IBusBus *bus, gpointer user_data) {
|
||||
GList *engines;
|
||||
IBusComponent *component;
|
||||
g_autolist(IBusEngineDesc) engines;
|
||||
g_autoptr(IBusComponent) component;
|
||||
|
||||
g_message("Adding keyboards to ibus");
|
||||
|
||||
component = ibus_keyman_get_component();
|
||||
|
||||
GDBusConnection *connection = ibus_bus_get_connection(bus);
|
||||
factory = ibus_factory_new(connection);
|
||||
factory = ibus_factory_new(g_object_ref(connection));
|
||||
|
||||
g_signal_connect(bus, "disconnected", G_CALLBACK(ibus_disconnected_cb), NULL);
|
||||
|
||||
engines = ibus_component_get_engines(component);
|
||||
g_list_foreach(engines, add_single_keyboard, NULL);
|
||||
g_list_free(engines);
|
||||
|
||||
if (ibus) {
|
||||
ibus_bus_request_name(bus, "org.freedesktop.IBus.Keyman", 0);
|
||||
|
|
@ -93,7 +97,6 @@ add_keyboards(IBusBus *bus, gpointer user_data) {
|
|||
ibus_bus_register_component(bus, component);
|
||||
}
|
||||
|
||||
g_object_unref(component);
|
||||
km_service_get_default(NULL); // initialise dbus service
|
||||
}
|
||||
|
||||
|
|
@ -117,8 +120,8 @@ start_component(void) {
|
|||
|
||||
static void
|
||||
print_engines_xml(void) {
|
||||
IBusComponent *component;
|
||||
GString *output;
|
||||
g_autoptr(IBusComponent) component;
|
||||
g_autoptr(GString) output;
|
||||
|
||||
ibus_init();
|
||||
|
||||
|
|
@ -128,9 +131,6 @@ print_engines_xml(void) {
|
|||
ibus_component_output_engines(component, output, 0);
|
||||
|
||||
fprintf(stdout, "%s", output->str);
|
||||
|
||||
g_string_free(output, TRUE);
|
||||
g_object_unref(component);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -145,7 +145,9 @@ main(gint argc, gchar **argv) {
|
|||
g_option_context_add_main_entries(context, entries, "ibus-keyman");
|
||||
|
||||
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
||||
g_assert(error != NULL);
|
||||
g_print("Option parsing failed: %s\n", error->message);
|
||||
g_error_free(error);
|
||||
g_option_context_free(context);
|
||||
exit(-1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,16 +86,7 @@ _free_tst_kb_data(add_keyboard_data* kb_data) {
|
|||
g_free(kb_data);
|
||||
}
|
||||
|
||||
// defined in kmpdetails
|
||||
void free_keyboard(gpointer data);
|
||||
void free_info(gpointer data);
|
||||
kmp_json_status free_keyboard_details(keyboard_details* kbd_details);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(add_keyboard_data, _free_tst_kb_data)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(kmp_keyboard, free_keyboard)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(kmp_info, free_info)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(keyboard_details, free_keyboard_details)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(IBusEngineDesc, g_object_unref)
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
void
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ int
|
|||
main (gint argc, gchar **argv)
|
||||
{
|
||||
struct stat filestat;
|
||||
kmp_details details;
|
||||
gchar *kmp_json;
|
||||
g_autofree gchar *kmp_json = NULL;
|
||||
g_autoptr(kmp_details) details = g_new0(kmp_details, 1);
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
|
|
@ -29,16 +29,13 @@ main (gint argc, gchar **argv)
|
|||
{
|
||||
g_print ("Usage: kmpdetails <path to kmp.json>\n");
|
||||
g_print ("ERROR: file %s not found\n", kmp_json);
|
||||
g_free(kmp_json);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
g_free(kmp_json);
|
||||
setlocale(LC_ALL, "C.UTF-8");
|
||||
|
||||
get_kmp_details(argv[1], &details);
|
||||
print_kmp_details(&details);
|
||||
free_kmp_details(&details);
|
||||
get_kmp_details(argv[1], details);
|
||||
print_kmp_details(details);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -346,9 +346,10 @@ function check_processes_running() {
|
|||
|
||||
if $MISSING; then
|
||||
echo "# Some background processes no longer running. Restarting..."
|
||||
echo "Some background processes no longer running:" > /tmp/debug.output
|
||||
echo "Some background processes no longer running:" >> /tmp/debug.output
|
||||
echo "$MISSING_PROCS" >> /tmp/debug.output
|
||||
echo "Restarting..." >> /tmp/debug.output
|
||||
mv /tmp/ibus-engine-keyman.log{,"-$(date -Iseconds)"}
|
||||
cleanup "${CLEANUP_FILE}" > /dev/null 2>&1
|
||||
setup "${DISPLAY_SERVER}" "${ENV_FILE}" "${CLEANUP_FILE}" "${PID_FILE}" > /dev/null 2>&1
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue