source: src-qt4/PCDM/src/dialogKeyboard.cpp @ a982a19

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

Add the ability for PCDM to save/load the previous/default locale and keyboard settings. Still needs testing, but if it works I just need to enable the keyboard settings for the user session as well in order to have all the localization stiff finished completely.

  • 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}
35
36void widgetKeyboard::connectKeyboardSlots()
37{
38  // load keyboards
39  listKbLayouts->clear();
40  listKbLayouts->addItems(keyboardLayouts);
41  comboBoxKeyboardModel->addItems(keyboardModels);
42
43  // Set the default keyboard stuff
44  setKbDefaults();
45  slotCurrentKbLayoutChanged(0);
46  groupKeyboard->setEnabled(true);
47
48
49  // Connect all our slots
50  connect(listKbLayouts, SIGNAL(currentRowChanged(int)), this, SLOT(slotCurrentKbLayoutChanged(int)));
51  connect(listKbVariants,SIGNAL(currentRowChanged(int)), this, SLOT(slotCurrentKbVariantChanged(int)));
52  connect(listKbLayouts, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectedKbItemChanged()));
53  connect(listKbVariants,SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectedKbItemChanged()));
54  connect(comboBoxKeyboardModel,SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateKbOnSys()));
55}
56
57void widgetKeyboard::slotCurrentKbLayoutChanged(int row)
58{
59    if (row != -1) {
60        QString kbLayout = listKbLayouts->currentItem()->text();
61        setKbVariants(kbLayout);
62    }
63
64   slotUpdateKbOnSys();
65}
66
67void widgetKeyboard::slotUpdateKbOnSys()
68{
69  QString model, layout, variant;
70
71  if ( ! (comboBoxKeyboardModel->currentIndex() == -1) )
72     return;
73  if ( ! listKbLayouts->currentItem() )
74     return;
75  if ( ! listKbVariants->currentItem() )
76     return;
77
78  model = comboBoxKeyboardModel->currentText();
79  model = model.remove(0, model.indexOf("- (") + 3 );
80  model.truncate(model.size() -1 );
81
82  layout = listKbLayouts->currentItem()->text();
83  layout = layout.remove(0, layout.indexOf("- (") + 3 );
84  layout.truncate(layout.size() -1 );
85
86  variant = listKbVariants->currentItem()->text();
87  if ( variant != "<none>" ) {
88    variant = variant.remove(0, variant.indexOf("- (") + 3 );
89    variant.truncate(variant.size() -1 );
90  } else {
91    variant = "";
92  }
93 
94  Backend::changeKbMap(model, layout, variant);
95  Backend::saveDefaultSysEnvironment( QString(getenv("LANG")) , model, layout, variant);
96}
97
98void widgetKeyboard::slotCurrentKbVariantChanged(int row)
99{
100   if (row != -1)
101      listKbVariants->currentItem()->text();
102
103   slotUpdateKbOnSys();
104}
105
106void widgetKeyboard::setKbVariants(const QString &kbLayout)
107{
108    QString laycode = kbLayout;
109    listKbVariants->clear();
110
111    // Get the code we should search for
112    laycode = laycode.remove(0, laycode.indexOf("(") + 1);
113    laycode.truncate(laycode.indexOf(")") );
114
115    listKbVariants->addItem("<none>");
116    listKbVariants->addItems(Backend::keyVariants(laycode, savedKeyVariants));
117
118    listKbVariants->setCurrentRow(0);
119}
120
121void widgetKeyboard::slotSelectedKbItemChanged()
122{
123    lineKbTest->clear();
124}
125
126// set the keyboard layout and variant defaults
127void widgetKeyboard::setKbDefaults()
128{
129        // Find the "us" key layout as the default
130        for ( int i = 0; i < listKbLayouts->count(); i++ )
131                if ( listKbLayouts->item(i)->text().indexOf("(us)") != -1 )
132                        listKbLayouts->setCurrentRow(i);
133
134
135        comboBoxKeyboardModel->setCurrentIndex(2);
136}
Note: See TracBrowser for help on using the repository browser.