diff options
10 files changed, 252 insertions, 109 deletions
diff --git a/src/plugins/platforms/blackberry/blackberry.pro b/src/plugins/platforms/blackberry/blackberry.pro index c8e483f..7f6da24 100644 --- a/src/plugins/platforms/blackberry/blackberry.pro +++ b/src/plugins/platforms/blackberry/blackberry.pro @@ -19,7 +19,8 @@ SOURCES = main.cpp \ qbbclipboard.cpp \ qbblocalethread.cpp \ qbbrootwindow.cpp \ - qbbscreeneventhandler.cpp + qbbscreeneventhandler.cpp \ + qbbabstractvirtualkeyboard.cpp HEADERS = qbbbuffer.h \ qbbeventthread.h \ @@ -35,7 +36,8 @@ HEADERS = qbbbuffer.h \ qbbclipboard.h \ qbblocalethread.h \ qbbrootwindow.h \ - qbbscreeneventhandler.h + qbbscreeneventhandler.h \ + qbbabstractvirtualkeyboard.h QMAKE_CXXFLAGS += -I./private diff --git a/src/plugins/platforms/blackberry/qbbabstractvirtualkeyboard.cpp b/src/plugins/platforms/blackberry/qbbabstractvirtualkeyboard.cpp new file mode 100644 index 0000000..46e4cab --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbabstractvirtualkeyboard.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** +** Contact: Research In Motion <blackberry-qt@qnx.com> +** Contact: Klarälvdalens Datakonsult AB <info@kdab.com> +** +** This file is part of the QtCore module 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. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbabstractvirtualkeyboard.h" + +QT_BEGIN_NAMESPACE + +QBBAbstractVirtualKeyboard::QBBAbstractVirtualKeyboard(QObject *parent) + : QObject(parent) + , mHeight(0) + , mKeyboardMode(Default) + , mVisible(false) + , mLanguageId(QString::fromLatin1("en")) + , mCountryId(QString::fromLatin1("US")) +{ +} + +void QBBAbstractVirtualKeyboard::setKeyboardMode(KeyboardMode mode) +{ + if (mode == mKeyboardMode) + return; + + mKeyboardMode = mode; + + applyKeyboardMode(mode); +} + +void QBBAbstractVirtualKeyboard::setVisible(bool visible) +{ + if (visible == mVisible) + return; + + const int effectiveHeight = getHeight(); + + mVisible = visible; + + if (effectiveHeight != getHeight()) + emit heightChanged(getHeight()); +} + +void QBBAbstractVirtualKeyboard::setHeight(bool height) +{ + if (height == mHeight) + return; + + const int effectiveHeight = getHeight(); + + mHeight = height; + + if (effectiveHeight != getHeight()) + emit heightChanged(getHeight()); +} + +void QBBAbstractVirtualKeyboard::setLanguage(const QString &language) +{ + if (language == mLanguageId) + return; + + mLanguageId = language; +} + +void QBBAbstractVirtualKeyboard::setCountry(const QString &country) +{ + if (country == mCountryId) + return; + + mCountryId = country; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbabstractvirtualkeyboard.h b/src/plugins/platforms/blackberry/qbbabstractvirtualkeyboard.h new file mode 100644 index 0000000..8f2e09e --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbabstractvirtualkeyboard.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** +** Contact: Research In Motion <blackberry-qt@qnx.com> +** Contact: Klarälvdalens Datakonsult AB <info@kdab.com> +** +** This file is part of the QtCore module 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. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBABSTRACTVIRTUALKEYBOARD_H +#define QBBABSTRACTVIRTUALKEYBOARD_H + +#include <QObject> + +QT_BEGIN_NAMESPACE + +class QBBAbstractVirtualKeyboard : public QObject +{ + Q_OBJECT +public: + // NOTE: Not all the following keyboard modes are currently used. + // Default - Regular Keyboard + // Url/Email - Enhanced keys for each types. + // Web - Regular keyboard with two blank keys, currently unused. + // NumPunc - Numbers & Punctionation, alternate to Symbol + // Symbol - All symbols, alternate to NumPunc, currently unused. + // Phone - Phone enhanced keyboard - currently unused as no alternate keyboard available to access a-zA-Z + // Pin - Keyboard for entering Pins (Hex values) currently unused. + // + // SPECIAL NOTE: Usage of NumPunc may have to be removed, ABC button is non-functional. + // + enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin }; + + explicit QBBAbstractVirtualKeyboard(QObject *parent = 0); + + virtual bool showKeyboard() = 0; + virtual bool hideKeyboard() = 0; + + int getHeight() const { return mVisible ? mHeight : 0; } + + void setKeyboardMode(KeyboardMode mode); + KeyboardMode keyboardMode() const { return mKeyboardMode; } + + bool isVisible() const { return mVisible; } + QString languageId() const { return mLanguageId; } + QString countryId() const { return mCountryId; } + +Q_SIGNALS: + void heightChanged(int height); + +protected: + virtual void applyKeyboardMode(KeyboardMode mode) = 0; + + void setVisible(bool visible); + void setHeight(bool height); + void setLanguage(const QString &language); + void setCountry(const QString &country); + +private: + int mHeight; + KeyboardMode mKeyboardMode; + bool mVisible; + QString mLanguageId; + QString mCountryId; +}; + +QT_END_NAMESPACE + +#endif // QBBABSTRACTVIRTUALKEYBOARD_H diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp b/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp index 5a87777..68c4785 100644 --- a/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp +++ b/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp @@ -49,7 +49,7 @@ #include <qbbeventthread.h> #include <qbbinputcontext.h> -#include <qbbvirtualkeyboard.h> +#include <qbbabstractvirtualkeyboard.h> #include <QAction> #include <QCoreApplication> @@ -678,7 +678,7 @@ static bool imfAvailable() QT_BEGIN_NAMESPACE -QBBInputContext::QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent): +QBBInputContext::QBBInputContext(QBBAbstractVirtualKeyboard &keyboard, QObject* parent): QInputContext(parent), mLastCaretPos(0), mIsComposing(false), diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_imf.h b/src/plugins/platforms/blackberry/qbbinputcontext_imf.h index ddbe912..435cbfe 100644 --- a/src/plugins/platforms/blackberry/qbbinputcontext_imf.h +++ b/src/plugins/platforms/blackberry/qbbinputcontext_imf.h @@ -48,12 +48,12 @@ QT_BEGIN_NAMESPACE -class QBBVirtualKeyboard; +class QBBAbstractVirtualKeyboard; class QBBInputContext : public QInputContext { public: - explicit QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent = 0); + explicit QBBInputContext(QBBAbstractVirtualKeyboard &keyboard, QObject* parent = 0); ~QBBInputContext(); virtual QList<QAction *> actions(); @@ -112,7 +112,7 @@ private: int mLastCaretPos; bool mIsComposing; QString mComposingText; - QBBVirtualKeyboard &mVirtualKeyboard; + QBBAbstractVirtualKeyboard &mVirtualKeyboard; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp index ef39aba..9f32170 100644 --- a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp +++ b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp @@ -40,14 +40,14 @@ // #define QBBINPUTCONTEXT_DEBUG #include <qbbinputcontext.h> -#include <qbbvirtualkeyboard.h> +#include <qbbabstractvirtualkeyboard.h> #include <QDebug> #include <QAbstractSpinBox> QT_BEGIN_NAMESPACE -QBBInputContext::QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent) +QBBInputContext::QBBInputContext(QBBAbstractVirtualKeyboard &keyboard, QObject* parent) : QInputContext(parent), mVirtualKeyboard(keyboard) { @@ -112,9 +112,9 @@ void QBBInputContext::setFocusWidget(QWidget *w) if (w) { if (qobject_cast<QAbstractSpinBox*>(w)) - mVirtualKeyboard.setKeyboardMode(QBBVirtualKeyboard::Phone); + mVirtualKeyboard.setKeyboardMode(QBBAbstractVirtualKeyboard::Phone); else - mVirtualKeyboard.setKeyboardMode(QBBVirtualKeyboard::Default); + mVirtualKeyboard.setKeyboardMode(QBBAbstractVirtualKeyboard::Default); mVirtualKeyboard.showKeyboard(); } else { diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h index 3c416c8..3816d12 100644 --- a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h +++ b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h @@ -45,12 +45,12 @@ QT_BEGIN_NAMESPACE -class QBBVirtualKeyboard; +class QBBAbstractVirtualKeyboard; class QBBInputContext : public QInputContext { public: - explicit QBBInputContext(QBBVirtualKeyboard &keyboard, QObject* parent = 0); + explicit QBBInputContext(QBBAbstractVirtualKeyboard &keyboard, QObject* parent = 0); ~QBBInputContext(); QString identifierName() { return QString("BlackBerry IMF"); } QString language(); @@ -65,7 +65,7 @@ public: private: bool hasPhysicalKeyboard(); - QBBVirtualKeyboard &mVirtualKeyboard; + QBBAbstractVirtualKeyboard &mVirtualKeyboard; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h index 2866b19..0ab50ca 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.h +++ b/src/plugins/platforms/blackberry/qbbintegration.h @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE class QBBEventThread; class QBBNavigatorEventHandler; class QBBLocaleThread; -class QBBVirtualKeyboard; +class QBBAbstractVirtualKeyboard; class QBBIntegration : public QPlatformIntegration { @@ -82,7 +82,7 @@ private: QBBLocaleThread *mLocaleThread; QPlatformFontDatabase *mFontDb; bool mPaintUsingOpenGL; - QBBVirtualKeyboard *mVirtualKeyboard; + QBBAbstractVirtualKeyboard *mVirtualKeyboard; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp index 0f1a16e..0842684 100644 --- a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp +++ b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp @@ -71,12 +71,7 @@ QBBVirtualKeyboard::QBBVirtualKeyboard() : mEncoder(0), mDecoder(0), mBuffer(0), - mHeight(0), mFd(-1), - mKeyboardMode(Default), - mVisible(false), - mLanguageId(QString::fromLatin1("en")), - mCountryId(QString::fromLatin1("US")), mReadNotifier(0) { } @@ -96,6 +91,11 @@ void QBBVirtualKeyboard::start() return; } +void QBBVirtualKeyboard::applyKeyboardMode(KeyboardMode mode) +{ + applyKeyboardModeOptions(mode); +} + void QBBVirtualKeyboard::close() { delete mReadNotifier; @@ -135,8 +135,7 @@ bool QBBVirtualKeyboard::connect() errno = 0; mFd = ::open(sPPSPath, O_RDWR); - if (mFd == -1) - { + if (mFd == -1) { qCritical("QBBVirtualKeyboard: Unable to open \"%s\" for keyboard: %s (%d).", sPPSPath, strerror(errno), errno); close(); @@ -174,12 +173,6 @@ bool QBBVirtualKeyboard::queryPPSInfo() return true; } -void QBBVirtualKeyboard::notifyClientActiveStateChange(bool active) -{ - if (!active) - hideKeyboard(); -} - void QBBVirtualKeyboard::ppsDataReady() { ssize_t nread = qt_safe_read(mFd, mBuffer, sBufferSize - 1); @@ -213,13 +206,11 @@ void QBBVirtualKeyboard::ppsDataReady() } if (pps_decoder_get_string(mDecoder, "msg", &value) == PPS_DECODER_OK) { - if (strcmp(value, "show") == 0) { - mVisible = true; - handleKeyboardStateChangeMessage(true); - } else if (strcmp(value, "hide") == 0) { - mVisible = false; - handleKeyboardStateChangeMessage(false); - } else if (strcmp(value, "info") == 0) + if (strcmp(value, "show") == 0) + setVisible(true); + else if (strcmp(value, "hide") == 0) + setVisible(false); + else if (strcmp(value, "info") == 0) handleKeyboardInfoMessage(); else if (strcmp(value, "connect") == 0) { } else @@ -229,8 +220,9 @@ void QBBVirtualKeyboard::ppsDataReady() handleKeyboardInfoMessage(); else qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS res value: %s", value ? value : "[null]"); - } else + } else { qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS message type"); + } } void QBBVirtualKeyboard::handleKeyboardInfoMessage() @@ -254,37 +246,21 @@ void QBBVirtualKeyboard::handleKeyboardInfoMessage() qCritical("QBBVirtualKeyboard: Keyboard PPS languageId field not found"); return; } - mLanguageId = QString::fromLatin1(value); + setLanguage(QString::fromLatin1(value)); if (pps_decoder_get_string(mDecoder, "countryId", &value) != PPS_DECODER_OK) { qCritical("QBBVirtualKeyboard: Keyboard PPS size countryId not found"); return; } - mCountryId = QString::fromLatin1(value); + setCountry(QString::fromLatin1(value)); // HUGE hack, should be removed ASAP. newHeight -= KEYBOARD_SHADOW_HEIGHT; // We want to ignore the 8 pixel shadow above the keyboard. (PR 88400) - - if (newHeight != mHeight) { - mHeight = newHeight; - if (mVisible) - emit heightChanged(mHeight); - } - -#ifdef QBBVIRTUALKEYBOARD_DEBUG - qDebug() << "QBB: handleKeyboardInfoMessage size=" << mHeight << "languageId=" << mLanguageId << " countryId=" << mCountryId; -#endif -} - -void QBBVirtualKeyboard::handleKeyboardStateChangeMessage(bool visible) -{ + setHeight(newHeight); #ifdef QBBVIRTUALKEYBOARD_DEBUG - qDebug() << "QBB: handleKeyboardStateChangeMessage " << visible; + qDebug() << "QBB: handleKeyboardInfoMessage size=" << getHeight() << "languageId=" << languageId() << " countryId=" << countryId(); #endif - - if (mVisible != visible) - emit heightChanged(getHeight()); } bool QBBVirtualKeyboard::showKeyboard() @@ -299,7 +275,7 @@ bool QBBVirtualKeyboard::showKeyboard() // NOTE: This must be done everytime the keyboard is shown even if there is no change because // hiding the keyboard wipes the setting. - applyKeyboardModeOptions(); + applyKeyboardModeOptions(keyboardMode()); pps_encoder_reset(mEncoder); @@ -338,9 +314,9 @@ bool QBBVirtualKeyboard::hideKeyboard() close(); return false; } - } - else + } else { return false; + } } pps_encoder_reset(mEncoder); @@ -350,17 +326,7 @@ bool QBBVirtualKeyboard::hideKeyboard() return true; } -void QBBVirtualKeyboard::setKeyboardMode(KeyboardMode mode) -{ - if (mKeyboardMode == mode) - return; - - mKeyboardMode = mode; - if (mVisible) - applyKeyboardModeOptions(); -} - -void QBBVirtualKeyboard::applyKeyboardModeOptions() +void QBBVirtualKeyboard::applyKeyboardModeOptions(KeyboardMode mode) { // Try to connect. if (mFd == -1 && !connect()) @@ -370,7 +336,7 @@ void QBBVirtualKeyboard::applyKeyboardModeOptions() pps_encoder_add_string(mEncoder, "msg", "options"); pps_encoder_start_object(mEncoder, "dat"); - switch (mKeyboardMode) { + switch (mode) { case Url: addUrlModeOptions(); break; @@ -392,7 +358,7 @@ void QBBVirtualKeyboard::applyKeyboardModeOptions() case Pin: addPinModeOptions(); break; - case Default: + case Default: // fall through default: addDefaultModeOptions(); break; @@ -400,9 +366,8 @@ void QBBVirtualKeyboard::applyKeyboardModeOptions() pps_encoder_end_object(mEncoder); - if (::write(mFd, pps_encoder_buffer(mEncoder), pps_encoder_length(mEncoder)) == -1) { + if (::write(mFd, pps_encoder_buffer(mEncoder), pps_encoder_length(mEncoder)) == -1) close(); - } pps_encoder_reset(mEncoder); } diff --git a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h index 6a8c332..e544622 100644 --- a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h +++ b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h @@ -40,12 +40,8 @@ #ifndef VIRTUALKEYBOARD_H_ #define VIRTUALKEYBOARD_H_ -#include <QtGui/QPlatformScreen> -#include <QObject> +#include "qbbabstractvirtualkeyboard.h" -#include <stddef.h> -#include <vector> -#include <string> #include <sys/pps.h> QT_BEGIN_NAMESPACE @@ -53,40 +49,21 @@ QT_BEGIN_NAMESPACE class QSocketNotifier; /* Shamelessly copied from the browser - this should be rewritten once we have a proper PPS wrapper class */ -class QBBVirtualKeyboard : public QObject +class QBBVirtualKeyboard : public QBBAbstractVirtualKeyboard { Q_OBJECT public: - // NOTE: Not all the following keyboard modes are currently used. - // Default - Regular Keyboard - // Url/Email - Enhanced keys for each types. - // Web - Regular keyboard with two blank keys, currently unused. - // NumPunc - Numbers & Punctionation, alternate to Symbol - // Symbol - All symbols, alternate to NumPunc, currently unused. - // Phone - Phone enhanced keyboard - currently unused as no alternate keyboard available to access a-zA-Z - // Pin - Keyboard for entering Pins (Hex values) currently unused. - // - // SPECIAL NOTE: Usage of NumPunc may have to be removed, ABC button is non-functional. - // - enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin }; - QBBVirtualKeyboard(); ~QBBVirtualKeyboard(); bool showKeyboard(); bool hideKeyboard(); - int getHeight() { return mVisible ? mHeight : 0; } - void setKeyboardMode(KeyboardMode); - void notifyClientActiveStateChange(bool); - bool isVisible() const { return mVisible; } - QString languageId() const { return mLanguageId; } - QString countryId() const { return mCountryId; } public Q_SLOTS: void start(); -Q_SIGNALS: - void heightChanged(int height); +protected: + void applyKeyboardMode(KeyboardMode mode); private Q_SLOTS: void ppsDataReady(); @@ -95,12 +72,7 @@ private: pps_encoder_t *mEncoder; pps_decoder_t *mDecoder; char *mBuffer; - int mHeight; int mFd; - KeyboardMode mKeyboardMode; - bool mVisible; - QString mLanguageId; - QString mCountryId; QSocketNotifier *mReadNotifier; // Path to keyboardManager in PPS. @@ -111,10 +83,9 @@ private: bool connect(); void close(); bool queryPPSInfo(); - void handleKeyboardStateChangeMessage(bool visible); void handleKeyboardInfoMessage(); - void applyKeyboardModeOptions(); + void applyKeyboardModeOptions(KeyboardMode mode); void addDefaultModeOptions(); void addUrlModeOptions(); void addEmailModeOptions(); |