Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/extension') (more/less context) (ignore whitespace changes)
16 files changed, 1429 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.cpp new file mode 100644 index 0000000..00a43d1 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.cpp | |||
@@ -0,0 +1,110 @@ | |||
1 | #include "ExtensionFactory.h" | ||
2 | |||
3 | ExtensionFactory::ExtensionFactory() | ||
4 | { | ||
5 | qDebug("ExtensionFactory::ExtensionFactory()"); | ||
6 | m_pLoadList = NULL; | ||
7 | } | ||
8 | |||
9 | ExtensionFactory::~ExtensionFactory() | ||
10 | { | ||
11 | qDebug("ExtensionFactory::~ExtensionFactory()"); | ||
12 | } | ||
13 | |||
14 | ExtensionInterface* ExtensionFactory::createInstance(const QString& kind) | ||
15 | { | ||
16 | ExtensionInterface* ext; | ||
17 | QString kindstr = kind.lower(); | ||
18 | |||
19 | if(kindstr == "switch"){ | ||
20 | ext = new TaskSwitcher(kindstr); | ||
21 | } else if(kindstr == "select"){ | ||
22 | ext = new TaskSelector(kindstr); | ||
23 | } else if(kindstr.find("launch") == 0){ | ||
24 | ext = new KeyLauncher(kindstr); | ||
25 | } else if(kindstr.find("menu") == 0){ | ||
26 | ext = new MenuLauncher(kindstr); | ||
27 | } else { | ||
28 | return(NULL); | ||
29 | } | ||
30 | m_oExtList.append(ext); | ||
31 | return(ext); | ||
32 | } | ||
33 | |||
34 | ExtensionInterface* ExtensionFactory::createInstance(const QString& kind, | ||
35 | int keycode, int keymask) | ||
36 | { | ||
37 | ExtensionInterface* ext; | ||
38 | QString kindstr = kind.lower(); | ||
39 | |||
40 | ext = loadInstance(kindstr, keycode, keymask); | ||
41 | if(ext != NULL){ | ||
42 | return(ext); | ||
43 | } | ||
44 | |||
45 | if(kindstr == "switch"){ | ||
46 | ext = new TaskSwitcher(kindstr); | ||
47 | } else if(kindstr == "select"){ | ||
48 | ext = new TaskSelector(kindstr); | ||
49 | } else if(kindstr.find("launch") == 0){ | ||
50 | ext = new KeyLauncher(kindstr); | ||
51 | } else if(kindstr.find("menu") == 0){ | ||
52 | ext = new MenuLauncher(kindstr); | ||
53 | } else { | ||
54 | return(NULL); | ||
55 | } | ||
56 | ext->setKeycode(keycode); | ||
57 | ext->setKeymask(keymask); | ||
58 | |||
59 | m_oExtList.append(ext); | ||
60 | return(ext); | ||
61 | } | ||
62 | |||
63 | ExtensionInterface* ExtensionFactory::loadInstance(const QString& kindstr, | ||
64 | int keycode, int keymask) | ||
65 | { | ||
66 | if(m_pLoadList == NULL){ | ||
67 | return(NULL); | ||
68 | } | ||
69 | |||
70 | for(ExtensionList::Iterator it=m_pLoadList->begin(); | ||
71 | it!=m_pLoadList->end(); ++it){ | ||
72 | if((*it)->kind() == kindstr | ||
73 | && (*it)->getKeycode() == keycode | ||
74 | && (*it)->getKeymask() == keymask){ | ||
75 | m_oExtList.append(*it); | ||
76 | return(*it); | ||
77 | } | ||
78 | } | ||
79 | return(NULL); | ||
80 | } | ||
81 | |||
82 | void ExtensionFactory::clear() | ||
83 | { | ||
84 | for(ExtensionList::Iterator it=m_oExtList.begin(); | ||
85 | it!=m_oExtList.end(); ++it){ | ||
86 | delete *it; | ||
87 | } | ||
88 | m_oExtList.clear(); | ||
89 | } | ||
90 | |||
91 | void ExtensionFactory::reset() | ||
92 | { | ||
93 | m_pLoadList = new ExtensionList(m_oExtList); | ||
94 | m_oExtList.clear(); | ||
95 | } | ||
96 | |||
97 | void ExtensionFactory::sweep() | ||
98 | { | ||
99 | if(m_pLoadList == NULL){ | ||
100 | return; | ||
101 | } | ||
102 | for(ExtensionList::Iterator it=m_pLoadList->begin(); | ||
103 | it!=m_pLoadList->end(); ++it){ | ||
104 | if(m_oExtList.contains(*it) == false){ | ||
105 | delete *it; | ||
106 | } | ||
107 | } | ||
108 | delete m_pLoadList; | ||
109 | m_pLoadList = NULL; | ||
110 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.h b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.h new file mode 100644 index 0000000..7fa6a5f --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.h | |||
@@ -0,0 +1,35 @@ | |||
1 | #ifndef _EXTENSION_FACTORY_H_ | ||
2 | #define _EXTENSION_FACTORY_H_ | ||
3 | |||
4 | #include "ExtensionInterface.h" | ||
5 | #include "TaskSwitcher.h" | ||
6 | #include "KeyLauncher.h" | ||
7 | #include "TaskSelector.h" | ||
8 | #include "MenuLauncher.h" | ||
9 | |||
10 | class ExtensionFactory | ||
11 | { | ||
12 | public: | ||
13 | ExtensionFactory(); | ||
14 | virtual ~ExtensionFactory(); | ||
15 | |||
16 | ExtensionInterface* createInstance(const QString& kind); | ||
17 | ExtensionInterface* createInstance(const QString& kind, | ||
18 | int keycode, int keymask); | ||
19 | ExtensionList& getList() | ||
20 | { | ||
21 | return(m_oExtList); | ||
22 | } | ||
23 | void clear(); | ||
24 | void reset(); | ||
25 | void sweep(); | ||
26 | private: | ||
27 | ExtensionList m_oExtList; | ||
28 | ExtensionList* m_pLoadList; | ||
29 | |||
30 | ExtensionInterface* loadInstance(const QString& kind, | ||
31 | int keycode, int keymask); | ||
32 | }; | ||
33 | |||
34 | #endif /* _EXTENSION_FACTORY_H_ */ | ||
35 | |||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionInterface.h b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionInterface.h new file mode 100644 index 0000000..1a81141 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionInterface.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef _EXTENSION_INTERFACE_H_ | ||
2 | #define _EXTENSION_INTERFACE_H_ | ||
3 | |||
4 | #include <qvaluelist.h> | ||
5 | |||
6 | class ExtensionInterface | ||
7 | { | ||
8 | public: | ||
9 | //ExtensionInterface(); | ||
10 | virtual ~ExtensionInterface(){} | ||
11 | virtual bool onKeyPress(int keycode) = 0; | ||
12 | virtual bool onModRelease(int modcode) = 0; | ||
13 | virtual int getKeycode() = 0; | ||
14 | virtual int getKeymask() = 0; | ||
15 | virtual const QValueList<int>& getModcodes() = 0; | ||
16 | virtual void setKeycode(int keycode) = 0; | ||
17 | virtual void setKeymask(int keymask) = 0; | ||
18 | virtual void setModcodes(const QValueList<int>& modcodes) = 0; | ||
19 | virtual const QString& kind() = 0; | ||
20 | private: | ||
21 | }; | ||
22 | |||
23 | typedef QValueList<ExtensionInterface*> ExtensionList; | ||
24 | |||
25 | #endif /* _EXTENSION_INTERFACE_H_ */ | ||
26 | |||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.cpp new file mode 100644 index 0000000..a61ea0a --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.cpp | |||
@@ -0,0 +1,111 @@ | |||
1 | #include "KeyExtensions.h" | ||
2 | |||
3 | KeyExtensions::KeyExtensions() | ||
4 | { | ||
5 | qDebug("KeyExtensions::KeyExtensions()"); | ||
6 | m_cancelcode = 0; | ||
7 | } | ||
8 | |||
9 | KeyExtensions::~KeyExtensions() | ||
10 | { | ||
11 | qDebug("KeyExtensions::~KeyExtensions()"); | ||
12 | clear(); | ||
13 | } | ||
14 | |||
15 | void KeyExtensions::assign(const QString& kind, int keycode, | ||
16 | int keymask, const QValueList<int>& modcodes) | ||
17 | { | ||
18 | ExtensionInterface* ext; | ||
19 | #if 0 | ||
20 | ext = m_oExtFactory.createInstance(kind); | ||
21 | if(ext != NULL){ | ||
22 | ext->setKeycode(keycode); | ||
23 | ext->setKeymask(keymask); | ||
24 | ext->setModcodes(modcodes); | ||
25 | } | ||
26 | #else | ||
27 | ext = m_oExtFactory.createInstance(kind, keycode, keymask); | ||
28 | if(ext != NULL){ | ||
29 | ext->setModcodes(modcodes); | ||
30 | } | ||
31 | #endif | ||
32 | } | ||
33 | |||
34 | void KeyExtensions::assign(const QString& kind, int keycode, | ||
35 | int keymask, int modcode) | ||
36 | { | ||
37 | QValueList<int> modcodes; | ||
38 | modcodes.append(modcode); | ||
39 | assign(kind, keycode, keymask, modcodes); | ||
40 | } | ||
41 | |||
42 | bool KeyExtensions::doKey(int keycode, int keymask, bool isPress) | ||
43 | { | ||
44 | bool fCancel = false; | ||
45 | ExtensionList& list = m_oExtFactory.getList(); | ||
46 | for(ExtensionList::Iterator it=list.begin(); | ||
47 | it!=list.end(); ++it){ | ||
48 | if(isPress){ | ||
49 | int code = (*it)->getKeycode(); | ||
50 | if((*it)->getKeymask() == keymask | ||
51 | && (code == 0 || code == keycode)){ | ||
52 | if((*it)->onKeyPress(keycode)){ | ||
53 | fCancel = true; | ||
54 | } | ||
55 | qWarning("ext:onKeyPress[%s][%x][%d]", | ||
56 | (*it)->kind().latin1(), | ||
57 | (*it)->getKeycode(), | ||
58 | fCancel); | ||
59 | } | ||
60 | } else { | ||
61 | if(keycode == m_cancelcode){ | ||
62 | fCancel = true; | ||
63 | } | ||
64 | const QValueList<int>& rlist = (*it)->getModcodes(); | ||
65 | if(rlist.contains(keycode)){ | ||
66 | if((*it)->onModRelease(keycode)){ | ||
67 | m_pModifiers->resetToggles(); | ||
68 | } | ||
69 | qWarning("ext:onModRelease[%s][%x]", | ||
70 | (*it)->kind().latin1(), | ||
71 | keycode); | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | if(isPress && fCancel){ | ||
76 | m_cancelcode = keycode; | ||
77 | } else { | ||
78 | m_cancelcode = 0; | ||
79 | } | ||
80 | return(fCancel); | ||
81 | } | ||
82 | |||
83 | void KeyExtensions::clear() | ||
84 | { | ||
85 | m_oExtFactory.clear(); | ||
86 | } | ||
87 | |||
88 | void KeyExtensions::reset() | ||
89 | { | ||
90 | //clear(); | ||
91 | m_oExtFactory.reset(); | ||
92 | } | ||
93 | |||
94 | void KeyExtensions::init() | ||
95 | { | ||
96 | m_oExtFactory.sweep(); | ||
97 | } | ||
98 | |||
99 | void KeyExtensions::statistics() | ||
100 | { | ||
101 | qWarning("KeyExtensions::statistics()"); | ||
102 | ExtensionList& list = m_oExtFactory.getList(); | ||
103 | for(ExtensionList::Iterator it=list.begin(); | ||
104 | it!=list.end(); ++it){ | ||
105 | qWarning(" [%s][%x][%x]", | ||
106 | (*it)->kind().latin1(), | ||
107 | (*it)->getKeycode(), | ||
108 | (*it)->getKeymask()); | ||
109 | } | ||
110 | } | ||
111 | |||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.h b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.h new file mode 100644 index 0000000..20ffc45 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.h | |||
@@ -0,0 +1,40 @@ | |||
1 | #ifndef _KEY_EXTENSIONS_H_ | ||
2 | #define _KEY_EXTENSIONS_H_ | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include "KeyNames.h" | ||
7 | #include "KeyModifiers.h" | ||
8 | #include "ExtensionFactory.h" | ||
9 | |||
10 | class KeyExtensions | ||
11 | { | ||
12 | public: | ||
13 | KeyExtensions(); | ||
14 | ~KeyExtensions(); | ||
15 | |||
16 | void setKeyModifiers(KeyModifiers* mod) | ||
17 | { | ||
18 | m_pModifiers = mod; | ||
19 | } | ||
20 | |||
21 | void assign(const QString& kind, int keycode, | ||
22 | int keymask, const QValueList<int>& modcodes); | ||
23 | void assign(const QString& kind, int keycode, | ||
24 | int keymask, int modcode); | ||
25 | bool doKey(int keycode, int keymask, bool isPress); | ||
26 | |||
27 | void statistics(); | ||
28 | |||
29 | void reset(); | ||
30 | void init(); | ||
31 | private: | ||
32 | KeyModifiers* m_pModifiers; | ||
33 | ExtensionFactory m_oExtFactory; | ||
34 | int m_cancelcode; | ||
35 | |||
36 | void clear(); | ||
37 | }; | ||
38 | |||
39 | #endif /* _KEY_EXTENSIONS_H_ */ | ||
40 | |||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.cpp new file mode 100644 index 0000000..7a0b88c --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.cpp | |||
@@ -0,0 +1,57 @@ | |||
1 | #include "KeyLauncher.h" | ||
2 | #include "KHUtil.h" | ||
3 | |||
4 | KeyLauncher::KeyLauncher(const QString& kind) : m_kind(kind) | ||
5 | { | ||
6 | qDebug("KeyLauncher::KeyLauncher()"); | ||
7 | } | ||
8 | |||
9 | KeyLauncher::~KeyLauncher() | ||
10 | { | ||
11 | qDebug("KeyLauncher::~KeyLauncher()"); | ||
12 | } | ||
13 | |||
14 | bool KeyLauncher::onKeyPress(int keycode) | ||
15 | { | ||
16 | QString key; | ||
17 | QStringList args; | ||
18 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
19 | |||
20 | key = KeyNames::getName(keycode); | ||
21 | if(key == QString::null){ | ||
22 | return(false); | ||
23 | } | ||
24 | |||
25 | QString group = kind(); | ||
26 | group[0] = group[0].upper(); | ||
27 | |||
28 | /* read application launcher */ | ||
29 | QString app = KHUtil::currentApp(); | ||
30 | if(!app.isEmpty()){ | ||
31 | cfg.setGroup(group + "_" + app); | ||
32 | /* read config */ | ||
33 | args = cfg.readListEntry(key, '\t'); | ||
34 | } | ||
35 | |||
36 | /* read default launcher */ | ||
37 | if(args.isEmpty()){ | ||
38 | cfg.setGroup(group); | ||
39 | |||
40 | /* read config */ | ||
41 | args = cfg.readListEntry(key, '\t'); | ||
42 | } | ||
43 | |||
44 | if(args.isEmpty()){ | ||
45 | return(false); | ||
46 | } | ||
47 | |||
48 | /* launch application */ | ||
49 | LnkWrapper lnk(args); | ||
50 | if(lnk.isValid()){ | ||
51 | //args.remove(args.begin()); | ||
52 | lnk.instance().execute(); | ||
53 | } | ||
54 | |||
55 | return(true); | ||
56 | } | ||
57 | |||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.h b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.h new file mode 100644 index 0000000..fbad3da --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.h | |||
@@ -0,0 +1,63 @@ | |||
1 | #ifndef _KEY_LAUNCHER_H_ | ||
2 | #define _KEY_LAUNCHER_H_ | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qvaluelist.h> | ||
7 | |||
8 | #include <qpe/qpeapplication.h> | ||
9 | #include <qpe/config.h> | ||
10 | #include <qpe/applnk.h> | ||
11 | #include <qpe/global.h> | ||
12 | #include <qpe/qcopenvelope_qws.h> | ||
13 | |||
14 | #include "ExtensionInterface.h" | ||
15 | #include "KeyNames.h" | ||
16 | #include "LnkWrapper.h" | ||
17 | #include "ConfigEx.h" | ||
18 | |||
19 | class KeyLauncher : public ExtensionInterface | ||
20 | { | ||
21 | public: | ||
22 | KeyLauncher(const QString& kind = "launch"); | ||
23 | virtual ~KeyLauncher(); | ||
24 | |||
25 | virtual bool onKeyPress(int keycode); | ||
26 | virtual bool onModRelease(int /*modcode*/){return(false);} | ||
27 | virtual int getKeycode() | ||
28 | { | ||
29 | return(m_keycode); | ||
30 | } | ||
31 | virtual int getKeymask() | ||
32 | { | ||
33 | return(m_keymask); | ||
34 | } | ||
35 | virtual const QValueList<int>& getModcodes() | ||
36 | { | ||
37 | return(m_modcodes); | ||
38 | } | ||
39 | virtual void setKeycode(int keycode) | ||
40 | { | ||
41 | m_keycode = keycode; | ||
42 | } | ||
43 | virtual void setKeymask(int keymask) | ||
44 | { | ||
45 | m_keymask = keymask; | ||
46 | } | ||
47 | virtual void setModcodes(const QValueList<int>& modcodes) | ||
48 | { | ||
49 | m_modcodes = modcodes; | ||
50 | } | ||
51 | virtual const QString& kind() | ||
52 | { | ||
53 | return(m_kind); | ||
54 | } | ||
55 | private: | ||
56 | int m_keycode; | ||
57 | int m_keymask; | ||
58 | QString m_kind; | ||
59 | QValueList<int> m_modcodes; | ||
60 | }; | ||
61 | |||
62 | #endif /* _KEY_LAUNCHER_H_ */ | ||
63 | |||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.cpp new file mode 100644 index 0000000..0595a3e --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.cpp | |||
@@ -0,0 +1,324 @@ | |||
1 | #include "MenuLauncher.h" | ||
2 | extern QWidget* g_Widget; | ||
3 | |||
4 | MenuLauncher::MenuLauncher(const QString& kind) : m_kind(kind) | ||
5 | { | ||
6 | qDebug("MenuLauncher::MenuLauncher()"); | ||
7 | m_pMenu = m_pTopMenu = NULL; | ||
8 | |||
9 | m_isShowing = false; | ||
10 | m_id = -1; | ||
11 | |||
12 | m_pTimer = new QTimer(this); | ||
13 | connect(m_pTimer, SIGNAL(timeout()), | ||
14 | this, SLOT(select())); | ||
15 | |||
16 | init(); | ||
17 | } | ||
18 | |||
19 | MenuLauncher::~MenuLauncher() | ||
20 | { | ||
21 | qDebug("MenuLauncher::~MenuLauncher()"); | ||
22 | delete m_pTopMenu; | ||
23 | delete m_pTimer; | ||
24 | } | ||
25 | |||
26 | void MenuLauncher::init() | ||
27 | { | ||
28 | buildMenu(); | ||
29 | } | ||
30 | |||
31 | QPopupMenu* MenuLauncher::initMenu(QWidget* parent, const QString& name) | ||
32 | { | ||
33 | QPopupMenu* pMenu; | ||
34 | pMenu = new QPopupMenuEx(parent, name); | ||
35 | pMenu->installEventFilter(this); | ||
36 | connect(pMenu, SIGNAL(activated(int)), this, SLOT(select(int))); | ||
37 | connect(pMenu, SIGNAL(highlighted(int)), this, SLOT(highlight(int))); | ||
38 | //connect(pMenu, SIGNAL(aboutToHide()), this, SLOT(execute())); | ||
39 | return(pMenu); | ||
40 | } | ||
41 | |||
42 | bool MenuLauncher::onKeyPress(int /*keycode*/) | ||
43 | { | ||
44 | if(m_isShowing){ | ||
45 | qDebug("showing ..."); | ||
46 | } else if(m_pMenu->isVisible()){ | ||
47 | next(); | ||
48 | } else { | ||
49 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
50 | cfg.setGroup("Global"); | ||
51 | int delay = cfg.readNumEntry("DelayPopup", 5); | ||
52 | QTimer::singleShot(delay, this, SLOT(show())); | ||
53 | m_isShowing = true; | ||
54 | } | ||
55 | return true; | ||
56 | } | ||
57 | |||
58 | bool MenuLauncher::onModRelease(int /*modcode*/) | ||
59 | { | ||
60 | if(m_pMenu->isVisible()){ | ||
61 | QTimer::singleShot(0, this, SLOT(select())); | ||
62 | return(true); | ||
63 | } else { | ||
64 | return(false); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | QString MenuLauncher::getMenuText(const QString& key, const QString& name) | ||
69 | { | ||
70 | QRegExp rx("^[0-9]+_"); | ||
71 | QString text; | ||
72 | QString ackey; | ||
73 | int len; | ||
74 | if(rx.match(key, 0, &len) == 0){ | ||
75 | ackey = key.mid(len); | ||
76 | } else { | ||
77 | ackey = key; | ||
78 | } | ||
79 | if(ackey.length() == 1){ | ||
80 | text = name; | ||
81 | text.append("(&"); | ||
82 | text.append(ackey); | ||
83 | text.append(")"); | ||
84 | } else { | ||
85 | text = ackey; | ||
86 | } | ||
87 | return(text); | ||
88 | } | ||
89 | |||
90 | int MenuLauncher::buildMenu(const QString& section, | ||
91 | QPopupMenu* pMenu, int& id) | ||
92 | { | ||
93 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
94 | |||
95 | if(m_oMenuList.contains(pMenu)){ | ||
96 | /* ̵¸Â¥ë¡¼¥×ËÉ»ß */ | ||
97 | return(0); | ||
98 | } | ||
99 | m_oMenuList.append(pMenu); | ||
100 | |||
101 | QString oldgroup = cfg.getGroup(); | ||
102 | |||
103 | QString group = section; | ||
104 | group[0] = group[0].upper(); | ||
105 | |||
106 | cfg.setGroup(group); | ||
107 | |||
108 | QStringList apps = cfg.getKeys(); | ||
109 | int cnt = 0; | ||
110 | if(apps.isEmpty() == false){ | ||
111 | for(QStringList::Iterator it=apps.begin(); | ||
112 | it!=apps.end(); ++it){ | ||
113 | QStringList args = cfg.readListEntry(*it, '\t'); | ||
114 | LnkWrapper lnk(args); | ||
115 | if(lnk.isValid()){ | ||
116 | cnt++; | ||
117 | QString text = getMenuText(*it, lnk.instance().name()); | ||
118 | if(args[0] == "@menu"){ | ||
119 | QPopupMenu* pSubMenu = initMenu(m_pTopMenu, args[1]); | ||
120 | pMenu->insertItem(lnk.instance().pixmap(), text, | ||
121 | pSubMenu, id); | ||
122 | m_oItemList.append(ItemInfo(section)); | ||
123 | id++; | ||
124 | buildMenu(args[1], pSubMenu, id); | ||
125 | } else { | ||
126 | pMenu->insertItem(lnk.instance().pixmap(), text, id); | ||
127 | m_oItemList.append(ItemInfo(section, *it)); | ||
128 | id++; | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | cfg.setGroup(oldgroup); | ||
134 | return(cnt); | ||
135 | } | ||
136 | |||
137 | void MenuLauncher::clearSubMenu() | ||
138 | { | ||
139 | for(QValueList<QPopupMenu*>::Iterator it=m_oMenuList.begin(); | ||
140 | it!=m_oMenuList.end(); ++it){ | ||
141 | if(*it != m_pTopMenu){ | ||
142 | delete *it; | ||
143 | } | ||
144 | } | ||
145 | m_oMenuList.clear(); | ||
146 | m_oItemList.clear(); | ||
147 | } | ||
148 | |||
149 | int MenuLauncher::buildMenu(bool force) | ||
150 | { | ||
151 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
152 | if(!force && m_lastmodify == cfg.lastRead()){ | ||
153 | return(m_pTopMenu->count()); | ||
154 | } | ||
155 | qDebug("buildMenu"); | ||
156 | |||
157 | QString oldgroup = cfg.getGroup(); | ||
158 | |||
159 | cfg.setGroup("Global"); | ||
160 | m_submenuTimeout = cfg.readNumEntry("SubMenuTimeout", 500); | ||
161 | |||
162 | if(m_pTopMenu){ | ||
163 | delete m_pTopMenu; | ||
164 | } | ||
165 | m_pMenu = m_pTopMenu = initMenu(g_Widget, kind()); | ||
166 | m_oLastId.clear(); | ||
167 | m_oMenuList.clear(); | ||
168 | m_oItemList.clear(); | ||
169 | |||
170 | MenuTitle* pTitle = new MenuTitle("MenuLauncher", | ||
171 | m_pTopMenu->font(), kind()); | ||
172 | m_pTopMenu->insertItem(pTitle); | ||
173 | |||
174 | int id = 0; | ||
175 | int cnt = buildMenu(kind(), m_pTopMenu, id); | ||
176 | if(cnt > 0){ | ||
177 | m_lastmodify = cfg.lastRead(); | ||
178 | } | ||
179 | |||
180 | cfg.setGroup(oldgroup); | ||
181 | return(cnt); | ||
182 | } | ||
183 | |||
184 | void MenuLauncher::show() | ||
185 | { | ||
186 | m_enablePopup = false; | ||
187 | int cnt = buildMenu(); | ||
188 | if(cnt > 0){ | ||
189 | m_pMenu = m_pTopMenu; | ||
190 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
191 | cfg.setGroup("Style"); | ||
192 | int x,y; | ||
193 | QString key = "Position_" + kind(); | ||
194 | if(cfg.hasKey(key)){ | ||
195 | const QStringList& list = cfg.readListEntry(key, ','); | ||
196 | x = list[0].toInt(); | ||
197 | y = list[1].toInt(); | ||
198 | } else { | ||
199 | x = (qt_screen->width() - m_pTopMenu->sizeHint().width()) / 2; | ||
200 | y = (qt_screen->height() - m_pTopMenu->sizeHint().height()) / 2; | ||
201 | } | ||
202 | QPoint pos(x, y); | ||
203 | m_pTopMenu->popup(pos); | ||
204 | m_pTopMenu->setActiveItem(1); | ||
205 | } | ||
206 | m_isShowing = false; | ||
207 | } | ||
208 | |||
209 | void MenuLauncher::next() | ||
210 | { | ||
211 | int index = m_pMenu->indexOf(m_id); | ||
212 | index++; | ||
213 | if(index >= (signed int)m_pMenu->count()){ | ||
214 | if(m_pMenu == m_pTopMenu){ | ||
215 | index = 1; | ||
216 | } else { | ||
217 | index = 0; | ||
218 | } | ||
219 | } | ||
220 | m_pMenu->setActiveItem(index); | ||
221 | m_id = m_pMenu->idAt(index); | ||
222 | } | ||
223 | |||
224 | void MenuLauncher::select() | ||
225 | { | ||
226 | if(m_pMenu->isVisible()){ | ||
227 | QMenuItem* item = m_pMenu->findItem(m_id); | ||
228 | int index = m_pMenu->indexOf(m_id); | ||
229 | QPopupMenu* p = m_pMenu; | ||
230 | //m_pMenu->activateItemAt(index); | ||
231 | if(item && item->popup()){ | ||
232 | m_pMenu = item->popup(); | ||
233 | } | ||
234 | p->activateItemAt(index); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | void MenuLauncher::select(int id) | ||
239 | { | ||
240 | if(id >= 0 && m_oItemList[id].entry != QString::null){ | ||
241 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
242 | |||
243 | cfg.setGroup("Global"); | ||
244 | int delay = cfg.readNumEntry("DelayExec", 100); | ||
245 | |||
246 | QString group = m_oItemList[id].group; | ||
247 | group[0] = group[0].upper(); | ||
248 | cfg.setGroup(group); | ||
249 | |||
250 | //QStringList args = cfg.readListEntry(m_oItemList[id].entry, '\t'); | ||
251 | m_args = cfg.readListEntry(m_oItemList[id].entry, '\t'); | ||
252 | |||
253 | #if 0 | ||
254 | LnkWrapper lnk(args); | ||
255 | if(lnk.isValid()){ | ||
256 | lnk.instance().execute(); | ||
257 | } | ||
258 | #else | ||
259 | QTimer::singleShot(delay, this, SLOT(execute())); | ||
260 | #endif | ||
261 | } | ||
262 | m_pMenu = m_pTopMenu; | ||
263 | m_id = -1; | ||
264 | } | ||
265 | |||
266 | void MenuLauncher::execute() | ||
267 | { | ||
268 | LnkWrapper lnk(m_args); | ||
269 | if(lnk.isValid()){ | ||
270 | lnk.instance().execute(); | ||
271 | } | ||
272 | m_args.clear(); | ||
273 | } | ||
274 | |||
275 | void MenuLauncher::highlight(int id) | ||
276 | { | ||
277 | if(m_pMenu && m_pMenu->isVisible()){ | ||
278 | m_id = id; | ||
279 | if(m_enablePopup){ | ||
280 | QMenuItem* item = m_pMenu->findItem(m_id); | ||
281 | if(item && item->popup()){ | ||
282 | if(m_submenuTimeout > 0){ | ||
283 | m_pTimer->start(m_submenuTimeout, true); | ||
284 | } | ||
285 | } else { | ||
286 | m_pTimer->stop(); | ||
287 | } | ||
288 | } else { | ||
289 | /* ¥á¥Ë¥å¡¼É½¼¨Ä¾¸å¤Ï¥Ý¥Ã¥×¥¢¥Ã¥×¤·¤Ê¤¤ */ | ||
290 | m_enablePopup = true; | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | |||
295 | bool MenuLauncher::eventFilter(QObject* o, QEvent* e) | ||
296 | { | ||
297 | if(m_pTopMenu->isVisible()){ | ||
298 | QKeyEvent* ke = (QKeyEvent*)e; | ||
299 | switch(e->type()){ | ||
300 | case QEvent::Accel: | ||
301 | if(ke->key() == Qt::Key_Space | ||
302 | && ke->isAutoRepeat() == false){ | ||
303 | select(); | ||
304 | } | ||
305 | break; | ||
306 | case QEvent::FocusIn: | ||
307 | //qDebug("FocusIn[%p][%p]", o, m_pMenu); | ||
308 | m_pMenu = (QPopupMenu*)o; | ||
309 | if(m_oLastId.contains(o)){ | ||
310 | m_id = m_oLastId[o]; | ||
311 | } | ||
312 | m_pMenu->updateItem(m_id); | ||
313 | break; | ||
314 | case QEvent::FocusOut: | ||
315 | //qDebug("FocusOut[%p][%p]", o, m_pMenu); | ||
316 | m_oLastId[o] = m_id; | ||
317 | break; | ||
318 | default: | ||
319 | //qDebug(">>>>> [%p][%d] <<<<<", o, e->type()); | ||
320 | break; | ||
321 | } | ||
322 | } | ||
323 | return QObject::eventFilter(o, e); | ||
324 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.h b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.h new file mode 100644 index 0000000..5eebe78 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.h | |||
@@ -0,0 +1,110 @@ | |||
1 | #ifndef _MENU_LAUNCHER_H_ | ||
2 | #define _MENU_LAUNCHER_H_ | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qvaluelist.h> | ||
7 | #include <qwindowsystem_qws.h> | ||
8 | #define INCLUDE_MENUITEM_DEF | ||
9 | #include <qpopupmenu.h> | ||
10 | #include <qpoint.h> | ||
11 | #include <qtimer.h> | ||
12 | #include <qgfx_qws.h> | ||
13 | |||
14 | #include <qpe/global.h> | ||
15 | #include <qpe/applnk.h> | ||
16 | #include <qpe/config.h> | ||
17 | #include <qpe/qpeapplication.h> | ||
18 | |||
19 | #include "ExtensionInterface.h" | ||
20 | #include "MenuTitle.h" | ||
21 | #include "KeyNames.h" | ||
22 | #include "ConfigEx.h" | ||
23 | #include "LnkWrapper.h" | ||
24 | #include "QPopupMenuEx.h" | ||
25 | |||
26 | struct ItemInfo{ | ||
27 | ItemInfo(QString g=QString::null, QString e=QString::null) | ||
28 | : group(g), entry(e){} | ||
29 | QString group; | ||
30 | QString entry; | ||
31 | }; | ||
32 | |||
33 | class MenuLauncher : public QObject, public ExtensionInterface | ||
34 | { | ||
35 | Q_OBJECT | ||
36 | public: | ||
37 | MenuLauncher(const QString& kind = "menu"); | ||
38 | virtual ~MenuLauncher(); | ||
39 | |||
40 | typedef QValueList<ItemInfo> ItemList; | ||
41 | |||
42 | virtual bool onKeyPress(int keycode); | ||
43 | virtual bool onModRelease(int modcode); | ||
44 | virtual int getKeycode() | ||
45 | { | ||
46 | return(m_keycode); | ||
47 | } | ||
48 | virtual int getKeymask() | ||
49 | { | ||
50 | return(m_keymask); | ||
51 | } | ||
52 | virtual const QValueList<int>& getModcodes() | ||
53 | { | ||
54 | return(m_modcodes); | ||
55 | } | ||
56 | virtual void setKeycode(int keycode) | ||
57 | { | ||
58 | m_keycode = keycode; | ||
59 | } | ||
60 | virtual void setKeymask(int keymask) | ||
61 | { | ||
62 | m_keymask = keymask; | ||
63 | } | ||
64 | virtual void setModcodes(const QValueList<int>& modcodes) | ||
65 | { | ||
66 | m_modcodes = modcodes; | ||
67 | } | ||
68 | virtual const QString& kind() | ||
69 | { | ||
70 | return(m_kind); | ||
71 | } | ||
72 | public slots: | ||
73 | void show(); | ||
74 | void select(); | ||
75 | void select(int id); | ||
76 | void highlight(int id); | ||
77 | private: | ||
78 | int m_keycode; | ||
79 | int m_keymask; | ||
80 | QString m_kind; | ||
81 | QValueList<int> m_modcodes; | ||
82 | |||
83 | int m_submenuTimeout; | ||
84 | bool m_isShowing; | ||
85 | bool m_enablePopup; | ||
86 | int m_id; | ||
87 | QPopupMenu* m_pMenu; | ||
88 | QPopupMenu* m_pTopMenu; | ||
89 | QDateTime m_lastmodify; | ||
90 | |||
91 | QMap<QObject*, int> m_oLastId; | ||
92 | QValueList<QPopupMenu*> m_oMenuList; | ||
93 | ItemList m_oItemList; | ||
94 | QTimer* m_pTimer; | ||
95 | |||
96 | QStringList m_args; | ||
97 | |||
98 | QString getMenuText(const QString& key, const QString& name); | ||
99 | QPopupMenu* initMenu(QWidget* parent, const QString& name); | ||
100 | int buildMenu(bool force=false); | ||
101 | int buildMenu(const QString& section, QPopupMenu* pMenu, int& id); | ||
102 | void clearSubMenu(); | ||
103 | void init(); | ||
104 | void next(); | ||
105 | private slots: | ||
106 | bool eventFilter(QObject* o, QEvent* e); | ||
107 | void execute(); | ||
108 | }; | ||
109 | |||
110 | #endif /* _MENU_LAUNCHER_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.cpp new file mode 100644 index 0000000..d8fd2a3 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.cpp | |||
@@ -0,0 +1,67 @@ | |||
1 | #include "MenuTitle.h" | ||
2 | |||
3 | MenuTitle::MenuTitle(const QString& s, const QFont& f, const QString& k) | ||
4 | { | ||
5 | font = f; | ||
6 | kind = k; | ||
7 | |||
8 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
9 | |||
10 | const QString curGroup = cfg.getGroup(); | ||
11 | cfg.setGroup("Style"); | ||
12 | |||
13 | caption = cfg.readEntry("Caption_" + k, s); | ||
14 | cfg.setGroup(curGroup); | ||
15 | } | ||
16 | |||
17 | bool MenuTitle::fullSpan() const | ||
18 | { | ||
19 | return(true); | ||
20 | } | ||
21 | |||
22 | bool MenuTitle::isSeparator() const | ||
23 | { | ||
24 | return(true); | ||
25 | } | ||
26 | |||
27 | void MenuTitle::paint(QPainter* p, const QColorGroup& cg, bool /*act*/, | ||
28 | bool /*enabled*/, int x, int y, int w, int h) | ||
29 | { | ||
30 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
31 | const QString& curGroup = cfg.getGroup(); | ||
32 | |||
33 | cfg.setGroup("Style"); | ||
34 | |||
35 | QString name; | ||
36 | QColor color; | ||
37 | |||
38 | p->setFont(font); | ||
39 | |||
40 | /* set fontcolor */ | ||
41 | name = cfg.readEntry("FontColor_" + kind, QString::null); | ||
42 | if(name != QString::null){ | ||
43 | color.setNamedColor(name); | ||
44 | if(color.isValid()){ | ||
45 | p->setPen(color); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | /* set bgcolor */ | ||
50 | name = cfg.readEntry("BgColor_" + kind, QString::null); | ||
51 | if(name != QString::null){ | ||
52 | color.setNamedColor(name); | ||
53 | if(color.isValid() == false){ | ||
54 | color = cg.mid(); | ||
55 | } | ||
56 | } else { | ||
57 | color = cg.mid(); | ||
58 | } | ||
59 | p->fillRect(x, y, w, h, QBrush(color)); | ||
60 | p->drawText(x, y, w, h, AlignCenter, caption); | ||
61 | cfg.setGroup(curGroup); | ||
62 | } | ||
63 | |||
64 | QSize MenuTitle::sizeHint() | ||
65 | { | ||
66 | return(QFontMetrics(font).size(AlignCenter, caption)); | ||
67 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.h b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.h new file mode 100644 index 0000000..77e46a5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.h | |||
@@ -0,0 +1,29 @@ | |||
1 | #ifndef _MENU_TITLE_ITEM_H_ | ||
2 | #define _MENU_TITLE_ITEM_H_ | ||
3 | |||
4 | #include <qmenudata.h> | ||
5 | #include <qpainter.h> | ||
6 | #include <qbrush.h> | ||
7 | #include <qcolor.h> | ||
8 | #include <qpalette.h> | ||
9 | #include <qpe/config.h> | ||
10 | #include "ConfigEx.h" | ||
11 | |||
12 | class MenuTitle : public QCustomMenuItem | ||
13 | { | ||
14 | public: | ||
15 | MenuTitle(const QString& s, const QFont& f, const QString& k = "default"); | ||
16 | virtual ~MenuTitle(){} | ||
17 | |||
18 | bool fullSpan () const; | ||
19 | bool isSeparator() const; | ||
20 | void paint(QPainter* p, const QColorGroup& cg, bool act, | ||
21 | bool enabled, int x, int y, int w, int h); | ||
22 | QSize sizeHint(); | ||
23 | private: | ||
24 | QString caption; | ||
25 | QString kind; | ||
26 | QFont font; | ||
27 | }; | ||
28 | |||
29 | #endif /* _MENU_TITLE_ITEM_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/QPopupMenuEx.h b/noncore/applets/keyhelper/keyhelperapplet/extension/QPopupMenuEx.h new file mode 100644 index 0000000..16e18a1 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/QPopupMenuEx.h | |||
@@ -0,0 +1,28 @@ | |||
1 | #ifndef _QPOPUPMENUEX_H_ | ||
2 | #define _QPOPUPMENUEX_H_ | ||
3 | |||
4 | #include <qpopupmenu.h> | ||
5 | #include <qstring.h> | ||
6 | #include <qevent.h> | ||
7 | |||
8 | class QPopupMenuEx : public QPopupMenu | ||
9 | { | ||
10 | public: | ||
11 | QPopupMenuEx(QWidget* parent=0, const char* name=0) | ||
12 | : QPopupMenu(parent, name){} | ||
13 | protected: | ||
14 | void keyPressEvent(QKeyEvent* e){ | ||
15 | QChar c = e->text()[0]; | ||
16 | QKeyEvent* ke = new QKeyEvent( | ||
17 | e->type(), | ||
18 | e->key(), | ||
19 | c.lower().latin1(), | ||
20 | 0, | ||
21 | c.lower(), | ||
22 | e->isAutoRepeat()); | ||
23 | QPopupMenu::keyPressEvent(ke); | ||
24 | } | ||
25 | private: | ||
26 | }; | ||
27 | |||
28 | #endif /* _QPOPUPMENUEX_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp new file mode 100644 index 0000000..4fc9cc4 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp | |||
@@ -0,0 +1,225 @@ | |||
1 | #include "TaskSelector.h" | ||
2 | extern QWidget* g_Widget; | ||
3 | |||
4 | static const char* defkeys = | ||
5 | "QWERTYUIOPASDFGHJKLZXCVBNM1234567890"; | ||
6 | |||
7 | #define START_INDEX 1 | ||
8 | |||
9 | TaskSelector::TaskSelector(const QString& kind) : m_kind(kind) | ||
10 | { | ||
11 | qDebug("TaskSelector::TaskSelector()"); | ||
12 | m_pMenu = new QPopupMenuEx(g_Widget); | ||
13 | m_pMenu->installEventFilter(this); | ||
14 | |||
15 | m_isShowing = false; | ||
16 | m_index = START_INDEX-1; | ||
17 | connect(m_pMenu, SIGNAL(activated(int)), this, SLOT(select(int))); | ||
18 | connect(m_pMenu, SIGNAL(highlighted(int)), this, SLOT(highlight(int))); | ||
19 | } | ||
20 | |||
21 | TaskSelector::~TaskSelector() | ||
22 | { | ||
23 | qDebug("TaskSelector::~TaskSelector()"); | ||
24 | delete m_pMenu; | ||
25 | } | ||
26 | |||
27 | bool TaskSelector::onKeyPress(int /*keycode*/) | ||
28 | { | ||
29 | if(m_isShowing){ | ||
30 | qDebug("showing ..."); | ||
31 | } else if(m_pMenu->isVisible()){ | ||
32 | next(); | ||
33 | } else { | ||
34 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
35 | cfg.setGroup("Global"); | ||
36 | int delay = cfg.readNumEntry("DelayPopup", 5); | ||
37 | QTimer::singleShot(delay, this, SLOT(show())); | ||
38 | m_isShowing = true; | ||
39 | } | ||
40 | return true; | ||
41 | } | ||
42 | |||
43 | bool TaskSelector::onModRelease(int /*modcode*/) | ||
44 | { | ||
45 | if(m_pMenu->isVisible()){ | ||
46 | //m_pMenu->hide(); | ||
47 | QTimer::singleShot(0, this, SLOT(select())); | ||
48 | return(true); | ||
49 | } else { | ||
50 | return(false); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | int TaskSelector::buildMenu() | ||
55 | { | ||
56 | const AppLnk* lnk; | ||
57 | |||
58 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
59 | QString oldgroup; | ||
60 | |||
61 | oldgroup = cfg.getGroup(); | ||
62 | cfg.setGroup("Global"); | ||
63 | QString accesskeys = cfg.readEntry("AccessKeys", defkeys); | ||
64 | if(accesskeys.length() <= 0){ | ||
65 | accesskeys = defkeys; | ||
66 | } | ||
67 | cfg.setGroup(oldgroup); | ||
68 | |||
69 | /* get list */ | ||
70 | int cnt = 0; | ||
71 | m_index = START_INDEX+1; | ||
72 | m_applist.clear(); | ||
73 | m_pMenu->clear(); | ||
74 | MenuTitle* pTitle = new MenuTitle("TaskSelector", m_pMenu->font(), kind()); | ||
75 | m_pMenu->insertItem(pTitle); | ||
76 | const QList<QWSWindow>& list = qwsServer->clientWindows(); | ||
77 | QWSWindow* w; | ||
78 | for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ | ||
79 | if(w->isVisible() == false | ||
80 | || w->caption() == QString::null){ | ||
81 | continue; | ||
82 | } | ||
83 | QString app = w->client()->identity(); | ||
84 | if(app == NULL || m_applist.contains(app)){ | ||
85 | continue; | ||
86 | } | ||
87 | /* exclude "launcher" */ | ||
88 | if(app == "launcher"){ | ||
89 | if(cnt == 0){ | ||
90 | m_index--; | ||
91 | } | ||
92 | continue; | ||
93 | } | ||
94 | m_applist.append(app); | ||
95 | /* append menu */ | ||
96 | cnt++; | ||
97 | AppLnkSet* lnkSet = AppLnkManager::getInstance(); | ||
98 | lnk = lnkSet->findExec(app); | ||
99 | QString text; | ||
100 | QPixmap icon; | ||
101 | #if 0 | ||
102 | if(lnk != NULL){ | ||
103 | icon = lnk->pixmap(); | ||
104 | text = lnk->name(); | ||
105 | } else { | ||
106 | AppLnkManager::notfound(); | ||
107 | icon = QPixmap(); | ||
108 | text = w->caption(); | ||
109 | } | ||
110 | #else | ||
111 | if(lnk != NULL){ | ||
112 | icon = lnk->pixmap(); | ||
113 | if(w->caption().length() > 0){ | ||
114 | text = w->caption(); | ||
115 | } else { | ||
116 | text = lnk->name(); | ||
117 | } | ||
118 | } else { | ||
119 | AppLnkManager::notfound(); | ||
120 | icon = QPixmap(); | ||
121 | text = w->caption(); | ||
122 | } | ||
123 | #endif | ||
124 | if(cnt <= (int)accesskeys.length()){ | ||
125 | text.append("(&"); | ||
126 | text.append(accesskeys[cnt-1].upper()); | ||
127 | text.append(")"); | ||
128 | } | ||
129 | m_pMenu->insertItem(icon, text, cnt); | ||
130 | } | ||
131 | return(cnt); | ||
132 | } | ||
133 | |||
134 | void TaskSelector::show() | ||
135 | { | ||
136 | /* build task selector menu */ | ||
137 | int cnt = buildMenu(); | ||
138 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
139 | QString oldgroup = cfg.getGroup(); | ||
140 | cfg.setGroup("Global"); | ||
141 | int min = cfg.readNumEntry("SelectMenuMin", 2); | ||
142 | if(min != 1 && min != 3){ | ||
143 | min = 2; | ||
144 | } | ||
145 | cfg.setGroup(oldgroup); | ||
146 | |||
147 | if(cnt == 0){ | ||
148 | qDebug("no applications"); | ||
149 | } else if(cnt < min){ | ||
150 | //m_index = START_INDEX; | ||
151 | if(m_index > cnt){ | ||
152 | m_index = cnt; | ||
153 | } | ||
154 | QTimer::singleShot(0, this, SLOT(select())); | ||
155 | } else { | ||
156 | if(m_index > cnt){ | ||
157 | m_index = cnt; | ||
158 | } | ||
159 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
160 | cfg.setGroup("Style"); | ||
161 | int x,y; | ||
162 | QString key = "Position_" + kind(); | ||
163 | if(cfg.hasKey(key)){ | ||
164 | const QStringList& list = cfg.readListEntry(key, ','); | ||
165 | x = list[0].toInt(); | ||
166 | y = list[1].toInt(); | ||
167 | } else { | ||
168 | x = (qt_screen->width() - m_pMenu->sizeHint().width()) / 2; | ||
169 | y = (qt_screen->height() - m_pMenu->sizeHint().height()) / 2; | ||
170 | } | ||
171 | QPoint pos(x, y); | ||
172 | m_pMenu->popup(pos); | ||
173 | m_pMenu->setActiveItem(m_index); | ||
174 | } | ||
175 | m_isShowing = false; | ||
176 | } | ||
177 | |||
178 | void TaskSelector::next() | ||
179 | { | ||
180 | m_index++; | ||
181 | if(m_index > (signed int)m_applist.count()){ | ||
182 | m_index = START_INDEX; | ||
183 | } | ||
184 | m_pMenu->setActiveItem(m_index); | ||
185 | } | ||
186 | |||
187 | void TaskSelector::select() | ||
188 | { | ||
189 | //select(m_index); | ||
190 | m_pMenu->activateItemAt(m_index); | ||
191 | } | ||
192 | |||
193 | void TaskSelector::select(int index) | ||
194 | { | ||
195 | if(index > 0){ | ||
196 | Global::execute(m_applist[index-1]); | ||
197 | } | ||
198 | m_index = 0; | ||
199 | } | ||
200 | |||
201 | void TaskSelector::highlight(int index) | ||
202 | { | ||
203 | if(m_pMenu->isVisible()){ | ||
204 | m_index = index; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | bool TaskSelector::eventFilter(QObject* o, QEvent* e) | ||
209 | { | ||
210 | if(m_pMenu->isVisible()){ | ||
211 | QKeyEvent* ke = (QKeyEvent*)e; | ||
212 | switch(e->type()){ | ||
213 | case QEvent::Accel: | ||
214 | if(ke->key() == Qt::Key_Space | ||
215 | && ke->isAutoRepeat() == false){ | ||
216 | select(); | ||
217 | } | ||
218 | break; | ||
219 | default: | ||
220 | //qDebug(">>>>> [%p][%d] <<<<<", o, e->type()); | ||
221 | break; | ||
222 | } | ||
223 | } | ||
224 | return QObject::eventFilter(o, e); | ||
225 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.h b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.h new file mode 100644 index 0000000..ceb157d --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.h | |||
@@ -0,0 +1,85 @@ | |||
1 | #ifndef _TASK_SELECTOR_H_ | ||
2 | #define _TASK_SELECTOR_H_ | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qvaluelist.h> | ||
7 | #include <qwindowsystem_qws.h> | ||
8 | #include <qpopupmenu.h> | ||
9 | #include <qpoint.h> | ||
10 | #include <qtimer.h> | ||
11 | #include <qgfx_qws.h> | ||
12 | |||
13 | #include <qpe/global.h> | ||
14 | #include <qpe/applnk.h> | ||
15 | #include <qpe/config.h> | ||
16 | #include <qpe/mimetype.h> | ||
17 | |||
18 | #include "ExtensionInterface.h" | ||
19 | #include "MenuTitle.h" | ||
20 | #include "KeyNames.h" | ||
21 | #include "AppLnkManager.h" | ||
22 | #include "ConfigEx.h" | ||
23 | #include "QPopupMenuEx.h" | ||
24 | |||
25 | class TaskSelector : public QObject, public ExtensionInterface | ||
26 | { | ||
27 | Q_OBJECT | ||
28 | public: | ||
29 | TaskSelector(const QString& kind = "select"); | ||
30 | virtual ~TaskSelector(); | ||
31 | |||
32 | virtual bool onKeyPress(int keycode); | ||
33 | virtual bool onModRelease(int modcode); | ||
34 | virtual int getKeycode() | ||
35 | { | ||
36 | return(m_keycode); | ||
37 | } | ||
38 | virtual int getKeymask() | ||
39 | { | ||
40 | return(m_keymask); | ||
41 | } | ||
42 | virtual const QValueList<int>& getModcodes() | ||
43 | { | ||
44 | return(m_modcodes); | ||
45 | } | ||
46 | virtual void setKeycode(int keycode) | ||
47 | { | ||
48 | m_keycode = keycode; | ||
49 | } | ||
50 | virtual void setKeymask(int keymask) | ||
51 | { | ||
52 | m_keymask = keymask; | ||
53 | } | ||
54 | virtual void setModcodes(const QValueList<int>& modcodes) | ||
55 | { | ||
56 | m_modcodes = modcodes; | ||
57 | } | ||
58 | virtual const QString& kind() | ||
59 | { | ||
60 | return(m_kind); | ||
61 | } | ||
62 | public slots: | ||
63 | void show(); | ||
64 | void select(); | ||
65 | void select(int); | ||
66 | void highlight(int id); | ||
67 | private: | ||
68 | int m_keycode; | ||
69 | int m_keymask; | ||
70 | QString m_kind; | ||
71 | QValueList<int> m_modcodes; | ||
72 | |||
73 | bool m_isShowing; | ||
74 | int m_index; | ||
75 | QPopupMenu* m_pMenu; | ||
76 | QStringList m_applist; | ||
77 | QString m_accesskeys; | ||
78 | |||
79 | int buildMenu(); | ||
80 | void next(); | ||
81 | private slots: | ||
82 | bool eventFilter(QObject* o, QEvent* e); | ||
83 | }; | ||
84 | |||
85 | #endif /* _TASK_SELECTOR_H_ */ | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.cpp new file mode 100644 index 0000000..c51eba5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.cpp | |||
@@ -0,0 +1,58 @@ | |||
1 | #include "TaskSwitcher.h" | ||
2 | |||
3 | TaskSwitcher::TaskSwitcher(const QString& kind) : m_kind(kind) | ||
4 | { | ||
5 | qDebug("TaskSwitcher::TaskSwitcher()"); | ||
6 | } | ||
7 | |||
8 | TaskSwitcher::~TaskSwitcher() | ||
9 | { | ||
10 | qDebug("TaskSwitcher::~TaskSwitcher()"); | ||
11 | } | ||
12 | |||
13 | bool TaskSwitcher::onKeyPress(int /*keycode*/) | ||
14 | { | ||
15 | if(m_applist.isEmpty()){ | ||
16 | /* get list */ | ||
17 | const QList<QWSWindow>& list = qwsServer->clientWindows(); | ||
18 | QWSWindow* w; | ||
19 | for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ | ||
20 | if(w->isVisible()){ | ||
21 | QString app = w->client()->identity(); | ||
22 | qDebug("applist[%s]", app.latin1()); | ||
23 | if(app != NULL && m_applist.contains(app) == false){ | ||
24 | m_applist.append(app); | ||
25 | } | ||
26 | } | ||
27 | } | ||
28 | m_appit = m_applist.begin(); | ||
29 | } | ||
30 | if(m_applist.count() > 1){ | ||
31 | /* switch next */ | ||
32 | next(); | ||
33 | if(*m_appit == "launcher"){ | ||
34 | next(); | ||
35 | } | ||
36 | Global::execute(*m_appit); | ||
37 | } else if(m_applist.count() == 1 | ||
38 | && *m_appit != "launcher"){ | ||
39 | Global::execute(*m_appit); | ||
40 | } else { | ||
41 | qDebug("no applications"); | ||
42 | } | ||
43 | return(true); | ||
44 | } | ||
45 | |||
46 | bool TaskSwitcher::onModRelease(int /*keycode*/) | ||
47 | { | ||
48 | m_applist.clear(); | ||
49 | return(false); | ||
50 | } | ||
51 | |||
52 | void TaskSwitcher::next() | ||
53 | { | ||
54 | ++m_appit; | ||
55 | if(m_appit == m_applist.end()){ | ||
56 | m_appit = m_applist.begin(); | ||
57 | } | ||
58 | } | ||
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.h b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.h new file mode 100644 index 0000000..7bbde55 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.h | |||
@@ -0,0 +1,61 @@ | |||
1 | #ifndef _TASK_SWITCHER_H_ | ||
2 | #define _TASK_SWITCHER_H_ | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qvaluelist.h> | ||
7 | #include <qwindowsystem_qws.h> | ||
8 | |||
9 | #include <qpe/global.h> | ||
10 | |||
11 | #include "ExtensionInterface.h" | ||
12 | |||
13 | class TaskSwitcher : public ExtensionInterface | ||
14 | { | ||
15 | public: | ||
16 | TaskSwitcher(const QString& kind = "switch"); | ||
17 | virtual ~TaskSwitcher(); | ||
18 | |||
19 | virtual bool onKeyPress(int keycode); | ||
20 | virtual bool onModRelease(int modcode); | ||
21 | virtual int getKeycode() | ||
22 | { | ||
23 | return(m_keycode); | ||
24 | } | ||
25 | virtual int getKeymask() | ||
26 | { | ||
27 | return(m_keymask); | ||
28 | } | ||
29 | virtual const QValueList<int>& getModcodes() | ||
30 | { | ||
31 | return(m_modcodes); | ||
32 | } | ||
33 | virtual void setKeycode(int keycode) | ||
34 | { | ||
35 | m_keycode = keycode; | ||
36 | } | ||
37 | virtual void setKeymask(int keymask) | ||
38 | { | ||
39 | m_keymask = keymask; | ||
40 | } | ||
41 | virtual void setModcodes(const QValueList<int>& modcodes) | ||
42 | { | ||
43 | m_modcodes = modcodes; | ||
44 | } | ||
45 | virtual const QString& kind() | ||
46 | { | ||
47 | return(m_kind); | ||
48 | } | ||
49 | private: | ||
50 | int m_keycode; | ||
51 | int m_keymask; | ||
52 | QString m_kind; | ||
53 | QValueList<int> m_modcodes; | ||
54 | |||
55 | QStringList m_applist; | ||
56 | QStringList::Iterator m_appit; | ||
57 | |||
58 | void next(); | ||
59 | }; | ||
60 | |||
61 | #endif /* _TASK_SWITCHER_H_ */ | ||