84 files changed, 8165 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/config.in b/noncore/applets/keyhelper/config.in new file mode 100644 index 0000000..5bba19a --- a/dev/null +++ b/noncore/applets/keyhelper/config.in @@ -0,0 +1,4 @@ + config KEYHELPER + boolean "keyhelper applet (Config keyboard layout on the fly)" + default "n" + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE diff --git a/noncore/applets/keyhelper/keyhelper.pro b/noncore/applets/keyhelper/keyhelper.pro new file mode 100644 index 0000000..483845d --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelper.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = keyhelperapplet keyhelperconf diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp new file mode 100644 index 0000000..3c2298e --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp @@ -0,0 +1,94 @@ +#include "AnyLnk.h" +#include "KHUtil.h" + +void AnyLnk::loadPixmap() +{ + if(m_params.count() >= 3){ + QString& str = m_params[2]; + QImage image = Resource::loadImage(str); + if(image.isNull() == false){ + const QSize& size = AppLnkManager::getIconSize(); + m_pixmap.convertFromImage( + image.smoothScale(size.width(), size.height()) ); + } + } +} + +void AnyLnk::parseText() +{ + if(m_params.count() >= 2){ + QString& str = m_params[1]; + if(str != QString::null && str.length() > 0){ + replaceKeyword(str); + replaceDate(str); + } + } +} + +void AnyLnk::replaceText(QString& str, const QString& s1, const QString& s2) +{ + int index = 0; + int idx; + int len = s1.length(); + idx = str.find(s1, index); + for(;;){ + idx = str.find(s1, index); + if(idx < 0) break; + str.replace(idx, len, s2); + index = idx; + } +} + +void AnyLnk::replaceDate(QString& str) +{ + time_t t; + struct tm lct; + char buf[4096]; + int nLen; + QString group; + + t = ::time(NULL); + ::localtime_r(&t, &lct); + + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + group = cfg.getGroup(); + cfg.setGroup("Global"); + QString charset = cfg.readEntry("SystemCharSet", "eucJP"); + if(charset.length() == 0){ + charset = "eucJP"; + } + cfg.setGroup(group); + + QTextCodec* codec = QTextCodec::codecForName(charset); + if(codec == NULL){ + codec = QTextCodec::codecForLocale(); + } + QTextDecoder* decoder = codec->makeDecoder(); + QTextEncoder* encoder = codec->makeEncoder(); + nLen = str.length(); + QCString localeString = encoder->fromUnicode(str, nLen); + + memset(buf, '\0', sizeof(buf)); + int n = ::strftime(buf, sizeof(buf), localeString, &lct); + if(n > 0){ + str = decoder->toUnicode(buf, n); + } + delete decoder; + delete encoder; +} + +void AnyLnk::replaceKeyword(QString& str) +{ + QString txt; + /* clipboard text */ + QClipboard* cb = QApplication::clipboard(); + if(cb == NULL){ + txt == ""; + } else { + txt = cb->text(); + } + replaceText(str, "%clipboard%", txt); + /* current app */ + txt = KHUtil::currentApp(); + replaceText(str, "%currentapp%", txt); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.h new file mode 100644 index 0000000..9853942 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.h @@ -0,0 +1,45 @@ +#ifndef _ANYLNK_H_ +#define _ANYLNK_H_ + +#include <time.h> + +#include <qstring.h> +#include <qstringlist.h> +#include <qpixmap.h> +#include <qimage.h> +#include <qclipboard.h> +#include <qtextcodec.h> + +#include <qpe/qpeapplication.h> +#include <qpe/resource.h> + +#include "AppLnkManager.h" +#include "ConfigEx.h" + +class AnyLnk +{ +public: + AnyLnk(){} + AnyLnk(const QStringList& params){ + m_params = params; + loadPixmap(); + } + virtual ~AnyLnk(){ + } + virtual bool isValid() = 0; + virtual void execute() = 0; + virtual QString name() = 0; + virtual const QPixmap& pixmap() = 0; + +protected: + QStringList m_params; + QPixmap m_pixmap; + + virtual void loadPixmap(); + virtual void parseText(); + virtual void replaceText(QString& str, const QString& s1, const QString& s2); + virtual void replaceDate(QString& str); + virtual void replaceKeyword(QString& str); +}; + +#endif /* _ANYLNK_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkManager.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkManager.cpp new file mode 100644 index 0000000..5e244a4 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkManager.cpp @@ -0,0 +1,5 @@ +#include "AppLnkManager.h" + +AppLnkSet* AppLnkManager::m_pLnkSet = NULL; +QSize AppLnkManager::m_oIconSize; +bool AppLnkManager::m_notfound = true; diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkManager.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkManager.h new file mode 100644 index 0000000..8446578 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkManager.h @@ -0,0 +1,56 @@ +#ifndef _APPLNK_MANAGER_H_ +#define _APPLNK_MANAGER_H_ + +#include <qsize.h> + +#include <qpe/applnk.h> +#include <qpe/mimetype.h> + +class AppLnkManager +{ +public: + AppLnkManager(){ + } + ~AppLnkManager(){ + if(m_pLnkSet) delete m_pLnkSet; + } + static void init(bool force=false){ + if(m_notfound || force){ + if(m_pLnkSet){ + delete m_pLnkSet; + } + qDebug("AppLnkManager::init()"); + m_pLnkSet = new AppLnkSet(MimeType::appsFolderName()); + m_notfound = false; + } + } + static AppLnkSet* getInstance(){ + if(m_pLnkSet == NULL){ + init(true); + } + return(m_pLnkSet); + } + static const QSize& getIconSize(){ + if(m_oIconSize.isValid()){ + return(m_oIconSize); + } + const QList<AppLnk>& lnkList = getInstance()->children(); + QListIterator<AppLnk> it(lnkList); + for(; it.current(); ++it){ + if((*it)->pixmap().isNull() == false){ + m_oIconSize = (*it)->pixmap().size(); + break; + } + } + return(m_oIconSize); + } + static void notfound(){ + m_notfound = true; + } +private: + static bool m_notfound; + static AppLnkSet* m_pLnkSet; + static QSize m_oIconSize; +}; + +#endif /* _APPLNK_MANAGER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkWrapper.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkWrapper.cpp new file mode 100644 index 0000000..1c3dbfe --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkWrapper.cpp @@ -0,0 +1,43 @@ +#ifndef _APPLNK_WRAPPER_H_ +#define _APPLNK_WRAPPER_H_ + +#include <qpe/qpeapplication.h> +#include <qpe/applnk.h> +#include "AnyLnk.h" + +class AppLnkWrapper : public AnyLnk +{ +public: + AppLnkWrapper(){} + AppLnkWrapper(const QStringList& params) + : AnyLnk(params) + { + m_pLnk = new AppLnk(QPEApplication::qpeDir() + + "apps/" + m_params[0] + ".desktop"); + } + virtual ~AppLnkWrapper(){ + delete m_pLnk; + } + + virtual bool isValid() { + return(m_pLnk->isValid()); + } + virtual void execute(){ + parseText(); + m_pLnk->execute(m_params[1]); + } + virtual QString name() { + return(m_pLnk->name()); + } + virtual const QPixmap& pixmap(){ + if(m_pixmap.isNull()){ + return(m_pLnk->pixmap()); + } else { + return(m_pixmap); + } + } +protected: + AppLnk* m_pLnk; +}; + +#endif /* _APPLNK_WRAPPER_H_ */
\ No newline at end of file diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkWrapper.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkWrapper.h new file mode 100644 index 0000000..6907dbe --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AppLnkWrapper.h @@ -0,0 +1,44 @@ +#ifndef _APPLNK_WRAPPER_H_ +#define _APPLNK_WRAPPER_H_ + +#include <qpe/qpeapplication.h> +#include <qpe/applnk.h> +#include "AnyLnk.h" + +class AppLnkWrapper : public AnyLnk +{ +public: + AppLnkWrapper(){} + AppLnkWrapper(const QStringList& params) + : AnyLnk(params) + { + m_pLnk = new AppLnk(QPEApplication::qpeDir() + + "apps/" + m_params[0] + ".desktop"); + } + virtual ~AppLnkWrapper(){ + delete m_pLnk; + } + + virtual bool isValid() { + return(m_pLnk->isValid()); + } + virtual void execute(){ + parseText(); + m_pLnk->execute(m_params[1]); + } + virtual QString name() { + return(m_pLnk->name()); + } + virtual const QPixmap& pixmap(){ + if(m_pixmap.isNull()){ + return(m_pLnk->pixmap()); + } else { + return(m_pixmap); + } + } +protected: + AppLnk* m_pLnk; +}; + +#endif /* _APPLNK_WRAPPER_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/DocLnkWrapper.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/DocLnkWrapper.h new file mode 100644 index 0000000..d6f2be5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/DocLnkWrapper.h @@ -0,0 +1,47 @@ +#ifndef _DOCLNK_WRAPPER_H_ +#define _DOCLNK_WRAPPER_H_ + +#include <qpe/applnk.h> +#include "AnyLnk.h" + +class DocLnkWrapper : public AnyLnk +{ +public: + DocLnkWrapper(){} + DocLnkWrapper(const QStringList& params) + : AnyLnk(params) + { + m_pLnk = new DocLnk(m_params[0], false); + } + virtual ~DocLnkWrapper(){ + delete m_pLnk; + } + + virtual bool isValid() { + if(m_pLnk->exec().length() > 0){ + return(true); + } else { + return(false); + } + } + virtual void execute(){ + parseText(); + m_pLnk->execute(m_params[1]); + } + virtual QString name() { + return(m_pLnk->name()); + } + virtual const QPixmap& pixmap(){ + if(m_pixmap.isNull()){ + return(m_pLnk->pixmap()); + } else { + return(m_pixmap); + } + } +protected: + DocLnk* m_pLnk; +}; + +#endif /* _DOCLNK_WRAPPER_H_ */ + + diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/ExecLnk.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ExecLnk.h new file mode 100644 index 0000000..7e595df --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ExecLnk.h @@ -0,0 +1,38 @@ +#ifndef _EXECLNK_H_ +#define _EXECLNK_H_ + +#include <qpe/qpeapplication.h> + +#include "AnyLnk.h" +#include "ProcessInvoker.h" + +class ExecLnk : public AnyLnk +{ +public: + ExecLnk(){} + ExecLnk(const QStringList& params) + : AnyLnk(params){} + virtual ~ExecLnk() { + } + + virtual bool isValid() { + return(true); + } + virtual void execute() { + parseText(); + ProcessInvoker& pi = ProcessInvoker::getInstance(); + pi.setArguments(m_params[1]); + pi.setNotify(); + pi.run(); + } + virtual QString name() { + return("exec"); + } + virtual const QPixmap& pixmap() { + return(m_pixmap); + } +protected: +}; + +#endif /* _EXECLNK_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/LnkWrapper.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/LnkWrapper.cpp new file mode 100644 index 0000000..39806e5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/LnkWrapper.cpp @@ -0,0 +1,32 @@ +#include "LnkWrapper.h" + +LnkWrapper::LnkWrapper(const QStringList& params) +{ + if(params[0][0] == '/'){ + qDebug("create DocLnk instance"); + m_pLnk = new DocLnkWrapper(params); + } else if(params[0] == "@exec"){ + qDebug("create ExecLnk instance"); + m_pLnk = new ExecLnk(params); + } else if(params[0] == "@qcop"){ + qDebug("create QCopLnk instance"); + m_pLnk = new QCopLnk(params); + } else if(params[0] == "@text"){ + qDebug("create TextLnk instance"); + m_pLnk = new TextLnk(params); + } else if(params[0] == "@menu"){ + qDebug("create MenuLnk instance"); + m_pLnk = new MenuLnk(params); + } else { + qDebug("create AppLnk instance"); + m_pLnk = new AppLnkWrapper(params); + } +} + +LnkWrapper::~LnkWrapper() +{ + if(m_pLnk){ + delete m_pLnk; + } +} + diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/LnkWrapper.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/LnkWrapper.h new file mode 100644 index 0000000..6b9536b --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/LnkWrapper.h @@ -0,0 +1,33 @@ +#ifndef _LNK_WRAPPER_H_ +#define _LNK_WRAPPER_H_ + +#include <qstring.h> +#include <qstringlist.h> + +#include <qpe/applnk.h> + +#include "AppLnkWrapper.h" +#include "DocLnkWrapper.h" +#include "ExecLnk.h" +#include "QCopLnk.h" +#include "TextLnk.h" +#include "MenuLnk.h" + +class LnkWrapper +{ +public: + LnkWrapper(const QStringList& params); + virtual ~LnkWrapper(); + + bool isValid(){ + return(m_pLnk && m_pLnk->isValid()); + } + AnyLnk& instance(){ + return(*m_pLnk); + } +private: + AnyLnk* m_pLnk; +}; + +#endif /* _LNK_WRAPPER_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/MenuLnk.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/MenuLnk.h new file mode 100644 index 0000000..19f75d6 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/MenuLnk.h @@ -0,0 +1,41 @@ +#ifndef _MENULNK_H_ +#define _MENULNK_H_ + +#include <qpe/qpeapplication.h> + +#include "AnyLnk.h" +#include "ConfigEx.h" + +class MenuLnk : public AnyLnk +{ +public: + MenuLnk(){} + MenuLnk(const QStringList& params) + : AnyLnk(params){} + virtual ~MenuLnk() { + } + + virtual bool isValid() { + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + QString group = cfg.getGroup(); + cfg.setGroup(name()); + bool valid = (cfg.getKeys().isEmpty() == false); + cfg.setGroup(group); + return(valid); + } + virtual void execute() { + } + virtual QString name() { + QString group; + group = m_params[1]; + group[0] = group[0].upper(); + return(group); + } + virtual const QPixmap& pixmap() { + return(m_pixmap); + } +protected: +}; + +#endif /* _MENULNK_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp new file mode 100644 index 0000000..09605bd --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.cpp @@ -0,0 +1,424 @@ +#include "ProcessInvoker.h" + +static ProcessInvoker* g_this; +/* ------------------------------------------------------------------------ */ +/* static functions */ +/* ------------------------------------------------------------------------ */ + +static Sigfunc* setSignalHandler(int signo, Sigfunc* handler) +{ + struct sigaction act,oact; + + act.sa_handler = handler; + ::sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif + if(::sigaction(signo, &act, &oact) < 0){ + return(NULL); + } + return(oact.sa_handler); +} + +static void childHandler(int /*signo*/) +{ + pid_t pid; + int status; + while((pid = ::waitpid(-1, &status, WNOHANG)) > 0){ + if(pid == g_this->m_child){ + g_this->notifyFinish(status); + } + } +} + +/* ------------------------------------------------------------------------ */ +/* ProcessInvoker Class : parent process */ +/* ------------------------------------------------------------------------ */ +ProcessInvoker::ProcessInvoker() +{ + g_this = this; + m_isRunning = false; + m_child = 0; + m_defChildHandler = SIG_DFL; + m_pTimer = new QTimer(this); + m_stdfd[0] = m_stdfd[1] = -1; + m_errfd[0] = m_errfd[1] = -1; + connect(m_pTimer, SIGNAL(timeout()), + this, SLOT(readOutputs())); +} + +ProcessInvoker::~ProcessInvoker() +{ + qDebug("ProcessInvoker::~ProcessInvoker()"); +} + +bool ProcessInvoker::openPipe() +{ + if(m_stdfd[0] >= 0) closePipe(m_stdfd, 0); + if(m_stdfd[1] >= 0) closePipe(m_stdfd, 1); + if(::pipe(m_stdfd) < 0){ + return(false); + } + if(m_errfd[0] >= 0) closePipe(m_errfd, 0); + if(m_errfd[1] >= 0) closePipe(m_errfd, 1); + if(::pipe(m_errfd) < 0){ + closePipe(m_stdfd); + return(false); + } + m_maxfdp1 = m_stdfd[0]; + if(m_errfd[0] > m_maxfdp1){ + m_maxfdp1 = m_errfd[0]; + } + m_maxfdp1++; + return(true); +} + +void ProcessInvoker::closePipe(int fd[], int n) +{ + if(fd == NULL){ + closePipe(m_stdfd, n); + closePipe(m_errfd, n); + } else { + if(n != 1 && fd[0] >= 0){ + ::close(fd[0]); + fd[0] = -1; + } + if(n != 0 && fd[1] >= 0){ + ::close(fd[1]); + fd[1] = -1; + } + } +} + +void ProcessInvoker::setRunning(int pid) +{ + m_child = pid; + m_isRunning = true; +} + +bool ProcessInvoker::run(const QString& args) +{ + //setArguments(KHUtil::parseArgs(args)); + setArguments(StringParser::split(' ', args)); + return(run()); +} + +bool ProcessInvoker::run() +{ + if(m_isRunning){ + return(false); + } + m_isRunning = true; + if(m_arguments.isEmpty()){ + m_isRunning = false; + return(false); + } + if(m_arguments[0][0] != '/'){ + m_isRunning = false; + return(false); + } + + for(QStringList::Iterator it=m_arguments.begin(); + it!=m_arguments.end(); ++it){ + qDebug("arguments[%s]", (*it).ascii()); + } + + /* open pipe */ + if(openPipe() == false){ + m_isRunning = false; + return(false); + } + + /* signal handler reset */ + m_defChildHandler = setSignalHandler(SIGCHLD, SIG_DFL); + + m_child = ::fork(); + if(m_child < 0){ + /* fork error */ + closePipe(); + setSignalHandler(SIGCHLD, m_defChildHandler); + m_isRunning = false; + return(false); + } else if(m_child == 0){ + /* child process */ + qDebug("child process[%d]", ::getpid()); + m_child = ::getpid(); + //setSignalHandler(SIGCHLD, SIG_DFL); + workerProc(); + /* no return */ + } + /* close pipe(write) */ + closePipe(NULL, 1); +#if 0 + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), + this, SLOT(readOutputs())); +#endif + m_pTimer->start(500); + { + emit start(m_child, m_arguments); + QCopEnvelope e(SC_CHANNEL, "start(int,QStringList)"); + e << m_child << m_arguments; + if(m_isNotify){ + int idx = m_arguments[0].findRev('/'); + notifyStatus(m_arguments[0].mid(idx+1), m_child); + } + } + int status; + if(::waitpid(-1, &status, WNOHANG) > 0){ + qDebug("finish"); + notifyFinish(status); + } else { + /* signal handler set */ + setSignalHandler(SIGCHLD, childHandler); + } + return(true); +} + +void ProcessInvoker::terminate() +{ + if(m_isRunning && m_child > 0){ + terminate(m_child); + } +} + +void ProcessInvoker::terminate(pid_t pid) +{ + ::kill(pid, SIGTERM); +} + +void ProcessInvoker::kill() +{ + if(m_isRunning && m_child > 0){ + kill(m_child); + } +} + +void ProcessInvoker::kill(pid_t pid) +{ + ::kill(pid, SIGKILL); +} + +#if 0 +const QStringList ProcessInvoker::parseArgs(const QString& arguments) +{ + QString str; + QStringList args; + char quote = 0; + char c; + for(unsigned int i=0; i<arguments.length(); i++){ + c = arguments[i]; + switch(c){ + case '\"': + if(quote == 0){ + quote = c; + } else if(quote == '\"'){ + if(str.length() > 0){ + args.append(str); + } + str = ""; + quote = 0; + } else { + str += c; + } + break; + case '\'': + if(quote == 0){ + quote = c; + } else if(quote == '\''){ + if(str.length() > 0){ + args.append(str); + } + str = ""; + quote = 0; + } else { + str += c; + } + break; + case ' ': + if(quote == 0){ + if(str.length() > 0){ + args.append(str); + str = ""; + } + } else { + str += c; + } + break; + default: + str += c; + break; + } + } + if(str.length() > 0){ + args.append(str); + } + return(args); +} +#endif + +void ProcessInvoker::readOutputs() +{ + struct timeval tmval; + tmval.tv_sec = 0; + tmval.tv_usec = 0; + fd_set rset; + + QByteArray stdBuf, errBuf, resBuf; + QDataStream stdStream(stdBuf, IO_WriteOnly); + QDataStream errStream(errBuf, IO_WriteOnly); + + int iRet; + bool running; + char buf[PIPE_BUF+1]; + while(true){ + running = false; + FD_ZERO(&rset); + if(m_stdfd[0] >= 0){ + FD_SET(m_stdfd[0], &rset); + running = true; + } + if(m_errfd[0] >= 0){ + FD_SET(m_errfd[0], &rset); + running = true; + } + if(running == false){ + m_pTimer->stop(); + //delete m_pTimer; + break; + } + + if((iRet = ::select(m_maxfdp1, &rset, NULL, NULL, &tmval)) <= 0){ + qDebug("select[%d]", iRet); + break; + } + + if(m_stdfd[0] >= 0 && FD_ISSET(m_stdfd[0], &rset)){ + int n = ::read(m_stdfd[0], buf, PIPE_BUF); + if(n > 0){ + stdStream.writeRawBytes(buf, n); + } else { + qDebug("stdout close"); + closePipe(m_stdfd, 0); + } + } + if(m_errfd[0] >= 0 && FD_ISSET(m_errfd[0], &rset)){ + int n = ::read(m_errfd[0], buf, PIPE_BUF); + if(n > 0){ + errStream.writeRawBytes(buf, n); + } else { + qDebug("stderr close"); + closePipe(m_errfd, 0); + } + } + } + + if(stdBuf.size() > 0){ + QCopEnvelope e(SC_CHANNEL, "stdout(int,QByteArray)"); + e << m_child << stdBuf; + } + if(errBuf.size() > 0){ + QCopEnvelope e(SC_CHANNEL, "stderr(int,QByteArray)"); + e << m_child << errBuf; + } + if(running == false){ + QCopEnvelope e(SC_CHANNEL, "close(int)"); + e << m_child; + } +} + +#if 0 +void ProcessInvoker::waitFinish() +{ + int status; + if(::waitpid(m_child, &status, 0) > 0){ + notifyFinish(status); + } else { + notifyFinish(0, false); + } +} +#endif + +void ProcessInvoker::notifyFinish(int status, bool success) +{ + bool stopped = false; + QString result; + int code; + if(success){ + if(WIFEXITED(status)){ + code = WEXITSTATUS(status); + if(code == 127){ + result = "error"; + } else { + result = "exit"; + } + } else if(WIFSIGNALED(status)){ + result = "terminated"; + code = WTERMSIG(status); + } else if(WIFSTOPPED(status)){ + result = "stopped"; + code = WSTOPSIG(status); + stopped = true; + } else { + /* ¤³¤ì¤Ï̵¤¤¤Ï¤º? */ + result = "error"; + code = -2; + qWarning("ProcessInvoker: unknown status"); + } + } else { + result = "error"; + code = -1; + qWarning("ProcessInvoker: wait error"); + } + emit finish(result, code); + QCopEnvelope e(SC_CHANNEL, "finish(int,QString,int)"); + e << m_child << result << code; + if(m_isNotify){ + notifyStatus(result, code); + setNotify(false); + } + if(stopped == false){ + setSignalHandler(SIGCHLD, m_defChildHandler); + m_isRunning = false; + } +} + +void ProcessInvoker::notifyStatus(const QString& result, int code) +{ + QString message = QString::number(code); + message.append(":"); + message.append(result); + Global::statusMessage(message); +} + +/* ------------------------------------------------------------------------ */ +/* ProcessInvoker Class : child process */ +/* ------------------------------------------------------------------------ */ +void ProcessInvoker::workerProc() +{ + closePipe(m_stdfd, 0); + closePipe(m_errfd, 0); + if(m_stdfd[1] != STDOUT_FILENO){ + ::dup2(m_stdfd[1], STDOUT_FILENO); + closePipe(m_stdfd, 1); + } + if(m_errfd[1] != STDERR_FILENO){ + ::dup2(m_errfd[1], STDERR_FILENO); + closePipe(m_errfd, 1); + } + + QCString* arglist = new QCString[m_arguments.count()+1]; + const char** argv = new const char*[m_arguments.count()+1]; + unsigned int i; + for(i=0; i<m_arguments.count(); i++){ + //arglist[i] = m_arguments[i].local8Bit(); + arglist[i] = m_arguments[i]; + argv[i] = arglist[i]; + } + argv[i] = 0; + ::execv(argv[0], (char*const*)argv); + delete[] arglist; + delete[] argv; + ::_exit(127); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.h new file mode 100644 index 0000000..1f53cd6 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/ProcessInvoker.h @@ -0,0 +1,114 @@ +#ifndef _PROCESS_INVOKER_H_ +#define _PROCESS_INVOKER_H_ + +#include <qobject.h> +#include <sys/wait.h> +#include <sys/types.h> +#include <sys/time.h> +#include <signal.h> +#include <stdio.h> +#include <unistd.h> +#include <errno.h> + +#include <qtimer.h> +#include <qdatastream.h> +#include <qcstring.h> +#include <qpe/qcopenvelope_qws.h> +#include <qpe/global.h> +//#include "KHUtil.h" +#include "StringParser.h" + +typedef void Sigfunc(int); + +#define SC_CHANNEL "QPE/ShellCommander" + +/* Sigleton Object */ +class ProcessInvoker : public QObject +{ + Q_OBJECT +public: + static ProcessInvoker& getInstance() + { + static ProcessInvoker instance; + return(instance); + } + + bool run(); + bool run(const QString& args); + void terminate(); + void terminate(pid_t pid); + void kill(); + void kill(pid_t pid); + void setCommand(const QString& command){ + m_arguments.clear(); + addArgument(command); + } + void setArguments(const QStringList& arglist){ + m_arguments = arglist; + } + void setArguments(const QString& arguments){ + //setArguments(KHUtil::parseArgs(arguments)); + setArguments(StringParser::split(' ', arguments)); + } + void addArgument(const QString& argument){ + m_arguments.append(argument); + } + void addArguments(const QString& arguments){ + QStringList arglist; + //arglist = KHUtil::parseArgs(arguments); + arglist = StringParser::split(' ', arguments); + addArguments(arglist); + } + void addArguments(const QStringList& arglist){ + for(QStringList::ConstIterator it=arglist.begin(); + it!=arglist.end(); ++it){ + addArgument(*it); + } + } + //const QStringList parseArgs(const QString& arguments); + void setRunning(int pid); + void setNotify(bool enable=true){ + m_isNotify = enable; + } + + bool isRunning(){ + return(m_isRunning); + } + void notifyFinish(int status, bool success=true); + + pid_t m_child; + + friend class Dummy; /* for compile warning */ +signals: + void start(int, QStringList); + void finish(QString,int); +private: + ProcessInvoker(); + ProcessInvoker(const ProcessInvoker&); + ProcessInvoker& operator=(const ProcessInvoker&); + ~ProcessInvoker(); + + class Dummy{}; /* for compile warning */ + + QTimer* m_pTimer; + QStringList m_arguments; + + bool m_isRunning; + bool m_isNotify; + + Sigfunc* m_defChildHandler; + + int m_stdfd[2]; + int m_errfd[2]; + int m_maxfdp1; + + bool openPipe(); + void closePipe(int fd[] = NULL, int n = 2); + void notifyStatus(const QString& result, int code); + + void workerProc(); +private slots: + void readOutputs(); +}; + +#endif /* _PROCESS_INVOKER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/QCopLnk.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/QCopLnk.cpp new file mode 100644 index 0000000..991bf87 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/QCopLnk.cpp @@ -0,0 +1,63 @@ +#include "QCopLnk.h" +#include "StringParser.h" + +void QCopLnk::execute() +{ + parseText(); + //QStringList argList = KHUtil::parseArgs(m_params[1]); + QStringList argList = StringParser::split(' ', m_params[1]); + if(argList.count() < 2){ + return; + } + QStringList paramList = + QStringList::split(QRegExp("[(),]"), argList[1]); + if(argList.count() < paramList.count()+1){ + return; + } + paramList.remove(paramList.begin()); + if(paramList.count() == 0){ + /* send qcop message */ + QCopEnvelope env(argList[0].latin1(), argList[1].latin1()); + } else { + QCopEnvelope* e = NULL; + QStringList::Iterator it=paramList.end(); + for(unsigned int index = 2; index<argList.count(); index++){ + if(it == paramList.end()){ + if(argList.count() - index < paramList.count()){ + break; + } + /* initialize */ + it = paramList.begin(); + e = new QCopEnvelope( + argList[0].latin1(), argList[1].latin1()); + } + QString arg = argList[index]; + if(*it == "QString"){ + *e << arg; + } else if(*it == "int"){ + *e << arg.toInt(); + } else if(*it == "bool"){ + QString s = arg.lower(); + int on; + if(s == "true"){ + on = TRUE; + } else if(s == "false"){ + on = FALSE; + } else { + on = s.toInt(); + } + *e << on; + } + ++it; + if(it == paramList.end()){ + /* send qcop message */ + delete e; + if(argList.count() - index >= paramList.count()){ + e = new QCopEnvelope( + argList[0].latin1(), argList[1].latin1()); + it = paramList.begin(); + } + } + } + } +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/QCopLnk.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/QCopLnk.h new file mode 100644 index 0000000..f994149 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/QCopLnk.h @@ -0,0 +1,34 @@ +#ifndef _QCOPLNK_H_ +#define _QCOPLNK_H_ + +#include <qpe/qpeapplication.h> +#include <qpe/qcopenvelope_qws.h> + +#include "AnyLnk.h" +#include "KHUtil.h" + +class QCopLnk : public AnyLnk +{ +public: + QCopLnk(){} + QCopLnk(const QStringList& params) + : AnyLnk(params){} + virtual ~QCopLnk() { + } + + virtual bool isValid() { + return(true); + } + virtual QString name() { + return("qcop"); + } + virtual const QPixmap& pixmap() { + return(m_pixmap); + } + + virtual void execute(); +protected: +}; + +#endif /* _QCOPLNK_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/TextLnk.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/TextLnk.cpp new file mode 100644 index 0000000..abb432c --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/TextLnk.cpp @@ -0,0 +1,34 @@ +#include "TextLnk.h" + +void TextLnk::execute() +{ + QClipboard* cb = QApplication::clipboard(); + parseText(); + cb->setText(m_params[1]); + QWSServer::sendKeyEvent('V'-'@',Qt::Key_V, Qt::ControlButton, + true, false); + QWSServer::sendKeyEvent('V'-'@',Qt::Key_V, Qt::ControlButton, + false, false); +} + +void TextLnk::parse(QString& str) +{ + replace(str, "\\\\", "\\"); + replace(str, "\\n", "\n"); + replace(str, "\\r", "\r"); + replace(str, "\\t", "\t"); +} + +void TextLnk::replace(QString& str, const QString& s1, const QString& s2) +{ + int index = 0; + int idx; + int len = s1.length(); + idx = str.find(s1, index); + for(;;){ + idx = str.find(s1, index); + if(idx < 0) break; + str.replace(idx, len, s2); + index = idx; + } +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/TextLnk.h b/noncore/applets/keyhelper/keyhelperapplet/anylnk/TextLnk.h new file mode 100644 index 0000000..3ae13c5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/TextLnk.h @@ -0,0 +1,38 @@ +#ifndef _PASTELNK_H_ +#define _PASTELNK_H_ + +#include <qwindowsystem_qws.h> + +#include <qpe/qpeapplication.h> +#include <qclipboard.h> +#include <qregexp.h> + +#include "AnyLnk.h" + +class TextLnk : public AnyLnk +{ +public: + TextLnk(){} + TextLnk(const QStringList& params) + : AnyLnk(params){} + virtual ~TextLnk() { + } + + virtual bool isValid() { + return(true); + } + virtual QString name() { + return("text"); + } + virtual const QPixmap& pixmap() { + return(m_pixmap); + } + + virtual void execute(); +protected: + virtual void parse(QString& str); + virtual void replace(QString& str, const QString& s1, const QString& s2); +}; + +#endif /* _PASTELNK_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelper.cpp b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelper.cpp new file mode 100644 index 0000000..4afdc1f --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelper.cpp @@ -0,0 +1,112 @@ +#include "KeyHelper.h" +#include <opie2/okeyfilter.h> + +KeyHelper::KeyHelper() +{ + qDebug("KeyHelper::KeyHelper()"); + load(); + + m_oAction.setKeyModifiers(&m_oModifiers); + m_oAction.setKeyMappings(&m_oMappings); + m_oAction.setKeyExtensions(&m_oExtensions); + m_oAction.setKeyRepeater(&m_oRepeater); + m_oExtensions.setKeyModifiers(&m_oModifiers); +} + +KeyHelper::~KeyHelper() +{ + unset(); + qDebug("KeyHelper::~KeyHelper()"); +} + +bool KeyHelper::filter(int unicode, int keycode, int modifiers, + bool isPress, bool autoRepeat) +{ + m_oAction.setAction(unicode, keycode, modifiers, + isPress, autoRepeat); + return(m_oAction.doAction()); +} + +void KeyHelper::unset() +{ + Opie::Core::OKeyFilter::inst()->remHandler(this);; +} + +void KeyHelper::set() +{ + Opie::Core::OKeyFilter::inst()->addHandler(this); + m_oModifiers.resetStates(); +} + +void KeyHelper::enable() +{ + m_oAction.enable(); +} + +void KeyHelper::disable() +{ + m_oAction.disable(); + m_oRepeater.stop(); +} + +bool KeyHelper::load(const QString& file) +{ + KeycfgReader oReader; + oReader.setKeyModifiers(&m_oModifiers); + oReader.setKeyMappings(&m_oMappings); + oReader.setKeyExtensions(&m_oExtensions); + oReader.setKeyRepeater(&m_oRepeater); + + bool success; + if(file.length() == 0){ + success = oReader.load(); + } else if(file[0] == '/'){ + success = oReader.load(file); + } else { + //QString filepath = QString(::getenv("HOME")) + "/Settings/" + file; + QString filepath = QDir::homeDirPath() + "/Settings/" + file; + success = oReader.load(filepath); + } + if(success == false){ + qDebug("config xml load error"); + setDefault(); + } + return(success); +} + +bool KeyHelper::reload(const QString& file) +{ + m_oModifiers.reset(); + m_oMappings.reset(); + m_oExtensions.reset(); + m_oRepeater.reset(); + + return(load(file)); +} + +void KeyHelper::setDefault() +{ + /* default settings */ + m_oExtensions.assign("switch", Qt::Key_F12, + m_oModifiers.getMask("Shift"), KeyNames::getCode("Shift")); + m_oExtensions.assign("select", Qt::Key_F11, + m_oModifiers.getMask("Shift"), KeyNames::getCode("Shift")); +} + +void KeyHelper::statistics() +{ + m_oModifiers.statistics(); + m_oMappings.statistics(); + m_oExtensions.statistics(); + m_oRepeater.statistics(); +} + +void KeyHelper::dumpkeymap() +{ + const QWSServer::KeyMap* m = QWSServer::keyMap(); + qWarning("KeyHelper::dumpkeymap()"); + while(m->key_code != 0){ + qWarning(" [%04x][%04x][%04x][%04x]", m->key_code, m->unicode, m->shift_unicode, m->ctrl_unicode); + m++; + } +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelper.h b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelper.h new file mode 100644 index 0000000..aabb6eb --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelper.h @@ -0,0 +1,42 @@ +#ifndef _KEY_HELPER_H_ +#define _KEY_HELPER_H_ + +#include <qdir.h> +#include <qwindowsystem_qws.h> +#include "KeyNames.h" +#include "KeyMappings.h" +#include "KeyModifiers.h" +#include "KeyExtensions.h" +#include "KeyRepeater.h" +#include "KeyAction.h" +#include "KeycfgReader.h" + +class KeyHelper : public QWSServer::KeyboardFilter +{ +public: + KeyHelper(); + virtual ~KeyHelper(); + bool filter(int unicode, int keycode, int modifiers, + bool isPress, bool autoRepeat); + + void enable(); + void disable(); + void set(); + void unset(); + void statistics(); + void dumpkeymap(); + bool reload(const QString& file=QString::null); +private: + friend class KeyHelperWidget; + + bool load(const QString& file=QString::null); + void setDefault(); + + KeyAction m_oAction; + KeyMappings m_oMappings; + KeyModifiers m_oModifiers; + KeyExtensions m_oExtensions; + KeyRepeater m_oRepeater; +}; + +#endif /* _KEY_HELPER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperApplet.cpp b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperApplet.cpp new file mode 100644 index 0000000..28304d7 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperApplet.cpp @@ -0,0 +1,65 @@ +#include "KeyHelperApplet.h" +#include "KeyHelperWidget.h" + +#if 0 +KeyHelperApplet::KeyHelperApplet() + : widget(0), ref(0) +{ + qDebug("KeyHelperApplet::KeyHelperApplet()"); +} + +KeyHelperApplet::~KeyHelperApplet() +{ + qDebug("KeyHelperApplet::~KeyHelperApplet()"); + delete widget; +} + +QWidget* KeyHelperApplet::applet(QWidget* parent) +{ + if(!widget){ + widget = new KeyHelperWidget(parent); + } + return(widget); +} + +int KeyHelperApplet::position() const +{ + return(6); +} + +QRESULT KeyHelperApplet::queryInterface(const QUuid& uuid, + QUnknownInterface** iface) +{ + *iface = 0; + + if(QFile::exists("/tmp/disable-keyhelper") + || QFile::exists("/mnt/card/disable-keyhelper") + || QFile::exists("/mnt/cf/disable-keyhelper")){ + return QS_FALSE; + } + + if(uuid == IID_QUnknown){ + *iface = this; + } else if(uuid == IID_TaskbarApplet){ + *iface = this; + } + + if(*iface){ + (*iface)->addRef(); + } + return QS_OK; +} + +Q_EXPORT_INTERFACE() +{ + Q_CREATE_INSTANCE(KeyHelperApplet) +} + +#else +#include <opie2/otaskbarapplet.h> + +using namespace Opie::Ui; + +EXPORT_OPIE_APPLET_v1( KeyHelperWidget ) + +#endif diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperApplet.h b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperApplet.h new file mode 100644 index 0000000..ef164dc --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperApplet.h @@ -0,0 +1,26 @@ +#ifndef _KEY_HELPER_APPLET_H_ +#define _KEY_HELPER_APPLET_H_ + +#if 0 +#include <qpe/taskbarappletinterface.h> +#include "KeyHelperWidget.h" + +class KeyHelperApplet : public TaskbarAppletInterface +{ +public: + KeyHelperApplet(); + virtual ~KeyHelperApplet(); + + QRESULT queryInterface(const QUuid&, QUnknownInterface**); + Q_REFCOUNT + + virtual QWidget* applet(QWidget* parent); + virtual int position() const; +private: + KeyHelperWidget* widget; + ulong ref; +}; + +#endif + +#endif /* _KEY_HELPER_APPLET_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperWidget.cpp b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperWidget.cpp new file mode 100644 index 0000000..7beb511 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperWidget.cpp @@ -0,0 +1,490 @@ +#include "KeyHelperWidget.h" +#include "QSafeDataStream.h" +#include "KHUtil.h" + +QWidget* g_Widget = NULL; +int g_level = 0; + +static const char* _version_ = "1.2.2"; + +KeyHelperWidget::KeyHelperWidget(QWidget* parent, const char* name) + : QLabel(parent, name),disabled(Resource::loadPixmap("zkb-disabled")) +{ + qDebug("KeyHelperWidget::KeyHelperWidget()"); + g_Widget = this; + m_defHandler = NULL; + //m_reset = false; + m_reset = true; + m_useFilter = false; + m_pHelper = NULL; + m_status = false; + + //unset(); + initDebugLevel(); + + m_pHelper = new KeyHelper(); + + //qApp->installEventFilter(this); + + connect(qwsServer, + SIGNAL(windowEvent(QWSWindow*, QWSServer::WindowEvent)), + this, + SLOT(windowEvent(QWSWindow*, QWSServer::WindowEvent))); + + m_pChannel = new QCopChannel("QPE/KeyHelper", this); + connect(m_pChannel, SIGNAL(received(const QCString&, const QByteArray&)), + this, SLOT(receiveMessage(const QCString&, const QByteArray&))); + m_pSysChannel = new QCopChannel("QPE/System", this); + connect(m_pSysChannel, SIGNAL(received(const QCString&, const QByteArray&)), + this, SLOT(sysMessage(const QCString&, const QByteArray&))); + + //AppLnkManager::init(); + setFixedWidth ( AppLnk::smallIconSize() ); + setFixedHeight ( AppLnk::smallIconSize() ); + setPixmap(disabled); + init(); +} + +KeyHelperWidget::~KeyHelperWidget() +{ + qDebug("KeyHelperWidget::~KeyHelperWidget()"); + disconnect(qwsServer, + SIGNAL(windowEvent(QWSWindow*, QWSServer::WindowEvent)), + this, + SLOT(windowEvent(QWSWindow*, QWSServer::WindowEvent))); + disconnect(m_pChannel, SIGNAL(received(const QCString&, const QByteArray&)), + this, SLOT(receiveMessage(const QCString&, const QByteArray&))); + unset(); + if (m_pHelper) delete m_pHelper; + if (m_pChannel) delete m_pChannel; + if (m_pSysChannel) delete m_pSysChannel; + m_pHelper = NULL; + setDebugLevel(0); +} + +void KeyHelperWidget::mouseReleaseEvent(QMouseEvent*) +{ + ConfigEx::getInstance("keyhelper").setConfig("keyhelper"); +} + +void KeyHelperWidget::receiveMessage( + const QCString& msg, const QByteArray& data) +{ + if(m_pHelper == NULL){ + return; + } + QSafeDataStream stream(data, IO_ReadOnly); + if(msg == "event(int,int,int,int,int)"){ + int unicode; + int keycode; + int modifiers; + int isPress; + int autoRepeat; + stream >> unicode >> keycode >> modifiers >> isPress >> autoRepeat; + doEvent(unicode, keycode, modifiers, isPress, autoRepeat); + } else if(msg == "event(QString,int)"){ + QString key; + int isPress; + stream >> key >> isPress; + doEvent(key, isPress); + } else if(msg == "enable()"){ + enable(); + } else if(msg == "disable()"){ + disable(); + } else if(msg == "pause()"){ + pause(); + } else if(msg == "restart()"){ + restart(); + } else if(msg == "reload()"){ + m_xmlfile = QString::null; + doReload(); + } else if(msg == "reload(QString)"){ + stream >> m_xmlfile; + doReload(false); + } else if(msg == "version()"){ + version(); + } else if(msg == "repeater(int)"){ + int mode; + stream >> mode; + m_pHelper->m_oRepeater.setMode(mode); + } else if(msg == "hook(QString)"){ + QString s; + stream >> s; + m_pHelper->m_oAction.setHook(s.local8Bit()); + } else if(msg == "unhook()"){ + m_pHelper->m_oAction.setHook(""); + } else if(msg == "config()"){ + ConfigEx::getInstance("keyhelper").setConfig("keyhelper"); + } else if(msg == "config(QString)"){ + QString name; + stream >> name; + if(name == QString::null){ + ConfigEx::getInstance("keyhelper").setConfig("keyhelper"); + } else { + ConfigEx::getInstance("keyhelper").setConfig(name); + } + } else if(msg == "capture(int)"){ + int enable; + stream >> enable; + m_pHelper->m_oAction.setCapture(enable); + } else if(msg == "statistics()"){ + int level = g_level; + if(level == 0){ + setDebugLevel(1); + } + m_pHelper->statistics(); + if(level == 0){ + setDebugLevel(0); + } + } else if(msg == "dumpkeymap()"){ + int level = g_level; + if(level == 0){ + setDebugLevel(1); + } + m_pHelper->dumpkeymap(); + if(level == 0){ + setDebugLevel(0); + } + } else if(msg == "debug(int)"){ + int level; + stream >> level; + setDebugLevel(level); + } +} + +void KeyHelperWidget::doReload(bool showstatus) +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + QString oldgroup = cfg.getGroup(); + cfg.setGroup("Global"); + m_status = false; + if(showstatus && (cfg.readNumEntry("ShowStatusOnReload", 1) == 1)){ + m_status = true; + version(); + QCopEnvelope("QPE/System", "busy()"); + } + cfg.setGroup(oldgroup); + QTimer::singleShot(0, this, SLOT(reload())); +} + +void KeyHelperWidget::doEvent(int unicode, int keycode, int modifiers, int isPress, int autoRepeat) +{ + if(isPress == 0 || isPress == 1){ + m_pHelper->m_oAction.setAction(unicode, keycode, modifiers, isPress, autoRepeat); + m_pHelper->m_oAction.doAction(); + } else { + /* press & release */ + m_pHelper->m_oAction.setAction(unicode, keycode, modifiers, 1, autoRepeat); + m_pHelper->m_oAction.doAction(); + m_pHelper->m_oAction.setAction(unicode, keycode, modifiers, 0, autoRepeat); + m_pHelper->m_oAction.doAction(); + } +} + +void KeyHelperWidget::doEvent(const QString& key, int isPress) +{ + int unicode,keycode; + int modifiers = 0; + int pos; + QString keyname = key; + pos = keyname.find("+SHIFT", 0, FALSE); + if(pos > 0){ + modifiers |= Qt::ShiftButton; + keyname.remove(pos, 6); + } + pos = keyname.find("+CTRL", 0, FALSE); + if(pos > 0){ + modifiers |= Qt::ControlButton; + keyname.remove(pos, 5); + } + pos = keyname.find("+ALT", 0, FALSE); + if(pos > 0){ + modifiers |= Qt::AltButton; + keyname.remove(pos, 4); + } + if(keyname.length() > 1){ + unicode = 0xffff; + keycode = KeyNames::getCode(keyname); + /* get unicode */ + const QWSServer::KeyMap* m; + for(m=QWSServer::keyMap(); m->key_code != 0; m++){ + if(m->key_code == keycode){ + if(modifiers & Qt::ControlButton){ + unicode = m->ctrl_unicode; + } else if(modifiers & Qt::ShiftButton){ + unicode = m->shift_unicode; + } else { + unicode = m->unicode; + } + break; + } + } + } else { + const QWSServer::KeyMap* m; + keycode = 0; + unicode = keyname[0].unicode(); + /* check unicode */ + for(m=QWSServer::keyMap(); keycode == 0 && m->key_code != 0; m++){ + if(m->unicode == unicode){ + keycode = m->key_code; + break; + } + } + /* check shift_unicode */ + for(m=QWSServer::keyMap(); keycode == 0 && m->key_code != 0; m++){ + if(m->shift_unicode == unicode){ + keycode = m->key_code; + modifiers |= Qt::ShiftButton; + break; + } + } + /* check ctrl_unicode */ + for(m=QWSServer::keyMap(); keycode == 0 && m->key_code != 0; m++){ + if(m->ctrl_unicode == unicode){ + keycode = m->key_code; + modifiers |= Qt::ControlButton; + break; + } + } + } + doEvent(unicode, keycode, modifiers, isPress, 0); +} + +void KeyHelperWidget::sysMessage( + const QCString& msg, const QByteArray& data) +{ + QSafeDataStream stream(data, IO_ReadOnly); + if(msg == "linkChanged(QString)"){ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + QString oldgroup = cfg.getGroup(); + if(cfg.readNumEntry("DetectLinkChange", 1) == 1){ + AppLnkManager::init(true); + reload(); + } + cfg.setGroup(oldgroup); + } +} + +void MsgHandler(QtMsgType type, const char* msg) +{ + switch(type){ + case QtDebugMsg: + if(g_level >= 2){ + syslog(LOG_LOCAL5|LOG_DEBUG, + "<2>%s", msg); + } + break; + case QtWarningMsg: + if(g_level >= 1){ + syslog(LOG_LOCAL5|LOG_DEBUG, + "<1>%s", msg); + } + break; + default: + break; + } +} + +void KeyHelperWidget::initDebugLevel() +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Global"); + + int level = cfg.readNumEntry("DebugLevel", 0); + setDebugLevel(level); +} + +void KeyHelperWidget::setDebugLevel(int level) +{ +#ifdef QT_QWS_EBX + static bool noDebug = true; + g_level = level; + if(g_level > 0){ + if(noDebug){ + m_defHandler = qInstallMsgHandler(MsgHandler); + noDebug = false; + } + } else { + qInstallMsgHandler(m_defHandler); + noDebug = true; + } +#endif +} + +void KeyHelperWidget::enable() +{ + m_enable = true; + m_pHelper->enable(); + //set(); + QTimer::singleShot(0, this, SLOT(set())); +} + +void KeyHelperWidget::disable() +{ + m_enable = false; + m_pHelper->disable(); + unset(); +} + +void KeyHelperWidget::pause() +{ + m_saved = m_enable; + disable(); +} + +void KeyHelperWidget::restart() +{ + if(m_saved){ + enable(); + } +} + +void KeyHelperWidget::reload() +{ + disable(); + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.reload(); + if(m_pHelper->reload(m_xmlfile) == false){ + if(m_status){ + Global::statusMessage("KeyHelper: Load Error"); + } + } + init(); + if(m_status){ + QCopEnvelope e("QPE/System", "notBusy(QString)"); + const QString app = KHUtil::currentApp(); + e << app; + m_status = false; + } +} + +void KeyHelperWidget::version() +{ + QString ver = "KeyHelper "; + ver.append(_version_); + Global::statusMessage(ver); +} + +void KeyHelperWidget::init() +{ + AppLnkManager::init(); +#if 0 + if(m_pHelper == NULL){ + m_pHelper = new KeyHelper(); + } +#endif + loadUseFilterApps(); + enable(); +} + +void KeyHelperWidget::set() +{ + if(m_pHelper != NULL && m_enable == true && m_useFilter == false){ + qWarning("KeyHelperWidget::set()"); + m_pHelper->set(); + } +} + +void KeyHelperWidget::unset() +{ + m_pHelper->unset(); +} + +void KeyHelperWidget::loadUseFilterApps() +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + cfg.setGroup("Global"); + m_apps = cfg.readListEntry("UseFilterApps", ','); + + if(m_apps.isEmpty()){ + /* default */ + m_apps.append("CRIM"); + m_apps.append("Jpn50Pad"); + m_apps.append("JpnKtnPad"); + m_apps.append("JpnNumPad"); + m_apps.append("JpnSymPad"); + m_apps.append("Keyboard"); + m_apps.append("IMWidget"); /* IMKit */ + m_apps.append("POBox"); /* QPOBox */ + } +} + +#if 0 +void KeyHelperWidget::windowEvent(QWSWindow* w, QWSServer::WindowEvent e) +{ + if(m_apps.contains(w->name())){ + switch(e){ + case QWSServer::Hide: + case QWSServer::Destroy: + m_useFilter = false; + //m_reset = true; + QTimer::singleShot(0, this, SLOT(set())); + break; + case QWSServer::Create: + case QWSServer::Raise: + case QWSServer::Show: + m_useFilter = true; + //m_reset = false; + m_reset = true; + break; + default: + break; + } + } else if(w->client()->identity() != NULL && w->name() != NULL){ + switch(e){ +#if 0 + case QWSServer::Create: + case QWSServer::Hide: + if(m_useFilter == false && m_reset){ + m_reset = false; + set(); + //QTimer::singleShot(0, this, SLOT(set())); + } + break; +#else + case QWSServer::Hide: + case QWSServer::Destroy: + //if(m_useFilter == false && m_reset){ + if(m_reset){ + m_reset = false; + set(); + //QTimer::singleShot(0, this, SLOT(set())); + } + break; + case QWSServer::Create: + case QWSServer::Raise: + case QWSServer::Show: + m_reset = true; + break; +#endif + default: +#if 0 + if(m_reset == true){ + m_reset = false; + set(); + } +#endif + break; + } + } + if(w->name() != NULL){ + qWarning("[%s][%s][%x][%s]", + w->name().latin1(), + w->caption().latin1(), + e, + w->client()->identity().latin1()); + } +} + +#endif + +bool KeyHelperWidget::eventFilter(QObject* o, QEvent* e) +{ + return QWidget::eventFilter(o, e); +} + +int KeyHelperWidget::position() +{ + return 3; +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperWidget.h b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperWidget.h new file mode 100644 index 0000000..4798c5c --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/KeyHelperWidget.h @@ -0,0 +1,75 @@ +#ifndef _KEY_HELPER_WIDGET_H_ +#define _KEY_HELPER_WIDGET_H_ + +#include <qwidget.h> +#include <qlabel.h> +#include <qpixmap.h> +#include <qtimer.h> +#include <qaccel.h> +#include <opie2/otaskbarapplet.h> +#include <opie2/okeyfilter.h> + +#include <qpe/qcopenvelope_qws.h> +#include <qpe/qpeapplication.h> +#include <qpe/global.h> +#include <qpe/resource.h> +#include "KeyHelper.h" +#include "AppLnkManager.h" +#include "ConfigEx.h" + +#include <syslog.h> + +Q_EXPORT void MsgHandler(QtMsgType type, const char* msg); + +class KeyHelperWidget : public QLabel +{ + Q_OBJECT +public: + KeyHelperWidget(QWidget* parent = 0, const char* name=0); + ~KeyHelperWidget(); + static int position(); + + virtual bool eventFilter(QObject* o, QEvent* e); + +public slots: + //void windowEvent(QWSWindow* w, QWSServer::WindowEvent e); +protected: + QCopChannel* m_pChannel; + QCopChannel* m_pSysChannel; + QPixmap disabled; + +protected slots: + void receiveMessage(const QCString& msg, const QByteArray& data); + void sysMessage(const QCString& msg, const QByteArray& data); + void reload(); + void set(); + void unset(); + void init(); + void mouseReleaseEvent(QMouseEvent*); + +private: + void loadUseFilterApps(); + void enable(); + void disable(); + void pause(); + void restart(); + void version(); + void setDebugLevel(int level); + void initDebugLevel(); + + bool m_reset; + bool m_useFilter; + bool m_status; + QString m_xmlfile; + msg_handler m_defHandler; + bool m_enable; + bool m_saved; + QStringList m_apps; + KeyHelper* m_pHelper; +private slots: + void doReload(bool showstatus=true); + void doEvent(int,int,int,int,int); + void doEvent(const QString&, int); +}; + +#endif /* _KEY_HELPER_WIDGET_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/QSafeDataStream.cpp b/noncore/applets/keyhelper/keyhelperapplet/applet/QSafeDataStream.cpp new file mode 100644 index 0000000..69ba562 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/QSafeDataStream.cpp @@ -0,0 +1,203 @@ +#include "QSafeDataStream.h" + +#include <qstring.h> +#include <qstringlist.h> +#include <qdatetime.h> + +QSafeDataStream &QSafeDataStream::operator>>( Q_INT8 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( Q_UINT8 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( Q_INT16 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( Q_UINT16 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( Q_INT32 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( Q_UINT32 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( Q_INT64 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( Q_UINT64 &i ) +{ + if(atEnd()){ + i = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(i); + } +} + + +QSafeDataStream &QSafeDataStream::operator>>( float &f ) +{ + if(atEnd()){ + f = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(f); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( double &f ) +{ + if(atEnd()){ + f = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(f); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( char *&str ) +{ + if(atEnd()){ + str = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::operator>>(str); + } +} + +QSafeDataStream &QSafeDataStream::readBytes( char *&s, uint &len ) +{ + if(atEnd()){ + s = 0; + len = 0; + return *this; + } else { + return (QSafeDataStream&)QDataStream::readBytes(s, len); + } +} + +QSafeDataStream &QSafeDataStream::readRawBytes( char *s, uint len ) +{ + if(atEnd()){ + return *this; + } else { + return (QSafeDataStream&)QDataStream::readRawBytes(s, len); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( QString& s ) +{ + if(atEnd()){ + s = QString::null; + return *this; + } else { + return (QSafeDataStream&)(*((QDataStream*)this) >> s); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( QStringList& list ) +{ + if(atEnd()){ + list.clear(); + return *this; + } else { + return (QSafeDataStream&)(*((QDataStream*)this) >> list); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( QByteArray& a ) +{ + if(atEnd()){ + a.resize(0); + return *this; + } else { + return (QSafeDataStream&)(*((QDataStream*)this) >> a); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( QCString& s ) +{ + if(atEnd()){ + s.resize(0); + return *this; + } else { + return (QSafeDataStream&)(*((QDataStream*)this) >> s); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( QDate& d ) +{ + if(atEnd()){ + return *this; + } else { + return (QSafeDataStream&)(*((QDataStream*)this) >> d); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( QTime& t ) +{ + if(atEnd()){ + return *this; + } else { + return (QSafeDataStream&)(*((QDataStream*)this) >> t); + } +} + +QSafeDataStream &QSafeDataStream::operator>>( QDateTime& dt ) +{ + if(atEnd()){ + return *this; + } else { + return (QSafeDataStream&)(*((QDataStream*)this) >> dt); + } +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/applet/QSafeDataStream.h b/noncore/applets/keyhelper/keyhelperapplet/applet/QSafeDataStream.h new file mode 100644 index 0000000..2152b23 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/applet/QSafeDataStream.h @@ -0,0 +1,51 @@ +#ifndef _QSAFEDATASTREAM_H_ +#define _QSAFEDATASTREAM_H_ + +#include <qdatastream.h> + +class QString; +class QStringList; +class QCString; +class QDate; +class QTime; +class QDateTime; + +class QSafeDataStream : public QDataStream +{ +public: + /* constructors */ + QSafeDataStream() + : QDataStream() {} + QSafeDataStream(QIODevice* d) + : QDataStream(d) {} + QSafeDataStream(QByteArray a, int mode) + : QDataStream(a, mode) {} + + /* read functions */ + QSafeDataStream &operator>>( Q_INT8 &i ); + QSafeDataStream &operator>>( Q_UINT8 &i ); + QSafeDataStream &operator>>( Q_INT16 &i ); + QSafeDataStream &operator>>( Q_UINT16 &i ); + QSafeDataStream &operator>>( Q_INT32 &i ); + QSafeDataStream &operator>>( Q_UINT32 &i ); + QSafeDataStream &operator>>( Q_INT64 &i ); + QSafeDataStream &operator>>( Q_UINT64 &i ); + + QSafeDataStream &operator>>( float &f ); + QSafeDataStream &operator>>( double &f ); + QSafeDataStream &operator>>( char *&str ); + + QSafeDataStream &readBytes( char *&, uint &len ); + QSafeDataStream &readRawBytes( char *, uint len ); + + QSafeDataStream &operator>>( QString& s ); + QSafeDataStream &operator>>( QStringList& list ); + QSafeDataStream &operator>>( QByteArray& a ); + QSafeDataStream &operator>>( QCString& s ); + QSafeDataStream &operator>>( QDate& d ); + QSafeDataStream &operator>>( QTime& t ); + QSafeDataStream &operator>>( QDateTime& dt ); + +}; + +#endif /* _QSAFEDATASTREAM_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/ExtensionsHandler.cpp b/noncore/applets/keyhelper/keyhelperapplet/config/ExtensionsHandler.cpp new file mode 100644 index 0000000..84bb375 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/ExtensionsHandler.cpp @@ -0,0 +1,80 @@ +#include "ExtensionsHandler.h" + +void ExtensionsHandler::dispose(QXmlReader* parser, QXmlContentHandler* parent) +{ + m_parser = parser; + m_parent = parent; + m_parser->setContentHandler(this); +} + +bool ExtensionsHandler::startElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */, + const QXmlAttributes& attr) +{ + if(localName == "define"){ + /* ÊÑ¿ô½é´ü²½ */ + m_kind = QString::null; + m_code = -1; + //m_mask = 0; + m_modlist.clear(); + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i).lower() == "key"){ + /* keyname */ + if(attr.value(i) == "All"){ + m_code = 0; + } else { + m_code = KeyNames::getCode(attr.value(i)); + } + } else if(attr.localName(i).lower() == "code"){ + /* keycode */ + m_code = KHUtil::hex2int(attr.value(i).lower()); + } else if(attr.localName(i).lower() == "kind"){ + /* extension kind */ + m_kind = attr.value(i); + } + } + } else if(localName == "modifier"){ + /* modifier keys */ + for(int i=0; i<attr.length(); i++){ + if(attr.value(i).lower() == "on"){ + m_modlist.append(attr.localName(i)); + //m_mask |= m_pModifiers->getMask(attr.localName(i)); + } + } + } + return(true); +} + +bool ExtensionsHandler::endElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */) +{ + if(localName == "define"){ +#if 0 + if(m_kind != QString::null + && (m_code > 0 || m_modlist.isEmpty() == false)){ +#else + if(m_kind != QString::null && m_code >= 0){ +#endif + /* assign extension */ + int keymask = 0; + QValueList<int> modcodes; + for(QStringList::Iterator it=m_modlist.begin(); + it!=m_modlist.end(); ++it){ + keymask |= m_pModifiers->getMask(*it); + qDebug("mask[%s][%x][%s]", m_kind.latin1(), keymask, (*it).latin1()); + int code = KeyNames::getCode(*it); + if(code > 0){ + modcodes.append(code); + } + } + m_pExtensions->assign(m_kind, m_code, keymask, modcodes); + } + } else if(localName == "extensions"){ + m_pExtensions->init(); + /* return parent */ + m_parser->setContentHandler(m_parent); + } + return(true); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/ExtensionsHandler.h b/noncore/applets/keyhelper/keyhelperapplet/config/ExtensionsHandler.h new file mode 100644 index 0000000..cc2422b --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/ExtensionsHandler.h @@ -0,0 +1,48 @@ +#ifndef _EXTENSIONS_HANDLER_H_ +#define _EXTENSIONS_HANDLER_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <qxml.h> +#include "KeyModifiers.h" +#include "KeyExtensions.h" +#include "KeyNames.h" +#include "KHUtil.h" + +class ExtensionsHandler : public QXmlDefaultHandler +{ +public: + void dispose(QXmlReader* parser, QXmlContentHandler* parent); + + void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + void setKeyExtensions(KeyExtensions* ext) + { + m_pExtensions = ext; + } + + bool startElement(const QString& namespaceURI, + const QString& localName, + const QString& qName, + const QXmlAttributes& atts); + bool endElement(const QString& namespaceURI, + const QString& localName, + const QString& qName); +private: + QXmlContentHandler* m_parent; + QXmlReader* m_parser; + + KeyModifiers* m_pModifiers; + KeyExtensions* m_pExtensions; + + QString m_kind; + int m_code; + QStringList m_modlist; + //int m_mask; + +}; + +#endif /* _EXTENSIONS_HANDLER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgErrorHandler.cpp b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgErrorHandler.cpp new file mode 100644 index 0000000..e1faf18 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgErrorHandler.cpp @@ -0,0 +1,38 @@ +#include "KeycfgErrorHandler.h" + +void KeycfgErrorHandler::setErrorString(const QString& header, + const QXmlParseException& exception) +{ + m_errstr = header; + m_errstr.append(": "); + m_errstr.append(exception.message()); + m_errstr.append(" ["); + m_errstr.append(QString::number(exception.lineNumber())); + m_errstr.append(", "); + m_errstr.append(QString::number(exception.columnNumber())); + m_errstr.append("]"); + qWarning(m_errstr.latin1()); +} + +bool KeycfgErrorHandler::warning(const QXmlParseException& exception) +{ + setErrorString("warning", exception); + return(true); +} + +bool KeycfgErrorHandler::error(const QXmlParseException& exception) +{ + setErrorString("error", exception); + return(false); +} + +bool KeycfgErrorHandler::fatalError(const QXmlParseException& exception) +{ + setErrorString("fatal", exception); + return(false); +} + +QString KeycfgErrorHandler::errorString() +{ + return(m_errstr); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgErrorHandler.h b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgErrorHandler.h new file mode 100644 index 0000000..61e7e70 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgErrorHandler.h @@ -0,0 +1,23 @@ +#ifndef _KEYCFG_ERROR_HANDLER_H_ +#define _KEYCFG_ERROR_HANDLER_H_ + +#include <qstring.h> +#include <qxml.h> + +class KeycfgErrorHandler : public QXmlErrorHandler +{ +public: + KeycfgErrorHandler(){} + virtual ~KeycfgErrorHandler(){} + + bool warning(const QXmlParseException& exception); + bool error(const QXmlParseException& exception); + bool fatalError(const QXmlParseException& exception); + QString errorString(); +private: + void setErrorString(const QString& header, + const QXmlParseException& exception); + QString m_errstr; +}; + +#endif /* _KEYCFG_ERROR_HANDLER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgHandler.cpp b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgHandler.cpp new file mode 100644 index 0000000..a342e36 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgHandler.cpp @@ -0,0 +1,43 @@ +#include "KeycfgHandler.h" + +KeycfgHandler::KeycfgHandler(QXmlReader* parser) + : QXmlDefaultHandler() +{ + m_parser = parser; + m_pModHandler = new ModifiersHandler(); + m_pMapHandler = new MappingsHandler(); + m_pExtHandler = new ExtensionsHandler(); + m_pRepHandler = new RepeaterHandler(); +} + +KeycfgHandler::~KeycfgHandler() +{ + delete m_pModHandler; + delete m_pMapHandler; + delete m_pExtHandler; + delete m_pRepHandler; +} + +bool KeycfgHandler::startElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */, + const QXmlAttributes& /* attr */) +{ + if(localName == "modifiers"){ + m_pModHandler->setKeyModifiers(m_pModifiers); + m_pModHandler->setKeyMappings(m_pMappings); + m_pModHandler->dispose(m_parser, this); + } else if(localName == "mappings"){ + m_pMapHandler->setKeyModifiers(m_pModifiers); + m_pMapHandler->setKeyMappings(m_pMappings); + m_pMapHandler->dispose(m_parser, this); + } else if(localName == "extensions"){ + m_pExtHandler->setKeyModifiers(m_pModifiers); + m_pExtHandler->setKeyExtensions(m_pExtensions); + m_pExtHandler->dispose(m_parser, this); + } else if(localName == "repeater"){ + m_pRepHandler->setKeyRepeater(m_pRepeater); + m_pRepHandler->dispose(m_parser, this); + } + return(true); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgHandler.h b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgHandler.h new file mode 100644 index 0000000..9ddded3 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgHandler.h @@ -0,0 +1,56 @@ +#ifndef _KEYCFG_HANDLER_H_ +#define _KEYCFG_HANDLER_H_ + +#include <qxml.h> +#include <qstring.h> +#include "ModifiersHandler.h" +#include "MappingsHandler.h" +#include "ExtensionsHandler.h" +#include "RepeaterHandler.h" + +class KeycfgHandler : public QXmlDefaultHandler +{ +public: + KeycfgHandler(QXmlReader* parser); + ~KeycfgHandler(); + + void dispose(QXmlReader* parser, QXmlContentHandler* parent); + + void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + void setKeyMappings(KeyMappings* map) + { + m_pMappings = map; + } + void setKeyExtensions(KeyExtensions* ext) + { + m_pExtensions = ext; + } + void setKeyRepeater(KeyRepeater* rep) + { + m_pRepeater = rep; + } + + + bool startElement(const QString& namespaceURI, + const QString& localName, + const QString& qName, + const QXmlAttributes& atts); +private: + QXmlContentHandler* m_parent; + QXmlReader* m_parser; + + ModifiersHandler* m_pModHandler; + MappingsHandler* m_pMapHandler; + ExtensionsHandler* m_pExtHandler; + RepeaterHandler* m_pRepHandler; + + KeyModifiers* m_pModifiers; + KeyMappings* m_pMappings; + KeyExtensions* m_pExtensions; + KeyRepeater* m_pRepeater; +}; + +#endif /* _KEYCFG_HANDLER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgReader.cpp b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgReader.cpp new file mode 100644 index 0000000..44b4b2f --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgReader.cpp @@ -0,0 +1,70 @@ +#include "KeycfgReader.h" + +KeycfgReader::KeycfgReader() +{ + qDebug("KeycfgReader::KeycfgReader()"); +} + +KeycfgReader::~KeycfgReader() +{ + qDebug("KeycfgReader::~KeycfgReader()"); +} + +bool KeycfgReader::load() +{ + QString file; + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + cfg.setGroup("Global"); + + file = cfg.readEntry("XmlFile"); + if(file.length() == 0 || !QFile::exists(file)){ + /* default */ + file = QDir::homeDirPath() + "/Settings/keyhelper.xml"; + } + return(load(file)); +} + +bool KeycfgReader::load(const QString& path) +{ + bool success = false; + + KeyNames::reset(); + + QXmlSimpleReader parser; + KeycfgHandler handler(&parser); + KeycfgErrorHandler errhandler; + QFile file(path); + + qWarning("KeycfgReader::load()[%s]", path.latin1()); + + if(file.exists()){ + QXmlInputSource source(file); + + handler.setKeyModifiers(m_pModifiers); + handler.setKeyMappings(m_pMappings); + handler.setKeyExtensions(m_pExtensions); + handler.setKeyRepeater(m_pRepeater); + + parser.setContentHandler(&handler); + parser.setErrorHandler(&errhandler); + success = parser.parse(source); + + file.close(); + } + + if(success){ + m_pModifiers->statistics(); + m_pMappings->statistics(); + m_pExtensions->statistics(); + m_pRepeater->statistics(); + } else { + m_pModifiers->reset(); + m_pMappings->reset(); + m_pExtensions->reset(); + m_pRepeater->reset(); + } + KeyNames::clearCode(); + + return(success); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgReader.h b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgReader.h new file mode 100644 index 0000000..8624a01 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/KeycfgReader.h @@ -0,0 +1,46 @@ +#ifndef _KEYCFG_READER_H_ +#define _KEYCFG_READER_H_ + +#include <stdlib.h> +#include <qxml.h> +#include <qstring.h> +#include <qdir.h> +#include "KeycfgHandler.h" +#include "KeycfgErrorHandler.h" +#include "KeyNames.h" +#include "ConfigEx.h" + +class KeycfgReader +{ +public: + KeycfgReader(); + ~KeycfgReader(); + + bool load(); + bool load(const QString& path); + + inline void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + inline void setKeyMappings(KeyMappings* map) + { + m_pMappings = map; + } + inline void setKeyExtensions(KeyExtensions* ext) + { + m_pExtensions = ext; + } + inline void setKeyRepeater(KeyRepeater* rep) + { + m_pRepeater = rep; + } + +private: + KeyModifiers* m_pModifiers; + KeyMappings* m_pMappings; + KeyExtensions* m_pExtensions; + KeyRepeater* m_pRepeater; +}; + +#endif /* _KEYCFG_READER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/MappingsHandler.cpp b/noncore/applets/keyhelper/keyhelperapplet/config/MappingsHandler.cpp new file mode 100644 index 0000000..3680fbf --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/MappingsHandler.cpp @@ -0,0 +1,102 @@ +#include "MappingsHandler.h" + +void MappingsHandler::dispose(QXmlReader* parser, QXmlContentHandler* parent) +{ + m_parser = parser; + m_parent = parent; + m_parser->setContentHandler(this); +} + +bool MappingsHandler::startElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */, + const QXmlAttributes& attr) +{ + if(localName == "define"){ + /* ÊÑ¿ô½é´ü²½ */ + m_code = 0; + m_mask = 0; + m_mapcode = 0; + m_unicode = 0; + m_mapmodifiers.clear(); + m_mapunicodes.clear(); + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i).lower() == "key"){ + /* keyname */ + m_code = KeyNames::getCode(attr.value(i)); + } else if(attr.localName(i).lower() == "code"){ + /* keycode */ + m_code = KHUtil::hex2int(attr.value(i).lower()); + } + } + } else if(localName == "modifier"){ + /* modifier keys */ + for(int i=0; i<attr.length(); i++){ + if(attr.value(i).lower() == "on"){ + m_mask |= m_pModifiers->getMask(attr.localName(i)); + } + } + } else if(localName == "map"){ + /* mapping key */ + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i).lower() == "key"){ + /* keyname */ + m_mapcode = KeyNames::getCode(attr.value(i)); + } else if(attr.localName(i).lower() == "code"){ + /* keycode */ + m_mapcode = KHUtil::hex2int(attr.value(i).lower()); + } + } + } else if(localName == "map_modifier"){ + /* mapping modifiers */ + for(int i=0; i<attr.length(); i++){ + m_mapmodifiers[attr.localName(i)] = attr.value(i); + } + } else if(localName == "map_unicode"){ + /* mapping unicodes */ + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i).lower() == "char"){ + /* unicode char */ + m_unicode = attr.value(i)[0].unicode(); + } else if(attr.localName(i).lower() == "code"){ + /* unicode code */ + m_unicode = KHUtil::hex2int(attr.value(i).lower()); + } else { + m_mapunicodes[attr.localName(i)] = attr.value(i); + } + } + } + return(true); +} + +bool MappingsHandler::endElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */) +{ + if(localName == "define"){ + if(m_code > 0){ + /* assign mapping */ + m_pMappings->assign(m_code, m_mask, m_mapcode); + + for(QMap<QString,QString>::Iterator it=m_mapmodifiers.begin(); + it!=m_mapmodifiers.end(); ++it){ + /* assign mapping modifier state */ + m_pMappings->assignModifier(it.key(), it.data()); + } + + if(m_unicode > 0){ + m_pMappings->assignUnicode(m_unicode); + } else { + for(QMap<QString,QString>::Iterator it=m_mapunicodes.begin(); + it!=m_mapunicodes.end(); ++it){ + /* assign mapping unicode */ + m_pMappings->assignUnicode(it.key(), it.data()); + } + } + } + } else if(localName == "mappings"){ + /* return parent */ + m_parser->setContentHandler(m_parent); + } + return(true); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/MappingsHandler.h b/noncore/applets/keyhelper/keyhelperapplet/config/MappingsHandler.h new file mode 100644 index 0000000..d899ea2 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/MappingsHandler.h @@ -0,0 +1,48 @@ +#ifndef _MAPPINGS_HANDLER_H_ +#define _MAPPINGS_HANDLER_H_ + +#include <qxml.h> +#include <qstring.h> +#include <qmap.h> +#include "KeyModifiers.h" +#include "KeyMappings.h" +#include "KeyNames.h" +#include "KHUtil.h" + +class MappingsHandler : public QXmlDefaultHandler +{ +public: + void dispose(QXmlReader* parser, QXmlContentHandler* parent); + + void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + void setKeyMappings(KeyMappings* map) + { + m_pMappings = map; + } + + bool startElement(const QString& namespaceURI, + const QString& localName, + const QString& qName, + const QXmlAttributes& atts); + bool endElement(const QString& namespaceURI, + const QString& localName, + const QString& qName); +private: + QXmlContentHandler* m_parent; + QXmlReader* m_parser; + + KeyModifiers* m_pModifiers; + KeyMappings* m_pMappings; + + int m_code; + int m_mask; + int m_mapcode; + int m_unicode; + QMap<QString,QString> m_mapmodifiers; + QMap<QString,QString> m_mapunicodes; +}; + +#endif /* _MAPPINGS_HANDLER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/ModifiersHandler.cpp b/noncore/applets/keyhelper/keyhelperapplet/config/ModifiersHandler.cpp new file mode 100644 index 0000000..b2cde92 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/ModifiersHandler.cpp @@ -0,0 +1,99 @@ +#include "ModifiersHandler.h" + +void ModifiersHandler::dispose(QXmlReader* parser, QXmlContentHandler* parent) +{ + m_parser = parser; + m_parent = parent; + m_parser->setContentHandler(this); +} + +bool ModifiersHandler::startElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */, + const QXmlAttributes& attr) +{ + if(localName == "define"){ + /* ÊÑ¿ô½é´ü²½ */ + m_type = QString::null; + m_code = 0; + m_mask = 0; + m_release.clear(); + m_toggle = false; + m_mapping = false; + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i).lower() == "key"){ + /* keyname */ + m_code = KeyNames::getCode(attr.value(i)); + } else if(attr.localName(i).lower() == "code"){ + /* keycode */ + m_code = KHUtil::hex2int(attr.value(i).lower()); + } else if(attr.localName(i).lower() == "type"){ + /* modifier type */ + m_type = attr.value(i); + } else if(attr.localName(i).lower() == "mapping"){ + /* auto mapping */ + if(attr.value(i).lower() == "true"){ + m_mapping = true; + } + } else if(attr.localName(i).lower() == "toggle"){ + /* toggle mode */ + if(attr.value(i).lower() == "true"){ + m_toggle = true; + } + } + } + } else if(localName == "modifier"){ + /* modifier keys */ + for(int i=0; i<attr.length(); i++){ + if(attr.value(i).lower() == "on"){ + m_mask |= m_pModifiers->getMask(attr.localName(i)); + } + } + } else if(localName == "release"){ + /* release keys */ + int code = 0; + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i) == "key"){ + /* keyname */ + code = KeyNames::getCode(attr.value(i)); + } else if(attr.localName(i) == "code"){ + /* keycode */ + code = KHUtil::hex2int(attr.value(i).lower()); + } + } + if(code > 0){ + m_release.append(code); + } + } + return(true); +} + +bool ModifiersHandler::endElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */) +{ + if(localName == "define"){ + if(m_type != QString::null && m_code > 0){ + /* assign modifier */ + m_pModifiers->assign(m_type, m_code, m_mask, m_toggle); + for(QValueList<int>::Iterator it=m_release.begin(); + it!=m_release.end(); ++it){ + /* assign modifier release keys */ + m_pModifiers->assignRelease(*it); + } + int code = KeyNames::getCode(m_type); + if(code <= 0){ + qDebug("setCode[%s][%x]", m_type.latin1(), m_code); + KeyNames::setCode(m_type, m_code); + } + if(m_mapping){ + /* auto mapping */ + m_pMappings->assign(m_code, m_mask, code, 0); + } + } + } else if(localName == "modifiers"){ + /* return parent */ + m_parser->setContentHandler(m_parent); + } + return(true); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/ModifiersHandler.h b/noncore/applets/keyhelper/keyhelperapplet/config/ModifiersHandler.h new file mode 100644 index 0000000..e2d8785 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/ModifiersHandler.h @@ -0,0 +1,48 @@ +#ifndef _MODIFIERS_HANDLER_H_ +#define _MODIFIERS_HANDLER_H_ + +#include <qstring.h> +#include <qvaluelist.h> +#include <qxml.h> +#include "KeyModifiers.h" +#include "KeyMappings.h" +#include "KeyNames.h" +#include "KHUtil.h" + +class ModifiersHandler : public QXmlDefaultHandler +{ +public: + void dispose(QXmlReader* parser, QXmlContentHandler* parent); + + void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + void setKeyMappings(KeyMappings* map) + { + m_pMappings = map; + } + + bool startElement(const QString& namespaceURI, + const QString& localName, + const QString& qName, + const QXmlAttributes& atts); + bool endElement(const QString& namespaceURI, + const QString& localName, + const QString& qName); +private: + QXmlContentHandler* m_parent; + QXmlReader* m_parser; + + KeyModifiers* m_pModifiers; + KeyMappings* m_pMappings; + + QString m_type; + int m_code; + int m_mask; + QValueList<int> m_release; + bool m_mapping; + bool m_toggle; +}; + +#endif /* _MODIFIERS_HANDLER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/RepeaterHandler.cpp b/noncore/applets/keyhelper/keyhelperapplet/config/RepeaterHandler.cpp new file mode 100644 index 0000000..aeae761 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/RepeaterHandler.cpp @@ -0,0 +1,76 @@ +#include "RepeaterHandler.h" + +void RepeaterHandler::dispose(QXmlReader* parser, QXmlContentHandler* parent) +{ + m_parser = parser; + m_parent = parent; + m_parser->setContentHandler(this); +} + +bool RepeaterHandler::startElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */, + const QXmlAttributes& attr) +{ + if(localName == "repeat"){ + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i).lower() == "delay"){ + bool ok; + int delay = attr.value(i).toInt(&ok); + if(ok){ + m_pRepeater->setDelay(delay); + } + } else if(attr.localName(i).lower() == "period"){ + bool ok; + int period = attr.value(i).toInt(&ok); + if(ok){ + m_pRepeater->setPeriod(period); + } + } else if(attr.localName(i).lower() == "mode"){ + /* default mode */ + bool ok; + int mode = attr.value(i).toInt(&ok); + if(ok){ + m_pRepeater->setMode(mode); + } + } + } + } else if(localName == "define"){ + /* ÊÑ¿ô½é´ü²½ */ + m_code = 0; + m_enable = true; + for(int i=0; i<attr.length(); i++){ + if(attr.localName(i).lower() == "key"){ + /* keyname */ + m_code = KeyNames::getCode(attr.value(i)); + } else if(attr.localName(i).lower() == "code"){ + /* keycode */ + m_code = KHUtil::hex2int(attr.value(i).lower()); + } else if(attr.localName(i).lower() == "enable"){ + /* enable/disable */ + if(attr.value(i).lower() == "false"){ + m_enable = false; + } else { + m_enable = true; + } + } + } + } + return(true); +} + +bool RepeaterHandler::endElement(const QString& /* namespaceURI */, + const QString& localName, + const QString& /* qName */) +{ + if(localName == "define"){ + if(m_code > 0){ + /* set repeat enable/disable */ + m_pRepeater->setRepeatable(m_code, m_enable); + } + } else if(localName == "repeater"){ + /* return parent */ + m_parser->setContentHandler(m_parent); + } + return(true); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/config/RepeaterHandler.h b/noncore/applets/keyhelper/keyhelperapplet/config/RepeaterHandler.h new file mode 100644 index 0000000..d25583b --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/config/RepeaterHandler.h @@ -0,0 +1,39 @@ +#ifndef _REPEATER_HANDLER_H_ +#define _REPEATER_HANDLER_H_ + +#include <qstring.h> +#include <qvaluelist.h> +#include <qxml.h> +#include "KeyRepeater.h" +#include "KeyNames.h" +#include "KHUtil.h" + +class RepeaterHandler : public QXmlDefaultHandler +{ +public: + void dispose(QXmlReader* parser, QXmlContentHandler* parent); + + void setKeyRepeater(KeyRepeater* rep) + { + m_pRepeater = rep; + } + + bool startElement(const QString& namespaceURI, + const QString& localName, + const QString& qName, + const QXmlAttributes& atts); + bool endElement(const QString& namespaceURI, + const QString& localName, + const QString& qName); +private: + QXmlContentHandler* m_parent; + QXmlReader* m_parser; + + KeyRepeater* m_pRepeater; + + int m_code; + bool m_enable; + +}; + +#endif /* _REPEATER_HANDLER_H_ */ 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 @@ +#include "ExtensionFactory.h" + +ExtensionFactory::ExtensionFactory() +{ + qDebug("ExtensionFactory::ExtensionFactory()"); + m_pLoadList = NULL; +} + +ExtensionFactory::~ExtensionFactory() +{ + qDebug("ExtensionFactory::~ExtensionFactory()"); +} + +ExtensionInterface* ExtensionFactory::createInstance(const QString& kind) +{ + ExtensionInterface* ext; + QString kindstr = kind.lower(); + + if(kindstr == "switch"){ + ext = new TaskSwitcher(kindstr); + } else if(kindstr == "select"){ + ext = new TaskSelector(kindstr); + } else if(kindstr.find("launch") == 0){ + ext = new KeyLauncher(kindstr); + } else if(kindstr.find("menu") == 0){ + ext = new MenuLauncher(kindstr); + } else { + return(NULL); + } + m_oExtList.append(ext); + return(ext); +} + +ExtensionInterface* ExtensionFactory::createInstance(const QString& kind, + int keycode, int keymask) +{ + ExtensionInterface* ext; + QString kindstr = kind.lower(); + + ext = loadInstance(kindstr, keycode, keymask); + if(ext != NULL){ + return(ext); + } + + if(kindstr == "switch"){ + ext = new TaskSwitcher(kindstr); + } else if(kindstr == "select"){ + ext = new TaskSelector(kindstr); + } else if(kindstr.find("launch") == 0){ + ext = new KeyLauncher(kindstr); + } else if(kindstr.find("menu") == 0){ + ext = new MenuLauncher(kindstr); + } else { + return(NULL); + } + ext->setKeycode(keycode); + ext->setKeymask(keymask); + + m_oExtList.append(ext); + return(ext); +} + +ExtensionInterface* ExtensionFactory::loadInstance(const QString& kindstr, + int keycode, int keymask) +{ + if(m_pLoadList == NULL){ + return(NULL); + } + + for(ExtensionList::Iterator it=m_pLoadList->begin(); + it!=m_pLoadList->end(); ++it){ + if((*it)->kind() == kindstr + && (*it)->getKeycode() == keycode + && (*it)->getKeymask() == keymask){ + m_oExtList.append(*it); + return(*it); + } + } + return(NULL); +} + +void ExtensionFactory::clear() +{ + for(ExtensionList::Iterator it=m_oExtList.begin(); + it!=m_oExtList.end(); ++it){ + delete *it; + } + m_oExtList.clear(); +} + +void ExtensionFactory::reset() +{ + m_pLoadList = new ExtensionList(m_oExtList); + m_oExtList.clear(); +} + +void ExtensionFactory::sweep() +{ + if(m_pLoadList == NULL){ + return; + } + for(ExtensionList::Iterator it=m_pLoadList->begin(); + it!=m_pLoadList->end(); ++it){ + if(m_oExtList.contains(*it) == false){ + delete *it; + } + } + delete m_pLoadList; + m_pLoadList = NULL; +} 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 @@ +#ifndef _EXTENSION_FACTORY_H_ +#define _EXTENSION_FACTORY_H_ + +#include "ExtensionInterface.h" +#include "TaskSwitcher.h" +#include "KeyLauncher.h" +#include "TaskSelector.h" +#include "MenuLauncher.h" + +class ExtensionFactory +{ +public: + ExtensionFactory(); + virtual ~ExtensionFactory(); + + ExtensionInterface* createInstance(const QString& kind); + ExtensionInterface* createInstance(const QString& kind, + int keycode, int keymask); + ExtensionList& getList() + { + return(m_oExtList); + } + void clear(); + void reset(); + void sweep(); +private: + ExtensionList m_oExtList; + ExtensionList* m_pLoadList; + + ExtensionInterface* loadInstance(const QString& kind, + int keycode, int keymask); +}; + +#endif /* _EXTENSION_FACTORY_H_ */ + 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 @@ +#ifndef _EXTENSION_INTERFACE_H_ +#define _EXTENSION_INTERFACE_H_ + +#include <qvaluelist.h> + +class ExtensionInterface +{ +public: + //ExtensionInterface(); + virtual ~ExtensionInterface(){} + virtual bool onKeyPress(int keycode) = 0; + virtual bool onModRelease(int modcode) = 0; + virtual int getKeycode() = 0; + virtual int getKeymask() = 0; + virtual const QValueList<int>& getModcodes() = 0; + virtual void setKeycode(int keycode) = 0; + virtual void setKeymask(int keymask) = 0; + virtual void setModcodes(const QValueList<int>& modcodes) = 0; + virtual const QString& kind() = 0; +private: +}; + +typedef QValueList<ExtensionInterface*> ExtensionList; + +#endif /* _EXTENSION_INTERFACE_H_ */ + 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 @@ +#include "KeyExtensions.h" + +KeyExtensions::KeyExtensions() +{ + qDebug("KeyExtensions::KeyExtensions()"); + m_cancelcode = 0; +} + +KeyExtensions::~KeyExtensions() +{ + qDebug("KeyExtensions::~KeyExtensions()"); + clear(); +} + +void KeyExtensions::assign(const QString& kind, int keycode, + int keymask, const QValueList<int>& modcodes) +{ + ExtensionInterface* ext; +#if 0 + ext = m_oExtFactory.createInstance(kind); + if(ext != NULL){ + ext->setKeycode(keycode); + ext->setKeymask(keymask); + ext->setModcodes(modcodes); + } +#else + ext = m_oExtFactory.createInstance(kind, keycode, keymask); + if(ext != NULL){ + ext->setModcodes(modcodes); + } +#endif +} + +void KeyExtensions::assign(const QString& kind, int keycode, + int keymask, int modcode) +{ + QValueList<int> modcodes; + modcodes.append(modcode); + assign(kind, keycode, keymask, modcodes); +} + +bool KeyExtensions::doKey(int keycode, int keymask, bool isPress) +{ + bool fCancel = false; + ExtensionList& list = m_oExtFactory.getList(); + for(ExtensionList::Iterator it=list.begin(); + it!=list.end(); ++it){ + if(isPress){ + int code = (*it)->getKeycode(); + if((*it)->getKeymask() == keymask + && (code == 0 || code == keycode)){ + if((*it)->onKeyPress(keycode)){ + fCancel = true; + } + qWarning("ext:onKeyPress[%s][%x][%d]", + (*it)->kind().latin1(), + (*it)->getKeycode(), + fCancel); + } + } else { + if(keycode == m_cancelcode){ + fCancel = true; + } + const QValueList<int>& rlist = (*it)->getModcodes(); + if(rlist.contains(keycode)){ + if((*it)->onModRelease(keycode)){ + m_pModifiers->resetToggles(); + } + qWarning("ext:onModRelease[%s][%x]", + (*it)->kind().latin1(), + keycode); + } + } + } + if(isPress && fCancel){ + m_cancelcode = keycode; + } else { + m_cancelcode = 0; + } + return(fCancel); +} + +void KeyExtensions::clear() +{ + m_oExtFactory.clear(); +} + +void KeyExtensions::reset() +{ + //clear(); + m_oExtFactory.reset(); +} + +void KeyExtensions::init() +{ + m_oExtFactory.sweep(); +} + +void KeyExtensions::statistics() +{ + qWarning("KeyExtensions::statistics()"); + ExtensionList& list = m_oExtFactory.getList(); + for(ExtensionList::Iterator it=list.begin(); + it!=list.end(); ++it){ + qWarning(" [%s][%x][%x]", + (*it)->kind().latin1(), + (*it)->getKeycode(), + (*it)->getKeymask()); + } +} + 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 @@ +#ifndef _KEY_EXTENSIONS_H_ +#define _KEY_EXTENSIONS_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include "KeyNames.h" +#include "KeyModifiers.h" +#include "ExtensionFactory.h" + +class KeyExtensions +{ +public: + KeyExtensions(); + ~KeyExtensions(); + + void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + + void assign(const QString& kind, int keycode, + int keymask, const QValueList<int>& modcodes); + void assign(const QString& kind, int keycode, + int keymask, int modcode); + bool doKey(int keycode, int keymask, bool isPress); + + void statistics(); + + void reset(); + void init(); +private: + KeyModifiers* m_pModifiers; + ExtensionFactory m_oExtFactory; + int m_cancelcode; + + void clear(); +}; + +#endif /* _KEY_EXTENSIONS_H_ */ + 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 @@ +#include "KeyLauncher.h" +#include "KHUtil.h" + +KeyLauncher::KeyLauncher(const QString& kind) : m_kind(kind) +{ + qDebug("KeyLauncher::KeyLauncher()"); +} + +KeyLauncher::~KeyLauncher() +{ + qDebug("KeyLauncher::~KeyLauncher()"); +} + +bool KeyLauncher::onKeyPress(int keycode) +{ + QString key; + QStringList args; + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + key = KeyNames::getName(keycode); + if(key == QString::null){ + return(false); + } + + QString group = kind(); + group[0] = group[0].upper(); + + /* read application launcher */ + QString app = KHUtil::currentApp(); + if(!app.isEmpty()){ + cfg.setGroup(group + "_" + app); + /* read config */ + args = cfg.readListEntry(key, '\t'); + } + + /* read default launcher */ + if(args.isEmpty()){ + cfg.setGroup(group); + + /* read config */ + args = cfg.readListEntry(key, '\t'); + } + + if(args.isEmpty()){ + return(false); + } + + /* launch application */ + LnkWrapper lnk(args); + if(lnk.isValid()){ + //args.remove(args.begin()); + lnk.instance().execute(); + } + + return(true); +} + 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 @@ +#ifndef _KEY_LAUNCHER_H_ +#define _KEY_LAUNCHER_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> + +#include <qpe/qpeapplication.h> +#include <qpe/config.h> +#include <qpe/applnk.h> +#include <qpe/global.h> +#include <qpe/qcopenvelope_qws.h> + +#include "ExtensionInterface.h" +#include "KeyNames.h" +#include "LnkWrapper.h" +#include "ConfigEx.h" + +class KeyLauncher : public ExtensionInterface +{ +public: + KeyLauncher(const QString& kind = "launch"); + virtual ~KeyLauncher(); + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int /*modcode*/){return(false);} + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; +}; + +#endif /* _KEY_LAUNCHER_H_ */ + 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 @@ +#include "MenuLauncher.h" +extern QWidget* g_Widget; + +MenuLauncher::MenuLauncher(const QString& kind) : m_kind(kind) +{ + qDebug("MenuLauncher::MenuLauncher()"); + m_pMenu = m_pTopMenu = NULL; + + m_isShowing = false; + m_id = -1; + + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), + this, SLOT(select())); + + init(); +} + +MenuLauncher::~MenuLauncher() +{ + qDebug("MenuLauncher::~MenuLauncher()"); + delete m_pTopMenu; + delete m_pTimer; +} + +void MenuLauncher::init() +{ + buildMenu(); +} + +QPopupMenu* MenuLauncher::initMenu(QWidget* parent, const QString& name) +{ + QPopupMenu* pMenu; + pMenu = new QPopupMenuEx(parent, name); + pMenu->installEventFilter(this); + connect(pMenu, SIGNAL(activated(int)), this, SLOT(select(int))); + connect(pMenu, SIGNAL(highlighted(int)), this, SLOT(highlight(int))); + //connect(pMenu, SIGNAL(aboutToHide()), this, SLOT(execute())); + return(pMenu); +} + +bool MenuLauncher::onKeyPress(int /*keycode*/) +{ + if(m_isShowing){ + qDebug("showing ..."); + } else if(m_pMenu->isVisible()){ + next(); + } else { + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Global"); + int delay = cfg.readNumEntry("DelayPopup", 5); + QTimer::singleShot(delay, this, SLOT(show())); + m_isShowing = true; + } + return true; +} + +bool MenuLauncher::onModRelease(int /*modcode*/) +{ + if(m_pMenu->isVisible()){ + QTimer::singleShot(0, this, SLOT(select())); + return(true); + } else { + return(false); + } +} + +QString MenuLauncher::getMenuText(const QString& key, const QString& name) +{ + QRegExp rx("^[0-9]+_"); + QString text; + QString ackey; + int len; + if(rx.match(key, 0, &len) == 0){ + ackey = key.mid(len); + } else { + ackey = key; + } + if(ackey.length() == 1){ + text = name; + text.append("(&"); + text.append(ackey); + text.append(")"); + } else { + text = ackey; + } + return(text); +} + +int MenuLauncher::buildMenu(const QString& section, + QPopupMenu* pMenu, int& id) +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + if(m_oMenuList.contains(pMenu)){ + /* ̵¸Â¥ë¡¼¥×ËÉ»ß */ + return(0); + } + m_oMenuList.append(pMenu); + + QString oldgroup = cfg.getGroup(); + + QString group = section; + group[0] = group[0].upper(); + + cfg.setGroup(group); + + QStringList apps = cfg.getKeys(); + int cnt = 0; + if(apps.isEmpty() == false){ + for(QStringList::Iterator it=apps.begin(); + it!=apps.end(); ++it){ + QStringList args = cfg.readListEntry(*it, '\t'); + LnkWrapper lnk(args); + if(lnk.isValid()){ + cnt++; + QString text = getMenuText(*it, lnk.instance().name()); + if(args[0] == "@menu"){ + QPopupMenu* pSubMenu = initMenu(m_pTopMenu, args[1]); + pMenu->insertItem(lnk.instance().pixmap(), text, + pSubMenu, id); + m_oItemList.append(ItemInfo(section)); + id++; + buildMenu(args[1], pSubMenu, id); + } else { + pMenu->insertItem(lnk.instance().pixmap(), text, id); + m_oItemList.append(ItemInfo(section, *it)); + id++; + } + } + } + } + cfg.setGroup(oldgroup); + return(cnt); +} + +void MenuLauncher::clearSubMenu() +{ + for(QValueList<QPopupMenu*>::Iterator it=m_oMenuList.begin(); + it!=m_oMenuList.end(); ++it){ + if(*it != m_pTopMenu){ + delete *it; + } + } + m_oMenuList.clear(); + m_oItemList.clear(); +} + +int MenuLauncher::buildMenu(bool force) +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + if(!force && m_lastmodify == cfg.lastRead()){ + return(m_pTopMenu->count()); + } + qDebug("buildMenu"); + + QString oldgroup = cfg.getGroup(); + + cfg.setGroup("Global"); + m_submenuTimeout = cfg.readNumEntry("SubMenuTimeout", 500); + + if(m_pTopMenu){ + delete m_pTopMenu; + } + m_pMenu = m_pTopMenu = initMenu(g_Widget, kind()); + m_oLastId.clear(); + m_oMenuList.clear(); + m_oItemList.clear(); + + MenuTitle* pTitle = new MenuTitle("MenuLauncher", + m_pTopMenu->font(), kind()); + m_pTopMenu->insertItem(pTitle); + + int id = 0; + int cnt = buildMenu(kind(), m_pTopMenu, id); + if(cnt > 0){ + m_lastmodify = cfg.lastRead(); + } + + cfg.setGroup(oldgroup); + return(cnt); +} + +void MenuLauncher::show() +{ + m_enablePopup = false; + int cnt = buildMenu(); + if(cnt > 0){ + m_pMenu = m_pTopMenu; + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Style"); + int x,y; + QString key = "Position_" + kind(); + if(cfg.hasKey(key)){ + const QStringList& list = cfg.readListEntry(key, ','); + x = list[0].toInt(); + y = list[1].toInt(); + } else { + x = (qt_screen->width() - m_pTopMenu->sizeHint().width()) / 2; + y = (qt_screen->height() - m_pTopMenu->sizeHint().height()) / 2; + } + QPoint pos(x, y); + m_pTopMenu->popup(pos); + m_pTopMenu->setActiveItem(1); + } + m_isShowing = false; +} + +void MenuLauncher::next() +{ + int index = m_pMenu->indexOf(m_id); + index++; + if(index >= (signed int)m_pMenu->count()){ + if(m_pMenu == m_pTopMenu){ + index = 1; + } else { + index = 0; + } + } + m_pMenu->setActiveItem(index); + m_id = m_pMenu->idAt(index); +} + +void MenuLauncher::select() +{ + if(m_pMenu->isVisible()){ + QMenuItem* item = m_pMenu->findItem(m_id); + int index = m_pMenu->indexOf(m_id); + QPopupMenu* p = m_pMenu; + //m_pMenu->activateItemAt(index); + if(item && item->popup()){ + m_pMenu = item->popup(); + } + p->activateItemAt(index); + } +} + +void MenuLauncher::select(int id) +{ + if(id >= 0 && m_oItemList[id].entry != QString::null){ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + cfg.setGroup("Global"); + int delay = cfg.readNumEntry("DelayExec", 100); + + QString group = m_oItemList[id].group; + group[0] = group[0].upper(); + cfg.setGroup(group); + + //QStringList args = cfg.readListEntry(m_oItemList[id].entry, '\t'); + m_args = cfg.readListEntry(m_oItemList[id].entry, '\t'); + +#if 0 + LnkWrapper lnk(args); + if(lnk.isValid()){ + lnk.instance().execute(); + } +#else + QTimer::singleShot(delay, this, SLOT(execute())); +#endif + } + m_pMenu = m_pTopMenu; + m_id = -1; +} + +void MenuLauncher::execute() +{ + LnkWrapper lnk(m_args); + if(lnk.isValid()){ + lnk.instance().execute(); + } + m_args.clear(); +} + +void MenuLauncher::highlight(int id) +{ + if(m_pMenu && m_pMenu->isVisible()){ + m_id = id; + if(m_enablePopup){ + QMenuItem* item = m_pMenu->findItem(m_id); + if(item && item->popup()){ + if(m_submenuTimeout > 0){ + m_pTimer->start(m_submenuTimeout, true); + } + } else { + m_pTimer->stop(); + } + } else { + /* ¥á¥Ë¥å¡¼É½¼¨Ä¾¸å¤Ï¥Ý¥Ã¥×¥¢¥Ã¥×¤·¤Ê¤¤ */ + m_enablePopup = true; + } + } +} + +bool MenuLauncher::eventFilter(QObject* o, QEvent* e) +{ + if(m_pTopMenu->isVisible()){ + QKeyEvent* ke = (QKeyEvent*)e; + switch(e->type()){ + case QEvent::Accel: + if(ke->key() == Qt::Key_Space + && ke->isAutoRepeat() == false){ + select(); + } + break; + case QEvent::FocusIn: + //qDebug("FocusIn[%p][%p]", o, m_pMenu); + m_pMenu = (QPopupMenu*)o; + if(m_oLastId.contains(o)){ + m_id = m_oLastId[o]; + } + m_pMenu->updateItem(m_id); + break; + case QEvent::FocusOut: + //qDebug("FocusOut[%p][%p]", o, m_pMenu); + m_oLastId[o] = m_id; + break; + default: + //qDebug(">>>>> [%p][%d] <<<<<", o, e->type()); + break; + } + } + return QObject::eventFilter(o, e); +} 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 @@ +#ifndef _MENU_LAUNCHER_H_ +#define _MENU_LAUNCHER_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <qwindowsystem_qws.h> +#define INCLUDE_MENUITEM_DEF +#include <qpopupmenu.h> +#include <qpoint.h> +#include <qtimer.h> +#include <qgfx_qws.h> + +#include <qpe/global.h> +#include <qpe/applnk.h> +#include <qpe/config.h> +#include <qpe/qpeapplication.h> + +#include "ExtensionInterface.h" +#include "MenuTitle.h" +#include "KeyNames.h" +#include "ConfigEx.h" +#include "LnkWrapper.h" +#include "QPopupMenuEx.h" + +struct ItemInfo{ + ItemInfo(QString g=QString::null, QString e=QString::null) + : group(g), entry(e){} + QString group; + QString entry; +}; + +class MenuLauncher : public QObject, public ExtensionInterface +{ + Q_OBJECT +public: + MenuLauncher(const QString& kind = "menu"); + virtual ~MenuLauncher(); + + typedef QValueList<ItemInfo> ItemList; + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int modcode); + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +public slots: + void show(); + void select(); + void select(int id); + void highlight(int id); +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; + + int m_submenuTimeout; + bool m_isShowing; + bool m_enablePopup; + int m_id; + QPopupMenu* m_pMenu; + QPopupMenu* m_pTopMenu; + QDateTime m_lastmodify; + + QMap<QObject*, int> m_oLastId; + QValueList<QPopupMenu*> m_oMenuList; + ItemList m_oItemList; + QTimer* m_pTimer; + + QStringList m_args; + + QString getMenuText(const QString& key, const QString& name); + QPopupMenu* initMenu(QWidget* parent, const QString& name); + int buildMenu(bool force=false); + int buildMenu(const QString& section, QPopupMenu* pMenu, int& id); + void clearSubMenu(); + void init(); + void next(); +private slots: + bool eventFilter(QObject* o, QEvent* e); + void execute(); +}; + +#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 @@ +#include "MenuTitle.h" + +MenuTitle::MenuTitle(const QString& s, const QFont& f, const QString& k) +{ + font = f; + kind = k; + + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + const QString curGroup = cfg.getGroup(); + cfg.setGroup("Style"); + + caption = cfg.readEntry("Caption_" + k, s); + cfg.setGroup(curGroup); +} + +bool MenuTitle::fullSpan() const +{ + return(true); +} + +bool MenuTitle::isSeparator() const +{ + return(true); +} + +void MenuTitle::paint(QPainter* p, const QColorGroup& cg, bool /*act*/, + bool /*enabled*/, int x, int y, int w, int h) +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + const QString& curGroup = cfg.getGroup(); + + cfg.setGroup("Style"); + + QString name; + QColor color; + + p->setFont(font); + + /* set fontcolor */ + name = cfg.readEntry("FontColor_" + kind, QString::null); + if(name != QString::null){ + color.setNamedColor(name); + if(color.isValid()){ + p->setPen(color); + } + } + + /* set bgcolor */ + name = cfg.readEntry("BgColor_" + kind, QString::null); + if(name != QString::null){ + color.setNamedColor(name); + if(color.isValid() == false){ + color = cg.mid(); + } + } else { + color = cg.mid(); + } + p->fillRect(x, y, w, h, QBrush(color)); + p->drawText(x, y, w, h, AlignCenter, caption); + cfg.setGroup(curGroup); +} + +QSize MenuTitle::sizeHint() +{ + return(QFontMetrics(font).size(AlignCenter, caption)); +} 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 @@ +#ifndef _MENU_TITLE_ITEM_H_ +#define _MENU_TITLE_ITEM_H_ + +#include <qmenudata.h> +#include <qpainter.h> +#include <qbrush.h> +#include <qcolor.h> +#include <qpalette.h> +#include <qpe/config.h> +#include "ConfigEx.h" + +class MenuTitle : public QCustomMenuItem +{ +public: + MenuTitle(const QString& s, const QFont& f, const QString& k = "default"); + virtual ~MenuTitle(){} + + bool fullSpan () const; + bool isSeparator() const; + void paint(QPainter* p, const QColorGroup& cg, bool act, + bool enabled, int x, int y, int w, int h); + QSize sizeHint(); +private: + QString caption; + QString kind; + QFont font; +}; + +#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 @@ +#ifndef _QPOPUPMENUEX_H_ +#define _QPOPUPMENUEX_H_ + +#include <qpopupmenu.h> +#include <qstring.h> +#include <qevent.h> + +class QPopupMenuEx : public QPopupMenu +{ +public: + QPopupMenuEx(QWidget* parent=0, const char* name=0) + : QPopupMenu(parent, name){} +protected: + void keyPressEvent(QKeyEvent* e){ + QChar c = e->text()[0]; + QKeyEvent* ke = new QKeyEvent( + e->type(), + e->key(), + c.lower().latin1(), + 0, + c.lower(), + e->isAutoRepeat()); + QPopupMenu::keyPressEvent(ke); + } +private: +}; + +#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 @@ +#include "TaskSelector.h" +extern QWidget* g_Widget; + +static const char* defkeys = +"QWERTYUIOPASDFGHJKLZXCVBNM1234567890"; + +#define START_INDEX 1 + +TaskSelector::TaskSelector(const QString& kind) : m_kind(kind) +{ + qDebug("TaskSelector::TaskSelector()"); + m_pMenu = new QPopupMenuEx(g_Widget); + m_pMenu->installEventFilter(this); + + m_isShowing = false; + m_index = START_INDEX-1; + connect(m_pMenu, SIGNAL(activated(int)), this, SLOT(select(int))); + connect(m_pMenu, SIGNAL(highlighted(int)), this, SLOT(highlight(int))); +} + +TaskSelector::~TaskSelector() +{ + qDebug("TaskSelector::~TaskSelector()"); + delete m_pMenu; +} + +bool TaskSelector::onKeyPress(int /*keycode*/) +{ + if(m_isShowing){ + qDebug("showing ..."); + } else if(m_pMenu->isVisible()){ + next(); + } else { + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Global"); + int delay = cfg.readNumEntry("DelayPopup", 5); + QTimer::singleShot(delay, this, SLOT(show())); + m_isShowing = true; + } + return true; +} + +bool TaskSelector::onModRelease(int /*modcode*/) +{ + if(m_pMenu->isVisible()){ + //m_pMenu->hide(); + QTimer::singleShot(0, this, SLOT(select())); + return(true); + } else { + return(false); + } +} + +int TaskSelector::buildMenu() +{ + const AppLnk* lnk; + + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + QString oldgroup; + + oldgroup = cfg.getGroup(); + cfg.setGroup("Global"); + QString accesskeys = cfg.readEntry("AccessKeys", defkeys); + if(accesskeys.length() <= 0){ + accesskeys = defkeys; + } + cfg.setGroup(oldgroup); + + /* get list */ + int cnt = 0; + m_index = START_INDEX+1; + m_applist.clear(); + m_pMenu->clear(); + MenuTitle* pTitle = new MenuTitle("TaskSelector", m_pMenu->font(), kind()); + m_pMenu->insertItem(pTitle); + const QList<QWSWindow>& list = qwsServer->clientWindows(); + QWSWindow* w; + for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ + if(w->isVisible() == false + || w->caption() == QString::null){ + continue; + } + QString app = w->client()->identity(); + if(app == NULL || m_applist.contains(app)){ + continue; + } + /* exclude "launcher" */ + if(app == "launcher"){ + if(cnt == 0){ + m_index--; + } + continue; + } + m_applist.append(app); + /* append menu */ + cnt++; + AppLnkSet* lnkSet = AppLnkManager::getInstance(); + lnk = lnkSet->findExec(app); + QString text; + QPixmap icon; +#if 0 + if(lnk != NULL){ + icon = lnk->pixmap(); + text = lnk->name(); + } else { + AppLnkManager::notfound(); + icon = QPixmap(); + text = w->caption(); + } +#else + if(lnk != NULL){ + icon = lnk->pixmap(); + if(w->caption().length() > 0){ + text = w->caption(); + } else { + text = lnk->name(); + } + } else { + AppLnkManager::notfound(); + icon = QPixmap(); + text = w->caption(); + } +#endif + if(cnt <= (int)accesskeys.length()){ + text.append("(&"); + text.append(accesskeys[cnt-1].upper()); + text.append(")"); + } + m_pMenu->insertItem(icon, text, cnt); + } + return(cnt); +} + +void TaskSelector::show() +{ + /* build task selector menu */ + int cnt = buildMenu(); + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + QString oldgroup = cfg.getGroup(); + cfg.setGroup("Global"); + int min = cfg.readNumEntry("SelectMenuMin", 2); + if(min != 1 && min != 3){ + min = 2; + } + cfg.setGroup(oldgroup); + + if(cnt == 0){ + qDebug("no applications"); + } else if(cnt < min){ + //m_index = START_INDEX; + if(m_index > cnt){ + m_index = cnt; + } + QTimer::singleShot(0, this, SLOT(select())); + } else { + if(m_index > cnt){ + m_index = cnt; + } + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Style"); + int x,y; + QString key = "Position_" + kind(); + if(cfg.hasKey(key)){ + const QStringList& list = cfg.readListEntry(key, ','); + x = list[0].toInt(); + y = list[1].toInt(); + } else { + x = (qt_screen->width() - m_pMenu->sizeHint().width()) / 2; + y = (qt_screen->height() - m_pMenu->sizeHint().height()) / 2; + } + QPoint pos(x, y); + m_pMenu->popup(pos); + m_pMenu->setActiveItem(m_index); + } + m_isShowing = false; +} + +void TaskSelector::next() +{ + m_index++; + if(m_index > (signed int)m_applist.count()){ + m_index = START_INDEX; + } + m_pMenu->setActiveItem(m_index); +} + +void TaskSelector::select() +{ + //select(m_index); + m_pMenu->activateItemAt(m_index); +} + +void TaskSelector::select(int index) +{ + if(index > 0){ + Global::execute(m_applist[index-1]); + } + m_index = 0; +} + +void TaskSelector::highlight(int index) +{ + if(m_pMenu->isVisible()){ + m_index = index; + } +} + +bool TaskSelector::eventFilter(QObject* o, QEvent* e) +{ + if(m_pMenu->isVisible()){ + QKeyEvent* ke = (QKeyEvent*)e; + switch(e->type()){ + case QEvent::Accel: + if(ke->key() == Qt::Key_Space + && ke->isAutoRepeat() == false){ + select(); + } + break; + default: + //qDebug(">>>>> [%p][%d] <<<<<", o, e->type()); + break; + } + } + return QObject::eventFilter(o, e); +} 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 @@ +#ifndef _TASK_SELECTOR_H_ +#define _TASK_SELECTOR_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <qwindowsystem_qws.h> +#include <qpopupmenu.h> +#include <qpoint.h> +#include <qtimer.h> +#include <qgfx_qws.h> + +#include <qpe/global.h> +#include <qpe/applnk.h> +#include <qpe/config.h> +#include <qpe/mimetype.h> + +#include "ExtensionInterface.h" +#include "MenuTitle.h" +#include "KeyNames.h" +#include "AppLnkManager.h" +#include "ConfigEx.h" +#include "QPopupMenuEx.h" + +class TaskSelector : public QObject, public ExtensionInterface +{ + Q_OBJECT +public: + TaskSelector(const QString& kind = "select"); + virtual ~TaskSelector(); + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int modcode); + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +public slots: + void show(); + void select(); + void select(int); + void highlight(int id); +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; + + bool m_isShowing; + int m_index; + QPopupMenu* m_pMenu; + QStringList m_applist; + QString m_accesskeys; + + int buildMenu(); + void next(); +private slots: + bool eventFilter(QObject* o, QEvent* e); +}; + +#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 @@ +#include "TaskSwitcher.h" + +TaskSwitcher::TaskSwitcher(const QString& kind) : m_kind(kind) +{ + qDebug("TaskSwitcher::TaskSwitcher()"); +} + +TaskSwitcher::~TaskSwitcher() +{ + qDebug("TaskSwitcher::~TaskSwitcher()"); +} + +bool TaskSwitcher::onKeyPress(int /*keycode*/) +{ + if(m_applist.isEmpty()){ + /* get list */ + const QList<QWSWindow>& list = qwsServer->clientWindows(); + QWSWindow* w; + for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ + if(w->isVisible()){ + QString app = w->client()->identity(); + qDebug("applist[%s]", app.latin1()); + if(app != NULL && m_applist.contains(app) == false){ + m_applist.append(app); + } + } + } + m_appit = m_applist.begin(); + } + if(m_applist.count() > 1){ + /* switch next */ + next(); + if(*m_appit == "launcher"){ + next(); + } + Global::execute(*m_appit); + } else if(m_applist.count() == 1 + && *m_appit != "launcher"){ + Global::execute(*m_appit); + } else { + qDebug("no applications"); + } + return(true); +} + +bool TaskSwitcher::onModRelease(int /*keycode*/) +{ + m_applist.clear(); + return(false); +} + +void TaskSwitcher::next() +{ + ++m_appit; + if(m_appit == m_applist.end()){ + m_appit = m_applist.begin(); + } +} 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 @@ +#ifndef _TASK_SWITCHER_H_ +#define _TASK_SWITCHER_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <qwindowsystem_qws.h> + +#include <qpe/global.h> + +#include "ExtensionInterface.h" + +class TaskSwitcher : public ExtensionInterface +{ +public: + TaskSwitcher(const QString& kind = "switch"); + virtual ~TaskSwitcher(); + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int modcode); + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; + + QStringList m_applist; + QStringList::Iterator m_appit; + + void next(); +}; + +#endif /* _TASK_SWITCHER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/keyhelperapplet.pro b/noncore/applets/keyhelper/keyhelperapplet/keyhelperapplet.pro new file mode 100644 index 0000000..dafb077 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/keyhelperapplet.pro @@ -0,0 +1,80 @@ +TEMPLATE = lib +CONFIG = qt plugin warn_on +HEADERS = anylnk/AnyLnk.h \ + anylnk/AppLnkManager.h \ + anylnk/AppLnkWrapper.h \ + anylnk/DocLnkWrapper.h \ + anylnk/ExecLnk.h \ + anylnk/LnkWrapper.h \ + anylnk/MenuLnk.h \ + anylnk/ProcessInvoker.h \ + anylnk/QCopLnk.h \ + anylnk/TextLnk.h \ + applet/KeyHelper.h \ + applet/KeyHelperApplet.h \ + applet/KeyHelperWidget.h \ + applet/QSafeDataStream.h \ + config/ExtensionsHandler.h \ + config/KeycfgErrorHandler.h \ + config/KeycfgHandler.h \ + config/KeycfgReader.h \ + config/MappingsHandler.h \ + config/ModifiersHandler.h \ + config/RepeaterHandler.h \ + extension/ExtensionFactory.h \ + extension/ExtensionInterface.h \ + extension/KeyExtensions.h \ + extension/KeyLauncher.h \ + extension/MenuLauncher.h \ + extension/MenuTitle.h \ + extension/QPopupMenuEx.h \ + extension/TaskSelector.h \ + extension/TaskSwitcher.h \ + misc/ConfigEx.h \ + misc/KHUtil.h \ + misc/KeyAction.h \ + misc/KeyMappings.h \ + misc/KeyModifiers.h \ + misc/KeyNames.h \ + misc/KeyRepeater.h \ + misc/StringParser.h +SOURCES = anylnk/AnyLnk.cpp \ + anylnk/AppLnkManager.cpp \ + anylnk/AppLnkWrapper.cpp \ + anylnk/LnkWrapper.cpp \ + anylnk/ProcessInvoker.cpp \ + anylnk/QCopLnk.cpp \ + anylnk/TextLnk.cpp \ + applet/KeyHelper.cpp \ + applet/KeyHelperApplet.cpp \ + applet/KeyHelperWidget.cpp \ + applet/QSafeDataStream.cpp \ + config/ExtensionsHandler.cpp \ + config/KeycfgErrorHandler.cpp \ + config/KeycfgHandler.cpp \ + config/KeycfgReader.cpp \ + config/MappingsHandler.cpp \ + config/ModifiersHandler.cpp \ + config/RepeaterHandler.cpp \ + extension/ExtensionFactory.cpp \ + extension/KeyExtensions.cpp \ + extension/KeyLauncher.cpp \ + extension/MenuLauncher.cpp \ + extension/MenuTitle.cpp \ + extension/TaskSelector.cpp \ + extension/TaskSwitcher.cpp \ + misc/ConfigEx.cpp \ + misc/KHUtil.cpp \ + misc/KeyAction.cpp \ + misc/KeyMappings.cpp \ + misc/KeyModifiers.cpp \ + misc/KeyNames.cpp \ + misc/KeyRepeater.cpp \ + misc/StringParser.cpp +DESTDIR = $(OPIEDIR)/plugins/applets/ +INCLUDEPATH += $(OPIEDIR)/include ./misc ./config ./applet ./extension ./anylnk +LIBS += -lqpe -lopiecore2 +TARGET = keyhelperapplet +VERSION = 1.2.2 + +include( $(OPIEDIR)/include.pro ) 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 @@ +#include "ConfigEx.h" + +ConfigEx::ConfigEx(const QString& name, Domain domain) + : Config(name, domain) +{ + m_charset = "utf8"; + decode(); + m_lastRead = QDateTime::currentDateTime(); +} + +#if 0 +void ConfigEx::removeComment() +{ + for(QMap<QString,ConfigGroup>::Iterator it=groups.begin(); + it!=groups.end(); ++it){ + QStringList removeList; + for(ConfigGroup::Iterator it2=(*it).begin(); + it2!=(*it).end(); ++it2){ + if(it2.key()[0] == '#'){ + QString key = it2.key(); + removeList.append(it2.key()); + } + } + for(QStringList::Iterator it3=removeList.begin(); + it3!=removeList.end(); ++it3){ + (*it).remove(*it3); + } + } +} +#endif + +void ConfigEx::decode() +{ + QString group = getGroup(); + setGroup("Global"); + QString charset = readEntry("CharSet", "utf8"); + qWarning("ConfigEx::decode()[%s][%s]", charset.latin1(), m_charset.latin1()); + setGroup(group); + if(charset != m_charset){ + m_charset = charset; + read(); + } + //removeComment(); +} + +void ConfigEx::read() +{ + qWarning("ConfigEx::read()"); + groups.clear(); + changed = FALSE; + + if ( !QFileInfo( filename ).exists() ) { + git = groups.end(); + return; + } + + QFile f( filename ); + if ( !f.open( IO_ReadOnly ) ) { + git = groups.end(); + return; + } + + QTextStream s( &f ); +#ifdef CONFIG_MULTICODEC + QTextCodec* codec = QTextCodec::codecForName(m_charset); + if(codec == NULL){ + codec = QTextCodec::codecForName("utf8"); + qWarning("Config CharSet[utf8]"); + } else { + qWarning("Config CharSet[%s]", m_charset.latin1()); + } + s.setCodec(codec); +#else /* CONFIG_MULTICODEC */ +#if QT_VERSION <= 230 && defined(QT_NO_CODECS) + // The below should work, but doesn't in Qt 2.3.0 + s.setCodec( QTextCodec::codecForMib( 106 ) ); +#else + s.setEncoding( QTextStream::UnicodeUTF8 ); +#endif +#endif /* CONFIG_MULTICODEC */ + + QStringList list = QStringList::split('\n', s.read() ); + + f.close(); + + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + if ( !parse( *it ) ) { + git = groups.end(); + return; + } + } +} + +QStringList ConfigEx::getKeys() +{ + QStringList keys; + if(groups.end() != git){ + for(ConfigGroup::ConstIterator it=(*git).begin(); + it!=(*git).end(); ++it){ + if(it.key()[0] != '#'){ + keys.append(it.key()); + } + } + } + return(keys); +} + +QDateTime ConfigEx::lastModified() +{ + QFileInfo info(filename); + return(info.lastModified()); +} 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 @@ +#ifndef _CONFIG_EX_H_ +#define _CONFIG_EX_H_ + +#include <qstringlist.h> +#include <qdatetime.h> +#include <qfileinfo.h> +#include <qtextstream.h> +#include <qtextcodec.h> + +#define QTOPIA_INTERNAL_LANGLIST +#include <qpe/config.h> +#include <qpe/global.h> + +#define CONFIG_MULTICODEC + +/* Singleton Object */ +class ConfigEx : public Config +{ +public: + static ConfigEx& getInstance(const QString& name){ + static ConfigEx cfg(name); + if(/*cfg.flush() ||*/cfg.m_lastRead < cfg.lastModified()){ + cfg.load(&cfg); + } + return(cfg); + } + +#if 0 + bool flush(){ + if(changed){ + write(); + return(true); + } else { + return(false); + } + } +#endif + + const QString& getGroup(){ + return(git.key()); + } + + void load(ConfigEx* cfg){ + cfg->read(); + cfg->decode(); + cfg->m_lastRead = QDateTime::currentDateTime(); + } + + void setConfig(const QString& name){ + if(name == QString::null){ + return; + } + /*flush();*/ + filename = configFilename(name, User); + load(this); + } + + void reload() { + /*flush();*/ + load(this); + } + + QStringList getKeys(); + QDateTime lastModified(); + QDateTime lastRead(){ + return(m_lastRead); + } + + friend class Dummy; /* for compie warning */ +private: + ConfigEx(const QString& name, Domain domain=User); + ConfigEx& operator=(const ConfigEx&); + virtual ~ConfigEx(){changed = false;} + + class Dummy{}; /* for compile warning */ + + + void read(); + void decode(); + //void removeComment(); + + QDateTime m_lastRead; +#ifdef CONFIG_MULTICODEC + QString m_charset; +#endif +}; + +#endif /* _CONFIG_EX_H_ */ + 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 @@ +#include "KHUtil.h" +#include <qwindowsystem_qws.h> + +int KHUtil::hex2int(const QString& hexstr, bool* ok) +{ + int val; + bool success; + if(hexstr.find("0x") == 0){ + val = hexstr.mid(2).toInt(&success, 16); + } else { + val = hexstr.toInt(&success, 16); + } + if(!success){ + val = 0; + } + if(ok){ + *ok = success; + } + return(val); +} + +const QStringList KHUtil::parseArgs(const QString& arguments) +{ + QString str; + QStringList args; + char quote = 0; + char c; + for(unsigned int i=0; i<arguments.length(); i++){ + c = arguments[i]; + switch(c){ + case '\"': + if(quote == 0){ + quote = c; + } else if(quote == '\"'){ + if(str.length() > 0){ + args.append(str); + } + str = ""; + quote = 0; + } else { + str += c; + } + break; + case '\'': + if(quote == 0){ + quote = c; + } else if(quote == '\''){ + if(str.length() > 0){ + args.append(str); + } + str = ""; + quote = 0; + } else { + str += c; + } + break; + case ' ': + if(quote == 0){ + if(str.length() > 0){ + args.append(str); + str = ""; + } + } else { + str += c; + } + break; + default: + str += c; + break; + } + } + if(str.length() > 0){ + args.append(str); + } + return(args); +} + +const QString KHUtil::currentApp() +{ + QString app; + const QList<QWSWindow>& list = qwsServer->clientWindows(); + QWSWindow* w; + for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ + if(w->isVisible() && w->client()->identity() != QString::null){ + app = w->client()->identity(); + break; + } + } + return app; +} 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 @@ +#ifndef _KHUTIL_H_ +#define _KHUTIL_H_ + +#include <qstring.h> +#include <qstringlist.h> + +class KHUtil +{ +public: + static int hex2int(const QString& hexstr, bool* ok=NULL); + static const QStringList parseArgs(const QString& arguments); + static const QString currentApp(); +}; + +#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 @@ +#include "KeyAction.h" + +KeyAction::KeyAction() +{ + qDebug("KeyAction::KeyAction()"); + enable(); +} + +KeyAction::~KeyAction() +{ + qDebug("KeyAction::~KeyAction()"); +} + +void KeyAction::init() +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + QString oldgroup = cfg.getGroup(); + cfg.setGroup("Global"); + + m_keepToggle = cfg.readBoolEntry("KeepToggle", true); + + m_excludeKeys.clear(); + if(cfg.hasKey("ExcludeKeys")){ + QStringList keys = cfg.readListEntry("ExcludeKeys", ','); + for(QStringList::Iterator it=keys.begin(); + it!=keys.end(); ++it){ + int code; + if((*it).find("0x") == 0){ + code = KHUtil::hex2int(*it); + } else { + code = KeyNames::getCode(*it); + } + if(code > 0){ + m_excludeKeys.append(code); + } + } + } else { + m_excludeKeys.append(Qt::Key_F34); + } + + m_presscnt = 0; + m_check = true; + m_keep_toggle_code = 0; + m_capture = false; + cfg.setGroup(oldgroup); +} + +void KeyAction::setAction(int unicode, int keycode, int modifiers, + bool isPress, bool autoRepeat) +{ + m_unicode = unicode; + m_keycode = keycode; + m_modifiers = modifiers; + m_isPress = isPress; + m_autoRepeat = autoRepeat; +} + +bool KeyAction::checkState() +{ + if(0 < m_unicode && m_unicode < 0xFFFF){ + QChar ch(m_unicode); + QChar::Category category = ch.category(); + if(category == QChar::Letter_Lowercase){ + if(m_modifiers == 0){ + m_pMappings->setCapsLock(false); + return(true); + } else if(m_modifiers == Qt::ShiftButton){ + m_pMappings->setCapsLock(true); + return(true); + } + } else if(category == QChar::Letter_Uppercase){ + if(m_modifiers == 0){ + m_pMappings->setCapsLock(true); + return(true); + } else if(m_modifiers == Qt::ShiftButton){ + m_pMappings->setCapsLock(false); + return(true); + } + } + } + return(false); +} + +void KeyAction::sendKeyEvent(int unicode, int keycode, int modifiers, + bool isPress, bool autoRepeat) +{ + if(m_hookChannel.isEmpty()){ + QWSServer::sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); + } else { + if(QCopChannel::isRegistered(m_hookChannel)){ + QCopEnvelope e(m_hookChannel, "keyEvent(int,int,int,int,int)"); + e << unicode << keycode << modifiers << (int)isPress << (int)autoRepeat; + } else { + m_hookChannel = ""; + QWSServer::sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); + } + } +} + +bool KeyAction::doAction() +{ + if(m_enable == false){ + return(false); + } +#if 0 + if(m_excludeKeys.contains(m_keycode)){ + return(false); + } +#endif + if(!m_autoRepeat){ + qDebug("recv[%x][%x][%x][%d]", + m_unicode, + m_keycode, + m_modifiers, + m_isPress); + } + + if(m_autoRepeat && !m_excludeKeys.contains(m_keycode)){ + KeyRepeater::RepeaterMode repMode = m_pRepeater->getMode(); + if(repMode == KeyRepeater::ENABLE + || repMode == KeyRepeater::KILL){ + /* autoRepeat ¤Ï̵»ë */ + return(true); + } + } + + if(m_pRepeater->isRepeatable(m_keycode)){ + if(m_isPress){ + m_presscnt++; + } else { + m_presscnt--; + if(m_presscnt <= 0){ + m_pRepeater->stop(); + m_presscnt = 0; + } + } + } + + if(m_check && m_isPress){ + /* check capslock state */ + if(checkState()){ + m_check = false; + } + } + + int unicode, keycode, modifiers; + /* keep toggle reset */ + if(m_keepToggle && m_keep_toggle_code != 0){ + if(m_keep_toggle_code != m_keycode){ + m_pModifiers->resetToggles(); + m_keep_toggle_code = 0; + } else { + m_pModifiers->keepToggles(); + } + } + + /* modifier ¾õÂÖ¼èÆÀ */ + int keymask = m_pModifiers->getState(m_modifiers); + modifiers = m_pModifiers->getModifiers(m_modifiers); + + bool isModMapped = false; + /* modifier ¾õÂÖ¹¹¿· */ + if(m_autoRepeat == false){ + if(m_isPress){ + isModMapped = m_pModifiers->pressKey(m_keycode, m_modifiers); + } else { + m_pModifiers->releaseKey(m_keycode); + } + } + + if(m_capture && m_isPress && m_autoRepeat == false){ + QCopEnvelope e("QPE/KeyHelperConf", "event(int,int,int)"); + e << m_keycode << m_unicode << modifiers; + } + + /* keyextension ŬÍÑ */ + bool fKeyCancel = m_pExtensions->doKey(m_keycode, keymask, m_isPress); + if(fKeyCancel){ + if(m_keepToggle){ + m_keep_toggle_code = m_keycode; + } else { + m_pModifiers->resetToggles(); + } + m_pRepeater->stop(); + return(true); + } + + /* keymapping ŬÍÑ */ +#if 0 + bool isMapped = m_pMappings->apply(m_keycode, keymask, m_isPress); + if(isMapped == false){ + if(m_pMappings->isDefined()){ + m_pMappings->setOriginal(m_unicode, m_modifiers); + } else { + m_pMappings->setUnicode(m_unicode); + //m_pMappings->setKeycode(m_keycode); + } + //return(false); + } +#else + bool isMapped = m_pMappings->apply(m_unicode, m_keycode, m_modifiers, + keymask, m_isPress); +#endif + + /* modifier ŬÍÑ */ + m_pMappings->setModifiers(modifiers); + + keycode = m_pMappings->getKeycode(); + if(keycode <= 0){ + return(true); + } + + if(/*m_autoRepeat == false &&*/ m_isPress){ + if(isModMapped == false || (isModMapped && isMapped)){ + if(m_pModifiers->isModifier(keycode) == false){ + m_pModifiers->resetToggles(); + } + } + } + unicode = m_pMappings->getUnicode(); + modifiers = m_pMappings->getModifiers(); + if(keycode > 0){ + /* disable mapping */ + if(m_excludeKeys.contains(keycode)){ + return(false); + } + /* send key event */ + sendKeyEvent( + unicode, + keycode, + modifiers, + m_isPress, + m_autoRepeat); + } + if(m_isPress){ + /* repeater start */ + m_pRepeater->start(unicode, keycode, modifiers); +#if 0 + } else if(m_presscnt <= 0){ + m_presscnt = 0; + m_pRepeater->stop(); +#endif + } else { + m_pRepeater->stop(keycode); + } + qWarning("send[%x][%x][%x][%d]", + m_pMappings->getUnicode(), + m_pMappings->getKeycode(), + m_pMappings->getModifiers(), + m_isPress); + return(true); +} 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 @@ +#ifndef _KEY_ACTION_H_ +#define _KEY_ACTION_H_ + +#include <qobject.h> +#include <qwindowsystem_qws.h> +#include <qtimer.h> +#include <qpe/power.h> +#include "KeyMappings.h" +#include "KeyModifiers.h" +#include "KeyExtensions.h" +#include "KeyRepeater.h" +#include "ConfigEx.h" + +class KeyAction : public QObject +{ + Q_OBJECT +public: + KeyAction(); + virtual ~KeyAction(); + + void setKeyMappings(KeyMappings* map) + { + m_pMappings = map; + } + void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + void setKeyExtensions(KeyExtensions* ext) + { + m_pExtensions = ext; + } + void setKeyRepeater(KeyRepeater* rep) + { + m_pRepeater = rep; + connect(m_pRepeater, SIGNAL(keyEvent(int,int,int,bool,bool)), + this, SLOT(sendKeyEvent(int,int,int,bool,bool))); + } + void setAction(int unicode, int keycode, int modifiers, + bool isPress, bool autoRepeat); + bool doAction(); + + void enable(){ + init(); + m_enable = true; + }; + void disable(){ + m_enable = false; + }; + void setCapture(bool enable){ + m_capture = enable; + } + + void setHook(const QCString& s){ + m_hookChannel = s; + } +private: + int m_unicode; + int m_keycode; + int m_modifiers; + bool m_isPress; + bool m_autoRepeat; + + bool m_capture; + bool m_enable; + int m_presscnt; + + int m_keep_toggle_code; + bool m_keepToggle; + bool m_check; + QValueList<int> m_excludeKeys; + + QCString m_hookChannel; + + KeyMappings* m_pMappings; + KeyModifiers* m_pModifiers; + KeyExtensions* m_pExtensions; + KeyRepeater* m_pRepeater; + + void init(); + bool checkState(); +private slots: + void sendKeyEvent(int unicode, int keycode, int modifiers, + bool isPress, bool autoRepeat); +}; + +#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 @@ +#include "KeyMappings.h" + +static QIntDict<QWSServer::KeyMap> g_mapCache(127); + +MapInfo::MapInfo(int code, int mod, int uni, + int shift_uni, int ctrl_uni) +{ + const QWSServer::KeyMap* map; + if(uni == 0 || shift_uni == 0 || ctrl_uni == 0){ + map = MapInfo::findKeyMap(code); + if(map != NULL){ + isDefined = true; + unicode = map->unicode; + shift_unicode = map->shift_unicode; + ctrl_unicode = map->ctrl_unicode; + } else { + isDefined = false; + unicode = 0; + shift_unicode = 0; + ctrl_unicode = 0; + } + } else { + isDefined = true; + } + keycode = code; + modifiers = mod; + if(uni != 0){ + unicode = uni; + } + if(shift_uni != 0){ + shift_unicode = shift_uni; + } + if(ctrl_uni != 0){ + ctrl_unicode = ctrl_uni; + } +} + +const QWSServer::KeyMap* MapInfo::findKeyMap(int keycode) +{ + const QWSServer::KeyMap* m = QWSServer::keyMap(); + + while(m->key_code != 0){ + if(m->key_code == keycode){ + return(m); + } + m++; + } + return(NULL); +} + +KeyMappings::KeyMappings() +{ + qDebug("KeyMappings::KeyMappings()"); + init(); +} + +KeyMappings::~KeyMappings() +{ + qDebug("KeyMappings::~KeyMappings()"); + clear(); +} + +void KeyMappings::init() +{ + m_capslock = false; +} + +void KeyMappings::reset() +{ + clear(); +} + +void KeyMappings::clear() +{ + for(QMap<int, CodeMaps*>::Iterator it = m_keymaps.begin(); + it!=m_keymaps.end(); ++it){ + delete (*it); + } + m_keymaps.clear(); + g_mapCache.setAutoDelete(true); + g_mapCache.clear(); +} + +void KeyMappings::assign(int keycode, int keymask, int mapcode, + int mapmodifiers, int unicode, int shift_unicode, int ctrl_unicode) +{ + CodeMaps* map; + if(m_keymaps.contains(keycode)){ + map = m_keymaps[keycode]; + } else { + map = new CodeMaps(); + m_keymaps.insert(keycode, map); + } + + MapInfo info(mapcode, mapmodifiers, unicode, shift_unicode, ctrl_unicode); + m_it = map->insert(keymask, info); +} + +void KeyMappings::assignModifier(const QString& type, const QString& state) +{ + int maskbit = 0; + QString str; + str = type.lower(); + if(str == "shift"){ + maskbit = Qt::ShiftButton; + } else if(str == "control"){ + maskbit = Qt::ControlButton; + } else if(str == "alt"){ + maskbit = Qt::AltButton; + } + str = state.lower(); + if(str == "off"){ + maskbit = (maskbit << 16) & 0xFFFF0000; + } + (*m_it).modifiers |= maskbit; +} + +void KeyMappings::assignUnicode(const QString& kind, const QString& ch) +{ + QString str; + int code = ch[0].unicode(); + str = kind.lower(); + if(str == "unicode"){ + (*m_it).unicode = code; + } else if(str == "shift_unicode"){ + (*m_it).shift_unicode = code; + } else if(str == "ctrl_unicode"){ + (*m_it).ctrl_unicode = code; + } +} + +void KeyMappings::assignUnicode(int unicode) +{ + (*m_it).unicode = (*m_it).shift_unicode = + (*m_it).ctrl_unicode = unicode; +} + +void KeyMappings::statistics() +{ + qWarning("KeyMappings::statistics()"); + for(QMap<int, CodeMaps*>::Iterator it=m_keymaps.begin(); + it!=m_keymaps.end(); ++it){ + qWarning(" code = %x", it.key()); + for(QMap<int, MapInfo>::Iterator it2=(*it)->begin(); + it2!=(*it)->end(); ++it2){ + qDebug(" [%x]-[%x][%x][%x][%x][%x]", it2.key(), + (*it2).keycode, + (*it2).modifiers, + (*it2).unicode, + (*it2).shift_unicode, + (*it2).ctrl_unicode); + } + } +} + +bool KeyMappings::apply(int unicode, int keycode, int modifiers, + int keymask, bool isPress) +{ + CodeMaps* map; + m_isMapped = false; + + if(m_keymaps.contains(keycode)){ + map = m_keymaps[keycode]; + if(map->contains(keymask)){ + m_isMapped = true; + m_keyinfo = (*map)[keymask]; + } else { + int mask = -1; + for(CodeMaps::Iterator it=map->begin(); + it!=map->end(); ++it){ + if((keymask & it.key()) == it.key() + && it.key() > mask){ + mask = it.key(); + } + } + if(mask != -1){ + m_isMapped = true; + m_keyinfo = (*map)[mask]; + } + } + } + + if(m_isMapped == false){ + QWSServer::KeyMap* cache = g_mapCache[keycode]; + if(cache == NULL){ + cache = new QWSServer::KeyMap(); + g_mapCache.insert(keycode, cache); + cache->unicode = cache->shift_unicode = cache->ctrl_unicode = 0; + } + if(cache->unicode == 0 || cache->shift_unicode == 0 || cache->ctrl_unicode == 0){ + QChar ch(unicode); + if(modifiers & Qt::ControlButton){ + cache->ctrl_unicode = unicode; + } else if(modifiers & Qt::ShiftButton){ + cache->shift_unicode = ch.upper().unicode(); + } else { + cache->unicode = ch.lower().unicode(); + } + } + m_keyinfo = MapInfo(keycode, 0, + cache->unicode, cache->shift_unicode, cache->ctrl_unicode); + if(m_keyinfo.isDefined){ + setOriginal(unicode, modifiers); + } else { + setUnicode(unicode); + } + } + +#if 1 + if(isPress){ + if(m_keyinfo.keycode == Qt::Key_CapsLock){ + m_capslock = !m_capslock; + } + } +#endif + return(m_isMapped); +} + +bool KeyMappings::apply(int keycode, int keymask, bool isPress) +{ + CodeMaps* map; + m_isMapped = false; + + if(m_keymaps.contains(keycode)){ + map = m_keymaps[keycode]; + if(map->contains(keymask)){ + m_isMapped = true; + m_keyinfo = (*map)[keymask]; + } else { + int mask = -1; + for(CodeMaps::Iterator it=map->begin(); + it!=map->end(); ++it){ + if((keymask & it.key()) == it.key() + && it.key() > mask){ + mask = it.key(); + } + } + if(mask != -1){ + m_isMapped = true; + m_keyinfo = (*map)[mask]; + } + } + } + if(m_isMapped == false){ + m_keyinfo = MapInfo(keycode); + } +#if 1 + if(isPress){ + if(m_keyinfo.keycode == Qt::Key_CapsLock){ + m_capslock = !m_capslock; + } + } +#endif + return(m_isMapped); +} + +/** + * set original unicode + */ +void KeyMappings::setOriginal(int unicode, int modifiers) +{ + if(modifiers & Qt::ControlButton){ + m_keyinfo.ctrl_unicode = unicode; + } else if(modifiers & Qt::ShiftButton){ + m_keyinfo.shift_unicode = unicode; + } else { + m_keyinfo.unicode = unicode; + } +} + +void KeyMappings::setModifiers(int modifiers) +{ + m_modifiers = modifiers; + m_modifiers |= (m_keyinfo.modifiers & 0xFFFF); + m_modifiers &= ~((m_keyinfo.modifiers >> 16) & 0xFFFF); +} + +void KeyMappings::setUnicode(int unicode) +{ + m_keyinfo.unicode = unicode; + m_keyinfo.shift_unicode = unicode; + m_keyinfo.ctrl_unicode = unicode; +} + +void KeyMappings::setKeycode(int keycode) +{ + m_keyinfo.keycode = keycode; +} + +int KeyMappings::getUnicode() +{ + int unicode; + if(m_modifiers & Qt::ControlButton){ + unicode = m_keyinfo.ctrl_unicode; + } else if(m_modifiers & Qt::ShiftButton){ + unicode = m_keyinfo.shift_unicode; + QChar ch(unicode); + if(m_capslock){ + unicode = ch.lower().unicode(); + } else { + unicode = ch.upper().unicode(); + } + } else { + unicode = m_keyinfo.unicode; + QChar ch(unicode); + if(m_capslock){ + unicode = ch.upper().unicode(); + } else { + unicode = ch.lower().unicode(); + } + } + qDebug("UNICODE[%d][%x][%x]", m_capslock, unicode, m_keyinfo.unicode); +#if 0 + if(m_isMapped && m_capslock){ + QChar ch(unicode); + QChar::Category category = ch.category(); + if(category == QChar::Letter_Uppercase){ + unicode = ch.lower().unicode(); + } else if(category == QChar::Letter_Lowercase){ + unicode = ch.upper().unicode(); + } + } +#endif + return(unicode); +} + +int KeyMappings::getKeycode() +{ + return(m_keyinfo.keycode); +} + +int KeyMappings::getModifiers() +{ + return(m_modifiers); +} + +bool KeyMappings::isDefined() +{ + return(m_keyinfo.isDefined); +} 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 @@ +#ifndef _KEY_MAPPINGS_H_ +#define _KEY_MAPPINGS_H_ + +#include <qwindowsystem_qws.h> +#include <qmap.h> + +#include <qintdict.h> + +class MapInfo +{ +public: + MapInfo(){}; + MapInfo(int code, int mod = 0, int uni = 0, + int shift_uni = 0, int ctrl_uni = 0); + + static const QWSServer::KeyMap* findKeyMap(int code); + + int keycode; + int modifiers; + int unicode; + int shift_unicode; + int ctrl_unicode; + bool isDefined; +}; + +class KeyMappings +{ +public: + typedef QWSServer::KeyMap KeyMap; + typedef QMap<int, MapInfo> CodeMaps; + + KeyMappings(); + virtual ~KeyMappings(); + + void setOriginal(int unicode, int modifiers); + void setModifiers(int modifiers); + void setUnicode(int unicode); + void setKeycode(int keycode); + + int getUnicode(); + int getKeycode(); + int getModifiers(); + bool isDefined(); + + void assign(int keycode, int keymask, int mapcode, int mapmodifiers = 0, + int unicode = 0, int shift_unicode = 0, int ctrl_unicode = 0); + void assignModifier(const QString& type, const QString& state); + void assignUnicode(const QString& kind, const QString& ch); + void assignUnicode(int unicode); + bool apply(int unicode, int keycode, int modifiers, int keymask, bool isPress); + bool apply(int keycode, int keymask, bool isPress); + void setCapsLock(bool on=true){ + m_capslock = on; + } + + void reset(); + + void statistics(); +private: + QMap<int, CodeMaps*> m_keymaps; + MapInfo m_keyinfo; + int m_modifiers; + CodeMaps::Iterator m_it; + + bool m_capslock; + bool m_isMapped; + + void init(); + void clear(); +}; + +#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 @@ +#include "KeyModifiers.h" + +KeyModifiers::KeyModifiers() +{ + qDebug("KeyModifiers::KeyModifiers()"); + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), + this, SLOT(resetToggles())); + init(); +} + +KeyModifiers::~KeyModifiers() +{ + qDebug("KeyModifiers::~KeyModifiers()"); + delete m_pTimer; + clear(); +} + +void KeyModifiers::addType(const QString& type) +{ + if(m_types.contains(type) == false){ + qDebug("addType[%s][%x]", type.latin1(), m_bitmask); + m_types.insert(type, m_bitmask); + m_bitmask = m_bitmask << 1; + } +} + +ModifierInfo* KeyModifiers::assign(const QString& type, int keycode, + int keymask, bool mode) +{ + m_info = new ModifierInfo(type, keycode, keymask, mode); + addType(type); + m_modifiers.append(m_info); + if(mode){ + m_togglekeys.append(m_info); + } + assignRelease(m_info, keycode); + return(m_info); +} + +void KeyModifiers::assignRelease(int keycode) +{ + assignRelease(m_info, keycode); +} + +void KeyModifiers::assignRelease(ModifierInfo* info, int keycode) +{ + if(m_releasekeys.contains(keycode) == false){ + m_releasekeys.insert(keycode, new ModifierList); + } + m_releasekeys[keycode]->append(info); +} + +void KeyModifiers::setToggle() +{ + setToggle(m_info); +} + +void KeyModifiers::setToggle(ModifierInfo* info) +{ + info->toggle_mode = true; + m_togglekeys.append(info); +} + +void KeyModifiers::keepToggles() +{ + if(m_timeout > 0){ + m_pTimer->start(m_timeout, true); + } +} + +bool KeyModifiers::pressKey(int keycode, int modifiers) +{ + int keymask; + + keymask = getState(modifiers, true); + + for(ModifierList::Iterator it=m_modifiers.begin(); + it!=m_modifiers.end(); ++it){ + if((*it)->keycode == keycode + && ((*it)->keymask & keymask) == (*it)->keymask){ + (*it)->pressed = true; + if((*it)->toggle_mode){ + /* change toggle state */ + (*it)->toggled = !((*it)->toggled); + if((*it)->toggled){ + keepToggles(); + } else { + m_pTimer->stop(); + } + } + return(true); + } + } + return(false); +} + +bool KeyModifiers::isModifier(int keycode) +{ + if(keycode == Qt::Key_Shift + || keycode == Qt::Key_Control + || keycode == Qt::Key_Alt + || keycode == Qt::Key_Meta + || keycode == Qt::Key_F22){ + return(true); + } else { + return(false); + } +} + +void KeyModifiers::releaseKey(int keycode) +{ + if(m_releasekeys.contains(keycode)){ + ModifierList* list = m_releasekeys[keycode]; + for(ModifierList::Iterator it=(*list).begin(); + it!=(*list).end(); ++it){ + (*it)->pressed = false; + } + } +} + +int KeyModifiers::getState() +{ + int state = 0; + for(ModifierList::Iterator it=m_modifiers.begin(); + it!=m_modifiers.end(); ++it){ + if((*it)->pressed || (*it)->toggled){ + state |= m_types[(*it)->type]; + } + } + return(state); +} + +int KeyModifiers::getState(int modifiers, bool reset) +{ + int state = getState(); + int mask; + + mask = getMask("Shift"); + if(modifiers & Qt::ShiftButton){ + state |= mask; + } else { + if(reset){ + state &= ~mask; + } + } + mask = getMask("Control"); + if(modifiers & Qt::ControlButton){ + state |= mask; + } else { + if(reset){ + state &= ~mask; + } + } + mask = getMask("Alt"); + if(modifiers & Qt::AltButton){ + state |= mask; + } else { + if(reset){ + state &= ~mask; + } + } + + return(state); +} + +int KeyModifiers::getModifiers(int modifiers) +{ + int state = getState(); + + if(state & getMask("Shift")){ + modifiers |= Qt::ShiftButton; + } + if(state & getMask("Control")){ + modifiers |= Qt::ControlButton; + } + if(state & getMask("Alt")){ + modifiers |= Qt::AltButton; + } + + return(modifiers); +} + +int KeyModifiers::getMask(const QString& type) +{ + if(m_types.contains(type)){ + return(m_types[type]); + } else { + return(0); + } +} + +void KeyModifiers::clear() +{ + m_types.clear(); + + m_togglekeys.clear(); + + for(ModifierList::Iterator it=m_modifiers.begin(); + it!=m_modifiers.end(); ++it){ + delete *it; + } + m_modifiers.clear(); + + for(QMap<int, ModifierList*>::Iterator it=m_releasekeys.begin(); + it!=m_releasekeys.end(); ++it){ + delete *it; + } + m_releasekeys.clear(); +} + +void KeyModifiers::init() +{ + m_bitmask = 0x00000001; + addType("Shift"); + addType("Control"); + addType("Alt"); + + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + cfg.setGroup("Global"); + + QString timeout = cfg.readEntry("ToggleTimeout", "10"); + int msec = timeout.toInt(); + msec *= 1000; /* sec to msec */ + m_timeout = msec; +} + +void KeyModifiers::reset() +{ + clear(); + init(); +} + +bool KeyModifiers::isToggled() +{ + for(ModifierList::Iterator it=m_togglekeys.begin(); + it!=m_togglekeys.end(); ++it){ + if((*it)->toggled){ + return(true); + } + } + return(false); +} + +void KeyModifiers::resetToggles() +{ + for(ModifierList::Iterator it=m_togglekeys.begin(); + it!=m_togglekeys.end(); ++it){ + (*it)->toggled = false; + } + m_pTimer->stop(); +} + +void KeyModifiers::resetStates() +{ + for(ModifierList::Iterator it=m_modifiers.begin(); + it!=m_modifiers.end(); ++it){ + (*it)->pressed = false; + } + resetToggles(); +} + +void KeyModifiers::statistics() +{ + qWarning("KeyModifiers::statistics()"); + for(ModifierList::Iterator it=m_modifiers.begin(); + it!=m_modifiers.end(); ++it){ + qWarning(" [%s][%x][%x][%d][%d]", + (*it)->type.latin1(), + (*it)->keycode, + (*it)->keymask, + (*it)->pressed, + (*it)->toggled); + for(QMap<int, ModifierList*>::Iterator it2=m_releasekeys.begin(); + it2!=m_releasekeys.end(); ++it2){ + for(ModifierList::Iterator it3=(*it2)->begin(); + it3!=(*it2)->end(); ++it3){ + if(*it == *it3){ + qWarning(" release[%x]", it2.key()); + } + } + } + } +} 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 @@ +#ifndef _KEY_MODIFIERS_H_ +#define _KEY_MODIFIERS_H_ + +#include <qmap.h> +#include <qtimer.h> +#include <qvaluelist.h> +#include <qnamespace.h> + +#include <qpe/config.h> +#include "ConfigEx.h" + +struct ModifierInfo { +public: + ModifierInfo(const QString& tp, int code, int mask, bool mode) + { + type = tp; + keycode = code; + keymask = mask; + pressed = false; + toggled = false; + toggle_mode = mode; + } + QString type; + int keycode; + int keymask; + bool pressed; + bool toggled; + bool toggle_mode; +private: +} ; + +class KeyModifiers : public QObject +{ + Q_OBJECT +public: + typedef QValueList<ModifierInfo*> ModifierList; + + KeyModifiers(); + virtual ~KeyModifiers(); + void addType(const QString& type); + ModifierInfo* assign(const QString& type, int keycode, + int keymask = 0, bool toggle = false); + void assignRelease(int keycode); + void assignRelease(ModifierInfo* info, int keycode); + void setToggle(); + void setToggle(ModifierInfo* info); + + bool isToggled(); + void resetStates(); + void keepToggles(); + + bool pressKey(int keycode, int modifiers); + void releaseKey(int keycode); + int getState(); + int getState(int modifiers, bool reset = false); + int getMask(const QString& type); + int getModifiers(int modifiers); + + bool isModifier(int keycode); + + void statistics(); + + void reset(); +public slots: + void resetToggles(); +private: + QMap<QString, int> m_types; + int m_bitmask; + ModifierList m_modifiers; + QMap<int, ModifierList*> m_releasekeys; + ModifierList m_togglekeys; + ModifierInfo* m_info; + QTimer* m_pTimer; + int m_timeout; + + void clear(); + void init(); +}; + +#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 @@ +#include "KeyNames.h" + +QMap<QString, int> KeyNames::codemap; +QMap<int, QString> KeyNames::namemap; +QString KeyNames::tmpname; + +static struct { + int code; + char* name; +} stKeyNames[] = { +{Qt::Key_Escape, "Escape"}, +{Qt::Key_Tab, "Tab"}, +{Qt::Key_Backtab, "Backtab"}, +{Qt::Key_BackTab, "BackTab"}, +{Qt::Key_Backtab, "Backtab"}, +{Qt::Key_Backspace, "Backspace"}, +{Qt::Key_BackSpace, "BackSpace"}, +{Qt::Key_Backspace, "Backspace"}, +{Qt::Key_Return, "Return"}, +{Qt::Key_Enter, "Enter"}, +{Qt::Key_Insert, "Insert"}, +{Qt::Key_Delete, "Delete"}, +{Qt::Key_Pause, "Pause"}, +{Qt::Key_Print, "Print"}, +{Qt::Key_SysReq, "SysReq"}, +{Qt::Key_Home, "Home"}, +{Qt::Key_End, "End"}, +{Qt::Key_Left, "Left"}, +{Qt::Key_Up, "Up"}, +{Qt::Key_Right, "Right"}, +{Qt::Key_Down, "Down"}, +{Qt::Key_Prior, "Prior"}, +{Qt::Key_PageUp, "PageUp"}, +{Qt::Key_Prior, "Prior"}, +{Qt::Key_Next, "Next"}, +{Qt::Key_PageDown, "PageDown"}, +{Qt::Key_Next, "Next"}, +{Qt::Key_Shift, "Shift"}, +{Qt::Key_Control, "Control"}, +{Qt::Key_Meta, "Meta"}, +{Qt::Key_Alt, "Alt"}, +{Qt::Key_CapsLock, "CapsLock"}, +{Qt::Key_NumLock, "NumLock"}, +{Qt::Key_ScrollLock, "ScrollLock"}, +{Qt::Key_F1, "F1"}, +{Qt::Key_F2, "F2"}, +{Qt::Key_F3, "F3"}, +{Qt::Key_F4, "F4"}, +{Qt::Key_F5, "F5"}, +{Qt::Key_F6, "F6"}, +{Qt::Key_F7, "F7"}, +{Qt::Key_F8, "F8"}, +{Qt::Key_F9, "F9"}, +{Qt::Key_F10, "F10"}, +{Qt::Key_F11, "F11"}, +{Qt::Key_F12, "F12"}, +{Qt::Key_F13, "F13"}, +{Qt::Key_F14, "F14"}, +{Qt::Key_F15, "F15"}, +{Qt::Key_F16, "F16"}, +{Qt::Key_F17, "F17"}, +{Qt::Key_F18, "F18"}, +{Qt::Key_F19, "F19"}, +{Qt::Key_F20, "F20"}, +{Qt::Key_F21, "F21"}, +{Qt::Key_F22, "F22"}, +{Qt::Key_F23, "F23"}, +{Qt::Key_F24, "F24"}, +{Qt::Key_F25, "F25"}, +{Qt::Key_F26, "F26"}, +{Qt::Key_F27, "F27"}, +{Qt::Key_F28, "F28"}, +{Qt::Key_F29, "F29"}, +{Qt::Key_F30, "F30"}, +{Qt::Key_F31, "F31"}, +{Qt::Key_F32, "F32"}, +{Qt::Key_F33, "F33"}, +{Qt::Key_F34, "F34"}, +{Qt::Key_F35, "F35"}, +{Qt::Key_Super_L, "Super_L"}, +{Qt::Key_Super_R, "Super_R"}, +{Qt::Key_Menu, "Menu"}, +{Qt::Key_Hyper_L, "Hyper_L"}, +{Qt::Key_Hyper_R, "Hyper_R"}, +{Qt::Key_Help, "Help"}, +{Qt::Key_Space, "Space"}, +{Qt::Key_Any, "Any"}, +{Qt::Key_Space, "Space"}, +{Qt::Key_Exclam, "Exclam"}, +{Qt::Key_QuoteDbl, "QuoteDbl"}, +{Qt::Key_NumberSign, "NumberSign"}, +{Qt::Key_Dollar, "Dollar"}, +{Qt::Key_Percent, "Percent"}, +{Qt::Key_Ampersand, "Ampersand"}, +{Qt::Key_Apostrophe, "Apostrophe"}, +{Qt::Key_ParenLeft, "ParenLeft"}, +{Qt::Key_ParenRight, "ParenRight"}, +{Qt::Key_Asterisk, "Asterisk"}, +{Qt::Key_Plus, "Plus"}, +{Qt::Key_Comma, "Comma"}, +{Qt::Key_Minus, "Minus"}, +{Qt::Key_Period, "Period"}, +{Qt::Key_Slash, "Slash"}, +{Qt::Key_0, "0"}, +{Qt::Key_1, "1"}, +{Qt::Key_2, "2"}, +{Qt::Key_3, "3"}, +{Qt::Key_4, "4"}, +{Qt::Key_5, "5"}, +{Qt::Key_6, "6"}, +{Qt::Key_7, "7"}, +{Qt::Key_8, "8"}, +{Qt::Key_9, "9"}, +{Qt::Key_Colon, "Colon"}, +{Qt::Key_Semicolon, "Semicolon"}, +{Qt::Key_Less, "Less"}, +{Qt::Key_Equal, "Equal"}, +{Qt::Key_Greater, "Greater"}, +{Qt::Key_Question, "Question"}, +{Qt::Key_At, "At"}, +{Qt::Key_A, "A"}, +{Qt::Key_B, "B"}, +{Qt::Key_C, "C"}, +{Qt::Key_D, "D"}, +{Qt::Key_E, "E"}, +{Qt::Key_F, "F"}, +{Qt::Key_G, "G"}, +{Qt::Key_H, "H"}, +{Qt::Key_I, "I"}, +{Qt::Key_J, "J"}, +{Qt::Key_K, "K"}, +{Qt::Key_L, "L"}, +{Qt::Key_M, "M"}, +{Qt::Key_N, "N"}, +{Qt::Key_O, "O"}, +{Qt::Key_P, "P"}, +{Qt::Key_Q, "Q"}, +{Qt::Key_R, "R"}, +{Qt::Key_S, "S"}, +{Qt::Key_T, "T"}, +{Qt::Key_U, "U"}, +{Qt::Key_V, "V"}, +{Qt::Key_W, "W"}, +{Qt::Key_X, "X"}, +{Qt::Key_Y, "Y"}, +{Qt::Key_Z, "Z"}, +{Qt::Key_BracketLeft, "BracketLeft"}, +{Qt::Key_Backslash, "Backslash"}, +{Qt::Key_BracketRight, "BracketRight"}, +{Qt::Key_AsciiCircum, "AsciiCircum"}, +{Qt::Key_Underscore, "Underscore"}, +{Qt::Key_QuoteLeft, "QuoteLeft"}, +{Qt::Key_BraceLeft, "BraceLeft"}, +{Qt::Key_Bar, "Bar"}, +{Qt::Key_BraceRight, "BraceRight"}, +{Qt::Key_AsciiTilde, "AsciiTilde"}, +{Qt::Key_nobreakspace, "nobreakspace"}, +{Qt::Key_exclamdown, "exclamdown"}, +{Qt::Key_cent, "cent"}, +{Qt::Key_sterling, "sterling"}, +{Qt::Key_currency, "currency"}, +{Qt::Key_yen, "yen"}, +{Qt::Key_brokenbar, "brokenbar"}, +{Qt::Key_section, "section"}, +{Qt::Key_diaeresis, "diaeresis"}, +{Qt::Key_copyright, "copyright"}, +{Qt::Key_ordfeminine, "ordfeminine"}, +{Qt::Key_guillemotleft, "guillemotleft"}, +{Qt::Key_notsign, "notsign"}, +{Qt::Key_hyphen, "hyphen"}, +{Qt::Key_registered, "registered"}, +{Qt::Key_macron, "macron"}, +{Qt::Key_degree, "degree"}, +{Qt::Key_plusminus, "plusminus"}, +{Qt::Key_twosuperior, "twosuperior"}, +{Qt::Key_threesuperior, "threesuperior"}, +{Qt::Key_acute, "acute"}, +{Qt::Key_mu, "mu"}, +{Qt::Key_paragraph, "paragraph"}, +{Qt::Key_periodcentered, "periodcentered"}, +{Qt::Key_cedilla, "cedilla"}, +{Qt::Key_onesuperior, "onesuperior"}, +{Qt::Key_masculine, "masculine"}, +{Qt::Key_guillemotright, "guillemotright"}, +{Qt::Key_onequarter, "onequarter"}, +{Qt::Key_onehalf, "onehalf"}, +{Qt::Key_threequarters, "threequarters"}, +{Qt::Key_questiondown, "questiondown"}, +{Qt::Key_Agrave, "Agrave"}, +{Qt::Key_Aacute, "Aacute"}, +{Qt::Key_Acircumflex, "Acircumflex"}, +{Qt::Key_Atilde, "Atilde"}, +{Qt::Key_Adiaeresis, "Adiaeresis"}, +{Qt::Key_Aring, "Aring"}, +{Qt::Key_AE, "AE"}, +{Qt::Key_Ccedilla, "Ccedilla"}, +{Qt::Key_Egrave, "Egrave"}, +{Qt::Key_Eacute, "Eacute"}, +{Qt::Key_Ecircumflex, "Ecircumflex"}, +{Qt::Key_Ediaeresis, "Ediaeresis"}, +{Qt::Key_Igrave, "Igrave"}, +{Qt::Key_Iacute, "Iacute"}, +{Qt::Key_Icircumflex, "Icircumflex"}, +{Qt::Key_Idiaeresis, "Idiaeresis"}, +{Qt::Key_ETH, "ETH"}, +{Qt::Key_Ntilde, "Ntilde"}, +{Qt::Key_Ograve, "Ograve"}, +{Qt::Key_Oacute, "Oacute"}, +{Qt::Key_Ocircumflex, "Ocircumflex"}, +{Qt::Key_Otilde, "Otilde"}, +{Qt::Key_Odiaeresis, "Odiaeresis"}, +{Qt::Key_multiply, "multiply"}, +{Qt::Key_Ooblique, "Ooblique"}, +{Qt::Key_Ugrave, "Ugrave"}, +{Qt::Key_Uacute, "Uacute"}, +{Qt::Key_Ucircumflex, "Ucircumflex"}, +{Qt::Key_Udiaeresis, "Udiaeresis"}, +{Qt::Key_Yacute, "Yacute"}, +{Qt::Key_THORN, "THORN"}, +{Qt::Key_ssharp, "ssharp"}, +{Qt::Key_agrave, "agrave"}, +{Qt::Key_aacute, "aacute"}, +{Qt::Key_acircumflex, "acircumflex"}, +{Qt::Key_atilde, "atilde"}, +{Qt::Key_adiaeresis, "adiaeresis"}, +{Qt::Key_aring, "aring"}, +{Qt::Key_ae, "ae"}, +{Qt::Key_ccedilla, "ccedilla"}, +{Qt::Key_egrave, "egrave"}, +{Qt::Key_eacute, "eacute"}, +{Qt::Key_ecircumflex, "ecircumflex"}, +{Qt::Key_ediaeresis, "ediaeresis"}, +{Qt::Key_igrave, "igrave"}, +{Qt::Key_iacute, "iacute"}, +{Qt::Key_icircumflex, "icircumflex"}, +{Qt::Key_idiaeresis, "idiaeresis"}, +{Qt::Key_eth, "eth"}, +{Qt::Key_ntilde, "ntilde"}, +{Qt::Key_ograve, "ograve"}, +{Qt::Key_oacute, "oacute"}, +{Qt::Key_ocircumflex, "ocircumflex"}, +{Qt::Key_otilde, "otilde"}, +{Qt::Key_odiaeresis, "odiaeresis"}, +{Qt::Key_division, "division"}, +{Qt::Key_oslash, "oslash"}, +{Qt::Key_ugrave, "ugrave"}, +{Qt::Key_uacute, "uacute"}, +{Qt::Key_ucircumflex, "ucircumflex"}, +{Qt::Key_udiaeresis, "udiaeresis"}, +{Qt::Key_yacute, "yacute"}, +{Qt::Key_thorn, "thorn"}, +{Qt::Key_ydiaeresis, "ydiaeresis"}, +{Qt::Key_unknown, "unknown"}, +{0,0}, +}; + +void KeyNames::setCodeMap() +{ + int i; + + codemap.clear(); + for(i=0; stKeyNames[i].code != 0; i++){ + codemap.insert(stKeyNames[i].name, stKeyNames[i].code); + } +} + +void KeyNames::setNameMap() +{ + int i; + + namemap.clear(); + for(i=0; stKeyNames[i].code != 0; i++){ + namemap.insert(stKeyNames[i].code, stKeyNames[i].name); + } +} + + +int KeyNames::getCode(const QString& s){ + if(codemap.isEmpty()) setCodeMap(); + if(codemap.contains(s)){ + return(codemap[s]); + } else { + if(s.find("0x") == 0){ + bool success; + int val = s.mid(2).toInt(&success, 16); + if(success){ + return(val); + } + } + return(0); + } +} + +const QString& KeyNames::getName(int code){ + if(namemap.isEmpty()) setNameMap(); + if(namemap.contains(code)){ + return(namemap[code]); + } else { + tmpname.sprintf("0x%x", code); + return(tmpname); + //return(QString::null); + } +} 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 @@ +#ifndef _KEY_NAMES_H_ +#define _KEY_NAMES_H_ + +#include <qstring.h> +#include <qmap.h> +#include <qnamespace.h> + +class KeyNames +{ +public: + static const QString& getName(int code); + static int getCode(const QString& s); + + static void clearName(){ + namemap.clear(); + } + static void setCode(const QString& s, int code){ + if(codemap.contains(s) == false){ + codemap.insert(s, code); + } + } + static void clearCode(){ + codemap.clear(); + } + static void reset(){ + clearCode(); + } +private: + static QMap<QString, int> codemap; + static QMap<int, QString> namemap; + static QString tmpname; + + static void setCodeMap(); + static void setNameMap(); +}; + +#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 @@ +#include "KeyRepeater.h" + +KeyRepeater::KeyRepeater() +{ + qDebug("KeyRepeater::KeyRepeater()"); + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), this, SLOT(autoRepeat())); + init(); +} + +KeyRepeater::~KeyRepeater() +{ + qDebug("KeyRepeater::~KeyRepeater()"); + delete m_pTimer; +} + +void KeyRepeater::start(int unicode, int keycode, int modifiers) +{ + m_unicode = unicode; + m_keycode = keycode; + m_modifiers = modifiers; + if(m_mode == ENABLE){ + m_pTimer->stop(); + if(isRepeatable(keycode)){ + /* repeater start */ + m_pTimer->start(m_repeatdelay, TRUE); + } + } +} + +void KeyRepeater::stop(int keycode) +{ + if(keycode == 0 + || keycode == m_keycode + || isRepeatable(keycode) == false){ + m_pTimer->stop(); + } +} + +void KeyRepeater::init() +{ + m_mode = ENABLE; + m_repeatdelay = 400; + m_repeatperiod = 60; + m_disablekeys.append(0); + m_disablekeys.append(Qt::Key_Escape); + m_disablekeys.append(Qt::Key_Shift); + m_disablekeys.append(Qt::Key_Control); + m_disablekeys.append(Qt::Key_Alt); + m_disablekeys.append(Qt::Key_Meta); + for(int i=Qt::Key_F1; i<=Qt::Key_F35; i++){ + m_disablekeys.append(i); + } +} + +void KeyRepeater::clear() +{ + m_disablekeys.clear(); +} + +void KeyRepeater::reset() +{ + clear(); + init(); +} + +void KeyRepeater::setRepeatable(int keycode, bool enable) +{ + if(enable){ + QValueList<int>::Iterator it = m_disablekeys.find(keycode); + if(it != m_disablekeys.end()){ + m_disablekeys.remove(it); + } + } else { + if(m_disablekeys.contains(keycode) == false){ + m_disablekeys.append(keycode); + } + } +} + +bool KeyRepeater::isRepeatable(int keycode) +{ + if(m_disablekeys.contains(keycode)){ + return(false); + } else { + return(true); + } +} + +void KeyRepeater::autoRepeat() +{ + /* key release event */ +#if 0 + sendKeyEvent( + m_unicode, + m_keycode, + m_modifiers, + FALSE, + TRUE); + /* key press event */ + sendKeyEvent( + m_unicode, + m_keycode, + m_modifiers, + TRUE, + TRUE); +#else + emit keyEvent( + m_unicode, + m_keycode, + m_modifiers, + FALSE, + TRUE); + /* key press event */ + emit keyEvent( + m_unicode, + m_keycode, + m_modifiers, + TRUE, + TRUE); +#endif + /* start auto repeat */ + m_pTimer->start(m_repeatperiod); +#if 0 + qDebug("autoRepeat[%x][%x][%x]", + m_unicode, + m_keycode, + m_modifiers); +#endif +} + +void KeyRepeater::statistics() +{ + qWarning("KeyRepeater::statistics()"); + qWarning(" delay[%d] period[%d]", m_repeatdelay, m_repeatperiod); + for(QValueList<int>::Iterator it=m_disablekeys.begin(); + it!=m_disablekeys.end(); ++it){ + qDebug(" disable[%x]", *it); + } +} 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 @@ +#ifndef _KEY_REPEATER_H_ +#define _KEY_REPEATER_H_ + +#include <qobject.h> +#include <qtimer.h> +#include <qvaluelist.h> +#include <qwindowsystem_qws.h> + +#include <syslog.h> + +class KeyRepeater : public QObject +{ + Q_OBJECT +public: + KeyRepeater(); + virtual ~KeyRepeater(); + + typedef enum { + DISABLE=0, + ENABLE=1, + KILL=2, + } RepeaterMode; + + void start(int unicode, int keycode, int modifieres); + void stop(int keycode = 0); + void reset(); + + void setRepeatable(int keycode, bool enable); + bool isRepeatable(int keycode); + + void setMode(int mode){ + switch(mode){ + case DISABLE: + m_mode = DISABLE; + break; + case ENABLE: + m_mode = ENABLE; + break; + case KILL: + m_mode = KILL; + break; + default: + m_mode = ENABLE; + break; + } + } + RepeaterMode getMode(){ + return(m_mode); + } + + void setDelay(int msec) + { + m_repeatdelay = msec; + } + void setPeriod(int msec) + { + m_repeatperiod = msec; + } + + void statistics(); +private slots: + void autoRepeat(); +private: + int m_unicode; + int m_keycode; + int m_modifiers; + + int m_repeatdelay; + int m_repeatperiod; + + QCString m_hookChannel; + + RepeaterMode m_mode; + + QValueList<int> m_disablekeys; + + QTimer* m_pTimer; + + void init(); + void clear(); +signals: + void keyEvent(int unicode, int keycode, int modifiers, + bool isPress, bool autoRepeat); +}; + +#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 @@ +#include "StringParser.h" + +#include <qregexp.h> + +QStringList StringParser::split(const QChar& sep, const QString& str, + bool allowEmptyEntries) +{ + QString line = str + sep; + QString quote; + QRegExp rxend; + QRegExp rxdbl; + int pos=0, len, idx=0; + QStringList list; + while(idx < (int)line.length()-1){ + if(!quote.isEmpty()){ + QString s; + while((pos = rxend.match(line, idx, &len)) != -1){ + s += line.mid(idx, len+pos-idx-1); + idx = pos+len-1; + if(len % 2 == 0){ + s.replace(rxdbl, quote); + list.append(s.left(s.length()-1)); + idx++; + break; + } + } + quote = ""; + } else if(line[idx] == '\"'){ + rxend.setPattern(QString("\"+") + sep); + rxdbl.setPattern("\"\""); + quote = "\""; + idx++; + } else if(line[idx] == '\''){ + rxend.setPattern(QString("\'+") + sep); + rxdbl.setPattern("\'\'"); + quote = "\'"; + idx++; + } else if(!allowEmptyEntries && line[idx] == sep){ + idx++; + } else { + pos = line.find(sep, idx); + if(pos != -1){ + const QString& s = line.mid(idx, pos-idx); + list.append(s); + idx = pos+1; + } + } + if(pos == -1) break; + } + return list; +} + +QString StringParser::join(const QChar& sep, const QStringList& list) +{ + QString str; + QString s; + QStringList tmp; + QRegExp quote("\""); + for(QStringList::ConstIterator it=list.begin(); + it!=list.end(); ++it){ + s = *it; + if(s.find(sep) != -1 + || s[0] == '\"' + || s[0] == '\''){ + s.replace(quote, "\"\""); + tmp.append("\"" + s + "\""); + } else { + tmp.append(s); + } + } + return tmp.join(sep); +} 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 @@ +#ifndef _STRING_PARSER_H_ +#define _STRING_PARSER_H_ + +#include <qstringlist.h> + +class StringParser +{ +public: + static QStringList split(const QChar& sep, const QString& str, + bool allowEmptyEntries=FALSE); + static QString join(const QChar& sep, const QStringList& list); +}; + +#endif /* _STRING_PARSER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp b/noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp new file mode 100644 index 0000000..b0767cf --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp @@ -0,0 +1,307 @@ +#include "KHCWidget.h" + +KHCWidget::KHCWidget(QWidget* parent, const char* name, WFlags fl) + : KHCWidgetBase(parent, name, fl) +{ + m_isEnable = true; + setLayout(); + setHandler(); + + txtOrgKey->installEventFilter(this); + txtMapKey->installEventFilter(this); +} + +KHCWidget::~KHCWidget() +{ +} + +void KHCWidget::setLayout() +{ + QBoxLayout* topLayout = new QVBoxLayout(this, 5); + + QBoxLayout* orgLayout1 = new QHBoxLayout(topLayout); + orgLayout1->addWidget(lblOriginal); + orgLayout1->addWidget(txtOrgKey); + + QBoxLayout* orgLayout2 = new QHBoxLayout(topLayout); + orgLayout2->addWidget(lblOrgK); + orgLayout2->addWidget(lblOrgKeycode); +#if 0 + orgLayout2->addWidget(lblOrgM); + orgLayout2->addWidget(lblOrgModifiers); +#endif + orgLayout2->addWidget(lblOrgU); + orgLayout2->addWidget(lblOrgUnicode); + orgLayout2->addWidget(chkOrgShift); + orgLayout2->addWidget(chkOrgCtrl); + orgLayout2->addWidget(chkOrgAlt); + + QBoxLayout* mapLayout1 = new QHBoxLayout(topLayout); + mapLayout1->addWidget(lblMapping); + mapLayout1->addWidget(txtMapKey); + + QBoxLayout* mapLayout2 = new QHBoxLayout(topLayout); + mapLayout2->addWidget(lblMapK); + mapLayout2->addWidget(lblMapKeycode); +#if 0 + mapLayout2->addWidget(lblMapM); + mapLayout2->addWidget(lblMapModifiers); +#endif + mapLayout2->addWidget(lblMapU); + mapLayout2->addWidget(lblMapUnicode); + mapLayout2->addWidget(chkMapShift); + mapLayout2->addWidget(chkMapCtrl); + mapLayout2->addWidget(chkMapAlt); + + QBoxLayout* btnLayout = new QHBoxLayout(topLayout); + btnLayout->addWidget(btnGen); + btnLayout->addWidget(btnCopy); + btnLayout->addWidget(btnCtrl); + + topLayout->addWidget(mleDefine); +} + +void KHCWidget::setHandler() +{ + connect(btnGen, SIGNAL(clicked()), this, SLOT(onClick_Gen())); + connect(btnCopy, SIGNAL(clicked()), this, SLOT(onClick_Copy())); + connect(btnCtrl, SIGNAL(clicked()), this, SLOT(onClick_Ctrl())); +} + +bool KHCWidget::eventFilter(QObject* o, QEvent* e) +{ + if(::strcmp(o->name(), "txtOrgKey") == 0){ + if(e->type() == QEvent::KeyPress){ + QKeyEvent* ke = (QKeyEvent*)e; + if(ke->isAutoRepeat() == false){ + onPress_Org(ke); + } + return(true); + } + } else if(::strcmp(o->name(), "txtMapKey") == 0){ + if(e->type() == QEvent::KeyPress){ + QKeyEvent* ke = (QKeyEvent*)e; + if(ke->isAutoRepeat() == false){ + onPress_Map(ke); + } + return(true); + } + } + + return QWidget::eventFilter(o, e); +} + +void KHCWidget::onPress_Org(QKeyEvent* ke) +{ + /* keycode */ + const QString& name = KeyNames::getName(ke->key()); + if(name == QString::null){ + lblOrgKeycode->setText(QString::number(ke->key(), 16)); + } else { + lblOrgKeycode->setText(name); + } + /* modifiers */ + chkOrgShift->setChecked(ke->state() & Qt::ShiftButton); + chkOrgCtrl->setChecked(ke->state() & Qt::ControlButton); + chkOrgAlt->setChecked(ke->state() & Qt::AltButton); + + /* unicode */ + if(ke->text()[0].isPrint()){ + lblOrgUnicode->setText(ke->text()); + } else { + lblOrgUnicode->setText(QString::number(ke->ascii(), 16)); + } + m_OrgkeyData.setData(ke); +} + +void KHCWidget::onPress_Map(QKeyEvent* ke) +{ + /* keycode */ + const QString& name = KeyNames::getName(ke->key()); + if(name == QString::null){ + lblMapKeycode->setText(QString::number(ke->key(), 16)); + } else { + lblMapKeycode->setText(name); + } + /* modifiers */ + chkMapShift->setChecked(ke->state() & Qt::ShiftButton); + chkMapCtrl->setChecked(ke->state() & Qt::ControlButton); + chkMapAlt->setChecked(ke->state() & Qt::AltButton); + + /* unicode */ + if(ke->text()[0].isPrint()){ + lblMapUnicode->setText(ke->text()); + } else { + lblMapUnicode->setText(QString::number(ke->ascii(), 16)); + } + m_MapkeyData.setData(ke); +} + +void KHCWidget::onClick_Gen() +{ + mleDefine->clear(); + if(m_OrgkeyData.key == 0 + || m_MapkeyData.key == 0){ + return; + } + /* original key */ + QString line; + const QString& name = KeyNames::getName(m_OrgkeyData.key); + line = "<define "; + if(name == QString::null){ + line.append("code=\""); + line.append(QString::number(m_OrgkeyData.key, 16)); + } else { + line.append("key=\""); + line.append(name); + } + line.append("\">"); + mleDefine->append(line); + + /* original modifiers */ + bool need = false; + line = "<modifier"; + if(chkOrgShift->isChecked()){ + line.append(" Shift=\"On\""); + need = true; + } + if(chkOrgCtrl->isChecked()){ + line.append(" Control=\"On\""); + need = true; + } + if(chkOrgAlt->isChecked()){ + line.append(" Alt=\"On\""); + need = true; + } + line.append("/>"); + if(need){ + mleDefine->append(line); + } + + /* mapping key */ + const QString& mapname = KeyNames::getName(m_MapkeyData.key); + line = "<map"; + if(mapname == QString::null){ + line.append(" code=\""); + line.append(QString::number(m_MapkeyData.key, 16)); + } else { + line.append(" key=\""); + line.append(mapname); + } + line.append("\"/>"); + mleDefine->append(line); + + /* mapping modifiers */ + need = false; + line = "<map_modifier"; + bool on = chkMapShift->isChecked(); + if(chkOrgShift->isChecked() != on){ + line.append(" Shift=\""); + if(on){ + line.append("On\""); + } else { + line.append("Off\""); + } + need = true; + } + on = chkMapCtrl->isChecked(); + if(chkOrgCtrl->isChecked() != on){ + line.append(" Control=\""); + if(on){ + line.append("On\""); + } else { + line.append("Off\""); + } + need = true; + } + on = chkMapAlt->isChecked(); + if(chkOrgAlt->isChecked() != on){ + line.append(" Alt=\""); + if(on){ + line.append("On\""); + } else { + line.append("Off\""); + } + need = true; + } + line.append("/>"); + if(need){ + mleDefine->append(line); + } + + /* mapping unicode */ + bool found = false; + for(const QWSServer::KeyMap* m = QWSServer::keyMap(); + m->key_code != 0; m++){ + if(m->key_code == m_MapkeyData.key){ + if(m_MapkeyData.state & Qt::ControlButton){ + if(m->ctrl_unicode == m_MapkeyData.ascii){ + found = true; + break; + } + } else if(m_MapkeyData.state & Qt::ShiftButton){ + if(m->shift_unicode == m_MapkeyData.ascii){ + found = true; + break; + } + } else { + if(m->unicode == m_MapkeyData.ascii){ + found = true; + break; + } + } + } + } + if(found == false){ + if(m_MapkeyData.text[0].isPrint()){ + line = "<map_unicode"; + if(m_MapkeyData.state & Qt::ControlButton){ + line.append(" ctrl_unicode=\""); + } else if(m_MapkeyData.state & Qt::ShiftButton){ + line.append(" shift_unicode=\""); + } else { + line.append(" unicode=\""); + } + line.append(m_MapkeyData.text); + line.append("\"/>"); + mleDefine->append(line); + } else { + mleDefine->clear(); + mleDefine->append("Not Support"); + return; + } + } + + /* close tag */ + line = "</define>"; + mleDefine->append(line); +} + +void KHCWidget::onClick_Copy() +{ + mleDefine->selectAll(); + mleDefine->copy(); + mleDefine->deselect(); +} + +void KHCWidget::onClick_Ctrl() +{ + if(m_isEnable){ + QCopEnvelope e("QPE/KeyHelper", "disable()"); + btnCtrl->setText(tr("Enable")); + //btnCtrl->update(); + } else { + QCopEnvelope e("QPE/KeyHelper", "enable()"); + btnCtrl->setText(tr("Disable")); + //btnCtrl->update(); + } + m_isEnable = !m_isEnable; +} + +void KHCWidget::closeEvent(QCloseEvent* ce) +{ + qDebug("closeEvent()"); + QCopEnvelope e("QPE/KeyHelper", "enable()"); + ce->accept(); +} + diff --git a/noncore/applets/keyhelper/keyhelperconf/KHCWidget.h b/noncore/applets/keyhelper/keyhelperconf/KHCWidget.h new file mode 100644 index 0000000..08b29b3 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KHCWidget.h @@ -0,0 +1,68 @@ +#ifndef _KHC_WIDGET_H_ +#define _KHC_WIDGET_H_ + +#include <stdlib.h> + +#include <qlabel.h> +#include <qpushbutton.h> +#include <qlineedit.h> +#include <qmultilineedit.h> +#include <qgroupbox.h> +#include <qcheckbox.h> +#include <qlayout.h> + +#include <qwindowsystem_qws.h> + +#include <qpe/qcopenvelope_qws.h> + +#include "KHCWidgetBase.h" +#include "KeyNames.h" + +struct KeyData +{ + KeyData(){ + key = 0; + state = 0; + ascii = 0; + } + void setData(QKeyEvent* ke) { + key = ke->key(); + state = ke->state(); + ascii = ke->ascii(); + text = ke->text(); + } + int key; + int state; + int ascii; + QString text; +}; + +class KHCWidget : public KHCWidgetBase +{ + Q_OBJECT +public: + KHCWidget(QWidget* parent=0, const char* name=0, WFlags fl=0); + virtual ~KHCWidget(); + +protected: + void closeEvent(QCloseEvent* ce); + +private: + void setLayout(); + void setHandler(); + + void onPress_Org(QKeyEvent* ke); + void onPress_Map(QKeyEvent* ke); + + bool eventFilter(QObject* o, QEvent* e); + + bool m_isEnable; + KeyData m_OrgkeyData; + KeyData m_MapkeyData; +private slots: + void onClick_Gen(); + void onClick_Copy(); + void onClick_Ctrl(); +}; + +#endif /* _KHC_WIDGET_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.cpp b/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.cpp new file mode 100644 index 0000000..16841f1 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** Form implementation generated from reading ui file 'KHCWidgetBase.ui' +** +** Created: Mon Feb 28 09:58:22 2005 +** by: The User Interface Compiler (uic) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ +#include "KHCWidgetBase.h" + +#include <qcheckbox.h> +#include <qlabel.h> +#include <qlineedit.h> +#include <qmultilineedit.h> +#include <qpushbutton.h> +#include <qlayout.h> +#include <qvariant.h> +#include <qtooltip.h> +#include <qwhatsthis.h> + +/* + * Constructs a KHCWidgetBase which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + */ +KHCWidgetBase::KHCWidgetBase( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "KHCWidgetBase" ); + resize( 431, 388 ); + setCaption( tr( "KeyHelperConf" ) ); + + btnCtrl = new QPushButton( this, "btnCtrl" ); + btnCtrl->setGeometry( QRect( 280, 150, 121, 31 ) ); + btnCtrl->setText( tr( "Disable" ) ); + + btnGen = new QPushButton( this, "btnGen" ); + btnGen->setGeometry( QRect( 10, 150, 110, 31 ) ); + btnGen->setText( tr( "Generate" ) ); + + btnCopy = new QPushButton( this, "btnCopy" ); + btnCopy->setGeometry( QRect( 140, 150, 121, 31 ) ); + btnCopy->setText( tr( "Copy" ) ); + + lblOrgK = new QLabel( this, "lblOrgK" ); + lblOrgK->setGeometry( QRect( 20, 50, 50, 20 ) ); + lblOrgK->setText( tr( "K" ) ); + + lblMapK = new QLabel( this, "lblMapK" ); + lblMapK->setGeometry( QRect( 20, 120, 20, 20 ) ); + lblMapK->setText( tr( "K" ) ); + + lblMapKeycode = new QLabel( this, "lblMapKeycode" ); + lblMapKeycode->setGeometry( QRect( 40, 120, 80, 21 ) ); + lblMapKeycode->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, lblMapKeycode->sizePolicy().hasHeightForWidth() ) ); + lblMapKeycode->setFrameShape( QLabel::Panel ); + lblMapKeycode->setFrameShadow( QLabel::Sunken ); + lblMapKeycode->setText( tr( "keycode" ) ); + + txtMapKey = new QLineEdit( this, "txtMapKey" ); + txtMapKey->setGeometry( QRect( 200, 80, 200, 22 ) ); + + txtOrgKey = new QLineEdit( this, "txtOrgKey" ); + txtOrgKey->setGeometry( QRect( 190, 10, 200, 22 ) ); + + lblOriginal = new QLabel( this, "lblOriginal" ); + lblOriginal->setGeometry( QRect( 10, 10, 120, 31 ) ); + lblOriginal->setFrameShape( QLabel::Box ); + lblOriginal->setFrameShadow( QLabel::Raised ); + lblOriginal->setText( tr( "Original Key" ) ); + + lblMapping = new QLabel( this, "lblMapping" ); + lblMapping->setGeometry( QRect( 10, 80, 120, 21 ) ); + lblMapping->setFrameShape( QLabel::Box ); + lblMapping->setFrameShadow( QLabel::Raised ); + lblMapping->setText( tr( "Mapping Key" ) ); + + mleDefine = new QMultiLineEdit( this, "mleDefine" ); + mleDefine->setGeometry( QRect( 10, 200, 391, 110 ) ); + mleDefine->setReadOnly( TRUE ); + + lblOrgKeycode = new QLabel( this, "lblOrgKeycode" ); + lblOrgKeycode->setGeometry( QRect( 50, 50, 70, 21 ) ); + lblOrgKeycode->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, lblOrgKeycode->sizePolicy().hasHeightForWidth() ) ); + lblOrgKeycode->setFrameShape( QLabel::Panel ); + lblOrgKeycode->setFrameShadow( QLabel::Sunken ); + lblOrgKeycode->setText( tr( "keycode" ) ); + + lblOrgU = new QLabel( this, "lblOrgU" ); + lblOrgU->setGeometry( QRect( 130, 50, 20, 21 ) ); + lblOrgU->setText( tr( "U" ) ); + + lblOrgUnicode = new QLabel( this, "lblOrgUnicode" ); + lblOrgUnicode->setGeometry( QRect( 150, 50, 80, 21 ) ); + lblOrgUnicode->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, lblOrgUnicode->sizePolicy().hasHeightForWidth() ) ); + lblOrgUnicode->setFrameShape( QLabel::Panel ); + lblOrgUnicode->setFrameShadow( QLabel::Sunken ); + lblOrgUnicode->setText( tr( "unicode" ) ); + + lblMapU = new QLabel( this, "lblMapU" ); + lblMapU->setGeometry( QRect( 130, 120, 20, 21 ) ); + lblMapU->setText( tr( "U" ) ); + + lblMapUnicode = new QLabel( this, "lblMapUnicode" ); + lblMapUnicode->setGeometry( QRect( 150, 120, 80, 21 ) ); + lblMapUnicode->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, lblMapUnicode->sizePolicy().hasHeightForWidth() ) ); + lblMapUnicode->setFrameShape( QLabel::Panel ); + lblMapUnicode->setFrameShadow( QLabel::Sunken ); + lblMapUnicode->setText( tr( "unicode" ) ); + + chkMapShift = new QCheckBox( this, "chkMapShift" ); + chkMapShift->setGeometry( QRect( 260, 120, 33, 19 ) ); + chkMapShift->setText( tr( "S" ) ); + chkMapShift->setAutoResize( TRUE ); + + chkMapCtrl = new QCheckBox( this, "chkMapCtrl" ); + chkMapCtrl->setGeometry( QRect( 310, 120, 34, 19 ) ); + chkMapCtrl->setText( tr( "C" ) ); + chkMapCtrl->setAutoResize( TRUE ); + + chkMapAlt = new QCheckBox( this, "chkMapAlt" ); + chkMapAlt->setGeometry( QRect( 360, 120, 34, 19 ) ); + chkMapAlt->setText( tr( "A" ) ); + chkMapAlt->setAutoResize( TRUE ); + + chkOrgShift = new QCheckBox( this, "chkOrgShift" ); + chkOrgShift->setGeometry( QRect( 250, 50, 33, 19 ) ); + chkOrgShift->setText( tr( "S" ) ); + chkOrgShift->setAutoResize( TRUE ); + + chkOrgCtrl = new QCheckBox( this, "chkOrgCtrl" ); + chkOrgCtrl->setGeometry( QRect( 300, 50, 34, 19 ) ); + chkOrgCtrl->setText( tr( "C" ) ); + chkOrgCtrl->setAutoResize( TRUE ); + + chkOrgAlt = new QCheckBox( this, "chkOrgAlt" ); + chkOrgAlt->setGeometry( QRect( 350, 50, 34, 19 ) ); + chkOrgAlt->setText( tr( "A" ) ); + chkOrgAlt->setAutoResize( TRUE ); + + // tab order + setTabOrder( txtOrgKey, chkOrgShift ); + setTabOrder( chkOrgShift, chkOrgCtrl ); + setTabOrder( chkOrgCtrl, chkOrgAlt ); + setTabOrder( chkOrgAlt, txtMapKey ); + setTabOrder( txtMapKey, chkMapShift ); + setTabOrder( chkMapShift, chkMapCtrl ); + setTabOrder( chkMapCtrl, chkMapAlt ); + setTabOrder( chkMapAlt, btnGen ); + setTabOrder( btnGen, btnCopy ); + setTabOrder( btnCopy, btnCtrl ); + setTabOrder( btnCtrl, mleDefine ); +} + +/* + * Destroys the object and frees any allocated resources + */ +KHCWidgetBase::~KHCWidgetBase() +{ + // no need to delete child widgets, Qt does it all for us +} + diff --git a/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.h b/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.h new file mode 100644 index 0000000..8193b61 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** Form interface generated from reading ui file 'KHCWidgetBase.ui' +** +** Created: Mon Feb 28 09:54:07 2005 +** by: The User Interface Compiler (uic) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ +#ifndef KHCWIDGETBASE_H +#define KHCWIDGETBASE_H + +#include <qvariant.h> +#include <qwidget.h> +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QCheckBox; +class QLabel; +class QLineEdit; +class QMultiLineEdit; +class QPushButton; + +class KHCWidgetBase : public QWidget +{ + Q_OBJECT + +public: + KHCWidgetBase( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~KHCWidgetBase(); + + QPushButton* btnCtrl; + QPushButton* btnGen; + QPushButton* btnCopy; + QLabel* lblOrgK; + QLabel* lblMapK; + QLabel* lblMapKeycode; + QLineEdit* txtMapKey; + QLineEdit* txtOrgKey; + QLabel* lblOriginal; + QLabel* lblMapping; + QMultiLineEdit* mleDefine; + QLabel* lblOrgKeycode; + QLabel* lblOrgU; + QLabel* lblOrgUnicode; + QLabel* lblMapU; + QLabel* lblMapUnicode; + QCheckBox* chkMapShift; + QCheckBox* chkMapCtrl; + QCheckBox* chkMapAlt; + QCheckBox* chkOrgShift; + QCheckBox* chkOrgCtrl; + QCheckBox* chkOrgAlt; + +}; + +#endif // KHCWIDGETBASE_H diff --git a/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.ui b/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.ui new file mode 100644 index 0000000..2be0772 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KHCWidgetBase.ui @@ -0,0 +1,569 @@ +<!DOCTYPE UI><UI> +<class>KHCWidgetBase</class> +<widget> + <class>QWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>KHCWidgetBase</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>0</x> + <y>0</y> + <width>431</width> + <height>388</height> + </rect> + </property> + <property stdset="1"> + <name>caption</name> + <string>KeyHelperConf</string> + </property> + <widget> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>btnCtrl</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>280</x> + <y>150</y> + <width>121</width> + <height>31</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>Disable</string> + </property> + </widget> + <widget> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>btnGen</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>10</x> + <y>150</y> + <width>110</width> + <height>31</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>Generate</string> + </property> + </widget> + <widget> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>btnCopy</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>140</x> + <y>150</y> + <width>121</width> + <height>31</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>Copy</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblOrgK</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>20</x> + <y>50</y> + <width>50</width> + <height>20</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>K</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblMapK</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>20</x> + <y>120</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>K</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblMapKeycode</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>40</x> + <y>120</y> + <width>80</width> + <height>21</height> + </rect> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Panel</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Sunken</enum> + </property> + <property stdset="1"> + <name>text</name> + <string>keycode</string> + </property> + </widget> + <widget> + <class>QLineEdit</class> + <property stdset="1"> + <name>name</name> + <cstring>txtMapKey</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>200</x> + <y>80</y> + <width>200</width> + <height>22</height> + </rect> + </property> + </widget> + <widget> + <class>QLineEdit</class> + <property stdset="1"> + <name>name</name> + <cstring>txtOrgKey</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>190</x> + <y>10</y> + <width>200</width> + <height>22</height> + </rect> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblOriginal</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>10</x> + <y>10</y> + <width>120</width> + <height>31</height> + </rect> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Box</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Raised</enum> + </property> + <property stdset="1"> + <name>text</name> + <string>Original Key</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblMapping</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>10</x> + <y>80</y> + <width>120</width> + <height>21</height> + </rect> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Box</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Raised</enum> + </property> + <property stdset="1"> + <name>text</name> + <string>Mapping Key</string> + </property> + </widget> + <widget> + <class>QMultiLineEdit</class> + <property stdset="1"> + <name>name</name> + <cstring>mleDefine</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>10</x> + <y>200</y> + <width>391</width> + <height>110</height> + </rect> + </property> + <property stdset="1"> + <name>readOnly</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblOrgKeycode</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>50</x> + <y>50</y> + <width>70</width> + <height>21</height> + </rect> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Panel</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Sunken</enum> + </property> + <property stdset="1"> + <name>text</name> + <string>keycode</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblOrgU</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>130</x> + <y>50</y> + <width>20</width> + <height>21</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>U</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblOrgUnicode</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>150</x> + <y>50</y> + <width>80</width> + <height>21</height> + </rect> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Panel</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Sunken</enum> + </property> + <property stdset="1"> + <name>text</name> + <string>unicode</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblMapU</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>130</x> + <y>120</y> + <width>20</width> + <height>21</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>U</string> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>lblMapUnicode</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>150</x> + <y>120</y> + <width>80</width> + <height>21</height> + </rect> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Panel</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Sunken</enum> + </property> + <property stdset="1"> + <name>text</name> + <string>unicode</string> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>chkMapShift</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>260</x> + <y>120</y> + <width>33</width> + <height>19</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>S</string> + </property> + <property stdset="1"> + <name>autoResize</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>chkMapCtrl</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>310</x> + <y>120</y> + <width>34</width> + <height>19</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>C</string> + </property> + <property stdset="1"> + <name>autoResize</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>chkMapAlt</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>360</x> + <y>120</y> + <width>34</width> + <height>19</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>A</string> + </property> + <property stdset="1"> + <name>autoResize</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>chkOrgShift</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>250</x> + <y>50</y> + <width>33</width> + <height>19</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>S</string> + </property> + <property stdset="1"> + <name>autoResize</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>chkOrgCtrl</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>300</x> + <y>50</y> + <width>34</width> + <height>19</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>C</string> + </property> + <property stdset="1"> + <name>autoResize</name> + <bool>true</bool> + </property> + </widget> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>chkOrgAlt</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>350</x> + <y>50</y> + <width>34</width> + <height>19</height> + </rect> + </property> + <property stdset="1"> + <name>text</name> + <string>A</string> + </property> + <property stdset="1"> + <name>autoResize</name> + <bool>true</bool> + </property> + </widget> +</widget> +<tabstops> + <tabstop>txtOrgKey</tabstop> + <tabstop>chkOrgShift</tabstop> + <tabstop>chkOrgCtrl</tabstop> + <tabstop>chkOrgAlt</tabstop> + <tabstop>txtMapKey</tabstop> + <tabstop>chkMapShift</tabstop> + <tabstop>chkMapCtrl</tabstop> + <tabstop>chkMapAlt</tabstop> + <tabstop>btnGen</tabstop> + <tabstop>btnCopy</tabstop> + <tabstop>btnCtrl</tabstop> + <tabstop>mleDefine</tabstop> +</tabstops> +</UI> diff --git a/noncore/applets/keyhelper/keyhelperconf/KeyNames.cpp b/noncore/applets/keyhelper/keyhelperconf/KeyNames.cpp new file mode 100644 index 0000000..e3d90b4 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KeyNames.cpp @@ -0,0 +1,274 @@ +#include "KeyNames.h" + +QMap<QString, int> KeyNames::codemap; +QMap<int, QString> KeyNames::namemap; + +static struct { + int code; + char* name; +} stKeyNames[] = { +{Qt::Key_Escape, "Escape"}, +{Qt::Key_Tab, "Tab"}, +{Qt::Key_Backtab, "Backtab"}, +{Qt::Key_BackTab, "BackTab"}, +{Qt::Key_Backtab, "Backtab"}, +{Qt::Key_Backspace, "Backspace"}, +{Qt::Key_BackSpace, "BackSpace"}, +{Qt::Key_Backspace, "Backspace"}, +{Qt::Key_Return, "Return"}, +{Qt::Key_Enter, "Enter"}, +{Qt::Key_Insert, "Insert"}, +{Qt::Key_Delete, "Delete"}, +{Qt::Key_Pause, "Pause"}, +{Qt::Key_Print, "Print"}, +{Qt::Key_SysReq, "SysReq"}, +{Qt::Key_Home, "Home"}, +{Qt::Key_End, "End"}, +{Qt::Key_Left, "Left"}, +{Qt::Key_Up, "Up"}, +{Qt::Key_Right, "Right"}, +{Qt::Key_Down, "Down"}, +{Qt::Key_Prior, "Prior"}, +{Qt::Key_PageUp, "PageUp"}, +{Qt::Key_Prior, "Prior"}, +{Qt::Key_Next, "Next"}, +{Qt::Key_PageDown, "PageDown"}, +{Qt::Key_Next, "Next"}, +{Qt::Key_Shift, "Shift"}, +{Qt::Key_Control, "Control"}, +{Qt::Key_Meta, "Meta"}, +{Qt::Key_Alt, "Alt"}, +{Qt::Key_CapsLock, "CapsLock"}, +{Qt::Key_NumLock, "NumLock"}, +{Qt::Key_ScrollLock, "ScrollLock"}, +{Qt::Key_F1, "F1"}, +{Qt::Key_F2, "F2"}, +{Qt::Key_F3, "F3"}, +{Qt::Key_F4, "F4"}, +{Qt::Key_F5, "F5"}, +{Qt::Key_F6, "F6"}, +{Qt::Key_F7, "F7"}, +{Qt::Key_F8, "F8"}, +{Qt::Key_F9, "F9"}, +{Qt::Key_F10, "F10"}, +{Qt::Key_F11, "F11"}, +{Qt::Key_F12, "F12"}, +{Qt::Key_F13, "F13"}, +{Qt::Key_F14, "F14"}, +{Qt::Key_F15, "F15"}, +{Qt::Key_F16, "F16"}, +{Qt::Key_F17, "F17"}, +{Qt::Key_F18, "F18"}, +{Qt::Key_F19, "F19"}, +{Qt::Key_F20, "F20"}, +{Qt::Key_F21, "F21"}, +{Qt::Key_F22, "F22"}, +{Qt::Key_F23, "F23"}, +{Qt::Key_F24, "F24"}, +{Qt::Key_F25, "F25"}, +{Qt::Key_F26, "F26"}, +{Qt::Key_F27, "F27"}, +{Qt::Key_F28, "F28"}, +{Qt::Key_F29, "F29"}, +{Qt::Key_F30, "F30"}, +{Qt::Key_F31, "F31"}, +{Qt::Key_F32, "F32"}, +{Qt::Key_F33, "F33"}, +{Qt::Key_F34, "F34"}, +{Qt::Key_F35, "F35"}, +{Qt::Key_Super_L, "Super_L"}, +{Qt::Key_Super_R, "Super_R"}, +{Qt::Key_Menu, "Menu"}, +{Qt::Key_Hyper_L, "Hyper_L"}, +{Qt::Key_Hyper_R, "Hyper_R"}, +{Qt::Key_Help, "Help"}, +{Qt::Key_Space, "Space"}, +{Qt::Key_Any, "Any"}, +{Qt::Key_Space, "Space"}, +{Qt::Key_Exclam, "Exclam"}, +{Qt::Key_QuoteDbl, "QuoteDbl"}, +{Qt::Key_NumberSign, "NumberSign"}, +{Qt::Key_Dollar, "Dollar"}, +{Qt::Key_Percent, "Percent"}, +{Qt::Key_Ampersand, "Ampersand"}, +{Qt::Key_Apostrophe, "Apostrophe"}, +{Qt::Key_ParenLeft, "ParenLeft"}, +{Qt::Key_ParenRight, "ParenRight"}, +{Qt::Key_Asterisk, "Asterisk"}, +{Qt::Key_Plus, "Plus"}, +{Qt::Key_Comma, "Comma"}, +{Qt::Key_Minus, "Minus"}, +{Qt::Key_Period, "Period"}, +{Qt::Key_Slash, "Slash"}, +{Qt::Key_0, "0"}, +{Qt::Key_1, "1"}, +{Qt::Key_2, "2"}, +{Qt::Key_3, "3"}, +{Qt::Key_4, "4"}, +{Qt::Key_5, "5"}, +{Qt::Key_6, "6"}, +{Qt::Key_7, "7"}, +{Qt::Key_8, "8"}, +{Qt::Key_9, "9"}, +{Qt::Key_Colon, "Colon"}, +{Qt::Key_Semicolon, "Semicolon"}, +{Qt::Key_Less, "Less"}, +{Qt::Key_Equal, "Equal"}, +{Qt::Key_Greater, "Greater"}, +{Qt::Key_Question, "Question"}, +{Qt::Key_At, "At"}, +{Qt::Key_A, "A"}, +{Qt::Key_B, "B"}, +{Qt::Key_C, "C"}, +{Qt::Key_D, "D"}, +{Qt::Key_E, "E"}, +{Qt::Key_F, "F"}, +{Qt::Key_G, "G"}, +{Qt::Key_H, "H"}, +{Qt::Key_I, "I"}, +{Qt::Key_J, "J"}, +{Qt::Key_K, "K"}, +{Qt::Key_L, "L"}, +{Qt::Key_M, "M"}, +{Qt::Key_N, "N"}, +{Qt::Key_O, "O"}, +{Qt::Key_P, "P"}, +{Qt::Key_Q, "Q"}, +{Qt::Key_R, "R"}, +{Qt::Key_S, "S"}, +{Qt::Key_T, "T"}, +{Qt::Key_U, "U"}, +{Qt::Key_V, "V"}, +{Qt::Key_W, "W"}, +{Qt::Key_X, "X"}, +{Qt::Key_Y, "Y"}, +{Qt::Key_Z, "Z"}, +{Qt::Key_BracketLeft, "BracketLeft"}, +{Qt::Key_Backslash, "Backslash"}, +{Qt::Key_BracketRight, "BracketRight"}, +{Qt::Key_AsciiCircum, "AsciiCircum"}, +{Qt::Key_Underscore, "Underscore"}, +{Qt::Key_QuoteLeft, "QuoteLeft"}, +{Qt::Key_BraceLeft, "BraceLeft"}, +{Qt::Key_Bar, "Bar"}, +{Qt::Key_BraceRight, "BraceRight"}, +{Qt::Key_AsciiTilde, "AsciiTilde"}, +{Qt::Key_nobreakspace, "nobreakspace"}, +{Qt::Key_exclamdown, "exclamdown"}, +{Qt::Key_cent, "cent"}, +{Qt::Key_sterling, "sterling"}, +{Qt::Key_currency, "currency"}, +{Qt::Key_yen, "yen"}, +{Qt::Key_brokenbar, "brokenbar"}, +{Qt::Key_section, "section"}, +{Qt::Key_diaeresis, "diaeresis"}, +{Qt::Key_copyright, "copyright"}, +{Qt::Key_ordfeminine, "ordfeminine"}, +{Qt::Key_guillemotleft, "guillemotleft"}, +{Qt::Key_notsign, "notsign"}, +{Qt::Key_hyphen, "hyphen"}, +{Qt::Key_registered, "registered"}, +{Qt::Key_macron, "macron"}, +{Qt::Key_degree, "degree"}, +{Qt::Key_plusminus, "plusminus"}, +{Qt::Key_twosuperior, "twosuperior"}, +{Qt::Key_threesuperior, "threesuperior"}, +{Qt::Key_acute, "acute"}, +{Qt::Key_mu, "mu"}, +{Qt::Key_paragraph, "paragraph"}, +{Qt::Key_periodcentered, "periodcentered"}, +{Qt::Key_cedilla, "cedilla"}, +{Qt::Key_onesuperior, "onesuperior"}, +{Qt::Key_masculine, "masculine"}, +{Qt::Key_guillemotright, "guillemotright"}, +{Qt::Key_onequarter, "onequarter"}, +{Qt::Key_onehalf, "onehalf"}, +{Qt::Key_threequarters, "threequarters"}, +{Qt::Key_questiondown, "questiondown"}, +{Qt::Key_Agrave, "Agrave"}, +{Qt::Key_Aacute, "Aacute"}, +{Qt::Key_Acircumflex, "Acircumflex"}, +{Qt::Key_Atilde, "Atilde"}, +{Qt::Key_Adiaeresis, "Adiaeresis"}, +{Qt::Key_Aring, "Aring"}, +{Qt::Key_AE, "AE"}, +{Qt::Key_Ccedilla, "Ccedilla"}, +{Qt::Key_Egrave, "Egrave"}, +{Qt::Key_Eacute, "Eacute"}, +{Qt::Key_Ecircumflex, "Ecircumflex"}, +{Qt::Key_Ediaeresis, "Ediaeresis"}, +{Qt::Key_Igrave, "Igrave"}, +{Qt::Key_Iacute, "Iacute"}, +{Qt::Key_Icircumflex, "Icircumflex"}, +{Qt::Key_Idiaeresis, "Idiaeresis"}, +{Qt::Key_ETH, "ETH"}, +{Qt::Key_Ntilde, "Ntilde"}, +{Qt::Key_Ograve, "Ograve"}, +{Qt::Key_Oacute, "Oacute"}, +{Qt::Key_Ocircumflex, "Ocircumflex"}, +{Qt::Key_Otilde, "Otilde"}, +{Qt::Key_Odiaeresis, "Odiaeresis"}, +{Qt::Key_multiply, "multiply"}, +{Qt::Key_Ooblique, "Ooblique"}, +{Qt::Key_Ugrave, "Ugrave"}, +{Qt::Key_Uacute, "Uacute"}, +{Qt::Key_Ucircumflex, "Ucircumflex"}, +{Qt::Key_Udiaeresis, "Udiaeresis"}, +{Qt::Key_Yacute, "Yacute"}, +{Qt::Key_THORN, "THORN"}, +{Qt::Key_ssharp, "ssharp"}, +{Qt::Key_agrave, "agrave"}, +{Qt::Key_aacute, "aacute"}, +{Qt::Key_acircumflex, "acircumflex"}, +{Qt::Key_atilde, "atilde"}, +{Qt::Key_adiaeresis, "adiaeresis"}, +{Qt::Key_aring, "aring"}, +{Qt::Key_ae, "ae"}, +{Qt::Key_ccedilla, "ccedilla"}, +{Qt::Key_egrave, "egrave"}, +{Qt::Key_eacute, "eacute"}, +{Qt::Key_ecircumflex, "ecircumflex"}, +{Qt::Key_ediaeresis, "ediaeresis"}, +{Qt::Key_igrave, "igrave"}, +{Qt::Key_iacute, "iacute"}, +{Qt::Key_icircumflex, "icircumflex"}, +{Qt::Key_idiaeresis, "idiaeresis"}, +{Qt::Key_eth, "eth"}, +{Qt::Key_ntilde, "ntilde"}, +{Qt::Key_ograve, "ograve"}, +{Qt::Key_oacute, "oacute"}, +{Qt::Key_ocircumflex, "ocircumflex"}, +{Qt::Key_otilde, "otilde"}, +{Qt::Key_odiaeresis, "odiaeresis"}, +{Qt::Key_division, "division"}, +{Qt::Key_oslash, "oslash"}, +{Qt::Key_ugrave, "ugrave"}, +{Qt::Key_uacute, "uacute"}, +{Qt::Key_ucircumflex, "ucircumflex"}, +{Qt::Key_udiaeresis, "udiaeresis"}, +{Qt::Key_yacute, "yacute"}, +{Qt::Key_thorn, "thorn"}, +{Qt::Key_ydiaeresis, "ydiaeresis"}, +{Qt::Key_unknown, "unknown"}, +{0,0}, +}; + +void KeyNames::setCodeMap() +{ + int i; + + codemap.clear(); + for(i=0; stKeyNames[i].code != 0; i++){ + codemap.insert(stKeyNames[i].name, stKeyNames[i].code); + } +} + +void KeyNames::setNameMap() +{ + int i; + + namemap.clear(); + for(i=0; stKeyNames[i].code != 0; i++){ + namemap.insert(stKeyNames[i].code, stKeyNames[i].name); + } +} diff --git a/noncore/applets/keyhelper/keyhelperconf/KeyNames.h b/noncore/applets/keyhelper/keyhelperconf/KeyNames.h new file mode 100644 index 0000000..edd7dc5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KeyNames.h @@ -0,0 +1,49 @@ +#ifndef _KEY_NAMES_H_ +#define _KEY_NAMES_H_ + +#include <qstring.h> +#include <qmap.h> +#include <qnamespace.h> + +class KeyNames +{ +public: + static const QString& getName(int code){ + if(namemap.isEmpty()) setNameMap(); + if(namemap.contains(code)){ + return(namemap[code]); + } else { + return(QString::null); + } + } + static void clearName(){ + namemap.clear(); + } + static int getCode(const QString& s){ + if(codemap.isEmpty()) setCodeMap(); + if(codemap.contains(s)){ + return(codemap[s]); + } else { + return(0); + } + } + static void setCode(const QString& s, int code){ + if(codemap.contains(s) == false){ + codemap.insert(s, code); + } + } + static void clearCode(){ + codemap.clear(); + } + static void reset(){ + clearCode(); + } +private: + static QMap<QString, int> codemap; + static QMap<int, QString> namemap; + + static void setCodeMap(); + static void setNameMap(); +}; + +#endif /* _KEY_NAMES_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperconf/keyhelperconf.pro b/noncore/applets/keyhelper/keyhelperconf/keyhelperconf.pro new file mode 100644 index 0000000..f84db3d --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/keyhelperconf.pro @@ -0,0 +1,13 @@ +CONFIG = qt warn_on quick-app +HEADERS = KHCWidget.h \ + KeyNames.h +SOURCES = KHCWidget.cpp \ + KeyNames.cpp \ + khcmain.cpp +INTERFACES = KHCWidgetBase.ui +DESTDIR = $(OPIEDIR)/bin +INCLUDEPATH += . $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe + +include( $(OPIEDIR)/include.pro ) diff --git a/noncore/applets/keyhelper/keyhelperconf/khcmain.cpp b/noncore/applets/keyhelper/keyhelperconf/khcmain.cpp new file mode 100644 index 0000000..757bde0 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/khcmain.cpp @@ -0,0 +1,11 @@ +#include <qpe/qpeapplication.h> +#include "KHCWidget.h" + +int main(int argc, char* argv[]) +{ + QPEApplication a(argc, argv); + + KHCWidget w; + a.showMainWidget(&w); + return a.exec(); +} @@ -50,48 +50,49 @@ CONFIG_EXAMPLE_LIBOPIE2NET examples/opienet opienet.pro CONFIG_EXAMPLE_LIBOPIE2PIM examples/opiepim opiepim.pro CONFIG_EXAMPLE_LIBOPIE2SECURITY examples/opiesecurity opiesecurity.pro CONFIG_EXAMPLE_LIBOPIE2UI examples/opieui opieui.pro CONFIG_EXAMPLE_MENU examples/menuapplet menuapplet.pro CONFIG_EXAMPLE_VPN examples/networksettings networksettings.pro CONFIG_FIFTEEN noncore/games/fifteen fifteen.pro CONFIG_FILEBROWSER noncore/unsupported/filebrowser filebrowser.pro CONFIG_FLAT noncore/styles/flat flat.pro CONFIG_FORMATTER noncore/tools/formatter formatter.pro CONFIG_FREETYPE freetype freetype.pro CONFIG_FRESH noncore/styles/fresh fresh.pro CONFIG_FTPLIB noncore/net/ftplib ftplib.pro CONFIG_GO noncore/games/go go.pro CONFIG_GSMTOOL noncore/unsupported/gsmtool gsmtool.pro CONFIG_GUTENBROWSER noncore/apps/opie-gutenbrowser opie-gutenbrowser.pro CONFIG_HANDWRITING inputmethods/handwriting handwriting.pro CONFIG_HELPBROWSER core/apps/helpbrowser helpbrowser.pro CONFIG_HOMEAPPLET core/applets/homeapplet homeapplet.pro CONFIG_INTERFACES noncore/settings/networksettings/interfaces interfaces.pro CONFIG_IRDAAPPLET core/applets/irdaapplet irdaapplet.pro CONFIG_JUMPX inputmethods/jumpx jumpx.pro CONFIG_KBILL noncore/games/kbill kbill.pro CONFIG_KCHECKERS noncore/games/kcheckers kcheckers.pro CONFIG_KEYBOARD inputmethods/keyboard keyboard.pro +CONFIG_KEYHELPER noncore/applets/keyhelper keyhelper.pro CONFIG_KEYPEBBLE noncore/comm/keypebble keypebble.pro CONFIG_KEYVIEW development/keyview keyview.pro CONFIG_KJUMPX inputmethods/kjumpx kjumpx.pro CONFIG_KPACMAN noncore/games/kpacman kpacman.pro CONFIG_LANGUAGE noncore/settings/language language.pro CONFIG_LAUNCHER core/launcher server.pro CONFIG_LAUNCHER-SETTINGS core/settings/launcher launcher.pro CONFIG_LIBFFMPEG core/multimedia/opieplayer/libffmpeg libffmpeg.pro CONFIG_LIBFLASH core/multimedia/opieplayer/libflash libflash.pro CONFIG_LIBMAD core/multimedia/opieplayer/libmad libmad.pro CONFIG_LIBMAIL noncore/unsupported/mail2/libmail libmail.pro CONFIG_LIBMAILWRAPPER noncore/net/mail/libmailwrapper libmailwrapper.pro CONFIG_LIBMPEG3 core/multimedia/opieplayer/libmpeg3 libmpeg3.pro CONFIG_LIBOPIE2CORE libopie2/opiecore opiecore.pro CONFIG_LIBOPIE2DB libopie2/opiedb opiedb.pro CONFIG_LIBOPIE2EXAMPLES libopie2/examples examples.pro CONFIG_LIBOPIE2MM libopie2/opiemm opiemm.pro CONFIG_LIBOPIE2NET libopie2/opienet opienet.pro CONFIG_LIBOPIE2PIM libopie2/opiepim opiepim.pro CONFIG_LIBOPIE2SECURITY libopie2/opiesecurity opiesecurity.pro CONFIG_LIBOPIE2UI libopie2/opieui opieui.pro CONFIG_LIBOPIETOOTH noncore/net/opietooth/lib lib.pro CONFIG_LIBOPIE noncore/unsupported/libopie libopie.pro CONFIG_LIBQPE library library.pro |