Qt 4.8
qbbvirtualkeyboardbps.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Research In Motion <blackberry-qt@qnx.com>
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //#define QBBVIRTUALKEYBOARD_DEBUG
43 
44 #include "qbbvirtualkeyboardbps.h"
45 
46 #include <QDebug>
47 
48 #include <bps/event.h>
49 #include <bps/locale.h>
50 #include <bps/virtualkeyboard.h>
51 
53 
56 {
57  if (locale_request_events(0) != BPS_SUCCESS)
58  qWarning("QBB: Failed to register for locale events");
59 
60  if (virtualkeyboard_request_events(0) != BPS_SUCCESS)
61  qWarning("QBB: Failed to register for virtual keyboard events");
62 
63  int height = 0;
64  if (virtualkeyboard_get_height(&height) != BPS_SUCCESS)
65  qWarning("QBB: Failed to get virtual keyboard height");
66 
67  setHeight(height);
68 }
69 
71 {
72  const int eventDomain = bps_event_get_domain(event);
73  if (eventDomain == locale_get_domain())
74  return handleLocaleEvent(event);
75 
76  if (eventDomain == virtualkeyboard_get_domain())
77  return handleVirtualKeyboardEvent(event);
78 
79  return false;
80 }
81 
83 {
84 #if defined(QBBVIRTUALKEYBOARD_DEBUG)
85  qDebug() << Q_FUNC_INFO << "current visibility=" << isVisible();
86 #endif
87 
88  // They keyboard's mode is global between applications, we have to set it each time
89  if (!isVisible())
91 
92  virtualkeyboard_show();
93  return true;
94 }
95 
97 {
98 #if defined(QBBVIRTUALKEYBOARD_DEBUG)
99  qDebug() << Q_FUNC_INFO << "current visibility=" << isVisible();
100 #endif
101 
102  virtualkeyboard_hide();
103  return true;
104 }
105 
107 {
108  virtualkeyboard_layout_t layout = VIRTUALKEYBOARD_LAYOUT_DEFAULT;
109 
110  switch (mode) {
111  case Url:
112  layout = VIRTUALKEYBOARD_LAYOUT_URL;
113  break;
114 
115  case Email:
116  layout = VIRTUALKEYBOARD_LAYOUT_EMAIL;
117  break;
118 
119  case Web:
120  layout = VIRTUALKEYBOARD_LAYOUT_WEB;
121  break;
122 
123  case NumPunc:
124  layout = VIRTUALKEYBOARD_LAYOUT_NUM_PUNC;
125  break;
126 
127  case Symbol:
128  layout = VIRTUALKEYBOARD_LAYOUT_SYMBOL;
129  break;
130 
131  case Phone:
132  layout = VIRTUALKEYBOARD_LAYOUT_PHONE;
133  break;
134 
135  case Pin:
136  layout = VIRTUALKEYBOARD_LAYOUT_PIN;
137  break;
138 
139  case Default: // fall through
140  default:
141  layout = VIRTUALKEYBOARD_LAYOUT_DEFAULT;
142  break;
143  }
144 
145 #if defined(QBBVIRTUALKEYBOARD_DEBUG)
146  qDebug() << Q_FUNC_INFO << "mode=" << mode;
147 #endif
148 
149  virtualkeyboard_change_options(layout, VIRTUALKEYBOARD_ENTER_DEFAULT);
150 }
151 
153 {
154  if (bps_event_get_code(event) == LOCALE_INFO) {
155  const QString language = QString::fromAscii(locale_event_get_language(event));
156  const QString country = QString::fromAscii(locale_event_get_country(event));
157 
158 #if defined(QBBVIRTUALKEYBOARD_DEBUG)
159  qDebug() << Q_FUNC_INFO << "current language/country" << languageId() << "/" << countryId()
160  << "new language/country=" << language << "/" << country;
161 #endif
162  setLanguage(language);
163  setCountry(country);
164  return true;
165  }
166 
167 #if defined(QBBVIRTUALKEYBOARD_DEBUG)
168  qDebug() << "QBB: Unhandled locale event. code=" << bps_event_get_code(event);
169 #endif
170 
171  return false;
172 }
173 
175 {
176  switch (bps_event_get_code(event)) {
177  case VIRTUALKEYBOARD_EVENT_VISIBLE:
178  #if defined(QBBVIRTUALKEYBOARD_DEBUG)
179  qDebug() << Q_FUNC_INFO << "EVENT VISIBLE: current visibility=" << isVisible();
180  #endif
181 
182  setVisible(true);
183  break;
184 
185  case VIRTUALKEYBOARD_EVENT_HIDDEN:
186  #if defined(QBBVIRTUALKEYBOARD_DEBUG)
187  qDebug() << Q_FUNC_INFO << "EVENT HIDDEN: current visibility=" << isVisible();
188  #endif
189 
190  setVisible(false);
191  break;
192 
193  case VIRTUALKEYBOARD_EVENT_INFO: {
194  const int newHeight = virtualkeyboard_event_get_height(event);
195 
196  #if defined(QBBVIRTUALKEYBOARD_DEBUG)
197  qDebug() << Q_FUNC_INFO << "EVENT INFO: current height=" << getHeight() << "new height=" << newHeight;
198  #endif
199 
200  setHeight(newHeight);
201  break;
202  }
203 
204  default:
205  #if defined(QBBVIRTUALKEYBOARD_DEBUG)
206  qDebug() << "QBB: Unhandled virtual keyboard event. code=" << bps_event_get_code(event);
207  #endif
208 
209  return false;
210  }
211 
212  return true;
213 }
214 
void setLanguage(const QString &language)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void setCountry(const QString &country)
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
Q_CORE_EXPORT void qDebug(const char *,...)
QBBVirtualKeyboardBps(QObject *parent=0)
QLocale::Language language
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * layout
Q_CORE_EXPORT void qWarning(const char *,...)
bool handleVirtualKeyboardEvent(bps_event_t *event)
bool handleEvent(bps_event_t *event)
void applyKeyboardMode(KeyboardMode mode)
bool handleLocaleEvent(bps_event_t *event)
QLocale::Country country
#define Q_FUNC_INFO
Definition: qglobal.h:1871