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