From e379ec4b68483613c30eee4500f5bdead32c903e Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Fri, 29 Mar 2024 22:43:34 +0300
Subject: kxkb: add options without group to the custom group

Bug: https://mirror.git.trinitydesktop.org/gitea/TDE/tdebase/issues/450
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 kxkb/kcmlayout.cpp | 42 ++++++++++++++++++++++++++----------------
 kxkb/x11helper.cpp | 29 +++++++++--------------------
 2 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/kxkb/kcmlayout.cpp b/kxkb/kcmlayout.cpp
index d9efb9e57..0156978c9 100644
--- a/kxkb/kcmlayout.cpp
+++ b/kxkb/kcmlayout.cpp
@@ -750,20 +750,23 @@ TQWidget* LayoutConfig::makeOptionsTab()
     if (pos >= 0)
     {
       OptionListItem *parent = m_optionGroups[key.left(pos)];
-      if (parent == NULL )
-        parent = m_optionGroups["misc"];
-      if (parent != NULL) {
-      // workaroung for mistake in rules file for xkb options in XFree 4.2.0
-        TQString text(it.current());
-        text = text.replace( "Cap$", "Caps." );
-        if ( parent->type() == TQCheckListItem::CheckBoxController
-             || key.startsWith("grp:"))
-            new OptionListItem(parent, XkbRules::trOpt(text),
-                TQCheckListItem::CheckBox, key);
-        else
-            new OptionListItem(parent, XkbRules::trOpt(text),
-                TQCheckListItem::RadioButton, key);
+      if (parent == NULL ) { // All unparanted options go into "custom" group
+        parent = m_optionGroups["custom"];
+        if (parent == NULL ) {
+          parent = new OptionListItem(listView, XkbRules::trOpt( I18N_NOOP("Miscellaneous options") ),
+              TQCheckListItem::CheckBoxController, "custom");
+        }
       }
+      // workaroung for mistake in rules file for xkb options in XFree 4.2.0
+      TQString text(it.current());
+      text = text.replace( "Cap$", "Caps." );
+      if ( parent->type() == TQCheckListItem::CheckBoxController
+           || key.startsWith("grp:"))
+          new OptionListItem(parent, XkbRules::trOpt(text),
+              TQCheckListItem::CheckBox, key);
+      else
+          new OptionListItem(parent, XkbRules::trOpt(text),
+              TQCheckListItem::RadioButton, key);
     }
   }
 
@@ -1193,10 +1196,17 @@ OptionListItem* LayoutConfig::itemForOption(TQString option) {
     OptionListItem *item = m_optionGroups[optionKey];
 
     if( !item ) {
-        kdDebug() << "WARNING: skipping empty group for " << option << endl;
-        return nullptr;
+        item = m_optionGroups["custom"];
+        if( !item ) {
+            kdDebug() << "WARNING: no group for item '"<< option << "' and 'custom' group does not exists" << endl;
+            return nullptr;
+        }
+    }
+    OptionListItem *rv = item->findChildItem(option);
+    if( !rv ) {
+        kdDebug() << "WARNING: no group for item '"<< option << "' and it's not in group 'custom'" << endl;
     }
-    return (OptionListItem*)item->findChildItem(option);
+    return rv;
 }
 
 TQString LayoutConfig::createOptionString()
diff --git a/kxkb/x11helper.cpp b/kxkb/x11helper.cpp
index d325b32a0..b2fbd5ae6 100644
--- a/kxkb/x11helper.cpp
+++ b/kxkb/x11helper.cpp
@@ -177,8 +177,10 @@ X11Helper::loadRules(const TQString& file, bool layoutsOnly) {
       while (!optGroupNode.isNull()) {
           TQDomElement optGroupElem = optGroupNode.toElement();
           if (optGroupElem.tagName() == "group") {
-              TQDomNode optNode = optGroupElem.firstChild();
-              while (!optNode.isNull()) {
+              for (TQDomNode optNode = optGroupElem.firstChild();
+                   !optNode.isNull();
+                   optNode = optNode.nextSibling()
+              ) {
                 TQDomElement optElem = optNode.toElement();
                 if (!optElem.isNull()) {
                     // This might be either a configItem (group) or an option tag
@@ -193,16 +195,17 @@ X11Helper::loadRules(const TQString& file, bool layoutsOnly) {
                     if (optDesc.isEmpty()) {
                         optDesc = optName;
                     }
-                    // Items from these 'meta' groups fall into other groups
-                    // Admittedly not the best way to handle this
-                    if (optName == "currencysign" || optName == "compat") break;
+                    // Items from these 'meta' groups fall into other groups.  They all will be
+                    // added to the "cystom" group as orphans and to avoid displaying empty groups
+                    // we won't be skipping the groups themself.
+                    // Admittedly not the best way to handle this.
+                    if (optName == "currencysign" || optName == "compat") continue;
 
                     // HACK this should be called "compose" or else the code breaks
                     if (optName == "Compose key") optName = "compose";
 
                     rulesInfo->options.replace(optName.ascii(), tqstrdup(optDesc.ascii()));
                 }
-                optNode = optNode.nextSibling();
               }
           }
           optGroupNode = optGroupNode.nextSibling();
@@ -220,20 +223,6 @@ X11Helper::loadRules(const TQString& file, bool layoutsOnly) {
       }
   }
 
-
-  for(TQDictIterator<char> it(rulesInfo->options) ; it.current() != NULL; ++it ) {
-      // Add missing option groups
-      TQString option(it.currentKey());
-      int columnPos = option.find(":");
-
-      if( columnPos != -1 ) {
-          TQString group = option.mid(0, columnPos);
-          if( rulesInfo->options.find(group) == NULL ) {
-              rulesInfo->options.replace(group, group.latin1());
-              kdDebug() << "Added missing option group: " << group << endl;
-          }
-      }
-  }
 //   // workaround for empty misc options group description in XFree86 4.4.0
 //   if( rulesInfo->options.find("numpad:microsoft") && !rulesInfo->options.find("misc") ) {
 //     rulesInfo->options.replace("misc", "Miscellaneous compatibility options" );
-- 
cgit v1.2.3

