not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / kxkb / kxkbconfig.h
blobec49308681d355e75d09379f085a4e3e7bf442f7
1 /*
2 * Copyright (C) 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 #ifndef KXKBCONFIG_H
20 #define KXKBCONFIG_H
23 #include <QQueue>
24 #include <QMap>
27 const int GROUP_LIMIT = 4;
28 const int MAX_LABEL_LEN = 3;
30 /* Utility classes for per-window/per-application layout implementation
32 enum SwitchingPolicy {
33 SWITCH_POLICY_GLOBAL = 0,
34 SWITCH_POLICY_DESKTOP = 1,
35 SWITCH_POLICY_WIN_CLASS = 2,
36 SWITCH_POLICY_WINDOW = 3,
37 SWITCH_POLICY_COUNT = 4
41 inline QString createPair(QString key, QString value)
43 if( value.isEmpty() )
44 return key;
45 return QString("%1(%2)").arg(key, value);
48 struct LayoutUnit {
49 private:
50 QString displayName;
51 public:
52 QString layout;
53 QString variant;
55 LayoutUnit() {}
57 LayoutUnit(QString layout_, QString variant_):
58 layout(layout_),
59 variant(variant_)
62 LayoutUnit(QString pair) {
63 setFromPair( pair );
66 void setDisplayName(const QString& name) { displayName = name; }
68 QString getDisplayName() const {
69 return !displayName.isEmpty() ? displayName : getDefaultDisplayName(layout, variant);
72 void setFromPair(const QString& pair) {
73 layout = parseLayout(pair);
74 variant = parseVariant(pair);
77 QString toPair() const {
78 return createPair(layout, variant);
80 /*
81 bool operator<(const LayoutUnit& lu) const {
82 return layout<lu.layout ||
83 (layout==lu.layout && variant<lu.variant);
85 */
86 bool operator!=(const LayoutUnit& lu) const {
87 return layout!=lu.layout || variant!=lu.variant;
89 bool operator==(const LayoutUnit& lu) const {
90 // kDebug() << layout << "==" << lu.layout << "&&" << variant << "==" << lu.variant;
91 return layout==lu.layout && variant==lu.variant;
95 static QString getDefaultDisplayName(const QString& layout, const QString& variant="");
97 //private:
98 static const QString parseLayout(const QString &layvar);
99 static const QString parseVariant(const QString &layvar);
102 extern const LayoutUnit DEFAULT_LAYOUT_UNIT;
103 extern const char* DEFAULT_MODEL;
105 struct XkbConfig {
106 QString model;
107 QStringList options;
108 QList<LayoutUnit> layouts;
111 class KxkbConfig
113 public:
114 enum { LOAD_ACTIVE_OPTIONS, LOAD_ALL };
115 static const char* OPTIONS_SEPARATOR;
117 bool m_useKxkb;
118 bool m_indicatorOnly;
119 bool m_showSingle;
120 bool m_showFlag;
121 // bool m_enableXkbOptions;
122 bool m_resetOldOptions;
123 bool m_stickySwitching;
124 int m_stickySwitchingDepth;
125 SwitchingPolicy m_switchingPolicy;
127 QString m_model;
128 QStringList m_options;
129 QList<LayoutUnit> m_layouts;
131 KxkbConfig();
132 int getDefaultLayout();
134 bool load(int loadMode);
135 void setConfiguredLayouts(XkbConfig xkbConfig);
136 void save();
137 void setDefaults();
139 QStringList getLayoutStringList(/*bool compact*/);
141 void updateDisplayNames();
143 private:
144 static const QMap<QString, QString> parseIncludesMap(const QStringList& pairList);
148 #endif