2
// C++ Implementation: kxkbconfig
7
// Author: Andriy Rysin <rysin@kde.org>, (C) 2006
9
// Copyright: See COPYING file that comes with this distribution
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.
12
20
#include <assert.h>
17
25
#include <ksharedconfig.h>
26
#include <kconfiggroup.h>
18
27
#include <kdebug.h>
20
29
#include "kxkbconfig.h"
25
34
static const char* switchModes[SWITCH_POLICY_COUNT] = {
26
"Global", "WinClass", "Window"
35
"Global", "Desktop", "WinClass", "Window"
29
38
const LayoutUnit DEFAULT_LAYOUT_UNIT = LayoutUnit("us", "");
44
53
bool KxkbConfig::load(int loadMode)
46
KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::NoGlobals ), "Layout");
55
kDebug() << "Reading configuration";
56
KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::CascadeConfig ), "Layout");
48
58
// Even if the layouts have been disabled we still want to set Xkb options
49
59
// user can always switch them off now in the "Options" tab
58
68
m_useKxkb = config.readEntry("Use", false);
59
69
kDebug() << "Use kxkb " << m_useKxkb;
71
m_indicatorOnly = config.readEntry("IndicatorOnly", false);
72
kDebug() << "Indicator only " << m_indicatorOnly << endl;
61
74
if( (m_useKxkb == false && loadMode == LOAD_ACTIVE_OPTIONS )
62
75
|| loadMode == LOAD_INIT_OPTIONS )
78
m_showSingle = config.readEntry("ShowSingle", false);
79
m_showFlag = config.readEntry("ShowFlag", true);
81
if( (m_indicatorOnly == true && loadMode == LOAD_ACTIVE_OPTIONS ) )
65
84
m_model = config.readEntry("Model", DEFAULT_MODEL);
66
85
kDebug() << "Model: " << m_model;
101
// m_includes.clear();
102
// if( X11Helper::areSingleGroupsSupported() ) {
103
// if( config.hasKey("IncludeGroups") ) {
104
// QStringList includeList;
105
// includeList = config.readEntry("IncludeGroups", includeList, ',');
106
// for(QStringList::ConstIterator it = includeList.begin(); it != includeList.end() ; ++it) {
107
// QStringList includePair = (*it).split(':');
108
// if( includePair.count() == 2 ) {
109
// LayoutUnit layoutUnit( includePair[0] );
110
// if( m_layouts.contains( layoutUnit ) ) {
111
// m_layouts[m_layouts.indexOf(layoutUnit)].includeGroup = includePair[1];
112
// kDebug() << "Got inc group: " << includePair[0] << ": " << includePair[1];
117
// else { //old includes format
118
// kDebug() << "Old includes...";
119
// QStringList includeList;
120
// includeList = config.readEntry("Includes", includeList);
121
// for(QStringList::ConstIterator it = includeList.begin(); it != includeList.end() ; ++it) {
122
// QString layoutName = LayoutUnit::parseLayout( *it );
123
// LayoutUnit layoutUnit( layoutName, "" );
124
// kDebug() << "old layout for inc: " << layoutUnit.toPair() << " included " << m_layouts.contains( layoutUnit );
125
// if( m_layouts.contains( layoutUnit ) ) {
126
// QString variantName = LayoutUnit::parseVariant(*it);
127
// m_layouts[m_layouts.indexOf(layoutUnit)].includeGroup = variantName;
128
// kDebug() << "Got inc group: " << layoutUnit.toPair() << ": " << variantName;
134
m_showSingle = config.readEntry("ShowSingle", false);
135
m_showFlag = config.readEntry("ShowFlag", true);
120
// m_showSingle = config.readEntry("ShowSingle", false);
121
// m_showFlag = config.readEntry("ShowFlag", true);
137
123
QString layoutOwner = config.readEntry("SwitchMode", "Global");
142
128
else if( layoutOwner == "Window" ) {
143
129
m_switchingPolicy = SWITCH_POLICY_WINDOW;
131
else if( layoutOwner == "Desktop" ) {
132
m_switchingPolicy = SWITCH_POLICY_DESKTOP;
145
134
else /*if( layoutOwner == "Global" )*/ {
146
135
m_switchingPolicy = SWITCH_POLICY_GLOBAL;
165
static QString addNum(QString& str, int n)
167
if( str.length() >= 3 ) return str.left(2) + n;
171
void KxkbConfig::updateDisplayNames()
173
for(int i=0; i<m_layouts.count(); i++) {
174
LayoutUnit& lu = m_layouts[i];
176
for(int j=i; j<m_layouts.count(); j++) {
177
LayoutUnit& lu2 = m_layouts[i];
178
if( lu.layout == lu2.layout ) {
180
lu.displayName = addNum(lu.layout, 1);
181
lu2.displayName = addNum(lu2.layout, cnt);
187
bool KxkbConfig::setConfiguredLayouts(QList<LayoutUnit> layoutUnits)
189
kDebug() << "resetting layouts to " << layoutUnits.count() << " active in X server" << endl;
190
m_layouts = layoutUnits;
191
updateDisplayNames();
192
return true; //TODO ?
176
195
void KxkbConfig::save()
178
KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::NoGlobals ), "Layout");
197
KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::CascadeConfig ), "Layout");
180
199
config.writeEntry("Model", m_model);
182
201
config.writeEntry("EnableXkbOptions", m_enableXkbOptions );
202
config.writeEntry("IndicatorOnly", m_indicatorOnly );
183
203
config.writeEntry("ResetOldOptions", m_resetOldOptions);
184
204
config.writeEntry("Options", m_options );