From 3416043a67601333536baf76705d13983b929aab Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Sat, 1 Nov 2025 18:24:25 +0600 Subject: [PATCH] Fixes --- source/CMakeLists.txt | 1 - source/ubl-settings-keyboard.c | 67 +++++++--------------------------- source/ubl-settings-keyboard.h | 5 +-- 3 files changed, 15 insertions(+), 58 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 81cad36..5cabe32 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -84,7 +84,6 @@ set(LIBRARIES ${UTILS_LIBRARIES} ${VTE291_LIBRARIES} pthread - xml2 ublsettings ublsettings-gtk3 ublsettingsui-gtk3) diff --git a/source/ubl-settings-keyboard.c b/source/ubl-settings-keyboard.c index 4a59358..f0f1ba3 100644 --- a/source/ubl-settings-keyboard.c +++ b/source/ubl-settings-keyboard.c @@ -3,55 +3,6 @@ config main_config; -const char *get_localized_layout_name(const char *layout_code) { - static char name[128]; - name[0] = '\0'; - - setlocale(LC_ALL, ""); - const char *lang = getenv("LANG"); - if (!lang) lang = "en"; - char lang_short[8]; - sscanf(lang, "%2s", lang_short); - - xmlDoc *doc = xmlReadFile("/usr/share/X11/xkb/rules/base.xml", NULL, 0); - if (!doc) return layout_code; - - xmlNode *root = xmlDocGetRootElement(doc); - for (xmlNode *layout = root->children; layout; layout = layout->next) { - if (layout->type == XML_ELEMENT_NODE && strcmp((char *)layout->name, "layout") == 0) { - xmlNode *config = layout->children; - const char *found_name = NULL; - const char *found_desc = NULL; - - for (xmlNode *n = config; n; n = n->next) { - if (n->type == XML_ELEMENT_NODE && strcmp((char *)n->name, "configItem") == 0) { - for (xmlNode *m = n->children; m; m = m->next) { - if (m->type != XML_ELEMENT_NODE) continue; - if (strcmp((char *)m->name, "name") == 0) - found_name = (char *)xmlNodeGetContent(m); - else if (strcmp((char *)m->name, "description") == 0) { - xmlChar *langAttr = xmlGetProp(m, (const xmlChar *)"xml:lang"); - if (langAttr && strncmp((char *)langAttr, lang_short, 2) == 0) - found_desc = (char *)xmlNodeGetContent(m); - xmlFree(langAttr); - } - } - } - } - - if (found_name && strcmp(found_name, layout_code) == 0) { - if (found_desc) - snprintf(name, sizeof(name), "%s", found_desc); - else - snprintf(name, sizeof(name), "%s", layout_code); - break; - } - } - } - xmlFreeDoc(doc); - xmlCleanupParser(); - return name[0] ? name : layout_code; -} void on_save_done(main_window *, config_str output, int size){ @@ -215,7 +166,7 @@ gboolean yon_interface_update(main_window *widgets){ int size=0; name = yon_config_get_by_key(keyboard_layout_parameter); config_str layouts = yon_char_parse(name,&size,","); - GtkTreeIter iter, itar; + GtkTreeIter iter, itar,itor; char *rid,*rname; gtk_list_store_clear(widgets->layoutsList); for (int i=0;ilayoutsList,&itar); gtk_list_store_set(widgets->layoutsList,&itar,0,rname,1,rid,2,1,-1); } + for(int valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(main_config.layouts_list),&itor,&iter);valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(main_config.layouts_list),&itor)){ + gtk_tree_model_get(GTK_TREE_MODEL(main_config.layouts_list),&itor,0,&rid,1,&rname,-1); + + if (!strcmp(layouts[i],rid)){ + gtk_list_store_append(widgets->layoutsList,&itar); + gtk_list_store_set(widgets->layoutsList,&itar,0,rname,1,rid,2,1,-1); + } + } } } } @@ -503,13 +462,15 @@ void yon_main_window_complete(main_window *widgets){ config_str layout = yon_char_parse(rtn[i],&laysize,"|"); if (yon_char_is_empty(layout[1])){ gtk_tree_store_append(main_config.layouts_list,&iter,NULL); - gtk_tree_store_set(main_config.layouts_list,&iter,0,layout[0],1,get_localized_layout_name(layout[2]),-1); + textdomain("iso_639"); + gtk_tree_store_set(main_config.layouts_list,&iter,0,layout[0],1,_(layout[2]),-1); + textdomain(LocaleName); } else { char *full_layout = yon_char_unite(layout[0],"_",layout[1],NULL); gtk_tree_store_append(main_config.layouts_list,&chiter,&iter); - textdomain("iso639"); - gtk_tree_store_set(main_config.layouts_list,&chiter,0,full_layout,1,get_localized_layout_name(layout[2]),-1); + textdomain("iso_639"); + gtk_tree_store_set(main_config.layouts_list,&chiter,0,full_layout,1,_(layout[2]),-1); textdomain(LocaleName); free(full_layout); diff --git a/source/ubl-settings-keyboard.h b/source/ubl-settings-keyboard.h index 007e003..c6501c0 100644 --- a/source/ubl-settings-keyboard.h +++ b/source/ubl-settings-keyboard.h @@ -9,8 +9,6 @@ #include #include #include -#include -#include #ifdef WEBKIT_FOUND #include @@ -164,5 +162,4 @@ void on_num_lock_changed(GtkComboBox *self, main_window *widgets); void on_layouts_remove(GtkWidget *, main_window *widgets); void yon_layouts_save(main_window *widgets); void on_layouts_chosen(GtkCellRenderer *self, gchar *path, layouts_window *window); -GList *yon_get_all_selected(GtkTreeView *tree, int column); -const char *get_localized_layout_name(const char *layout_code); \ No newline at end of file +GList *yon_get_all_selected(GtkTreeView *tree, int column); \ No newline at end of file