Diffstat (limited to 'noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp new file mode 100644 index 0000000..8d868d4 --- a/dev/null +++ b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | |||
2 | #include <qdir.h> | ||
3 | #include <qpe/qpeapplication.h> | ||
4 | #include <qpe/qcopenvelope_qws.h> | ||
5 | #include <unistd.h> | ||
6 | #include "cfgdlg.h" | ||
7 | |||
8 | CfgDlg::CfgDlg(QWidget* parent, CfgFile* cf, QApplication* app, bool mod): | ||
9 | QDialog(parent, "CfgDlg", mod), cfile(cf), application(app) { | ||
10 | |||
11 | setCaption(tr("keyz configurator")); | ||
12 | |||
13 | QGridLayout* gl = new QGridLayout(this, 7, 5, 5, 5); | ||
14 | |||
15 | QLabel* flabel = new QLabel("Available Keymaps", this); | ||
16 | files = new QListBox(this); | ||
17 | QPushButton* addButton = new QPushButton(">>", this); //add->setText("Add"); | ||
18 | connect(addButton, SIGNAL(clicked()), this, SLOT(add())); | ||
19 | QLabel* klabel = new QLabel("Selected Keymaps", this); | ||
20 | keymaps = new QListBox(this); | ||
21 | connect(keymaps, SIGNAL(highlighted(const QString&)), this, SLOT(keymapHighlighted(const QString&))); | ||
22 | QPushButton* delButton = new QPushButton("<<", this); //del->setText("Delete"); | ||
23 | connect(delButton, SIGNAL(clicked()), this, SLOT(del())); | ||
24 | QPushButton* slabelButton = new QPushButton("Set Label", this); //apply->setText("Apply"); | ||
25 | connect(slabelButton, SIGNAL(clicked()), this, SLOT(setLabel())); | ||
26 | QLabel* l = new QLabel("Label", this); | ||
27 | label = new QLineEdit(this); | ||
28 | QLabel* adlabel = new QLabel("Auto Repeat Delay (ms)", this); | ||
29 | QLabel* aplabel = new QLabel("Auto Repeat Period (ms)", this); | ||
30 | ad = new QSpinBox(50, 5000, 5, this); | ||
31 | ap = new QSpinBox(0, 5000, 5, this); | ||
32 | |||
33 | //QLabel* adms = new QLabel("ms", this); | ||
34 | //QLabel* apms = new QLabel("ms", this); | ||
35 | |||
36 | //QCheckBox* enable = new QCheckBox("Enable", t); | ||
37 | |||
38 | gl->setColStretch(0, 1); | ||
39 | gl->setColStretch(1, 1); | ||
40 | gl->setColStretch(3, 1); | ||
41 | gl->setColStretch(4, 1); | ||
42 | gl->setRowStretch(3, 1); | ||
43 | gl->addMultiCellWidget(flabel, 0, 0, 0, 1); | ||
44 | gl->addMultiCellWidget(klabel, 0, 0, 3, 4); | ||
45 | gl->addMultiCellWidget(files, 1, 3, 0, 1); | ||
46 | gl->addMultiCellWidget(keymaps, 1, 3, 3, 4); | ||
47 | gl->addWidget(addButton, 1, 2); | ||
48 | gl->addWidget(delButton, 2, 2); | ||
49 | |||
50 | gl->addWidget(l, 4, 0); | ||
51 | gl->addWidget(label, 4, 1); | ||
52 | gl->addMultiCellWidget(slabelButton, 4, 4, 3, 4); | ||
53 | |||
54 | gl->addMultiCellWidget(adlabel, 5, 5, 0, 2); | ||
55 | gl->addMultiCellWidget(ad, 5, 5, 3, 4); | ||
56 | //gl->addWidget(adms, 5, 3); | ||
57 | |||
58 | gl->addMultiCellWidget(aplabel, 6, 6, 0, 2); | ||
59 | gl->addMultiCellWidget(ap, 6, 6, 3, 4); | ||
60 | |||
61 | //gl->addWidget(apms, 6, 3); | ||
62 | |||
63 | QList<CfgEntry>& e = cfile->getEntries(); | ||
64 | |||
65 | for(uint i = 0; i < e.count(); i++) { | ||
66 | CfgEntry* entry = e.at(i); | ||
67 | keymaps->insertItem(entry->getFile()); | ||
68 | m.insert(entry->getFile(), entry->getLabel()); | ||
69 | } | ||
70 | |||
71 | QDir dir(QPEApplication::qpeDir()+"/share/zkb", "*.xml"); | ||
72 | QStringList flist = dir.entryList(); | ||
73 | QStringList::Iterator sit; | ||
74 | for(sit = flist.begin(); sit != flist.end(); ++sit) { | ||
75 | if (*sit != "common.xml" && *sit != "zkb.xml" && m.find(*sit) == m.end()) { | ||
76 | files->insertItem(*sit); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | ad->setValue(cfile->getAutorepeatDelay()); | ||
81 | ap->setValue(cfile->getAutorepeatPeriod()); | ||
82 | |||
83 | //gl->addMultiCellWidget(enable, 7, 7, 0, 4); | ||
84 | } | ||
85 | |||
86 | CfgDlg::~CfgDlg() { | ||
87 | } | ||
88 | |||
89 | void CfgDlg::add() { | ||
90 | if (!files->currentText().isEmpty()) { | ||
91 | QString t = files->currentText(); | ||
92 | files->removeItem(files->currentItem()); | ||
93 | keymaps->insertItem(t); | ||
94 | cfile->replaceEntry(t, ""); | ||
95 | m.replace(t, ""); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void CfgDlg::del() { | ||
100 | if (!keymaps->currentText().isEmpty()) { | ||
101 | QString t = keymaps->currentText(); | ||
102 | keymaps->removeItem(keymaps->currentItem()); | ||
103 | cfile->deleteEntry(t); | ||
104 | files->insertItem(t); | ||
105 | m.remove(files->currentText()); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | void CfgDlg::setLabel() { | ||
110 | if (!keymaps->currentText().isEmpty()) { | ||
111 | cfile->replaceEntry(keymaps->currentText(), | ||
112 | label->text()); | ||
113 | m.replace(keymaps->currentText(), label->text()); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | void CfgDlg::keymapHighlighted(const QString&text) { | ||
118 | label->setText(*m.find(text)); | ||
119 | } | ||
120 | |||
121 | |||
122 | void CfgDlg::accept() { | ||
123 | cfile->setAutorepeatDelay(ad->value()); | ||
124 | cfile->setAutorepeatPeriod(ap->value()); | ||
125 | |||
126 | CfgParser p; | ||
127 | p.save(QPEApplication::qpeDir()+"/share/zkb/zkb.xml", *cfile); | ||
128 | QCopEnvelope("QPE/zkb", "reload()"); | ||
129 | |||
130 | QDialog::accept(); | ||
131 | } | ||
132 | |||