diff options
Diffstat (limited to 'kxkb/x11helper.cpp')
-rw-r--r-- | kxkb/x11helper.cpp | 138 |
1 files changed, 111 insertions, 27 deletions
diff --git a/kxkb/x11helper.cpp b/kxkb/x11helper.cpp index aa39845dd..90e29d9e2 100644 --- a/kxkb/x11helper.cpp +++ b/kxkb/x11helper.cpp @@ -1,3 +1,4 @@ +#include <tqdom.h> #include <tqdir.h> #include <tqstring.h> #include <tqwindowdefs.h> @@ -7,6 +8,8 @@ #include <tqregexp.h> #include <kdebug.h> +#include <kstandarddirs.h> +#include <tdelocale.h> #include <X11/Xlib.h> #include <X11/Xatom.h> @@ -22,20 +25,37 @@ // Compiler will size array automatically. static const char* X11DirList[] = { +#ifdef X11_XKB_RULES_DIR + X11_XKB_RULES_DIR, +#endif XLIBDIR, "/usr/share/X11/", - "/etc/X11/", - "/usr/local/share/X11/", + "/usr/lib/X11/", + "/usr/lib64/X11/", + "/usr/X11/share/X11/", + "/usr/X11/lib/X11/", + "/usr/X11/lib64/X11/", + "/usr/X11R7/share/X11/", + "/usr/X11R7/lib/X11/", + "/usr/X11R7/lib64/X11/", + "/usr/X11R6/share/X11/", "/usr/X11R6/lib/X11/", "/usr/X11R6/lib64/X11/", + "/usr/local/X11/share/X11/", + "/usr/local/X11/lib/X11/", + "/usr/local/X11/lib64/X11/", + "/usr/local/X11R7/share/X11/", + "/usr/local/X11R7/lib/X11/", + "/usr/local/X11R7/lib64/X11/", + "/usr/local/X11R6/share/X11/", "/usr/local/X11R6/lib/X11/", "/usr/local/X11R6/lib64/X11/", - "/usr/lib/X11/", - "/usr/lib64/X11/", + "/usr/local/share/X11/", "/usr/local/lib/X11/", "/usr/local/lib64/X11/", "/usr/pkg/share/X11/", - "/usr/pkg/xorg/lib/X11/" + "/usr/pkg/xorg/lib/X11/", + "/etc/X11/" }; // Compiler will size array automatically. @@ -102,13 +122,12 @@ X11Helper::findXkbRulesFile(TQString x11Dir, Display *dpy) } } } - + return rulesFile; } RulesInfo* -X11Helper::loadRules(const TQString& file, bool layoutsOnly) -{ +X11Helper::loadRules(const TQString& file, bool layoutsOnly) { XkbRF_RulesPtr xkbRules = XkbRF_Load(TQFile::encodeName(file).data(), "", true, true); if (xkbRules == NULL) { @@ -134,32 +153,87 @@ X11Helper::loadRules(const TQString& file, bool layoutsOnly) XkbRF_Free(xkbRules, true); return rulesInfo; } - + for (int i = 0; i < xkbRules->models.num_desc; ++i) rulesInfo->models.replace(xkbRules->models.desc[i].name, tqstrdup( xkbRules->models.desc[i].desc ) ); - for (int i = 0; i < xkbRules->options.num_desc; ++i) - rulesInfo->options.replace(xkbRules->options.desc[i].name, tqstrdup( xkbRules->options.desc[i].desc ) ); - XkbRF_Free(xkbRules, true); + // Prefer XML file for Xkb options + if (TQFile(file + ".xml").exists()) { + XkbRF_Free(xkbRules, true); + + TQDomDocument xmlrules("xkbrules"); + TQFile xmlfile(file + ".xml"); + if (!xmlfile.open(IO_ReadOnly)) { + return NULL; + } + if (!xmlrules.setContent(&xmlfile)) { + xmlfile.close(); + return NULL; + } + xmlfile.close(); + + TQDomElement options = xmlrules.documentElement().namedItem("optionList").toElement(); + TQDomNode optGroupNode = options.firstChild(); + while (!optGroupNode.isNull()) { + TQDomElement optGroupElem = optGroupNode.toElement(); + if (optGroupElem.tagName() == "group") { + TQDomNode optNode = optGroupElem.firstChild(); + while (!optNode.isNull()) { + TQDomElement optElem = optNode.toElement(); + if (!optElem.isNull()) { + // This might be either a configItem (group) or an option tag + // If it is an option tag, it contains a configItem that describes + // the option + if (optElem.tagName() == "option") { + optElem = optElem.namedItem("configItem").toElement(); + } + + TQString optName = optElem.namedItem("name").toElement().text(); + TQString optDesc = optElem.namedItem("description").toElement().text(); + 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; + + // 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(); + } + } + else { + for (int i = 0; i < xkbRules->options.num_desc; ++i) + rulesInfo->options.replace(xkbRules->options.desc[i].name, tqstrdup( xkbRules->options.desc[i].desc ) ); + + XkbRF_Free(xkbRules, true); + + // workaround for empty 'compose' options group description + if( rulesInfo->options.find("compose:menu") && !rulesInfo->options.find("compose") ) { + rulesInfo->options.replace("compose", I18N_NOOP("Compose Key Position")); + } + } -// workaround for empty 'compose' options group description - if( rulesInfo->options.find("compose:menu") && !rulesInfo->options.find("compose") ) { - rulesInfo->options.replace("compose", "Compose Key Position"); - } for(TQDictIterator<char> it(rulesInfo->options) ; it.current() != NULL; ++it ) { - 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; - } - } + // 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" ); @@ -318,3 +392,13 @@ bool X11Helper::areSingleGroupsSupported() { return true; //TODO: } + +void X11Helper::initializeTranslations() { + // TDE is usually installed into some non-standard prefix and by default system-wide locale + // dirs are not considered when searching for gettext message catalogues, so we have to add + // it explicitly. +#ifdef WITH_XKB_TRANSLATIONS + TDEGlobal::dirs()->addResourceDir("locale", XKB_CONFIG_LOCALE_DIR); + TDEGlobal::locale()->insertCatalogue("xkeyboard-config"); +#endif +} |