Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/misc') (more/less context) (ignore whitespace changes)
16 files changed, 2075 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp new file mode 100644 index 0000000..3693dff --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.cpp | |||
@@ -0,0 +1,112 @@ | |||
1 | #include "ConfigEx.h" | ||
2 | |||
3 | ConfigEx::ConfigEx(const QString& name, Domain domain) | ||
4 | : Config(name, domain) | ||
5 | { | ||
6 | m_charset = "utf8"; | ||
7 | decode(); | ||
8 | m_lastRead = QDateTime::currentDateTime(); | ||
9 | } | ||
10 | |||
11 | #if 0 | ||
12 | void ConfigEx::removeComment() | ||
13 | { | ||
14 | for(QMap<QString,ConfigGroup>::Iterator it=groups.begin(); | ||
15 | it!=groups.end(); ++it){ | ||
16 | QStringList removeList; | ||
17 | for(ConfigGroup::Iterator it2=(*it).begin(); | ||
18 | it2!=(*it).end(); ++it2){ | ||
19 | if(it2.key()[0] == '#'){ | ||
20 | QString key = it2.key(); | ||
21 | removeList.append(it2.key()); | ||
22 | } | ||
23 | } | ||
24 | for(QStringList::Iterator it3=removeList.begin(); | ||
25 | it3!=removeList.end(); ++it3){ | ||
26 | (*it).remove(*it3); | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | #endif | ||
31 | |||
32 | void ConfigEx::decode() | ||
33 | { | ||
34 | QString group = getGroup(); | ||
35 | setGroup("Global"); | ||
36 | QString charset = readEntry("CharSet", "utf8"); | ||
37 | qWarning("ConfigEx::decode()[%s][%s]", charset.latin1(), m_charset.latin1()); | ||
38 | setGroup(group); | ||
39 | if(charset != m_charset){ | ||
40 | m_charset = charset; | ||
41 | read(); | ||
42 | } | ||
43 | //removeComment(); | ||
44 | } | ||
45 | |||
46 | void ConfigEx::read() | ||
47 | { | ||
48 | qWarning("ConfigEx::read()"); | ||
49 | groups.clear(); | ||
50 | changed = FALSE; | ||
51 | |||
52 | if ( !QFileInfo( filename ).exists() ) { | ||
53 | git = groups.end(); | ||
54 | return; | ||
55 | } | ||
56 | |||
57 | QFile f( filename ); | ||
58 | if ( !f.open( IO_ReadOnly ) ) { | ||
59 | git = groups.end(); | ||
60 | return; | ||
61 | } | ||
62 | |||
63 | QTextStream s( &f ); | ||
64 | #ifdef CONFIG_MULTICODEC | ||
65 | QTextCodec* codec = QTextCodec::codecForName(m_charset); | ||
66 | if(codec == NULL){ | ||
67 | codec = QTextCodec::codecForName("utf8"); | ||
68 | qWarning("Config CharSet[utf8]"); | ||
69 | } else { | ||
70 | qWarning("Config CharSet[%s]", m_charset.latin1()); | ||
71 | } | ||
72 | s.setCodec(codec); | ||
73 | #else /* CONFIG_MULTICODEC */ | ||
74 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | ||
75 | // The below should work, but doesn't in Qt 2.3.0 | ||
76 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | ||
77 | #else | ||
78 | s.setEncoding( QTextStream::UnicodeUTF8 ); | ||
79 | #endif | ||
80 | #endif /* CONFIG_MULTICODEC */ | ||
81 | |||
82 | QStringList list = QStringList::split('\n', s.read() ); | ||
83 | |||
84 | f.close(); | ||
85 | |||
86 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
87 | if ( !parse( *it ) ) { | ||
88 | git = groups.end(); | ||
89 | return; | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | |||
94 | QStringList ConfigEx::getKeys() | ||
95 | { | ||
96 | QStringList keys; | ||
97 | if(groups.end() != git){ | ||
98 | for(ConfigGroup::ConstIterator it=(*git).begin(); | ||
99 | it!=(*git).end(); ++it){ | ||
100 | if(it.key()[0] != '#'){ | ||
101 | keys.append(it.key()); | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | return(keys); | ||
106 | } | ||
107 | |||
108 | QDateTime ConfigEx::lastModified() | ||
109 | { | ||
110 | QFileInfo info(filename); | ||
111 | return(info.lastModified()); | ||
112 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.h b/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.h new file mode 100644 index 0000000..32120cc --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/ConfigEx.h | |||
@@ -0,0 +1,89 @@ | |||
1 | #ifndef _CONFIG_EX_H_ | ||
2 | #define _CONFIG_EX_H_ | ||
3 | |||
4 | #include <qstringlist.h> | ||
5 | #include <qdatetime.h> | ||
6 | #include <qfileinfo.h> | ||
7 | #include <qtextstream.h> | ||
8 | #include <qtextcodec.h> | ||
9 | |||
10 | #define QTOPIA_INTERNAL_LANGLIST | ||
11 | #include <qpe/config.h> | ||
12 | #include <qpe/global.h> | ||
13 | |||
14 | #define CONFIG_MULTICODEC | ||
15 | |||
16 | /* Singleton Object */ | ||
17 | class ConfigEx : public Config | ||
18 | { | ||
19 | public: | ||
20 | static ConfigEx& getInstance(const QString& name){ | ||
21 | static ConfigEx cfg(name); | ||
22 | if(/*cfg.flush() ||*/cfg.m_lastRead < cfg.lastModified()){ | ||
23 | cfg.load(&cfg); | ||
24 | } | ||
25 | return(cfg); | ||
26 | } | ||
27 | |||
28 | #if 0 | ||
29 | bool flush(){ | ||
30 | if(changed){ | ||
31 | write(); | ||
32 | return(true); | ||
33 | } else { | ||
34 | return(false); | ||
35 | } | ||
36 | } | ||
37 | #endif | ||
38 | |||
39 | const QString& getGroup(){ | ||
40 | return(git.key()); | ||
41 | } | ||
42 | |||
43 | void load(ConfigEx* cfg){ | ||
44 | cfg->read(); | ||
45 | cfg->decode(); | ||
46 | cfg->m_lastRead = QDateTime::currentDateTime(); | ||
47 | } | ||
48 | |||
49 | void setConfig(const QString& name){ | ||
50 | if(name == QString::null){ | ||
51 | return; | ||
52 | } | ||
53 | /*flush();*/ | ||
54 | filename = configFilename(name, User); | ||
55 | load(this); | ||
56 | } | ||
57 | |||
58 | void reload() { | ||
59 | /*flush();*/ | ||
60 | load(this); | ||
61 | } | ||
62 | |||
63 | QStringList getKeys(); | ||
64 | QDateTime lastModified(); | ||
65 | QDateTime lastRead(){ | ||
66 | return(m_lastRead); | ||
67 | } | ||
68 | |||
69 | friend class Dummy; /* for compie warning */ | ||
70 | private: | ||
71 | ConfigEx(const QString& name, Domain domain=User); | ||
72 | ConfigEx& operator=(const ConfigEx&); | ||
73 | virtual ~ConfigEx(){changed = false;} | ||
74 | |||
75 | class Dummy{}; /* for compile warning */ | ||
76 | |||
77 | |||
78 | void read(); | ||
79 | void decode(); | ||
80 | //void removeComment(); | ||
81 | |||
82 | QDateTime m_lastRead; | ||
83 | #ifdef CONFIG_MULTICODEC | ||
84 | QString m_charset; | ||
85 | #endif | ||
86 | }; | ||
87 | |||
88 | #endif /* _CONFIG_EX_H_ */ | ||
89 | |||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KHUtil.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KHUtil.cpp new file mode 100644 index 0000000..b7134d9 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KHUtil.cpp | |||
@@ -0,0 +1,90 @@ | |||
1 | #include "KHUtil.h" | ||
2 | #include <qwindowsystem_qws.h> | ||
3 | |||
4 | int KHUtil::hex2int(const QString& hexstr, bool* ok) | ||
5 | { | ||
6 | int val; | ||
7 | bool success; | ||
8 | if(hexstr.find("0x") == 0){ | ||
9 | val = hexstr.mid(2).toInt(&success, 16); | ||
10 | } else { | ||
11 | val = hexstr.toInt(&success, 16); | ||
12 | } | ||
13 | if(!success){ | ||
14 | val = 0; | ||
15 | } | ||
16 | if(ok){ | ||
17 | *ok = success; | ||
18 | } | ||
19 | return(val); | ||
20 | } | ||
21 | |||
22 | const QStringList KHUtil::parseArgs(const QString& arguments) | ||
23 | { | ||
24 | QString str; | ||
25 | QStringList args; | ||
26 | char quote = 0; | ||
27 | char c; | ||
28 | for(unsigned int i=0; i<arguments.length(); i++){ | ||
29 | c = arguments[i]; | ||
30 | switch(c){ | ||
31 | case '\"': | ||
32 | if(quote == 0){ | ||
33 | quote = c; | ||
34 | } else if(quote == '\"'){ | ||
35 | if(str.length() > 0){ | ||
36 | args.append(str); | ||
37 | } | ||
38 | str = ""; | ||
39 | quote = 0; | ||
40 | } else { | ||
41 | str += c; | ||
42 | } | ||
43 | break; | ||
44 | case '\'': | ||
45 | if(quote == 0){ | ||
46 | quote = c; | ||
47 | } else if(quote == '\''){ | ||
48 | if(str.length() > 0){ | ||
49 | args.append(str); | ||
50 | } | ||
51 | str = ""; | ||
52 | quote = 0; | ||
53 | } else { | ||
54 | str += c; | ||
55 | } | ||
56 | break; | ||
57 | case ' ': | ||
58 | if(quote == 0){ | ||
59 | if(str.length() > 0){ | ||
60 | args.append(str); | ||
61 | str = ""; | ||
62 | } | ||
63 | } else { | ||
64 | str += c; | ||
65 | } | ||
66 | break; | ||
67 | default: | ||
68 | str += c; | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | if(str.length() > 0){ | ||
73 | args.append(str); | ||
74 | } | ||
75 | return(args); | ||
76 | } | ||
77 | |||
78 | const QString KHUtil::currentApp() | ||
79 | { | ||
80 | QString app; | ||
81 | const QList<QWSWindow>& list = qwsServer->clientWindows(); | ||
82 | QWSWindow* w; | ||
83 | for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ | ||
84 | if(w->isVisible() && w->client()->identity() != QString::null){ | ||
85 | app = w->client()->identity(); | ||
86 | break; | ||
87 | } | ||
88 | } | ||
89 | return app; | ||
90 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KHUtil.h b/noncore/applets/keyhelper/keyhelperapplet/misc/KHUtil.h new file mode 100644 index 0000000..a92a1b2 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KHUtil.h | |||
@@ -0,0 +1,15 @@ | |||
1 | #ifndef _KHUTIL_H_ | ||
2 | #define _KHUTIL_H_ | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | |||
7 | class KHUtil | ||
8 | { | ||
9 | public: | ||
10 | static int hex2int(const QString& hexstr, bool* ok=NULL); | ||
11 | static const QStringList parseArgs(const QString& arguments); | ||
12 | static const QString currentApp(); | ||
13 | }; | ||
14 | |||
15 | #endif /* _KHUTIL_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.cpp new file mode 100644 index 0000000..f44138c --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.cpp | |||
@@ -0,0 +1,253 @@ | |||
1 | #include "KeyAction.h" | ||
2 | |||
3 | KeyAction::KeyAction() | ||
4 | { | ||
5 | qDebug("KeyAction::KeyAction()"); | ||
6 | enable(); | ||
7 | } | ||
8 | |||
9 | KeyAction::~KeyAction() | ||
10 | { | ||
11 | qDebug("KeyAction::~KeyAction()"); | ||
12 | } | ||
13 | |||
14 | void KeyAction::init() | ||
15 | { | ||
16 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
17 | |||
18 | QString oldgroup = cfg.getGroup(); | ||
19 | cfg.setGroup("Global"); | ||
20 | |||
21 | m_keepToggle = cfg.readBoolEntry("KeepToggle", true); | ||
22 | |||
23 | m_excludeKeys.clear(); | ||
24 | if(cfg.hasKey("ExcludeKeys")){ | ||
25 | QStringList keys = cfg.readListEntry("ExcludeKeys", ','); | ||
26 | for(QStringList::Iterator it=keys.begin(); | ||
27 | it!=keys.end(); ++it){ | ||
28 | int code; | ||
29 | if((*it).find("0x") == 0){ | ||
30 | code = KHUtil::hex2int(*it); | ||
31 | } else { | ||
32 | code = KeyNames::getCode(*it); | ||
33 | } | ||
34 | if(code > 0){ | ||
35 | m_excludeKeys.append(code); | ||
36 | } | ||
37 | } | ||
38 | } else { | ||
39 | m_excludeKeys.append(Qt::Key_F34); | ||
40 | } | ||
41 | |||
42 | m_presscnt = 0; | ||
43 | m_check = true; | ||
44 | m_keep_toggle_code = 0; | ||
45 | m_capture = false; | ||
46 | cfg.setGroup(oldgroup); | ||
47 | } | ||
48 | |||
49 | void KeyAction::setAction(int unicode, int keycode, int modifiers, | ||
50 | bool isPress, bool autoRepeat) | ||
51 | { | ||
52 | m_unicode = unicode; | ||
53 | m_keycode = keycode; | ||
54 | m_modifiers = modifiers; | ||
55 | m_isPress = isPress; | ||
56 | m_autoRepeat = autoRepeat; | ||
57 | } | ||
58 | |||
59 | bool KeyAction::checkState() | ||
60 | { | ||
61 | if(0 < m_unicode && m_unicode < 0xFFFF){ | ||
62 | QChar ch(m_unicode); | ||
63 | QChar::Category category = ch.category(); | ||
64 | if(category == QChar::Letter_Lowercase){ | ||
65 | if(m_modifiers == 0){ | ||
66 | m_pMappings->setCapsLock(false); | ||
67 | return(true); | ||
68 | } else if(m_modifiers == Qt::ShiftButton){ | ||
69 | m_pMappings->setCapsLock(true); | ||
70 | return(true); | ||
71 | } | ||
72 | } else if(category == QChar::Letter_Uppercase){ | ||
73 | if(m_modifiers == 0){ | ||
74 | m_pMappings->setCapsLock(true); | ||
75 | return(true); | ||
76 | } else if(m_modifiers == Qt::ShiftButton){ | ||
77 | m_pMappings->setCapsLock(false); | ||
78 | return(true); | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | return(false); | ||
83 | } | ||
84 | |||
85 | void KeyAction::sendKeyEvent(int unicode, int keycode, int modifiers, | ||
86 | bool isPress, bool autoRepeat) | ||
87 | { | ||
88 | if(m_hookChannel.isEmpty()){ | ||
89 | QWSServer::sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); | ||
90 | } else { | ||
91 | if(QCopChannel::isRegistered(m_hookChannel)){ | ||
92 | QCopEnvelope e(m_hookChannel, "keyEvent(int,int,int,int,int)"); | ||
93 | e << unicode << keycode << modifiers << (int)isPress << (int)autoRepeat; | ||
94 | } else { | ||
95 | m_hookChannel = ""; | ||
96 | QWSServer::sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | bool KeyAction::doAction() | ||
102 | { | ||
103 | if(m_enable == false){ | ||
104 | return(false); | ||
105 | } | ||
106 | #if 0 | ||
107 | if(m_excludeKeys.contains(m_keycode)){ | ||
108 | return(false); | ||
109 | } | ||
110 | #endif | ||
111 | if(!m_autoRepeat){ | ||
112 | qDebug("recv[%x][%x][%x][%d]", | ||
113 | m_unicode, | ||
114 | m_keycode, | ||
115 | m_modifiers, | ||
116 | m_isPress); | ||
117 | } | ||
118 | |||
119 | if(m_autoRepeat && !m_excludeKeys.contains(m_keycode)){ | ||
120 | KeyRepeater::RepeaterMode repMode = m_pRepeater->getMode(); | ||
121 | if(repMode == KeyRepeater::ENABLE | ||
122 | || repMode == KeyRepeater::KILL){ | ||
123 | /* autoRepeat ¤Ï̵»ë */ | ||
124 | return(true); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | if(m_pRepeater->isRepeatable(m_keycode)){ | ||
129 | if(m_isPress){ | ||
130 | m_presscnt++; | ||
131 | } else { | ||
132 | m_presscnt--; | ||
133 | if(m_presscnt <= 0){ | ||
134 | m_pRepeater->stop(); | ||
135 | m_presscnt = 0; | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | if(m_check && m_isPress){ | ||
141 | /* check capslock state */ | ||
142 | if(checkState()){ | ||
143 | m_check = false; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | int unicode, keycode, modifiers; | ||
148 | /* keep toggle reset */ | ||
149 | if(m_keepToggle && m_keep_toggle_code != 0){ | ||
150 | if(m_keep_toggle_code != m_keycode){ | ||
151 | m_pModifiers->resetToggles(); | ||
152 | m_keep_toggle_code = 0; | ||
153 | } else { | ||
154 | m_pModifiers->keepToggles(); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | /* modifier ¾õÂÖ¼èÆÀ */ | ||
159 | int keymask = m_pModifiers->getState(m_modifiers); | ||
160 | modifiers = m_pModifiers->getModifiers(m_modifiers); | ||
161 | |||
162 | bool isModMapped = false; | ||
163 | /* modifier ¾õÂÖ¹¹¿· */ | ||
164 | if(m_autoRepeat == false){ | ||
165 | if(m_isPress){ | ||
166 | isModMapped = m_pModifiers->pressKey(m_keycode, m_modifiers); | ||
167 | } else { | ||
168 | m_pModifiers->releaseKey(m_keycode); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | if(m_capture && m_isPress && m_autoRepeat == false){ | ||
173 | QCopEnvelope e("QPE/KeyHelperConf", "event(int,int,int)"); | ||
174 | e << m_keycode << m_unicode << modifiers; | ||
175 | } | ||
176 | |||
177 | /* keyextension ŬÍÑ */ | ||
178 | bool fKeyCancel = m_pExtensions->doKey(m_keycode, keymask, m_isPress); | ||
179 | if(fKeyCancel){ | ||
180 | if(m_keepToggle){ | ||
181 | m_keep_toggle_code = m_keycode; | ||
182 | } else { | ||
183 | m_pModifiers->resetToggles(); | ||
184 | } | ||
185 | m_pRepeater->stop(); | ||
186 | return(true); | ||
187 | } | ||
188 | |||
189 | /* keymapping ŬÍÑ */ | ||
190 | #if 0 | ||
191 | bool isMapped = m_pMappings->apply(m_keycode, keymask, m_isPress); | ||
192 | if(isMapped == false){ | ||
193 | if(m_pMappings->isDefined()){ | ||
194 | m_pMappings->setOriginal(m_unicode, m_modifiers); | ||
195 | } else { | ||
196 | m_pMappings->setUnicode(m_unicode); | ||
197 | //m_pMappings->setKeycode(m_keycode); | ||
198 | } | ||
199 | //return(false); | ||
200 | } | ||
201 | #else | ||
202 | bool isMapped = m_pMappings->apply(m_unicode, m_keycode, m_modifiers, | ||
203 | keymask, m_isPress); | ||
204 | #endif | ||
205 | |||
206 | /* modifier ŬÍÑ */ | ||
207 | m_pMappings->setModifiers(modifiers); | ||
208 | |||
209 | keycode = m_pMappings->getKeycode(); | ||
210 | if(keycode <= 0){ | ||
211 | return(true); | ||
212 | } | ||
213 | |||
214 | if(/*m_autoRepeat == false &&*/ m_isPress){ | ||
215 | if(isModMapped == false || (isModMapped && isMapped)){ | ||
216 | if(m_pModifiers->isModifier(keycode) == false){ | ||
217 | m_pModifiers->resetToggles(); | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | unicode = m_pMappings->getUnicode(); | ||
222 | modifiers = m_pMappings->getModifiers(); | ||
223 | if(keycode > 0){ | ||
224 | /* disable mapping */ | ||
225 | if(m_excludeKeys.contains(keycode)){ | ||
226 | return(false); | ||
227 | } | ||
228 | /* send key event */ | ||
229 | sendKeyEvent( | ||
230 | unicode, | ||
231 | keycode, | ||
232 | modifiers, | ||
233 | m_isPress, | ||
234 | m_autoRepeat); | ||
235 | } | ||
236 | if(m_isPress){ | ||
237 | /* repeater start */ | ||
238 | m_pRepeater->start(unicode, keycode, modifiers); | ||
239 | #if 0 | ||
240 | } else if(m_presscnt <= 0){ | ||
241 | m_presscnt = 0; | ||
242 | m_pRepeater->stop(); | ||
243 | #endif | ||
244 | } else { | ||
245 | m_pRepeater->stop(keycode); | ||
246 | } | ||
247 | qWarning("send[%x][%x][%x][%d]", | ||
248 | m_pMappings->getUnicode(), | ||
249 | m_pMappings->getKeycode(), | ||
250 | m_pMappings->getModifiers(), | ||
251 | m_isPress); | ||
252 | return(true); | ||
253 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.h b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.h new file mode 100644 index 0000000..4eb5eb6 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.h | |||
@@ -0,0 +1,87 @@ | |||
1 | #ifndef _KEY_ACTION_H_ | ||
2 | #define _KEY_ACTION_H_ | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qwindowsystem_qws.h> | ||
6 | #include <qtimer.h> | ||
7 | #include <qpe/power.h> | ||
8 | #include "KeyMappings.h" | ||
9 | #include "KeyModifiers.h" | ||
10 | #include "KeyExtensions.h" | ||
11 | #include "KeyRepeater.h" | ||
12 | #include "ConfigEx.h" | ||
13 | |||
14 | class KeyAction : public QObject | ||
15 | { | ||
16 | Q_OBJECT | ||
17 | public: | ||
18 | KeyAction(); | ||
19 | virtual ~KeyAction(); | ||
20 | |||
21 | void setKeyMappings(KeyMappings* map) | ||
22 | { | ||
23 | m_pMappings = map; | ||
24 | } | ||
25 | void setKeyModifiers(KeyModifiers* mod) | ||
26 | { | ||
27 | m_pModifiers = mod; | ||
28 | } | ||
29 | void setKeyExtensions(KeyExtensions* ext) | ||
30 | { | ||
31 | m_pExtensions = ext; | ||
32 | } | ||
33 | void setKeyRepeater(KeyRepeater* rep) | ||
34 | { | ||
35 | m_pRepeater = rep; | ||
36 | connect(m_pRepeater, SIGNAL(keyEvent(int,int,int,bool,bool)), | ||
37 | this, SLOT(sendKeyEvent(int,int,int,bool,bool))); | ||
38 | } | ||
39 | void setAction(int unicode, int keycode, int modifiers, | ||
40 | bool isPress, bool autoRepeat); | ||
41 | bool doAction(); | ||
42 | |||
43 | void enable(){ | ||
44 | init(); | ||
45 | m_enable = true; | ||
46 | }; | ||
47 | void disable(){ | ||
48 | m_enable = false; | ||
49 | }; | ||
50 | void setCapture(bool enable){ | ||
51 | m_capture = enable; | ||
52 | } | ||
53 | |||
54 | void setHook(const QCString& s){ | ||
55 | m_hookChannel = s; | ||
56 | } | ||
57 | private: | ||
58 | int m_unicode; | ||
59 | int m_keycode; | ||
60 | int m_modifiers; | ||
61 | bool m_isPress; | ||
62 | bool m_autoRepeat; | ||
63 | |||
64 | bool m_capture; | ||
65 | bool m_enable; | ||
66 | int m_presscnt; | ||
67 | |||
68 | int m_keep_toggle_code; | ||
69 | bool m_keepToggle; | ||
70 | bool m_check; | ||
71 | QValueList<int> m_excludeKeys; | ||
72 | |||
73 | QCString m_hookChannel; | ||
74 | |||
75 | KeyMappings* m_pMappings; | ||
76 | KeyModifiers* m_pModifiers; | ||
77 | KeyExtensions* m_pExtensions; | ||
78 | KeyRepeater* m_pRepeater; | ||
79 | |||
80 | void init(); | ||
81 | bool checkState(); | ||
82 | private slots: | ||
83 | void sendKeyEvent(int unicode, int keycode, int modifiers, | ||
84 | bool isPress, bool autoRepeat); | ||
85 | }; | ||
86 | |||
87 | #endif /* _KEY_ACTION_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyMappings.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyMappings.cpp new file mode 100644 index 0000000..0151d39 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyMappings.cpp | |||
@@ -0,0 +1,340 @@ | |||
1 | #include "KeyMappings.h" | ||
2 | |||
3 | static QIntDict<QWSServer::KeyMap> g_mapCache(127); | ||
4 | |||
5 | MapInfo::MapInfo(int code, int mod, int uni, | ||
6 | int shift_uni, int ctrl_uni) | ||
7 | { | ||
8 | const QWSServer::KeyMap* map; | ||
9 | if(uni == 0 || shift_uni == 0 || ctrl_uni == 0){ | ||
10 | map = MapInfo::findKeyMap(code); | ||
11 | if(map != NULL){ | ||
12 | isDefined = true; | ||
13 | unicode = map->unicode; | ||
14 | shift_unicode = map->shift_unicode; | ||
15 | ctrl_unicode = map->ctrl_unicode; | ||
16 | } else { | ||
17 | isDefined = false; | ||
18 | unicode = 0; | ||
19 | shift_unicode = 0; | ||
20 | ctrl_unicode = 0; | ||
21 | } | ||
22 | } else { | ||
23 | isDefined = true; | ||
24 | } | ||
25 | keycode = code; | ||
26 | modifiers = mod; | ||
27 | if(uni != 0){ | ||
28 | unicode = uni; | ||
29 | } | ||
30 | if(shift_uni != 0){ | ||
31 | shift_unicode = shift_uni; | ||
32 | } | ||
33 | if(ctrl_uni != 0){ | ||
34 | ctrl_unicode = ctrl_uni; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | const QWSServer::KeyMap* MapInfo::findKeyMap(int keycode) | ||
39 | { | ||
40 | const QWSServer::KeyMap* m = QWSServer::keyMap(); | ||
41 | |||
42 | while(m->key_code != 0){ | ||
43 | if(m->key_code == keycode){ | ||
44 | return(m); | ||
45 | } | ||
46 | m++; | ||
47 | } | ||
48 | return(NULL); | ||
49 | } | ||
50 | |||
51 | KeyMappings::KeyMappings() | ||
52 | { | ||
53 | qDebug("KeyMappings::KeyMappings()"); | ||
54 | init(); | ||
55 | } | ||
56 | |||
57 | KeyMappings::~KeyMappings() | ||
58 | { | ||
59 | qDebug("KeyMappings::~KeyMappings()"); | ||
60 | clear(); | ||
61 | } | ||
62 | |||
63 | void KeyMappings::init() | ||
64 | { | ||
65 | m_capslock = false; | ||
66 | } | ||
67 | |||
68 | void KeyMappings::reset() | ||
69 | { | ||
70 | clear(); | ||
71 | } | ||
72 | |||
73 | void KeyMappings::clear() | ||
74 | { | ||
75 | for(QMap<int, CodeMaps*>::Iterator it = m_keymaps.begin(); | ||
76 | it!=m_keymaps.end(); ++it){ | ||
77 | delete (*it); | ||
78 | } | ||
79 | m_keymaps.clear(); | ||
80 | g_mapCache.setAutoDelete(true); | ||
81 | g_mapCache.clear(); | ||
82 | } | ||
83 | |||
84 | void KeyMappings::assign(int keycode, int keymask, int mapcode, | ||
85 | int mapmodifiers, int unicode, int shift_unicode, int ctrl_unicode) | ||
86 | { | ||
87 | CodeMaps* map; | ||
88 | if(m_keymaps.contains(keycode)){ | ||
89 | map = m_keymaps[keycode]; | ||
90 | } else { | ||
91 | map = new CodeMaps(); | ||
92 | m_keymaps.insert(keycode, map); | ||
93 | } | ||
94 | |||
95 | MapInfo info(mapcode, mapmodifiers, unicode, shift_unicode, ctrl_unicode); | ||
96 | m_it = map->insert(keymask, info); | ||
97 | } | ||
98 | |||
99 | void KeyMappings::assignModifier(const QString& type, const QString& state) | ||
100 | { | ||
101 | int maskbit = 0; | ||
102 | QString str; | ||
103 | str = type.lower(); | ||
104 | if(str == "shift"){ | ||
105 | maskbit = Qt::ShiftButton; | ||
106 | } else if(str == "control"){ | ||
107 | maskbit = Qt::ControlButton; | ||
108 | } else if(str == "alt"){ | ||
109 | maskbit = Qt::AltButton; | ||
110 | } | ||
111 | str = state.lower(); | ||
112 | if(str == "off"){ | ||
113 | maskbit = (maskbit << 16) & 0xFFFF0000; | ||
114 | } | ||
115 | (*m_it).modifiers |= maskbit; | ||
116 | } | ||
117 | |||
118 | void KeyMappings::assignUnicode(const QString& kind, const QString& ch) | ||
119 | { | ||
120 | QString str; | ||
121 | int code = ch[0].unicode(); | ||
122 | str = kind.lower(); | ||
123 | if(str == "unicode"){ | ||
124 | (*m_it).unicode = code; | ||
125 | } else if(str == "shift_unicode"){ | ||
126 | (*m_it).shift_unicode = code; | ||
127 | } else if(str == "ctrl_unicode"){ | ||
128 | (*m_it).ctrl_unicode = code; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | void KeyMappings::assignUnicode(int unicode) | ||
133 | { | ||
134 | (*m_it).unicode = (*m_it).shift_unicode = | ||
135 | (*m_it).ctrl_unicode = unicode; | ||
136 | } | ||
137 | |||
138 | void KeyMappings::statistics() | ||
139 | { | ||
140 | qWarning("KeyMappings::statistics()"); | ||
141 | for(QMap<int, CodeMaps*>::Iterator it=m_keymaps.begin(); | ||
142 | it!=m_keymaps.end(); ++it){ | ||
143 | qWarning(" code = %x", it.key()); | ||
144 | for(QMap<int, MapInfo>::Iterator it2=(*it)->begin(); | ||
145 | it2!=(*it)->end(); ++it2){ | ||
146 | qDebug(" [%x]-[%x][%x][%x][%x][%x]", it2.key(), | ||
147 | (*it2).keycode, | ||
148 | (*it2).modifiers, | ||
149 | (*it2).unicode, | ||
150 | (*it2).shift_unicode, | ||
151 | (*it2).ctrl_unicode); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | bool KeyMappings::apply(int unicode, int keycode, int modifiers, | ||
157 | int keymask, bool isPress) | ||
158 | { | ||
159 | CodeMaps* map; | ||
160 | m_isMapped = false; | ||
161 | |||
162 | if(m_keymaps.contains(keycode)){ | ||
163 | map = m_keymaps[keycode]; | ||
164 | if(map->contains(keymask)){ | ||
165 | m_isMapped = true; | ||
166 | m_keyinfo = (*map)[keymask]; | ||
167 | } else { | ||
168 | int mask = -1; | ||
169 | for(CodeMaps::Iterator it=map->begin(); | ||
170 | it!=map->end(); ++it){ | ||
171 | if((keymask & it.key()) == it.key() | ||
172 | && it.key() > mask){ | ||
173 | mask = it.key(); | ||
174 | } | ||
175 | } | ||
176 | if(mask != -1){ | ||
177 | m_isMapped = true; | ||
178 | m_keyinfo = (*map)[mask]; | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | |||
183 | if(m_isMapped == false){ | ||
184 | QWSServer::KeyMap* cache = g_mapCache[keycode]; | ||
185 | if(cache == NULL){ | ||
186 | cache = new QWSServer::KeyMap(); | ||
187 | g_mapCache.insert(keycode, cache); | ||
188 | cache->unicode = cache->shift_unicode = cache->ctrl_unicode = 0; | ||
189 | } | ||
190 | if(cache->unicode == 0 || cache->shift_unicode == 0 || cache->ctrl_unicode == 0){ | ||
191 | QChar ch(unicode); | ||
192 | if(modifiers & Qt::ControlButton){ | ||
193 | cache->ctrl_unicode = unicode; | ||
194 | } else if(modifiers & Qt::ShiftButton){ | ||
195 | cache->shift_unicode = ch.upper().unicode(); | ||
196 | } else { | ||
197 | cache->unicode = ch.lower().unicode(); | ||
198 | } | ||
199 | } | ||
200 | m_keyinfo = MapInfo(keycode, 0, | ||
201 | cache->unicode, cache->shift_unicode, cache->ctrl_unicode); | ||
202 | if(m_keyinfo.isDefined){ | ||
203 | setOriginal(unicode, modifiers); | ||
204 | } else { | ||
205 | setUnicode(unicode); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | #if 1 | ||
210 | if(isPress){ | ||
211 | if(m_keyinfo.keycode == Qt::Key_CapsLock){ | ||
212 | m_capslock = !m_capslock; | ||
213 | } | ||
214 | } | ||
215 | #endif | ||
216 | return(m_isMapped); | ||
217 | } | ||
218 | |||
219 | bool KeyMappings::apply(int keycode, int keymask, bool isPress) | ||
220 | { | ||
221 | CodeMaps* map; | ||
222 | m_isMapped = false; | ||
223 | |||
224 | if(m_keymaps.contains(keycode)){ | ||
225 | map = m_keymaps[keycode]; | ||
226 | if(map->contains(keymask)){ | ||
227 | m_isMapped = true; | ||
228 | m_keyinfo = (*map)[keymask]; | ||
229 | } else { | ||
230 | int mask = -1; | ||
231 | for(CodeMaps::Iterator it=map->begin(); | ||
232 | it!=map->end(); ++it){ | ||
233 | if((keymask & it.key()) == it.key() | ||
234 | && it.key() > mask){ | ||
235 | mask = it.key(); | ||
236 | } | ||
237 | } | ||
238 | if(mask != -1){ | ||
239 | m_isMapped = true; | ||
240 | m_keyinfo = (*map)[mask]; | ||
241 | } | ||
242 | } | ||
243 | } | ||
244 | if(m_isMapped == false){ | ||
245 | m_keyinfo = MapInfo(keycode); | ||
246 | } | ||
247 | #if 1 | ||
248 | if(isPress){ | ||
249 | if(m_keyinfo.keycode == Qt::Key_CapsLock){ | ||
250 | m_capslock = !m_capslock; | ||
251 | } | ||
252 | } | ||
253 | #endif | ||
254 | return(m_isMapped); | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * set original unicode | ||
259 | */ | ||
260 | void KeyMappings::setOriginal(int unicode, int modifiers) | ||
261 | { | ||
262 | if(modifiers & Qt::ControlButton){ | ||
263 | m_keyinfo.ctrl_unicode = unicode; | ||
264 | } else if(modifiers & Qt::ShiftButton){ | ||
265 | m_keyinfo.shift_unicode = unicode; | ||
266 | } else { | ||
267 | m_keyinfo.unicode = unicode; | ||
268 | } | ||
269 | } | ||
270 | |||
271 | void KeyMappings::setModifiers(int modifiers) | ||
272 | { | ||
273 | m_modifiers = modifiers; | ||
274 | m_modifiers |= (m_keyinfo.modifiers & 0xFFFF); | ||
275 | m_modifiers &= ~((m_keyinfo.modifiers >> 16) & 0xFFFF); | ||
276 | } | ||
277 | |||
278 | void KeyMappings::setUnicode(int unicode) | ||
279 | { | ||
280 | m_keyinfo.unicode = unicode; | ||
281 | m_keyinfo.shift_unicode = unicode; | ||
282 | m_keyinfo.ctrl_unicode = unicode; | ||
283 | } | ||
284 | |||
285 | void KeyMappings::setKeycode(int keycode) | ||
286 | { | ||
287 | m_keyinfo.keycode = keycode; | ||
288 | } | ||
289 | |||
290 | int KeyMappings::getUnicode() | ||
291 | { | ||
292 | int unicode; | ||
293 | if(m_modifiers & Qt::ControlButton){ | ||
294 | unicode = m_keyinfo.ctrl_unicode; | ||
295 | } else if(m_modifiers & Qt::ShiftButton){ | ||
296 | unicode = m_keyinfo.shift_unicode; | ||
297 | QChar ch(unicode); | ||
298 | if(m_capslock){ | ||
299 | unicode = ch.lower().unicode(); | ||
300 | } else { | ||
301 | unicode = ch.upper().unicode(); | ||
302 | } | ||
303 | } else { | ||
304 | unicode = m_keyinfo.unicode; | ||
305 | QChar ch(unicode); | ||
306 | if(m_capslock){ | ||
307 | unicode = ch.upper().unicode(); | ||
308 | } else { | ||
309 | unicode = ch.lower().unicode(); | ||
310 | } | ||
311 | } | ||
312 | qDebug("UNICODE[%d][%x][%x]", m_capslock, unicode, m_keyinfo.unicode); | ||
313 | #if 0 | ||
314 | if(m_isMapped && m_capslock){ | ||
315 | QChar ch(unicode); | ||
316 | QChar::Category category = ch.category(); | ||
317 | if(category == QChar::Letter_Uppercase){ | ||
318 | unicode = ch.lower().unicode(); | ||
319 | } else if(category == QChar::Letter_Lowercase){ | ||
320 | unicode = ch.upper().unicode(); | ||
321 | } | ||
322 | } | ||
323 | #endif | ||
324 | return(unicode); | ||
325 | } | ||
326 | |||
327 | int KeyMappings::getKeycode() | ||
328 | { | ||
329 | return(m_keyinfo.keycode); | ||
330 | } | ||
331 | |||
332 | int KeyMappings::getModifiers() | ||
333 | { | ||
334 | return(m_modifiers); | ||
335 | } | ||
336 | |||
337 | bool KeyMappings::isDefined() | ||
338 | { | ||
339 | return(m_keyinfo.isDefined); | ||
340 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyMappings.h b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyMappings.h new file mode 100644 index 0000000..9705c8c --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyMappings.h | |||
@@ -0,0 +1,72 @@ | |||
1 | #ifndef _KEY_MAPPINGS_H_ | ||
2 | #define _KEY_MAPPINGS_H_ | ||
3 | |||
4 | #include <qwindowsystem_qws.h> | ||
5 | #include <qmap.h> | ||
6 | |||
7 | #include <qintdict.h> | ||
8 | |||
9 | class MapInfo | ||
10 | { | ||
11 | public: | ||
12 | MapInfo(){}; | ||
13 | MapInfo(int code, int mod = 0, int uni = 0, | ||
14 | int shift_uni = 0, int ctrl_uni = 0); | ||
15 | |||
16 | static const QWSServer::KeyMap* findKeyMap(int code); | ||
17 | |||
18 | int keycode; | ||
19 | int modifiers; | ||
20 | int unicode; | ||
21 | int shift_unicode; | ||
22 | int ctrl_unicode; | ||
23 | bool isDefined; | ||
24 | }; | ||
25 | |||
26 | class KeyMappings | ||
27 | { | ||
28 | public: | ||
29 | typedef QWSServer::KeyMap KeyMap; | ||
30 | typedef QMap<int, MapInfo> CodeMaps; | ||
31 | |||
32 | KeyMappings(); | ||
33 | virtual ~KeyMappings(); | ||
34 | |||
35 | void setOriginal(int unicode, int modifiers); | ||
36 | void setModifiers(int modifiers); | ||
37 | void setUnicode(int unicode); | ||
38 | void setKeycode(int keycode); | ||
39 | |||
40 | int getUnicode(); | ||
41 | int getKeycode(); | ||
42 | int getModifiers(); | ||
43 | bool isDefined(); | ||
44 | |||
45 | void assign(int keycode, int keymask, int mapcode, int mapmodifiers = 0, | ||
46 | int unicode = 0, int shift_unicode = 0, int ctrl_unicode = 0); | ||
47 | void assignModifier(const QString& type, const QString& state); | ||
48 | void assignUnicode(const QString& kind, const QString& ch); | ||
49 | void assignUnicode(int unicode); | ||
50 | bool apply(int unicode, int keycode, int modifiers, int keymask, bool isPress); | ||
51 | bool apply(int keycode, int keymask, bool isPress); | ||
52 | void setCapsLock(bool on=true){ | ||
53 | m_capslock = on; | ||
54 | } | ||
55 | |||
56 | void reset(); | ||
57 | |||
58 | void statistics(); | ||
59 | private: | ||
60 | QMap<int, CodeMaps*> m_keymaps; | ||
61 | MapInfo m_keyinfo; | ||
62 | int m_modifiers; | ||
63 | CodeMaps::Iterator m_it; | ||
64 | |||
65 | bool m_capslock; | ||
66 | bool m_isMapped; | ||
67 | |||
68 | void init(); | ||
69 | void clear(); | ||
70 | }; | ||
71 | |||
72 | #endif /* _KEY_MAPPINGS_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyModifiers.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyModifiers.cpp new file mode 100644 index 0000000..4699b11 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyModifiers.cpp | |||
@@ -0,0 +1,285 @@ | |||
1 | #include "KeyModifiers.h" | ||
2 | |||
3 | KeyModifiers::KeyModifiers() | ||
4 | { | ||
5 | qDebug("KeyModifiers::KeyModifiers()"); | ||
6 | m_pTimer = new QTimer(this); | ||
7 | connect(m_pTimer, SIGNAL(timeout()), | ||
8 | this, SLOT(resetToggles())); | ||
9 | init(); | ||
10 | } | ||
11 | |||
12 | KeyModifiers::~KeyModifiers() | ||
13 | { | ||
14 | qDebug("KeyModifiers::~KeyModifiers()"); | ||
15 | delete m_pTimer; | ||
16 | clear(); | ||
17 | } | ||
18 | |||
19 | void KeyModifiers::addType(const QString& type) | ||
20 | { | ||
21 | if(m_types.contains(type) == false){ | ||
22 | qDebug("addType[%s][%x]", type.latin1(), m_bitmask); | ||
23 | m_types.insert(type, m_bitmask); | ||
24 | m_bitmask = m_bitmask << 1; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | ModifierInfo* KeyModifiers::assign(const QString& type, int keycode, | ||
29 | int keymask, bool mode) | ||
30 | { | ||
31 | m_info = new ModifierInfo(type, keycode, keymask, mode); | ||
32 | addType(type); | ||
33 | m_modifiers.append(m_info); | ||
34 | if(mode){ | ||
35 | m_togglekeys.append(m_info); | ||
36 | } | ||
37 | assignRelease(m_info, keycode); | ||
38 | return(m_info); | ||
39 | } | ||
40 | |||
41 | void KeyModifiers::assignRelease(int keycode) | ||
42 | { | ||
43 | assignRelease(m_info, keycode); | ||
44 | } | ||
45 | |||
46 | void KeyModifiers::assignRelease(ModifierInfo* info, int keycode) | ||
47 | { | ||
48 | if(m_releasekeys.contains(keycode) == false){ | ||
49 | m_releasekeys.insert(keycode, new ModifierList); | ||
50 | } | ||
51 | m_releasekeys[keycode]->append(info); | ||
52 | } | ||
53 | |||
54 | void KeyModifiers::setToggle() | ||
55 | { | ||
56 | setToggle(m_info); | ||
57 | } | ||
58 | |||
59 | void KeyModifiers::setToggle(ModifierInfo* info) | ||
60 | { | ||
61 | info->toggle_mode = true; | ||
62 | m_togglekeys.append(info); | ||
63 | } | ||
64 | |||
65 | void KeyModifiers::keepToggles() | ||
66 | { | ||
67 | if(m_timeout > 0){ | ||
68 | m_pTimer->start(m_timeout, true); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | bool KeyModifiers::pressKey(int keycode, int modifiers) | ||
73 | { | ||
74 | int keymask; | ||
75 | |||
76 | keymask = getState(modifiers, true); | ||
77 | |||
78 | for(ModifierList::Iterator it=m_modifiers.begin(); | ||
79 | it!=m_modifiers.end(); ++it){ | ||
80 | if((*it)->keycode == keycode | ||
81 | && ((*it)->keymask & keymask) == (*it)->keymask){ | ||
82 | (*it)->pressed = true; | ||
83 | if((*it)->toggle_mode){ | ||
84 | /* change toggle state */ | ||
85 | (*it)->toggled = !((*it)->toggled); | ||
86 | if((*it)->toggled){ | ||
87 | keepToggles(); | ||
88 | } else { | ||
89 | m_pTimer->stop(); | ||
90 | } | ||
91 | } | ||
92 | return(true); | ||
93 | } | ||
94 | } | ||
95 | return(false); | ||
96 | } | ||
97 | |||
98 | bool KeyModifiers::isModifier(int keycode) | ||
99 | { | ||
100 | if(keycode == Qt::Key_Shift | ||
101 | || keycode == Qt::Key_Control | ||
102 | || keycode == Qt::Key_Alt | ||
103 | || keycode == Qt::Key_Meta | ||
104 | || keycode == Qt::Key_F22){ | ||
105 | return(true); | ||
106 | } else { | ||
107 | return(false); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | void KeyModifiers::releaseKey(int keycode) | ||
112 | { | ||
113 | if(m_releasekeys.contains(keycode)){ | ||
114 | ModifierList* list = m_releasekeys[keycode]; | ||
115 | for(ModifierList::Iterator it=(*list).begin(); | ||
116 | it!=(*list).end(); ++it){ | ||
117 | (*it)->pressed = false; | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | |||
122 | int KeyModifiers::getState() | ||
123 | { | ||
124 | int state = 0; | ||
125 | for(ModifierList::Iterator it=m_modifiers.begin(); | ||
126 | it!=m_modifiers.end(); ++it){ | ||
127 | if((*it)->pressed || (*it)->toggled){ | ||
128 | state |= m_types[(*it)->type]; | ||
129 | } | ||
130 | } | ||
131 | return(state); | ||
132 | } | ||
133 | |||
134 | int KeyModifiers::getState(int modifiers, bool reset) | ||
135 | { | ||
136 | int state = getState(); | ||
137 | int mask; | ||
138 | |||
139 | mask = getMask("Shift"); | ||
140 | if(modifiers & Qt::ShiftButton){ | ||
141 | state |= mask; | ||
142 | } else { | ||
143 | if(reset){ | ||
144 | state &= ~mask; | ||
145 | } | ||
146 | } | ||
147 | mask = getMask("Control"); | ||
148 | if(modifiers & Qt::ControlButton){ | ||
149 | state |= mask; | ||
150 | } else { | ||
151 | if(reset){ | ||
152 | state &= ~mask; | ||
153 | } | ||
154 | } | ||
155 | mask = getMask("Alt"); | ||
156 | if(modifiers & Qt::AltButton){ | ||
157 | state |= mask; | ||
158 | } else { | ||
159 | if(reset){ | ||
160 | state &= ~mask; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | return(state); | ||
165 | } | ||
166 | |||
167 | int KeyModifiers::getModifiers(int modifiers) | ||
168 | { | ||
169 | int state = getState(); | ||
170 | |||
171 | if(state & getMask("Shift")){ | ||
172 | modifiers |= Qt::ShiftButton; | ||
173 | } | ||
174 | if(state & getMask("Control")){ | ||
175 | modifiers |= Qt::ControlButton; | ||
176 | } | ||
177 | if(state & getMask("Alt")){ | ||
178 | modifiers |= Qt::AltButton; | ||
179 | } | ||
180 | |||
181 | return(modifiers); | ||
182 | } | ||
183 | |||
184 | int KeyModifiers::getMask(const QString& type) | ||
185 | { | ||
186 | if(m_types.contains(type)){ | ||
187 | return(m_types[type]); | ||
188 | } else { | ||
189 | return(0); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | void KeyModifiers::clear() | ||
194 | { | ||
195 | m_types.clear(); | ||
196 | |||
197 | m_togglekeys.clear(); | ||
198 | |||
199 | for(ModifierList::Iterator it=m_modifiers.begin(); | ||
200 | it!=m_modifiers.end(); ++it){ | ||
201 | delete *it; | ||
202 | } | ||
203 | m_modifiers.clear(); | ||
204 | |||
205 | for(QMap<int, ModifierList*>::Iterator it=m_releasekeys.begin(); | ||
206 | it!=m_releasekeys.end(); ++it){ | ||
207 | delete *it; | ||
208 | } | ||
209 | m_releasekeys.clear(); | ||
210 | } | ||
211 | |||
212 | void KeyModifiers::init() | ||
213 | { | ||
214 | m_bitmask = 0x00000001; | ||
215 | addType("Shift"); | ||
216 | addType("Control"); | ||
217 | addType("Alt"); | ||
218 | |||
219 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
220 | |||
221 | cfg.setGroup("Global"); | ||
222 | |||
223 | QString timeout = cfg.readEntry("ToggleTimeout", "10"); | ||
224 | int msec = timeout.toInt(); | ||
225 | msec *= 1000; /* sec to msec */ | ||
226 | m_timeout = msec; | ||
227 | } | ||
228 | |||
229 | void KeyModifiers::reset() | ||
230 | { | ||
231 | clear(); | ||
232 | init(); | ||
233 | } | ||
234 | |||
235 | bool KeyModifiers::isToggled() | ||
236 | { | ||
237 | for(ModifierList::Iterator it=m_togglekeys.begin(); | ||
238 | it!=m_togglekeys.end(); ++it){ | ||
239 | if((*it)->toggled){ | ||
240 | return(true); | ||
241 | } | ||
242 | } | ||
243 | return(false); | ||
244 | } | ||
245 | |||
246 | void KeyModifiers::resetToggles() | ||
247 | { | ||
248 | for(ModifierList::Iterator it=m_togglekeys.begin(); | ||
249 | it!=m_togglekeys.end(); ++it){ | ||
250 | (*it)->toggled = false; | ||
251 | } | ||
252 | m_pTimer->stop(); | ||
253 | } | ||
254 | |||
255 | void KeyModifiers::resetStates() | ||
256 | { | ||
257 | for(ModifierList::Iterator it=m_modifiers.begin(); | ||
258 | it!=m_modifiers.end(); ++it){ | ||
259 | (*it)->pressed = false; | ||
260 | } | ||
261 | resetToggles(); | ||
262 | } | ||
263 | |||
264 | void KeyModifiers::statistics() | ||
265 | { | ||
266 | qWarning("KeyModifiers::statistics()"); | ||
267 | for(ModifierList::Iterator it=m_modifiers.begin(); | ||
268 | it!=m_modifiers.end(); ++it){ | ||
269 | qWarning(" [%s][%x][%x][%d][%d]", | ||
270 | (*it)->type.latin1(), | ||
271 | (*it)->keycode, | ||
272 | (*it)->keymask, | ||
273 | (*it)->pressed, | ||
274 | (*it)->toggled); | ||
275 | for(QMap<int, ModifierList*>::Iterator it2=m_releasekeys.begin(); | ||
276 | it2!=m_releasekeys.end(); ++it2){ | ||
277 | for(ModifierList::Iterator it3=(*it2)->begin(); | ||
278 | it3!=(*it2)->end(); ++it3){ | ||
279 | if(*it == *it3){ | ||
280 | qWarning(" release[%x]", it2.key()); | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyModifiers.h b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyModifiers.h new file mode 100644 index 0000000..a99c181 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyModifiers.h | |||
@@ -0,0 +1,80 @@ | |||
1 | #ifndef _KEY_MODIFIERS_H_ | ||
2 | #define _KEY_MODIFIERS_H_ | ||
3 | |||
4 | #include <qmap.h> | ||
5 | #include <qtimer.h> | ||
6 | #include <qvaluelist.h> | ||
7 | #include <qnamespace.h> | ||
8 | |||
9 | #include <qpe/config.h> | ||
10 | #include "ConfigEx.h" | ||
11 | |||
12 | struct ModifierInfo { | ||
13 | public: | ||
14 | ModifierInfo(const QString& tp, int code, int mask, bool mode) | ||
15 | { | ||
16 | type = tp; | ||
17 | keycode = code; | ||
18 | keymask = mask; | ||
19 | pressed = false; | ||
20 | toggled = false; | ||
21 | toggle_mode = mode; | ||
22 | } | ||
23 | QString type; | ||
24 | int keycode; | ||
25 | int keymask; | ||
26 | bool pressed; | ||
27 | bool toggled; | ||
28 | bool toggle_mode; | ||
29 | private: | ||
30 | } ; | ||
31 | |||
32 | class KeyModifiers : public QObject | ||
33 | { | ||
34 | Q_OBJECT | ||
35 | public: | ||
36 | typedef QValueList<ModifierInfo*> ModifierList; | ||
37 | |||
38 | KeyModifiers(); | ||
39 | virtual ~KeyModifiers(); | ||
40 | void addType(const QString& type); | ||
41 | ModifierInfo* assign(const QString& type, int keycode, | ||
42 | int keymask = 0, bool toggle = false); | ||
43 | void assignRelease(int keycode); | ||
44 | void assignRelease(ModifierInfo* info, int keycode); | ||
45 | void setToggle(); | ||
46 | void setToggle(ModifierInfo* info); | ||
47 | |||
48 | bool isToggled(); | ||
49 | void resetStates(); | ||
50 | void keepToggles(); | ||
51 | |||
52 | bool pressKey(int keycode, int modifiers); | ||
53 | void releaseKey(int keycode); | ||
54 | int getState(); | ||
55 | int getState(int modifiers, bool reset = false); | ||
56 | int getMask(const QString& type); | ||
57 | int getModifiers(int modifiers); | ||
58 | |||
59 | bool isModifier(int keycode); | ||
60 | |||
61 | void statistics(); | ||
62 | |||
63 | void reset(); | ||
64 | public slots: | ||
65 | void resetToggles(); | ||
66 | private: | ||
67 | QMap<QString, int> m_types; | ||
68 | int m_bitmask; | ||
69 | ModifierList m_modifiers; | ||
70 | QMap<int, ModifierList*> m_releasekeys; | ||
71 | ModifierList m_togglekeys; | ||
72 | ModifierInfo* m_info; | ||
73 | QTimer* m_pTimer; | ||
74 | int m_timeout; | ||
75 | |||
76 | void clear(); | ||
77 | void init(); | ||
78 | }; | ||
79 | |||
80 | #endif /* _KEY_MODIFIERS_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyNames.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyNames.cpp new file mode 100644 index 0000000..2def857 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyNames.cpp | |||
@@ -0,0 +1,303 @@ | |||
1 | #include "KeyNames.h" | ||
2 | |||
3 | QMap<QString, int> KeyNames::codemap; | ||
4 | QMap<int, QString> KeyNames::namemap; | ||
5 | QString KeyNames::tmpname; | ||
6 | |||
7 | static struct { | ||
8 | int code; | ||
9 | char* name; | ||
10 | } stKeyNames[] = { | ||
11 | {Qt::Key_Escape, "Escape"}, | ||
12 | {Qt::Key_Tab, "Tab"}, | ||
13 | {Qt::Key_Backtab, "Backtab"}, | ||
14 | {Qt::Key_BackTab, "BackTab"}, | ||
15 | {Qt::Key_Backtab, "Backtab"}, | ||
16 | {Qt::Key_Backspace, "Backspace"}, | ||
17 | {Qt::Key_BackSpace, "BackSpace"}, | ||
18 | {Qt::Key_Backspace, "Backspace"}, | ||
19 | {Qt::Key_Return, "Return"}, | ||
20 | {Qt::Key_Enter, "Enter"}, | ||
21 | {Qt::Key_Insert, "Insert"}, | ||
22 | {Qt::Key_Delete, "Delete"}, | ||
23 | {Qt::Key_Pause, "Pause"}, | ||
24 | {Qt::Key_Print, "Print"}, | ||
25 | {Qt::Key_SysReq, "SysReq"}, | ||
26 | {Qt::Key_Home, "Home"}, | ||
27 | {Qt::Key_End, "End"}, | ||
28 | {Qt::Key_Left, "Left"}, | ||
29 | {Qt::Key_Up, "Up"}, | ||
30 | {Qt::Key_Right, "Right"}, | ||
31 | {Qt::Key_Down, "Down"}, | ||
32 | {Qt::Key_Prior, "Prior"}, | ||
33 | {Qt::Key_PageUp, "PageUp"}, | ||
34 | {Qt::Key_Prior, "Prior"}, | ||
35 | {Qt::Key_Next, "Next"}, | ||
36 | {Qt::Key_PageDown, "PageDown"}, | ||
37 | {Qt::Key_Next, "Next"}, | ||
38 | {Qt::Key_Shift, "Shift"}, | ||
39 | {Qt::Key_Control, "Control"}, | ||
40 | {Qt::Key_Meta, "Meta"}, | ||
41 | {Qt::Key_Alt, "Alt"}, | ||
42 | {Qt::Key_CapsLock, "CapsLock"}, | ||
43 | {Qt::Key_NumLock, "NumLock"}, | ||
44 | {Qt::Key_ScrollLock, "ScrollLock"}, | ||
45 | {Qt::Key_F1, "F1"}, | ||
46 | {Qt::Key_F2, "F2"}, | ||
47 | {Qt::Key_F3, "F3"}, | ||
48 | {Qt::Key_F4, "F4"}, | ||
49 | {Qt::Key_F5, "F5"}, | ||
50 | {Qt::Key_F6, "F6"}, | ||
51 | {Qt::Key_F7, "F7"}, | ||
52 | {Qt::Key_F8, "F8"}, | ||
53 | {Qt::Key_F9, "F9"}, | ||
54 | {Qt::Key_F10, "F10"}, | ||
55 | {Qt::Key_F11, "F11"}, | ||
56 | {Qt::Key_F12, "F12"}, | ||
57 | {Qt::Key_F13, "F13"}, | ||
58 | {Qt::Key_F14, "F14"}, | ||
59 | {Qt::Key_F15, "F15"}, | ||
60 | {Qt::Key_F16, "F16"}, | ||
61 | {Qt::Key_F17, "F17"}, | ||
62 | {Qt::Key_F18, "F18"}, | ||
63 | {Qt::Key_F19, "F19"}, | ||
64 | {Qt::Key_F20, "F20"}, | ||
65 | {Qt::Key_F21, "F21"}, | ||
66 | {Qt::Key_F22, "F22"}, | ||
67 | {Qt::Key_F23, "F23"}, | ||
68 | {Qt::Key_F24, "F24"}, | ||
69 | {Qt::Key_F25, "F25"}, | ||
70 | {Qt::Key_F26, "F26"}, | ||
71 | {Qt::Key_F27, "F27"}, | ||
72 | {Qt::Key_F28, "F28"}, | ||
73 | {Qt::Key_F29, "F29"}, | ||
74 | {Qt::Key_F30, "F30"}, | ||
75 | {Qt::Key_F31, "F31"}, | ||
76 | {Qt::Key_F32, "F32"}, | ||
77 | {Qt::Key_F33, "F33"}, | ||
78 | {Qt::Key_F34, "F34"}, | ||
79 | {Qt::Key_F35, "F35"}, | ||
80 | {Qt::Key_Super_L, "Super_L"}, | ||
81 | {Qt::Key_Super_R, "Super_R"}, | ||
82 | {Qt::Key_Menu, "Menu"}, | ||
83 | {Qt::Key_Hyper_L, "Hyper_L"}, | ||
84 | {Qt::Key_Hyper_R, "Hyper_R"}, | ||
85 | {Qt::Key_Help, "Help"}, | ||
86 | {Qt::Key_Space, "Space"}, | ||
87 | {Qt::Key_Any, "Any"}, | ||
88 | {Qt::Key_Space, "Space"}, | ||
89 | {Qt::Key_Exclam, "Exclam"}, | ||
90 | {Qt::Key_QuoteDbl, "QuoteDbl"}, | ||
91 | {Qt::Key_NumberSign, "NumberSign"}, | ||
92 | {Qt::Key_Dollar, "Dollar"}, | ||
93 | {Qt::Key_Percent, "Percent"}, | ||
94 | {Qt::Key_Ampersand, "Ampersand"}, | ||
95 | {Qt::Key_Apostrophe, "Apostrophe"}, | ||
96 | {Qt::Key_ParenLeft, "ParenLeft"}, | ||
97 | {Qt::Key_ParenRight, "ParenRight"}, | ||
98 | {Qt::Key_Asterisk, "Asterisk"}, | ||
99 | {Qt::Key_Plus, "Plus"}, | ||
100 | {Qt::Key_Comma, "Comma"}, | ||
101 | {Qt::Key_Minus, "Minus"}, | ||
102 | {Qt::Key_Period, "Period"}, | ||
103 | {Qt::Key_Slash, "Slash"}, | ||
104 | {Qt::Key_0, "0"}, | ||
105 | {Qt::Key_1, "1"}, | ||
106 | {Qt::Key_2, "2"}, | ||
107 | {Qt::Key_3, "3"}, | ||
108 | {Qt::Key_4, "4"}, | ||
109 | {Qt::Key_5, "5"}, | ||
110 | {Qt::Key_6, "6"}, | ||
111 | {Qt::Key_7, "7"}, | ||
112 | {Qt::Key_8, "8"}, | ||
113 | {Qt::Key_9, "9"}, | ||
114 | {Qt::Key_Colon, "Colon"}, | ||
115 | {Qt::Key_Semicolon, "Semicolon"}, | ||
116 | {Qt::Key_Less, "Less"}, | ||
117 | {Qt::Key_Equal, "Equal"}, | ||
118 | {Qt::Key_Greater, "Greater"}, | ||
119 | {Qt::Key_Question, "Question"}, | ||
120 | {Qt::Key_At, "At"}, | ||
121 | {Qt::Key_A, "A"}, | ||
122 | {Qt::Key_B, "B"}, | ||
123 | {Qt::Key_C, "C"}, | ||
124 | {Qt::Key_D, "D"}, | ||
125 | {Qt::Key_E, "E"}, | ||
126 | {Qt::Key_F, "F"}, | ||
127 | {Qt::Key_G, "G"}, | ||
128 | {Qt::Key_H, "H"}, | ||
129 | {Qt::Key_I, "I"}, | ||
130 | {Qt::Key_J, "J"}, | ||
131 | {Qt::Key_K, "K"}, | ||
132 | {Qt::Key_L, "L"}, | ||
133 | {Qt::Key_M, "M"}, | ||
134 | {Qt::Key_N, "N"}, | ||
135 | {Qt::Key_O, "O"}, | ||
136 | {Qt::Key_P, "P"}, | ||
137 | {Qt::Key_Q, "Q"}, | ||
138 | {Qt::Key_R, "R"}, | ||
139 | {Qt::Key_S, "S"}, | ||
140 | {Qt::Key_T, "T"}, | ||
141 | {Qt::Key_U, "U"}, | ||
142 | {Qt::Key_V, "V"}, | ||
143 | {Qt::Key_W, "W"}, | ||
144 | {Qt::Key_X, "X"}, | ||
145 | {Qt::Key_Y, "Y"}, | ||
146 | {Qt::Key_Z, "Z"}, | ||
147 | {Qt::Key_BracketLeft, "BracketLeft"}, | ||
148 | {Qt::Key_Backslash, "Backslash"}, | ||
149 | {Qt::Key_BracketRight, "BracketRight"}, | ||
150 | {Qt::Key_AsciiCircum, "AsciiCircum"}, | ||
151 | {Qt::Key_Underscore, "Underscore"}, | ||
152 | {Qt::Key_QuoteLeft, "QuoteLeft"}, | ||
153 | {Qt::Key_BraceLeft, "BraceLeft"}, | ||
154 | {Qt::Key_Bar, "Bar"}, | ||
155 | {Qt::Key_BraceRight, "BraceRight"}, | ||
156 | {Qt::Key_AsciiTilde, "AsciiTilde"}, | ||
157 | {Qt::Key_nobreakspace, "nobreakspace"}, | ||
158 | {Qt::Key_exclamdown, "exclamdown"}, | ||
159 | {Qt::Key_cent, "cent"}, | ||
160 | {Qt::Key_sterling, "sterling"}, | ||
161 | {Qt::Key_currency, "currency"}, | ||
162 | {Qt::Key_yen, "yen"}, | ||
163 | {Qt::Key_brokenbar, "brokenbar"}, | ||
164 | {Qt::Key_section, "section"}, | ||
165 | {Qt::Key_diaeresis, "diaeresis"}, | ||
166 | {Qt::Key_copyright, "copyright"}, | ||
167 | {Qt::Key_ordfeminine, "ordfeminine"}, | ||
168 | {Qt::Key_guillemotleft, "guillemotleft"}, | ||
169 | {Qt::Key_notsign, "notsign"}, | ||
170 | {Qt::Key_hyphen, "hyphen"}, | ||
171 | {Qt::Key_registered, "registered"}, | ||
172 | {Qt::Key_macron, "macron"}, | ||
173 | {Qt::Key_degree, "degree"}, | ||
174 | {Qt::Key_plusminus, "plusminus"}, | ||
175 | {Qt::Key_twosuperior, "twosuperior"}, | ||
176 | {Qt::Key_threesuperior, "threesuperior"}, | ||
177 | {Qt::Key_acute, "acute"}, | ||
178 | {Qt::Key_mu, "mu"}, | ||
179 | {Qt::Key_paragraph, "paragraph"}, | ||
180 | {Qt::Key_periodcentered, "periodcentered"}, | ||
181 | {Qt::Key_cedilla, "cedilla"}, | ||
182 | {Qt::Key_onesuperior, "onesuperior"}, | ||
183 | {Qt::Key_masculine, "masculine"}, | ||
184 | {Qt::Key_guillemotright, "guillemotright"}, | ||
185 | {Qt::Key_onequarter, "onequarter"}, | ||
186 | {Qt::Key_onehalf, "onehalf"}, | ||
187 | {Qt::Key_threequarters, "threequarters"}, | ||
188 | {Qt::Key_questiondown, "questiondown"}, | ||
189 | {Qt::Key_Agrave, "Agrave"}, | ||
190 | {Qt::Key_Aacute, "Aacute"}, | ||
191 | {Qt::Key_Acircumflex, "Acircumflex"}, | ||
192 | {Qt::Key_Atilde, "Atilde"}, | ||
193 | {Qt::Key_Adiaeresis, "Adiaeresis"}, | ||
194 | {Qt::Key_Aring, "Aring"}, | ||
195 | {Qt::Key_AE, "AE"}, | ||
196 | {Qt::Key_Ccedilla, "Ccedilla"}, | ||
197 | {Qt::Key_Egrave, "Egrave"}, | ||
198 | {Qt::Key_Eacute, "Eacute"}, | ||
199 | {Qt::Key_Ecircumflex, "Ecircumflex"}, | ||
200 | {Qt::Key_Ediaeresis, "Ediaeresis"}, | ||
201 | {Qt::Key_Igrave, "Igrave"}, | ||
202 | {Qt::Key_Iacute, "Iacute"}, | ||
203 | {Qt::Key_Icircumflex, "Icircumflex"}, | ||
204 | {Qt::Key_Idiaeresis, "Idiaeresis"}, | ||
205 | {Qt::Key_ETH, "ETH"}, | ||
206 | {Qt::Key_Ntilde, "Ntilde"}, | ||
207 | {Qt::Key_Ograve, "Ograve"}, | ||
208 | {Qt::Key_Oacute, "Oacute"}, | ||
209 | {Qt::Key_Ocircumflex, "Ocircumflex"}, | ||
210 | {Qt::Key_Otilde, "Otilde"}, | ||
211 | {Qt::Key_Odiaeresis, "Odiaeresis"}, | ||
212 | {Qt::Key_multiply, "multiply"}, | ||
213 | {Qt::Key_Ooblique, "Ooblique"}, | ||
214 | {Qt::Key_Ugrave, "Ugrave"}, | ||
215 | {Qt::Key_Uacute, "Uacute"}, | ||
216 | {Qt::Key_Ucircumflex, "Ucircumflex"}, | ||
217 | {Qt::Key_Udiaeresis, "Udiaeresis"}, | ||
218 | {Qt::Key_Yacute, "Yacute"}, | ||
219 | {Qt::Key_THORN, "THORN"}, | ||
220 | {Qt::Key_ssharp, "ssharp"}, | ||
221 | {Qt::Key_agrave, "agrave"}, | ||
222 | {Qt::Key_aacute, "aacute"}, | ||
223 | {Qt::Key_acircumflex, "acircumflex"}, | ||
224 | {Qt::Key_atilde, "atilde"}, | ||
225 | {Qt::Key_adiaeresis, "adiaeresis"}, | ||
226 | {Qt::Key_aring, "aring"}, | ||
227 | {Qt::Key_ae, "ae"}, | ||
228 | {Qt::Key_ccedilla, "ccedilla"}, | ||
229 | {Qt::Key_egrave, "egrave"}, | ||
230 | {Qt::Key_eacute, "eacute"}, | ||
231 | {Qt::Key_ecircumflex, "ecircumflex"}, | ||
232 | {Qt::Key_ediaeresis, "ediaeresis"}, | ||
233 | {Qt::Key_igrave, "igrave"}, | ||
234 | {Qt::Key_iacute, "iacute"}, | ||
235 | {Qt::Key_icircumflex, "icircumflex"}, | ||
236 | {Qt::Key_idiaeresis, "idiaeresis"}, | ||
237 | {Qt::Key_eth, "eth"}, | ||
238 | {Qt::Key_ntilde, "ntilde"}, | ||
239 | {Qt::Key_ograve, "ograve"}, | ||
240 | {Qt::Key_oacute, "oacute"}, | ||
241 | {Qt::Key_ocircumflex, "ocircumflex"}, | ||
242 | {Qt::Key_otilde, "otilde"}, | ||
243 | {Qt::Key_odiaeresis, "odiaeresis"}, | ||
244 | {Qt::Key_division, "division"}, | ||
245 | {Qt::Key_oslash, "oslash"}, | ||
246 | {Qt::Key_ugrave, "ugrave"}, | ||
247 | {Qt::Key_uacute, "uacute"}, | ||
248 | {Qt::Key_ucircumflex, "ucircumflex"}, | ||
249 | {Qt::Key_udiaeresis, "udiaeresis"}, | ||
250 | {Qt::Key_yacute, "yacute"}, | ||
251 | {Qt::Key_thorn, "thorn"}, | ||
252 | {Qt::Key_ydiaeresis, "ydiaeresis"}, | ||
253 | {Qt::Key_unknown, "unknown"}, | ||
254 | {0,0}, | ||
255 | }; | ||
256 | |||
257 | void KeyNames::setCodeMap() | ||
258 | { | ||
259 | int i; | ||
260 | |||
261 | codemap.clear(); | ||
262 | for(i=0; stKeyNames[i].code != 0; i++){ | ||
263 | codemap.insert(stKeyNames[i].name, stKeyNames[i].code); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | void KeyNames::setNameMap() | ||
268 | { | ||
269 | int i; | ||
270 | |||
271 | namemap.clear(); | ||
272 | for(i=0; stKeyNames[i].code != 0; i++){ | ||
273 | namemap.insert(stKeyNames[i].code, stKeyNames[i].name); | ||
274 | } | ||
275 | } | ||
276 | |||
277 | |||
278 | int KeyNames::getCode(const QString& s){ | ||
279 | if(codemap.isEmpty()) setCodeMap(); | ||
280 | if(codemap.contains(s)){ | ||
281 | return(codemap[s]); | ||
282 | } else { | ||
283 | if(s.find("0x") == 0){ | ||
284 | bool success; | ||
285 | int val = s.mid(2).toInt(&success, 16); | ||
286 | if(success){ | ||
287 | return(val); | ||
288 | } | ||
289 | } | ||
290 | return(0); | ||
291 | } | ||
292 | } | ||
293 | |||
294 | const QString& KeyNames::getName(int code){ | ||
295 | if(namemap.isEmpty()) setNameMap(); | ||
296 | if(namemap.contains(code)){ | ||
297 | return(namemap[code]); | ||
298 | } else { | ||
299 | tmpname.sprintf("0x%x", code); | ||
300 | return(tmpname); | ||
301 | //return(QString::null); | ||
302 | } | ||
303 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyNames.h b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyNames.h new file mode 100644 index 0000000..3e80763 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyNames.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #ifndef _KEY_NAMES_H_ | ||
2 | #define _KEY_NAMES_H_ | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qmap.h> | ||
6 | #include <qnamespace.h> | ||
7 | |||
8 | class KeyNames | ||
9 | { | ||
10 | public: | ||
11 | static const QString& getName(int code); | ||
12 | static int getCode(const QString& s); | ||
13 | |||
14 | static void clearName(){ | ||
15 | namemap.clear(); | ||
16 | } | ||
17 | static void setCode(const QString& s, int code){ | ||
18 | if(codemap.contains(s) == false){ | ||
19 | codemap.insert(s, code); | ||
20 | } | ||
21 | } | ||
22 | static void clearCode(){ | ||
23 | codemap.clear(); | ||
24 | } | ||
25 | static void reset(){ | ||
26 | clearCode(); | ||
27 | } | ||
28 | private: | ||
29 | static QMap<QString, int> codemap; | ||
30 | static QMap<int, QString> namemap; | ||
31 | static QString tmpname; | ||
32 | |||
33 | static void setCodeMap(); | ||
34 | static void setNameMap(); | ||
35 | }; | ||
36 | |||
37 | #endif /* _KEY_NAMES_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp new file mode 100644 index 0000000..84a8a89 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp | |||
@@ -0,0 +1,140 @@ | |||
1 | #include "KeyRepeater.h" | ||
2 | |||
3 | KeyRepeater::KeyRepeater() | ||
4 | { | ||
5 | qDebug("KeyRepeater::KeyRepeater()"); | ||
6 | m_pTimer = new QTimer(this); | ||
7 | connect(m_pTimer, SIGNAL(timeout()), this, SLOT(autoRepeat())); | ||
8 | init(); | ||
9 | } | ||
10 | |||
11 | KeyRepeater::~KeyRepeater() | ||
12 | { | ||
13 | qDebug("KeyRepeater::~KeyRepeater()"); | ||
14 | delete m_pTimer; | ||
15 | } | ||
16 | |||
17 | void KeyRepeater::start(int unicode, int keycode, int modifiers) | ||
18 | { | ||
19 | m_unicode = unicode; | ||
20 | m_keycode = keycode; | ||
21 | m_modifiers = modifiers; | ||
22 | if(m_mode == ENABLE){ | ||
23 | m_pTimer->stop(); | ||
24 | if(isRepeatable(keycode)){ | ||
25 | /* repeater start */ | ||
26 | m_pTimer->start(m_repeatdelay, TRUE); | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
31 | void KeyRepeater::stop(int keycode) | ||
32 | { | ||
33 | if(keycode == 0 | ||
34 | || keycode == m_keycode | ||
35 | || isRepeatable(keycode) == false){ | ||
36 | m_pTimer->stop(); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | void KeyRepeater::init() | ||
41 | { | ||
42 | m_mode = ENABLE; | ||
43 | m_repeatdelay = 400; | ||
44 | m_repeatperiod = 60; | ||
45 | m_disablekeys.append(0); | ||
46 | m_disablekeys.append(Qt::Key_Escape); | ||
47 | m_disablekeys.append(Qt::Key_Shift); | ||
48 | m_disablekeys.append(Qt::Key_Control); | ||
49 | m_disablekeys.append(Qt::Key_Alt); | ||
50 | m_disablekeys.append(Qt::Key_Meta); | ||
51 | for(int i=Qt::Key_F1; i<=Qt::Key_F35; i++){ | ||
52 | m_disablekeys.append(i); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | void KeyRepeater::clear() | ||
57 | { | ||
58 | m_disablekeys.clear(); | ||
59 | } | ||
60 | |||
61 | void KeyRepeater::reset() | ||
62 | { | ||
63 | clear(); | ||
64 | init(); | ||
65 | } | ||
66 | |||
67 | void KeyRepeater::setRepeatable(int keycode, bool enable) | ||
68 | { | ||
69 | if(enable){ | ||
70 | QValueList<int>::Iterator it = m_disablekeys.find(keycode); | ||
71 | if(it != m_disablekeys.end()){ | ||
72 | m_disablekeys.remove(it); | ||
73 | } | ||
74 | } else { | ||
75 | if(m_disablekeys.contains(keycode) == false){ | ||
76 | m_disablekeys.append(keycode); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | bool KeyRepeater::isRepeatable(int keycode) | ||
82 | { | ||
83 | if(m_disablekeys.contains(keycode)){ | ||
84 | return(false); | ||
85 | } else { | ||
86 | return(true); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void KeyRepeater::autoRepeat() | ||
91 | { | ||
92 | /* key release event */ | ||
93 | #if 0 | ||
94 | sendKeyEvent( | ||
95 | m_unicode, | ||
96 | m_keycode, | ||
97 | m_modifiers, | ||
98 | FALSE, | ||
99 | TRUE); | ||
100 | /* key press event */ | ||
101 | sendKeyEvent( | ||
102 | m_unicode, | ||
103 | m_keycode, | ||
104 | m_modifiers, | ||
105 | TRUE, | ||
106 | TRUE); | ||
107 | #else | ||
108 | emit keyEvent( | ||
109 | m_unicode, | ||
110 | m_keycode, | ||
111 | m_modifiers, | ||
112 | FALSE, | ||
113 | TRUE); | ||
114 | /* key press event */ | ||
115 | emit keyEvent( | ||
116 | m_unicode, | ||
117 | m_keycode, | ||
118 | m_modifiers, | ||
119 | TRUE, | ||
120 | TRUE); | ||
121 | #endif | ||
122 | /* start auto repeat */ | ||
123 | m_pTimer->start(m_repeatperiod); | ||
124 | #if 0 | ||
125 | qDebug("autoRepeat[%x][%x][%x]", | ||
126 | m_unicode, | ||
127 | m_keycode, | ||
128 | m_modifiers); | ||
129 | #endif | ||
130 | } | ||
131 | |||
132 | void KeyRepeater::statistics() | ||
133 | { | ||
134 | qWarning("KeyRepeater::statistics()"); | ||
135 | qWarning(" delay[%d] period[%d]", m_repeatdelay, m_repeatperiod); | ||
136 | for(QValueList<int>::Iterator it=m_disablekeys.begin(); | ||
137 | it!=m_disablekeys.end(); ++it){ | ||
138 | qDebug(" disable[%x]", *it); | ||
139 | } | ||
140 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.h b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.h new file mode 100644 index 0000000..56d6414 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.h | |||
@@ -0,0 +1,86 @@ | |||
1 | #ifndef _KEY_REPEATER_H_ | ||
2 | #define _KEY_REPEATER_H_ | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qtimer.h> | ||
6 | #include <qvaluelist.h> | ||
7 | #include <qwindowsystem_qws.h> | ||
8 | |||
9 | #include <syslog.h> | ||
10 | |||
11 | class KeyRepeater : public QObject | ||
12 | { | ||
13 | Q_OBJECT | ||
14 | public: | ||
15 | KeyRepeater(); | ||
16 | virtual ~KeyRepeater(); | ||
17 | |||
18 | typedef enum { | ||
19 | DISABLE=0, | ||
20 | ENABLE=1, | ||
21 | KILL=2, | ||
22 | } RepeaterMode; | ||
23 | |||
24 | void start(int unicode, int keycode, int modifieres); | ||
25 | void stop(int keycode = 0); | ||
26 | void reset(); | ||
27 | |||
28 | void setRepeatable(int keycode, bool enable); | ||
29 | bool isRepeatable(int keycode); | ||
30 | |||
31 | void setMode(int mode){ | ||
32 | switch(mode){ | ||
33 | case DISABLE: | ||
34 | m_mode = DISABLE; | ||
35 | break; | ||
36 | case ENABLE: | ||
37 | m_mode = ENABLE; | ||
38 | break; | ||
39 | case KILL: | ||
40 | m_mode = KILL; | ||
41 | break; | ||
42 | default: | ||
43 | m_mode = ENABLE; | ||
44 | break; | ||
45 | } | ||
46 | } | ||
47 | RepeaterMode getMode(){ | ||
48 | return(m_mode); | ||
49 | } | ||
50 | |||
51 | void setDelay(int msec) | ||
52 | { | ||
53 | m_repeatdelay = msec; | ||
54 | } | ||
55 | void setPeriod(int msec) | ||
56 | { | ||
57 | m_repeatperiod = msec; | ||
58 | } | ||
59 | |||
60 | void statistics(); | ||
61 | private slots: | ||
62 | void autoRepeat(); | ||
63 | private: | ||
64 | int m_unicode; | ||
65 | int m_keycode; | ||
66 | int m_modifiers; | ||
67 | |||
68 | int m_repeatdelay; | ||
69 | int m_repeatperiod; | ||
70 | |||
71 | QCString m_hookChannel; | ||
72 | |||
73 | RepeaterMode m_mode; | ||
74 | |||
75 | QValueList<int> m_disablekeys; | ||
76 | |||
77 | QTimer* m_pTimer; | ||
78 | |||
79 | void init(); | ||
80 | void clear(); | ||
81 | signals: | ||
82 | void keyEvent(int unicode, int keycode, int modifiers, | ||
83 | bool isPress, bool autoRepeat); | ||
84 | }; | ||
85 | |||
86 | #endif /* _KEY_REPEATER_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/StringParser.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/StringParser.cpp new file mode 100644 index 0000000..72c15f1 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/StringParser.cpp | |||
@@ -0,0 +1,72 @@ | |||
1 | #include "StringParser.h" | ||
2 | |||
3 | #include <qregexp.h> | ||
4 | |||
5 | QStringList StringParser::split(const QChar& sep, const QString& str, | ||
6 | bool allowEmptyEntries) | ||
7 | { | ||
8 | QString line = str + sep; | ||
9 | QString quote; | ||
10 | QRegExp rxend; | ||
11 | QRegExp rxdbl; | ||
12 | int pos=0, len, idx=0; | ||
13 | QStringList list; | ||
14 | while(idx < (int)line.length()-1){ | ||
15 | if(!quote.isEmpty()){ | ||
16 | QString s; | ||
17 | while((pos = rxend.match(line, idx, &len)) != -1){ | ||
18 | s += line.mid(idx, len+pos-idx-1); | ||
19 | idx = pos+len-1; | ||
20 | if(len % 2 == 0){ | ||
21 | s.replace(rxdbl, quote); | ||
22 | list.append(s.left(s.length()-1)); | ||
23 | idx++; | ||
24 | break; | ||
25 | } | ||
26 | } | ||
27 | quote = ""; | ||
28 | } else if(line[idx] == '\"'){ | ||
29 | rxend.setPattern(QString("\"+") + sep); | ||
30 | rxdbl.setPattern("\"\""); | ||
31 | quote = "\""; | ||
32 | idx++; | ||
33 | } else if(line[idx] == '\''){ | ||
34 | rxend.setPattern(QString("\'+") + sep); | ||
35 | rxdbl.setPattern("\'\'"); | ||
36 | quote = "\'"; | ||
37 | idx++; | ||
38 | } else if(!allowEmptyEntries && line[idx] == sep){ | ||
39 | idx++; | ||
40 | } else { | ||
41 | pos = line.find(sep, idx); | ||
42 | if(pos != -1){ | ||
43 | const QString& s = line.mid(idx, pos-idx); | ||
44 | list.append(s); | ||
45 | idx = pos+1; | ||
46 | } | ||
47 | } | ||
48 | if(pos == -1) break; | ||
49 | } | ||
50 | return list; | ||
51 | } | ||
52 | |||
53 | QString StringParser::join(const QChar& sep, const QStringList& list) | ||
54 | { | ||
55 | QString str; | ||
56 | QString s; | ||
57 | QStringList tmp; | ||
58 | QRegExp quote("\""); | ||
59 | for(QStringList::ConstIterator it=list.begin(); | ||
60 | it!=list.end(); ++it){ | ||
61 | s = *it; | ||
62 | if(s.find(sep) != -1 | ||
63 | || s[0] == '\"' | ||
64 | || s[0] == '\''){ | ||
65 | s.replace(quote, "\"\""); | ||
66 | tmp.append("\"" + s + "\""); | ||
67 | } else { | ||
68 | tmp.append(s); | ||
69 | } | ||
70 | } | ||
71 | return tmp.join(sep); | ||
72 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/StringParser.h b/noncore/applets/keyhelper/keyhelperapplet/misc/StringParser.h new file mode 100644 index 0000000..8c1dc58 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/StringParser.h | |||
@@ -0,0 +1,14 @@ | |||
1 | #ifndef _STRING_PARSER_H_ | ||
2 | #define _STRING_PARSER_H_ | ||
3 | |||
4 | #include <qstringlist.h> | ||
5 | |||
6 | class StringParser | ||
7 | { | ||
8 | public: | ||
9 | static QStringList split(const QChar& sep, const QString& str, | ||
10 | bool allowEmptyEntries=FALSE); | ||
11 | static QString join(const QChar& sep, const QStringList& list); | ||
12 | }; | ||
13 | |||
14 | #endif /* _STRING_PARSER_H_ */ | ||