~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to kcontrol/kxkb/kxkbconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-11 14:04:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071011140448-v0eb7lxbb24zagca
Tags: 3.94.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// C++ Implementation: kxkbconfig
3
 
//
4
 
// Description:
5
 
//
6
 
//
7
 
// Author: Andriy Rysin <rysin@kde.org>, (C) 2006
8
 
//
9
 
// Copyright: See COPYING file that comes with this distribution
10
 
//
11
 
//
 
1
/*
 
2
 *  Copyright (C) 2006 Andriy Rysin (rysin@kde.org)
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
 
12
20
#include <assert.h>
13
21
 
14
22
#include <QRegExp>
15
23
#include <QHash>
16
24
 
17
25
#include <ksharedconfig.h>
 
26
#include <kconfiggroup.h>
18
27
#include <kdebug.h>
19
28
 
20
29
#include "kxkbconfig.h"
23
32
 
24
33
 
25
34
static const char* switchModes[SWITCH_POLICY_COUNT] = {
26
 
  "Global", "WinClass", "Window"
 
35
  "Global", "Desktop", "WinClass", "Window"
27
36
};
28
37
 
29
38
const LayoutUnit DEFAULT_LAYOUT_UNIT = LayoutUnit("us", "");
43
52
 
44
53
bool KxkbConfig::load(int loadMode)
45
54
{
46
 
    KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::NoGlobals ), "Layout");
 
55
    kDebug() << "Reading configuration";
 
56
    KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::CascadeConfig ), "Layout");
47
57
 
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;
60
70
 
 
71
        m_indicatorOnly = config.readEntry("IndicatorOnly", false);
 
72
        kDebug() << "Indicator only " << m_indicatorOnly << endl;
 
73
 
61
74
        if( (m_useKxkb == false && loadMode == LOAD_ACTIVE_OPTIONS )
62
75
                        || loadMode == LOAD_INIT_OPTIONS )
63
76
                return true;
64
77
 
 
78
        m_showSingle = config.readEntry("ShowSingle", false);
 
79
        m_showFlag = config.readEntry("ShowFlag", true);
 
80
 
 
81
        if( (m_indicatorOnly == true && loadMode == LOAD_ACTIVE_OPTIONS ) )
 
82
                return true;
 
83
 
65
84
        m_model = config.readEntry("Model", DEFAULT_MODEL);
66
85
        kDebug() << "Model: " << m_model;
67
86
 
98
117
                }
99
118
        }
100
119
 
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];
113
 
//                                      }
114
 
//                              }
115
 
//                      }
116
 
//              }
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;
129
 
//                              }
130
 
//                      }
131
 
//              }
132
 
//      }
133
 
 
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);
136
122
 
137
123
        QString layoutOwner = config.readEntry("SwitchMode", "Global");
138
124
 
142
128
        else if( layoutOwner == "Window" ) {
143
129
                m_switchingPolicy = SWITCH_POLICY_WINDOW;
144
130
        }
 
131
        else if( layoutOwner == "Desktop" ) {
 
132
                m_switchingPolicy = SWITCH_POLICY_DESKTOP;
 
133
        }
145
134
        else /*if( layoutOwner == "Global" )*/ {
146
135
                m_switchingPolicy = SWITCH_POLICY_GLOBAL;
147
136
        }
173
162
        return true;
174
163
}
175
164
 
 
165
static QString addNum(QString& str, int n)
 
166
{
 
167
  if( str.length() >= 3 ) return str.left(2) + n;
 
168
  return str + n;
 
169
}
 
170
 
 
171
void KxkbConfig::updateDisplayNames()
 
172
{
 
173
  for(int i=0; i<m_layouts.count(); i++) {
 
174
        LayoutUnit& lu = m_layouts[i];
 
175
        int cnt = 1;
 
176
        for(int j=i; j<m_layouts.count(); j++) {
 
177
          LayoutUnit& lu2 = m_layouts[i];
 
178
          if( lu.layout == lu2.layout ) {
 
179
                ++cnt;
 
180
                lu.displayName = addNum(lu.layout, 1);
 
181
                lu2.displayName = addNum(lu2.layout, cnt);
 
182
          }
 
183
        }
 
184
  }
 
185
}
 
186
 
 
187
bool KxkbConfig::setConfiguredLayouts(QList<LayoutUnit> layoutUnits)
 
188
{
 
189
  kDebug() << "resetting layouts to " << layoutUnits.count() << " active in X server" << endl;
 
190
  m_layouts = layoutUnits;
 
191
  updateDisplayNames();
 
192
  return true; //TODO ?
 
193
}
 
194
 
176
195
void KxkbConfig::save()
177
196
{
178
 
        KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::NoGlobals ), "Layout");
 
197
        KConfigGroup config(KSharedConfig::openConfig( "kxkbrc", KConfig::CascadeConfig ), "Layout");
179
198
 
180
199
        config.writeEntry("Model", m_model);
181
200
 
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 );
185
205
 
249
269
        m_layouts.append( DEFAULT_LAYOUT_UNIT );
250
270
 
251
271
        m_useKxkb = false;
 
272
        m_indicatorOnly = false;
252
273
        m_showSingle = false;
253
274
        m_showFlag = true;
254
275