2 * Copyright (C) 2003-2006 Andriy Rysin (rysin@kde.org)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <QtGui/QWidgetList>
22 #include <QTextStream>
26 #include <kstandarddirs.h>
30 #include <config-workspace.h>
32 #include "x11helper.h"
36 #include "xklavier_adaptor.h"
39 #include "kxkbconfig.h"
42 static const QRegExp
NON_CLEAN_LAYOUT_REGEXP("[^a-z]");
44 //bool XkbRules::m_layoutsClean = true;
46 XkbRules::XkbRules(bool layoutsOnly
)
49 loadNewRules(layoutsOnly
);
51 X11_DIR
= X11Helper::findX11Dir();
53 if( X11_DIR
== NULL
) {
54 kError() << "Cannot find X11 directory!" << endl
;
59 QString rulesFile
= X11Helper::findXkbRulesFile(X11_DIR
, QX11Info::display());
61 if( rulesFile
.isEmpty() ) {
62 kError() << "Cannot find rules file in " << X11_DIR
<< endl
;
67 loadRules(rulesFile
, layoutsOnly
);
75 void XkbRules::loadNewRules(bool layoutsOnly
)
77 XKlavierAdaptor
* xklAdaptor
= XKlavierAdaptor::getInstance(QX11Info::display());
78 xklAdaptor
->loadXkbConfig(layoutsOnly
);
80 m_layouts
= xklAdaptor
->getLayouts();
81 if( layoutsOnly
== false ) {
82 m_models
= xklAdaptor
->getModels();
83 m_varLists
= xklAdaptor
->getVariants();
84 m_optionGroups
= xklAdaptor
->getOptionGroups();
85 m_options
= xklAdaptor
->getOptions();
87 QHashIterator
<QString
, XkbOption
> it( m_options
);
88 for (; it
.hasNext(); ) {
89 const XkbOption
& option
= it
.next().value();
90 option
.group
->options
.append(option
);
97 void XkbRules::loadRules(const QString
&file
, bool layoutsOnly
)
99 RulesInfo
* rules
= X11Helper::loadRules(file
, layoutsOnly
);
102 kDebug() << "Unable to load rules";
106 m_layouts
= rules
->layouts
;
108 if( layoutsOnly
== false ) {
109 m_models
= rules
->models
;
110 // m_varLists = rules->variants;
111 m_options
= rules
->options
;
112 m_optionGroups
= rules
->optionGroups
;
114 QHashIterator
<QString
, XkbOption
> it( m_options
);
115 for (; it
.hasNext(); ) {
116 const XkbOption
& option
= it
.next().value();
117 option
.group
->options
.append(option
);
126 XkbRules::getAvailableVariants(const QString
& layout
)
128 if( layout
.isEmpty() || !layouts().contains(layout
) )
129 return QList
<XkbVariant
>();
131 QList
<XkbVariant
>* result1
= m_varLists
[layout
];
139 QList
<XkbVariant
>* result
= X11Helper::getVariants(layout
, X11_DIR
);
141 m_varLists
.insert(layout
, result
);