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