diff --git a/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.cpp b/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.cpp index 1d8591cfa1..800cb96bdf 100644 --- a/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.cpp +++ b/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.cpp @@ -49,6 +49,7 @@ QQnxAbstractVirtualKeyboard::QQnxAbstractVirtualKeyboard(QObject *parent) , m_visible(false) , m_locale(QLocale::system()) , m_keyboardMode(Default) + , m_enterKeyType(DefaultReturn) { } @@ -59,7 +60,19 @@ void QQnxAbstractVirtualKeyboard::setKeyboardMode(KeyboardMode mode) m_keyboardMode = mode; - applyKeyboardMode(mode); + if (m_visible) + applyKeyboardOptions(); +} + +void QQnxAbstractVirtualKeyboard::setEnterKeyType(EnterKeyType type) +{ + if (type == m_enterKeyType) + return; + + m_enterKeyType = type; + + if (m_visible) + applyKeyboardOptions(); } void QQnxAbstractVirtualKeyboard::setInputHints(int inputHints) @@ -69,10 +82,11 @@ void QQnxAbstractVirtualKeyboard::setInputHints(int inputHints) } else if (inputHints & Qt::ImhDialableCharactersOnly) { setKeyboardMode(QQnxAbstractVirtualKeyboard::Phone); } else if (inputHints & Qt::ImhUrlCharactersOnly) { - setKeyboardMode(QQnxAbstractVirtualKeyboard::Web); - } else if (inputHints & Qt::ImhFormattedNumbersOnly || inputHints & Qt::ImhDigitsOnly || - inputHints & Qt::ImhDate || inputHints & Qt::ImhTime) { - setKeyboardMode(QQnxAbstractVirtualKeyboard::NumPunc); + setKeyboardMode(QQnxAbstractVirtualKeyboard::Url); + } else if (inputHints & Qt::ImhFormattedNumbersOnly || inputHints & Qt::ImhDigitsOnly) { + setKeyboardMode(QQnxAbstractVirtualKeyboard::Number); + } else if (inputHints & Qt::ImhDate || inputHints & Qt::ImhTime) { + setKeyboardMode(QQnxAbstractVirtualKeyboard::NumPunc); // Use NumPunc so that : is available. } else if (inputHints & Qt::ImhHiddenText) { setKeyboardMode(QQnxAbstractVirtualKeyboard::Password); } else { diff --git a/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.h b/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.h index 033d8ebb74..bff8c56835 100644 --- a/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.h +++ b/src/plugins/platforms/qnx/qqnxabstractvirtualkeyboard.h @@ -51,19 +51,20 @@ class QQnxAbstractVirtualKeyboard : public QObject { Q_OBJECT public: - // NOTE: Not all the following keyboard modes are currently used. + // Keyboard Types currently supported. // 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 + // Number - Number pad // 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. - // Password - Keyboard for entering passwords. + // Phone - Phone enhanced keyboard + // Pin - Keyboard for entering Pins (Hex values). + // Password - Keyboard with lots of extra characters for password input. + // Alphanumeric - Similar to password without any of the security implications. // - // 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, Password }; + enum KeyboardMode { Default, Url, Email, Web, NumPunc, Number, Symbol, Phone, Pin, Password, Alphanumeric }; + enum EnterKeyType { DefaultReturn, Connect, Done, Go, Join, Next, Search, Send, Submit }; explicit QQnxAbstractVirtualKeyboard(QObject *parent = 0); @@ -75,8 +76,11 @@ public: QLocale locale() const { return m_locale; } void setKeyboardMode(KeyboardMode mode); + void setEnterKeyType(EnterKeyType type); + void setInputHints(int inputHints); KeyboardMode keyboardMode() const { return m_keyboardMode; } + EnterKeyType enterKeyType() const { return m_enterKeyType; } Q_SIGNALS: void heightChanged(int height); @@ -84,7 +88,7 @@ Q_SIGNALS: void localeChanged(const QLocale &locale); protected: - virtual void applyKeyboardMode(KeyboardMode mode) = 0; + virtual void applyKeyboardOptions() = 0; void setHeight(int height); void setVisible(bool visible); @@ -95,6 +99,7 @@ private: bool m_visible; QLocale m_locale; KeyboardMode m_keyboardMode; + EnterKeyType m_enterKeyType; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.cpp b/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.cpp index f3a6887613..b154638865 100644 --- a/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.cpp +++ b/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.cpp @@ -89,7 +89,7 @@ bool QQnxVirtualKeyboardBps::showKeyboard() // They keyboard's mode is global between applications, we have to set it each time if ( !isVisible() ) - applyKeyboardMode(keyboardMode()); + applyKeyboardOptions(); virtualkeyboard_show(); return true; @@ -102,52 +102,72 @@ bool QQnxVirtualKeyboardBps::hideKeyboard() return true; } -void QQnxVirtualKeyboardBps::applyKeyboardMode(KeyboardMode mode) +void QQnxVirtualKeyboardBps::applyKeyboardOptions() { - virtualkeyboard_layout_t layout = VIRTUALKEYBOARD_LAYOUT_DEFAULT; + virtualkeyboard_layout_t layout = keyboardLayout(); + virtualkeyboard_enter_t enter = enterKey(); - switch (mode) { + qVirtualKeyboardDebug() << Q_FUNC_INFO << "mode=" << keyboardMode() << "enterKey=" << enterKeyType(); + + virtualkeyboard_change_options(layout, enter); +} + +virtualkeyboard_layout_t QQnxVirtualKeyboardBps::keyboardLayout() const +{ + switch (keyboardMode()) { case Url: - layout = VIRTUALKEYBOARD_LAYOUT_URL; - break; - + return VIRTUALKEYBOARD_LAYOUT_URL; case Email: - layout = VIRTUALKEYBOARD_LAYOUT_EMAIL; - break; - + return VIRTUALKEYBOARD_LAYOUT_EMAIL; case Web: - layout = VIRTUALKEYBOARD_LAYOUT_WEB; - break; - + return VIRTUALKEYBOARD_LAYOUT_WEB; case NumPunc: - layout = VIRTUALKEYBOARD_LAYOUT_NUM_PUNC; - break; - + return VIRTUALKEYBOARD_LAYOUT_NUM_PUNC; + case Number: + return VIRTUALKEYBOARD_LAYOUT_NUMBER; case Symbol: - layout = VIRTUALKEYBOARD_LAYOUT_SYMBOL; - break; - + return VIRTUALKEYBOARD_LAYOUT_SYMBOL; case Phone: - layout = VIRTUALKEYBOARD_LAYOUT_PHONE; - break; - + return VIRTUALKEYBOARD_LAYOUT_PHONE; case Pin: - layout = VIRTUALKEYBOARD_LAYOUT_PIN; - break; - + return VIRTUALKEYBOARD_LAYOUT_PIN; case Password: - layout = VIRTUALKEYBOARD_LAYOUT_PASSWORD; - break; - + return VIRTUALKEYBOARD_LAYOUT_PASSWORD; + case Alphanumeric: + return VIRTUALKEYBOARD_LAYOUT_ALPHANUMERIC; case Default: // fall through default: - layout = VIRTUALKEYBOARD_LAYOUT_DEFAULT; - break; + return VIRTUALKEYBOARD_LAYOUT_DEFAULT; } - qVirtualKeyboardDebug() << Q_FUNC_INFO << "mode=" << mode; + return VIRTUALKEYBOARD_LAYOUT_DEFAULT; +} - virtualkeyboard_change_options(layout, VIRTUALKEYBOARD_ENTER_DEFAULT); +virtualkeyboard_enter_t QQnxVirtualKeyboardBps::enterKey() const +{ + switch (enterKeyType()) { + case Connect: + return VIRTUALKEYBOARD_ENTER_CONNECT; + case Done: + return VIRTUALKEYBOARD_ENTER_DONE; + case Go: + return VIRTUALKEYBOARD_ENTER_GO; + case Join: + return VIRTUALKEYBOARD_ENTER_JOIN; + case Next: + return VIRTUALKEYBOARD_ENTER_NEXT; + case Search: + return VIRTUALKEYBOARD_ENTER_SEARCH; + case Send: + return VIRTUALKEYBOARD_ENTER_SEND; + case Submit: + return VIRTUALKEYBOARD_ENTER_SUBMIT; + case Default: // fall through + default: + return VIRTUALKEYBOARD_ENTER_DEFAULT; + } + + return VIRTUALKEYBOARD_ENTER_DEFAULT; } bool QQnxVirtualKeyboardBps::handleLocaleEvent(bps_event_t *event) diff --git a/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.h b/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.h index 43ecb4ecf8..5749deb4e0 100644 --- a/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.h +++ b/src/plugins/platforms/qnx/qqnxvirtualkeyboardbps.h @@ -43,6 +43,7 @@ #define QQNXVIRTUALKEYBOARDBPS_H #include "qqnxabstractvirtualkeyboard.h" +#include struct bps_event_t; @@ -60,11 +61,14 @@ public: bool hideKeyboard(); protected: - void applyKeyboardMode(KeyboardMode mode); + void applyKeyboardOptions(); private: bool handleLocaleEvent(bps_event_t *event); bool handleVirtualKeyboardEvent(bps_event_t *event); + + virtualkeyboard_layout_t keyboardLayout() const; + virtualkeyboard_enter_t enterKey() const; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.cpp b/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.cpp index 20fce3da70..2b6ee3d1dc 100644 --- a/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.cpp +++ b/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.cpp @@ -67,9 +67,6 @@ QT_BEGIN_NAMESPACE 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 - QQnxVirtualKeyboardPps::QQnxVirtualKeyboardPps() : m_encoder(0), m_decoder(0), @@ -91,11 +88,6 @@ void QQnxVirtualKeyboardPps::start() return; } -void QQnxVirtualKeyboardPps::applyKeyboardMode(KeyboardMode mode) -{ - applyKeyboardModeOptions(mode); -} - void QQnxVirtualKeyboardPps::close() { delete m_readNotifier; @@ -159,18 +151,14 @@ bool QQnxVirtualKeyboardPps::connect() bool QQnxVirtualKeyboardPps::queryPPSInfo() { + if (!prepareToSend()) + return false; + // Request info, requires id to regenerate res message. pps_encoder_add_string(m_encoder, "msg", "info"); pps_encoder_add_string(m_encoder, "id", "libWebView"); - if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { - close(); - return false; - } - - pps_encoder_reset(m_encoder); - - return true; + return writeCurrentPPSEncoder(); } void QQnxVirtualKeyboardPps::ppsDataReady() @@ -257,9 +245,6 @@ void QQnxVirtualKeyboardPps::handleKeyboardInfoMessage() } const QString countryId = 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) - setHeight(newHeight); const QLocale locale = QLocale(languageId + QLatin1Char('_') + countryId); @@ -272,13 +257,12 @@ bool QQnxVirtualKeyboardPps::showKeyboard() { qVirtualKeyboardDebug() << Q_FUNC_INFO; - // Try to connect. - if (m_fd == -1 && !connect()) + if (!prepareToSend()) return false; // NOTE: This must be done everytime the keyboard is shown even if there is no change because // hiding the keyboard wipes the setting. - applyKeyboardModeOptions(keyboardMode()); + applyKeyboardOptions(); if (isVisible()) return true; @@ -288,140 +272,110 @@ bool QQnxVirtualKeyboardPps::showKeyboard() // Send the show message. pps_encoder_add_string(m_encoder, "msg", "show"); - if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { - close(); - return false; - } - - pps_encoder_reset(m_encoder); - - // Return true if no error occurs. Sizing response will be triggered when confirmation of - // the change arrives. - return true; + return writeCurrentPPSEncoder(); } bool QQnxVirtualKeyboardPps::hideKeyboard() { qVirtualKeyboardDebug() << Q_FUNC_INFO; - if (m_fd == -1 && !connect()) + if (!prepareToSend()) return false; pps_encoder_add_string(m_encoder, "msg", "hide"); - if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { - close(); + return writeCurrentPPSEncoder(); +} - //Try again. - if (connect()) { - if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { - close(); - return false; - } - } - else - return false; - } +bool QQnxVirtualKeyboardPps::prepareToSend() +{ + if (m_fd == -1 && !connect()) + return false; pps_encoder_reset(m_encoder); - - // Return true if no error occurs. Sizing response will be triggered when confirmation of - // the change arrives. return true; } -void QQnxVirtualKeyboardPps::applyKeyboardModeOptions(KeyboardMode mode) +bool QQnxVirtualKeyboardPps::writeCurrentPPSEncoder() { - // Try to connect. - if (m_fd == -1 && !connect()) + if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { + close(); + return false; + } + return true; +} + +void QQnxVirtualKeyboardPps::applyKeyboardOptions() +{ + if (!prepareToSend()) return; // Send the options message. pps_encoder_add_string(m_encoder, "msg", "options"); - pps_encoder_start_object(m_encoder, "dat"); - switch (mode) { - case Url: - addUrlModeOptions(); - break; - case Email: - addEmailModeOptions(); - break; - case Web: - addWebModeOptions(); - break; - case NumPunc: - addNumPuncModeOptions(); - break; - case Symbol: - addSymbolModeOptions(); - break; - case Phone: - addPhoneModeOptions(); - break; - case Pin: - addPinModeOptions(); - break; - case Default: - default: - addDefaultModeOptions(); - break; - } + + pps_encoder_add_string(m_encoder, "enter", enterKeyTypeStr()); + pps_encoder_add_string(m_encoder, "type", keyboardModeStr()); pps_encoder_end_object(m_encoder); - if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) - close(); - - pps_encoder_reset(m_encoder); + writeCurrentPPSEncoder(); } -void QQnxVirtualKeyboardPps::addDefaultModeOptions() +const char* QQnxVirtualKeyboardPps::keyboardModeStr() const { - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "default"); + switch (keyboardMode()) { + case Url: + return "url"; + case Email: + return "email"; + case Web: + return "web"; + case NumPunc: + return "num_punc"; + case Number: + return "number"; + case Symbol: + return "symbol"; + case Phone: + return "phone"; + case Pin: + return "pin"; + case Password: + return "password"; + case Alphanumeric: + return "alphanumeric"; + case Default: + return "default"; + } + + return ""; } -void QQnxVirtualKeyboardPps::addUrlModeOptions() +const char* QQnxVirtualKeyboardPps::enterKeyTypeStr() const { - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "url"); -} + switch (enterKeyType()) { + case DefaultReturn: + return "enter.default"; + case Connect: + return "enter.connect"; + case Done: + return "enter.done"; + case Go: + return "enter.go"; + case Join: + return "enter.join"; + case Next: + return "enter.next"; + case Search: + return "enter.search"; + case Send: + return "enter.send"; + case Submit: + return "enter.submit"; + } -void QQnxVirtualKeyboardPps::addEmailModeOptions() -{ - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "email"); -} - -void QQnxVirtualKeyboardPps::addWebModeOptions() -{ - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "web"); -} - -void QQnxVirtualKeyboardPps::addNumPuncModeOptions() -{ - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "numPunc"); -} - -void QQnxVirtualKeyboardPps::addPhoneModeOptions() -{ - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "phone"); -} - -void QQnxVirtualKeyboardPps::addPinModeOptions() -{ - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "pin"); -} - -void QQnxVirtualKeyboardPps::addSymbolModeOptions() -{ - pps_encoder_add_string(m_encoder, "enter", "enter.default"); - pps_encoder_add_string(m_encoder, "type", "symbol"); + return ""; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.h b/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.h index 6048868b08..2b56d5afbe 100644 --- a/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.h +++ b/src/plugins/platforms/qnx/qqnxvirtualkeyboardpps.h @@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE + class QSocketNotifier; class QQnxVirtualKeyboardPps : public QQnxAbstractVirtualKeyboard @@ -64,7 +65,7 @@ public Q_SLOTS: void start(); protected: - void applyKeyboardMode(KeyboardMode mode); + void applyKeyboardOptions(); private Q_SLOTS: void ppsDataReady(); @@ -76,15 +77,11 @@ private: bool queryPPSInfo(); void handleKeyboardInfoMessage(); - void applyKeyboardModeOptions(KeyboardMode mode); - void addDefaultModeOptions(); - void addUrlModeOptions(); - void addEmailModeOptions(); - void addWebModeOptions(); - void addNumPuncModeOptions(); - void addSymbolModeOptions(); - void addPhoneModeOptions(); - void addPinModeOptions(); + const char* keyboardModeStr() const; + const char* enterKeyTypeStr() const; + + bool prepareToSend(); + bool writeCurrentPPSEncoder(); pps_encoder_t *m_encoder; pps_decoder_t *m_decoder;