~ubuntu-branches/ubuntu/warty/kdebase/warty

« back to all changes in this revision

Viewing changes to kxkb/kcmlayout.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-09-16 04:51:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040916045145-9vr63kith3k1cpza
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
 
 
3
#include <qlayout.h>
 
4
#include <qlabel.h>
 
5
#include <qcombobox.h>
 
6
#include <qtabwidget.h>
 
7
#include <qvgroupbox.h>
 
8
#include <qpushbutton.h>
 
9
#include <qlistview.h>
 
10
#include <qheader.h>
 
11
#include <qwhatsthis.h>
 
12
#include <qcheckbox.h>
 
13
#include <qradiobutton.h>
 
14
#include <qlineedit.h>
 
15
#include <qlistview.h>
 
16
#include <qbuttongroup.h>
 
17
#include <qspinbox.h>
 
18
 
 
19
#include <kkeydialog.h>
 
20
#include <kglobal.h>
 
21
#include <kconfig.h>
 
22
#include <klocale.h>
 
23
#include <kstandarddirs.h>
 
24
#include <kdebug.h>
 
25
#include <kapplication.h>
 
26
 
 
27
#include "rules.h"
 
28
#include "kcmlayout.h"
 
29
#include "kcmlayout.moc"
 
30
#include "pixmap.h"
 
31
#include "kcmmisc.h"
 
32
#include "kcmlayoutwidget.h"
 
33
 
 
34
#include <X11/Xlib.h>
 
35
 
 
36
 
 
37
static const char* switchModes[] = {
 
38
  "Global", "WinClass", "Window"
 
39
};
 
40
 
 
41
static QString lookupLocalized(const QDict<char> &dict, const QString& text)
 
42
{
 
43
  QDictIterator<char> it(dict);
 
44
  while (it.current())
 
45
    {
 
46
      if ( i18n(it.current()) == text )
 
47
        return it.currentKey();
 
48
      ++it;
 
49
    }
 
50
 
 
51
  return QString::null;
 
52
}
 
53
 
 
54
OptionListItem::OptionListItem( OptionListItem *parent, const QString &text,
 
55
    Type tt, const QString &optionName )
 
56
    : QCheckListItem( parent, text, tt ), m_OptionName( optionName )
 
57
{
 
58
}
 
59
 
 
60
OptionListItem::OptionListItem( QListView *parent, const QString &text,
 
61
    Type tt, const QString &optionName )
 
62
    : QCheckListItem( parent, text, tt ), m_OptionName( optionName )
 
63
{
 
64
}
 
65
 
 
66
OptionListItem * OptionListItem::findChildItem( const QString& optionName )
 
67
{
 
68
  OptionListItem *child = static_cast<OptionListItem *>( firstChild() );
 
69
 
 
70
  while ( child )
 
71
    {
 
72
      if ( child->optionName() == optionName )
 
73
        break;
 
74
      child = static_cast<OptionListItem *>( child->nextSibling() );
 
75
    }
 
76
 
 
77
  return child;
 
78
}
 
79
 
 
80
LayoutConfig::LayoutConfig(QWidget *parent, const char *name)
 
81
  : KCModule(parent, name), m_rules(0)
 
82
{
 
83
  QVBoxLayout *main = new QVBoxLayout(this, 0, KDialog::spacingHint());
 
84
 
 
85
  widget = new LayoutConfigWidget(this, "widget");
 
86
  main->addWidget(widget);
 
87
 
 
88
  connect( widget->chkEnable, SIGNAL( toggled( bool )), this, SLOT(changed()));
 
89
  connect( widget->chkShowSingle, SIGNAL( toggled( bool )), this, SLOT(changed()));
 
90
  connect( widget->comboModel, SIGNAL(activated(int)), this, SLOT(changed()));
 
91
 
 
92
  connect( widget->btnAdd, SIGNAL(clicked()), this, SLOT(changed()));
 
93
  connect( widget->btnAdd, SIGNAL(clicked()), this, SLOT(add()));
 
94
  connect( widget->btnRemove, SIGNAL(clicked()), this, SLOT(changed()));
 
95
  connect( widget->btnRemove, SIGNAL(clicked()), this, SLOT(remove()));
 
96
 
 
97
  connect( widget->comboVariant, SIGNAL(activated(int)), this, SLOT(changed()));
 
98
  connect( widget->comboVariant, SIGNAL(activated(int)), this, SLOT(variantChanged()));
 
99
  connect( widget->listLayoutsDst, SIGNAL(selectionChanged(QListViewItem *)),
 
100
                this, SLOT(layoutSelChanged(QListViewItem *)));
 
101
 
 
102
  connect( widget->chkLatin, SIGNAL(clicked()), this, SLOT(changed()));
 
103
  connect( widget->chkLatin, SIGNAL(clicked()), this, SLOT(latinChanged()));
 
104
 
 
105
  connect( widget->btnUp, SIGNAL(clicked()), this, SLOT(changed()));
 
106
  connect( widget->btnUp, SIGNAL(clicked()), this, SLOT(moveUp()));
 
107
  connect( widget->btnDown, SIGNAL(clicked()), this, SLOT(changed()));
 
108
  connect( widget->btnDown, SIGNAL(clicked()), this, SLOT(moveDown()));
 
109
 
 
110
  connect( widget->grpSwitching, SIGNAL( clicked( int ) ), SLOT(changed()));
 
111
 
 
112
  connect( widget->chkEnableSticky, SIGNAL(toggled(bool)), this, SLOT(changed()));
 
113
  connect( widget->spinStickyDepth, SIGNAL(valueChanged(int)), this, SLOT(changed()));
 
114
 
 
115
  widget->listLayoutsSrc->setColumnWidth(0, 28);
 
116
  widget->listLayoutsDst->setColumnWidth(0, 28);
 
117
  widget->listLayoutsDst->setSorting(-1);
 
118
#if 0
 
119
  widget->listLayoutsDst->setResizeMode(QListView::LastColumn);
 
120
  widget->listLayoutsSrc->setResizeMode(QListView::LastColumn);
 
121
#endif
 
122
 
 
123
  //Read rules - we _must_ read _before_ creating xkb-options comboboxes
 
124
  ruleChanged("xfree86");
 
125
 
 
126
  makeOptionsTab();
 
127
 
 
128
  load();
 
129
}
 
130
 
 
131
 
 
132
LayoutConfig::~LayoutConfig()
 
133
{
 
134
  delete m_rules;
 
135
}
 
136
 
 
137
void LayoutConfig::updateStickyLimit()
 
138
{
 
139
    int layoutsCnt = widget->listLayoutsDst->childCount();
 
140
    widget->spinStickyDepth->setMaxValue( (layoutsCnt<=2) ? 2 : layoutsCnt - 1);
 
141
}
 
142
 
 
143
void LayoutConfig::add()
 
144
{
 
145
    QListViewItem* sel = widget->listLayoutsSrc->selectedItem();
 
146
    if( sel == 0 )
 
147
        return;
 
148
 
 
149
    widget->listLayoutsDst->insertItem(sel);
 
150
    sel->moveItem(widget->listLayoutsDst->lastItem());
 
151
    widget->listLayoutsSrc->setSelected(sel, true);
 
152
    layoutSelChanged(sel);
 
153
 
 
154
    updateStickyLimit();
 
155
}
 
156
 
 
157
void LayoutConfig::remove()
 
158
{
 
159
    QListViewItem* sel = widget->listLayoutsDst->selectedItem();
 
160
    QListViewItem* newSel = 0;
 
161
 
 
162
    if( sel == 0 )
 
163
        return;
 
164
 
 
165
    if( sel->itemBelow() )
 
166
        newSel = sel->itemBelow();
 
167
    else
 
168
    if( sel->itemAbove() )
 
169
        newSel = sel->itemAbove();
 
170
 
 
171
    widget->listLayoutsSrc->insertItem(sel);
 
172
    if( newSel )
 
173
        widget->listLayoutsSrc->setSelected(newSel, true);
 
174
    layoutSelChanged(newSel);
 
175
 
 
176
    updateStickyLimit();
 
177
}
 
178
 
 
179
void LayoutConfig::moveUp()
 
180
{
 
181
    QListViewItem* sel = widget->listLayoutsDst->selectedItem();
 
182
    if( sel == 0 || sel->itemAbove() == 0 )
 
183
        return;
 
184
 
 
185
    if( sel->itemAbove()->itemAbove() == 0 ) {
 
186
        widget->listLayoutsDst->takeItem(sel);
 
187
        widget->listLayoutsDst->insertItem(sel);
 
188
        widget->listLayoutsDst->setSelected(sel, true);
 
189
    }
 
190
    else
 
191
        sel->moveItem(sel->itemAbove()->itemAbove());
 
192
}
 
193
 
 
194
void LayoutConfig::moveDown()
 
195
{
 
196
    QListViewItem* sel = widget->listLayoutsDst->selectedItem();
 
197
    if( sel == 0 || sel->itemBelow() == 0 )
 
198
        return;
 
199
 
 
200
    sel->moveItem(sel->itemBelow());
 
201
}
 
202
 
 
203
void LayoutConfig::variantChanged()
 
204
{
 
205
    QListViewItem* selLayout = widget->listLayoutsDst->selectedItem();
 
206
    if( !selLayout ) {
 
207
      widget->comboVariant->clear();
 
208
      widget->comboVariant->setEnabled(false);
 
209
      return;
 
210
    }
 
211
 
 
212
    QString kbdLayout = lookupLocalized( m_rules->layouts(), selLayout->text(1) );
 
213
    m_variants.replace(kbdLayout, widget->comboVariant->currentText().latin1());
 
214
}
 
215
 
 
216
void LayoutConfig::latinChanged()
 
217
{
 
218
    QListViewItem* selLayout = widget->listLayoutsDst->selectedItem();
 
219
    if (  !selLayout ) {
 
220
      widget->chkLatin->setChecked( false );
 
221
      widget->chkLatin->setEnabled( false );
 
222
      return;
 
223
    }
 
224
 
 
225
    QString kbdLayout = lookupLocalized(  m_rules->layouts(), selLayout->text( 1 ) );
 
226
    if (  widget->chkLatin->isChecked() )
 
227
        m_includes.replace( kbdLayout, "us" );
 
228
    else
 
229
        m_includes.replace( kbdLayout, "" );
 
230
}
 
231
 
 
232
void LayoutConfig::layoutSelChanged(QListViewItem *sel)
 
233
{
 
234
 
 
235
    widget->comboVariant->clear();
 
236
    widget->comboVariant->setEnabled( sel != 0 );
 
237
    widget->chkLatin->setChecked( false );
 
238
    widget->chkLatin->setEnabled( sel != 0 );
 
239
 
 
240
    if( sel == 0 ) {
 
241
        updateLayoutCommand();
 
242
        return;
 
243
    }
 
244
 
 
245
    QString kbdLayout = lookupLocalized( m_rules->layouts(), sel->text(1) );
 
246
 
 
247
    if (  ! m_rules->isSingleGroup(kbdLayout) || kbdLayout == "us" ) {
 
248
        widget->chkLatin->setEnabled(  false );
 
249
    }
 
250
    else {
 
251
        char* inc = m_includes[ kbdLayout ];
 
252
        if ( inc && strcmp(inc, "us")==0 ) {
 
253
            widget->chkLatin->setChecked(true);
 
254
        }
 
255
        else {
 
256
            widget->chkLatin->setChecked(false);
 
257
        }
 
258
    }
 
259
 
 
260
    QStringList vars = m_rules->getVariants(kbdLayout);
 
261
 
 
262
 
 
263
    if( vars.count() == 0 ) {   // cowardly running away
 
264
        updateLayoutCommand();
 
265
        return;
 
266
    }
 
267
 
 
268
    char* variant = m_variants[kbdLayout];
 
269
    widget->comboVariant->insertStringList(vars);
 
270
 
 
271
    if( variant ) {
 
272
      widget->comboVariant->setCurrentText(variant);
 
273
    }
 
274
    else {
 
275
      widget->comboVariant->setCurrentItem(0);
 
276
      m_variants.insert(kbdLayout, widget->comboVariant->currentText().latin1());
 
277
    }
 
278
 
 
279
    updateLayoutCommand();
 
280
}
 
281
 
 
282
QWidget* LayoutConfig::makeOptionsTab()
 
283
{
 
284
  QListView *listView = widget->listOptions;
 
285
 
 
286
  listView->setMinimumHeight(150);
 
287
  listView->setSortColumn( -1 );
 
288
  listView->setColumnText( 0, i18n( "Options" ) );
 
289
  listView->clear();
 
290
 
 
291
  connect(listView, SIGNAL(clicked(QListViewItem *)), SLOT(changed()));
 
292
  connect(listView, SIGNAL(clicked(QListViewItem *)), SLOT(updateOptionsCommand()));
 
293
 
 
294
  connect(widget->checkResetOld, SIGNAL(toggled(bool)), SLOT(changed()));
 
295
  connect(widget->checkResetOld, SIGNAL(toggled(bool)), SLOT(updateOptionsCommand()));
 
296
 
 
297
  //Create controllers for all options
 
298
  QDictIterator<char> it(m_rules->options());
 
299
  OptionListItem *parent;
 
300
  for (; it.current(); ++it)
 
301
  {
 
302
    if (!it.currentKey().contains(':'))
 
303
    {
 
304
      if( it.currentKey() == "ctrl" || it.currentKey() == "caps"
 
305
          || it.currentKey() == "altwin" ) {
 
306
        parent = new OptionListItem(listView, i18n( it.current() ),
 
307
            QCheckListItem::RadioButtonController, it.currentKey());
 
308
        OptionListItem *item = new OptionListItem(parent, i18n( "None" ),
 
309
            QCheckListItem::RadioButton, "none");
 
310
        item->setState(QCheckListItem::On);
 
311
      }
 
312
      else {
 
313
        parent = new OptionListItem(listView, i18n( it.current() ),
 
314
            QCheckListItem::CheckBoxController, it.currentKey());
 
315
      }
 
316
      parent->setOpen(true);
 
317
      m_optionGroups.insert(i18n(it.currentKey().local8Bit()), parent);
 
318
    }
 
319
  }
 
320
 
 
321
  it.toFirst();
 
322
  for( ; it.current(); ++it)
 
323
  {
 
324
    QString key = it.currentKey();
 
325
    int pos = key.find(':');
 
326
    if (pos >= 0)
 
327
    {
 
328
      OptionListItem *parent = m_optionGroups[key.left(pos)];
 
329
      if (parent == NULL )
 
330
        parent = m_optionGroups["misc"];
 
331
      if (parent != NULL) {
 
332
      // workaroung for mistake in rules file for xkb options in XFree 4.2.0
 
333
        QString text(it.current());
 
334
        text = text.replace( "Cap$", "Caps." );
 
335
        if( parent->type() == QCheckListItem::RadioButtonController )
 
336
            new OptionListItem(parent, i18n(text.latin1()),
 
337
                QCheckListItem::RadioButton, key);
 
338
        else
 
339
            new OptionListItem(parent, i18n(text.latin1()),
 
340
                QCheckListItem::CheckBox, key);
 
341
      }
 
342
    }
 
343
  }
 
344
 
 
345
  //scroll->setMinimumSize(450, 330);
 
346
 
 
347
  return listView;
 
348
}
 
349
 
 
350
void LayoutConfig::updateOptionsCommand()
 
351
{
 
352
  QString setxkbmap;
 
353
  QString options = createOptionString();
 
354
 
 
355
  if( !options.isEmpty() ) {
 
356
    setxkbmap = "setxkbmap -option "; //-rules " + m_rule
 
357
    if( widget->checkResetOld->isChecked() )
 
358
      setxkbmap += "-option ";
 
359
    setxkbmap += options;
 
360
  }
 
361
  widget->editCmdLineOpt->setText(setxkbmap);
 
362
}
 
363
 
 
364
void LayoutConfig::updateLayoutCommand()
 
365
{
 
366
  QString setxkbmap;
 
367
  QListViewItem* sel = widget->listLayoutsDst->selectedItem();
 
368
 
 
369
  if( sel ) {
 
370
    QString kbdLayout = lookupLocalized(m_rules->layouts(), sel->text(1));
 
371
//    char* variant = m_variants[kbdLayout];
 
372
    QString variant = widget->comboVariant->currentText();
 
373
 
 
374
    setxkbmap = "setxkbmap"; //-rules " + m_rule
 
375
    setxkbmap += " -model " + lookupLocalized(m_rules->models(), widget->comboModel->currentText())
 
376
      + " -layout ";
 
377
    if( widget->chkLatin->isChecked() )
 
378
      setxkbmap += "us,";
 
379
    setxkbmap += kbdLayout;
 
380
 
 
381
    if( !variant.isEmpty() ) {
 
382
      setxkbmap += " -variant ";
 
383
      if( widget->chkLatin->isChecked() )
 
384
        setxkbmap += ",";
 
385
      setxkbmap += variant;
 
386
    }
 
387
  }
 
388
  widget->editCmdLine->setText(setxkbmap);
 
389
}
 
390
 
 
391
void LayoutConfig::changed()
 
392
{
 
393
  updateLayoutCommand();
 
394
  emit KCModule::changed( true );
 
395
}
 
396
 
 
397
 
 
398
void LayoutConfig::load()
 
399
{
 
400
  // open the config file
 
401
  KConfig *config = new KConfig("kxkbrc", true);
 
402
  config->setGroup("Layout");
 
403
 
 
404
  bool use = config->readBoolEntry( "Use", false );
 
405
 
 
406
  // find out which rule applies
 
407
  QString rule = "xfree86"; //config->readEntry("Rule", "xfree86");
 
408
 
 
409
  // update other files
 
410
  ruleChanged(rule);
 
411
 
 
412
  // find out about the model
 
413
  QString model = config->readEntry("Model", "pc104");
 
414
 
 
415
  // TODO: When no model and no layout are known (1st start), we really
 
416
  // should ask the X-server about it's settings!
 
417
 
 
418
  QString m_name = m_rules->models()[model];
 
419
  widget->comboModel->setCurrentText(i18n(m_name.local8Bit()));
 
420
 
 
421
  QString layout = config->readEntry("Layout", "us");
 
422
  QString l_name = m_rules->layouts()[layout];
 
423
 
 
424
  QStringList otherLayouts = config->readListEntry("Additional");
 
425
  if( !l_name.isEmpty() ) {
 
426
    otherLayouts.prepend(layout);
 
427
  }
 
428
// to optimize we should have gone from it.end to it.begin
 
429
  for ( QStringList::Iterator it = otherLayouts.begin(); it != otherLayouts.end(); ++it ) {
 
430
    QListViewItemIterator src_it( widget->listLayoutsSrc );
 
431
    for ( ; src_it.current(); ++src_it ) {
 
432
        QListViewItem* srcItem = src_it.current();
 
433
        if ( *it == lookupLocalized(m_rules->layouts(), src_it.current()->text(1)) ) {
 
434
            widget->listLayoutsDst->insertItem(srcItem);
 
435
            srcItem->moveItem(widget->listLayoutsDst->lastItem());
 
436
            break;
 
437
        }
 
438
    }
 
439
  }
 
440
 
 
441
// reading variants
 
442
  QStringList vars = config->readListEntry("Variants");
 
443
  m_rules->parseVariants(vars, m_variants);
 
444
//  m_rules->parseVariants( vars, m_variants );
 
445
 
 
446
  QStringList incs = config->readListEntry( "Includes" );
 
447
  m_rules->parseVariants( incs, m_includes, false );
 
448
 
 
449
  bool showSingle = config->readBoolEntry( "ShowSingle", false );
 
450
  widget->chkShowSingle->setChecked(showSingle);
 
451
 
 
452
  bool enableXkbOptions = config->readBoolEntry( "EnableXkbOptions", true );
 
453
  widget->chkEnableOptions->setChecked( enableXkbOptions );
 
454
  bool resetOld = config->readBoolEntry("ResetOldOptions", false);
 
455
  widget->checkResetOld->setChecked(resetOld);
 
456
  QStringList options = config->readListEntry("Options");
 
457
 
 
458
  for (QStringList::Iterator it = options.begin(); it != options.end(); ++it)
 
459
    {
 
460
      QString option = *it;
 
461
      QString optionKey = option.mid(0, option.find(':'));
 
462
      QString optionName = m_rules->options()[option];
 
463
      OptionListItem *item = m_optionGroups[optionKey];
 
464
      if (item != NULL) {
 
465
        OptionListItem *child = item->findChildItem( option );
 
466
 
 
467
        if ( child )
 
468
          child->setState( QCheckListItem::On );
 
469
            else
 
470
              kdDebug() << "load: Unknown option " << option << endl;
 
471
      }
 
472
      else {
 
473
            kdDebug() << "load: Unknown option group " << optionKey << endl;
 
474
      }
 
475
    }
 
476
 
 
477
  QString swMode = config->readEntry("SwitchMode", "Global");
 
478
  widget->grpSwitching->setButton(0);
 
479
 
 
480
   for(int ii=1; ii<3; ii++)
 
481
    if( swMode == switchModes[ii] )
 
482
      widget->grpSwitching->setButton(ii);
 
483
 
 
484
  bool stickySwitching = config->readBoolEntry("StickySwitching", false);
 
485
  widget->chkEnableSticky->setChecked(stickySwitching);
 
486
  widget->spinStickyDepth->setEnabled(stickySwitching);
 
487
  widget->spinStickyDepth->setValue( config->readEntry("StickySwitchingDepth", "1").toInt() + 1);
 
488
 
 
489
  updateStickyLimit();
 
490
 
 
491
  delete config;
 
492
 
 
493
  widget->chkEnable->setChecked( use );
 
494
  widget->grpLayouts->setEnabled(use);
 
495
  widget->grpSwitching->setEnabled(use);
 
496
 
 
497
  updateOptionsCommand();
 
498
  emit KCModule::changed( false );
 
499
}
 
500
 
 
501
void LayoutConfig::ruleChanged(const QString &rule)
 
502
{
 
503
  if( rule == m_rule )
 
504
    return;
 
505
 
 
506
  m_rule = rule;
 
507
 
 
508
  QString model; //, layout;
 
509
  if (m_rules)
 
510
    {
 
511
      model = lookupLocalized(m_rules->models(), widget->comboModel->currentText());
 
512
//      layout = lookupLocalized(m_rules->layouts(), layoutCombo->currentText());
 
513
    }
 
514
 
 
515
  delete m_rules;
 
516
  m_rules = new KeyRules(rule);
 
517
 
 
518
  QStringList tmp;
 
519
  widget->comboModel->clear();
 
520
  QDictIterator<char> it(m_rules->models());
 
521
  while (it.current())
 
522
    {
 
523
      tmp.append(i18n(it.current()));
 
524
      ++it;
 
525
    }
 
526
  tmp.sort();
 
527
  widget->comboModel->insertStringList(tmp);
 
528
 
 
529
 
 
530
  // fill in the additional layouts  -- moved from load() by A. Rysin
 
531
  widget->listLayoutsSrc->clear();
 
532
  QDictIterator<char> it2(m_rules->layouts());
 
533
  while (it2.current())
 
534
    {
 
535
      QCheckListItem *item = new QCheckListItem(widget->listLayoutsSrc, "");
 
536
      QString addLayout = it2.currentKey();
 
537
      item->setPixmap(0, findPixmap(addLayout));
 
538
      item->setText(1, i18n(it2.current()) );
 
539
      item->setText(2, "(" + addLayout + ")" );
 
540
      ++it2;
 
541
    }
 
542
  widget->listLayoutsSrc->setSorting(1);        // from Qt3 QListView sorts by language
 
543
 
 
544
 
 
545
  if (!model.isEmpty())
 
546
  {
 
547
    QString m_name = m_rules->models()[model];
 
548
    widget->comboModel->setCurrentText(m_name);
 
549
  }
 
550
}
 
551
 
 
552
 
 
553
QString LayoutConfig::createOptionString()
 
554
{
 
555
  QString options;
 
556
  for (QDictIterator<char> it(m_rules->options()); it.current(); ++it)
 
557
  {
 
558
    QString option(it.currentKey());
 
559
 
 
560
    if (option.contains(':')) {
 
561
 
 
562
      QString optionKey = option.mid(0, option.find(':'));
 
563
      OptionListItem *item = m_optionGroups[optionKey];
 
564
 
 
565
      if( !item ) {
 
566
        kdDebug() << "WARNING: skipping empty group for " << it.currentKey()
 
567
          << endl;
 
568
        continue;
 
569
      }
 
570
 
 
571
      OptionListItem *child = item->findChildItem( option );
 
572
 
 
573
      if ( child ) {
 
574
        if ( child->state() == QCheckListItem::On ) {
 
575
          QString selectedName = child->optionName();
 
576
          if ( !selectedName.isEmpty() && selectedName != "none" ) {
 
577
            if (!options.isEmpty())
 
578
              options.append(',');
 
579
            options.append(selectedName);
 
580
          }
 
581
        }
 
582
      }
 
583
      else
 
584
        kdDebug() << "Empty option button for group " << it.currentKey() << endl;
 
585
    }
 
586
  }
 
587
  return options;
 
588
}
 
589
 
 
590
void LayoutConfig::save()
 
591
{
 
592
  KConfig *config = new KConfig("kxkbrc", false);
 
593
  config->setGroup("Layout");
 
594
  //  config->writeEntry("Rule", ruleCombo->currentText());
 
595
 
 
596
  QString model = lookupLocalized(m_rules->models(), widget->comboModel->currentText());
 
597
  config->writeEntry("Model", model);
 
598
 
 
599
  config->writeEntry("EnableXkbOptions", widget->chkEnableOptions->isChecked() );
 
600
  config->writeEntry("ResetOldOptions", widget->checkResetOld->isChecked());
 
601
  config->writeEntry("Options", createOptionString() );
 
602
 
 
603
  QString layout;
 
604
  QStringList otherLayouts;
 
605
  QListViewItem *item = widget->listLayoutsDst->firstChild();
 
606
  if( item ) {
 
607
    layout = lookupLocalized(m_rules->layouts(), item->text(1));
 
608
    if( !layout.isEmpty() )
 
609
        config->writeEntry("Layout", layout);
 
610
    item = item->nextSibling();
 
611
  }
 
612
  else {
 
613
    widget->chkEnable->setChecked(false);
 
614
  }
 
615
 
 
616
  while (item) {
 
617
        QString layout = lookupLocalized(m_rules->layouts(), item->text(1));
 
618
        otherLayouts.append(layout);
 
619
      item = item->nextSibling();
 
620
  }
 
621
  config->writeEntry("Additional", otherLayouts);
 
622
 
 
623
  QStringList varList;
 
624
  QStringList incList;
 
625
  item = widget->listLayoutsDst->firstChild();
 
626
  while ( item ) {
 
627
    QString layout = lookupLocalized( m_rules->layouts(), item->text( 1 ) );
 
628
    if( m_includes[ layout ] && m_includes[ layout ][ 0 ] != '\0' )
 
629
    {
 
630
        QString inc = layout;
 
631
        inc += "(";
 
632
        inc += m_includes[ layout ];
 
633
        inc += ")";
 
634
        incList.append(  inc );
 
635
    }
 
636
    if( m_variants[ layout ] && m_variants[ layout ][ 0 ] != '\0' )
 
637
    {
 
638
        QString var = layout;
 
639
        var += "(";
 
640
        var += m_variants[ layout ];
 
641
        var += ")";
 
642
        varList.append( var );
 
643
    }
 
644
 
 
645
    item = item->nextSibling();
 
646
  }
 
647
  config->writeEntry( "Includes", incList );
 
648
  config->writeEntry("Variants", varList);
 
649
 
 
650
  config->writeEntry("Use", widget->chkEnable->isChecked());
 
651
  config->writeEntry("ShowSingle", widget->chkShowSingle->isChecked());
 
652
 
 
653
  int modeId = widget->grpSwitching->id(widget->grpSwitching->selected());
 
654
  if( modeId < 1 || modeId > 2 )
 
655
    modeId = 0;
 
656
 
 
657
  config->writeEntry("SwitchMode", switchModes[modeId]);
 
658
 
 
659
  config->writeEntry("StickySwitching", widget->chkEnableSticky->isChecked());
 
660
  config->writeEntry("StickySwitchingDepth", widget->spinStickyDepth->value() - 1);
 
661
 
 
662
  config->sync();
 
663
 
 
664
  delete config;
 
665
 
 
666
  kapp->kdeinitExec("kxkb");
 
667
  emit KCModule::changed( false );
 
668
}
 
669
 
 
670
 
 
671
void LayoutConfig::defaults()
 
672
{
 
673
  widget->chkEnable->setChecked(false);
 
674
  ruleChanged("xfree86");
 
675
 
 
676
  widget->comboModel->setCurrentText("pc104");
 
677
  //layoutCombo->setCurrentText("us");
 
678
 
 
679
  widget->chkEnableOptions->setChecked( true );
 
680
  widget->checkResetOld->setChecked( false );
 
681
 
 
682
  widget->grpSwitching->setButton(0);
 
683
 
 
684
  widget->chkEnableSticky->setChecked( false );
 
685
  widget->spinStickyDepth->setEnabled( false );
 
686
 
 
687
  QListViewItem *item = widget->listLayoutsSrc->firstChild();
 
688
  while (item)
 
689
    {
 
690
      QCheckListItem *cli = dynamic_cast<QCheckListItem*>(item);
 
691
      cli->setOn(false);
 
692
      item = item->nextSibling();
 
693
    }
 
694
  emit KCModule::changed( true );
 
695
}
 
696
 
 
697
extern "C"
 
698
{
 
699
  KCModule *create_keyboard_layout(QWidget *parent, const char *)
 
700
  {
 
701
    return new LayoutConfig(parent, "kcmlayout");
 
702
  }
 
703
 
 
704
  KCModule *create_keyboard(QWidget *parent, const char *)
 
705
  {
 
706
    return new KeyboardConfig(parent, "kcmlayout");
 
707
  }
 
708
 
 
709
  void init_keyboard()
 
710
  {
 
711
    KConfig *config = new KConfig("kcminputrc", true); // Read-only, no globals
 
712
    config->setGroup("Keyboard");
 
713
 
 
714
    XKeyboardState   kbd;
 
715
    XKeyboardControl kbdc;
 
716
 
 
717
    XGetKeyboardControl(kapp->getDisplay(), &kbd);
 
718
    bool key = config->readBoolEntry("KeyboardRepeating", true);
 
719
    kbdc.key_click_percent = config->readNumEntry("ClickVolume", kbd.key_click_percent);
 
720
    kbdc.auto_repeat_mode = (key ? AutoRepeatModeOn : AutoRepeatModeOff);
 
721
 
 
722
    XChangeKeyboardControl(kapp->getDisplay(),
 
723
                           KBKeyClickPercent | KBAutoRepeatMode,
 
724
                           &kbdc);
 
725
 
 
726
    if( key ) {
 
727
        int delay_ = config->readNumEntry("RepeatDelay", 250);
 
728
        int rate_ = config->readNumEntry("RepeatRate", 30);
 
729
        set_repeatrate(delay_, rate_);
 
730
    }
 
731
 
 
732
 
 
733
    int numlockState = config->readNumEntry( "NumLock", 2 );
 
734
    if( numlockState != 2 )
 
735
        numlockx_change_numlock_state( numlockState == 0 );
 
736
 
 
737
    delete config;
 
738
 
 
739
    config = new KConfig("kxkbrc", true, false);
 
740
    config->setGroup("Layout");
 
741
    if (config->readBoolEntry("Use", false) == true)
 
742
        kapp->startServiceByDesktopName("kxkb");
 
743
    delete config;
 
744
  }
 
745
}
 
746
 
 
747
#if 0// do not remove!
 
748
// please don't change/fix messages below
 
749
// they're taken from XFree86 as is and should stay the same
 
750
   I18N_NOOP("Brazilian ABNT2");
 
751
   I18N_NOOP("Dell 101-key PC");
 
752
   I18N_NOOP("Everex STEPnote");
 
753
   I18N_NOOP("Generic 101-key PC");
 
754
   I18N_NOOP("Generic 102-key (Intl) PC");
 
755
   I18N_NOOP("Generic 104-key PC");
 
756
   I18N_NOOP("Generic 105-key (Intl) PC");
 
757
   I18N_NOOP("Japanese 106-key");
 
758
   I18N_NOOP("Microsoft Natural");
 
759
   I18N_NOOP("Northgate OmniKey 101");
 
760
   I18N_NOOP("Keytronic FlexPro");
 
761
   I18N_NOOP("Winbook Model XP5");
 
762
 
 
763
// These options are from XFree 4.1.0
 
764
 I18N_NOOP("Group Shift/Lock behavior");
 
765
 I18N_NOOP("R-Alt switches group while pressed");
 
766
 I18N_NOOP("Right Alt key changes group");
 
767
 I18N_NOOP("Caps Lock key changes group");
 
768
 I18N_NOOP("Menu key changes group");
 
769
 I18N_NOOP("Both Shift keys together change group");
 
770
 I18N_NOOP("Control+Shift changes group");
 
771
 I18N_NOOP("Alt+Control changes group");
 
772
 I18N_NOOP("Alt+Shift changes group");
 
773
 I18N_NOOP("Control Key Position");
 
774
 I18N_NOOP("Make CapsLock an additional Control");
 
775
 I18N_NOOP("Swap Control and Caps Lock");
 
776
 I18N_NOOP("Control key at left of 'A'");
 
777
 I18N_NOOP("Control key at bottom left");
 
778
 I18N_NOOP("Use keyboard LED to show alternative group");
 
779
 I18N_NOOP("Num_Lock LED shows alternative group");
 
780
 I18N_NOOP("Caps_Lock LED shows alternative group");
 
781
 I18N_NOOP("Scroll_Lock LED shows alternative group");
 
782
 
 
783
//these seem to be new in XFree86 4.2.0
 
784
 I18N_NOOP("Left Win-key switches group while pressed");
 
785
 I18N_NOOP("Right Win-key switches group while pressed");
 
786
 I18N_NOOP("Both Win-keys switch group while pressed");
 
787
 I18N_NOOP("Left Win-key changes group");
 
788
 I18N_NOOP("Right Win-key changes group");
 
789
 I18N_NOOP("Third level choosers");
 
790
 I18N_NOOP("Press Right Control to choose 3rd level");
 
791
 I18N_NOOP("Press Menu key to choose 3rd level");
 
792
 I18N_NOOP("Press any of Win-keys to choose 3rd level");
 
793
 I18N_NOOP("Press Left Win-key to choose 3rd level");
 
794
 I18N_NOOP("Press Right Win-key to choose 3rd level");
 
795
 I18N_NOOP("CapsLock key behavior");
 
796
 I18N_NOOP("uses internal capitalization. Shift cancels Caps.");
 
797
 I18N_NOOP("uses internal capitalization. Shift doesn't cancel Caps.");
 
798
 I18N_NOOP("acts as Shift with locking. Shift cancels Caps.");
 
799
 I18N_NOOP("acts as Shift with locking. Shift doesn't cancel Caps.");
 
800
 I18N_NOOP("Alt/Win key behavior");
 
801
 I18N_NOOP("Add the standard behavior to Menu key.");
 
802
 I18N_NOOP("Alt and Meta on the Alt keys (default).");
 
803
 I18N_NOOP("Meta is mapped to the Win-keys.");
 
804
 I18N_NOOP("Meta is mapped to the left Win-key.");
 
805
 I18N_NOOP("Super is mapped to the Win-keys (default).");
 
806
 I18N_NOOP("Hyper is mapped to the Win-keys.");
 
807
 I18N_NOOP("Right Alt is Compose");
 
808
 I18N_NOOP("Right Win-key is Compose");
 
809
 I18N_NOOP("Menu is Compose");
 
810
 
 
811
//these seem to be new in XFree86 4.3.0
 
812
 I18N_NOOP( "Both Ctrl keys together change group" );
 
813
 I18N_NOOP( "Both Alt keys together change group" );
 
814
 I18N_NOOP( "Left Shift key changes group" );
 
815
 I18N_NOOP( "Right Shift key changes group" );
 
816
 I18N_NOOP( "Right Ctrl key changes group" );
 
817
 I18N_NOOP( "Left Alt key changes group" );
 
818
 I18N_NOOP( "Left Ctrl key changes group" );
 
819
 I18N_NOOP( "Compose Key" );
 
820
 
 
821
//these seem to be new in XFree86 4.4.0
 
822
 I18N_NOOP("Shift with numpad keys works as in MS Windows.");
 
823
 I18N_NOOP("Special keys (Ctrl+Alt+<key>) handled in a server.");
 
824
 I18N_NOOP("Miscellaneous compatibility options");
 
825
 I18N_NOOP("Right Control key works as Right Alt");
 
826
#endif