source: src-qt4/PCDM/src/dialogKeyboard.cpp @ 4eecf13

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 4eecf13 was 4eecf13, checked in by Ken Moore <ken@…>, 9 months ago

Add a bit of debugging to the PCDM keyboard layout switcher.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/* PCDM Login Manager:
2*  Written by Ken Moore (ken@pcbsd.org) 2012/2013
3*  Copyright(c) 2013 by the PC-BSD Project
4*  Available under the 3-clause BSD license
5*
6* Note: This file initially copied from the graphical PC-BSD installer
7*/
8
9#include "pcdm-backend.h"
10#include "dialogKeyboard.h"
11#include "ui_dialogKeyboard.h"
12
13widgetKeyboard::widgetKeyboard(QWidget* parent) : QWidget(parent){
14  setupUi(this);
15}
16
17void widgetKeyboard::programInit(QStringList kModel, QStringList kLayouts)
18{
19  connect(pushClose, SIGNAL(clicked()), this, SLOT(slotClose()));
20  connect(pushApply, SIGNAL(clicked()), this, SLOT(slotApply()));
21  keyboardModels = kModel;
22  keyboardLayouts = kLayouts;
23  connectKeyboardSlots();
24}
25
26void widgetKeyboard::slotClose()
27{
28  close();
29}
30
31void widgetKeyboard::slotApply()
32{
33  slotUpdateKbOnSys();
34  this->close();
35}
36
37void widgetKeyboard::connectKeyboardSlots()
38{
39  // load keyboards
40  listKbLayouts->clear();
41  listKbLayouts->addItems(keyboardLayouts);
42  comboBoxKeyboardModel->addItems(keyboardModels);
43
44  // Set the default keyboard stuff
45  setKbDefaults();
46  slotCurrentKbLayoutChanged(0);
47  groupKeyboard->setEnabled(true);
48
49
50  // Connect all our slots
51  connect(listKbLayouts, SIGNAL(currentRowChanged(int)), this, SLOT(slotCurrentKbLayoutChanged(int)));
52  connect(listKbVariants,SIGNAL(currentRowChanged(int)), this, SLOT(slotCurrentKbVariantChanged(int)));
53  connect(listKbLayouts, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectedKbItemChanged()));
54  connect(listKbVariants,SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectedKbItemChanged()));
55  connect(comboBoxKeyboardModel,SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateKbOnSys()));
56}
57
58void widgetKeyboard::slotCurrentKbLayoutChanged(int row)
59{
60    if (row != -1) {
61        QString kbLayout = listKbLayouts->currentItem()->text();
62        setKbVariants(kbLayout);
63    }
64
65   slotUpdateKbOnSys();
66}
67
68void widgetKeyboard::slotUpdateKbOnSys()
69{
70  QString model, layout, variant;
71
72  if ( ! (comboBoxKeyboardModel->currentIndex() == -1) )
73     return;
74  if ( ! listKbLayouts->currentItem() )
75     return;
76  if ( ! listKbVariants->currentItem() )
77     return;
78
79  model = comboBoxKeyboardModel->currentText();
80  model = model.remove(0, model.indexOf("- (") + 3 );
81  model.truncate(model.size() -1 );
82
83  layout = listKbLayouts->currentItem()->text();
84  layout = layout.remove(0, layout.indexOf("- (") + 3 );
85  layout.truncate(layout.size() -1 );
86
87  variant = listKbVariants->currentItem()->text();
88  if ( variant != "<none>" ) {
89    variant = variant.remove(0, variant.indexOf("- (") + 3 );
90    variant.truncate(variant.size() -1 );
91  } else {
92    variant = "";
93  }
94 
95  Backend::changeKbMap(model, layout, variant);
96  Backend::saveDefaultSysEnvironment( QString(getenv("LANG")) , model, layout, variant);
97}
98
99void widgetKeyboard::slotCurrentKbVariantChanged(int row)
100{
101   if (row != -1)
102      listKbVariants->currentItem()->text();
103
104   slotUpdateKbOnSys();
105}
106
107void widgetKeyboard::setKbVariants(const QString &kbLayout)
108{
109    QString laycode = kbLayout;
110    listKbVariants->clear();
111
112    // Get the code we should search for
113    laycode = laycode.remove(0, laycode.indexOf("(") + 1);
114    laycode.truncate(laycode.indexOf(")") );
115
116    listKbVariants->addItem("<none>");
117    listKbVariants->addItems(Backend::keyVariants(laycode, savedKeyVariants));
118
119    listKbVariants->setCurrentRow(0);
120}
121
122void widgetKeyboard::slotSelectedKbItemChanged()
123{
124    lineKbTest->clear();
125}
126
127// set the keyboard layout and variant defaults
128void widgetKeyboard::setKbDefaults()
129{
130        // Find the "us" key layout as the default
131        for ( int i = 0; i < listKbLayouts->count(); i++ )
132                if ( listKbLayouts->item(i)->text().indexOf("(us)") != -1 )
133                        listKbLayouts->setCurrentRow(i);
134
135
136        comboBoxKeyboardModel->setCurrentIndex(2);
137}
Note: See TracBrowser for help on using the repository browser.