Add implementation of virtual keyboard based on BPS events

Change-Id: Ida4fa344c54db32b7b22b08a124b8c7b6df8adef
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Kevin Krammer 2012-03-27 18:39:49 +02:00 committed by Qt by Nokia
parent 77a8bd1e01
commit a818a1eb2f
8 changed files with 353 additions and 53 deletions

View File

@ -84,11 +84,13 @@ contains(QT_CONFIG, opengles2) {
CONFIG(blackberry) {
SOURCES += qqnxnavigatorbps.cpp \
qqnxeventdispatcher_blackberry.cpp \
qqnxbpseventfilter.cpp
qqnxbpseventfilter.cpp \
qqnxvirtualkeyboardbps.cpp
HEADERS += qqnxnavigatorbps.h \
qqnxeventdispatcher_blackberry.h \
qqnxbpseventfilter.h
qqnxbpseventfilter.h \
qqnxvirtualkeyboardbps.h
LIBS += -lbps
}
@ -98,12 +100,12 @@ CONFIG(qqnx_pps) {
SOURCES += qqnxnavigatorpps.cpp \
qqnxnavigatoreventnotifier.cpp \
qqnxvirtualkeyboard.cpp \
qqnxvirtualkeyboardpps.cpp \
qqnxclipboard.cpp
HEADERS += qqnxnavigatorpps.h \
qqnxnavigatoreventnotifier.h \
qqnxvirtualkeyboard.h \
qqnxvirtualkeyboardpps.h \
qqnxclipboard.h
LIBS += -lpps -lclipboard

View File

@ -43,6 +43,7 @@
#include "qqnxnavigatoreventhandler.h"
#include "qqnxscreen.h"
#include "qqnxscreeneventhandler.h"
#include "qqnxvirtualkeyboardbps.h"
#include <QAbstractEventDispatcher>
#include <QDebug>
@ -56,10 +57,12 @@ QT_BEGIN_NAMESPACE
static QQnxBpsEventFilter *s_instance = 0;
QQnxBpsEventFilter::QQnxBpsEventFilter(QQnxNavigatorEventHandler *navigatorEventHandler,
QQnxScreenEventHandler *screenEventHandler, QObject *parent)
QQnxScreenEventHandler *screenEventHandler,
QQnxVirtualKeyboardBps *virtualKeyboard, QObject *parent)
: QObject(parent)
, m_navigatorEventHandler(navigatorEventHandler)
, m_screenEventHandler(screenEventHandler)
, m_virtualKeyboard(virtualKeyboard)
{
Q_ASSERT(s_instance == 0);
@ -132,6 +135,9 @@ bool QQnxBpsEventFilter::bpsEventFilter(bps_event_t *event)
if (eventDomain == navigator_get_domain())
return handleNavigatorEvent(event);
if (m_virtualKeyboard->handleEvent(event))
return true;
return false;
}

View File

@ -52,13 +52,15 @@ class QAbstractEventDispatcher;
class QQnxNavigatorEventHandler;
class QQnxScreen;
class QQnxScreenEventHandler;
class QQnxVirtualKeyboardBps;
class QQnxBpsEventFilter : public QObject
{
Q_OBJECT
public:
QQnxBpsEventFilter(QQnxNavigatorEventHandler *navigatorEventHandler,
QQnxScreenEventHandler *screenEventHandler, QObject *parent = 0);
QQnxScreenEventHandler *screenEventHandler,
QQnxVirtualKeyboardBps *virtualKeyboard, QObject *parent = 0);
~QQnxBpsEventFilter();
void installOnEventDispatcher(QAbstractEventDispatcher *dispatcher);
@ -75,6 +77,7 @@ private:
private:
QQnxNavigatorEventHandler *m_navigatorEventHandler;
QQnxScreenEventHandler *m_screenEventHandler;
QQnxVirtualKeyboardBps *m_virtualKeyboard;
};
QT_END_NAMESPACE

View File

@ -54,13 +54,14 @@
#if defined(Q_OS_BLACKBERRY)
#include "qqnxbpseventfilter.h"
#include "qqnxnavigatorbps.h"
#include "qqnxvirtualkeyboardbps.h"
#elif defined(QQNX_PPS)
#include "qqnxnavigatorpps.h"
#include "qqnxvirtualkeyboardpps.h"
#endif
#if defined(QQNX_PPS)
# include "qqnxnavigatoreventnotifier.h"
# include "qqnxvirtualkeyboard.h"
# include "qqnxclipboard.h"
# if defined(QQNX_IMF)
@ -159,20 +160,14 @@ QQnxIntegration::QQnxIntegration()
m_screenEventThread->start();
#endif
#if defined(QQNX_PPS)
// Not on BlackBerry, it has specialised event dispatcher which also handles virtual keyboard events
#if !defined(Q_OS_BLACKBERRY) && defined(QQNX_PPS)
// Create/start the keyboard class.
m_virtualKeyboard = new QQnxVirtualKeyboard();
m_virtualKeyboard = new QQnxVirtualKeyboardPps();
// delay invocation of start() to the time the event loop is up and running
// needed to have the QThread internals of the main thread properly initialized
QMetaObject::invokeMethod(m_virtualKeyboard, "start", Qt::QueuedConnection);
// TODO check if we need to do this for all screens or only the primary one
QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(int)),
primaryDisplay(), SLOT(keyboardHeightChanged(int)));
// Set up the input context
m_inputContext = new QQnxInputContext(*m_virtualKeyboard);
#endif
#if defined(Q_OS_BLACKBERRY)
@ -186,13 +181,27 @@ QQnxIntegration::QQnxIntegration()
m_services = new QQnxServices(m_navigator);
#if defined(Q_OS_BLACKBERRY)
m_bpsEventFilter = new QQnxBpsEventFilter(m_navigatorEventHandler, m_screenEventHandler);
QQnxVirtualKeyboardBps* virtualKeyboardBps = new QQnxVirtualKeyboardBps;
m_bpsEventFilter = new QQnxBpsEventFilter(m_navigatorEventHandler, m_screenEventHandler, virtualKeyboardBps);
Q_FOREACH (QQnxScreen *screen, m_screens)
m_bpsEventFilter->registerForScreenEvents(screen);
m_bpsEventFilter->installOnEventDispatcher(m_eventDispatcher);
m_virtualKeyboard = virtualKeyboardBps;
#endif
if (m_virtualKeyboard) {
// TODO check if we need to do this for all screens or only the primary one
QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(int)),
primaryDisplay(), SLOT(keyboardHeightChanged(int)));
#if defined(QQNX_PPS)
// Set up the input context
m_inputContext = new QQnxInputContext(*m_virtualKeyboard);
#endif
}
}
QQnxIntegration::~QQnxIntegration()

View File

@ -0,0 +1,209 @@
/***************************************************************************
**
** Copyright (C) 2012 Research In Motion
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qqnxvirtualkeyboardbps.h"
#include <QDebug>
#include <bps/event.h>
#include <bps/locale.h>
#include <bps/virtualkeyboard.h>
QT_BEGIN_NAMESPACE
QQnxVirtualKeyboardBps::QQnxVirtualKeyboardBps(QObject *parent)
: QQnxAbstractVirtualKeyboard(parent)
{
if (locale_request_events(0) != BPS_SUCCESS)
qWarning("QQNX: Failed to register for locale events");
if (virtualkeyboard_request_events(0) != BPS_SUCCESS)
qWarning("QQNX: Failed to register for virtual keyboard events");
int height = 0;
if (virtualkeyboard_get_height(&height) != BPS_SUCCESS)
qWarning("QQNX: Failed to get virtual keyboard height");
setHeight(height);
}
bool QQnxVirtualKeyboardBps::handleEvent(bps_event_t *event)
{
const int eventDomain = bps_event_get_domain(event);
if (eventDomain == locale_get_domain())
return handleLocaleEvent(event);
if (eventDomain == virtualkeyboard_get_domain())
return handleVirtualKeyboardEvent(event);
return false;
}
bool QQnxVirtualKeyboardBps::showKeyboard()
{
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << Q_FUNC_INFO << "current visibility=" << isVisible();
#endif
virtualkeyboard_show();
return true;
}
bool QQnxVirtualKeyboardBps::hideKeyboard()
{
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << Q_FUNC_INFO << "current visibility=" << isVisible();
#endif
virtualkeyboard_hide();
return true;
}
void QQnxVirtualKeyboardBps::applyKeyboardMode(KeyboardMode mode)
{
virtualkeyboard_layout_t layout = VIRTUALKEYBOARD_LAYOUT_DEFAULT;
switch (mode) {
case Url:
layout = VIRTUALKEYBOARD_LAYOUT_URL;
break;
case Email:
layout = VIRTUALKEYBOARD_LAYOUT_EMAIL;
break;
case Web:
layout = VIRTUALKEYBOARD_LAYOUT_WEB;
break;
case NumPunc:
layout = VIRTUALKEYBOARD_LAYOUT_NUM_PUNC;
break;
case Symbol:
layout = VIRTUALKEYBOARD_LAYOUT_SYMBOL;
break;
case Phone:
layout = VIRTUALKEYBOARD_LAYOUT_PHONE;
break;
case Pin:
layout = VIRTUALKEYBOARD_LAYOUT_PIN;
break;
case Default: // fall through
default:
layout = VIRTUALKEYBOARD_LAYOUT_DEFAULT;
break;
}
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << Q_FUNC_INFO << "mode=" << mode;
#endif
virtualkeyboard_change_options(layout, VIRTUALKEYBOARD_ENTER_DEFAULT);
}
bool QQnxVirtualKeyboardBps::handleLocaleEvent(bps_event_t *event)
{
if (bps_event_get_code(event) == LOCALE_INFO) {
const QString language = QString::fromAscii(locale_event_get_language(event));
const QString country = QString::fromAscii(locale_event_get_country(event));
const QLocale newLocale(language + QLatin1Char('_') + country);
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << Q_FUNC_INFO << "current locale" << locale() << "new locale=" << newLocale;
#endif
setLocale(newLocale);
return true;
}
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << "QQNX: Unhandled locale event. code=" << bps_event_get_code(event);
#endif
return false;
}
bool QQnxVirtualKeyboardBps::handleVirtualKeyboardEvent(bps_event_t *event)
{
switch (bps_event_get_code(event)) {
case VIRTUALKEYBOARD_EVENT_VISIBLE:
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << Q_FUNC_INFO << "EVENT VISIBLE: current visibility=" << isVisible();
#endif
setVisible(true);
break;
case VIRTUALKEYBOARD_EVENT_HIDDEN:
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << Q_FUNC_INFO << "EVENT HIDDEN: current visibility=" << isVisible();
#endif
setVisible(false);
break;
case VIRTUALKEYBOARD_EVENT_INFO: {
const int newHeight = virtualkeyboard_event_get_height(event);
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << Q_FUNC_INFO << "EVENT INFO: current height=" << height() << "new height=" << newHeight;
#endif
setHeight(newHeight);
break;
}
default:
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << "QQNX: Unhandled virtual keyboard event. code=" << bps_event_get_code(event);
#endif
return false;
}
return true;
}
QT_END_NAMESPACE

View File

@ -0,0 +1,72 @@
/***************************************************************************
**
** Copyright (C) 2012 Research In Motion
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QQNXVIRTUALKEYBOARDBPS_H
#define QQNXVIRTUALKEYBOARDBPS_H
#include "qqnxabstractvirtualkeyboard.h"
struct bps_event_t;
QT_BEGIN_NAMESPACE
class QQnxVirtualKeyboardBps : public QQnxAbstractVirtualKeyboard
{
Q_OBJECT
public:
explicit QQnxVirtualKeyboardBps(QObject *parent = 0);
bool handleEvent(bps_event_t *event);
bool showKeyboard();
bool hideKeyboard();
protected:
void applyKeyboardMode(KeyboardMode mode);
private:
bool handleLocaleEvent(bps_event_t *event);
bool handleVirtualKeyboardEvent(bps_event_t *event);
};
QT_END_NAMESPACE
#endif // QQNXVIRTUALKEYBOARDBPS_H

View File

@ -39,7 +39,7 @@
**
****************************************************************************/
#include "qqnxvirtualkeyboard.h"
#include "qqnxvirtualkeyboardpps.h"
#include "qqnxscreen.h"
#include <QtCore/QDebug>
@ -58,13 +58,13 @@
QT_BEGIN_NAMESPACE
const char *QQnxVirtualKeyboard::ms_PPSPath = "/pps/services/input/control";
const size_t QQnxVirtualKeyboard::ms_bufferSize = 2048;
const char *QQnxVirtualKeyboardPps::ms_PPSPath = "/pps/services/input/control";
const size_t QQnxVirtualKeyboardPps::ms_bufferSize = 2048;
// Huge hack for keyboard shadow (see QNX PR 88400). Should be removed ASAP.
#define KEYBOARD_SHADOW_HEIGHT 8
QQnxVirtualKeyboard::QQnxVirtualKeyboard()
QQnxVirtualKeyboardPps::QQnxVirtualKeyboardPps()
: m_encoder(0),
m_decoder(0),
m_buffer(0),
@ -73,26 +73,26 @@ QQnxVirtualKeyboard::QQnxVirtualKeyboard()
{
}
QQnxVirtualKeyboard::~QQnxVirtualKeyboard()
QQnxVirtualKeyboardPps::~QQnxVirtualKeyboardPps()
{
close();
}
void QQnxVirtualKeyboard::start()
void QQnxVirtualKeyboardPps::start()
{
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << "QQNX: starting keyboard event processing";
#endif
if (!connect())
return;
}
void QQnxVirtualKeyboard::applyKeyboardMode(KeyboardMode mode)
void QQnxVirtualKeyboardPps::applyKeyboardMode(KeyboardMode mode)
{
applyKeyboardModeOptions(mode);
}
void QQnxVirtualKeyboard::close()
void QQnxVirtualKeyboardPps::close()
{
delete m_readNotifier;
m_readNotifier = 0;
@ -118,7 +118,7 @@ void QQnxVirtualKeyboard::close()
m_buffer = 0;
}
bool QQnxVirtualKeyboard::connect()
bool QQnxVirtualKeyboardPps::connect()
{
close();
@ -153,7 +153,7 @@ bool QQnxVirtualKeyboard::connect()
return true;
}
bool QQnxVirtualKeyboard::queryPPSInfo()
bool QQnxVirtualKeyboardPps::queryPPSInfo()
{
// Request info, requires id to regenerate res message.
pps_encoder_add_string(m_encoder, "msg", "info");
@ -169,11 +169,11 @@ bool QQnxVirtualKeyboard::queryPPSInfo()
return true;
}
void QQnxVirtualKeyboard::ppsDataReady()
void QQnxVirtualKeyboardPps::ppsDataReady()
{
ssize_t nread = qt_safe_read(m_fd, m_buffer, ms_bufferSize - 1);
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << "QQNX: keyboardMessage size: " << nread;
#endif
if (nread < 0){
@ -196,7 +196,7 @@ void QQnxVirtualKeyboard::ppsDataReady()
m_buffer[nread] = 0;
pps_decoder_parse_pps_str(m_decoder, m_buffer);
pps_decoder_push(m_decoder, NULL);
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
pps_decoder_dump_tree(m_decoder, stderr);
#endif
@ -225,7 +225,7 @@ void QQnxVirtualKeyboard::ppsDataReady()
qCritical("QQnxVirtualKeyboard: Unexpected keyboard PPS message type");
}
void QQnxVirtualKeyboard::handleKeyboardInfoMessage()
void QQnxVirtualKeyboardPps::handleKeyboardInfoMessage()
{
int newHeight = 0;
const char *value;
@ -261,14 +261,14 @@ void QQnxVirtualKeyboard::handleKeyboardInfoMessage()
const QLocale locale = QLocale(languageId + QLatin1Char('_') + countryId);
setLocale(locale);
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << "QQNX: handleKeyboardInfoMessage size=" << newHeight << "locale=" << locale;
#endif
}
bool QQnxVirtualKeyboard::showKeyboard()
bool QQnxVirtualKeyboardPps::showKeyboard()
{
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << "QQNX: showKeyboard()";
#endif
@ -300,9 +300,9 @@ bool QQnxVirtualKeyboard::showKeyboard()
return true;
}
bool QQnxVirtualKeyboard::hideKeyboard()
bool QQnxVirtualKeyboardPps::hideKeyboard()
{
#ifdef QQNXVIRTUALKEYBOARD_DEBUG
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
qDebug() << "QQNX: hideKeyboard()";
#endif
@ -332,7 +332,7 @@ bool QQnxVirtualKeyboard::hideKeyboard()
return true;
}
void QQnxVirtualKeyboard::applyKeyboardModeOptions(KeyboardMode mode)
void QQnxVirtualKeyboardPps::applyKeyboardModeOptions(KeyboardMode mode)
{
// Try to connect.
if (m_fd == -1 && !connect())
@ -379,49 +379,49 @@ void QQnxVirtualKeyboard::applyKeyboardModeOptions(KeyboardMode mode)
pps_encoder_reset(m_encoder);
}
void QQnxVirtualKeyboard::addDefaultModeOptions()
void QQnxVirtualKeyboardPps::addDefaultModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "default");
}
void QQnxVirtualKeyboard::addUrlModeOptions()
void QQnxVirtualKeyboardPps::addUrlModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "url");
}
void QQnxVirtualKeyboard::addEmailModeOptions()
void QQnxVirtualKeyboardPps::addEmailModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "email");
}
void QQnxVirtualKeyboard::addWebModeOptions()
void QQnxVirtualKeyboardPps::addWebModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "web");
}
void QQnxVirtualKeyboard::addNumPuncModeOptions()
void QQnxVirtualKeyboardPps::addNumPuncModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "numPunc");
}
void QQnxVirtualKeyboard::addPhoneModeOptions()
void QQnxVirtualKeyboardPps::addPhoneModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "phone");
}
void QQnxVirtualKeyboard::addPinModeOptions()
void QQnxVirtualKeyboardPps::addPinModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "pin");
}
void QQnxVirtualKeyboard::addSymbolModeOptions()
void QQnxVirtualKeyboardPps::addSymbolModeOptions()
{
pps_encoder_add_string(m_encoder, "enter", "enter.default");
pps_encoder_add_string(m_encoder, "type", "symbol");

View File

@ -39,8 +39,8 @@
**
****************************************************************************/
#ifndef VIRTUALKEYBOARD_H_
#define VIRTUALKEYBOARD_H_
#ifndef VIRTUALKEYBOARDPPS_H_
#define VIRTUALKEYBOARDPPS_H_
#include "qqnxabstractvirtualkeyboard.h"
@ -50,13 +50,12 @@ QT_BEGIN_NAMESPACE
class QSocketNotifier;
/* Shamelessly copied from the browser - this should be rewritten once we have a proper PPS wrapper class */
class QQnxVirtualKeyboard : public QQnxAbstractVirtualKeyboard
class QQnxVirtualKeyboardPps : public QQnxAbstractVirtualKeyboard
{
Q_OBJECT
public:
QQnxVirtualKeyboard();
~QQnxVirtualKeyboard();
QQnxVirtualKeyboardPps();
~QQnxVirtualKeyboardPps();
bool showKeyboard();
bool hideKeyboard();
@ -98,4 +97,4 @@ private:
static const size_t ms_bufferSize;
};
#endif /* VIRTUALKEYBOARD_H_ */
#endif /* VIRTUALKEYBOARDPPS_H_ */