author | zecke <zecke> | 2004-12-20 22:17:40 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-20 22:17:40 (UTC) |
commit | b15930cd03acafd9770bca26f3388817f1a4dcbf (patch) (unidiff) | |
tree | 7f86e31793c1bacb0882e7abb88a3847333f5c4a | |
parent | a50334dddaa542fd63726a639e852c30036f53a0 (diff) | |
download | opie-b15930cd03acafd9770bca26f3388817f1a4dcbf.zip opie-b15930cd03acafd9770bca26f3388817f1a4dcbf.tar.gz opie-b15930cd03acafd9770bca26f3388817f1a4dcbf.tar.bz2 |
-Fix for 1483
"ZKB should keep user settings in $HOME/Settings instead of $OPIEDIR/share/zkb"
Now by default it loads and saves to $HOME/Applications/zkb but falls
back to $OPIEDIR/share/zkb to find the included files
-rw-r--r-- | noncore/applets/zkbapplet/applet/zkbwidget.cpp | 18 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/applet/zkbwidget.h | 2 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp | 2 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/main.cpp | 4 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp | 67 |
5 files changed, 47 insertions, 46 deletions
diff --git a/noncore/applets/zkbapplet/applet/zkbwidget.cpp b/noncore/applets/zkbapplet/applet/zkbwidget.cpp index 13729ea..55c08b3 100644 --- a/noncore/applets/zkbapplet/applet/zkbwidget.cpp +++ b/noncore/applets/zkbapplet/applet/zkbwidget.cpp | |||
@@ -1,168 +1,160 @@ | |||
1 | #include <opie2/otaskbarapplet.h> | 1 | #include <opie2/otaskbarapplet.h> |
2 | #include <opie2/okeyfilter.h> | 2 | #include <opie2/okeyfilter.h> |
3 | #include <qpe/qcopenvelope_qws.h> | 3 | #include <qpe/qcopenvelope_qws.h> |
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | #include <qpe/qpeapplication.h> | 5 | #include <qpe/qpeapplication.h> |
6 | #include <qpe/resource.h> | 6 | #include <qpe/resource.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | #include "zkbwidget.h" | 9 | #include "zkbwidget.h" |
10 | #include "zkbcfg.h" | 10 | #include "zkbcfg.h" |
11 | 11 | ||
12 | using namespace Opie::Ui; | 12 | using namespace Opie::Ui; |
13 | 13 | ||
14 | ZkbWidget::ZkbWidget(QWidget* parent) | 14 | ZkbWidget::ZkbWidget(QWidget* parent) |
15 | :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { | 15 | :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { |
16 | 16 | ||
17 | labels = new QPopupMenu(); | 17 | labels = new QPopupMenu(); |
18 | connect(labels, SIGNAL(activated(int)), this, | 18 | connect(labels, SIGNAL(activated(int)), this, |
19 | SLOT(labelChanged(int))); | 19 | SLOT(labelChanged(int))); |
20 | 20 | ||
21 | loadKeymap(); | 21 | loadKeymap(); |
22 | 22 | ||
23 | channel = new QCopChannel("QPE/zkb", this); | 23 | channel = new QCopChannel("QPE/zkb", this); |
24 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | 24 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), |
25 | this, SLOT(signalReceived(const QCString&,const QByteArray&))); | 25 | this, SLOT(signalReceived(const QCString&,const QByteArray&))); |
26 | setFixedWidth ( AppLnk::smallIconSize() ); | 26 | setFixedWidth ( AppLnk::smallIconSize() ); |
27 | setFixedHeight ( AppLnk::smallIconSize() ); | 27 | setFixedHeight ( AppLnk::smallIconSize() ); |
28 | } | 28 | } |
29 | 29 | ||
30 | ZkbWidget::~ZkbWidget() | 30 | ZkbWidget::~ZkbWidget() |
31 | { | 31 | { |
32 | if (keymap != 0) { | 32 | delete keymap; |
33 | delete keymap; | 33 | keymap = 0; |
34 | keymap = 0; | ||
35 | } | ||
36 | } | 34 | } |
37 | 35 | ||
38 | int ZkbWidget::position() | 36 | int ZkbWidget::position() |
39 | { | 37 | { |
40 | return 8; | 38 | return 8; |
41 | } | 39 | } |
42 | 40 | ||
43 | bool ZkbWidget::loadKeymap() { | 41 | bool ZkbWidget::loadKeymap() { |
44 | ZkbConfig c(QPEApplication::qpeDir()+"share/zkb"); | 42 | ZkbConfig c(Global::applicationFileName("zkb", QString::null) ); |
45 | QFontMetrics fm(font()); | 43 | QFontMetrics fm(font()); |
46 | 44 | ||
47 | if (keymap != 0) { | 45 | delete keymap; |
48 | delete keymap; | 46 | keymap = 0; |
49 | keymap = 0; | ||
50 | } | ||
51 | 47 | ||
52 | Keymap* km = new Keymap(); | 48 | Keymap* km = new Keymap(); |
53 | 49 | ||
54 | if (!c.load("zkb.xml", *km, "")) { | 50 | if (!c.load("zkb.xml", *km, "")) { |
55 | delete km; | 51 | delete km; |
56 | setPixmap(disabled); | 52 | setPixmap(disabled); |
57 | return false; | 53 | return false; |
58 | } | 54 | } |
59 | 55 | ||
60 | connect(km, SIGNAL(stateChanged(const QString&)), | 56 | connect(km, SIGNAL(stateChanged(const QString&)), |
61 | this, SLOT(stateChanged(const QString&))); | 57 | this, SLOT(stateChanged(const QString&))); |
62 | 58 | ||
63 | Opie::Core::OKeyFilter::inst()->addHandler(km); | 59 | Opie::Core::OKeyFilter::inst()->addHandler(km); |
64 | 60 | ||
65 | Keymap* oldkm = keymap; | 61 | Keymap* oldkm = keymap; |
66 | keymap = km; | 62 | keymap = km; |
67 | 63 | ||
68 | if (oldkm != 0) { | 64 | if (oldkm != 0) { |
69 | delete oldkm; | 65 | delete oldkm; |
70 | } | 66 | } |
71 | 67 | ||
72 | QString ltext = keymap->getCurrentLabel(); | 68 | QString ltext = keymap->getCurrentLabel(); |
73 | if (ltext.length()==0) ltext = "??"; | 69 | if (ltext.length()==0) ltext = "??"; |
74 | setText(ltext); | 70 | setText(ltext); |
75 | 71 | ||
76 | labels->clear(); | 72 | labels->clear(); |
77 | QStringList l = keymap->listLabels(); | 73 | QStringList l = keymap->listLabels(); |
78 | labels->insertItem(disabled, 0, 0); | 74 | labels->insertItem(disabled, 0, 0); |
79 | int n = 1; | 75 | int n = 1; |
80 | w = 0; | 76 | w = 0; |
81 | for(QStringList::Iterator it = l.begin(); it != l.end(); | 77 | for(QStringList::Iterator it = l.begin(); it != l.end(); |
82 | ++it, n++) { | 78 | ++it, n++) { |
83 | 79 | ||
84 | // printf("label: %s\n", (const char*) (*it).utf8()); | 80 | // printf("label: %s\n", (const char*) (*it).utf8()); |
85 | 81 | ||
86 | labels->insertItem(*it, n, n); | 82 | labels->insertItem(*it, n, n); |
87 | int lw = fm.width(*it); | 83 | int lw = fm.width(*it); |
88 | if (lw > w) { | 84 | if (lw > w) { |
89 | w = lw; | 85 | w = lw; |
90 | } | 86 | } |
91 | } | 87 | } |
92 | 88 | ||
93 | if (w == 0) { | 89 | if (w == 0) { |
94 | hide(); | 90 | hide(); |
95 | } else { | 91 | } else { |
96 | show(); | 92 | show(); |
97 | } | 93 | } |
98 | return true; | 94 | return true; |
99 | } | 95 | } |
100 | 96 | ||
101 | QSize ZkbWidget::sizeHint() const { | ||
102 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); | ||
103 | } | ||
104 | |||
105 | void ZkbWidget::stateChanged(const QString& s) { | 97 | void ZkbWidget::stateChanged(const QString& s) { |
106 | // odebug << "stateChanged: " << s.utf8() << "\n" << oendl; | 98 | // odebug << "stateChanged: " << s.utf8() << "\n" << oendl; |
107 | setText(s); | 99 | setText(s); |
108 | } | 100 | } |
109 | 101 | ||
110 | void ZkbWidget::labelChanged(int id) { | 102 | void ZkbWidget::labelChanged(int id) { |
111 | if (id == 0) { | 103 | if (id == 0) { |
112 | keymap->disable(); | 104 | keymap->disable(); |
113 | setPixmap(disabled); | 105 | setPixmap(disabled); |
114 | return; | 106 | return; |
115 | } | 107 | } |
116 | 108 | ||
117 | keymap->enable(); | 109 | keymap->enable(); |
118 | 110 | ||
119 | QStringList l = keymap->listLabels(); | 111 | QStringList l = keymap->listLabels(); |
120 | QString lbl = l[id-1]; | 112 | QString lbl = l[id-1]; |
121 | 113 | ||
122 | // printf("labelChanged: %s\n", (const char*) lbl.utf8()); | 114 | // printf("labelChanged: %s\n", (const char*) lbl.utf8()); |
123 | State* state = keymap->getStateByLabel(lbl); | 115 | State* state = keymap->getStateByLabel(lbl); |
124 | if (state != 0) { | 116 | if (state != 0) { |
125 | keymap->setCurrentState(state); | 117 | keymap->setCurrentState(state); |
126 | setText(lbl); | 118 | setText(lbl); |
127 | } | 119 | } |
128 | } | 120 | } |
129 | 121 | ||
130 | void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { | 122 | void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { |
131 | QSize sh = labels->sizeHint(); | 123 | QSize sh = labels->sizeHint(); |
132 | QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); | 124 | QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); |
133 | labels->exec(p); | 125 | labels->exec(p); |
134 | } | 126 | } |
135 | 127 | ||
136 | void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { | 128 | void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { |
137 | QDataStream stream(data, IO_ReadOnly); | 129 | QDataStream stream(data, IO_ReadOnly); |
138 | 130 | ||
139 | if (msg == "enable()") { | 131 | if (msg == "enable()") { |
140 | keymap->enable(); | 132 | keymap->enable(); |
141 | } else if (msg == "disable()") { | 133 | } else if (msg == "disable()") { |
142 | keymap->disable(); | 134 | keymap->disable(); |
143 | } else if (msg == "reload()") { | 135 | } else if (msg == "reload()") { |
144 | QCopEnvelope("QPE/System", "busy()"); | 136 | QCopEnvelope("QPE/System", "busy()"); |
145 | QTimer::singleShot(0, this, SLOT(reload())); | 137 | QTimer::singleShot(0, this, SLOT(reload())); |
146 | } else if (msg == "switch(QString)") { | 138 | } else if (msg == "switch(QString)") { |
147 | QString lbl; | 139 | QString lbl; |
148 | stream >> lbl; | 140 | stream >> lbl; |
149 | 141 | ||
150 | if (keymap != 0) { | 142 | if (keymap != 0) { |
151 | State* state = keymap->getStateByLabel(lbl); | 143 | State* state = keymap->getStateByLabel(lbl); |
152 | if (state != 0) { | 144 | if (state != 0) { |
153 | keymap->setCurrentState(state); | 145 | keymap->setCurrentState(state); |
154 | setText(lbl); | 146 | setText(lbl); |
155 | } | 147 | } |
156 | } | 148 | } |
157 | } else if (msg == "debug(QString)") { | 149 | } else if (msg == "debug(QString)") { |
158 | QString flag; | 150 | QString flag; |
159 | stream >> flag; | 151 | stream >> flag; |
160 | } | 152 | } |
161 | } | 153 | } |
162 | 154 | ||
163 | void ZkbWidget::reload() { | 155 | void ZkbWidget::reload() { |
164 | loadKeymap(); | 156 | loadKeymap(); |
165 | QCopEnvelope("QPE/System", "notBusy()"); | 157 | QCopEnvelope("QPE/System", "notBusy()"); |
166 | } | 158 | } |
167 | 159 | ||
168 | EXPORT_OPIE_APPLET_v1( ZkbWidget ) | 160 | EXPORT_OPIE_APPLET_v1( ZkbWidget ) |
diff --git a/noncore/applets/zkbapplet/applet/zkbwidget.h b/noncore/applets/zkbapplet/applet/zkbwidget.h index 9bce85a..13906c0 100644 --- a/noncore/applets/zkbapplet/applet/zkbwidget.h +++ b/noncore/applets/zkbapplet/applet/zkbwidget.h | |||
@@ -1,39 +1,37 @@ | |||
1 | #ifndef ZKBWIDGET_H | 1 | #ifndef ZKBWIDGET_H |
2 | #define ZKBWIDGET_H | 2 | #define ZKBWIDGET_H |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qpopupmenu.h> | 6 | #include <qpopupmenu.h> |
7 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
8 | #include <qcopchannel_qws.h> | 8 | #include <qcopchannel_qws.h> |
9 | 9 | ||
10 | #include "zkb.h" | 10 | #include "zkb.h" |
11 | 11 | ||
12 | class ZkbWidget : public QLabel { | 12 | class ZkbWidget : public QLabel { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | ZkbWidget(QWidget* parent); | 16 | ZkbWidget(QWidget* parent); |
17 | ~ZkbWidget(); | 17 | ~ZkbWidget(); |
18 | static int position(); | 18 | static int position(); |
19 | 19 | ||
20 | QSize sizeHint() const; | ||
21 | |||
22 | protected: | 20 | protected: |
23 | QLabel* label; | 21 | QLabel* label; |
24 | Keymap* keymap; | 22 | Keymap* keymap; |
25 | QPopupMenu* labels; | 23 | QPopupMenu* labels; |
26 | QCopChannel* channel; | 24 | QCopChannel* channel; |
27 | int w, h; | 25 | int w, h; |
28 | QPixmap disabled; | 26 | QPixmap disabled; |
29 | 27 | ||
30 | bool loadKeymap(); | 28 | bool loadKeymap(); |
31 | void mouseReleaseEvent(QMouseEvent*); | 29 | void mouseReleaseEvent(QMouseEvent*); |
32 | 30 | ||
33 | protected slots: | 31 | protected slots: |
34 | void stateChanged(const QString&); | 32 | void stateChanged(const QString&); |
35 | void labelChanged(int id); | 33 | void labelChanged(int id); |
36 | void signalReceived(const QCString& msg, const QByteArray& data); | 34 | void signalReceived(const QCString& msg, const QByteArray& data); |
37 | void reload(); | 35 | void reload(); |
38 | }; | 36 | }; |
39 | #endif | 37 | #endif |
diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp index 4190a9e..6f24ea0 100644 --- a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp +++ b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp | |||
@@ -1,132 +1,132 @@ | |||
1 | 1 | ||
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <qpe/qcopenvelope_qws.h> | 4 | #include <qpe/qcopenvelope_qws.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include "cfgdlg.h" | 6 | #include "cfgdlg.h" |
7 | 7 | ||
8 | CfgDlg::CfgDlg(QWidget* parent, CfgFile* cf, QApplication* app, bool mod): | 8 | CfgDlg::CfgDlg(QWidget* parent, CfgFile* cf, QApplication* app, bool mod): |
9 | QDialog(parent, "CfgDlg", mod), cfile(cf), application(app) { | 9 | QDialog(parent, "CfgDlg", mod), cfile(cf), application(app) { |
10 | 10 | ||
11 | setCaption(tr("keyz configurator")); | 11 | setCaption(tr("keyz configurator")); |
12 | 12 | ||
13 | QGridLayout* gl = new QGridLayout(this, 7, 5, 5, 5); | 13 | QGridLayout* gl = new QGridLayout(this, 7, 5, 5, 5); |
14 | 14 | ||
15 | QLabel* flabel = new QLabel("Available Keymaps", this); | 15 | QLabel* flabel = new QLabel("Available Keymaps", this); |
16 | files = new QListBox(this); | 16 | files = new QListBox(this); |
17 | QPushButton* addButton = new QPushButton(">>", this); //add->setText("Add"); | 17 | QPushButton* addButton = new QPushButton(">>", this); //add->setText("Add"); |
18 | connect(addButton, SIGNAL(clicked()), this, SLOT(add())); | 18 | connect(addButton, SIGNAL(clicked()), this, SLOT(add())); |
19 | QLabel* klabel = new QLabel("Selected Keymaps", this); | 19 | QLabel* klabel = new QLabel("Selected Keymaps", this); |
20 | keymaps = new QListBox(this); | 20 | keymaps = new QListBox(this); |
21 | connect(keymaps, SIGNAL(highlighted(const QString&)), this, SLOT(keymapHighlighted(const QString&))); | 21 | connect(keymaps, SIGNAL(highlighted(const QString&)), this, SLOT(keymapHighlighted(const QString&))); |
22 | QPushButton* delButton = new QPushButton("<<", this); //del->setText("Delete"); | 22 | QPushButton* delButton = new QPushButton("<<", this); //del->setText("Delete"); |
23 | connect(delButton, SIGNAL(clicked()), this, SLOT(del())); | 23 | connect(delButton, SIGNAL(clicked()), this, SLOT(del())); |
24 | QPushButton* slabelButton = new QPushButton("Set Label", this); //apply->setText("Apply"); | 24 | QPushButton* slabelButton = new QPushButton("Set Label", this); //apply->setText("Apply"); |
25 | connect(slabelButton, SIGNAL(clicked()), this, SLOT(setLabel())); | 25 | connect(slabelButton, SIGNAL(clicked()), this, SLOT(setLabel())); |
26 | QLabel* l = new QLabel("Label", this); | 26 | QLabel* l = new QLabel("Label", this); |
27 | label = new QLineEdit(this); | 27 | label = new QLineEdit(this); |
28 | QLabel* adlabel = new QLabel("Auto Repeat Delay (ms)", this); | 28 | QLabel* adlabel = new QLabel("Auto Repeat Delay (ms)", this); |
29 | QLabel* aplabel = new QLabel("Auto Repeat Period (ms)", this); | 29 | QLabel* aplabel = new QLabel("Auto Repeat Period (ms)", this); |
30 | ad = new QSpinBox(50, 5000, 5, this); | 30 | ad = new QSpinBox(50, 5000, 5, this); |
31 | ap = new QSpinBox(0, 5000, 5, this); | 31 | ap = new QSpinBox(0, 5000, 5, this); |
32 | 32 | ||
33 | //QLabel* adms = new QLabel("ms", this); | 33 | //QLabel* adms = new QLabel("ms", this); |
34 | //QLabel* apms = new QLabel("ms", this); | 34 | //QLabel* apms = new QLabel("ms", this); |
35 | 35 | ||
36 | //QCheckBox* enable = new QCheckBox("Enable", t); | 36 | //QCheckBox* enable = new QCheckBox("Enable", t); |
37 | 37 | ||
38 | gl->setColStretch(0, 1); | 38 | gl->setColStretch(0, 1); |
39 | gl->setColStretch(1, 1); | 39 | gl->setColStretch(1, 1); |
40 | gl->setColStretch(3, 1); | 40 | gl->setColStretch(3, 1); |
41 | gl->setColStretch(4, 1); | 41 | gl->setColStretch(4, 1); |
42 | gl->setRowStretch(3, 1); | 42 | gl->setRowStretch(3, 1); |
43 | gl->addMultiCellWidget(flabel, 0, 0, 0, 1); | 43 | gl->addMultiCellWidget(flabel, 0, 0, 0, 1); |
44 | gl->addMultiCellWidget(klabel, 0, 0, 3, 4); | 44 | gl->addMultiCellWidget(klabel, 0, 0, 3, 4); |
45 | gl->addMultiCellWidget(files, 1, 3, 0, 1); | 45 | gl->addMultiCellWidget(files, 1, 3, 0, 1); |
46 | gl->addMultiCellWidget(keymaps, 1, 3, 3, 4); | 46 | gl->addMultiCellWidget(keymaps, 1, 3, 3, 4); |
47 | gl->addWidget(addButton, 1, 2); | 47 | gl->addWidget(addButton, 1, 2); |
48 | gl->addWidget(delButton, 2, 2); | 48 | gl->addWidget(delButton, 2, 2); |
49 | 49 | ||
50 | gl->addWidget(l, 4, 0); | 50 | gl->addWidget(l, 4, 0); |
51 | gl->addWidget(label, 4, 1); | 51 | gl->addWidget(label, 4, 1); |
52 | gl->addMultiCellWidget(slabelButton, 4, 4, 3, 4); | 52 | gl->addMultiCellWidget(slabelButton, 4, 4, 3, 4); |
53 | 53 | ||
54 | gl->addMultiCellWidget(adlabel, 5, 5, 0, 2); | 54 | gl->addMultiCellWidget(adlabel, 5, 5, 0, 2); |
55 | gl->addMultiCellWidget(ad, 5, 5, 3, 4); | 55 | gl->addMultiCellWidget(ad, 5, 5, 3, 4); |
56 | //gl->addWidget(adms, 5, 3); | 56 | //gl->addWidget(adms, 5, 3); |
57 | 57 | ||
58 | gl->addMultiCellWidget(aplabel, 6, 6, 0, 2); | 58 | gl->addMultiCellWidget(aplabel, 6, 6, 0, 2); |
59 | gl->addMultiCellWidget(ap, 6, 6, 3, 4); | 59 | gl->addMultiCellWidget(ap, 6, 6, 3, 4); |
60 | 60 | ||
61 | //gl->addWidget(apms, 6, 3); | 61 | //gl->addWidget(apms, 6, 3); |
62 | 62 | ||
63 | QList<CfgEntry>& e = cfile->getEntries(); | 63 | QList<CfgEntry>& e = cfile->getEntries(); |
64 | 64 | ||
65 | for(uint i = 0; i < e.count(); i++) { | 65 | for(uint i = 0; i < e.count(); i++) { |
66 | CfgEntry* entry = e.at(i); | 66 | CfgEntry* entry = e.at(i); |
67 | keymaps->insertItem(entry->getFile()); | 67 | keymaps->insertItem(entry->getFile()); |
68 | m.insert(entry->getFile(), entry->getLabel()); | 68 | m.insert(entry->getFile(), entry->getLabel()); |
69 | } | 69 | } |
70 | 70 | ||
71 | QDir dir(QPEApplication::qpeDir()+"share/zkb", "*.xml"); | 71 | QDir dir(QPEApplication::qpeDir()+"share/zkb", "*.xml"); |
72 | QStringList flist = dir.entryList(); | 72 | QStringList flist = dir.entryList(); |
73 | QStringList::Iterator sit; | 73 | QStringList::Iterator sit; |
74 | for(sit = flist.begin(); sit != flist.end(); ++sit) { | 74 | for(sit = flist.begin(); sit != flist.end(); ++sit) { |
75 | if (*sit != "common.xml" && *sit != "zkb.xml" && m.find(*sit) == m.end()) { | 75 | if (*sit != "common.xml" && *sit != "zkb.xml" && m.find(*sit) == m.end()) { |
76 | files->insertItem(*sit); | 76 | files->insertItem(*sit); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | ad->setValue(cfile->getAutorepeatDelay()); | 80 | ad->setValue(cfile->getAutorepeatDelay()); |
81 | ap->setValue(cfile->getAutorepeatPeriod()); | 81 | ap->setValue(cfile->getAutorepeatPeriod()); |
82 | 82 | ||
83 | //gl->addMultiCellWidget(enable, 7, 7, 0, 4); | 83 | //gl->addMultiCellWidget(enable, 7, 7, 0, 4); |
84 | } | 84 | } |
85 | 85 | ||
86 | CfgDlg::~CfgDlg() { | 86 | CfgDlg::~CfgDlg() { |
87 | } | 87 | } |
88 | 88 | ||
89 | void CfgDlg::add() { | 89 | void CfgDlg::add() { |
90 | if (!files->currentText().isEmpty()) { | 90 | if (!files->currentText().isEmpty()) { |
91 | QString t = files->currentText(); | 91 | QString t = files->currentText(); |
92 | files->removeItem(files->currentItem()); | 92 | files->removeItem(files->currentItem()); |
93 | keymaps->insertItem(t); | 93 | keymaps->insertItem(t); |
94 | cfile->replaceEntry(t, ""); | 94 | cfile->replaceEntry(t, ""); |
95 | m.replace(t, ""); | 95 | m.replace(t, ""); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | void CfgDlg::del() { | 99 | void CfgDlg::del() { |
100 | if (!keymaps->currentText().isEmpty()) { | 100 | if (!keymaps->currentText().isEmpty()) { |
101 | QString t = keymaps->currentText(); | 101 | QString t = keymaps->currentText(); |
102 | keymaps->removeItem(keymaps->currentItem()); | 102 | keymaps->removeItem(keymaps->currentItem()); |
103 | cfile->deleteEntry(t); | 103 | cfile->deleteEntry(t); |
104 | files->insertItem(t); | 104 | files->insertItem(t); |
105 | m.remove(files->currentText()); | 105 | m.remove(files->currentText()); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | void CfgDlg::setLabel() { | 109 | void CfgDlg::setLabel() { |
110 | if (!keymaps->currentText().isEmpty()) { | 110 | if (!keymaps->currentText().isEmpty()) { |
111 | cfile->replaceEntry(keymaps->currentText(), | 111 | cfile->replaceEntry(keymaps->currentText(), |
112 | label->text()); | 112 | label->text()); |
113 | m.replace(keymaps->currentText(), label->text()); | 113 | m.replace(keymaps->currentText(), label->text()); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | void CfgDlg::keymapHighlighted(const QString&text) { | 117 | void CfgDlg::keymapHighlighted(const QString&text) { |
118 | label->setText(*m.find(text)); | 118 | label->setText(*m.find(text)); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | void CfgDlg::accept() { | 122 | void CfgDlg::accept() { |
123 | cfile->setAutorepeatDelay(ad->value()); | 123 | cfile->setAutorepeatDelay(ad->value()); |
124 | cfile->setAutorepeatPeriod(ap->value()); | 124 | cfile->setAutorepeatPeriod(ap->value()); |
125 | 125 | ||
126 | CfgParser p; | 126 | CfgParser p; |
127 | p.save(QPEApplication::qpeDir()+"share/zkb/zkb.xml", *cfile); | 127 | p.save(Global::applicationFileName("zkb", "zkb.xml" ), *cfile); |
128 | QCopEnvelope("QPE/zkb", "reload()"); | 128 | QCopEnvelope("QPE/zkb", "reload()"); |
129 | 129 | ||
130 | QDialog::accept(); | 130 | QDialog::accept(); |
131 | } | 131 | } |
132 | 132 | ||
diff --git a/noncore/applets/zkbapplet/keyzcfg/main.cpp b/noncore/applets/zkbapplet/keyzcfg/main.cpp index afd0f6a..d7926f0 100644 --- a/noncore/applets/zkbapplet/keyzcfg/main.cpp +++ b/noncore/applets/zkbapplet/keyzcfg/main.cpp | |||
@@ -1,22 +1,24 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <qpe/qpeapplication.h> | 2 | #include <qpe/qpeapplication.h> |
3 | #include <qpe/global.h> | ||
4 | |||
3 | #include <qlayout.h> | 5 | #include <qlayout.h> |
4 | #include <qmainwindow.h> | 6 | #include <qmainwindow.h> |
5 | 7 | ||
6 | #include "cfgdlg.h" | 8 | #include "cfgdlg.h" |
7 | 9 | ||
8 | int main( int argc, char **argv ) { | 10 | int main( int argc, char **argv ) { |
9 | QPEApplication app(argc, argv); | 11 | QPEApplication app(argc, argv); |
10 | CfgFile cfile; | 12 | CfgFile cfile; |
11 | CfgParser cp; | 13 | CfgParser cp; |
12 | cp.load(QPEApplication::qpeDir()+"share/zkb/zkb.xml", cfile); | 14 | cp.load(Global::applicationFileName("zkb", "zkb.xml"), cfile); |
13 | 15 | ||
14 | 16 | ||
15 | CfgDlg c(0, &cfile, &app, true); | 17 | CfgDlg c(0, &cfile, &app, true); |
16 | 18 | ||
17 | 19 | ||
18 | app.showMainWidget(&c); | 20 | app.showMainWidget(&c); |
19 | int ret = QPEApplication::execDialog(&c); | 21 | int ret = QPEApplication::execDialog(&c); |
20 | 22 | ||
21 | return ret; | 23 | return ret; |
22 | } | 24 | } |
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp index 24bd897..6f3b9bf 100644 --- a/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp +++ b/noncore/applets/zkbapplet/keyzcfg/zkbcfg.cpp | |||
@@ -1,231 +1,240 @@ | |||
1 | #include "zkbcfg.h" | 1 | #include "zkbcfg.h" |
2 | 2 | ||
3 | /* OPIE */ | 3 | /* OPIE */ |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | #include <opie2/oapplication.h> | ||
5 | using namespace Opie::Core; | 6 | using namespace Opie::Core; |
6 | 7 | ||
7 | /* QT */ | 8 | /* QT */ |
8 | #include <qfileinfo.h> | 9 | #include <qfileinfo.h> |
9 | 10 | ||
10 | // Implementation of XkbConfig class | 11 | // Implementation of XkbConfig class |
11 | ZkbConfig::ZkbConfig(const QString& dir):path(dir) { | 12 | ZkbConfig::ZkbConfig(const QString& dir):path(dir) { |
12 | } | 13 | } |
13 | 14 | ||
14 | ZkbConfig::~ZkbConfig() { | 15 | ZkbConfig::~ZkbConfig() { |
15 | } | 16 | } |
16 | 17 | ||
17 | bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) { | 18 | bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) { |
18 | bool ret; | 19 | bool ret; |
19 | QFile f(path+"/"+file); | 20 | QFile *f = new QFile(path+"/"+file); |
20 | QFileInfo fi(f); | 21 | QFileInfo fi(*f); |
21 | 22 | ||
22 | odebug << "start loading file=" << file.utf8() << "\n" << oendl; | 23 | /* Try */ |
23 | if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { | 24 | if ( !fi.exists() && !path.contains( QPEApplication::qpeDir()) ) { |
24 | return false; | 25 | delete f; |
25 | } | 26 | f = new QFile( QPEApplication::qpeDir() + "share/zkb/" + file ); |
27 | fi = QFileInfo( *f ); | ||
28 | } | ||
26 | 29 | ||
27 | includedFiles.insert(fi.absFilePath(), 1); | 30 | odebug << "start loading file=" << file << "\n" << oendl; |
28 | QXmlInputSource is(f); | 31 | if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { |
29 | QXmlSimpleReader reader; | 32 | return false; |
30 | ZkbHandler h(*this, keymap, prefix); | 33 | } |
31 | 34 | ||
32 | reader.setContentHandler(&h); | 35 | includedFiles.insert(fi.absFilePath(), 1); |
33 | reader.setErrorHandler(this); | 36 | QXmlInputSource is(*f); |
34 | ret = reader.parse(is); | 37 | QXmlSimpleReader reader; |
35 | includedFiles.remove(fi.absFilePath()); | 38 | ZkbHandler h(*this, keymap, prefix); |
36 | 39 | ||
37 | odebug << "end loading file=" << file.utf8() << ": status=" << err.utf8() << oendl; | 40 | reader.setContentHandler(&h); |
38 | return ret; | 41 | reader.setErrorHandler(this); |
42 | ret = reader.parse(is); | ||
43 | includedFiles.remove(fi.absFilePath()); | ||
44 | |||
45 | odebug << "end loading file=" << file << ": status=" << err << oendl; | ||
46 | delete f; | ||
47 | return ret; | ||
39 | } | 48 | } |
40 | 49 | ||
41 | bool ZkbConfig::warning(const QXmlParseException& e) { | 50 | bool ZkbConfig::warning(const QXmlParseException& e) { |
42 | QString tmp; | 51 | QString tmp; |
43 | 52 | ||
44 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), | 53 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), |
45 | (const char*) e.message().utf8()); | 54 | (const char*) e.message().utf8()); |
46 | 55 | ||
47 | err += tmp; | 56 | err += tmp; |
48 | 57 | ||
49 | return true; | 58 | return true; |
50 | } | 59 | } |
51 | 60 | ||
52 | bool ZkbConfig::error(const QXmlParseException& e) { | 61 | bool ZkbConfig::error(const QXmlParseException& e) { |
53 | QString tmp; | 62 | QString tmp; |
54 | 63 | ||
55 | tmp.sprintf("%d: error: %s\n", e.lineNumber(), | 64 | tmp.sprintf("%d: error: %s\n", e.lineNumber(), |
56 | (const char*) e.message().utf8()); | 65 | (const char*) e.message().utf8()); |
57 | 66 | ||
58 | err += tmp; | 67 | err += tmp; |
59 | 68 | ||
60 | return true; | 69 | return true; |
61 | } | 70 | } |
62 | 71 | ||
63 | bool ZkbConfig::fatalError(const QXmlParseException& e) { | 72 | bool ZkbConfig::fatalError(const QXmlParseException& e) { |
64 | QString tmp; | 73 | QString tmp; |
65 | 74 | ||
66 | tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), | 75 | tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), |
67 | (const char*) e.message().utf8()); | 76 | (const char*) e.message().utf8()); |
68 | 77 | ||
69 | err += tmp; | 78 | err += tmp; |
70 | 79 | ||
71 | return false; | 80 | return false; |
72 | } | 81 | } |
73 | 82 | ||
74 | QString ZkbConfig::errorString() { | 83 | QString ZkbConfig::errorString() { |
75 | return err; | 84 | return err; |
76 | } | 85 | } |
77 | 86 | ||
78 | // Implementation of ZkbHandler | 87 | // Implementation of ZkbHandler |
79 | ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k), | 88 | ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k), |
80 | prefix(p), ardelay(-1), arperiod(-1), currentState(0), currentAction(0) { | 89 | prefix(p), ardelay(-1), arperiod(-1), currentState(0), currentAction(0) { |
81 | } | 90 | } |
82 | 91 | ||
83 | ZkbHandler::~ZkbHandler() { | 92 | ZkbHandler::~ZkbHandler() { |
84 | } | 93 | } |
85 | 94 | ||
86 | bool ZkbHandler::startKeymapElement(int ard, int arp, const QString&) { | 95 | bool ZkbHandler::startKeymapElement(int ard, int arp, const QString&) { |
87 | ardelay = ard; | 96 | ardelay = ard; |
88 | arperiod = arp; | 97 | arperiod = arp; |
89 | 98 | ||
90 | return true; | 99 | return true; |
91 | } | 100 | } |
92 | 101 | ||
93 | bool ZkbHandler::startIncludeElement(const QString& file, | 102 | bool ZkbHandler::startIncludeElement(const QString& file, |
94 | const QString& pref) { | 103 | const QString& pref) { |
95 | 104 | ||
96 | QString p = prefix; | 105 | QString p = prefix; |
97 | 106 | ||
98 | if (!pref.isNull()) { | 107 | if (!pref.isNull()) { |
99 | p += pref + ":"; | 108 | p += pref + ":"; |
100 | } | 109 | } |
101 | 110 | ||
102 | 111 | ||
103 | bool ret = zkc.load(file, keymap, p); | 112 | bool ret = zkc.load(file, keymap, p); |
104 | if (!ret) { | 113 | if (!ret) { |
105 | setError("Error including file: " + file); | 114 | setError("Error including file: " + file); |
106 | } | 115 | } |
107 | 116 | ||
108 | return ret; | 117 | return ret; |
109 | } | 118 | } |
110 | 119 | ||
111 | bool ZkbHandler::startLabelElement(const QString& label, | 120 | bool ZkbHandler::startLabelElement(const QString& label, |
112 | const QString& state) { | 121 | const QString& state) { |
113 | 122 | ||
114 | if (!keymap.addLabel(label, prefix + state)) { | 123 | if (!keymap.addLabel(label, prefix + state)) { |
115 | err = "label " + label + " already defined"; | 124 | err = "label " + label + " already defined"; |
116 | return false; | 125 | return false; |
117 | } | 126 | } |
118 | 127 | ||
119 | return true; | 128 | return true; |
120 | } | 129 | } |
121 | 130 | ||
122 | bool ZkbHandler::startStateElement(const QString& name, | 131 | bool ZkbHandler::startStateElement(const QString& name, |
123 | const QString& parentName, bool dflt) { | 132 | const QString& parentName, bool dflt) { |
124 | 133 | ||
125 | currentStateName = prefix + name; | 134 | currentStateName = prefix + name; |
126 | currentState = keymap.getStateByName(currentStateName); | 135 | currentState = keymap.getStateByName(currentStateName); |
127 | 136 | ||
128 | //odebug << "state name=" << currentStateName.utf8() << "\n" << oendl; | 137 | //odebug << "state name=" << currentStateName.utf8() << "\n" << oendl; |
129 | 138 | ||
130 | State* parent = 0; | 139 | State* parent = 0; |
131 | if (!parentName.isEmpty()) { | 140 | if (!parentName.isEmpty()) { |
132 | QString pn = prefix + parentName; | 141 | QString pn = prefix + parentName; |
133 | parent = keymap.getStateByName(pn); | 142 | parent = keymap.getStateByName(pn); |
134 | if (parent == 0) { | 143 | if (parent == 0) { |
135 | err = currentStateName + | 144 | err = currentStateName + |
136 | ": undefined parent state: " + pn; | 145 | ": undefined parent state: " + pn; |
137 | return false; | 146 | return false; |
138 | } | 147 | } |
139 | } | 148 | } |
140 | 149 | ||
141 | if (currentState == 0) { | 150 | if (currentState == 0) { |
142 | currentState = new State(parent); | 151 | currentState = new State(parent); |
143 | keymap.addState(currentStateName, currentState); | 152 | keymap.addState(currentStateName, currentState); |
144 | } else { | 153 | } else { |
145 | if (parent!=0) { | 154 | if (parent!=0) { |
146 | currentState->setParent(parent); | 155 | currentState->setParent(parent); |
147 | } | 156 | } |
148 | } | 157 | } |
149 | 158 | ||
150 | if (dflt) { | 159 | if (dflt) { |
151 | keymap.setCurrentState(currentState); | 160 | keymap.setCurrentState(currentState); |
152 | } | 161 | } |
153 | 162 | ||
154 | return true; | 163 | return true; |
155 | } | 164 | } |
156 | 165 | ||
157 | bool ZkbHandler::startMapElement(int keycode, bool pressed) { | 166 | bool ZkbHandler::startMapElement(int keycode, bool pressed) { |
158 | currentAction = currentState->get(keycode, pressed); | 167 | currentAction = currentState->get(keycode, pressed); |
159 | if (currentAction == 0) { | 168 | if (currentAction == 0) { |
160 | setError("keycode " + QString::number(keycode) + " not supported"); | 169 | setError("keycode " + QString::number(keycode) + " not supported"); |
161 | return false; | 170 | return false; |
162 | } | 171 | } |
163 | 172 | ||
164 | currentAction->setEvent(false); | 173 | currentAction->setEvent(false); |
165 | currentAction->setState(0); | 174 | currentAction->setState(0); |
166 | 175 | ||
167 | return true; | 176 | return true; |
168 | } | 177 | } |
169 | 178 | ||
170 | bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers, | 179 | bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers, |
171 | bool pressed, bool autorepeat) { | 180 | bool pressed, bool autorepeat) { |
172 | 181 | ||
173 | currentAction->setEvent(true); | 182 | currentAction->setEvent(true); |
174 | currentAction->setKeycode(keycode); | 183 | currentAction->setKeycode(keycode); |
175 | currentAction->setUnicode(unicode); | 184 | currentAction->setUnicode(unicode); |
176 | currentAction->setModifiers(modifiers); | 185 | currentAction->setModifiers(modifiers); |
177 | currentAction->setPressed(pressed); | 186 | currentAction->setPressed(pressed); |
178 | currentAction->setAutorepeat(autorepeat); | 187 | currentAction->setAutorepeat(autorepeat); |
179 | 188 | ||
180 | return true; | 189 | return true; |
181 | } | 190 | } |
182 | 191 | ||
183 | bool ZkbHandler::startNextStateElement(const QString& state) { | 192 | bool ZkbHandler::startNextStateElement(const QString& state) { |
184 | State* s = keymap.getStateByName(prefix + state); | 193 | State* s = keymap.getStateByName(prefix + state); |
185 | if (s == 0) { | 194 | if (s == 0) { |
186 | setError("undefine state: " + prefix + state); | 195 | setError("undefine state: " + prefix + state); |
187 | return false; | 196 | return false; |
188 | } | 197 | } |
189 | 198 | ||
190 | currentAction->setState(s); | 199 | currentAction->setState(s); |
191 | return true; | 200 | return true; |
192 | } | 201 | } |
193 | 202 | ||
194 | 203 | ||
195 | bool ZkbHandler::endKeymapElement() { | 204 | bool ZkbHandler::endKeymapElement() { |
196 | if (ardelay > 0) { | 205 | if (ardelay > 0) { |
197 | keymap.setAutorepeatDelay(ardelay); | 206 | keymap.setAutorepeatDelay(ardelay); |
198 | } | 207 | } |
199 | 208 | ||
200 | if (arperiod > 0) { | 209 | if (arperiod > 0) { |
201 | keymap.setAutorepeatPeriod(arperiod); | 210 | keymap.setAutorepeatPeriod(arperiod); |
202 | } | 211 | } |
203 | 212 | ||
204 | return true; | 213 | return true; |
205 | } | 214 | } |
206 | 215 | ||
207 | bool ZkbHandler::endIncludeElement() { | 216 | bool ZkbHandler::endIncludeElement() { |
208 | return true; | 217 | return true; |
209 | } | 218 | } |
210 | 219 | ||
211 | bool ZkbHandler::endLabelElement() { | 220 | bool ZkbHandler::endLabelElement() { |
212 | return true; | 221 | return true; |
213 | } | 222 | } |
214 | 223 | ||
215 | bool ZkbHandler::endStateElement() { | 224 | bool ZkbHandler::endStateElement() { |
216 | currentState = 0; | 225 | currentState = 0; |
217 | return true; | 226 | return true; |
218 | } | 227 | } |
219 | 228 | ||
220 | bool ZkbHandler::endMapElement() { | 229 | bool ZkbHandler::endMapElement() { |
221 | currentAction = 0; | 230 | currentAction = 0; |
222 | return true; | 231 | return true; |
223 | } | 232 | } |
224 | 233 | ||
225 | bool ZkbHandler::endEventElement() { | 234 | bool ZkbHandler::endEventElement() { |
226 | return true; | 235 | return true; |
227 | } | 236 | } |
228 | 237 | ||
229 | bool ZkbHandler::endNextStateElement() { | 238 | bool ZkbHandler::endNextStateElement() { |
230 | return true; | 239 | return true; |
231 | } | 240 | } |